diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-12-19 14:40:17 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-12-19 14:40:17 -0200 |
commit | 4dc0be950ad67e4385400aacd25e10325a2a6e59 (patch) | |
tree | 9d201a8d3725f7130740bb574f7e19d8ad3c4d96 | |
parent | 3153a41e330a624fccfb7b9ade576767619b4a6b (diff) | |
download | lua-4dc0be950ad67e4385400aacd25e10325a2a6e59.tar.gz lua-4dc0be950ad67e4385400aacd25e10325a2a6e59.tar.bz2 lua-4dc0be950ad67e4385400aacd25e10325a2a6e59.zip |
new macro 'isLuacode' (to distinguish regular Lua code from
hooks, where C code can run inside a Lua function).
-rw-r--r-- | ldo.c | 7 | ||||
-rw-r--r-- | lstate.c | 4 | ||||
-rw-r--r-- | lstate.h | 10 | ||||
-rw-r--r-- | ltm.c | 6 |
4 files changed, 16 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.180 2017/12/12 11:57:30 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.181 2017/12/15 13:07:10 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 | */ |
@@ -454,7 +454,7 @@ void luaD_call (lua_State *L, StkId func, int nresults) { | |||
454 | ci->func = func; | 454 | ci->func = func; |
455 | ci->top = L->top + LUA_MINSTACK; | 455 | ci->top = L->top + LUA_MINSTACK; |
456 | lua_assert(ci->top <= L->stack_last); | 456 | lua_assert(ci->top <= L->stack_last); |
457 | ci->callstatus = 0; | 457 | ci->callstatus = CIST_C; |
458 | if (L->hookmask & LUA_MASKCALL) | 458 | if (L->hookmask & LUA_MASKCALL) |
459 | luaD_hook(L, LUA_HOOKCALL, -1); | 459 | luaD_hook(L, LUA_HOOKCALL, -1); |
460 | lua_unlock(L); | 460 | lua_unlock(L); |
@@ -479,7 +479,7 @@ void luaD_call (lua_State *L, StkId func, int nresults) { | |||
479 | L->top = ci->top = func + 1 + fsize; | 479 | L->top = ci->top = func + 1 + fsize; |
480 | lua_assert(ci->top <= L->stack_last); | 480 | lua_assert(ci->top <= L->stack_last); |
481 | ci->u.l.savedpc = p->code; /* starting point */ | 481 | ci->u.l.savedpc = p->code; /* starting point */ |
482 | ci->callstatus = CIST_LUA; | 482 | ci->callstatus = 0; |
483 | if (L->hookmask) | 483 | if (L->hookmask) |
484 | callhook(L, ci, 0); | 484 | callhook(L, ci, 0); |
485 | luaV_execute(L, ci); /* run the function */ | 485 | luaV_execute(L, ci); /* run the function */ |
@@ -698,6 +698,7 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx, | |||
698 | } | 698 | } |
699 | L->status = LUA_YIELD; | 699 | L->status = LUA_YIELD; |
700 | if (isLua(ci)) { /* inside a hook? */ | 700 | if (isLua(ci)) { /* inside a hook? */ |
701 | lua_assert(!isLuacode(ci)); | ||
701 | api_check(L, k == NULL, "hooks cannot continue after yielding"); | 702 | api_check(L, k == NULL, "hooks cannot continue after yielding"); |
702 | ci->u2.nyield = 0; /* no results */ | 703 | ci->u2.nyield = 0; /* no results */ |
703 | } | 704 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 2.147 2017/11/13 15:36:52 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.148 2017/11/23 16:35:54 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -177,7 +177,7 @@ static void stack_init (lua_State *L1, lua_State *L) { | |||
177 | /* initialize first ci */ | 177 | /* initialize first ci */ |
178 | ci = &L1->base_ci; | 178 | ci = &L1->base_ci; |
179 | ci->next = ci->previous = NULL; | 179 | ci->next = ci->previous = NULL; |
180 | ci->callstatus = 0; | 180 | ci->callstatus = CIST_C; |
181 | ci->func = L1->top; | 181 | ci->func = L1->top; |
182 | setnilvalue(s2v(L1->top)); /* 'function' entry for this 'ci' */ | 182 | setnilvalue(s2v(L1->top)); /* 'function' entry for this 'ci' */ |
183 | L1->top++; | 183 | L1->top++; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 2.151 2017/11/13 15:36:52 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.152 2017/11/23 16:35:54 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -112,7 +112,7 @@ typedef struct CallInfo { | |||
112 | ** Bits in CallInfo status | 112 | ** Bits in CallInfo status |
113 | */ | 113 | */ |
114 | #define CIST_OAH (1<<0) /* original value of 'allowhook' */ | 114 | #define CIST_OAH (1<<0) /* original value of 'allowhook' */ |
115 | #define CIST_LUA (1<<1) /* call is running a Lua function */ | 115 | #define CIST_C (1<<1) /* call is running a C function */ |
116 | #define CIST_HOOKED (1<<2) /* call is running a debug hook */ | 116 | #define CIST_HOOKED (1<<2) /* call is running a debug hook */ |
117 | #define CIST_YPCALL (1<<3) /* call is a yieldable protected call */ | 117 | #define CIST_YPCALL (1<<3) /* call is a yieldable protected call */ |
118 | #define CIST_TAIL (1<<4) /* call was tail called */ | 118 | #define CIST_TAIL (1<<4) /* call was tail called */ |
@@ -120,7 +120,11 @@ typedef struct CallInfo { | |||
120 | #define CIST_LEQ (1<<6) /* using __lt for __le */ | 120 | #define CIST_LEQ (1<<6) /* using __lt for __le */ |
121 | #define CIST_FIN (1<<7) /* call is running a finalizer */ | 121 | #define CIST_FIN (1<<7) /* call is running a finalizer */ |
122 | 122 | ||
123 | #define isLua(ci) ((ci)->callstatus & CIST_LUA) | 123 | /* active function is a Lua function */ |
124 | #define isLua(ci) (!((ci)->callstatus & CIST_C)) | ||
125 | |||
126 | /* call is running Lua code (not a hook) */ | ||
127 | #define isLuacode(ci) (!((ci)->callstatus & (CIST_C | CIST_HOOKED))) | ||
124 | 128 | ||
125 | /* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */ | 129 | /* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */ |
126 | #define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v)) | 130 | #define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v)) |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 2.52 2017/12/13 18:32:09 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 2.53 2017/12/15 13:07:10 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -108,7 +108,7 @@ void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, | |||
108 | setobj2s(L, func + 3, p3); /* 3rd argument */ | 108 | setobj2s(L, func + 3, p3); /* 3rd argument */ |
109 | L->top += 4; | 109 | L->top += 4; |
110 | /* metamethod may yield only when called from Lua code */ | 110 | /* metamethod may yield only when called from Lua code */ |
111 | if (isLua(L->ci)) | 111 | if (isLuacode(L->ci)) |
112 | luaD_call(L, func, 0); | 112 | luaD_call(L, func, 0); |
113 | else | 113 | else |
114 | luaD_callnoyield(L, func, 0); | 114 | luaD_callnoyield(L, func, 0); |
@@ -124,7 +124,7 @@ void luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1, | |||
124 | setobj2s(L, func + 2, p2); /* 2nd argument */ | 124 | setobj2s(L, func + 2, p2); /* 2nd argument */ |
125 | L->top += 3; | 125 | L->top += 3; |
126 | /* metamethod may yield only when called from Lua code */ | 126 | /* metamethod may yield only when called from Lua code */ |
127 | if (isLua(L->ci)) | 127 | if (isLuacode(L->ci)) |
128 | luaD_call(L, func, 1); | 128 | luaD_call(L, func, 1); |
129 | else | 129 | else |
130 | luaD_callnoyield(L, func, 1); | 130 | luaD_callnoyield(L, func, 1); |