diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-11-25 16:58:51 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-11-25 16:58:51 -0200 |
commit | d29ce757376dd309f097e8ff30dd2a9b14567575 (patch) | |
tree | dc762b6fa87831898b4340882e6b374a585203de /ldo.c | |
parent | 878ef96127e5c4649b07af74029ac14511bdb50a (diff) | |
download | lua-d29ce757376dd309f097e8ff30dd2a9b14567575.tar.gz lua-d29ce757376dd309f097e8ff30dd2a9b14567575.tar.bz2 lua-d29ce757376dd309f097e8ff30dd2a9b14567575.zip |
new signature for function luaD_call (old luaD_calln)
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 27 |
1 files changed, 12 insertions, 15 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.51 1999/11/04 17:22:26 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.52 1999/11/22 13:12:07 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 | */ |
@@ -162,23 +162,21 @@ static StkId callCclosure (lua_State *L, const struct Closure *cl, | |||
162 | void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults) { | 162 | void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults) { |
163 | luaD_openstack(L, nParams); | 163 | luaD_openstack(L, nParams); |
164 | *(L->stack.top-nParams-1) = *f; | 164 | *(L->stack.top-nParams-1) = *f; |
165 | luaD_calln(L, nParams, nResults); | 165 | luaD_call(L, L->stack.top-nParams-1, nResults); |
166 | } | 166 | } |
167 | 167 | ||
168 | 168 | ||
169 | /* | 169 | /* |
170 | ** Call a function (C or Lua). The parameters must be on the stack, | 170 | ** Call a function (C or Lua). The function to be called is at *func. |
171 | ** between [top-nArgs,top). The function to be called is right below the | 171 | ** The arguments are on the stack, right after the function. |
172 | ** arguments. | 172 | ** When returns, the results are on the stack, starting at the original |
173 | ** When returns, the results are on the stack, between [top-nArgs-1,top). | 173 | ** function position. |
174 | ** The number of results is nResults, unless nResults=MULT_RET. | 174 | ** The number of results is nResults, unless nResults=MULT_RET. |
175 | */ | 175 | */ |
176 | void luaD_calln (lua_State *L, int nArgs, int nResults) { | 176 | void luaD_call (lua_State *L, TObject *func, int nResults) { |
177 | struct Stack *S = &L->stack; /* to optimize */ | 177 | struct Stack *S = &L->stack; /* to optimize */ |
178 | StkId base = (S->top-S->stack)-nArgs; | 178 | StkId base = func - S->stack + 1; /* where is first argument */ |
179 | TObject *func = S->stack+base-1; | ||
180 | StkId firstResult; | 179 | StkId firstResult; |
181 | int i; | ||
182 | switch (ttype(func)) { | 180 | switch (ttype(func)) { |
183 | case LUA_T_CPROTO: | 181 | case LUA_T_CPROTO: |
184 | ttype(func) = LUA_T_CMARK; | 182 | ttype(func) = LUA_T_CMARK; |
@@ -213,8 +211,7 @@ void luaD_calln (lua_State *L, int nArgs, int nResults) { | |||
213 | luaD_adjusttop(L, firstResult+nResults); | 211 | luaD_adjusttop(L, firstResult+nResults); |
214 | /* move results to base-1 (to erase parameters and function) */ | 212 | /* move results to base-1 (to erase parameters and function) */ |
215 | base--; | 213 | base--; |
216 | for (i=0; i<nResults; i++) | 214 | luaO_memdown(S->stack+base, S->stack+firstResult, nResults*sizeof(TObject)); |
217 | *(S->stack+base+i) = *(S->stack+firstResult+i); | ||
218 | S->top -= firstResult-base; | 215 | S->top -= firstResult-base; |
219 | } | 216 | } |
220 | 217 | ||
@@ -226,7 +223,7 @@ static void message (lua_State *L, const char *s) { | |||
226 | *L->stack.top = *em; | 223 | *L->stack.top = *em; |
227 | incr_top; | 224 | incr_top; |
228 | lua_pushstring(L, s); | 225 | lua_pushstring(L, s); |
229 | luaD_calln(L, 1, 0); | 226 | luaD_call(L, L->stack.top-2, 0); |
230 | } | 227 | } |
231 | } | 228 | } |
232 | 229 | ||
@@ -256,7 +253,7 @@ int luaD_protectedrun (lua_State *L) { | |||
256 | L->errorJmp = &myErrorJmp; | 253 | L->errorJmp = &myErrorJmp; |
257 | if (setjmp(myErrorJmp.b) == 0) { | 254 | if (setjmp(myErrorJmp.b) == 0) { |
258 | StkId base = L->Cstack.base; | 255 | StkId base = L->Cstack.base; |
259 | luaD_calln(L, (L->stack.top-L->stack.stack)-base-1, MULT_RET); | 256 | luaD_call(L, L->stack.stack+base, MULT_RET); |
260 | L->Cstack.lua2C = base; /* position of the new results */ | 257 | L->Cstack.lua2C = base; /* position of the new results */ |
261 | L->Cstack.num = (L->stack.top-L->stack.stack) - base; | 258 | L->Cstack.num = (L->stack.top-L->stack.stack) - base; |
262 | L->Cstack.base = base + L->Cstack.num; /* incorporate results on stack */ | 259 | L->Cstack.base = base + L->Cstack.num; /* incorporate results on stack */ |