Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,8 @@ export abstract class LuaTranspiler {
switch (expressionName) {
case "push":
return this.transpileLuaLibFunction(LuaLibFeature.ArrayPush, caller, params);
case "pop":
return `table.remove(${caller})`;
case "forEach":
return this.transpileLuaLibFunction(LuaLibFeature.ArrayForEach, caller, params);
case "indexOf":
Expand Down
34 changes: 33 additions & 1 deletion test/unit/lualib/lualib.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,38 @@ export class LuaLibArrayTests {
Expect(result).toBe(JSON.stringify([0].concat(inp)));
}

@TestCase("[1, 2, 3]", [3, 2])
@TestCase("[1, 2, 3, null]", [3, 2])
@Test("array.pop")
public arrayPop(array: string, expected) {
{
// Transpile
const lua = util.transpileString(
`let testArray = ${array};
let val = testArray.pop();
return val`);

// Execute
const result = util.executeLua(lua);

// Assert
Expect(result).toBe(expected[0]);
}
{
// Transpile
const lua = util.transpileString(
`let testArray = ${array};
testArray.pop();
return testArray.length`);

// Execute
const result = util.executeLua(lua);

// Assert
Expect(result).toBe(expected[1]);
}
}

@TestCase("true", "4", "5", 4)
@TestCase("false", "4", "5", 5)
@TestCase("3", "4", "5", 4)
Expand All @@ -276,7 +308,7 @@ export class LuaLibArrayTests {
// Assert
Expect(result).toBe(expected);
}

@TestCase("true", 11)
@TestCase("false", 13)
@TestCase("a < 4", 13)
Expand Down