|
|
@ -511,23 +511,10 @@ l_sinline CallInfo *prepCallInfo (lua_State *L, StkId func, int nret, |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Prepares the call to a function (C or Lua). For C functions, also do |
|
|
|
** the call. The function to be called is at '*func'. The arguments |
|
|
|
** are on the stack, right after the function. Returns the CallInfo |
|
|
|
** to be executed, if it was a Lua function. Otherwise (a C function) |
|
|
|
** returns NULL, with all the results on the stack, starting at the |
|
|
|
** original function position. |
|
|
|
** precall for C functions |
|
|
|
*/ |
|
|
|
CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { |
|
|
|
lua_CFunction f; |
|
|
|
retry: |
|
|
|
switch (ttypetag(s2v(func))) { |
|
|
|
case LUA_VCCL: /* C closure */ |
|
|
|
f = clCvalue(s2v(func))->f; |
|
|
|
goto Cfunc; |
|
|
|
case LUA_VLCF: /* light C function */ |
|
|
|
f = fvalue(s2v(func)); |
|
|
|
Cfunc: { |
|
|
|
l_sinline CallInfo *precallC (lua_State *L, StkId func, int nresults, |
|
|
|
lua_CFunction f) { |
|
|
|
int n; /* number of returns */ |
|
|
|
CallInfo *ci; |
|
|
|
checkstackGCp(L, LUA_MINSTACK, func); /* ensure minimum stack size */ |
|
|
@ -545,6 +532,22 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { |
|
|
|
luaD_poscall(L, ci, n); |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Prepares the call to a function (C or Lua). For C functions, also do |
|
|
|
** the call. The function to be called is at '*func'. The arguments |
|
|
|
** are on the stack, right after the function. Returns the CallInfo |
|
|
|
** to be executed, if it was a Lua function. Otherwise (a C function) |
|
|
|
** returns NULL, with all the results on the stack, starting at the |
|
|
|
** original function position. |
|
|
|
*/ |
|
|
|
CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { |
|
|
|
switch (ttypetag(s2v(func))) { |
|
|
|
case LUA_VCCL: /* C closure */ |
|
|
|
return precallC(L, func, nresults, clCvalue(s2v(func))->f); |
|
|
|
case LUA_VLCF: /* light C function */ |
|
|
|
return precallC(L, func, nresults, fvalue(s2v(func))); |
|
|
|
case LUA_VLCL: { /* Lua function */ |
|
|
|
CallInfo *ci; |
|
|
|
Proto *p = clLvalue(s2v(func))->p; |
|
|
@ -561,7 +564,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) { |
|
|
|
} |
|
|
|
default: { /* not a function */ |
|
|
|
func = luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */ |
|
|
|
goto retry; /* try again with metamethod */ |
|
|
|
return luaD_precall(L, func, nresults); /* try again with metamethod */ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|