commit 23b79c5945023a661754e45c58595f89c84d4800
parent 6fcd334ca0baa76a4509ff584aff3b146b43e027
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 22 Aug 2005 16:58:07 -0300
small changes to facilitate external C coroutines
Diffstat:
3 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/ldo.c b/ldo.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldo.c,v 2.29 2005/08/09 19:49:04 roberto Exp roberto $
+** $Id: ldo.c,v 2.30 2005/08/22 18:54:49 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -48,7 +48,7 @@ struct lua_longjmp {
};
-static void seterrorobj (lua_State *L, int errcode, StkId oldtop) {
+void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {
switch (errcode) {
case LUA_ERRMEM: {
setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG));
@@ -82,7 +82,7 @@ static void resetstack (lua_State *L, int status) {
L->ci = L->base_ci;
L->base = L->ci->base;
luaF_close(L, L->base); /* close eventual pending closures */
- seterrorobj(L, status, L->base);
+ luaD_seterrorobj(L, status, L->base);
L->nCcalls = 0;
L->allowhook = 1;
restore_stack_limit(L);
@@ -427,10 +427,11 @@ LUA_API int lua_resume (lua_State *L, int nargs) {
else if (L->ci != L->base_ci)
return resume_error(L, "cannot resume non-suspended coroutine");
}
+ luai_userstateresume(L, nargs);
status = luaD_rawrunprotected(L, resume, L->top - nargs);
if (status != 0) { /* error? */
L->status = cast(lu_byte, status); /* mark thread as `dead' */
- seterrorobj(L, status, L->top);
+ luaD_seterrorobj(L, status, L->top);
}
else
status = L->status;
@@ -440,9 +441,8 @@ LUA_API int lua_resume (lua_State *L, int nargs) {
LUA_API int lua_yield (lua_State *L, int nresults) {
- CallInfo *ci;
+ luai_userstateyield(L, nresults);
lua_lock(L);
- ci = L->ci;
if (L->nCcalls > 0)
luaG_runerror(L, "attempt to yield across metamethod/C-call boundary");
L->base = L->top - nresults; /* protect stack slots below */
@@ -464,7 +464,7 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u,
if (status != 0) { /* an error occurred? */
StkId oldtop = restorestack(L, old_top);
luaF_close(L, oldtop); /* close eventual pending closures */
- seterrorobj(L, status, oldtop);
+ luaD_seterrorobj(L, status, oldtop);
L->nCcalls = oldnCcalls;
L->ci = restoreci(L, old_ci);
L->base = L->ci->base;
diff --git a/ldo.h b/ldo.h
@@ -1,5 +1,5 @@
/*
-** $Id: ldo.h,v 2.4 2005/04/25 19:24:10 roberto Exp roberto $
+** $Id: ldo.h,v 2.5 2005/08/22 18:54:49 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -61,6 +61,7 @@ LUAI_FUNC void luaD_growstack (lua_State *L, int n);
LUAI_FUNC void luaD_throw (lua_State *L, int errcode);
LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
+LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
#endif
diff --git a/luaconf.h b/luaconf.h
@@ -1,5 +1,5 @@
/*
-** $Id: luaconf.h,v 1.59 2005/08/15 14:12:32 roberto Exp roberto $
+** $Id: luaconf.h,v 1.60 2005/08/17 18:32:09 roberto Exp roberto $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@@ -670,11 +670,15 @@ union luai_Cast { double l_d; long l_l; };
/*
-@@ luai_userstateopen allows user-specific initialization on new threads.
-** CHANGE it if you defined LUAI_EXTRASPACE and need to initialize that
-** data whenever a new lua_State is created.
+@@ luai_userstate* allow user-specific actions on threads.
+** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
+** extra when a thread is created/deleted/resumed/yielded.
*/
-#define luai_userstateopen(L) ((void)0)
+#define luai_userstateopen(L) ((void)0)
+#define luai_userstatefree(L) ((void)0)
+#define luai_userstateresume(L,n) ((void)0)
+#define luai_userstateyield(L,n) ((void)0)
+