diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-10-02 13:45:03 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-10-02 13:45:03 -0300 |
| commit | 15462edb0ff86bf1904011b29635420451cab2c5 (patch) | |
| tree | 9a626d34736b830f83fda3f1b2f3342990a05b1f /ldo.c | |
| parent | 6f936bc7931662d0460d47ad73eca308ba5fab2f (diff) | |
| download | lua-15462edb0ff86bf1904011b29635420451cab2c5.tar.gz lua-15462edb0ff86bf1904011b29635420451cab2c5.tar.bz2 lua-15462edb0ff86bf1904011b29635420451cab2c5.zip | |
new definitions for closure structures
Diffstat (limited to 'ldo.c')
| -rw-r--r-- | ldo.c | 15 |
1 files changed, 8 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.140 2001/09/07 17:39:10 roberto Exp $ | 2 | ** $Id: ldo.c,v 1.141 2001/09/25 17:05:49 roberto Exp $ |
| 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 | */ |
| @@ -118,14 +118,14 @@ static void luaD_callHook (lua_State *L, lua_Hook callhook, | |||
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | 120 | ||
| 121 | static StkId callCclosure (lua_State *L, const struct Closure *cl) { | 121 | static StkId callCclosure (lua_State *L, const struct CClosure *cl) { |
| 122 | int nup = cl->nupvalues; /* number of upvalues */ | 122 | int nup = cl->nupvalues; /* number of upvalues */ |
| 123 | int n; | 123 | int n; |
| 124 | luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */ | 124 | luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */ |
| 125 | for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ | 125 | for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ |
| 126 | setobj(L->top++, &cl->u.c.upvalue[n]); | 126 | setobj(L->top++, &cl->upvalue[n]); |
| 127 | lua_unlock(L); | 127 | lua_unlock(L); |
| 128 | n = (*cl->u.c.f)(L); /* do the actual call */ | 128 | n = (*cl->f)(L); /* do the actual call */ |
| 129 | lua_lock(L); | 129 | lua_lock(L); |
| 130 | return L->top - n; /* return index of first result */ | 130 | return L->top - n; /* return index of first result */ |
| 131 | } | 131 | } |
| @@ -155,8 +155,9 @@ void luaD_call (lua_State *L, StkId func) { | |||
| 155 | callhook = L->callhook; | 155 | callhook = L->callhook; |
| 156 | if (callhook) | 156 | if (callhook) |
| 157 | luaD_callHook(L, callhook, l_s("call")); | 157 | luaD_callHook(L, callhook, l_s("call")); |
| 158 | firstResult = (clvalue(func)->isC ? callCclosure(L, clvalue(func)) : | 158 | firstResult = (clvalue(func)->c.isC ? |
| 159 | luaV_execute(L, clvalue(func), func+1)); | 159 | callCclosure(L, &clvalue(func)->c) : |
| 160 | luaV_execute(L, &clvalue(func)->l, func+1)); | ||
| 160 | if (callhook) /* same hook that was active at entry */ | 161 | if (callhook) /* same hook that was active at entry */ |
| 161 | luaD_callHook(L, callhook, l_s("return")); | 162 | luaD_callHook(L, callhook, l_s("return")); |
| 162 | L->ci = ci.prev; /* unchain callinfo */ | 163 | L->ci = ci.prev; /* unchain callinfo */ |
| @@ -213,7 +214,7 @@ static void f_parser (lua_State *L, void *ud) { | |||
| 213 | struct SParser *p = cast(struct SParser *, ud); | 214 | struct SParser *p = cast(struct SParser *, ud); |
| 214 | Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z); | 215 | Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z); |
| 215 | Closure *cl = luaF_newLclosure(L, 0); | 216 | Closure *cl = luaF_newLclosure(L, 0); |
| 216 | cl->u.l.p = tf; | 217 | cl->l.p = tf; |
| 217 | luaF_LConlist(L, cl); | 218 | luaF_LConlist(L, cl); |
| 218 | setclvalue(L->top, cl); | 219 | setclvalue(L->top, cl); |
| 219 | incr_top; | 220 | incr_top; |
