summaryrefslogtreecommitdiff
path: root/src/lauxlib.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-15 14:18:50 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-15 14:49:38 +1000
commit874cec3fc683671f6d5e540b7f854461a9c5544e (patch)
treeb80d36047d48558812e20b176be381a06f6ce0f1 /src/lauxlib.js
parent43238f0f3d12c0cf2424579f9562b73323021d61 (diff)
downloadfengari-874cec3fc683671f6d5e540b7f854461a9c5544e.tar.gz
fengari-874cec3fc683671f6d5e540b7f854461a9c5544e.tar.bz2
fengari-874cec3fc683671f6d5e540b7f854461a9c5544e.zip
src/lauxlib.js: Feed readahead back into parser
Diffstat (limited to 'src/lauxlib.js')
-rw-r--r--src/lauxlib.js13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js
index 0754aab..23cd041 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -695,10 +695,10 @@ if (!WEB) {
}
}
- const toDataView = function(buffer) {
- let ab = new ArrayBuffer(buffer.length);
+ const toDataView = function(buffer, bytes) {
+ let ab = new ArrayBuffer(bytes);
let au = new Uint8Array(ab);
- for (let i = 0; i < buffer.length; i++)
+ for (let i = 0; i < bytes; i++)
au[i] = buffer[i];
return new DataView(ab);
};
@@ -707,6 +707,7 @@ if (!WEB) {
let lf = ud;
let bytes = 0;
if (lf.n > 0) { /* are there pre-read characters to be read? */
+ bytes = lf.n; /* return them (chars already in buffer) */
lf.n = 0; /* no more pre-read characters */
} else { /* read a block from file */
lf.buff.fill(0);
@@ -714,7 +715,7 @@ if (!WEB) {
lf.pos += bytes;
}
if (bytes > 0)
- return lf.binary ? toDataView(lf.buff) : lf.buff.slice(0, bytes);
+ return lf.binary ? toDataView(lf.buff, bytes) : lf.buff.slice(0, bytes);
else return null;
};
@@ -766,7 +767,6 @@ if (!WEB) {
c: getc(lf) /* skip end-of-line, if present */
};
} else {
- lf.pos--;
return {
skipped: false,
c: c
@@ -798,7 +798,8 @@ if (!WEB) {
if (com.c === lua.LUA_SIGNATURE.charCodeAt(0) && filename) { /* binary file? */
lf.binary = true;
}
-
+ if (com.c !== null)
+ lf.buff[lf.n++] = com.c; /* 'c' is the first character of the stream */
let status = lua.lua_load(L, getF, lf, lua.lua_tostring(L, -1), mode);
if (filename) fs.closeSync(lf.f); /* close file (even in case of errors) */
lua.lua_remove(L, fnameindex);