diff options
author | daurnimator <quae@daurnimator.com> | 2017-05-08 11:37:03 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-08 11:40:36 +1000 |
commit | ef39c3a77c753d16a702f403faf791d0caf9a595 (patch) | |
tree | 5017628e84845d42e194101599e865fbec6f0163 | |
parent | 41ce60e14b313758d36b6fd3ac91eed8db233e87 (diff) | |
download | fengari-ef39c3a77c753d16a702f403faf791d0caf9a595.tar.gz fengari-ef39c3a77c753d16a702f403faf791d0caf9a595.tar.bz2 fengari-ef39c3a77c753d16a702f403faf791d0caf9a595.zip |
src/lundump.js: .readString should return a lua string, not a js string
This also reverts commit b1a8a4b0435199982d26de4a183600c155619a5a.
-rw-r--r-- | src/lapi.js | 6 | ||||
-rw-r--r-- | src/lundump.js | 17 |
2 files changed, 9 insertions, 14 deletions
diff --git a/src/lapi.js b/src/lapi.js index a7fbc91..aa8cf04 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -527,8 +527,7 @@ const lua_getupvalue = function(L, funcindex, n) { L.stack[L.top++] = new TValue(val.type, val.value); - // FIXME: should always be a lua string - return typeof name === 'string' ? defs.to_luastring(name) : name; + return name; } return null; }; @@ -545,8 +544,7 @@ const lua_setupvalue = function(L, funcindex, n) { val.type = L.stack[L.top].type; val.value = L.stack[L.top].value; - // FIXME: should always be a lua string - return typeof name === 'string' ? defs.to_luastring(name) : name; + return name; } return null; }; diff --git a/src/lundump.js b/src/lundump.js index 9caad90..1570588 100644 --- a/src/lundump.js +++ b/src/lundump.js @@ -9,6 +9,8 @@ const lobject = require('./lobject.js'); const lopcodes = require('./lopcodes.js'); const llex = require('./llex.js'); +let LUAC_DATA = [0x19, 0x93, defs.char["\r"], defs.char["\n"], 0x1a, defs.char["\n"]]; + class BytecodeParser { constructor(L, buffer, name) { @@ -100,12 +102,7 @@ class BytecodeParser { return null; } - let string = ""; - - for (let i = 0; i < size; i++) - string += String.fromCharCode(this.readByte()); - - return string; + return this.read(size); } /* creates a mask with 'n' 1 bits at position 'p' */ @@ -204,7 +201,7 @@ class BytecodeParser { n = this.readInt(); for (let i = 0; i < n; i++) { f.locvars[i] = { - varname: defs.to_luastring(this.readString()), + varname: this.readString(), startpc: this.readInt(), endpc: this.readInt() }; @@ -218,7 +215,7 @@ class BytecodeParser { readFunction(f, psource) { f.source = this.readString(); - if (f.source === null || f.source === undefined || f.source.length === 0) /* no source in dump? */ + if (f.source === null) /* no source in dump? */ f.source = psource; /* reuse parent's source */ f.linedefined = this.readInt(); f.lastlinedefined = this.readInt(); @@ -233,7 +230,7 @@ class BytecodeParser { } checkHeader() { - if (this.readString(3) !== defs.LUA_SIGNATURE.slice(1)) /* 1st char already checked */ + if (this.readString(3).join() !== defs.to_luastring(defs.LUA_SIGNATURE.substring(1)).join()) /* 1st char already checked */ this.error("bad LUA_SIGNATURE, expected '<esc>Lua'"); if (this.readByte() !== 0x53) @@ -242,7 +239,7 @@ class BytecodeParser { if (this.readByte() !== 0) this.error("supports only official PUC-Rio implementation"); - if (this.readString(6) !== "\x19\x93\r\n\x1a\n") + if (this.readString(6).join() !== LUAC_DATA.join()) this.error("bytecode corrupted"); this.intSize = this.readByte(); |