From fa2cf3808b5b60c5e5cd5d5374196913d3afb74f Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 13 Dec 2017 11:21:19 +1100 Subject: src/lauxlib.js: Implement luaL_prepbuffsize using a Uint8Array --- src/lauxlib.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lauxlib.js b/src/lauxlib.js index 32dd37c..b9b7078 100644 --- a/src/lauxlib.js +++ b/src/lauxlib.js @@ -16,6 +16,7 @@ class luaL_Buffer { constructor() { this.b = null; this.L = null; + this.initb = null; } } @@ -359,7 +360,8 @@ const luaL_optinteger = function(L, arg, def) { }; const luaL_prepbuffsize = function(B, sz) { - return B; + B.initb = new Uint8Array(sz); + return B.initb; }; const luaL_buffinit = function(L, B) { @@ -369,7 +371,7 @@ const luaL_buffinit = function(L, B) { const luaL_buffinitsize = function(L, B, sz) { luaL_buffinit(L, B); - return B; + return luaL_prepbuffsize(B, sz); }; const LUAL_BUFFERSIZE = 8192; @@ -394,7 +396,9 @@ const luaL_addchar = function(B, c) { }; const luaL_addsize = function(B, s) { + B.b = B.b.concat(Array.from(B.initb.subarray(0, s))); B.n += s; + B.initb = null; }; const luaL_pushresultsize = function(B, sz) { -- cgit v1.2.3-70-g09d2