diff options
Diffstat (limited to 'lib/BLua.cc')
-rw-r--r-- | lib/BLua.cc | 23 |
1 files changed, 21 insertions, 2 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(); |