aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-08-22 16:58:29 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-08-22 16:58:29 -0300
commit23b79c5945023a661754e45c58595f89c84d4800 (patch)
treec96b90464cca1b6837cfb8a7cf928ed81bc0ffce
parent6fcd334ca0baa76a4509ff584aff3b146b43e027 (diff)
downloadlua-23b79c5945023a661754e45c58595f89c84d4800.tar.gz
lua-23b79c5945023a661754e45c58595f89c84d4800.tar.bz2
lua-23b79c5945023a661754e45c58595f89c84d4800.zip
small changes to facilitate external C coroutines
-rw-r--r--ldo.c14
-rw-r--r--ldo.h3
-rw-r--r--luaconf.h14
3 files changed, 18 insertions, 13 deletions
diff --git a/ldo.c b/ldo.c
index 6af8843e..fcec993e 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.29 2005/08/09 19:49:04 roberto Exp roberto $ 2** $Id: ldo.c,v 2.30 2005/08/22 18:54:49 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -48,7 +48,7 @@ struct lua_longjmp {
48}; 48};
49 49
50 50
51static void seterrorobj (lua_State *L, int errcode, StkId oldtop) { 51void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {
52 switch (errcode) { 52 switch (errcode) {
53 case LUA_ERRMEM: { 53 case LUA_ERRMEM: {
54 setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG)); 54 setsvalue2s(L, oldtop, luaS_newliteral(L, MEMERRMSG));
@@ -82,7 +82,7 @@ static void resetstack (lua_State *L, int status) {
82 L->ci = L->base_ci; 82 L->ci = L->base_ci;
83 L->base = L->ci->base; 83 L->base = L->ci->base;
84 luaF_close(L, L->base); /* close eventual pending closures */ 84 luaF_close(L, L->base); /* close eventual pending closures */
85 seterrorobj(L, status, L->base); 85 luaD_seterrorobj(L, status, L->base);
86 L->nCcalls = 0; 86 L->nCcalls = 0;
87 L->allowhook = 1; 87 L->allowhook = 1;
88 restore_stack_limit(L); 88 restore_stack_limit(L);
@@ -427,10 +427,11 @@ LUA_API int lua_resume (lua_State *L, int nargs) {
427 else if (L->ci != L->base_ci) 427 else if (L->ci != L->base_ci)
428 return resume_error(L, "cannot resume non-suspended coroutine"); 428 return resume_error(L, "cannot resume non-suspended coroutine");
429 } 429 }
430 luai_userstateresume(L, nargs);
430 status = luaD_rawrunprotected(L, resume, L->top - nargs); 431 status = luaD_rawrunprotected(L, resume, L->top - nargs);
431 if (status != 0) { /* error? */ 432 if (status != 0) { /* error? */
432 L->status = cast(lu_byte, status); /* mark thread as `dead' */ 433 L->status = cast(lu_byte, status); /* mark thread as `dead' */
433 seterrorobj(L, status, L->top); 434 luaD_seterrorobj(L, status, L->top);
434 } 435 }
435 else 436 else
436 status = L->status; 437 status = L->status;
@@ -440,9 +441,8 @@ LUA_API int lua_resume (lua_State *L, int nargs) {
440 441
441 442
442LUA_API int lua_yield (lua_State *L, int nresults) { 443LUA_API int lua_yield (lua_State *L, int nresults) {
443 CallInfo *ci; 444 luai_userstateyield(L, nresults);
444 lua_lock(L); 445 lua_lock(L);
445 ci = L->ci;
446 if (L->nCcalls > 0) 446 if (L->nCcalls > 0)
447 luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); 447 luaG_runerror(L, "attempt to yield across metamethod/C-call boundary");
448 L->base = L->top - nresults; /* protect stack slots below */ 448 L->base = L->top - nresults; /* protect stack slots below */
@@ -464,7 +464,7 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u,
464 if (status != 0) { /* an error occurred? */ 464 if (status != 0) { /* an error occurred? */
465 StkId oldtop = restorestack(L, old_top); 465 StkId oldtop = restorestack(L, old_top);
466 luaF_close(L, oldtop); /* close eventual pending closures */ 466 luaF_close(L, oldtop); /* close eventual pending closures */
467 seterrorobj(L, status, oldtop); 467 luaD_seterrorobj(L, status, oldtop);
468 L->nCcalls = oldnCcalls; 468 L->nCcalls = oldnCcalls;
469 L->ci = restoreci(L, old_ci); 469 L->ci = restoreci(L, old_ci);
470 L->base = L->ci->base; 470 L->base = L->ci->base;
diff --git a/ldo.h b/ldo.h
index e1b27db7..574005a3 100644
--- a/ldo.h
+++ b/ldo.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.h,v 2.4 2005/04/25 19:24:10 roberto Exp roberto $ 2** $Id: ldo.h,v 2.5 2005/08/22 18:54:49 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -61,6 +61,7 @@ LUAI_FUNC void luaD_growstack (lua_State *L, int n);
61LUAI_FUNC void luaD_throw (lua_State *L, int errcode); 61LUAI_FUNC void luaD_throw (lua_State *L, int errcode);
62LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 62LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
63 63
64LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
64 65
65#endif 66#endif
66 67
diff --git a/luaconf.h b/luaconf.h
index e623e314..8a57dddd 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: luaconf.h,v 1.59 2005/08/15 14:12:32 roberto Exp roberto $ 2** $Id: luaconf.h,v 1.60 2005/08/17 18:32:09 roberto Exp roberto $
3** Configuration file for Lua 3** Configuration file for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -670,11 +670,15 @@ union luai_Cast { double l_d; long l_l; };
670 670
671 671
672/* 672/*
673@@ luai_userstateopen allows user-specific initialization on new threads. 673@@ luai_userstate* allow user-specific actions on threads.
674** CHANGE it if you defined LUAI_EXTRASPACE and need to initialize that 674** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
675** data whenever a new lua_State is created. 675** extra when a thread is created/deleted/resumed/yielded.
676*/ 676*/
677#define luai_userstateopen(L) ((void)0) 677#define luai_userstateopen(L) ((void)0)
678#define luai_userstatefree(L) ((void)0)
679#define luai_userstateresume(L,n) ((void)0)
680#define luai_userstateyield(L,n) ((void)0)
681
678 682
679 683
680 684