From ebeb32400b9a2d3e7196887f7021b9bf08770fd9 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 1 Feb 2017 12:08:05 +0100 Subject: Lua 5.3 bytecode parser --- src/bytecodeparser.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bytecodeparser.js diff --git a/src/bytecodeparser.js b/src/bytecodeparser.js new file mode 100644 index 0000000..595158e --- /dev/null +++ b/src/bytecodeparser.js @@ -0,0 +1,28 @@ +"use strict"; + +const DataView = require('buffer-dataview'); + +/** + * Parse Lua 5.3 bytecode + */ +class BytecodeParser { + + constructor(dataView) { + this.dataView = dataView; + this.offset = 0; + } + + _read(offset, nbytes) { + let bytes = new Uint8Array(nbytes); + + for (let i = 0; i < nbytes; i++) + bytes[i] = this.dataView.getUint8(offset, true); + + return bytes.length === 1 ? bytes[0] : bytes; + } + + readByte() { + return read(this.offset++, 1); + } + +} \ No newline at end of file -- cgit v1.2.3-70-g09d2