diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-05-23 11:30:45 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-05-24 10:15:31 +0200 |
commit | 3f6f88a1948454562b4416b2f4d398dedac725cc (patch) | |
tree | 979074e24387ef232f9b3b2c2b9ba5f11f93f760 /tests/test-suite/ltests.js | |
parent | 98994b4140e9df0b7795c74f6debf0a4161aae5b (diff) | |
download | fengari-3f6f88a1948454562b4416b2f4d398dedac725cc.tar.gz fengari-3f6f88a1948454562b4416b2f4d398dedac725cc.tar.bz2 fengari-3f6f88a1948454562b4416b2f4d398dedac725cc.zip |
ltests.js: resume, coroutine.js: yields inside hooks
Diffstat (limited to 'tests/test-suite/ltests.js')
-rw-r--r-- | tests/test-suite/ltests.js | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/test-suite/ltests.js b/tests/test-suite/ltests.js index fc81131..dcc8cec 100644 --- a/tests/test-suite/ltests.js +++ b/tests/test-suite/ltests.js @@ -102,7 +102,7 @@ const runJS = function(L, L1, pc) { let status = 0; if (!pc || pc.length === 0) return lauxlib.luaL_error(L, "attempt to runJS empty script"); for (;;) { - let inst = getstring(L, buff, pc); + let inst = lua.to_jsstring(getstring(L, buff, pc).slice(0, -1)); if (inst.length === 0) return 0; else if (inst === "absindex") { lua.lua_pushnumber(1, lua.lua_absindex(1, getindex(L, L1, pc))); @@ -385,6 +385,7 @@ const sethook = function(L) { if (count > 0) mask |= lua.LUA_MASKCOUNT; sethookaux(L, mask, count, scpt); } + return 0; }; const Cfunck = function(L, status, ctx) { @@ -395,8 +396,25 @@ const Cfunck = function(L, status, ctx) { return runJS(L, L, lua.lua_tostring(L, ctx)); }; +const coresume = function(L) { + let status; + let co = lua.lua_tothread(L, 1); + lauxlib.luaL_argcheck(L, co, 1, lua.to_luastring("coroutine expected", true)); + status = lua.lua_resume(co, L, 0); + if (status != lua.LUA_OK && status !== lua.LUA_YIELD) { + lua.lua_pushboolean(L, 0); + lua.lua_insert(L, -2); + return 2; /* return false + error message */ + } + else { + lua.lua_pushboolean(L, 1); + return 1; + } +}; + const tests_funcs = { "newuserdata": newuserdata, + "resume": coresume, "sethook": sethook }; |