From 3e7c102eefbaae9e6bc839b11bba79aee1c5e040 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 13 Dec 2017 15:13:27 +1100 Subject: Introduce defs.string_of to create string from bytes --- src/defs.js | 3 +++ src/ldump.js | 4 ++-- src/lobject.js | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/defs.js b/src/defs.js index 268e76e..27498c6 100644 --- a/src/defs.js +++ b/src/defs.js @@ -131,6 +131,8 @@ class lua_Debug { } +const string_of = Array.of; + const is_luastring = function(s) { return Array.isArray(s); }; @@ -422,6 +424,7 @@ module.exports.lua_upvalueindex = lua_upvalueindex; module.exports.thread_status = thread_status; module.exports.is_luastring = is_luastring; module.exports.luastring_cmp = luastring_cmp; +module.exports.string_of = string_of; module.exports.to_jsstring = to_jsstring; module.exports.to_luastring = to_luastring; module.exports.to_uristring = to_uristring; diff --git a/src/ldump.js b/src/ldump.js index 627a252..964d6ff 100644 --- a/src/ldump.js +++ b/src/ldump.js @@ -3,7 +3,7 @@ const defs = require('./defs.js'); const CT = defs.constant_types; -const LUAC_DATA = [25, 147, 13, 10, 26, 10]; +const LUAC_DATA = defs.string_of(25, 147, 13, 10, 26, 10); const LUAC_INT = 0x5678; const LUAC_NUM = 370.5; const LUAC_VERSION = Number.parseInt(defs.LUA_VERSION_MAJOR) * 16 + Number.parseInt(defs.LUA_VERSION_MINOR); @@ -30,7 +30,7 @@ const DumpLiteral = function(s, D) { }; const DumpByte = function(y, D) { - DumpBlock([y], 1, D); + DumpBlock(defs.string_of(y), 1, D); }; const DumpInt = function(x, D) { diff --git a/src/lobject.js b/src/lobject.js index a70866d..707cdf8 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -547,7 +547,7 @@ const luaO_pushvfstring = function(L, fmt, argp) { case char['c']: { let buff = argp[a++]; if (ljstype.lisprint(buff)) - pushstr(L, [buff]); + pushstr(L, defs.string_of(buff)); else luaO_pushfstring(L, defs.to_luastring("<\\%d>", true), buff); break; -- cgit v1.2.3-70-g09d2