summaryrefslogtreecommitdiff
path: root/src/lcorolib.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-04-26 17:55:37 +1000
committerdaurnimator <quae@daurnimator.com>2017-04-26 18:06:57 +1000
commitb688ef577a10e8b6f2cf948faaa8d1af70c7949c (patch)
tree0ff07d75f65442b92d8a95259b9ab6845e66b27a /src/lcorolib.js
parent53bd1fcc4b90f24427064419354ad07c552a93d5 (diff)
downloadfengari-b688ef577a10e8b6f2cf948faaa8d1af70c7949c.tar.gz
fengari-b688ef577a10e8b6f2cf948faaa8d1af70c7949c.tar.bz2
fengari-b688ef577a10e8b6f2cf948faaa8d1af70c7949c.zip
Export lapi.js functions from lua.js
Diffstat (limited to 'src/lcorolib.js')
-rw-r--r--src/lcorolib.js75
1 files changed, 37 insertions, 38 deletions
diff --git a/src/lcorolib.js b/src/lcorolib.js
index 98eebac..9c05e40 100644
--- a/src/lcorolib.js
+++ b/src/lcorolib.js
@@ -3,7 +3,6 @@
const assert = require('assert');
const lua = require('./lua.js');
-const lapi = require('./lapi.js');
const lauxlib = require('./lauxlib.js');
const lstate = require('./lstate.js');
const ldo = require('./ldo.js');
@@ -11,65 +10,65 @@ const ldebug = require('./ldebug.js');
const lobject = require('./lobject.js');
const getco = function(L) {
- let co = lapi.lua_tothread(L, 1);
+ let co = lua.lua_tothread(L, 1);
lauxlib.luaL_argcheck(L, co, 1, lua.to_luastring("thread expected", true));
return co;
};
const auxresume = function(L, co, narg) {
- if (!lapi.lua_checkstack(co, narg)) {
- lapi.lua_pushliteral(L, "too many arguments to resume");
+ if (!lua.lua_checkstack(co, narg)) {
+ lua.lua_pushliteral(L, "too many arguments to resume");
return -1; /* error flag */
}
- if (lapi.lua_status(co) === lua.LUA_OK && lapi.lua_gettop(co) === 0) {
- lapi.lua_pushliteral(L, "cannot resume dead coroutine");
+ if (lua.lua_status(co) === lua.LUA_OK && lua.lua_gettop(co) === 0) {
+ lua.lua_pushliteral(L, "cannot resume dead coroutine");
return -1; /* error flag */
}
- lapi.lua_xmove(L, co, narg);
+ lua.lua_xmove(L, co, narg);
let status = ldo.lua_resume(co, L, narg);
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 */
- lapi.lua_pushliteral(L, "too many results to resume");
+ let nres = lua.lua_gettop(co);
+ if (!lua.lua_checkstack(L, nres + 1)) {
+ lua.lua_pop(co, nres); /* remove results anyway */
+ lua.lua_pushliteral(L, "too many results to resume");
return -1; /* error flag */
}
- lapi.lua_xmove(co, L, nres); /* move yielded values */
+ lua.lua_xmove(co, L, nres); /* move yielded values */
return nres;
} else {
- lapi.lua_xmove(co, L, 1); /* move error message */
+ lua.lua_xmove(co, L, 1); /* move error message */
return -1; /* error flag */
}
};
const luaB_coresume = function(L) {
let co = getco(L);
- let r = auxresume(L, co, lapi.lua_gettop(L) - 1);
+ let r = auxresume(L, co, lua.lua_gettop(L) - 1);
if (r < 0) {
- lapi.lua_pushboolean(L, 0);
- lapi.lua_insert(L, -2);
+ lua.lua_pushboolean(L, 0);
+ lua.lua_insert(L, -2);
return 2; /* return false + error message */
} else {
- lapi.lua_pushboolean(L, 1);
- lapi.lua_insert(L, -(r + 1));
+ lua.lua_pushboolean(L, 1);
+ lua.lua_insert(L, -(r + 1));
return r + 1; /* return true + 'resume' returns */
}
};
const luaB_auxwrap = function(L) {
- let co = lapi.lua_tothread(L, lua.lua_upvalueindex(1));
- let r = auxresume(L, co, lapi.lua_gettop(L));
+ let co = lua.lua_tothread(L, lua.lua_upvalueindex(1));
+ let r = auxresume(L, co, lua.lua_gettop(L));
if (r < 0) {
- if (lapi.lua_type(L, -1) === lua.LUA_TSTRING) { /* error object is a string? */
+ if (lua.lua_type(L, -1) === lua.LUA_TSTRING) { /* error object is a string? */
lauxlib.luaL_where(L, 1); /* add extra info */
- lapi.lua_insert(L, -2);
- lapi.lua_concat(L, 2);
+ lua.lua_insert(L, -2);
+ lua.lua_concat(L, 2);
}
- return lapi.lua_error(L); /* propagate error */
+ return lua.lua_error(L); /* propagate error */
}
return r;
@@ -78,41 +77,41 @@ const luaB_auxwrap = function(L) {
const luaB_cocreate = function(L) {
lauxlib.luaL_checktype(L, 1, lua.LUA_TFUNCTION);
let NL = lstate.lua_newthread(L);
- lapi.lua_pushvalue(L, 1); /* move function to top */
- lapi.lua_xmove(L, NL, 1); /* move function from L to NL */
+ lua.lua_pushvalue(L, 1); /* move function to top */
+ lua.lua_xmove(L, NL, 1); /* move function from L to NL */
return 1;
};
const luaB_cowrap = function(L) {
luaB_cocreate(L);
- lapi.lua_pushcclosure(L, luaB_auxwrap, 1);
+ lua.lua_pushcclosure(L, luaB_auxwrap, 1);
return 1;
};
const luaB_yield = function(L) {
- return ldo.lua_yield(L, lapi.lua_gettop(L));
+ return ldo.lua_yield(L, lua.lua_gettop(L));
};
const luaB_costatus = function(L) {
let co = getco(L);
- if (L === co) lapi.lua_pushliteral(L, "running");
+ if (L === co) lua.lua_pushliteral(L, "running");
else {
- switch (lapi.lua_status(co)) {
+ switch (lua.lua_status(co)) {
case lua.LUA_YIELD:
- lapi.lua_pushliteral(L, "suspended");
+ lua.lua_pushliteral(L, "suspended");
break;
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 */
- else if (lapi.lua_gettop(co) === 0)
- lapi.lua_pushliteral(L, "dead");
+ lua.lua_pushliteral(L, "normal"); /* it is running */
+ else if (lua.lua_gettop(co) === 0)
+ lua.lua_pushliteral(L, "dead");
else
- lapi.lua_pushliteral(L, "suspended"); /* initial state */
+ lua.lua_pushliteral(L, "suspended"); /* initial state */
break;
}
default: /* some error occurred */
- lapi.lua_pushliteral(L, "dead");
+ lua.lua_pushliteral(L, "dead");
break;
}
}
@@ -121,12 +120,12 @@ const luaB_costatus = function(L) {
};
const luaB_yieldable = function(L) {
- lapi.lua_pushboolean(L, ldo.lua_isyieldable(L));
+ lua.lua_pushboolean(L, ldo.lua_isyieldable(L));
return 1;
};
const luaB_corunning = function(L) {
- lapi.lua_pushboolean(L, lapi.lua_pushthread(L));
+ lua.lua_pushboolean(L, lua.lua_pushthread(L));
return 2;
};