From 693f073be7408e0eb0422b0e93c60e16b6648045 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Sat, 6 May 2017 08:11:15 +0200 Subject: BytecodeParser consumes a MBuffer (== ZIO) instead of a DataView So we can read binary code with a user reader function --- src/llex.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/llex.js') 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 = [ "", "", "", "" ]; -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); -- cgit v1.2.3-54-g00ecf