bool Event::checkScript(const std::string& basePath, const std::string& scriptsName, const std::string& scriptFile) const { LuaScriptInterface* testInterface = g_luaEnvironment.getTestInterface(); testInterface->reInitState(); if (testInterface->loadFile(std::string(basePath + "lib/" + scriptsName + ".lua")) == -1) { std::cout << "[Warning - Event::checkScript] Can not load " << scriptsName << " lib/" << scriptsName << ".lua" << std::endl; } if (m_scriptId != 0) { std::cout << "[Failure - Event::checkScript] scriptid = " << m_scriptId << std::endl; return false; } if (testInterface->loadFile(basePath + scriptFile) == -1) { std::cout << "[Warning - Event::checkScript] Can not load script: " << scriptFile << std::endl; std::cout << testInterface->getLastLuaError() << std::endl; return false; } int32_t id = testInterface->getEvent(getScriptEventName()); if (id == -1) { std::cout << "[Warning - Event::checkScript] Event " << getScriptEventName() << " not found. " << scriptFile << std::endl; return false; } return true; }
bool Event::checkScript(const std::string& datadir, const std::string& scriptsName, const std::string& scriptFile) { LuaScriptInterface testInterface("Test Interface"); testInterface.initState(); if(testInterface.loadFile(std::string(datadir + scriptsName + "/lib/" + scriptsName + ".lua")) == -1){ std::cout << "Warning: [Event::checkScript] Can not load " << scriptsName << " lib/" << scriptsName << ".lua" << std::endl; } if(m_scriptId != 0){ std::cout << "Failure: [Event::checkScript] scriptid = " << m_scriptId << std::endl; return false; } if(testInterface.loadFile(datadir + scriptsName + scriptFile) == -1){ std::cout << "Warning: [Event::checkScript] Can not load script. " << scriptFile << std::endl; std::cout << testInterface.getLastLuaError() << std::endl; return false; } int32_t id = testInterface.getEvent(getScriptEventName()); if(id == -1){ std::cout << "Warning: [Event::checkScript] Event " << getScriptEventName() << " not found. " << scriptFile << std::endl; return false; } return true; }
bool Event::loadScript(const std::string& script, bool file) { if(!m_interface || m_scriptId != 0) { LOGe("[Event::loadScript] m_interface == nullptr, scriptId = " << m_scriptId); return false; } bool result = false; if(!file) { std::string buffer = script, function = "function " + getScriptEventName(); trimString(buffer); if(buffer.find(function) == std::string::npos) { std::stringstream scriptstream; scriptstream << function << "(" << getScriptEventParams() << ")" << std::endl << buffer << std::endl << "end"; buffer = scriptstream.str(); } result = m_interface->loadBuffer(buffer); } else result = m_interface->loadFile(script); if(!result) { LOGe("[Event::loadScript] Cannot load script (" << script << "): " << m_interface->getLastError()); return false; } int32_t id = m_interface->getEvent(getScriptEventName()); if(id == -1) { LOGe("[Event::loadScript] Event " << getScriptEventName() << " not found (" << script << ")"); return false; } m_scripted = EVENT_SCRIPT_TRUE; m_scriptId = id; return true; }
bool Event::loadScript(const std::string& scriptFile) { if(!m_scriptInterface || m_scriptId != 0){ std::cout << "Failure: [Event::loadScript] m_scriptInterface == NULL. scriptid = " << m_scriptId << std::endl; return false; } if(m_scriptInterface->loadFile(scriptFile) == -1){ std::cout << "Warning: [Event::loadScript] Can not load script. " << scriptFile << std::endl; std::cout << m_scriptInterface->getLastLuaError() << std::endl; return false; } int32_t id = m_scriptInterface->getEvent(getScriptEventName()); if(id == -1){ std::cout << "Warning: [Event::loadScript] Event " << getScriptEventName() << " not found. " << scriptFile << std::endl; return false; } m_scripted = true; m_scriptId = id; return true; }