Added error handling in wren. Game while abort lauching and print error in logger
This commit is contained in:
@@ -23,13 +23,13 @@ void errorFn(WrenVM* vm, WrenErrorType errorType,
|
||||
{
|
||||
case WREN_ERROR_COMPILE:
|
||||
{
|
||||
std::string t = "Script error in: " + std::string(module)+ " line:" + std::to_string(line) + " \n error: "+ msg;
|
||||
std::string t = std::string(module)+ " line " + std::to_string(line) + ": "+ msg;
|
||||
Logger::Log(t, CRITICAL);
|
||||
Engine::ExitPlayMode();
|
||||
} break;
|
||||
case WREN_ERROR_STACK_TRACE:
|
||||
{
|
||||
std::string t = "Script Stack trace: " + std::string(module) + " line:" + std::to_string(line) + " \n stack: " + msg;
|
||||
std::string t = "Stack trace: " + std::string(module) + " line " + std::to_string(line) + ": " + msg;
|
||||
Logger::Log(t, CRITICAL);
|
||||
} break;
|
||||
case WREN_ERROR_RUNTIME:
|
||||
|
||||
@@ -9,8 +9,15 @@ WrenScript::WrenScript(const std::string& path, const std::string& mod, bool isE
|
||||
// Import statement
|
||||
std::string source = "import \"" + path + "\" for " + mod;
|
||||
|
||||
CompiledSuccesfully = true;
|
||||
|
||||
// Import file as module
|
||||
wrenInterpret(vm, "main", source.c_str());
|
||||
WrenInterpretResult result = wrenInterpret(vm, "main", source.c_str());
|
||||
if (result != WREN_RESULT_SUCCESS)
|
||||
CompiledSuccesfully = false;
|
||||
|
||||
if (!CompiledSuccesfully)
|
||||
return;
|
||||
|
||||
// Get handle to class
|
||||
wrenEnsureSlots(vm, 1);
|
||||
@@ -61,6 +68,9 @@ void WrenScript::CallFixedUpdate(float timestep)
|
||||
|
||||
void WrenScript::CallExit()
|
||||
{
|
||||
if (!CompiledSuccesfully)
|
||||
return;
|
||||
|
||||
WrenVM* vm = ScriptingEngine::GetWrenVM();
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenSetSlotHandle(vm, 0, this->m_Instance);
|
||||
|
||||
@@ -15,6 +15,8 @@ public:
|
||||
WrenHandle* m_OnExitHandle;
|
||||
WrenHandle* m_SetEntityIDHandle;
|
||||
|
||||
bool CompiledSuccesfully;
|
||||
|
||||
WrenScript(const std::string& path, const std::string& mod, bool isEntity = false);
|
||||
|
||||
void CallInit();
|
||||
|
||||
Reference in New Issue
Block a user