summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lauxlib.c13
-rw-r--r--lauxlib.h5
-rw-r--r--lstate.c20
-rw-r--r--lua.c5
-rw-r--r--lua.h5
5 files changed, 8 insertions, 40 deletions
diff --git a/lauxlib.c b/lauxlib.c
index d255f814..eebdaedd 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.206 2010/03/29 17:44:31 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.207 2010/04/09 16:14:46 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -766,14 +766,3 @@ LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver) {
766 ver, *v); 766 ver, *v);
767} 767}
768 768
769
770LUALIB_API int luaL_cpcall (lua_State *L, lua_CFunction f, int nargs,
771 int nresults) {
772 nargs++; /* to include function itself */
773 lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_CCALL);
774 lua_insert(L, -nargs); /* 'ccall' is real function to be called */
775 lua_pushlightuserdata(L, &f);
776 lua_insert(L, -nargs); /* 'f' address is its first argument */
777 return lua_pcall(L, nargs, nresults, 0);
778}
779
diff --git a/lauxlib.h b/lauxlib.h
index bb5a6d52..3c77392e 100644
--- a/lauxlib.h
+++ b/lauxlib.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.h,v 1.101 2010/03/17 21:37:37 roberto Exp roberto $ 2** $Id: lauxlib.h,v 1.102 2010/04/09 16:14:46 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -82,9 +82,6 @@ LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
82LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1, 82LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
83 const char *msg, int level); 83 const char *msg, int level);
84 84
85LUALIB_API int (luaL_cpcall) (lua_State *L, lua_CFunction f, int nargs,
86 int nresults);
87
88 85
89/* 86/*
90** =============================================================== 87** ===============================================================
diff --git a/lstate.c b/lstate.c
index 6be44a9b..78b776a6 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.78 2010/04/08 17:16:46 roberto Exp roberto $ 2** $Id: lstate.c,v 2.79 2010/04/12 16:07:06 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -114,22 +114,9 @@ static void freestack (lua_State *L) {
114 114
115 115
116/* 116/*
117** Calls the function in variable pointed to by userdata in first argument
118** (Userdata cannot point directly to the function because pointer to
119** function is not compatible with void*.)
120*/
121static int ccall (lua_State *L) {
122 lua_CFunction f = *(lua_CFunction *)lua_touserdata(L, 1);
123 lua_remove(L, 1); /* remove f from stack */
124 return f(L);
125}
126
127
128/*
129** Create registry table and its predefined values 117** Create registry table and its predefined values
130*/ 118*/
131static void init_registry (lua_State *L, global_State *g) { 119static void init_registry (lua_State *L, global_State *g) {
132 Closure *cp;
133 TValue mt; 120 TValue mt;
134 /* create registry */ 121 /* create registry */
135 Table *registry = luaH_new(L); 122 Table *registry = luaH_new(L);
@@ -138,11 +125,6 @@ static void init_registry (lua_State *L, global_State *g) {
138 /* registry[LUA_RIDX_MAINTHREAD] = L */ 125 /* registry[LUA_RIDX_MAINTHREAD] = L */
139 setthvalue(L, &mt, L); 126 setthvalue(L, &mt, L);
140 setobj2t(L, luaH_setint(L, registry, LUA_RIDX_MAINTHREAD), &mt); 127 setobj2t(L, luaH_setint(L, registry, LUA_RIDX_MAINTHREAD), &mt);
141 /* registry[LUA_RIDX_CCALL] = ccall */
142 cp = luaF_newCclosure(L, 0);
143 cp->c.f = ccall;
144 setclvalue(L, &mt, cp);
145 setobj2t(L, luaH_setint(L, registry, LUA_RIDX_CCALL), &mt);
146 /* registry[LUA_RIDX_GLOBALS] = table of globals */ 128 /* registry[LUA_RIDX_GLOBALS] = table of globals */
147 sethvalue(L, &mt, luaH_new(L)); 129 sethvalue(L, &mt, luaH_new(L));
148 setobj2t(L, luaH_setint(L, registry, LUA_RIDX_GLOBALS), &mt); 130 setobj2t(L, luaH_setint(L, registry, LUA_RIDX_GLOBALS), &mt);
diff --git a/lua.c b/lua.c
index ad4e8c28..b2add022 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.188 2010/02/27 21:15:36 roberto Exp roberto $ 2** $Id: lua.c,v 1.189 2010/03/13 03:57:46 roberto Exp roberto $
3** Lua stand-alone interpreter 3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -454,9 +454,10 @@ int main (int argc, char **argv) {
454 return EXIT_FAILURE; 454 return EXIT_FAILURE;
455 } 455 }
456 /* call 'pmain' in protected mode */ 456 /* call 'pmain' in protected mode */
457 lua_pushcfunction(L, &pmain);
457 lua_pushinteger(L, argc); /* 1st argument */ 458 lua_pushinteger(L, argc); /* 1st argument */
458 lua_pushlightuserdata(L, argv); /* 2nd argument */ 459 lua_pushlightuserdata(L, argv); /* 2nd argument */
459 status = luaL_cpcall(L, &pmain, 2, 1); 460 status = lua_pcall(L, 2, 1, 0);
460 result = lua_toboolean(L, -1); /* get result */ 461 result = lua_toboolean(L, -1); /* get result */
461 finalreport(L, status); 462 finalreport(L, status);
462 lua_close(L); 463 lua_close(L);
diff --git a/lua.h b/lua.h
index 1fb67628..ea9d0f17 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.266 2010/04/02 15:19:19 roberto Exp roberto $ 2** $Id: lua.h,v 1.267 2010/04/12 16:04:10 roberto Exp roberto $
3** Lua - A Scripting Language 3** Lua - A Scripting Language
4** Lua.org, PUC-Rio, Brazil (http://www.lua.org) 4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
5** See Copyright Notice at the end of this file 5** 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);
91 91
92/* predefined values in the registry */ 92/* predefined values in the registry */
93#define LUA_RIDX_MAINTHREAD 1 93#define LUA_RIDX_MAINTHREAD 1
94#define LUA_RIDX_CCALL 2 94#define LUA_RIDX_GLOBALS 2
95#define LUA_RIDX_GLOBALS 3
96#define LUA_RIDX_LAST LUA_RIDX_GLOBALS 95#define LUA_RIDX_LAST LUA_RIDX_GLOBALS
97 96
98 97