From dbe2a3bf2ef8c053e6c596c99e29eb27b6118f1b Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 22 Feb 2017 08:23:37 +0100 Subject: ipairs --- tests/lbaselib.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests') 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 -- cgit v1.2.3-70-g09d2