aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-01 12:08:05 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-01 12:08:05 +0100
commitebeb32400b9a2d3e7196887f7021b9bf08770fd9 (patch)
treeb81a3b3bf4e6b80b96c03d0cc8e25b98a6259647 /src
parent68ea92442abea0fd56421c103427d8bdcd9607b0 (diff)
downloadfengari-ebeb32400b9a2d3e7196887f7021b9bf08770fd9.tar.gz
fengari-ebeb32400b9a2d3e7196887f7021b9bf08770fd9.tar.bz2
fengari-ebeb32400b9a2d3e7196887f7021b9bf08770fd9.zip
Lua 5.3 bytecode parser
Diffstat (limited to 'src')
-rw-r--r--src/bytecodeparser.js28
1 files changed, 28 insertions, 0 deletions
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