File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -757,7 +757,12 @@ export class LuaTranspiler {
757757 case "splice" :
758758 return `TS_splice(${ caller } , ${ params } )` ;
759759 case "join" :
760- return `table.concat(${ caller } , ${ params } )` ;
760+ if ( node . arguments . length === 0 ) {
761+ // if seperator is omitted default seperator is ","
762+ return `table.concat(${ caller } , ",")` ;
763+ } else {
764+ return `table.concat(${ caller } , ${ params } )` ;
765+ }
761766 default :
762767 throw new TranspileError ( "Unsupported array function: " + expression . name . escapedText , node ) ;
763768 }
Original file line number Diff line number Diff line change @@ -138,4 +138,35 @@ export class LuaLibArrayTests {
138138 Expect ( result ) . toBe ( JSON . stringify ( inp . splice ( start ) ) ) ;
139139 }
140140 }
141+
142+ @TestCase ( [ ] , "" )
143+ @TestCase ( [ "test1" ] , "test1" )
144+ @TestCase ( [ "test1" , "test2" ] , "test1,test2" )
145+ @TestCase ( [ "test1" , "test2" ] , "test1;test2" , ";" )
146+ @TestCase ( [ "test1" , "test2" ] , "test1test2" , "" )
147+ @Test ( "array.join" )
148+ public join < T > ( inp : T [ ] , expected : string , seperator ?: string ) {
149+ let seperatorLua ;
150+ if ( seperator === "" ) {
151+ seperatorLua = "\"\"" ;
152+ } else if ( seperator ) {
153+ seperatorLua = "\"" + seperator + "\"" ;
154+ } else {
155+ seperatorLua = "" ;
156+ }
157+ // Transpile
158+ let lua = util . transpileString (
159+ `let joinTestTable = ${ JSON . stringify ( inp ) } ;
160+ return joinTestTable.join(${ seperatorLua } );` ,
161+ util . dummyTypes . Array
162+ ) ;
163+
164+ // Execute
165+ let result = util . executeLua ( lua ) ;
166+
167+ // Assert
168+ let joinedInp = inp . join ( seperator ) ;
169+ Expect ( result ) . toBe ( joinedInp ) ;
170+ }
171+
141172}
You can’t perform that action at this time.
0 commit comments