summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ldump.js5
-rw-r--r--src/lundump.js16
-rw-r--r--tests/lstrlib.js4
3 files changed, 16 insertions, 9 deletions
diff --git a/src/ldump.js b/src/ldump.js
index dd8eb29..98c48ef 100644
--- a/src/ldump.js
+++ b/src/ldump.js
@@ -76,7 +76,7 @@ const DumpString = function(s, D) {
DumpByte(size, D);
else {
DumpByte(0xFF, D);
- DumpInt(size, D);
+ DumpInteger(size, D);
}
DumpBlock(str, size - 1, D); /* no need to save '\0' */
}
@@ -135,7 +135,8 @@ const DumpUpvalues = function(f, D) {
const DumpDebug = function(f, D) {
let n = D.strip ? 0 : f.lineinfo.length;
DumpInt(n, D);
- DumpBlock(f.lineinfo, n, D);
+ for (let i = 0; i < n; i++)
+ DumpInt(f.lineinfo[i], D);
n = D.strip ? 0 : f.locvars.length;
DumpInt(n, D);
for (let i = 0; i < n; i++) {
diff --git a/src/lundump.js b/src/lundump.js
index 70adbec..7452c43 100644
--- a/src/lundump.js
+++ b/src/lundump.js
@@ -48,6 +48,10 @@ class BytecodeParser {
return integer;
}
+ readSize_t() {
+ return this.readInteger();
+ }
+
peekInt() {
return this.dataView.getInt32(this.offset, true);
}
@@ -71,10 +75,10 @@ class BytecodeParser {
}
read8bitString(n) {
- let size = typeof n !== 'undefined' ? n : this.readByte() - 1;
+ let size = typeof n !== 'undefined' ? n : Math.max(this.readByte() - 1, 0);
- if (size === 0xFF) // TODO: test
- this.offset += this.size_tSize;
+ if (size + 1 === 0xFF)
+ size = this.readSize_t() - 1;
if (size === 0) {
return null;
@@ -89,10 +93,10 @@ class BytecodeParser {
}
readString(n) {
- let size = typeof n !== 'undefined' ? n : this.readByte() - 1;
+ let size = typeof n !== 'undefined' ? n : Math.max(this.readByte() - 1, 0);
- if (size === 0xFF) // TODO: test
- this.offset += this.size_tSize;
+ if (size + 1 === 0xFF)
+ size = this.readSize_t() - 1;
if (size === 0) {
return null;
diff --git a/tests/lstrlib.js b/tests/lstrlib.js
index a7693a1..23cd786 100644
--- a/tests/lstrlib.js
+++ b/tests/lstrlib.js
@@ -438,7 +438,7 @@ test('string.dump', function (t) {
linit.luaL_openlibs(L);
- lauxlib.luaL_loadstring(L, luaCode);
+ lauxlib.luaL_loadstring(L, luaCode.trim());
}, "Lua program loaded without error");
@@ -450,6 +450,8 @@ test('string.dump', function (t) {
lapi.lua_load(L, null, dv, "test", "binary");
+ lapi.lua_call(L, 0, -1);
+
}, "Lua program ran without error");
t.strictEqual(