summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lcode.js4
-rw-r--r--src/lundump.js2
-rw-r--r--src/lvm.js7
-rw-r--r--tests/test-suite/events.js52
4 files changed, 58 insertions, 7 deletions
diff --git a/src/lcode.js b/src/lcode.js
index 1235fe4..2887e6d 100644
--- a/src/lcode.js
+++ b/src/lcode.js
@@ -799,8 +799,8 @@ const luaK_exp2RK = function(fs, e) {
let vk = false;
luaK_exp2val(fs, e);
switch (e.k) { /* move constants to 'k' */
- case ek.VTRUE: e.u.info = boolK(fs, 1); vk = true; break;
- case ek.VFALSE: e.u.info = boolK(fs, 0); vk = true; break;
+ case ek.VTRUE: e.u.info = boolK(fs, true); vk = true; break;
+ case ek.VFALSE: e.u.info = boolK(fs, false); vk = true; break;
case ek.VNIL: e.u.info = nilK(fs); vk = true; break;
case ek.VKINT: e.u.info = luaK_intK(fs, e.u.ival); vk = true; break;
case ek.VKFLT: e.u.info = luaK_numberK(fs, e.u.nval); vk = true; break;
diff --git a/src/lundump.js b/src/lundump.js
index 5ea459e..3c35710 100644
--- a/src/lundump.js
+++ b/src/lundump.js
@@ -158,7 +158,7 @@ class BytecodeParser {
f.k.push(new lobject.TValue(defs.CT.LUA_TNIL, null));
break;
case defs.CT.LUA_TBOOLEAN:
- f.k.push(new lobject.TValue(defs.CT.LUA_TBOOLEAN, this.readByte()));
+ f.k.push(new lobject.TValue(defs.CT.LUA_TBOOLEAN, this.readByte() !== 0));
break;
case defs.CT.LUA_TNUMFLT:
f.k.push(new lobject.TValue(defs.CT.LUA_TNUMFLT, this.readNumber()));
diff --git a/src/lvm.js b/src/lvm.js
index 169420e..6a1602c 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -971,14 +971,13 @@ const luaV_concat = function(L, total) {
delete L.stack[top - 1];
} else {
/* at least two non-empty string values; get as many as possible */
- let toconcat = new Array(total);
- toconcat[total-1] = L.stack[top-1].svalue();
+ let concatenated = L.stack[top-1].svalue();
delete L.stack[top - 1];
for (n = 1; n < total && tostring(L, top - n - 1); n++) {
- toconcat[total-n-1] = L.stack[top - n - 1].svalue();
+ concatenated = L.stack[top - n - 1].svalue().concat(concatenated);
delete L.stack[top - n - 1];
}
- let ts = lstring.luaS_bless(L, Array.prototype.concat.apply([], toconcat));
+ let ts = lstring.luaS_bless(L, concatenated);
L.stack[top - n] = new lobject.TValue(CT.LUA_TLNGSTR, ts);
}
total -= n - 1; /* got 'n' strings to create 1 new */
diff --git a/tests/test-suite/events.js b/tests/test-suite/events.js
index 8aa7aa7..090b104 100644
--- a/tests/test-suite/events.js
+++ b/tests/test-suite/events.js
@@ -428,3 +428,55 @@ test("[test-suite] events: __eq between userdata", function (t) {
}, "Lua program ran without error");
});
+
+
+test("[test-suite] events: concat", function (t) {
+ let luaCode = `
+ t = {}
+
+ t.__concat = function (a,b,c)
+ assert(c == nil)
+ if type(a) == 'table' then a = a.val end
+ if type(b) == 'table' then b = b.val end
+ if A then return a..b
+ else
+ return setmetatable({val=a..b}, t)
+ end
+ end
+
+ c = {val="c"}; setmetatable(c, t)
+ d = {val="d"}; setmetatable(d, t)
+
+ A = true
+ assert(c..d == 'cd')
+ assert(0 .."a".."b"..c..d.."e".."f"..(5+3).."g" == "0abcdef8g")
+
+ A = false
+ assert((c..d..c..d).val == 'cdcd')
+ x = c..d
+ assert(getmetatable(x) == t and x.val == 'cd')
+ x = 0 .."a".."b"..c..d.."e".."f".."g"
+ assert(x.val == "0abcdefg")
+ `, L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ lualib.luaL_openlibs(L);
+
+ ltests.luaopen_tests(L);
+
+ lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode));
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lua.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+
+});