mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-10 20:46:47 +03:00
Add doCallback function to throw an exception if one of the callback encounters an error (and if WarningsAsErrors is on).
This commit is contained in:
parent
0d082bea8b
commit
474cf41a7d
1 changed files with 15 additions and 6 deletions
|
@ -389,30 +389,39 @@ void LuaVariables::SetVariable(std::string key, sol::object value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void doCallback(sol::protected_function const & func) {
|
||||||
|
auto r = func();
|
||||||
|
if (WarningsAsErrors && !r.valid())
|
||||||
|
{
|
||||||
|
sol::error err = r;
|
||||||
|
std::cerr << "An error occurred: " << err.what() << "\n";
|
||||||
|
throw std::runtime_error(err.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GameScript::OnStart()
|
void GameScript::OnStart()
|
||||||
{
|
{
|
||||||
m_onStart();
|
doCallback(m_onStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScript::OnLoad()
|
void GameScript::OnLoad()
|
||||||
{
|
{
|
||||||
m_onLoad();
|
doCallback(m_onLoad);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScript::OnControlPhase()
|
void GameScript::OnControlPhase()
|
||||||
{
|
{
|
||||||
m_onControlPhase();
|
doCallback(m_onControlPhase);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScript::OnSave()
|
void GameScript::OnSave()
|
||||||
{
|
{
|
||||||
m_onSave();
|
doCallback(m_onSave);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScript::OnEnd()
|
void GameScript::OnEnd()
|
||||||
{
|
{
|
||||||
m_onEnd();
|
doCallback(m_onEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScript::InitCallbacks()
|
void GameScript::InitCallbacks()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue