diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-05-05 15:24:00 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-05-05 15:41:29 +0200 |
commit | 7ef345bee73f6cc843b0d82866d036a3ac5829ca (patch) | |
tree | 11b170164238126952f3c790e18a74a7af629d48 | |
parent | 818a86ae8e4afe75f0521967125cdf1cca6b26f0 (diff) | |
download | fengari-7ef345bee73f6cc843b0d82866d036a3ac5829ca.tar.gz fengari-7ef345bee73f6cc843b0d82866d036a3ac5829ca.tar.bz2 fengari-7ef345bee73f6cc843b0d82866d036a3ac5829ca.zip |
Binary chunk can be a lua string (string.dump)
-rw-r--r-- | src/ldo.js | 4 | ||||
-rw-r--r-- | src/lundump.js | 4 | ||||
-rw-r--r-- | tests/test-suite/calls.js | 35 |
3 files changed, 36 insertions, 7 deletions
@@ -574,7 +574,9 @@ const f_parser = function(L, p) { let c = p.z.getc(); /* read first character */ if (c === defs.LUA_SIGNATURE.charCodeAt(0)) { checkmode(L, p.mode, defs.to_luastring("binary", true)); - cl = new BytecodeParser(L, p.z.buffer, p.name).luaU_undump(); + let buff = p.z.buffer; + if (Array.isArray(buff)) buff = new DataView(new Uint8Array(p.z.buffer).buffer); /* Lua string holding binary (string.dump) */ + cl = new BytecodeParser(L, buff, p.name).luaU_undump(); } else { checkmode(L, p.mode, defs.to_luastring("text", true)); cl = lparser.luaY_parser(L, p.z, p.buff, p.dyd, p.name, c); diff --git a/src/lundump.js b/src/lundump.js index 5d158bd..26405d6 100644 --- a/src/lundump.js +++ b/src/lundump.js @@ -8,11 +8,11 @@ const lfunc = require('./lfunc.js'); const lobject = require('./lobject.js'); const lopcodes = require('./lopcodes.js'); -const LUAI_MAXSHORTLEN = 40; - class BytecodeParser { constructor(L, dataView, name) { + assert(dataView instanceof DataView, "BytecodeParser only operates on a dataView") + this.L = L; this.intSize = 4; this.size_tSize = 8; diff --git a/tests/test-suite/calls.js b/tests/test-suite/calls.js index f7ea559..bccad87 100644 --- a/tests/test-suite/calls.js +++ b/tests/test-suite/calls.js @@ -378,7 +378,6 @@ test("[test-suite] calls: test for generic load", function (t) { function read1 (x) local i = 0 return function () - --print(x) i=i+1 return string.sub(x, i, i) end @@ -401,7 +400,7 @@ test("[test-suite] calls: test for generic load", function (t) { assert(not load(function () return true end)) `, L; - t.plan(1); + t.plan(2); t.doesNotThrow(function () { @@ -413,10 +412,38 @@ test("[test-suite] calls: test for generic load", function (t) { }, "Lua program loaded without error"); - // t.doesNotThrow(function () { + t.doesNotThrow(function () { lua.lua_call(L, 0, -1); - // }, "Lua program ran without error"); + }, "Lua program ran without error"); + +}); + + +test("[test-suite] calls: small bug", function (t) { + let luaCode = ` + local t = {nil, "return ", "3"} + f, msg = load(function () return table.remove(t, 1) end) + assert(f() == nil) -- should read the empty chunk + `, L; + + t.plan(2); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + lauxlib.luaL_openlibs(L); + + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); + + }, "Lua program loaded without error"); + + t.doesNotThrow(function () { + + lua.lua_call(L, 0, -1); + + }, "Lua program ran without error"); }); |