From 8ca3810b6efa8f76284016e1fa3b319449caba37 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Thu, 2 Feb 2017 16:03:03 +0100 Subject: readUpvalues --- src/lundump.js | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/lundump.js b/src/lundump.js index ce16312..608b868 100644 --- a/src/lundump.js +++ b/src/lundump.js @@ -114,6 +114,24 @@ class BytecodeParser { f.code.push(this.readInstruction()); } + readUpvalues(f) { + let n = this.readInt(); + + for (let i = 0; i < n; i++) { + f.upvalues[i] = { + name: null, + instack: this.readByte(), + idx: this.readByte() + }; + + console.log(` + f.upvalues[${i}].name = ${f.upvalues[i].name} + f.upvalues[${i}].instack = ${f.upvalues[i].instack} + f.upvalues[${i}].idx = ${f.upvalues[i].idx} + `); + } + } + readConstants(f) { let n = this.readInt(); @@ -126,28 +144,28 @@ class BytecodeParser { type: constant_types.LUA_TNIL, value: null }); - console.log(`LUA_TNIL : ${f.k[f.k.length - 1].value}`); + console.log(`LUA_TNIL = ${f.k[f.k.length - 1].value}`); break; case constant_types.LUA_TBOOLEAN: f.k.push({ type: constant_types.LUA_TBOOLEAN, value: this.readByte() }); - console.log(`LUA_TBOOLEAN : ${f.k[f.k.length - 1].value}`); + console.log(`LUA_TBOOLEAN = ${f.k[f.k.length - 1].value}`); break; case constant_types.LUA_TNUMFLT: f.k.push({ type: constant_types.LUA_TNUMFLT, value: this.readNumber() }); - console.log(`LUA_TNUMFLT : ${f.k[f.k.length - 1].value}`); + console.log(`LUA_TNUMFLT = ${f.k[f.k.length - 1].value}`); break; case constant_types.LUA_TNUMINT: f.k.push({ type: constant_types.LUA_TNUMINT, value: this.readInteger() }); - console.log(`LUA_TNUMINT : ${f.k[f.k.length - 1].value}`); + console.log(`LUA_TNUMINT = ${f.k[f.k.length - 1].value}`); break; case constant_types.LUA_TSHRSTR: case constant_types.LUA_TLNGSTR: @@ -155,7 +173,7 @@ class BytecodeParser { type: constant_types.LUA_TLNGSTR, value: this.readString() }); - console.log(`LUA_TLNGSTR : ${f.k[f.k.length - 1].value}`); + console.log(`LUA_TLNGSTR = ${f.k[f.k.length - 1].value}`); break; default: throw new Error(`unrecognized constant '${t}'`); @@ -184,7 +202,7 @@ class BytecodeParser { this.readCode(f); this.readConstants(f); - // this.readUpvalues(f); + this.readUpvalues(f); // this.readProtos(f); // this.readDebug(f); } -- cgit v1.2.3-70-g09d2