Browse Source

Removed goto's in 'luaD_precall'

(plus a detail in lauxlib.h.)
pull/27/head
Roberto Ierusalimschy 3 years ago
parent
commit
3699446aaf
  1. 2
      lauxlib.h
  2. 39
      ldo.c

2
lauxlib.h

@ -102,7 +102,7 @@ LUALIB_API lua_State *(luaL_newstate) (void);
LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);
LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s,
LUALIB_API void (luaL_addgsub) (luaL_Buffer *b, const char *s,
const char *p, const char *r);
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s,
const char *p, const char *r);

39
ldo.c

@ -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 */
@ -544,7 +531,23 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
api_checknelems(L, n);
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 */
}
}
}

Loading…
Cancel
Save