Skip to content

Commit

Permalink
Replaced try-catch logic for error in script
Browse files Browse the repository at this point in the history
  • Loading branch information
Mormert committed Jul 19, 2023
1 parent 9598cd3 commit 1468e13
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions engine/jleLuaScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,31 +111,33 @@ jleLuaScript::loadScript()
try {
lua.script(_sourceCode);

lua.collect_garbage();

auto setup = lua[_luaScriptName]["setup"];
auto start = lua[_luaScriptName]["start"];
auto update = lua[_luaScriptName]["update"];
auto onDestroy = lua[_luaScriptName]["onDestroy"];

if (!setup.valid() || !setup.is<sol::function>()) {
std::string err = "Expected " + _luaScriptName + ".setup function was not found!";
throw std::exception(err.c_str());
LOGE << "Expected " + _luaScriptName + ".setup function was not found!";
faultyState = true;
return;
}

if (!start.valid() || !start.is<sol::function>()) {
std::string err = "Expected " + _luaScriptName + ".start function was not found!";
throw std::exception(err.c_str());
LOGE << "Expected " + _luaScriptName + ".start function was not found!";
faultyState = true;
return;
}

if (!update.valid() || !update.is<sol::function>()) {
std::string err = "Expected " + _luaScriptName + ".update function was not found!";
throw std::exception(err.c_str());
LOGE << "Expected " + _luaScriptName + ".update function was not found!";
faultyState = true;
return;
}

if (!onDestroy.valid() || !onDestroy.is<sol::function>()) {
std::string err = "Expected " + _luaScriptName + ".onDestroy function was not found!";
throw std::exception(err.c_str());
LOGE << "Expected " + _luaScriptName + ".onDestroy function was not found!";
faultyState = true;
return;
}

_setupLua = setup;
Expand Down

0 comments on commit 1468e13

Please sign in to comment.