File tree Expand file tree Collapse file tree 3 files changed +27
-5
lines changed
Expand file tree Collapse file tree 3 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,12 @@ function TS_split(str, separator)
115115 return out
116116end
117117
118+ function TS_push (list , ...)
119+ for _ , v in pairs ({... }) do
120+ list [# list + 1 ] = v
121+ end
122+ end
123+
118124-- Set data structure implementation
119125Set = Set or {}
120126Set .__index = Set
Original file line number Diff line number Diff line change @@ -899,10 +899,7 @@ export class LuaTranspiler {
899899 const caller = this . transpileExpression ( expression . expression ) ;
900900 switch ( expression . name . escapedText ) {
901901 case "push" :
902- if ( node . arguments . length > 1 ) {
903- throw new TranspileError ( "Unsupported array function: " + expression . name . escapedText + " with more than one argument" , node ) ;
904- }
905- return `table.insert(${ caller } , ${ params } )` ;
902+ return `TS_push(${ caller } , ${ params } )` ;
906903 case "forEach" :
907904 return `TS_forEach(${ caller } , ${ params } )` ;
908905 case "indexOf" :
@@ -1074,7 +1071,7 @@ export class LuaTranspiler {
10741071 const vars = node . name . elements . map ( element => ( < ts . Identifier > ( < ts . BindingElement > element ) . name ) . escapedText ) . join ( "," ) ;
10751072
10761073 // Don't unpack TupleReturn decorated functions
1077- if ( ts . isCallExpression ( node . initializer )
1074+ if ( ts . isCallExpression ( node . initializer )
10781075 && tsEx . isTupleReturnFunction ( this . checker . getTypeAtLocation ( node . initializer . expression ) , this . checker ) ) {
10791076 return `local ${ vars } =${ value } ` ;
10801077 } else {
Original file line number Diff line number Diff line change @@ -225,4 +225,23 @@ export class LuaLibArrayTests {
225225 // Assert
226226 Expect ( result ) . toBe ( expected ) ;
227227 }
228+
229+ @TestCase ( [ 1 ] )
230+ @TestCase ( [ 1 , 2 , 3 ] )
231+ @Test ( "array.push" )
232+ public arrayPush ( inp : number [ ] ) {
233+ // Transpile
234+ let lua = util . transpileString (
235+ `let testArray = [0];
236+ testArray.push(${ inp . join ( ', ' ) } );
237+ return JSONStringify(testArray);
238+ `
239+ , util . dummyTypes . Array ) ;
240+
241+ // Execute
242+ let result = util . executeLua ( lua ) ;
243+
244+ // Assert
245+ Expect ( result ) . toBe ( JSON . stringify ( [ 0 ] . concat ( inp ) ) ) ;
246+ }
228247}
You can’t perform that action at this time.
0 commit comments