From a0fa83dc9c170542630dbc83d1732d3e7a6313e9 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sat, 6 Jan 2018 19:32:31 +1100 Subject: Expose lua.luastring_of to construct a lua 'string' from raw byte values --- src/defs.js | 4 ++-- src/ldump.js | 4 ++-- src/lobject.js | 2 +- src/lua.js | 1 + src/lutf8lib.js | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/defs.js b/src/defs.js index bb98485..0d53c66 100644 --- a/src/defs.js +++ b/src/defs.js @@ -131,7 +131,7 @@ class lua_Debug { } -const string_of = Uint8Array.of.bind(Uint8Array); +const luastring_of = Uint8Array.of.bind(Uint8Array); const is_luastring = function(s) { return s instanceof Uint8Array; @@ -431,7 +431,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.luastring_of = luastring_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 7e62da3..f736e22 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 = defs.string_of(25, 147, 13, 10, 26, 10); +const LUAC_DATA = defs.luastring_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(defs.string_of(y), 1, D); + DumpBlock(defs.luastring_of(y), 1, D); }; const DumpInt = function(x, D) { diff --git a/src/lobject.js b/src/lobject.js index 1b490f3..bd10be8 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -559,7 +559,7 @@ const luaO_pushvfstring = function(L, fmt, argp) { case char['c']: { let buff = argp[a++]; if (ljstype.lisprint(buff)) - pushstr(L, defs.string_of(buff)); + pushstr(L, defs.luastring_of(buff)); else luaO_pushfstring(L, defs.to_luastring("<\\%d>", true), buff); break; diff --git a/src/lua.js b/src/lua.js index ab1820f..a102431 100644 --- a/src/lua.js +++ b/src/lua.js @@ -78,6 +78,7 @@ module.exports.LUA_VERSUFFIX = defs.LUA_VERSUFFIX; module.exports.LUA_YIELD = defs.thread_status.LUA_YIELD; module.exports.lua_Debug = defs.lua_Debug; module.exports.lua_upvalueindex = defs.lua_upvalueindex; +module.exports.luastring_of = defs.luastring_of; module.exports.to_jsstring = defs.to_jsstring; module.exports.to_luastring = defs.to_luastring; module.exports.to_uristring = defs.to_uristring; diff --git a/src/lutf8lib.js b/src/lutf8lib.js index f581a9e..722d9f1 100644 --- a/src/lutf8lib.js +++ b/src/lutf8lib.js @@ -216,7 +216,7 @@ const funcs = { }; /* pattern to match a single UTF-8 character */ -const UTF8PATT = Uint8Array.of(91, 0, 45, 127, 194, 45, 244, 93, 91, 128, 45, 191, 93, 42); +const UTF8PATT = lua.luastring_of(91, 0, 45, 127, 194, 45, 244, 93, 91, 128, 45, 191, 93, 42); const luaopen_utf8 = function(L) { lauxlib.luaL_newlib(L, funcs); -- cgit v1.2.3-70-g09d2