summaryrefslogtreecommitdiff
path: root/src/lua51/lbaselib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua51/lbaselib.c')
-rw-r--r--src/lua51/lbaselib.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/lua51/lbaselib.c b/src/lua51/lbaselib.c
index 2ab550b..b4f0b8f 100644
--- a/src/lua51/lbaselib.c
+++ b/src/lua51/lbaselib.c
@@ -140,6 +140,7 @@ static int luaB_getfenv (lua_State *L) {
}
+//c 设置闭包的env
static int luaB_setfenv (lua_State *L) {
luaL_checktype(L, 2, LUA_TTABLE);
getfunc(L, 0);
@@ -515,6 +516,7 @@ static int luaB_costatus (lua_State *L) {
}
+//c coroutine.resume
static int auxresume (lua_State *L, lua_State *co, int narg) {
int status = costatus(L, co);
if (!lua_checkstack(co, narg))
@@ -539,12 +541,13 @@ static int auxresume (lua_State *L, lua_State *co, int narg) {
}
}
-
+//c coroutine.resume()
static int luaB_coresume (lua_State *L) {
lua_State *co = lua_tothread(L, 1);
int r;
luaL_argcheck(L, co, 1, "coroutine expected");
r = auxresume(L, co, lua_gettop(L) - 1);
+// 根据auxresume返回false+错误信息或者true+返回值
if (r < 0) {
lua_pushboolean(L, 0);
lua_insert(L, -2);
@@ -558,6 +561,7 @@ static int luaB_coresume (lua_State *L) {
}
+//c wrap coroutine
static int luaB_auxwrap (lua_State *L) {
lua_State *co = lua_tothread(L, lua_upvalueindex(1));
int r = auxresume(L, co, lua_gettop(L));
@@ -573,8 +577,9 @@ static int luaB_auxwrap (lua_State *L) {
}
+//c 创建协程
static int luaB_cocreate (lua_State *L) {
- lua_State *NL = lua_newthread(L);
+ lua_State *NL = lua_newthread(L); //创建协程
luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 1,
"Lua function expected");
lua_pushvalue(L, 1); /* move function to top */