From 0cbdb3527041d016097aa3384af9c5908af2cce6 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 17 Mar 2017 07:56:18 +0100 Subject: lua_dump, string.dump --- tests/lstrlib.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'tests') diff --git a/tests/lstrlib.js b/tests/lstrlib.js index 4df4283..aec8e2a 100644 --- a/tests/lstrlib.js +++ b/tests/lstrlib.js @@ -414,4 +414,50 @@ test('string.sub', function (t) { "456", "Correct element(s) on the stack" ); +}); + + +test('string.dump', function (t) { + let luaCodeToDump = ` + local todump = function(p1, p2, p3) + local s = "hello" + local i = 12 + local f = 12.5 + local b = true + + return p1 + p2 + p3 + end`, + luaCode = ` + ${luaCodeToDump} + + return string.dump(todump) + `, L, bytes = []; + + t.plan(3); + + t.doesNotThrow(function () { + + let bc = toByteCode(luaCodeToDump).dataView; + for (let i = 0; i < bc.byteLength; i++) + bytes.push(bc.getUint8(i, true)); + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lauxlib.luaL_loadstring(L, luaCode); + + }, "Lua program loaded without error"); + + t.doesNotThrow(function () { + + lapi.lua_call(L, 0, -1); + + }, "Lua program ran without error"); + + t.deepEqual( + L.stack[L.top -1].value, + bytes, + "Correct element(s) on the stack" + ); }); \ No newline at end of file -- cgit v1.2.3-70-g09d2