diff options
-rw-r--r-- | tests/test-suite/inprogress/coroutine.js | 94 | ||||
-rw-r--r-- | tests/test-suite/ltests.js | 74 |
2 files changed, 131 insertions, 37 deletions
diff --git a/tests/test-suite/inprogress/coroutine.js b/tests/test-suite/inprogress/coroutine.js index 8bf2664..29461d3 100644 --- a/tests/test-suite/inprogress/coroutine.js +++ b/tests/test-suite/inprogress/coroutine.js @@ -1197,6 +1197,100 @@ test("[test-suite] coroutine: testing debug library on last function in a suspen }); +test("[test-suite] coroutine: reusing a thread", function (t) { + let luaCode = ` + assert(T.testC([[ + newthread # create thread + pushvalue 2 # push body + pushstring 'a a a' # push argument + xmove 0 3 2 # move values to new thread + resume -1, 1 # call it first time + pushstatus + xmove 3 0 0 # move results back to stack + setglobal X # result + setglobal Y # status + pushvalue 2 # push body (to call it again) + pushstring 'b b b' + xmove 0 3 2 + resume -1, 1 # call it again + pushstatus + xmove 3 0 0 + return 1 # return result + ]], function (...) return ... end) == 'b b b') + + assert(X == 'a a a' and Y == 'OK') + `, 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"); +}); + + +test("[test-suite] coroutine: resuming running coroutine", function (t) { + let luaCode = ` + C = coroutine.create(function () + return T.testC([[ + pushnum 10; + pushnum 20; + resume -3 2; + pushstatus + gettop; + return 3]], C) + end) + local a, b, c, d = coroutine.resume(C) + assert(a == true and string.find(b, "non%-suspended") and + c == "ERRRUN" and d == 4) + + a, b, c, d = T.testC([[ + rawgeti R 1 # get main thread + pushnum 10; + pushnum 20; + resume -3 2; + pushstatus + gettop; + return 4]]) + assert(a == coroutine.running() and string.find(b, "non%-suspended") and + c == "ERRRUN" and d == 4) + `, 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"); +}); + test("[test-suite] coroutine: tests for coroutine API", { skip: true }, function (t) { t.comment("TODO"); }); diff --git a/tests/test-suite/ltests.js b/tests/test-suite/ltests.js index f9d75a6..1f26d45 100644 --- a/tests/test-suite/ltests.js +++ b/tests/test-suite/ltests.js @@ -105,98 +105,98 @@ const runJS = function(L, L1, pc) { let inst = lua.to_jsstring(getstring(L, buff, pc)); if (inst.length === 0) return 0; else if (inst === "absindex") { - lua.lua_pushnumber(1, lua.lua_absindex(1, getindex(L, L1, pc))); + lua.lua_pushnumber(L1, lua.lua_absindex(L1, getindex(L, L1, pc))); } else if (inst === "append") { let t = getindex(L, L1, pc); - let i = lua.lua_rawlen(1, t); - lua.lua_rawseti(1, t, i + 1); + let i = lua.lua_rawlen(L1, t); + lua.lua_rawseti(L1, t, i + 1); } else if (inst === "arith") { let op; skip(pc); op = ops.indexOf(pc[0]); - lua.lua_arith(1, op); + lua.lua_arith(L1, op); } else if (inst === "call") { let narg = getnum(L, L1, pc); let nres = getnum(L, L1, pc); - lua.lua_call(1, narg, nres); + lua.lua_call(L1, narg, nres); } else if (inst === "callk") { let narg = getnum(L, L1, pc); let nres = getnum(L, L1, pc); let i = getindex(L, L1, pc); - lua.lua_callk(1, narg, nres, i, Cfunck); + lua.lua_callk(L1, narg, nres, i, Cfunck); } else if (inst === "checkstack") { let sz = getnum(L, L1, pc); let msg = getstring(L, buff, pc); if (msg.length === 0) msg = null; /* to test 'luaL_checkstack' with no message */ - lauxlib.luaL_checkstack(1, sz, msg); + lauxlib.luaL_checkstack(L1, sz, msg); } else if (inst === "compare") { let opt = getstring(L, buff, pc); /* EQ, LT, or LE */ let op = (opt[0] === 'E'.charCodeAt(0)) ? lua.LUA_OPEQ : (opt[1] === 'T'.charCodeAt(0)) ? lua.LUA_OPLT : lua.LUA_OPLE; let a = getindex(L, L1, pc); let b = getindex(L, L1, pc); - lua.lua_pushboolean(1, lua.lua_compare(1, a, b, op)); + lua.lua_pushboolean(L1, lua.lua_compare(L1, a, b, op)); } else if (inst === "concat") { - lua.lua_concat(1, getnum(L, L1, pc)); + lua.lua_concat(L1, getnum(L, L1, pc)); } else if (inst === "copy") { let f = getindex(L, L1, pc); - lua.lua_copy(1, f, getindex(L, L1, pc)); + lua.lua_copy(L1, f, getindex(L, L1, pc)); } else if (inst === "func2num") { - let func = lua.lua_tocfunction(1, getindex(L, L1, pc)); - lua.lua_pushnumber(1, NaN); // TOODO + let func = lua.lua_tocfunction(L1, getindex(L, L1, pc)); + lua.lua_pushnumber(L1, NaN); // TOODO } else if (inst === "getfield") { let t = getindex(L, L1, pc); - lua.lua_getfield(1, t, getstring(L, buff, pc)); + lua.lua_getfield(L1, t, getstring(L, buff, pc)); } else if (inst === "getglobal") { - lua.lua_getglobal(1, getstring(L, buff, pc)); + lua.lua_getglobal(L1, getstring(L, buff, pc)); } else if (inst === "getmetatable") { - if (lua.lua_getmetatable(1, getindex(L, L1, pc)) === 0) - lua.lua_pushnil(1); + if (lua.lua_getmetatable(L1, getindex(L, L1, pc)) === 0) + lua.lua_pushnil(L1); } else if (inst === "gettable") { - lua.lua_gettable(1, getindex(L, L1, pc)); + lua.lua_gettable(L1, getindex(L, L1, pc)); } else if (inst === "gettop") { - lua.lua_pushinteger(1, lua.lua_gettop(1)); + lua.lua_pushinteger(L1, lua.lua_gettop(L1)); } else if (inst === "gsub") { let a = getnum(L, L1, pc); let b = getnum(L, L1, pc); let c = getnum(L, L1, pc); - lauxlib.luaL_gsub(1, lua.lua_tostring(1, a), lua.lua_tostring(1, b), lua.lua_tostring(1, c)); + lauxlib.luaL_gsub(L1, lua.lua_tostring(L1, a), lua.lua_tostring(L1, b), lua.lua_tostring(L1, c)); } else if (inst === "insert") { - lua.lua_insert(1, getnum(L, L1, pc)); + lua.lua_insert(L1, getnum(L, L1, pc)); } else if (inst === "iscfunction") { - lua.lua_pushboolean(1, lua.lua_iscfunction(1, getindex(L, L1, pc))); + lua.lua_pushboolean(L1, lua.lua_iscfunction(L1, getindex(L, L1, pc))); } else if (inst === "isfunction") { - lua.lua_pushboolean(1, lua.lua_isfunction(1, getindex(L, L1, pc))); + lua.lua_pushboolean(L1, lua.lua_isfunction(L1, getindex(L, L1, pc))); } else if (inst === "isnil") { - lua.lua_pushboolean(1, lua.lua_isnil(1, getindex(L, L1, pc))); + lua.lua_pushboolean(L1, lua.lua_isnil(L1, getindex(L, L1, pc))); } else if (inst === "isnull") { - lua.lua_pushboolean(1, lua.lua_isnone(1, getindex(L, L1, pc))); + lua.lua_pushboolean(L1, lua.lua_isnone(L1, getindex(L, L1, pc))); } else if (inst === "isnumber") { - lua.lua_pushboolean(1, lua.lua_isnumber(1, getindex(L, L1, pc))); + lua.lua_pushboolean(L1, lua.lua_isnumber(L1, getindex(L, L1, pc))); } else if (inst === "isstring") { - lua.lua_pushboolean(1, lua.lua_isstring(1, getindex(L, L1, pc))); + lua.lua_pushboolean(L1, lua.lua_isstring(L1, getindex(L, L1, pc))); } else if (inst === "istable") { - lua.lua_pushboolean(1, lua.lua_istable(1, getindex(L, L1, pc))); + lua.lua_pushboolean(L1, lua.lua_istable(L1, getindex(L, L1, pc))); } else if (inst === "isudataval") { - lua.lua_pushboolean(1, lua.lua_islightuserdata(1, getindex(L, L1, pc))); + lua.lua_pushboolean(L1, lua.lua_islightuserdata(L1, getindex(L, L1, pc))); } else if (inst === "isuserdata") { - lua.lua_pushboolean(1, lua.lua_isuserdata(1, getindex(L, L1, pc))); + lua.lua_pushboolean(L1, lua.lua_isuserdata(L1, getindex(L, L1, pc))); } else if (inst === "len") { - lua.lua_len(1, getindex(L, L1, pc)); + lua.lua_len(L1, getindex(L, L1, pc)); } else if (inst === "Llen") { - lua.lua_pushinteger(1, lauxlib.luaL_len(1, getindex(L, L1, pc))); + lua.lua_pushinteger(L1, lauxlib.luaL_len(L1, getindex(L, L1, pc))); } else if (inst === "loadfile") { - lauxlib.luaL_loadfile(1, lauxlib.luaL_checkstring(1, getnum(L, L1, pc))); + lauxlib.luaL_loadfile(L1, lauxlib.luaL_checkstring(L1, getnum(L, L1, pc))); } else if (inst === "loadstring") { - let s = lauxlib.luaL_checkstring(1, getnum(L, L1, pc)); - lauxlib.luaL_loadstring(1, s); + let s = lauxlib.luaL_checkstring(L1, getnum(L, L1, pc)); + lauxlib.luaL_loadstring(L1, s); } else if (inst === "newmetatable") { - lua.lua_pushboolean(1, lauxlib.luaL_newmetatable(1, getstring(L, buff, pc))); + lua.lua_pushboolean(L1, lauxlib.luaL_newmetatable(L1, getstring(L, buff, pc))); } else if (inst === "newtable") { - lua.lua_newtable(1); + lua.lua_newtable(L1); } else if (inst === "newthread") { - lua.lua_newthread(1); + lua.lua_newthread(L1); } else if (inst === "newuserdata") { lua.lua_newuserdata(L1, getnum(L, L1, pc)); } else if (inst === "next") { |