summaryrefslogtreecommitdiff
path: root/src/lundump.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-03-12 10:23:11 +0100
committerBenoit Giannangeli <giann@users.noreply.github.com>2017-03-13 11:03:24 +0100
commit52fa5f8a97fd5322fcb110298c4ce14328074818 (patch)
treefbfb7f43039885491a87bdfc71f21a73e3dfbe25 /src/lundump.js
parente96d75a87d879f7f455e4b9c6457bf6580743fa5 (diff)
downloadfengari-52fa5f8a97fd5322fcb110298c4ce14328074818.tar.gz
fengari-52fa5f8a97fd5322fcb110298c4ce14328074818.tar.bz2
fengari-52fa5f8a97fd5322fcb110298c4ce14328074818.zip
[Strings] lvm.js
Diffstat (limited to 'src/lundump.js')
-rw-r--r--src/lundump.js35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/lundump.js b/src/lundump.js
index aa66584..d215c60 100644
--- a/src/lundump.js
+++ b/src/lundump.js
@@ -15,7 +15,8 @@ const LUAI_MAXSHORTLEN = 40;
class BytecodeParser {
- constructor(dataView) {
+ constructor(L, dataView) {
+ this.L = L;
this.intSize = 4;
this.size_tSize = 8;
this.instructionSize = 4;
@@ -69,7 +70,7 @@ class BytecodeParser {
return number;
}
- readString(n) {
+ read8bitString(n) {
let size = typeof n !== 'undefined' ? n : this.readByte() - 1;
if (size === 0xFF) // TODO: test
@@ -79,7 +80,7 @@ class BytecodeParser {
return null;
}
- let string = new Uint8Array();
+ let string = [];//new Uint8Array();
for (let i = 0; i < size; i++)
string.push(this.readByte());
@@ -87,6 +88,24 @@ class BytecodeParser {
return string;
}
+ readString(n) {
+ let size = typeof n !== 'undefined' ? n : this.readByte() - 1;
+
+ if (size === 0xFF) // TODO: test
+ this.offset += this.size_tSize;
+
+ if (size === 0) {
+ return null;
+ }
+
+ let string = "";
+
+ for (let i = 0; i < size; i++)
+ string += String.fromCharCode(this.readByte());
+
+ return string;
+ }
+
/* creates a mask with 'n' 1 bits at position 'p' */
static MASK1(n, p) {
return ((~((~0)<<(n)))<<(p));
@@ -158,7 +177,7 @@ class BytecodeParser {
break;
case constant_types.LUA_TSHRSTR:
case constant_types.LUA_TLNGSTR:
- f.k.push(new TValue(constant_types.LUA_TLNGSTR, this.readString()));
+ f.k.push(this.L.l_G.intern(this.read8bitString()));
break;
default:
throw new Error(`unrecognized constant '${t}'`);
@@ -238,13 +257,13 @@ class BytecodeParser {
}
- luaU_undump(L) {
+ luaU_undump() {
this.checkHeader();
- let cl = new LClosure(L, this.readByte());
+ let cl = new LClosure(this.L, this.readByte());
- L.stack[L.top] = cl;
- L.top++;
+ this.L.stack[this.L.top] = cl;
+ this.L.top++;
cl.p = new Proto();