mirror of
https://github.com/fortressforever/fortressforever-2013.git
synced 2025-02-15 16:41:19 +00:00
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
This commit is contained in:
parent
65d28cc2e0
commit
04397c4005
1 changed files with 45 additions and 5 deletions
|
@ -48,18 +48,34 @@ void CFF_CL_LuaUI_BasePanel::Init()
|
||||||
Reset();
|
Reset();
|
||||||
|
|
||||||
if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["Init"] ) == LUA_TFUNCTION )
|
if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["Init"] ) == LUA_TFUNCTION )
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
luabind::call_function<void>( m_LuaObject["Init"], this );
|
luabind::call_function<void>( m_LuaObject["Init"], this );
|
||||||
}
|
}
|
||||||
|
catch( error& e )
|
||||||
|
{
|
||||||
|
object error_msg(from_stack(e.state(), -1));
|
||||||
|
g_UIScriptManager.LuaWarning( luabind::object_cast<const char*>( error_msg ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// from CHudElement
|
/// from CHudElement
|
||||||
void CFF_CL_LuaUI_BasePanel::Reset()
|
void CFF_CL_LuaUI_BasePanel::Reset()
|
||||||
{
|
{
|
||||||
if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["Reset"] ) == LUA_TFUNCTION )
|
if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["Reset"] ) == LUA_TFUNCTION )
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
luabind::call_function<void>( m_LuaObject["Reset"], this );
|
luabind::call_function<void>( m_LuaObject["Reset"], this );
|
||||||
}
|
}
|
||||||
|
catch( error& e )
|
||||||
|
{
|
||||||
|
object error_msg(from_stack(e.state(), -1));
|
||||||
|
g_UIScriptManager.LuaWarning( "%s\n", luabind::object_cast<const char*>( error_msg ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// from CHudElement
|
/// from CHudElement
|
||||||
|
@ -69,7 +85,15 @@ void CFF_CL_LuaUI_BasePanel::VidInit()
|
||||||
|
|
||||||
if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["VidInit"] ) == LUA_TFUNCTION )
|
if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["VidInit"] ) == LUA_TFUNCTION )
|
||||||
{
|
{
|
||||||
luabind::call_function<void>( m_LuaObject["VidInit"], this );
|
try
|
||||||
|
{
|
||||||
|
luabind::call_member<HFont>(m_LuaObject, "VidInit");
|
||||||
|
}
|
||||||
|
catch( error& e )
|
||||||
|
{
|
||||||
|
object error_msg(from_stack(e.state(), -1));
|
||||||
|
g_UIScriptManager.LuaWarning( "%s\n", luabind::object_cast<const char*>( error_msg ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,9 +103,17 @@ void CFF_CL_LuaUI_BasePanel::OnThink()
|
||||||
BaseClass::OnThink();
|
BaseClass::OnThink();
|
||||||
|
|
||||||
if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["OnThink"] ) == LUA_TFUNCTION )
|
if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["OnThink"] ) == LUA_TFUNCTION )
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
luabind::call_function<void>( m_LuaObject["OnThink"], this );
|
luabind::call_function<void>( m_LuaObject["OnThink"], this );
|
||||||
}
|
}
|
||||||
|
catch( error& e )
|
||||||
|
{
|
||||||
|
object error_msg(from_stack(e.state(), -1));
|
||||||
|
g_UIScriptManager.LuaWarning( "%s\n", luabind::object_cast<const char*>( error_msg ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// from vgui::Panel
|
/// from vgui::Panel
|
||||||
|
@ -90,9 +122,17 @@ void CFF_CL_LuaUI_BasePanel::Paint()
|
||||||
BaseClass::Paint();
|
BaseClass::Paint();
|
||||||
|
|
||||||
if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["Paint"] ) == LUA_TFUNCTION )
|
if ( m_LuaObject.is_valid() && luabind::type( m_LuaObject["Paint"] ) == LUA_TFUNCTION )
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
luabind::call_function<void>( m_LuaObject["Paint"], this );
|
luabind::call_function<void>( m_LuaObject["Paint"], this );
|
||||||
}
|
}
|
||||||
|
catch( error& e )
|
||||||
|
{
|
||||||
|
object error_msg(from_stack(e.state(), -1));
|
||||||
|
g_UIScriptManager.LuaWarning( "%s\n", luabind::object_cast<const char*>( error_msg ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Drawtext helper function
|
/// Drawtext helper function
|
||||||
|
|
Loading…
Reference in a new issue