From 8871373cea55df0374ed0d4da9cd21f2fb08fe09 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 24 Mar 2017 16:56:31 +0100 Subject: %c put the actual value in the string array --- src/lbaselib.js | 1 + src/lstrlib.js | 3 ++- tests/single.lua | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lbaselib.js b/src/lbaselib.js index 11906db..a6f2ce8 100644 --- a/src/lbaselib.js +++ b/src/lbaselib.js @@ -251,6 +251,7 @@ const luaB_xpcall = function(L) { return finishpcall(L, status, 2); }; +// TODO: does it overwrite the upvalue of the previous closure ? const load_aux = function(L, status, envidx) { if (status === TS.LUA_OK) { if (envidx !== 0) { /* 'env' parameter? */ diff --git a/src/lstrlib.js b/src/lstrlib.js index 03c6358..1294baa 100644 --- a/src/lstrlib.js +++ b/src/lstrlib.js @@ -319,7 +319,8 @@ const str_format = function(L) { switch (String.fromCharCode(strfrmt[0])) { case 'c': { strfrmt = strfrmt.slice(1); - concat(b, lua.to_luastring(sprintf(String.fromCharCode(...form), lauxlib.luaL_checkinteger(L, arg)))); + // concat(b, lua.to_luastring(sprintf(String.fromCharCode(...form), lauxlib.luaL_checkinteger(L, arg)))); + b.push(lauxlib.luaL_checkinteger(L, arg)); break; } case 'd': case 'i': diff --git a/tests/single.lua b/tests/single.lua index e3ba2f5..e8d7210 100644 --- a/tests/single.lua +++ b/tests/single.lua @@ -151,3 +151,8 @@ end x = '"ílo"\n\\' assert(string.format('%q%s', x, x) == '"\\"ílo\\"\\\n\\\\""ílo"\n\\') assert(string.format('%q', "\0") == [["\0"]]) +assert(load(string.format('return %q', x))() == x) +x = "\0\1\0023\5\0009" +assert(load(string.format('return %q', x))() == x) +assert(string.format("\0%c\0%c%x\0", string.byte("\xe4"), string.byte("b"), 140) == + "\0\xe4\0b8c\0") -- cgit v1.2.3-70-g09d2