From db18560dbfa3a102404a982f1d5364fdde62393a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20F=C3=BCndgens?= Date: Fri, 6 Mar 2015 13:18:55 +0100 Subject: [PATCH] Added an errorcheck when loading lua files. --- trigger.cc | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/trigger.cc b/trigger.cc index ee66fbe..56cf321 100644 --- a/trigger.cc +++ b/trigger.cc @@ -27,22 +27,30 @@ Trigger::~Trigger(){ } void Trigger::triggerUpdate(){ - if (isBigger && (glm::distance(object->getPosition(), position) > distance)) { - luaL_dofile(luaState, luaScript.c_str()); - if (undo){ - luabridge::getGlobal(luaState, "triggerUndo")(objectToChange); - }else{ - luabridge::getGlobal(luaState, "trigger")(objectToChange); - } + if (isBigger && (glm::distance(object->getPosition(), position) > distance)) { + int error = luaL_dofile(luaState, luaScript.c_str()); + if (error != 0) { + std::cout << "Couldn't load file: " << this->luaScript << std::endl; + exit(-1); } - else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) { - luaL_dofile(luaState, luaScript.c_str()); - if (undo){ - luabridge::getGlobal(luaState, "triggerUndo")(objectToChange); - }else{ - luabridge::getGlobal(luaState, "trigger")(objectToChange); - } + if (undo){ + luabridge::getGlobal(luaState, "triggerUndo")(objectToChange); + }else{ + luabridge::getGlobal(luaState, "trigger")(objectToChange); } + } + else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) { + int error = luaL_dofile(luaState, luaScript.c_str()); + if (error != 0) { + std::cout << "Couldn't load file: " << this->luaScript << std::endl; + exit(-1); + } + if (undo){ + luabridge::getGlobal(luaState, "triggerUndo")(objectToChange); + }else{ + luabridge::getGlobal(luaState, "trigger")(objectToChange); + } + } } bool Trigger::deleteNotification(int deletedObjectIndex){