1
0
mirror of https://github.com/lua/lua.git synced 2025-01-28 06:03:00 +08:00

no more 'ccall' nor 'cpcall' functions. (With light C functions they

are obsolete.)
This commit is contained in:
Roberto Ierusalimschy 2010-04-14 12:14:21 -03:00
parent 7dfa4cd655
commit afdb19ac82
5 changed files with 8 additions and 40 deletions

View File

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.206 2010/03/29 17:44:31 roberto Exp roberto $
** $Id: lauxlib.c,v 1.207 2010/04/09 16:14:46 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -766,14 +766,3 @@ 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_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);
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.h,v 1.101 2010/03/17 21:37:37 roberto Exp roberto $
** $Id: lauxlib.h,v 1.102 2010/04/09 16:14:46 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -82,9 +82,6 @@ LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
const char *msg, int level);
LUALIB_API int (luaL_cpcall) (lua_State *L, lua_CFunction f, int nargs,
int nresults);
/*
** ===============================================================

View File

@ -1,5 +1,5 @@
/*
** $Id: lstate.c,v 2.78 2010/04/08 17:16:46 roberto Exp roberto $
** $Id: lstate.c,v 2.79 2010/04/12 16:07:06 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@ -113,23 +113,10 @@ static void freestack (lua_State *L) {
}
/*
** Calls the function in variable pointed to by userdata in first argument
** (Userdata cannot point directly to the function because pointer to
** function is not compatible with void*.)
*/
static int ccall (lua_State *L) {
lua_CFunction f = *(lua_CFunction *)lua_touserdata(L, 1);
lua_remove(L, 1); /* remove f from stack */
return f(L);
}
/*
** Create registry table and its predefined values
*/
static void init_registry (lua_State *L, global_State *g) {
Closure *cp;
TValue mt;
/* create registry */
Table *registry = luaH_new(L);
@ -138,11 +125,6 @@ static void init_registry (lua_State *L, global_State *g) {
/* registry[LUA_RIDX_MAINTHREAD] = L */
setthvalue(L, &mt, L);
setobj2t(L, luaH_setint(L, registry, LUA_RIDX_MAINTHREAD), &mt);
/* registry[LUA_RIDX_CCALL] = ccall */
cp = luaF_newCclosure(L, 0);
cp->c.f = ccall;
setclvalue(L, &mt, cp);
setobj2t(L, luaH_setint(L, registry, LUA_RIDX_CCALL), &mt);
/* registry[LUA_RIDX_GLOBALS] = table of globals */
sethvalue(L, &mt, luaH_new(L));
setobj2t(L, luaH_setint(L, registry, LUA_RIDX_GLOBALS), &mt);

5
lua.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.c,v 1.188 2010/02/27 21:15:36 roberto Exp roberto $
** $Id: lua.c,v 1.189 2010/03/13 03:57:46 roberto Exp roberto $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
*/
@ -454,9 +454,10 @@ int main (int argc, char **argv) {
return EXIT_FAILURE;
}
/* call 'pmain' in protected mode */
lua_pushcfunction(L, &pmain);
lua_pushinteger(L, argc); /* 1st argument */
lua_pushlightuserdata(L, argv); /* 2nd argument */
status = luaL_cpcall(L, &pmain, 2, 1);
status = lua_pcall(L, 2, 1, 0);
result = lua_toboolean(L, -1); /* get result */
finalreport(L, status);
lua_close(L);

5
lua.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.266 2010/04/02 15:19:19 roberto Exp roberto $
** $Id: lua.h,v 1.267 2010/04/12 16:04:10 roberto Exp roberto $
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
@ -91,8 +91,7 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
/* predefined values in the registry */
#define LUA_RIDX_MAINTHREAD 1
#define LUA_RIDX_CCALL 2
#define LUA_RIDX_GLOBALS 3
#define LUA_RIDX_GLOBALS 2
#define LUA_RIDX_LAST LUA_RIDX_GLOBALS