mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-30 08:47:58 +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
d328a7f36c
commit
4e09dc1d1d
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()
|
||||
{
|
||||
m_onStart();
|
||||
doCallback(m_onStart);
|
||||
}
|
||||
|
||||
void GameScript::OnLoad()
|
||||
{
|
||||
m_onLoad();
|
||||
doCallback(m_onLoad);
|
||||
}
|
||||
|
||||
void GameScript::OnControlPhase()
|
||||
{
|
||||
m_onControlPhase();
|
||||
doCallback(m_onControlPhase);
|
||||
}
|
||||
|
||||
void GameScript::OnSave()
|
||||
{
|
||||
m_onSave();
|
||||
|
||||
doCallback(m_onSave);
|
||||
}
|
||||
|
||||
void GameScript::OnEnd()
|
||||
{
|
||||
m_onEnd();
|
||||
doCallback(m_onEnd);
|
||||
}
|
||||
|
||||
void GameScript::InitCallbacks()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue