diff options
-rw-r--r-- | lib/BLua.cc | 23 | ||||
-rw-r--r-- | lib/lua/include/lua.h | 5 | ||||
-rw-r--r-- | lib/lua/includes/lstate.h | 3 | ||||
-rw-r--r-- | lib/lua/src/ldebug.c | 12 | ||||
-rw-r--r-- | lib/lua/src/ldo.c | 8 | ||||
-rw-r--r-- | lib/lua/src/lstate.c | 3 |
6 files changed, 46 insertions, 8 deletions
diff --git a/lib/BLua.cc b/lib/BLua.cc index 335da3d..8f5e3ca 100644 --- a/lib/BLua.cc +++ b/lib/BLua.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: BLua.cc,v 1.26 2004-12-27 18:50:55 pixel Exp $ */ +/* $Id: BLua.cc,v 1.27 2004-12-27 22:18:52 pixel Exp $ */ #include "BLua.h" #include <lualib.h> @@ -55,6 +55,7 @@ class LuaStatics : public Base { static int luapanic(lua_State *); static int trueluapanic(lua_State *) throw(GeneralException); static int luaerror(lua_State *); + static int callwrap(lua_State *, lua_CFunction); static int collector(lua_State *); static int destructor(lua_State *); @@ -218,6 +219,7 @@ int LuaStatics::hex(lua_State * _L) { Lua::Lua() : L(lua_open()) { lualist[L] = this; lua_atpanic(L, LuaStatics::luapanic); + lua_setcallwrap(L, LuaStatics::callwrap); declarefunc("andB", LuaStatics::andB); declarefunc("orB", LuaStatics::orB); @@ -229,8 +231,8 @@ Lua::Lua() : L(lua_open()) { } Lua::Lua(lua_State * _L) : L(_L), _protected(false) { - lua_atpanic(L, LuaStatics::luapanic); lualist[L] = this; + lua_atpanic(L, LuaStatics::luapanic); } Lua::~Lua() { @@ -680,6 +682,23 @@ void LuaObject::pushmeta(Lua * L, const String & s, lua_CFunction f) { L->setmetatable(); } +int LuaStatics::callwrap(lua_State * _L, lua_CFunction func) { + Lua * L = Lua::find(_L); + int n; + + try { + n = func(_L); + } + catch (LuaException e) { + L->error(String("LuaException: ") + e.GetMsg()); + } + catch (GeneralException e) { + L->error(String("GeneralException: ") + e.GetMsg()); + } + + return n; +} + int LuaStatics::collector(lua_State * _L) { Lua * L = Lua::find(_L); void ** u = (void **) L->touserdata(); 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)); } |