diff options
author | daurnimator <quae@daurnimator.com> | 2017-04-26 17:26:00 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-04-26 17:27:03 +1000 |
commit | 992285ba12d217a3def72e49a29fba70e4e48f2f (patch) | |
tree | 5d84504946443de0c86b3419c871a38f59322364 | |
parent | 382e28086f97085edbf099247949c3f801cc0ed0 (diff) | |
download | fengari-992285ba12d217a3def72e49a29fba70e4e48f2f.tar.gz fengari-992285ba12d217a3def72e49a29fba70e4e48f2f.tar.bz2 fengari-992285ba12d217a3def72e49a29fba70e4e48f2f.zip |
Remove lua.thread_status
-rw-r--r-- | src/lauxlib.js | 2 | ||||
-rw-r--r-- | src/lbaselib.js | 7 | ||||
-rw-r--r-- | src/lcorolib.js | 9 | ||||
-rw-r--r-- | src/lmathlib.js | 1 | ||||
-rw-r--r-- | src/ltablib.js | 1 | ||||
-rw-r--r-- | src/lua.js | 8 | ||||
-rwxr-xr-x | tests/manual-tests/lua-cli.js | 28 |
7 files changed, 29 insertions, 27 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js index 1ee8900..f2cf220 100644 --- a/src/lauxlib.js +++ b/src/lauxlib.js @@ -514,7 +514,7 @@ if (typeof require === "function") { let filename = lapi.lua_tostring(L, fnameindex).slice(1); lapi.lua_pushstring(L, lua.to_luastring(`cannot ${what} ${lobject.jsstring(filename)}: ${serr}`)); lapi.lua_remove(L, fnameindex); - return lua.thread_status.LUA_ERRFILE; + return lua.LUA_ERRFILE; }; const getc = function(lf) { diff --git a/src/lbaselib.js b/src/lbaselib.js index 8b4e6a5..aa02908 100644 --- a/src/lbaselib.js +++ b/src/lbaselib.js @@ -6,7 +6,6 @@ const lua = require('./lua.js'); const lapi = require('./lapi.js'); const lauxlib = require('./lauxlib.js'); const lobject = require('./lobject.js'); -const TS = lua.thread_status; const luaB_print = function(L) { let n = lapi.lua_gettop(L); /* number of arguments */ @@ -222,7 +221,7 @@ const luaB_select = function(L) { ** ignored). */ const finishpcall = function(L, status, extra) { - if (status !== TS.LUA_OK && status !== TS.LUA_YIELD) { /* error? */ + if (status !== lua.LUA_OK && status !== lua.LUA_YIELD) { /* error? */ lapi.lua_pushboolean(L, 0); /* first result (false) */ lapi.lua_pushvalue(L, -2); /* error message */ return 2; /* return false, msg */ @@ -255,7 +254,7 @@ const luaB_xpcall = function(L) { // TODO: does it overwrite the upvalue of the previous closure ? const load_aux = function(L, status, envidx) { - if (status === TS.LUA_OK) { + if (status === lua.LUA_OK) { if (envidx !== 0) { /* 'env' parameter? */ lapi.lua_pushvalue(L, envidx); /* environment for loaded function */ if (!lapi.lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */ @@ -359,7 +358,7 @@ if (typeof require === "function") { const luaB_dofile = function(L) { let fname = lauxlib.luaL_optstring(L, 1, null); lapi.lua_settop(L, 1); - if (lauxlib.luaL_loadfile(L, fname) !== TS.LUA_OK) + if (lauxlib.luaL_loadfile(L, fname) !== lua.LUA_OK) return lapi.lua_error(L); lapi.lua_callk(L, 0, lua.LUA_MULTRET, 0, dofilecont); return dofilecont(L, 0, 0); diff --git a/src/lcorolib.js b/src/lcorolib.js index a46df98..98eebac 100644 --- a/src/lcorolib.js +++ b/src/lcorolib.js @@ -9,7 +9,6 @@ const lstate = require('./lstate.js'); const ldo = require('./ldo.js'); const ldebug = require('./ldebug.js'); const lobject = require('./lobject.js'); -const TS = lua.thread_status; const getco = function(L) { let co = lapi.lua_tothread(L, 1); @@ -23,14 +22,14 @@ const auxresume = function(L, co, narg) { return -1; /* error flag */ } - if (lapi.lua_status(co) === TS.LUA_OK && lapi.lua_gettop(co) === 0) { + if (lapi.lua_status(co) === lua.LUA_OK && lapi.lua_gettop(co) === 0) { lapi.lua_pushliteral(L, "cannot resume dead coroutine"); return -1; /* error flag */ } lapi.lua_xmove(L, co, narg); let status = ldo.lua_resume(co, L, narg); - if (status === TS.LUA_OK || status === TS.LUA_YIELD) { + if (status === lua.LUA_OK || status === lua.LUA_YIELD) { let nres = lapi.lua_gettop(co); if (!lapi.lua_checkstack(L, nres + 1)) { lapi.lua_pop(co, nres); /* remove results anyway */ @@ -99,10 +98,10 @@ const luaB_costatus = function(L) { if (L === co) lapi.lua_pushliteral(L, "running"); else { switch (lapi.lua_status(co)) { - case TS.LUA_YIELD: + case lua.LUA_YIELD: lapi.lua_pushliteral(L, "suspended"); break; - case TS.LUA_OK: { + case lua.LUA_OK: { let ar = new lua.lua_Debug(); if (ldebug.lua_getstack(co, 0, ar) > 0) /* does it have frames? */ lapi.lua_pushliteral(L, "normal"); /* it is running */ diff --git a/src/lmathlib.js b/src/lmathlib.js index 149bebd..9603d2e 100644 --- a/src/lmathlib.js +++ b/src/lmathlib.js @@ -11,7 +11,6 @@ const ldo = require('./ldo.js'); const ldebug = require('./ldebug.js'); const llimit = require('./llimit.js'); const luaconf = require('./luaconf.js'); -const TS = lua.thread_status; var RNG = seedrandom(); diff --git a/src/ltablib.js b/src/ltablib.js index 60b1554..51f9810 100644 --- a/src/ltablib.js +++ b/src/ltablib.js @@ -10,7 +10,6 @@ const ldo = require('./ldo.js'); const ldebug = require('./ldebug.js'); const llimit = require('./llimit.js'); const lobject = require('./lobject.js'); -const TS = lua.thread_status; /* @@ -14,6 +14,11 @@ module.exports.FENGARI_VERSION_NUM = defs.FENGARI_VERSION_NUM; module.exports.FENGARI_VERSION_RELEASE = defs.FENGARI_VERSION_RELEASE; module.exports.LUA_AUTHORS = defs.LUA_AUTHORS; module.exports.LUA_COPYRIGHT = defs.LUA_COPYRIGHT; +module.exports.LUA_ERRERR = defs.thread_status.LUA_ERRERR; +module.exports.LUA_ERRGCMM = defs.thread_status.LUA_ERRGCMM; +module.exports.LUA_ERRMEM = defs.thread_status.LUA_ERRMEM; +module.exports.LUA_ERRRUN = defs.thread_status.LUA_ERRRUN; +module.exports.LUA_ERRSYNTAX = defs.thread_status.LUA_ERRSYNTAX; module.exports.LUA_HOOKCALL = defs.LUA_HOOKCALL; module.exports.LUA_HOOKCOUNT = defs.LUA_HOOKCOUNT; module.exports.LUA_HOOKLINE = defs.LUA_HOOKLINE; @@ -28,6 +33,7 @@ module.exports.LUA_MASKRET = defs.LUA_MASKRET; module.exports.LUA_MINSTACK = defs.LUA_MINSTACK; module.exports.LUA_MULTRET = defs.LUA_MULTRET; module.exports.LUA_NUMTAGS = defs.LUA_NUMTAGS; +module.exports.LUA_OK = defs.thread_status.LUA_OK; module.exports.LUA_OPADD = defs.LUA_OPADD; module.exports.LUA_OPBAND = defs.LUA_OPBAND; module.exports.LUA_OPBNOT = defs.LUA_OPBNOT; @@ -67,7 +73,7 @@ module.exports.LUA_VERSION_MINOR = defs.LUA_VERSION_MINOR; module.exports.LUA_VERSION_NUM = defs.LUA_VERSION_NUM; module.exports.LUA_VERSION_RELEASE = defs.LUA_VERSION_RELEASE; module.exports.LUA_VERSUFFIX = defs.LUA_VERSUFFIX; +module.exports.LUA_YIELD = defs.thread_status.LUA_YIELD; module.exports.lua_Debug = defs.lua_Debug; module.exports.lua_upvalueindex = defs.lua_upvalueindex; -module.exports.thread_status = defs.thread_status; module.exports.to_luastring = defs.to_luastring; diff --git a/tests/manual-tests/lua-cli.js b/tests/manual-tests/lua-cli.js index 322a963..008f39a 100755 --- a/tests/manual-tests/lua-cli.js +++ b/tests/manual-tests/lua-cli.js @@ -13,7 +13,7 @@ const _PROMPT = lua.to_luastring("_PROMPT"); const _PROMPT2 = lua.to_luastring("_PROMPT2"); const report = function(L, status) { - if (status !== lua.thread_status.LUA_OK) { + if (status !== lua.LUA_OK) { lauxlib.lua_writestringerror(`${lapi.lua_tojsstring(L, -1)}\n`); lapi.lua_pop(L, 1); } @@ -26,7 +26,7 @@ const docall = function(L, narg, nres) { }; const dochunk = function(L, status) { - if (status === lua.thread_status.LUA_OK) { + if (status === lua.LUA_OK) { status = docall(L, 0, 0); } return report(L, status); @@ -45,7 +45,7 @@ const dolibrary = function(L, name) { lapi.lua_getglobal(L, lua.to_luastring("require")); lapi.lua_pushliteral(L, name); let status = docall(L, 1, 1); /* call 'require(name)' */ - if (status === lua.thread_status.LUA_OK) + if (status === lua.LUA_OK) lapi.lua_setglobal(L, lua.to_luastring(name)); /* global[name] = require return */ return report(L, status); }; @@ -167,7 +167,7 @@ if (!has_E) { } else { status = dostring(L, init, name); } - if (status !== lua.thread_status.LUA_OK) { + if (status !== lua.LUA_OK) { return process.exit(1); } } @@ -186,7 +186,7 @@ for (let i = 1; i < script; i++) { } else { status = dolibrary(L, extra); } - if (status !== lua.thread_status.LUA_OK) { + if (status !== lua.LUA_OK) { return process.exit(1); } } @@ -212,7 +212,7 @@ const handle_script = function(L, argv) { else fname = lua.to_luastring(fname); status = lauxlib.luaL_loadfile(L, fname); - if (status === lua.thread_status.LUA_OK) { + if (status === lua.LUA_OK) { let n = pushargs(L); /* push arguments to script */ status = docall(L, n, lua.LUA_MULTRET); } @@ -235,14 +235,14 @@ const doREPL = function(L) { let buffer = lua.to_luastring("return " + input); status = lauxlib.luaL_loadbuffer(L, buffer, buffer.length, stdin); } - if (status !== lua.thread_status.LUA_OK) { + if (status !== lua.LUA_OK) { lapi.lua_pop(L, 1); let buffer = lua.to_luastring(input); - if (lauxlib.luaL_loadbuffer(L, buffer, buffer.length, stdin) === lua.thread_status.LUA_OK) { - status = lua.thread_status.LUA_OK; + if (lauxlib.luaL_loadbuffer(L, buffer, buffer.length, stdin) === lua.LUA_OK) { + status = lua.LUA_OK; } } - while (status === lua.thread_status.LUA_ERRSYNTAX && lapi.lua_tojsstring(L, -1).endsWith("<eof>")) { + while (status === lua.LUA_ERRSYNTAX && lapi.lua_tojsstring(L, -1).endsWith("<eof>")) { /* continuation */ lapi.lua_pop(L, 1); lapi.lua_getglobal(L, _PROMPT2); @@ -253,15 +253,15 @@ const doREPL = function(L) { let buffer = lua.to_luastring(input); status = lauxlib.luaL_loadbuffer(L, buffer, buffer.length, stdin); } - if (status === lua.thread_status.LUA_OK) { + if (status === lua.LUA_OK) { status = docall(L, 0, lua.LUA_MULTRET); } - if (status === lua.thread_status.LUA_OK) { + if (status === lua.LUA_OK) { let n = lapi.lua_gettop(L); if (n > 0) { /* any result to be printed? */ lapi.lua_getglobal(L, lua.to_luastring("print")); lapi.lua_insert(L, 1); - if (lapi.lua_pcall(L, n, 0, 0) != lua.thread_status.LUA_OK) { + if (lapi.lua_pcall(L, n, 0, 0) != lua.LUA_OK) { lauxlib.lua_writestringerror(`error calling 'print' (${lapi.lua_tojsstring(L, -1)})\n`); } } @@ -273,7 +273,7 @@ const doREPL = function(L) { }; if (script < process.argv.length && /* execute main script (if there is one) */ - handle_script(L, process.argv.slice(script)) !== lua.thread_status.LUA_OK) { + handle_script(L, process.argv.slice(script)) !== lua.LUA_OK) { /* success */ } else if (has_i) { doREPL(L); |