aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-09-21 09:09:52 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-09-21 09:09:52 -0300
commita650378822f48e81978e626329bbd96373035eb2 (patch)
tree67a2595d55e90b0c13db752f70d19b3731e90566 /lapi.c
parent99182c6872f173e8e91426a0dba1468769818681 (diff)
downloadlua-a650378822f48e81978e626329bbd96373035eb2.tar.gz
lua-a650378822f48e81978e626329bbd96373035eb2.tar.bz2
lua-a650378822f48e81978e626329bbd96373035eb2.zip
'cpcall' reimplemented as a predefined value in the registry
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c44
1 files changed, 9 insertions, 35 deletions
diff --git a/lapi.c b/lapi.c
index bf3386c4..c727cd6c 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.89 2009/08/31 14:26:28 roberto Exp roberto $ 2** $Id: lapi.c,v 2.90 2009/09/17 18:04:21 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*/
@@ -854,40 +854,6 @@ LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,
854} 854}
855 855
856 856
857/*
858** Execute a protected C call.
859*/
860struct CCallS { /* data to `f_Ccall' */
861 lua_CFunction func;
862 void *ud;
863};
864
865
866static void f_Ccall (lua_State *L, void *ud) {
867 struct CCallS *c = cast(struct CCallS *, ud);
868 Closure *cl;
869 cl = luaF_newCclosure(L, 0, getcurrenv(L));
870 cl->c.f = c->func;
871 setclvalue(L, L->top, cl); /* push function */
872 api_incr_top(L);
873 setpvalue(L->top, c->ud); /* push only argument */
874 api_incr_top(L);
875 luaD_call(L, L->top - 2, 0, 0);
876}
877
878
879LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) {
880 struct CCallS c;
881 int status;
882 lua_lock(L);
883 c.func = func;
884 c.ud = ud;
885 status = luaD_pcall(L, f_Ccall, &c, savestack(L, L->top), 0);
886 lua_unlock(L);
887 return status;
888}
889
890
891LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, 857LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
892 const char *chunkname) { 858 const char *chunkname) {
893 ZIO z; 859 ZIO z;
@@ -1113,3 +1079,11 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
1113 return name; 1079 return name;
1114} 1080}
1115 1081
1082
1083LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) {
1084 lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_CPCALL);
1085 lua_pushlightuserdata(L, &func);
1086 lua_pushlightuserdata(L, ud);
1087 return lua_pcall(L, 2, 0, 0);
1088}
1089