summaryrefslogtreecommitdiff
path: root/src/llex.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-05-06 08:11:15 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-05-06 08:16:58 +0200
commit693f073be7408e0eb0422b0e93c60e16b6648045 (patch)
tree7ddcccc9189bd34465fa6b1cbe3ae18fd7209c52 /src/llex.js
parente9db75fac5f5fb4e8a211f69560151fe4415f9d4 (diff)
downloadfengari-693f073be7408e0eb0422b0e93c60e16b6648045.tar.gz
fengari-693f073be7408e0eb0422b0e93c60e16b6648045.tar.bz2
fengari-693f073be7408e0eb0422b0e93c60e16b6648045.zip
BytecodeParser consumes a MBuffer (== ZIO) instead of a DataView
So we can read binary code with a user reader function
Diffstat (limited to 'src/llex.js')
-rw-r--r--src/llex.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/llex.js b/src/llex.js
index 59c9015..5591054 100644
--- a/src/llex.js
+++ b/src/llex.js
@@ -67,8 +67,6 @@ const luaX_tokens = [
"<number>", "<integer>", "<name>", "<string>"
];
-const NUM_RESERVED = Object.keys(RESERVED).length;
-
class MBuffer {
constructor(L, data, reader) {
this.L = L;
@@ -102,6 +100,18 @@ class MBuffer {
return r;
}
+ read(size) {
+ let r = [];
+
+ while (size > 0) {
+ let byte = this.getc();
+ if (byte !== -1) r.push(byte);
+ size--;
+ }
+
+ return r;
+ }
+
fill() {
if (this.reader) {
this.buffer = this.reader(this.L, this.data);