From 8d16611e9a9110b8be41bc0af72da1fb8cfaf873 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 11 Jun 2018 16:33:32 +0200 Subject: [PATCH] Adapt to new Ghoul change with luaError --- ext/ghoul | 2 +- .../base/rendering/screenspacedashboard.cpp | 18 +++++++++++------- .../globebrowsing/globebrowsingmodule_lua.inl | 18 +++++++++--------- modules/iswa/util/iswamanager_lua.inl | 4 +++- src/engine/moduleengine_lua.inl | 2 +- src/engine/openspaceengine_lua.inl | 18 +++++++++++------- src/interaction/keybindingmanager_lua.inl | 8 ++++---- src/interaction/navigationhandler_lua.inl | 9 ++++++--- src/mission/missionmanager_lua.inl | 10 +++++----- src/rendering/dashboard_lua.inl | 2 +- src/rendering/renderengine_lua.inl | 2 +- src/scene/assetloader.cpp | 5 ++++- src/scene/scene_lua.inl | 16 +++++++++------- src/scripting/scriptscheduler_lua.inl | 2 +- src/util/spicemanager_lua.inl | 5 ++++- src/util/time_lua.inl | 8 ++++---- 16 files changed, 75 insertions(+), 54 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index 23de750662..debf58989c 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 23de7506623dea89daf8c282a5bb4d4cd776282a +Subproject commit debf58989c5ba0c36341d4bb64b945fb90db4dcd diff --git a/modules/base/rendering/screenspacedashboard.cpp b/modules/base/rendering/screenspacedashboard.cpp index 8ef9a82904..04d29a44e8 100644 --- a/modules/base/rendering/screenspacedashboard.cpp +++ b/modules/base/rendering/screenspacedashboard.cpp @@ -58,7 +58,7 @@ int addDashboardItemToScreenSpace(lua_State* L) { const std::string& name = ghoul::lua::value(L, 1); const int type = lua_type(L, 2); if (type != LUA_TTABLE) { - return luaL_error(L, "Expected argument of type 'table'"); // NOLINT + return ghoul::lua::luaError(L, "Expected argument of type 'table'"); } ghoul::Dictionary d; @@ -73,13 +73,15 @@ int addDashboardItemToScreenSpace(lua_State* L) { ScreenSpaceRenderable* ssr = OsEng.renderEngine().screenSpaceRenderable(name); if (!ssr) { - return luaL_error(L, "Provided name is not a ScreenSpace item"); // NOLINT + return ghoul::lua::luaError(L, "Provided name is not a ScreenSpace item"); } ScreenSpaceDashboard* dash = dynamic_cast(ssr); if (!dash) { - // NOLINTNEXTLINE - return luaL_error(L, "Provided name is a ScreenSpace item but not a dashboard"); + return ghoul::lua::luaError( + L, + "Provided name is a ScreenSpace item but not a dashboard" + ); } dash->dashboard().addDashboardItem(DashboardItem::createFromDictionary(d)); @@ -99,13 +101,15 @@ int removeDashboardItemsFromScreenSpace(lua_State* L) { ScreenSpaceRenderable* ssr = OsEng.renderEngine().screenSpaceRenderable(name); if (!ssr) { - return luaL_error(L, "Provided name is not a ScreenSpace item"); // NOLINT + return ghoul::lua::luaError(L, "Provided name is not a ScreenSpace item"); } ScreenSpaceDashboard* dash = dynamic_cast(ssr); if (!dash) { - // NOLINTNEXTLINE - return luaL_error(L, "Provided name is a ScreenSpace item but not a dashboard"); + return ghoul::lua::luaError( + L, + "Provided name is a ScreenSpace item but not a dashboard" + ); } dash->dashboard().clearDashboardItems(); diff --git a/modules/globebrowsing/globebrowsingmodule_lua.inl b/modules/globebrowsing/globebrowsingmodule_lua.inl index d132abc93a..d852355160 100644 --- a/modules/globebrowsing/globebrowsingmodule_lua.inl +++ b/modules/globebrowsing/globebrowsingmodule_lua.inl @@ -54,19 +54,19 @@ int addLayer(lua_State* L) { // Get the node and make sure it exists SceneGraphNode* n = OsEng.renderEngine().scene()->sceneGraphNode(globeName); if (!n) { - return luaL_error(L, ("Unknown globe name: " + globeName).c_str()); + return ghoul::lua::luaError(L, "Unknown globe name: " + globeName); } // Get the renderable globe const RenderableGlobe* globe = dynamic_cast(n->renderable()); if (!globe) { - return luaL_error(L, ("Renderable is not a globe: " + globeName).c_str()); + return ghoul::lua::luaError(L, "Renderable is not a globe: " + globeName); } // Get the layer group layergroupid::GroupID groupID = layergroupid::getGroupIDFromName(layerGroupName); if (groupID == layergroupid::GroupID::Unknown) { - return luaL_error(L, ("Unknown layer group: " + layerGroupName).c_str()); + return ghoul::lua::luaError(L, "Unknown layer group: " + layerGroupName); } // Get the dictionary defining the layer @@ -104,19 +104,19 @@ int deleteLayer(lua_State* L) { // Get the node and make sure it exists SceneGraphNode* n = OsEng.renderEngine().scene()->sceneGraphNode(globeName); if (!n) { - return luaL_error(L, ("Unknown globe name: " + globeName).c_str()); + return ghoul::lua::luaError(L, "Unknown globe name: " + globeName); } // Get the renderable globe const RenderableGlobe* globe = dynamic_cast(n->renderable()); if (!globe) { - return luaL_error(L, ("Renderable is not a globe: " + globeName).c_str()); + return ghoul::lua::luaError(L, "Renderable is not a globe: " + globeName); } // Get the layer group layergroupid::GroupID groupID = layergroupid::getGroupIDFromName(layerGroupName); if (groupID == layergroupid::GroupID::Unknown) { - return luaL_error(L, ("Unknown layer group: " + layerGroupName).c_str()); + return ghoul::lua::luaError(L, "Unknown layer group: " + layerGroupName); } globe->layerManager()->deleteLayer(groupID, layerName); @@ -174,11 +174,11 @@ int getGeoPosition(lua_State* L) { SceneGraphNode* n = sceneGraphNode(name); if (!n) { - return luaL_error(L, ("Unknown globe name: " + name).c_str()); + return ghoul::lua::luaError(L, "Unknown globe name: " + name); } const RenderableGlobe* globe = dynamic_cast(n->renderable()); if (!globe) { - return luaL_error(L, "Name must be a RenderableGlobe"); + return ghoul::lua::luaError(L, "Name must be a RenderableGlobe"); } GlobeBrowsingModule& mod = *(OsEng.moduleEngine().module()); @@ -201,7 +201,7 @@ int getGeoPositionForCamera(lua_State* L) { GlobeBrowsingModule* module = OsEng.moduleEngine().module(); const RenderableGlobe* globe = module->castFocusNodeRenderableToGlobe(); if (!globe) { - return luaL_error(L, "Focus node must be a RenderableGlobe"); + return ghoul::lua::luaError(L, "Focus node must be a RenderableGlobe"); } const glm::dvec3 cameraPosition = OsEng.navigationHandler().camera()->positionVec3(); diff --git a/modules/iswa/util/iswamanager_lua.inl b/modules/iswa/util/iswamanager_lua.inl index b095e7b08a..152302969d 100644 --- a/modules/iswa/util/iswamanager_lua.inl +++ b/modules/iswa/util/iswamanager_lua.inl @@ -57,7 +57,9 @@ int iswa_addScreenSpaceCygnet(lua_State* L) { int nArguments = lua_gettop(L); if (nArguments != 1) { - return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments); + return ghoul::lua::luaError(L, fmt::format( + "Expected {} argumemts, got {}", 1, nArguments + )); } ghoul::Dictionary d; diff --git a/src/engine/moduleengine_lua.inl b/src/engine/moduleengine_lua.inl index 3c4c160bb2..6855c76b70 100644 --- a/src/engine/moduleengine_lua.inl +++ b/src/engine/moduleengine_lua.inl @@ -37,7 +37,7 @@ int isLoaded(lua_State* L) { const int type = lua_type(L, 1); if (type != LUA_TSTRING) { - return luaL_error(L, "Expected argument of type 'string'"); + return ghoul::lua::luaError(L, "Expected argument of type 'string'"); } const std::string& moduleName = ghoul::lua::value( L, diff --git a/src/engine/openspaceengine_lua.inl b/src/engine/openspaceengine_lua.inl index 3d657cf20d..c21e180410 100644 --- a/src/engine/openspaceengine_lua.inl +++ b/src/engine/openspaceengine_lua.inl @@ -108,7 +108,7 @@ int addVirtualProperty(lua_State* L) { } else { lua_settop(L, 0); - return luaL_error(L, "Unknown property type '%s'", type.c_str()); + return ghoul::lua::luaError(L, fmt::format("Unknown property type '{}'", type)); } lua_settop(L, 0); @@ -176,7 +176,10 @@ int addTag(lua_State* L) { SceneGraphNode* node = OsEng.renderEngine().scene()->sceneGraphNode(uri); if (!node) { - return luaL_error(L, "Unknown scene graph node type '%s'", uri.c_str()); + return ghoul::lua::luaError( + L, + fmt::format("Unknown scene graph node type '{}'", uri) + ); } node->addTag(std::move(tag)); @@ -199,7 +202,10 @@ int removeTag(lua_State* L) { SceneGraphNode* node = OsEng.renderEngine().scene()->sceneGraphNode(uri); if (!node) { - return luaL_error(L, "Unknown scene graph node type '%s'", uri.c_str()); + return ghoul::lua::luaError( + L, + fmt::format("Unknown scene graph node type '{}'", uri) + ); } node->removeTag(tag); @@ -230,11 +236,9 @@ int downloadFile(lua_State* L) { 5 ); if (!future || (future && !future->isFinished)) { - return luaL_error( + return ghoul::lua::luaError( L, - future ? - "Download failed" : - ("Download failed: " + future->errorMessage).c_str() + future ? "Download failed" : "Download failed: " + future->errorMessage ); } diff --git a/src/interaction/keybindingmanager_lua.inl b/src/interaction/keybindingmanager_lua.inl index 975e83aafd..2e01d9c7ec 100644 --- a/src/interaction/keybindingmanager_lua.inl +++ b/src/interaction/keybindingmanager_lua.inl @@ -43,7 +43,7 @@ int bindKey(lua_State* L) { if (command.empty()) { lua_settop(L, 0); - return luaL_error(L, "Command string is empty"); + return ghoul::lua::luaError(L, "Command string is empty"); } openspace::KeyWithModifier iKey = openspace::stringToKey(key); @@ -52,7 +52,7 @@ int bindKey(lua_State* L) { std::string error = fmt::format("Could not find key '{}'", key); LERRORC("lua.bindKey", error); lua_settop(L, 0); - return luaL_error(L, error.c_str()); + return ghoul::lua::luaError(L, error); } std::string doc = (nArguments == 3) ? ghoul::lua::value(L, 3) : ""; @@ -83,7 +83,7 @@ int bindKeyLocal(lua_State* L) { const std::string& command = ghoul::lua::value(L, 2); if (command.empty()) { - return luaL_error(L, "Command string is empty"); + return ghoul::lua::luaError(L, "Command string is empty"); } openspace::KeyWithModifier iKey = openspace::stringToKey(key); @@ -91,7 +91,7 @@ int bindKeyLocal(lua_State* L) { if (iKey.key == openspace::Key::Unknown) { std::string error = fmt::format("Could not find key '{}'", key); LERRORC("lua.bindKey", error); - return luaL_error(L, error.c_str()); + return ghoul::lua::luaError(L, error); } std::string doc = nArguments == 3 ? ghoul::lua::value(L, 3) : ""; diff --git a/src/interaction/navigationhandler_lua.inl b/src/interaction/navigationhandler_lua.inl index d9b1089c45..458e2c0b91 100644 --- a/src/interaction/navigationhandler_lua.inl +++ b/src/interaction/navigationhandler_lua.inl @@ -36,7 +36,7 @@ int restoreCameraStateFromFile(lua_State* L) { ); if (cameraStateFilePath.empty()) { - return luaL_error(L, "filepath string is empty"); + return ghoul::lua::luaError(L, "filepath string is empty"); } OsEng.navigationHandler().restoreCameraStateFromFile(cameraStateFilePath); @@ -54,7 +54,10 @@ int setCameraState(lua_State* L) { OsEng.navigationHandler().setCameraStateFromDictionary(dictionary); } catch (const ghoul::RuntimeError& e) { lua_settop(L, 0); - return luaL_error(L, "Could not set camera state: %s", e.what()); + return ghoul::lua::luaError( + L, + fmt::format("Could not set camera state: {}", e.what()) + ); } // @CLEANUP: When luaDictionaryFromState doesn't leak space anymore, remove the next @@ -74,7 +77,7 @@ int saveCameraStateToFile(lua_State* L) { ); if (cameraStateFilePath.empty()) { - return luaL_error(L, "filepath string is empty"); + return ghoul::lua::luaError(L, "filepath string is empty"); } OsEng.navigationHandler().saveCameraStateToFile(cameraStateFilePath); diff --git a/src/mission/missionmanager_lua.inl b/src/mission/missionmanager_lua.inl index 7f394fbdf0..0ce5bb8d82 100644 --- a/src/mission/missionmanager_lua.inl +++ b/src/mission/missionmanager_lua.inl @@ -33,7 +33,7 @@ int loadMission(lua_State* L) { ghoul::lua::PopValue::Yes ); if (missionFileName.empty()) { - return luaL_error(L, "Filepath is empty"); + return ghoul::lua::luaError(L, "Filepath is empty"); } std::string name = MissionManager::ref().loadMission(absPath(missionFileName)); @@ -52,11 +52,11 @@ int unloadMission(lua_State* L) { ghoul::lua::PopValue::Yes ); if (missionName.empty()) { - return luaL_error(L, "Mission name is empty"); + return ghoul::lua::luaError(L, "Mission name is empty"); } if (!MissionManager::ref().hasMission(missionName)) { - return luaL_error(L, "Mission was not previously loaded"); + return ghoul::lua::luaError(L, "Mission was not previously loaded"); } MissionManager::ref().unloadMission(missionName); @@ -74,7 +74,7 @@ int hasMission(lua_State* L) { ghoul::lua::PopValue::Yes ); if (missionName.empty()) { - return luaL_error(L, "Missing name is empty"); + return ghoul::lua::luaError(L, "Missing name is empty"); } const bool hasMission = MissionManager::ref().hasMission(missionName); @@ -94,7 +94,7 @@ int setCurrentMission(lua_State* L) { ghoul::lua::PopValue::Yes ); if (missionName.empty()) { - return luaL_error(L, "Mission name is empty"); + return ghoul::lua::luaError(L, "Mission name is empty"); } MissionManager::ref().setCurrentMission(missionName); diff --git a/src/rendering/dashboard_lua.inl b/src/rendering/dashboard_lua.inl index 0c05d51b0d..1419805801 100644 --- a/src/rendering/dashboard_lua.inl +++ b/src/rendering/dashboard_lua.inl @@ -55,7 +55,7 @@ int addDashboardItem(lua_State* L) { return 0; } else { - return luaL_error(L, "Expected argument of type 'table'"); + return ghoul::lua::luaError(L, "Expected argument of type 'table'"); } } diff --git a/src/rendering/renderengine_lua.inl b/src/rendering/renderengine_lua.inl index 9b70fe6b04..97ad393cdb 100644 --- a/src/rendering/renderengine_lua.inl +++ b/src/rendering/renderengine_lua.inl @@ -34,7 +34,7 @@ int setRenderer(lua_State* L) { const int type = lua_type(L, -1); if (type != LUA_TSTRING) { - return luaL_error(L, "Expected argument of type 'string'"); + return ghoul::lua::luaError(L, "Expected argument of type 'string'"); } const std::string& renderer = ghoul::lua::value( diff --git a/src/scene/assetloader.cpp b/src/scene/assetloader.cpp index f3b88ab813..32be8a7f86 100644 --- a/src/scene/assetloader.cpp +++ b/src/scene/assetloader.cpp @@ -626,7 +626,10 @@ int AssetLoader::requireLua(Asset* dependant) { std::shared_ptr dependency = require(assetName); if (!dependency) { - return luaL_error(*_luaState, "Asset '%s' not found", assetName.c_str()); + return ghoul::lua::luaError( + *_luaState, + fmt::format("Asset '{}' not found", assetName) + ); } addLuaDependencyTable(dependant, dependency.get()); diff --git a/src/scene/scene_lua.inl b/src/scene/scene_lua.inl index 7dd7685ae2..74dee6a8f6 100644 --- a/src/scene/scene_lua.inl +++ b/src/scene/scene_lua.inl @@ -424,27 +424,29 @@ int addSceneGraphNode(lua_State* L) { } catch (const ghoul::lua::LuaFormatException& e) { LERRORC("addSceneGraphNode", e.what()); - return luaL_error(L, "Error loading dictionary from lua state"); + return ghoul::lua::luaError(L, "Error loading dictionary from lua state"); } try { SceneGraphNode* node = OsEng.renderEngine().scene()->loadNode(d); if (!node) { LERRORC("Scene", "Could not load scene graph node"); - return luaL_error(L, "Error loading scene graph node"); + return ghoul::lua::luaError(L, "Error loading scene graph node"); } OsEng.renderEngine().scene()->initializeNode(node); } catch (const documentation::SpecificationError& e) { - return luaL_error( + return ghoul::lua::luaError( L, - "Error loading scene graph node: %s: %s", - e.what(), - std::to_string(e.result).c_str() + fmt::format("Error loading scene graph node: {}: {}", + e.what(), std::to_string(e.result)) ); } catch (const ghoul::RuntimeError& e) { - return luaL_error(L, "Error loading scene graph node: %s", e.what()); + return ghoul::lua::luaError( + L, + fmt::format("Error loading scene graph node: {}", e.what()) + ); } lua_settop(L, 0); diff --git a/src/scripting/scriptscheduler_lua.inl b/src/scripting/scriptscheduler_lua.inl index ace28f7c31..42c74ad719 100644 --- a/src/scripting/scriptscheduler_lua.inl +++ b/src/scripting/scriptscheduler_lua.inl @@ -33,7 +33,7 @@ int loadFile(lua_State* L) { ghoul::lua::PopValue::Yes ); if (missionFileName.empty()) { - return luaL_error(L, "filepath string is empty"); + return ghoul::lua::luaError(L, "filepath string is empty"); } OsEng.scriptScheduler().loadScripts( diff --git a/src/util/spicemanager_lua.inl b/src/util/spicemanager_lua.inl index 665f13e77b..ef079f3f27 100644 --- a/src/util/spicemanager_lua.inl +++ b/src/util/spicemanager_lua.inl @@ -50,7 +50,10 @@ int loadKernel(lua_State* L) { ghoul::lua::PopValue::Yes ); if (!FileSys.fileExists(argument)) { - return luaL_error(L, "Kernel file '%s' did not exist", argument.c_str()); + return ghoul::lua::luaError( + L, + fmt::format("Kernel file '{}' did not exist", argument) + ); } unsigned int result = SpiceManager::ref().loadKernel(argument); diff --git a/src/util/time_lua.inl b/src/util/time_lua.inl index 86239736bd..0ac0ad4059 100644 --- a/src/util/time_lua.inl +++ b/src/util/time_lua.inl @@ -39,7 +39,7 @@ int time_setDeltaTime(lua_State* L) { if (isFunction) { // If the top of the stack is a function, it is ourself const char* msg = lua_pushfstring(L, "method called without argument"); - return luaL_error(L, "bad argument (%s)", msg); + return ghoul::lua::luaError(L, fmt::format("bad argument ({})", msg)); } const bool isNumber = (lua_isnumber(L, -1) != 0); @@ -57,7 +57,7 @@ int time_setDeltaTime(lua_State* L) { lua_typename(L, LUA_TNUMBER), luaL_typename(L, -1) ); - return luaL_error(L, "bad argument #%d (%s)", 1, msg); + return ghoul::lua::luaError(L, fmt::format("bad argument #1 ({})", msg)); } } @@ -117,7 +117,7 @@ int time_setTime(lua_State* L) { if (isFunction) { // If the top of the stack is a function, it is ourself const char* msg = lua_pushfstring(L, "method called without argument"); - return luaL_error(L, "bad argument (%s)", 1, msg); + return ghoul::lua::luaError(L, fmt::format("bad argument #1 ({})", msg)); } const bool isNumber = (lua_isnumber(L, -1) != 0); @@ -126,7 +126,7 @@ int time_setTime(lua_State* L) { const char* msg = lua_pushfstring(L, "%s or %s expected, got %s", lua_typename(L, LUA_TNUMBER), lua_typename(L, LUA_TSTRING), luaL_typename(L, -1)); - return luaL_error(L, "bad argument #%d (%s)", 1, msg); + return ghoul::lua::luaError(L, fmt::format("bad argument #1 ({})", msg)); } if (isNumber) { double value = lua_tonumber(L, -1);