aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-05-08 11:03:21 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-05-08 11:03:21 +0200
commit57a5514f724ee5d31ee6c008954d207da0a6f245 (patch)
tree109f09b369dbc45062e1be9cc5b3fdcc3c782055
parente535c784055065ba8c8b6313b2804562c35dd261 (diff)
downloadfengari-57a5514f724ee5d31ee6c008954d207da0a6f245.tar.gz
fengari-57a5514f724ee5d31ee6c008954d207da0a6f245.tar.bz2
fengari-57a5514f724ee5d31ee6c008954d207da0a6f245.zip
Fixed bad default separator in table.concat
-rw-r--r--src/ltablib.js2
-rw-r--r--tests/test-suite/calls.js47
2 files changed, 48 insertions, 1 deletions
diff --git a/src/ltablib.js b/src/ltablib.js
index 788e236..aaadfd7 100644
--- a/src/ltablib.js
+++ b/src/ltablib.js
@@ -130,7 +130,7 @@ const tmove = function(L) {
const tconcat = function(L) {
let last = aux_getn(L, 1, TAB_R);
- let sep = lauxlib.luaL_optlstring(L, 2, "");
+ let sep = lauxlib.luaL_optlstring(L, 2, []);
let i = lauxlib.luaL_optinteger(L, 3, 1);
last = lauxlib.luaL_optinteger(L, 4, last);
diff --git a/tests/test-suite/calls.js b/tests/test-suite/calls.js
index 20352da..6396dd8 100644
--- a/tests/test-suite/calls.js
+++ b/tests/test-suite/calls.js
@@ -587,3 +587,50 @@ test("[test-suite] calls: test for dump/undump with upvalues", function (t) {
}, "Lua program ran without error");
});
+
+
+test("[test-suite] calls: test for dump/undump with many upvalues", function (t) {
+ let luaCode = `
+ do
+ local nup = 200 -- maximum number of local variables
+ local prog = {"local a1"}
+ for i = 2, nup do prog[#prog + 1] = ", a" .. i end
+ prog[#prog + 1] = " = 1"
+ for i = 2, nup do prog[#prog + 1] = ", " .. i end
+ local sum = 1
+ prog[#prog + 1] = "; return function () return a1"
+ for i = 2, nup do prog[#prog + 1] = " + a" .. i; sum = sum + i end
+ prog[#prog + 1] = " end"
+ prog = table.concat(prog)
+ local f = assert(load(prog))()
+ assert(f() == sum)
+
+ f = load(string.dump(f)) -- main chunk now has many upvalues
+ local a = 10
+ local h = function () return a end
+ for i = 1, nup do
+ debug.upvaluejoin(f, i, h, 1)
+ end
+ assert(f() == 10 * nup)
+ end
+ `, L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ lauxlib.luaL_openlibs(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");
+
+});