aboutsummaryrefslogtreecommitdiff
path: root/tests/lbaselib.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lbaselib.js')
-rw-r--r--tests/lbaselib.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/lbaselib.js b/tests/lbaselib.js
index 85563da..53191eb 100644
--- a/tests/lbaselib.js
+++ b/tests/lbaselib.js
@@ -365,4 +365,40 @@ test('xpcall', function (t) {
lapi.lua_tostring(L, -1).endsWith("you fucked up"),
"msgh was called and modified the error"
)
+});
+
+
+test('ipairs', function (t) {
+ let luaCode = `
+ local t = {1, 2, 3, 4, 5, ['yo'] = 'lo'}
+
+ local sum = 0
+ for i, v in ipairs(t) do
+ sum = sum + v
+ end
+
+ return sum
+ `, L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+
+ let bc = toByteCode(luaCode).dataView;
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, bc, "test-pcall");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tointeger(L, -1),
+ 15,
+ "Correct element(s) on the stack"
+ )
}); \ No newline at end of file