lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> > This function was not in the work2 manual. Its entry is like this:
> > 
> >   int luaL_cpcall (lua_State *L, lua_CFunction f, int nargs, int nresults);
> > 
> >   Calls a C function in protected mode.
> > 
> >   This function is equivalent to lua_pcall, but it calls the C function
> >   f (instead of a Lua function in the stack) and it does not have an
> >   error handler function.
> 
> That looks good to me.  Is this from a new 5.2-workN version that's
> been released that I missed, or has it only been internal?

I am sorry. I thought it was in work2 bar the manual, but it is not. It
will be in the next version. The manual is as above, the implementation
is here:

LUALIB_API int luaL_cpcall (lua_State *L, lua_CFunction f, int nargs,
                            int nresults) {
  nargs++;  /* to include function itself */
  lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_CCALL);
  lua_insert(L, -nargs);  /* 'ccall' is real function to be called */
  lua_pushlightuserdata(L, &f);
  lua_insert(L, -nargs);  /* 'f' address is its first argument */
  return lua_pcall(L, nargs, nresults, 0);
}

(Note that LUA_RIDX_CPCALL has been renamed.)

-- Roberto