diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-02 15:38:51 +0100 |
---|---|---|
committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-02 15:48:11 +0100 |
commit | 066719cf3db7f67d4373acb1398e9ca3a2dde3ed (patch) | |
tree | 44ce04e5517dead2ba97efc78588915d777738a6 /src/lundump.js | |
parent | bad73671ca959f292becb8c68b73a14380aeeb56 (diff) | |
download | fengari-066719cf3db7f67d4373acb1398e9ca3a2dde3ed.tar.gz fengari-066719cf3db7f67d4373acb1398e9ca3a2dde3ed.tar.bz2 fengari-066719cf3db7f67d4373acb1398e9ca3a2dde3ed.zip |
readConstants
Diffstat (limited to 'src/lundump.js')
-rw-r--r-- | src/lundump.js | 64 |
1 files changed, 57 insertions, 7 deletions
diff --git a/src/lundump.js b/src/lundump.js index c9481da..ce16312 100644 --- a/src/lundump.js +++ b/src/lundump.js @@ -1,13 +1,14 @@ /*jshint esversion: 6 */ "use strict"; -const DataView = require('buffer-dataview'); -const fs = require('fs'); -const assert = require('assert'); +const DataView = require('buffer-dataview'); +const fs = require('fs'); +const assert = require('assert'); -const lua_State = require('./lstate.js').lua_State; -const LClosure = require('./lobject.js').LClosure; -const Proto = require('./lfunc.js').Proto; +const lua_State = require('./lstate.js').lua_State; +const LClosure = require('./lobject.js').LClosure; +const Proto = require('./lfunc.js').Proto; +const constant_types = require('./lua.js').constant_types; const LUAI_MAXSHORTLEN = 40; @@ -113,6 +114,55 @@ class BytecodeParser { f.code.push(this.readInstruction()); } + readConstants(f) { + let n = this.readInt(); + + for (let i = 0; i < n; i++) { + let t = this.readByte(); + + switch (t) { + case constant_types.LUA_TNIL: + f.k.push({ + type: constant_types.LUA_TNIL, + value: null + }); + 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}`); + 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}`); + 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}`); + break; + case constant_types.LUA_TSHRSTR: + case constant_types.LUA_TLNGSTR: + f.k.push({ + type: constant_types.LUA_TLNGSTR, + value: this.readString() + }); + console.log(`LUA_TLNGSTR : ${f.k[f.k.length - 1].value}`); + break; + default: + throw new Error(`unrecognized constant '${t}'`); + } + } + } + readFunction(f, psource) { f.source = this.readString(); if (f.source == null) /* no source in dump? */ @@ -133,7 +183,7 @@ class BytecodeParser { `); this.readCode(f); - // this.readConstants(f); + this.readConstants(f); // this.readUpvalues(f); // this.readProtos(f); // this.readDebug(f); |