From 618d00711d4fe7c602bad4fa9da1a2a3482142d3 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 29 Dec 2017 01:33:12 +1100 Subject: src/lbaselib.js: Buffer console output as JS strings rather than in Array of bytes --- src/lbaselib.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lbaselib.js b/src/lbaselib.js index 103a9ca..86ba6cc 100644 --- a/src/lbaselib.js +++ b/src/lbaselib.js @@ -6,13 +6,16 @@ const lauxlib = require('./lauxlib.js'); let lua_writestring; let lua_writeline; if (typeof process === "undefined") { - let buff = []; + let buff = ""; + let decoder = new TextDecoder("utf-8"); lua_writestring = function(s) { - buff = buff.concat(Array.from(s)); + buff += decoder.decode(s, {stream: true}); }; + let empty = new Uint8Array(0); lua_writeline = function() { - console.log(new TextDecoder("utf-8").decode(Uint8Array.from(buff))); - buff = []; + buff += decoder.decode(empty); + console.log(buff); + buff = ""; }; } else { lua_writestring = function(s) { -- cgit v1.2.3-70-g09d2