From 04397c400510223f2c3a1522a22e9b1fd2997b88 Mon Sep 17 00:00:00 2001 From: squeek Date: Sat, 9 Nov 2013 05:58:58 +0000 Subject: [PATCH] A bad but effective way to catch Luabind execution errors when calling Lua functions from C++; still need to formalize a standard method of doing so --- .../client/ff/ui/ff_cl_luaui_basepanel.cpp | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/mp/src/game/client/ff/ui/ff_cl_luaui_basepanel.cpp b/mp/src/game/client/ff/ui/ff_cl_luaui_basepanel.cpp index f2167e0a..ab76bcec 100644 --- a/mp/src/game/client/ff/ui/ff_cl_luaui_basepanel.cpp +++ b/mp/src/game/client/ff/ui/ff_cl_luaui_basepanel.cpp @@ -49,7 +49,15 @@ void CFF_CL_LuaUI_BasePanel::Init() if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["Init"] ) == LUA_TFUNCTION ) { - luabind::call_function( m_LuaObject["Init"], this ); + try + { + luabind::call_function( m_LuaObject["Init"], this ); + } + catch( error& e ) + { + object error_msg(from_stack(e.state(), -1)); + g_UIScriptManager.LuaWarning( luabind::object_cast( error_msg ) ); + } } } @@ -58,7 +66,15 @@ void CFF_CL_LuaUI_BasePanel::Reset() { if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["Reset"] ) == LUA_TFUNCTION ) { - luabind::call_function( m_LuaObject["Reset"], this ); + try + { + luabind::call_function( m_LuaObject["Reset"], this ); + } + catch( error& e ) + { + object error_msg(from_stack(e.state(), -1)); + g_UIScriptManager.LuaWarning( "%s\n", luabind::object_cast( error_msg ) ); + } } } @@ -69,7 +85,15 @@ void CFF_CL_LuaUI_BasePanel::VidInit() if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["VidInit"] ) == LUA_TFUNCTION ) { - luabind::call_function( m_LuaObject["VidInit"], this ); + try + { + luabind::call_member(m_LuaObject, "VidInit"); + } + catch( error& e ) + { + object error_msg(from_stack(e.state(), -1)); + g_UIScriptManager.LuaWarning( "%s\n", luabind::object_cast( error_msg ) ); + } } } @@ -80,7 +104,15 @@ void CFF_CL_LuaUI_BasePanel::OnThink() if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["OnThink"] ) == LUA_TFUNCTION ) { - luabind::call_function( m_LuaObject["OnThink"], this ); + try + { + luabind::call_function( m_LuaObject["OnThink"], this ); + } + catch( error& e ) + { + object error_msg(from_stack(e.state(), -1)); + g_UIScriptManager.LuaWarning( "%s\n", luabind::object_cast( error_msg ) ); + } } } @@ -91,7 +123,15 @@ void CFF_CL_LuaUI_BasePanel::Paint() if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["Paint"] ) == LUA_TFUNCTION ) { - luabind::call_function( m_LuaObject["Paint"], this ); + try + { + luabind::call_function( m_LuaObject["Paint"], this ); + } + catch( error& e ) + { + object error_msg(from_stack(e.state(), -1)); + g_UIScriptManager.LuaWarning( "%s\n", luabind::object_cast( error_msg ) ); + } } }