diff options
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.99 2000/10/02 14:47:43 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.100 2000/10/02 20:10:55 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 | */ |
@@ -112,7 +112,7 @@ void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook) { | |||
112 | } | 112 | } |
113 | 113 | ||
114 | 114 | ||
115 | static void luaD_callHook (lua_State *L, StkId func, lua_Hook callhook, | 115 | void luaD_callHook (lua_State *L, StkId func, lua_Hook callhook, |
116 | const char *event) { | 116 | const char *event) { |
117 | if (L->allowhooks) { | 117 | if (L->allowhooks) { |
118 | lua_Debug ar; | 118 | lua_Debug ar; |
@@ -124,6 +124,7 @@ static void luaD_callHook (lua_State *L, StkId func, lua_Hook callhook, | |||
124 | 124 | ||
125 | 125 | ||
126 | static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) { | 126 | static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) { |
127 | lua_Hook callhook = L->callhook; | ||
127 | int nup = cl->nupvalues; /* number of upvalues */ | 128 | int nup = cl->nupvalues; /* number of upvalues */ |
128 | StkId old_Cbase = L->Cbase; | 129 | StkId old_Cbase = L->Cbase; |
129 | int n; | 130 | int n; |
@@ -131,7 +132,11 @@ static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) { | |||
131 | luaD_checkstack(L, nup+LUA_MINSTACK); /* assures minimum stack size */ | 132 | luaD_checkstack(L, nup+LUA_MINSTACK); /* assures minimum stack size */ |
132 | for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ | 133 | for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ |
133 | *(L->top++) = cl->upvalue[n]; | 134 | *(L->top++) = cl->upvalue[n]; |
135 | if (callhook) | ||
136 | luaD_callHook(L, base-1, callhook, "call"); | ||
134 | n = (*cl->f.c)(L); /* do the actual call */ | 137 | n = (*cl->f.c)(L); /* do the actual call */ |
138 | if (callhook) /* same hook that was active at entry */ | ||
139 | luaD_callHook(L, base-1, callhook, "return"); | ||
135 | L->Cbase = old_Cbase; /* restore old C base */ | 140 | L->Cbase = old_Cbase; /* restore old C base */ |
136 | return L->top - n; /* return index of first result */ | 141 | return L->top - n; /* return index of first result */ |
137 | } | 142 | } |
@@ -154,25 +159,21 @@ void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults) { | |||
154 | */ | 159 | */ |
155 | void luaD_call (lua_State *L, StkId func, int nResults) { | 160 | void luaD_call (lua_State *L, StkId func, int nResults) { |
156 | StkId firstResult; | 161 | StkId firstResult; |
157 | lua_Hook callhook = L->callhook; | ||
158 | retry: /* for `function' tag method */ | 162 | retry: /* for `function' tag method */ |
159 | switch (ttype(func)) { | 163 | switch (ttype(func)) { |
160 | case TAG_LCLOSURE: { | 164 | case TAG_LCLOSURE: { |
161 | CallInfo ci; | 165 | CallInfo ci; |
162 | ci.func = clvalue(func); | 166 | ci.func = clvalue(func); |
163 | ci.line = 0; | ||
164 | ttype(func) = TAG_LMARK; | ||
165 | infovalue(func) = &ci; | 167 | infovalue(func) = &ci; |
166 | if (callhook) | 168 | ttype(func) = TAG_LMARK; |
167 | luaD_callHook(L, func, callhook, "call"); | ||
168 | firstResult = luaV_execute(L, ci.func, func+1); | 169 | firstResult = luaV_execute(L, ci.func, func+1); |
170 | LUA_ASSERT(ttype(func) == TAG_LMARK, "invalid tag"); | ||
169 | break; | 171 | break; |
170 | } | 172 | } |
171 | case TAG_CCLOSURE: { | 173 | case TAG_CCLOSURE: { |
172 | ttype(func) = TAG_CMARK; | 174 | ttype(func) = TAG_CMARK; |
173 | if (callhook) | ||
174 | luaD_callHook(L, func, callhook, "call"); | ||
175 | firstResult = callCclosure(L, clvalue(func), func+1); | 175 | firstResult = callCclosure(L, clvalue(func), func+1); |
176 | LUA_ASSERT(ttype(func) == TAG_CMARK, "invalid tag"); | ||
176 | break; | 177 | break; |
177 | } | 178 | } |
178 | default: { /* `func' is not a function; check the `function' tag method */ | 179 | default: { /* `func' is not a function; check the `function' tag method */ |
@@ -184,8 +185,6 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
184 | goto retry; /* retry the call */ | 185 | goto retry; /* retry the call */ |
185 | } | 186 | } |
186 | } | 187 | } |
187 | if (callhook) /* same hook that was active at entry */ | ||
188 | luaD_callHook(L, func, callhook, "return"); | ||
189 | /* adjust the number of results */ | 188 | /* adjust the number of results */ |
190 | if (nResults == LUA_MULTRET) | 189 | if (nResults == LUA_MULTRET) |
191 | nResults = L->top - firstResult; | 190 | nResults = L->top - firstResult; |