new function 'luaL_cpcall'

This commit is contained in:
Roberto Ierusalimschy
2010-01-21 14:49:21 -02:00
parent 01586d539e
commit 4f5f2fe367
5 changed files with 25 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.195 2009/12/17 16:20:01 roberto Exp roberto $
** $Id: lauxlib.c,v 1.196 2009/12/22 15:32:50 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -773,3 +773,14 @@ LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver) {
ver, *v);
}
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_CPCALL);
lua_insert(L, -nargs);
lua_pushlightuserdata(L, &f);
lua_insert(L, -nargs);
return lua_pcall(L, nargs, nresults, 0);
}