From f7f8f279de8cd1280598adb2de5765400d36225f Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 18 Jul 2016 12:40:29 +0200 Subject: [PATCH] Move the LuaLibrary definition into its own file --- include/openspace/engine/moduleengine.h | 2 +- include/openspace/engine/openspaceengine.h | 2 +- .../interaction/interactionhandler.h | 4 +- include/openspace/interaction/luaconsole.h | 2 +- .../openspace/network/parallelconnection.h | 2 +- include/openspace/rendering/renderengine.h | 2 +- include/openspace/scene/scene.h | 2 +- include/openspace/scripting/lualibrary.h | 69 +++++++++++++++++++ include/openspace/scripting/scriptengine.h | 35 +--------- include/openspace/util/time.h | 2 +- modules/iswa/util/iswamanager.cpp | 2 +- modules/iswa/util/iswamanager.h | 2 +- modules/onscreengui/include/gui.h | 2 +- modules/onscreengui/src/gui.cpp | 2 +- src/CMakeLists.txt | 2 + src/engine/moduleengine.cpp | 2 +- src/engine/openspaceengine.cpp | 2 +- src/engine/openspaceengine_lua.inl | 1 - src/interaction/interactionhandler.cpp | 4 +- src/interaction/luaconsole.cpp | 2 +- src/network/parallelconnection.cpp | 2 +- src/rendering/renderengine.cpp | 2 +- src/scene/scene.cpp | 2 +- src/scripting/lualibrary.cpp | 35 ++++++++++ src/scripting/scriptengine.cpp | 6 +- src/util/time.cpp | 5 +- 26 files changed, 132 insertions(+), 63 deletions(-) create mode 100644 include/openspace/scripting/lualibrary.h create mode 100644 src/scripting/lualibrary.cpp diff --git a/include/openspace/engine/moduleengine.h b/include/openspace/engine/moduleengine.h index a15515c4d0..6075ebe125 100644 --- a/include/openspace/engine/moduleengine.h +++ b/include/openspace/engine/moduleengine.h @@ -79,7 +79,7 @@ public: * Returns the Lua library that contains all Lua functions available to affect the * modules. */ - static scripting::ScriptEngine::LuaLibrary luaLibrary(); + static scripting::LuaLibrary luaLibrary(); private: /// The list of all registered OpenSpaceModule%s diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 30817172d3..442eb7ed71 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -120,7 +120,7 @@ public: * Returns the Lua library that contains all Lua functions available to affect the * application. */ - static scripting::ScriptEngine::LuaLibrary luaLibrary(); + static scripting::LuaLibrary luaLibrary(); private: OpenSpaceEngine(std::string programName, std::unique_ptr windowWrapper); diff --git a/include/openspace/interaction/interactionhandler.h b/include/openspace/interaction/interactionhandler.h index a90df2ba87..4b89d42e44 100644 --- a/include/openspace/interaction/interactionhandler.h +++ b/include/openspace/interaction/interactionhandler.h @@ -93,7 +93,7 @@ public: * \return The Lua library that contains all Lua functions available to affect the * interaction */ - static scripting::ScriptEngine::LuaLibrary luaLibrary(); + static scripting::LuaLibrary luaLibrary(); // Callback functions @@ -342,7 +342,7 @@ public: * \return The Lua library that contains all Lua functions available to affect the * interaction */ - static scripting::ScriptEngine::LuaLibrary luaLibrary(); + static scripting::LuaLibrary luaLibrary(); // Callback functions void keyboardCallback(Key key, KeyModifier modifier, KeyAction action); diff --git a/include/openspace/interaction/luaconsole.h b/include/openspace/interaction/luaconsole.h index d3e6aed595..9273a717a7 100644 --- a/include/openspace/interaction/luaconsole.h +++ b/include/openspace/interaction/luaconsole.h @@ -52,7 +52,7 @@ public: void setVisible(bool visible); void toggleVisibility(); - static scripting::ScriptEngine::LuaLibrary luaLibrary(); + static scripting::LuaLibrary luaLibrary(); private: diff --git a/include/openspace/network/parallelconnection.h b/include/openspace/network/parallelconnection.h index f377ab0457..979b57a8cc 100644 --- a/include/openspace/network/parallelconnection.h +++ b/include/openspace/network/parallelconnection.h @@ -108,7 +108,7 @@ namespace openspace{ * \return The Lua library that contains all Lua functions available to affect the * interaction */ - static scripting::ScriptEngine::LuaLibrary luaLibrary(); + static scripting::LuaLibrary luaLibrary(); protected: diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index 832671c52b..647f516c3e 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -165,7 +165,7 @@ public: * Returns the Lua library that contains all Lua functions available to affect the * rendering. */ - static scripting::ScriptEngine::LuaLibrary luaLibrary(); + static scripting::LuaLibrary luaLibrary(); // This is a temporary method to change the origin of the coordinate system ---abock void changeViewPoint(std::string origin); diff --git a/include/openspace/scene/scene.h b/include/openspace/scene/scene.h index d871fac952..8950866867 100644 --- a/include/openspace/scene/scene.h +++ b/include/openspace/scene/scene.h @@ -115,7 +115,7 @@ public: * \return The Lua library that contains all Lua functions available to change the * scene graph */ - static scripting::ScriptEngine::LuaLibrary luaLibrary(); + static scripting::LuaLibrary luaLibrary(); private: bool loadSceneInternal(const std::string& sceneDescriptionFilePath); diff --git a/include/openspace/scripting/lualibrary.h b/include/openspace/scripting/lualibrary.h new file mode 100644 index 0000000000..6787575a84 --- /dev/null +++ b/include/openspace/scripting/lualibrary.h @@ -0,0 +1,69 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __LUALIBRARY_H__ +#define __LUALIBRARY_H__ + +#include + +namespace openspace { +namespace scripting { + +/** +* This structure represents a Lua library, itself consisting of a unique #name and +* an arbitrary number of #functions +*/ +struct LuaLibrary { + /** + * This structure represents a Lua function with its #name, #function pointer + * #argumentText describing the arguments this function takes, the #helpText + * describing the function, and whether it should be shared in a parallel + * connection (#parallelShared) + */ + struct Function { + /// The name of the function + std::string name; + /// The function pointer that is executed if the function is called + lua_CFunction function; + /// A text describing the arugments to this function + std::string argumentText; + /// A help text describing what the function does/ + std::string helpText; + /// If true, this function will be shared with other parallel + /// connections + bool parallelShared; + }; + /// The name of the library + std::string name; + /// The list of all functions for this library + std::vector functions; + + /// Comparison function that compares two LuaLibrary%s name + bool operator<(const LuaLibrary& rhs) const; +}; + +} // namespace scripting +} // namespace openspace + +#endif // __LUALIBRARY_H__ diff --git a/include/openspace/scripting/scriptengine.h b/include/openspace/scripting/scriptengine.h index 54242e7081..cb7797e181 100644 --- a/include/openspace/scripting/scriptengine.h +++ b/include/openspace/scripting/scriptengine.h @@ -25,6 +25,8 @@ #ifndef __SCRIPTENGINE_H__ #define __SCRIPTENGINE_H__ +#include + #include #include @@ -47,39 +49,6 @@ namespace scripting { */ class ScriptEngine { public: - /** - * This structure represents a Lua library, itself consisting of a unique #name and - * an arbitrary number of #functions - */ - struct LuaLibrary { - /** - * This structure represents a Lua function with its #name, #function pointer - * #argumentText describing the arguments this function takes, the #helpText - * describing the function, and whether it should be shared in a parallel - * connection (#parallelShared) - */ - struct Function { - /// The name of the function - std::string name; - /// The function pointer that is executed if the function is called - lua_CFunction function; - /// A text describing the arugments to this function - std::string argumentText; - /// A help text describing what the function does/ - std::string helpText; - /// If true, this function will be shared with other parallel - /// connections - bool parallelShared; - }; - /// The name of the library - std::string name; - /// The list of all functions for this library - std::vector functions; - - /// Comparison function that compares two LuaLibrary%s name - bool operator<(const LuaLibrary& rhs) const; - }; - /** * Initializes the internal Lua state and registers a common set of library functions * \throw LuaRuntimeException If the creation of the new Lua state fails diff --git a/include/openspace/util/time.h b/include/openspace/util/time.h index 345a5be062..8820bcbcc0 100644 --- a/include/openspace/util/time.h +++ b/include/openspace/util/time.h @@ -207,7 +207,7 @@ public: * \return The Lua library that contains all Lua functions available to change the * Time singleton */ - static scripting::ScriptEngine::LuaLibrary luaLibrary(); + static scripting::LuaLibrary luaLibrary(); private: static Time* _instance; ///< The singleton instance diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index 2b0728698b..bad0b41bf7 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -652,7 +652,7 @@ void IswaManager::setBaseUrl(std::string bUrl){ baseUrl = bUrl; } -scripting::ScriptEngine::LuaLibrary IswaManager::luaLibrary() { +scripting::LuaLibrary IswaManager::luaLibrary() { return { "iswa", { diff --git a/modules/iswa/util/iswamanager.h b/modules/iswa/util/iswamanager.h index bab50f2deb..9b81fa4646 100644 --- a/modules/iswa/util/iswamanager.h +++ b/modules/iswa/util/iswamanager.h @@ -99,7 +99,7 @@ public: std::map>& groups(); std::map>& cdfInformation(); - static scripting::ScriptEngine::LuaLibrary luaLibrary(); + static scripting::LuaLibrary luaLibrary(); ghoul::Event<>& iswaEvent(){ return _iswaEvent; diff --git a/modules/onscreengui/include/gui.h b/modules/onscreengui/include/gui.h index 7f36048b33..673e7dbb31 100644 --- a/modules/onscreengui/include/gui.h +++ b/modules/onscreengui/include/gui.h @@ -61,7 +61,7 @@ public: void render(); - static openspace::scripting::ScriptEngine::LuaLibrary luaLibrary(); + static openspace::scripting::LuaLibrary luaLibrary(); //protected: GuiHelpComponent _help; diff --git a/modules/onscreengui/src/gui.cpp b/modules/onscreengui/src/gui.cpp index 3e08132fca..2057c64a38 100644 --- a/modules/onscreengui/src/gui.cpp +++ b/modules/onscreengui/src/gui.cpp @@ -499,7 +499,7 @@ void GUI::render() { ImGui::End(); } -scripting::ScriptEngine::LuaLibrary GUI::luaLibrary() { +scripting::LuaLibrary GUI::luaLibrary() { return { "gui", { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1dd0430a65..25fe24bf5e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -77,6 +77,7 @@ set(OPENSPACE_SOURCE ${OPENSPACE_BASE_DIR}/src/scene/scene_lua.inl ${OPENSPACE_BASE_DIR}/src/scene/scenegraph.cpp ${OPENSPACE_BASE_DIR}/src/scene/scenegraphnode.cpp + ${OPENSPACE_BASE_DIR}/src/scripting/lualibrary.cpp ${OPENSPACE_BASE_DIR}/src/scripting/scriptengine.cpp ${OPENSPACE_BASE_DIR}/src/scripting/scriptengine_lua.inl ${OPENSPACE_BASE_DIR}/src/util/blockplaneintersectiongeometry.cpp @@ -158,6 +159,7 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/scene/scene.h ${OPENSPACE_BASE_DIR}/include/openspace/scene/scenegraph.h ${OPENSPACE_BASE_DIR}/include/openspace/scene/scenegraphnode.h + ${OPENSPACE_BASE_DIR}/include/openspace/scripting/lualibrary.h ${OPENSPACE_BASE_DIR}/include/openspace/scripting/script_helper.h ${OPENSPACE_BASE_DIR}/include/openspace/scripting/scriptengine.h ${OPENSPACE_BASE_DIR}/include/openspace/util/blockplaneintersectiongeometry.h diff --git a/src/engine/moduleengine.cpp b/src/engine/moduleengine.cpp index ed14d9a74e..76611a92cc 100644 --- a/src/engine/moduleengine.cpp +++ b/src/engine/moduleengine.cpp @@ -82,7 +82,7 @@ std::vector ModuleEngine::modules() const { return result; } -scripting::ScriptEngine::LuaLibrary ModuleEngine::luaLibrary() { +scripting::LuaLibrary ModuleEngine::luaLibrary() { return { "modules", { diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 09d861d2fb..9cb627b5c2 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -967,7 +967,7 @@ void OpenSpaceEngine::toggleShutdownMode() { } } -scripting::ScriptEngine::LuaLibrary OpenSpaceEngine::luaLibrary() { +scripting::LuaLibrary OpenSpaceEngine::luaLibrary() { return { "", { diff --git a/src/engine/openspaceengine_lua.inl b/src/engine/openspaceengine_lua.inl index ca4db329f7..7d33f6af76 100644 --- a/src/engine/openspaceengine_lua.inl +++ b/src/engine/openspaceengine_lua.inl @@ -22,7 +22,6 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ - namespace openspace { namespace luascriptfunctions { diff --git a/src/interaction/interactionhandler.cpp b/src/interaction/interactionhandler.cpp index 6f7b676f2c..c5d0ca18e7 100644 --- a/src/interaction/interactionhandler.cpp +++ b/src/interaction/interactionhandler.cpp @@ -493,7 +493,7 @@ void InteractionHandler::bindKey(Key key, KeyModifier modifier, std::string lua) }); } -scripting::ScriptEngine::LuaLibrary InteractionHandler::luaLibrary() { +scripting::LuaLibrary InteractionHandler::luaLibrary() { return { "", { @@ -1173,7 +1173,7 @@ void InteractionHandler::writeKeyboardDocumentation(const std::string& type, con } } -scripting::ScriptEngine::LuaLibrary InteractionHandler::luaLibrary() { +scripting::LuaLibrary InteractionHandler::luaLibrary() { return{ "", { diff --git a/src/interaction/luaconsole.cpp b/src/interaction/luaconsole.cpp index 7fe960624b..b9adcbec21 100644 --- a/src/interaction/luaconsole.cpp +++ b/src/interaction/luaconsole.cpp @@ -398,7 +398,7 @@ void LuaConsole::toggleVisibility() { _isVisible = !_isVisible; } -scripting::ScriptEngine::LuaLibrary LuaConsole::luaLibrary() { +scripting::LuaLibrary LuaConsole::luaLibrary() { return { "console", { diff --git a/src/network/parallelconnection.cpp b/src/network/parallelconnection.cpp index 1b4a634350..416968cff7 100644 --- a/src/network/parallelconnection.cpp +++ b/src/network/parallelconnection.cpp @@ -1100,7 +1100,7 @@ int ParallelConnection::headerSize(){ return 2 * sizeof(uint8_t) + 2 + sizeof(uint32_t); } -scripting::ScriptEngine::LuaLibrary ParallelConnection::luaLibrary() { +scripting::LuaLibrary ParallelConnection::luaLibrary() { return { "parallel", { diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 4b98620289..a48d56a66d 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -677,7 +677,7 @@ void RenderEngine::setNAaSamples(int nAaSamples) { } } -scripting::ScriptEngine::LuaLibrary RenderEngine::luaLibrary() { +scripting::LuaLibrary RenderEngine::luaLibrary() { return { "", { diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index d66c4fc2b4..0a4ad41624 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -555,7 +555,7 @@ void Scene::writePropertyDocumentation(const std::string& filename, const std::s LERROR("Undefined type '" << type << "' for Property documentation"); } -scripting::ScriptEngine::LuaLibrary Scene::luaLibrary() { +scripting::LuaLibrary Scene::luaLibrary() { return { "", { diff --git a/src/scripting/lualibrary.cpp b/src/scripting/lualibrary.cpp new file mode 100644 index 0000000000..4aff78390c --- /dev/null +++ b/src/scripting/lualibrary.cpp @@ -0,0 +1,35 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2016 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +namespace openspace { +namespace scripting { + +bool LuaLibrary::operator<(const LuaLibrary& rhs) const { + return name < rhs.name; +} + +} // namespace scripting +} // namespace openspace diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 9ebfa1ca4b..a795067bf6 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -54,10 +54,6 @@ namespace { } -bool ScriptEngine::LuaLibrary::operator<(const LuaLibrary& rhs) const { - return name < rhs.name; -} - void ScriptEngine::initialize() { LDEBUG("Adding base library"); addBaseLibrary(); @@ -208,7 +204,7 @@ bool ScriptEngine::shouldScriptBeSent(const std::string& library, const std::str } } - std::vector::const_iterator funcit; + std::vector::const_iterator funcit; //library was found if (libit != _registeredLibraries.cend()){ for (funcit = libit->functions.cbegin(); diff --git a/src/util/time.cpp b/src/util/time.cpp index a541638b6c..2695202e2e 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -240,8 +240,8 @@ bool Time::paused() const { return _timePaused; } -scripting::ScriptEngine::LuaLibrary Time::luaLibrary() { - scripting::ScriptEngine::LuaLibrary timeLibrary = { +scripting::LuaLibrary Time::luaLibrary() { + return { "time", { { @@ -307,7 +307,6 @@ scripting::ScriptEngine::LuaLibrary Time::luaLibrary() { } } }; - return timeLibrary; } } // namespace openspace