From 4710572bf3f2fb202d0cb3dda95ef28c85ea1b81 Mon Sep 17 00:00:00 2001 From: pixel Date: Mon, 27 Dec 2004 22:18:52 +0000 Subject: adding C-closure wrapping to lua, and using it. --- lib/lua/include/lua.h | 5 ++++- lib/lua/includes/lstate.h | 3 ++- lib/lua/src/ldebug.c | 12 +++++++++++- lib/lua/src/ldo.c | 8 ++++++-- lib/lua/src/lstate.c | 3 ++- 5 files changed, 25 insertions(+), 6 deletions(-) (limited to 'lib/lua') diff --git a/lib/lua/include/lua.h b/lib/lua/include/lua.h index 2540709..10496ec 100644 --- a/lib/lua/include/lua.h +++ b/lib/lua/include/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.7 2004-12-27 19:52:23 pixel Exp $ +** $Id: lua.h,v 1.8 2004-12-27 22:18:52 pixel Exp $ ** Lua - An Extensible Extension Language ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil ** http://www.lua.org mailto:info@lua.org @@ -335,6 +335,7 @@ LUA_API int lua_pushupvalues (lua_State *L); typedef struct lua_Debug lua_Debug; /* activation record */ typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); +typedef int (*lua_CallWrap) (lua_State *L, lua_CFunction func); LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); @@ -349,6 +350,8 @@ LUA_API lua_Hook lua_gethook (lua_State *L); LUA_API int lua_gethookmask (lua_State *L); LUA_API int lua_gethookcount (lua_State *L); +LUA_API lua_CallWrap lua_setcallwrap (lua_State *L, lua_CallWrap func); + #define LUA_IDSIZE 60 diff --git a/lib/lua/includes/lstate.h b/lib/lua/includes/lstate.h index dec40f5..8df9844 100644 --- a/lib/lua/includes/lstate.h +++ b/lib/lua/includes/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 1.5 2004-11-27 21:46:06 pixel Exp $ +** $Id: lstate.h,v 1.6 2004-12-27 22:18:53 pixel Exp $ ** Global State ** See Copyright Notice in lua.h */ @@ -157,6 +157,7 @@ struct lua_State { GCObject *gclist; struct lua_longjmp *errorJmp; /* current error recover point */ ptrdiff_t errfunc; /* current error handling function (stack index) */ + lua_CallWrap callwrap; }; diff --git a/lib/lua/src/ldebug.c b/lib/lua/src/ldebug.c index 65114c7..b154c1b 100644 --- a/lib/lua/src/ldebug.c +++ b/lib/lua/src/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 1.4 2004-11-27 21:46:07 pixel Exp $ +** $Id: ldebug.c,v 1.5 2004-12-27 22:18:53 pixel Exp $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -91,6 +91,16 @@ LUA_API int lua_gethookcount (lua_State *L) { } +LUA_API lua_CallWrap lua_setcallwrap (lua_State *L, lua_CallWrap func) { + lua_CallWrap old_func; + lua_lock(L); + old_func = L->callwrap; + L->callwrap = func; + lua_unlock(L); + return old_func; +} + + LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { int status; CallInfo *ci; diff --git a/lib/lua/src/ldo.c b/lib/lua/src/ldo.c index 082b9e6..b23f8b1 100644 --- a/lib/lua/src/ldo.c +++ b/lib/lua/src/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 1.7 2004-12-27 19:59:05 pixel Exp $ +** $Id: ldo.c,v 1.8 2004-12-27 22:18:53 pixel Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -257,7 +257,11 @@ StkId luaD_precall (lua_State *L, StkId func) { #ifdef LUA_COMPATUPVALUES lua_pushupvalues(L); #endif - n = (*clvalue(L->base - 1)->c.f)(L); /* do the actual call */ + if (L->callwrap) { + n = L->callwrap(L, clvalue(L->base - 1)->c.f); /* wrap the call */ + } else { + n = (*clvalue(L->base - 1)->c.f)(L); /* do the actual call */ + } lua_lock(L); return L->top - n; } diff --git a/lib/lua/src/lstate.c b/lib/lua/src/lstate.c index ccd6aeb..113a69b 100644 --- a/lib/lua/src/lstate.c +++ b/lib/lua/src/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 1.4 2004-11-27 21:46:07 pixel Exp $ +** $Id: lstate.c,v 1.5 2004-12-27 22:18:53 pixel Exp $ ** Global State ** See Copyright Notice in lua.h */ @@ -137,6 +137,7 @@ static void preinit_state (lua_State *L) { L->nCcalls = 0; L->base_ci = L->ci = NULL; L->errfunc = 0; + L->callwrap = 0; setnilvalue(gt(L)); } -- cgit v1.2.3