aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c11
-rw-r--r--lauxlib.c13
-rw-r--r--lauxlib.h4
-rw-r--r--lua.c11
-rw-r--r--luaconf.h9
5 files changed, 25 insertions, 23 deletions
diff --git a/lapi.c b/lapi.c
index c9b30ace..8b229d7b 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.110 2010/01/11 17:38:30 roberto Exp roberto $ 2** $Id: lapi.c,v 2.111 2010/01/13 16:18:25 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -1150,12 +1150,3 @@ LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1,
1150 luaC_objbarrier(L, f1, *up2); 1150 luaC_objbarrier(L, f1, *up2);
1151} 1151}
1152 1152
1153
1154#if defined(LUA_COMPAT_CPCALL)
1155LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) {
1156 lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_CPCALL);
1157 lua_pushlightuserdata(L, &func);
1158 lua_pushlightuserdata(L, ud);
1159 return lua_pcall(L, 2, 0, 0);
1160}
1161#endif
diff --git a/lauxlib.c b/lauxlib.c
index 2eaa163b..0e449ac3 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.195 2009/12/17 16:20:01 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.196 2009/12/22 15:32:50 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*/
@@ -773,3 +773,14 @@ LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver) {
773 ver, *v); 773 ver, *v);
774} 774}
775 775
776
777LUALIB_API int luaL_cpcall (lua_State *L, lua_CFunction f, int nargs,
778 int nresults) {
779 nargs++; /* to include function itself */
780 lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_CPCALL);
781 lua_insert(L, -nargs);
782 lua_pushlightuserdata(L, &f);
783 lua_insert(L, -nargs);
784 return lua_pcall(L, nargs, nresults, 0);
785}
786
diff --git a/lauxlib.h b/lauxlib.h
index e7cf8c7a..fa293c64 100644
--- a/lauxlib.h
+++ b/lauxlib.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.h,v 1.98 2010/01/06 15:14:15 roberto Exp roberto $ 2** $Id: lauxlib.h,v 1.99 2010/01/11 16:00:45 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,6 +82,8 @@ 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);
85 87
86 88
87/* 89/*
diff --git a/lua.c b/lua.c
index 9e83025a..cec63efe 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.182 2009/12/22 16:47:12 roberto Exp roberto $ 2** $Id: lua.c,v 1.183 2010/01/21 16:31:06 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*/
@@ -445,7 +445,6 @@ static int pmain (lua_State *L) {
445 445
446 446
447int main (int argc, char **argv) { 447int main (int argc, char **argv) {
448 static lua_CFunction ppmain = &pmain;
449 int status, result; 448 int status, result;
450 lua_State *L = luaL_newstate(); /* create state */ 449 lua_State *L = luaL_newstate(); /* create state */
451 if (L == NULL) { 450 if (L == NULL) {
@@ -453,11 +452,9 @@ int main (int argc, char **argv) {
453 return EXIT_FAILURE; 452 return EXIT_FAILURE;
454 } 453 }
455 /* call 'pmain' in protected mode */ 454 /* call 'pmain' in protected mode */
456 lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_CPCALL); /* calling function */ 455 lua_pushinteger(L, argc); /* 1st argument */
457 lua_pushlightuserdata(L, &ppmain); 456 lua_pushlightuserdata(L, argv); /* 2nd argument */
458 lua_pushinteger(L, argc); 457 status = luaL_cpcall(L, &pmain, 2, 1);
459 lua_pushlightuserdata(L, argv);
460 status = lua_pcall(L, 3, 1, 0);
461 result = lua_toboolean(L, -1); /* get result */ 458 result = lua_toboolean(L, -1); /* get result */
462 finalreport(L, status); 459 finalreport(L, status);
463 lua_close(L); 460 lua_close(L);
diff --git a/luaconf.h b/luaconf.h
index 9326c03e..293f70ac 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: luaconf.h,v 1.130 2010/01/11 17:15:30 roberto Exp roberto $ 2** $Id: luaconf.h,v 1.131 2010/01/21 16:31:24 roberto Exp roberto $
3** Configuration file for Lua 3** Configuration file for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -220,11 +220,11 @@
220#define LUA_COMPAT_UNPACK 220#define LUA_COMPAT_UNPACK
221 221
222/* 222/*
223@@ LUA_COMPAT_CPCALL controls the presence of function 'lua_cpcall'. 223@@ LUA_COMPAT_CPCALL controls the presence of macro 'lua_cpcall'.
224** You can replace it with the preregistered function 'cpcall'. 224** You can replace it with the preregistered function 'cpcall'.
225*/ 225*/
226#define LUA_COMPAT_CPCALL 226#define lua_cpcall(L,f,u) \
227LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); 227 (lua_pushlightuserdata(L,(u)), luaL_cpcall(L,(f),1,0))
228 228
229/* 229/*
230@@ LUA_COMPAT_FENV controls the presence of functions 'setfenv/getfenv'. 230@@ LUA_COMPAT_FENV controls the presence of functions 'setfenv/getfenv'.
@@ -233,6 +233,7 @@ LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
233*/ 233*/
234#define LUA_COMPAT_FENV 234#define LUA_COMPAT_FENV
235 235
236
236/* 237/*
237@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library. 238@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.
238** You can rewrite 'log10(x)' as 'log(x, 10)'. 239** You can rewrite 'log10(x)' as 'log(x, 10)'.