@@ -4295,7 +4295,7 @@ export class LuaTransformer {
42954295 }
42964296
42974297 if ( tsHelper . isStandardLibraryType ( ownerType , "NumberConstructor" , this . program ) ) {
4298- return this . transformNumberCallExpression ( node ) ;
4298+ return this . transformNumberExpression ( node ) ;
42994299 }
43004300
43014301 const classDecorators = tsHelper . getCustomDecorators ( ownerType , this . checker ) ;
@@ -4308,6 +4308,10 @@ export class LuaTransformer {
43084308 return this . transformStringCallExpression ( node ) ;
43094309 }
43104310
4311+ if ( tsHelper . isNumberType ( ownerType , this . checker , this . program ) ) {
4312+ return this . transformNumberCallExpression ( node ) ;
4313+ }
4314+
43114315 // if ownerType is a array, use only supported functions
43124316 if ( tsHelper . isExplicitArrayType ( ownerType , this . checker , this . program ) ) {
43134317 return this . transformArrayCallExpression ( node ) ;
@@ -4883,6 +4887,23 @@ export class LuaTransformer {
48834887 ) ;
48844888 }
48854889
4890+ protected transformNumberCallExpression ( node : ts . CallExpression ) : tstl . Expression {
4891+ const expression = node . expression as ts . PropertyAccessExpression ;
4892+ const signature = this . checker . getResolvedSignature ( node ) ;
4893+ const params = this . transformArguments ( node . arguments , signature ) ;
4894+ const caller = this . transformExpression ( expression . expression ) ;
4895+
4896+ const expressionName = expression . name . text ;
4897+ switch ( expressionName ) {
4898+ case "toString" :
4899+ return params . length === 0
4900+ ? tstl . createCallExpression ( tstl . createIdentifier ( "tostring" ) , [ caller ] , node )
4901+ : this . transformLuaLibFunction ( LuaLibFeature . NumberToString , node , caller , ...params ) ;
4902+ default :
4903+ throw TSTLErrors . UnsupportedProperty ( "number" , expressionName , node ) ;
4904+ }
4905+ }
4906+
48864907 // Transpile a String._ property
48874908 protected transformStringExpression ( identifier : ts . Identifier ) : ExpressionVisitResult {
48884909 const identifierString = identifier . text ;
@@ -5015,7 +5036,7 @@ export class LuaTransformer {
50155036 }
50165037
50175038 // Transpile a Number._ property
5018- protected transformNumberCallExpression ( expression : ts . CallExpression ) : tstl . CallExpression {
5039+ protected transformNumberExpression ( expression : ts . CallExpression ) : tstl . CallExpression {
50195040 const method = expression . expression as ts . PropertyAccessExpression ;
50205041 const parameters = this . transformArguments ( expression . arguments ) ;
50215042 const methodName = method . name . text ;
0 commit comments