diff --git a/apps/OpenSpace/ext/sgct b/apps/OpenSpace/ext/sgct index 3f2bbf3ebb..d03bd10777 160000 --- a/apps/OpenSpace/ext/sgct +++ b/apps/OpenSpace/ext/sgct @@ -1 +1 @@ -Subproject commit 3f2bbf3ebb1e1ef23af25731c182a711b4102814 +Subproject commit d03bd1077704da032fe25ef70c97d19e5c431d11 diff --git a/ext/ghoul b/ext/ghoul index af5545a13d..b9013de0cb 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit af5545a13d140b15e7b37f581ea7dde522be2b5b +Subproject commit b9013de0cbfceb211f2ee85640f2be98427c980c diff --git a/include/openspace/scripting/lualibrary.h b/include/openspace/scripting/lualibrary.h index 698da1ca6a..3aef532165 100644 --- a/include/openspace/scripting/lualibrary.h +++ b/include/openspace/scripting/lualibrary.h @@ -33,9 +33,9 @@ namespace openspace::scripting { /** -* This structure represents a Lua library, itself consisting of a unique #name and -* an arbitrary number of #functions -*/ + * 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 @@ -47,9 +47,7 @@ struct LuaLibrary { std::string name; /// The function pointer that is executed if the function is called lua_CFunction function; - /// A vector of light userdata to be passed into the function - std::vector userdata; - /// A text describing the arugments to this function + /// A text describing the arguments to this function std::string argumentText; /// A help text describing what the function does/ std::string helpText; @@ -60,6 +58,8 @@ struct LuaLibrary { std::vector functions; /// A list of script files that are executed for each Lua state std::vector scripts = std::vector(); + /// A list of all libraries that are children for this library + std::vector subLibraries; /// This struct contains information about a function or constant that is defined in /// a Lua script @@ -77,6 +77,9 @@ struct LuaLibrary { /// Comparison function that compares two LuaLibrary%s name bool operator<(const LuaLibrary& rhs) const; + + /// Merges the contents of a second LuaLibrary into this LuaLibrary + void merge(LuaLibrary rhs); }; } // namespace openspace::scripting diff --git a/modules/base/rendering/screenspacedashboard.cpp b/modules/base/rendering/screenspacedashboard.cpp index 5cbb793421..1b45ed0766 100644 --- a/modules/base/rendering/screenspacedashboard.cpp +++ b/modules/base/rendering/screenspacedashboard.cpp @@ -139,14 +139,12 @@ scripting::LuaLibrary ScreenSpaceDashboard::luaLibrary() { { "addDashboardItemToScreenSpace", &luascriptfunctions::addDashboardItemToScreenSpace, - {}, "string, table", "Adds a new dashboard item to an existing SceenSpaceDashboard." }, { "removeDashboardItemsFromScreenSpace", &luascriptfunctions::removeDashboardItemsFromScreenSpace, - {}, "string", "Removes all dashboard items from an existing ScreenSpaceDashboard." } diff --git a/modules/debugging/debuggingmodule.cpp b/modules/debugging/debuggingmodule.cpp index 7e7e2eac9c..624ac3b084 100644 --- a/modules/debugging/debuggingmodule.cpp +++ b/modules/debugging/debuggingmodule.cpp @@ -58,7 +58,6 @@ scripting::LuaLibrary DebuggingModule::luaLibrary() const { { "renderCameraPath", &luascriptfunctions::renderCameraPath, - {}, "[number, bool, number]", "Render the current camera path from the path navigation system. The " "first optional argument is the number of samples to take along the path " @@ -71,14 +70,12 @@ scripting::LuaLibrary DebuggingModule::luaLibrary() const { { "removeRenderedCameraPath", &luascriptfunctions::removeRenderedCameraPath, - {}, "", "Removes the rendered camera path, if there is one" }, { "renderPathControlPoints", &luascriptfunctions::renderPathControlPoints, - {}, "[number]", "Render the control points for the camera path spline as spheres. The " "optional argument can be used to set the radius of the created spheres. " @@ -86,14 +83,12 @@ scripting::LuaLibrary DebuggingModule::luaLibrary() const { { "removePathControlPoints", &luascriptfunctions::removePathControlPoints, - {}, "", "Removes the rendered control points" }, { "addCartesianAxes", &luascriptfunctions::addCartesianAxes, - {}, "string, [number]", "Adds a set of Cartesian axes to the scene graph node identified by the " "first string, to illustrate its local coordinate system. The second " diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 2f483cd099..20a8765ef1 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -255,7 +255,6 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { { "addExoplanetSystem", &exoplanets::luascriptfunctions::addExoplanetSystem, - {}, "string or list of strings", "Add one or multiple exoplanet systems to the scene, as specified by the " "input. An input string should be the name of the system host star" @@ -263,14 +262,12 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { { "removeExoplanetSystem", &exoplanets::luascriptfunctions::removeExoplanetSystem, - {}, "string", "Removes the nodes of the specified exoplanet system from the scene graph" }, { "listAvailableExoplanetSystems", &exoplanets::luascriptfunctions::listAvailableExoplanetSystems, - {}, "", "Prints a list with the names of all exoplanet systems that can be added to " "the scene graph to the OpenSpace Log" @@ -278,7 +275,6 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { { "getListOfExoplanets", &exoplanets::luascriptfunctions::getListOfExoplanets, - {}, "", "Gets a list with the names of all exoplanet systems" } diff --git a/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp b/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp index 1754dc85dc..a8e4db7a1d 100644 --- a/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp +++ b/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp @@ -819,7 +819,7 @@ std::unordered_map> continue; } - std::ifstream seedFile(spFile); + std::ifstream seedFile(spFile.path()); if (!seedFile.good()) { LERROR(fmt::format("Could not open seed points file '{}'", seedFilePath)); outMap.clear(); diff --git a/modules/globebrowsing/globebrowsingmodule.cpp b/modules/globebrowsing/globebrowsingmodule.cpp index f4fd899794..09b75daa7b 100644 --- a/modules/globebrowsing/globebrowsingmodule.cpp +++ b/modules/globebrowsing/globebrowsingmodule.cpp @@ -340,7 +340,6 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const { { "addLayer", &globebrowsing::luascriptfunctions::addLayer, - {}, "string, string, table", "Adds a layer to the specified globe. The first argument specifies the " "name of the scene graph node of which to add the layer. The renderable " @@ -352,7 +351,6 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const { { "deleteLayer", &globebrowsing::luascriptfunctions::deleteLayer, - {}, "string, string", "Removes a layer from the specified globe. The first argument specifies " "the name of the scene graph node of which to remove the layer. " @@ -364,7 +362,6 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const { { "getLayers", &globebrowsing::luascriptfunctions::getLayers, - {}, "string, string", "Returns the list of layers for the scene graph node specified in the first " "parameter. The second parameter specifies which layer type should be " @@ -373,7 +370,6 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const { { "moveLayer", &globebrowsing::luascriptfunctions::moveLayer, - {}, "string, string, number, number", "Rearranges the order of a single layer in a scene graph node. The first " "parameter specifies the scene graph node, the second parameter specifies " @@ -385,14 +381,12 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const { { "goToChunk", &globebrowsing::luascriptfunctions::goToChunk, - {}, "void", "Go to chunk with given index x, y, level" }, { "goToGeo", &globebrowsing::luascriptfunctions::goToGeo, - {}, "[string], number, number, [number]", "Go to geographic coordinates of a globe. The first (optional) argument is " "the identifier of a scene graph node that has a RenderableGlobe attached. " @@ -408,7 +402,6 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const { // paths work really well close to surfaces "flyToGeo", &globebrowsing::luascriptfunctions::flyToGeo, - {}, "[string], number, number, number [, bool, number]", "Fly the camera to geographic coordinates of a globe, using the path " "navigation system. The first (optional) argument is the identifier of a " @@ -422,7 +415,6 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const { { "getLocalPositionFromGeo", &globebrowsing::luascriptfunctions::getLocalPositionFromGeo, - {}, "string, number, number, number", "Returns a position in the local Cartesian coordinate system of the globe " "identified by the first argument, that corresponds to the given geographic " @@ -433,7 +425,6 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const { { "getGeoPositionForCamera", &globebrowsing::luascriptfunctions::getGeoPositionForCamera, - {}, "void", "Get geographic coordinates of the camera position in latitude, " "longitude, and altitude (degrees and meters)." @@ -441,7 +432,6 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const { { "loadWMSCapabilities", &globebrowsing::luascriptfunctions::loadWMSCapabilities, - {}, "string, string, string", "Loads and parses the WMS capabilities xml file from a remote server. " "The first argument is the name of the capabilities that can be used to " @@ -452,7 +442,6 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const { { "removeWMSServer", &globebrowsing::luascriptfunctions::removeWMSServer, - {}, "string", "Removes the WMS server identified by the first argument from the list " "of available servers. The parameter corrsponds to the first argument in " @@ -461,7 +450,6 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const { { "capabilitiesWMS", &globebrowsing::luascriptfunctions::capabilities, - {}, "string", "Returns an array of tables that describe the available layers that are " "supported by the WMS server identified by the provided name. The 'URL'" diff --git a/modules/globebrowsing/src/layergroup.cpp b/modules/globebrowsing/src/layergroup.cpp index 3254049cb1..276b5af11c 100644 --- a/modules/globebrowsing/src/layergroup.cpp +++ b/modules/globebrowsing/src/layergroup.cpp @@ -151,14 +151,29 @@ Layer* LayerGroup::addLayer(const ghoul::Dictionary& layerDict) { properties::PropertyOwner* layerGroup = ptr->owner(); properties::PropertyOwner* layerManager = layerGroup->owner(); - properties::PropertyOwner* globe = layerManager->owner(); - properties::PropertyOwner* sceneGraphNode = globe->owner(); - global::eventEngine->publishEvent( - sceneGraphNode->identifier(), - layerGroup->identifier(), - ptr->identifier() - ); + // @TODO (emmbr, 2021-11-03) If the layer is added as part of the globe's + // dictionary during construction this function is called in the LayerManager's + // initialize function. This means that the layerManager does not exists yet, and + // we cannot find which SGN it belongs to... Want to avoid doing this check, so + // this should be fixed (probably as part of a cleanup/rewite of the LayerManager) + if (!layerManager) { + global::eventEngine->publishEvent( + "", // we don't know this yet + layerGroup->identifier(), + ptr->identifier() + ); + } + else { + properties::PropertyOwner* globe = layerManager->owner(); + properties::PropertyOwner* sceneGraphNode = globe->owner(); + global::eventEngine->publishEvent( + sceneGraphNode->identifier(), + layerGroup->identifier(), + ptr->identifier() + ); + } + return ptr; } diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index 8d1fccebf1..8539747ef7 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -757,63 +757,48 @@ scripting::LuaLibrary IswaManager::luaLibrary() { { "addCygnet", &luascriptfunctions::iswa_addCygnet, - {}, "int, string, string", "Adds a IswaCygnet", }, { "addScreenSpaceCygnet", &luascriptfunctions::iswa_addScreenSpaceCygnet, - {}, "int, string, string", "Adds a Screen Space Cygnets", }, { "addKameleonPlanes", &luascriptfunctions::iswa_addKameleonPlanes, - {}, "string, int", "Adds KameleonPlanes from cdf file.", }, - // { - // "addKameleonPlane", - // &luascriptfunctions::iswa_addKameleonPlane, - // "string, string, string", - // "Adds a KameleonPlane from cdf file.", - // true - // }, { "addCdfFiles", &luascriptfunctions::iswa_addCdfFiles, - {}, "string", "Adds a cdf files to choose from.", }, { "removeCygnet", &luascriptfunctions::iswa_removeCygnet, - {}, "string", "Remove a Cygnets", }, { "removeScreenSpaceCygnet", &luascriptfunctions::iswa_removeScrenSpaceCygnet, - {}, "int", "Remove a Screen Space Cygnets", }, { "removeGroup", &luascriptfunctions::iswa_removeGroup, - {}, "int", "Remove a group of Cygnets", }, { "setBaseUrl", &luascriptfunctions::iswa_setBaseUrl, - {}, "string", "sets the base url", } diff --git a/modules/space/spacemodule.cpp b/modules/space/spacemodule.cpp index a8de0b933d..254097b419 100644 --- a/modules/space/spacemodule.cpp +++ b/modules/space/spacemodule.cpp @@ -149,7 +149,6 @@ scripting::LuaLibrary SpaceModule::luaLibrary() const { { "convertFromRaDec", &space::luascriptfunctions::convertFromRaDec, - {}, "string/double, string/double, double", "Returns the cartesian world position of a ra dec coordinate with distance. " "If the coordinate is given as strings the format should be ra 'XhYmZs' and " @@ -159,7 +158,6 @@ scripting::LuaLibrary SpaceModule::luaLibrary() const { { "convertToRaDec", &space::luascriptfunctions::convertToRaDec, - {}, "double, double, double", "Returns the formatted ra, dec strings and distance for a given cartesian " "world coordinate." diff --git a/modules/statemachine/statemachinemodule.cpp b/modules/statemachine/statemachinemodule.cpp index 5075da664f..81cd6c1fe0 100644 --- a/modules/statemachine/statemachinemodule.cpp +++ b/modules/statemachine/statemachinemodule.cpp @@ -146,7 +146,6 @@ scripting::LuaLibrary StateMachineModule::luaLibrary() const { { "createStateMachine", &luascriptfunctions::createStateMachine, - {}, "table, table, [string]", "Creates a state machine from a list of states and transitions. See State " "and Transition documentation for details. The optional thrid argument is " @@ -156,14 +155,12 @@ scripting::LuaLibrary StateMachineModule::luaLibrary() const { { "destroyStateMachine", &luascriptfunctions::destroyStateMachine, - {}, "", "Destroys the current state machine and deletes all the memory." }, { "goToState", &luascriptfunctions::goToState, - {}, "string", "Triggers a transition from the current state to the state with the given " "identifier. Requires that the specified string corresponds to an existing " @@ -172,7 +169,6 @@ scripting::LuaLibrary StateMachineModule::luaLibrary() const { { "setInitialState", &luascriptfunctions::setInitialState, - {}, "string", "Immediately sets the current state to the state with the given name, if " "it exists. This is done without doing a transition and completely ignores " @@ -181,14 +177,12 @@ scripting::LuaLibrary StateMachineModule::luaLibrary() const { { "currentState", &luascriptfunctions::currentState, - {}, "", "Returns the string name of the current state that the statemachine is in." }, { "possibleTransitions", &luascriptfunctions::possibleTransitions, - {}, "", "Returns a list with the identifiers of all the states that can be " "transitioned to from the current state." @@ -196,7 +190,6 @@ scripting::LuaLibrary StateMachineModule::luaLibrary() const { { "canGoToState", &luascriptfunctions::canGoToState, - {}, "string", "Returns true if there is a defined transition between the current state and " "the given string name of a state, otherwise false" @@ -204,7 +197,6 @@ scripting::LuaLibrary StateMachineModule::luaLibrary() const { { "printCurrentStateInfo", &luascriptfunctions::printCurrentStateInfo, - {}, "", "Prints information about the current state and possible transitions to the " "log." @@ -212,7 +204,6 @@ scripting::LuaLibrary StateMachineModule::luaLibrary() const { { "saveToDotFile", &luascriptfunctions::saveToDotFile, - {}, "string, [string]", "Saves the current state machine to a .dot file as a directed graph. The " "resulting graph can be rendered using external tools such as Graphviz. " diff --git a/modules/sync/syncmodule.cpp b/modules/sync/syncmodule.cpp index 7a0a82c0da..df23f84188 100644 --- a/modules/sync/syncmodule.cpp +++ b/modules/sync/syncmodule.cpp @@ -150,7 +150,6 @@ scripting::LuaLibrary SyncModule::luaLibrary() const { { "syncResource", &luascriptfunctions::syncResource, - {}, "string, number", "Synchronizes the http resource identified by the name passed as the " "first parameter and the version provided as the second parameter. The " @@ -159,7 +158,6 @@ scripting::LuaLibrary SyncModule::luaLibrary() const { { "unsyncResource", &luascriptfunctions::unsyncResource, - {}, "string [, number]", "Unsynchronizes the http resources identified by the name passed as the " "first parameter by removing all data that was downloaded as part of the " diff --git a/modules/webbrowser/Tester.exe.manifest b/modules/webbrowser/Tester.exe.manifest new file mode 100644 index 0000000000..d36f084b65 --- /dev/null +++ b/modules/webbrowser/Tester.exe.manifest @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/engine/moduleengine.cpp b/src/engine/moduleengine.cpp index 235003d400..badc485706 100644 --- a/src/engine/moduleengine.cpp +++ b/src/engine/moduleengine.cpp @@ -171,7 +171,6 @@ scripting::LuaLibrary ModuleEngine::luaLibrary() { { "isLoaded", &luascriptfunctions::isLoaded, - {}, "string", "Checks whether a specific module is loaded" } diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index ae7f8c0469..45f93ab97a 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1742,7 +1742,6 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() { { "toggleShutdown", &luascriptfunctions::toggleShutdown, - {}, "", "Toggles the shutdown mode that will close the application after the " "count down timer is reached" @@ -1750,21 +1749,18 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() { { "writeDocumentation", &luascriptfunctions::writeDocumentation, - {}, "", "Writes out documentation files" }, { "downloadFile", &luascriptfunctions::downloadFile, - {}, "", "Downloads a file from Lua scope" }, { "addVirtualProperty", &luascriptfunctions::addVirtualProperty, - {}, "type, name, identifier," "[description, value, minimumValue, maximumValue]", "Adds a virtual property that will set a group of properties" @@ -1772,42 +1768,36 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() { { "removeVirtualProperty", &luascriptfunctions::removeVirtualProperty, - {}, "string", "Removes a previously added virtual property" }, { "removeAllVirtualProperties", &luascriptfunctions::removeAllVirtualProperties, - {}, "", "Remove all registered virtual properties" }, { "setScreenshotFolder", &luascriptfunctions::setScreenshotFolder, - {}, "string", "Sets the folder used for storing screenshots or session recording frames" }, { "addTag", &luascriptfunctions::addTag, - {}, "string, string", "Adds a tag (second argument) to a scene graph node (first argument)" }, { "removeTag", &luascriptfunctions::removeTag, - {}, "string, string", "Removes a tag (second argument) from a scene graph node (first argument)" }, { "createSingleColorImage", &luascriptfunctions::createSingleColorImage, - {}, "string, vec3", "Creates a 1 pixel image with a certain color in the cache folder and " "returns the path to the file. If a cached file with the given name " @@ -1818,7 +1808,6 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() { { "isMaster", &luascriptfunctions::isMaster, - {}, "", "Returns whether the current OpenSpace instance is the master node of a " "cluster configuration. If this instance is not part of a cluster, this " diff --git a/src/events/eventengine.cpp b/src/events/eventengine.cpp index b01e1502a0..34872eaebb 100644 --- a/src/events/eventengine.cpp +++ b/src/events/eventengine.cpp @@ -112,7 +112,6 @@ scripting::LuaLibrary EventEngine::luaLibrary() { res.functions.push_back({ "registerEventAction", &luascriptfunctions::registerEventAction, - {}, "string, string [, table]", "Registers an action (second parameter) to be executed whenever an event (first " "parameter) is encountered. If the optional third parameter is provided, it " @@ -122,7 +121,6 @@ scripting::LuaLibrary EventEngine::luaLibrary() { res.functions.push_back({ "unregisterEventAction", &luascriptfunctions::unregisterEventAction, - {}, "string, string [, table]", "Unregisters a specific combination of event (first parameter), action (second " "parameter), and potentially a filter (optional third argument)" diff --git a/src/interaction/actionmanager.cpp b/src/interaction/actionmanager.cpp index b16f79c5d6..545d6e0154 100644 --- a/src/interaction/actionmanager.cpp +++ b/src/interaction/actionmanager.cpp @@ -117,21 +117,18 @@ scripting::LuaLibrary ActionManager::luaLibrary() { { "hasAction", &luascriptfunctions::hasAction, - {}, "string", "Checks if the passed identifier corresponds to an action" }, { "removeAction", &luascriptfunctions::removeAction, - {}, "string", "Removes an existing action from the list of possible actions" }, { "registerAction", &luascriptfunctions::registerAction, - {}, "table", "Registers a new action. The table must at least contain the keys " "'Identifier' and 'Command' represeting the unique identifier and the " @@ -145,7 +142,6 @@ scripting::LuaLibrary ActionManager::luaLibrary() { { "action", &luascriptfunctions::action, - {}, "string", "Returns information about the action as a table with the keys " "'Identifier', 'Command', 'Name', 'Documentation', 'GuiPath', and " @@ -154,7 +150,6 @@ scripting::LuaLibrary ActionManager::luaLibrary() { { "actions", &luascriptfunctions::actions, - {}, "", "Returns all registered actions in the system as a table of tables each " "containing the keys 'Identifier', 'Command', 'Name', 'Documentation', " @@ -163,7 +158,6 @@ scripting::LuaLibrary ActionManager::luaLibrary() { { "triggerAction", &luascriptfunctions::triggerAction, - {}, "string", "Triggers the action given by the specified identifier" } diff --git a/src/interaction/keybindingmanager.cpp b/src/interaction/keybindingmanager.cpp index 29b3418c64..62a9bd7253 100644 --- a/src/interaction/keybindingmanager.cpp +++ b/src/interaction/keybindingmanager.cpp @@ -149,14 +149,12 @@ scripting::LuaLibrary KeybindingManager::luaLibrary() { { "clearKeys", &luascriptfunctions::clearKeys, - {}, "", "Clear all key bindings" }, { "clearKey", &luascriptfunctions::clearKey, - {}, "string or strings", "Unbinds the key or keys that have been provided. This function can be " "called with a single key or with an array of keys to remove all of the " @@ -165,14 +163,12 @@ scripting::LuaLibrary KeybindingManager::luaLibrary() { { "bindKey", &luascriptfunctions::bindKey, - {}, "string, string", "Binds a key by name to the action identified by the second argument" }, { "getKeyBinding", &luascriptfunctions::getKeyBindings, - {}, "string", "Returns a list of information about the keybindings for the provided key" } diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 44ab5daab0..61b8aa76e9 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -2559,7 +2559,6 @@ scripting::LuaLibrary SessionRecording::luaLibrary() { { "startRecording", &luascriptfunctions::startRecording, - {}, "string", "Starts a recording session. The string argument is the filename used " "for the file where the recorded keyframes are saved. " @@ -2568,7 +2567,6 @@ scripting::LuaLibrary SessionRecording::luaLibrary() { { "startRecordingAscii", &luascriptfunctions::startRecordingAscii, - {}, "string", "Starts a recording session. The string argument is the filename used " "for the file where the recorded keyframes are saved. " @@ -2577,14 +2575,12 @@ scripting::LuaLibrary SessionRecording::luaLibrary() { { "stopRecording", &luascriptfunctions::stopRecording, - {}, "void", "Stops a recording session" }, { "startPlayback", &luascriptfunctions::startPlaybackDefault, - {}, "string [, bool]", "Starts a playback session with keyframe times that are relative to " "the time since the recording was started (the same relative time " @@ -2598,7 +2594,6 @@ scripting::LuaLibrary SessionRecording::luaLibrary() { { "startPlaybackApplicationTime", &luascriptfunctions::startPlaybackApplicationTime, - {}, "string", "Starts a playback session with keyframe times that are relative to " "application time (seconds since OpenSpace application started). " @@ -2609,7 +2604,6 @@ scripting::LuaLibrary SessionRecording::luaLibrary() { { "startPlaybackRecordedTime", &luascriptfunctions::startPlaybackRecordedTime, - {}, "string [, bool]", "Starts a playback session with keyframe times that are relative to " "the time since the recording was started (the same relative time " @@ -2622,7 +2616,6 @@ scripting::LuaLibrary SessionRecording::luaLibrary() { { "startPlaybackSimulationTime", &luascriptfunctions::startPlaybackSimulationTime, - {}, "string", "Starts a playback session with keyframe times that are relative to " "the simulated date & time. The string argument is the filename to pull " @@ -2632,14 +2625,12 @@ scripting::LuaLibrary SessionRecording::luaLibrary() { { "stopPlayback", &luascriptfunctions::stopPlayback, - {}, - "void", + "", "Stops a playback session before playback of all keyframes is complete" }, { "enableTakeScreenShotDuringPlayback", &luascriptfunctions::enableTakeScreenShotDuringPlayback, - {}, "[int]", "Enables that rendered frames should be saved during playback. The " "parameter determines the number of frames that are exported per second " @@ -2648,14 +2639,12 @@ scripting::LuaLibrary SessionRecording::luaLibrary() { { "disableTakeScreenShotDuringPlayback", &luascriptfunctions::disableTakeScreenShotDuringPlayback, - {}, - "void", + "", "Used to disable that renderings are saved during playback" }, { "fileFormatConversion", &luascriptfunctions::fileFormatConversion, - {}, "string", "Performs a conversion of the specified file to the most most recent " "file format, creating a copy of the recording file." @@ -2663,14 +2652,12 @@ scripting::LuaLibrary SessionRecording::luaLibrary() { { "setPlaybackPause", &luascriptfunctions::setPlaybackPause, - {}, "bool", "Pauses or resumes the playback progression through keyframes" }, { "togglePlaybackPause", &luascriptfunctions::togglePlaybackPause, - {}, "", "Toggles the pause function, i.e. temporarily setting the delta time to 0" " and restoring it afterwards" @@ -2678,7 +2665,6 @@ scripting::LuaLibrary SessionRecording::luaLibrary() { { "isPlayingBack", & luascriptfunctions::isPlayingBack, - {}, "", "Returns true if session recording is currently playing back a recording" } diff --git a/src/mission/missionmanager.cpp b/src/mission/missionmanager.cpp index 1ec94598b4..5aa71ffac8 100644 --- a/src/mission/missionmanager.cpp +++ b/src/mission/missionmanager.cpp @@ -111,28 +111,24 @@ scripting::LuaLibrary MissionManager::luaLibrary() { { "loadMission", &luascriptfunctions::loadMission, - {}, "string", "Load mission phases from file" }, { "unloadMission", &luascriptfunctions::unloadMission, - {}, "string", "Unloads a previously loaded mission" }, { "hasMission", &luascriptfunctions::hasMission, - {}, "string", "Returns whether a mission with the provided name has been loaded" }, { "setCurrentMission", &luascriptfunctions::setCurrentMission, - {}, "string", "Set the currnet mission" }, diff --git a/src/navigation/navigationhandler.cpp b/src/navigation/navigationhandler.cpp index 4d840c07f4..b645c6a4cc 100644 --- a/src/navigation/navigationhandler.cpp +++ b/src/navigation/navigationhandler.cpp @@ -604,7 +604,6 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() { { "getNavigationState", &luascriptfunctions::getNavigationState, - {}, "[string]", "Return the current navigation state as a lua table. The optional " "argument is the scene graph node to use as reference frame. By default, " @@ -616,14 +615,12 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() { { "setNavigationState", &luascriptfunctions::setNavigationState, - {}, "table", "Set the navigation state. The argument must be a valid Navigation State." }, { "saveNavigationState", &luascriptfunctions::saveNavigationState, - {}, "string, [string]", "Save the current navigation state to a file with the path given by the " "first argument. The optoinal second argument is the scene graph node to " @@ -635,7 +632,6 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() { { "loadNavigationState", &luascriptfunctions::loadNavigationState, - {}, "string", "Load a navigation state from file. The file should be a lua file " "returning the navigation state as a table formatted as a " @@ -644,21 +640,18 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() { { "retargetAnchor", &luascriptfunctions::retargetAnchor, - {}, "void", "Reset the camera direction to point at the anchor node" }, { "retargetAim", &luascriptfunctions::retargetAim, - {}, "void", "Reset the camera direction to point at the aim node" }, { "bindJoystickAxis", &luascriptfunctions::bindJoystickAxis, - {}, "name, axis, axisType [, isInverted, isNormalized, isSticky, sensitivity]", "Finds the input joystick with the given 'name' and binds the axis " "identified by the second argument to be used as the type identified by " @@ -672,7 +665,6 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() { { "bindJoystickAxisProperty", &luascriptfunctions::bindJoystickAxisProperty, - {}, "name, axis, propertyUri [, min, max, isInverted, isSticky, sensitivity, " "isRemote]", "Finds the input joystick with the given 'name' and binds the axis " @@ -690,7 +682,6 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() { { "joystickAxis", &luascriptfunctions::joystickAxis, - {}, "name, axis", "Finds the input joystick with the given 'name' and returns the joystick " "axis information for the passed axis. The information that is returned " @@ -704,7 +695,6 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() { { "setAxisDeadZone", &luascriptfunctions::setJoystickAxisDeadzone, - {}, "name, axis, float", "Finds the input joystick with the given 'name' and sets the deadzone " "for a particular joystick axis, which means that any input less than " @@ -713,7 +703,6 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() { { "bindJoystickButton", &luascriptfunctions::bindJoystickButton, - {}, "name, button, string [, string, string, bool]", "Finds the input joystick with the given 'name' and binds a Lua script " "given by the third argument to be executed when the joystick button " @@ -728,7 +717,6 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() { { "clearJoystickButton", &luascriptfunctions::clearJoystickButton, - {}, "name, button", "Finds the input joystick with the given 'name' and removes all commands " "that are currently bound to the button identified by the second argument." @@ -736,7 +724,6 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() { { "joystickButton", &luascriptfunctions::joystickButton, - {}, "name, button", "Finds the input joystick with the given 'name' and returns the script " "that is currently bound to be executed when the provided button is " @@ -745,35 +732,30 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() { { "addGlobalRotation", &luascriptfunctions::addGlobalRotation, - {}, "double, double", "Directly adds to the global rotation of the camera" }, { "addLocalRotation", &luascriptfunctions::addLocalRotation, - {}, "double, double", "Directly adds to the local rotation of the camera" }, { "addTruckMovement", &luascriptfunctions::addTruckMovement, - {}, "double, double", "Directly adds to the truck movement of the camera" }, { "addLocalRoll", &luascriptfunctions::addLocalRoll, - {}, "double, double", "Directly adds to the local roll of the camera" }, { "addGlobalRoll", &luascriptfunctions::addGlobalRoll, - {}, "double, double", "Directly adds to the global roll of the camera" } diff --git a/src/navigation/pathnavigator.cpp b/src/navigation/pathnavigator.cpp index 94dff5aa2c..2895e2e322 100644 --- a/src/navigation/pathnavigator.cpp +++ b/src/navigation/pathnavigator.cpp @@ -391,35 +391,30 @@ scripting::LuaLibrary PathNavigator::luaLibrary() { { "isFlying", &luascriptfunctions::isFlying, - {}, "", "Returns true if a camera path is currently running, and false otherwise" }, { "continuePath", &luascriptfunctions::continuePath, - {}, "", "Continue playing a paused camera path" }, { "pausePath", &luascriptfunctions::pausePath, - {}, "", "Pause a playing camera path" }, { "stopPath", &luascriptfunctions::stopPath, - {}, "", "Stops a path, if one is being played" }, { "goTo", &luascriptfunctions::goTo, - {}, "string [, bool, double]", "Move the camera to the node with the specified identifier. The optional " "double specifies the duration of the motion. If the optional bool is " @@ -429,7 +424,6 @@ scripting::LuaLibrary PathNavigator::luaLibrary() { { "goToHeight", &luascriptfunctions::goToHeight, - {}, "string, double [, bool, double]", "Move the camera to the node with the specified identifier. The second " "argument is the desired target height above the target node's bounding " @@ -441,7 +435,6 @@ scripting::LuaLibrary PathNavigator::luaLibrary() { { "goToNavigationState", &luascriptfunctions::goToNavigationState, - {}, "table, [double]", "Create a path to the navigation state described by the input table. " "The optional double specifies the target duration of the motion. Note " @@ -451,7 +444,6 @@ scripting::LuaLibrary PathNavigator::luaLibrary() { { "createPath", &luascriptfunctions::createPath, - {}, "table", "Create the path as described by the lua table input argument" }, diff --git a/src/network/parallelpeer.cpp b/src/network/parallelpeer.cpp index b5ee89dd38..688902ed65 100644 --- a/src/network/parallelpeer.cpp +++ b/src/network/parallelpeer.cpp @@ -736,28 +736,24 @@ scripting::LuaLibrary ParallelPeer::luaLibrary() { { "connect", &luascriptfunctions::connect, - {}, "", "Connect to parallel" }, { "disconnect", &luascriptfunctions::disconnect, - {}, "", "Disconnect from parallel" }, { "requestHostship", &luascriptfunctions::requestHostship, - {}, "", "Request to be the host for this session" }, { "resignHostship", &luascriptfunctions::resignHostship, - {}, "", "Resign hostship" }, diff --git a/src/rendering/dashboard.cpp b/src/rendering/dashboard.cpp index 1a9ef79422..92ae69f649 100644 --- a/src/rendering/dashboard.cpp +++ b/src/rendering/dashboard.cpp @@ -152,21 +152,18 @@ scripting::LuaLibrary Dashboard::luaLibrary() { { "addDashboardItem", &luascriptfunctions::addDashboardItem, - {}, "table", "Adds a new dashboard item to the main dashboard." }, { "removeDashboardItem", &luascriptfunctions::removeDashboardItem, - {}, "string", "Removes the dashboard item with the specified identifier." }, { "clearDashboardItems", &luascriptfunctions::clearDashboardItems, - {}, "", "Removes all dashboard items from the main dashboard." } diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index b9c4bafc9f..cf019622db 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -1060,7 +1060,6 @@ scripting::LuaLibrary RenderEngine::luaLibrary() { { "addScreenSpaceRenderable", &luascriptfunctions::addScreenSpaceRenderable, - {}, "table", "Will create a ScreenSpaceRenderable from a lua Table and add it in the " "RenderEngine" @@ -1068,7 +1067,6 @@ scripting::LuaLibrary RenderEngine::luaLibrary() { { "removeScreenSpaceRenderable", &luascriptfunctions::removeScreenSpaceRenderable, - {}, "string", "Given a ScreenSpaceRenderable name this script will remove it from the " "renderengine" @@ -1076,12 +1074,11 @@ scripting::LuaLibrary RenderEngine::luaLibrary() { { "takeScreenshot", &luascriptfunctions::takeScreenshot, - {}, "", "Take a screenshot and return the screenshot number. The screenshot will " "be stored in the ${SCREENSHOTS} folder. " } - }, + } }; } diff --git a/src/scene/assetmanager.cpp b/src/scene/assetmanager.cpp index c129207ed0..346adf3c7a 100644 --- a/src/scene/assetmanager.cpp +++ b/src/scene/assetmanager.cpp @@ -134,14 +134,12 @@ scripting::LuaLibrary AssetManager::luaLibrary() { { "add", &luascriptfunctions::asset::add, - { this }, "string", "" }, { "remove", &luascriptfunctions::asset::remove, - { this }, "string", "" } diff --git a/src/scene/assetmanager_lua.inl b/src/scene/assetmanager_lua.inl index a27e6a6bf4..0c8834af9c 100644 --- a/src/scene/assetmanager_lua.inl +++ b/src/scene/assetmanager_lua.inl @@ -31,13 +31,11 @@ namespace openspace::luascriptfunctions::asset { int add(lua_State* L) { ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::add"); - AssetManager* assetManager = reinterpret_cast( - lua_touserdata(L, lua_upvalueindex(1)) - ); + AssetManager& assetManager = global::openSpaceEngine->assetManager(); const std::string assetName = ghoul::lua::value(L); if (global::renderEngine->scene()) { - assetManager->add(assetName); + assetManager.add(assetName); } else { // The scene might not exist yet if OpenSpace was started without specifying an @@ -51,21 +49,18 @@ int add(lua_State* L) { int remove(lua_State* L) { ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::remove"); - AssetManager* assetManager = - reinterpret_cast(lua_touserdata(L, lua_upvalueindex(1))); + AssetManager& assetManager = global::openSpaceEngine->assetManager(); const std::string assetName = ghoul::lua::value(L); - assetManager->remove(assetName); + assetManager.remove(assetName); return 0; } int removeAll(lua_State* L) { ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::removeAll"); - AssetManager* assetManager = - reinterpret_cast(lua_touserdata(L, lua_upvalueindex(1))); - - assetManager->removeAll(); + AssetManager& assetManager = global::openSpaceEngine->assetManager(); + assetManager.removeAll(); return 0; } diff --git a/src/scene/profile.cpp b/src/scene/profile.cpp index 9ded721ecc..4fbae6dbac 100644 --- a/src/scene/profile.cpp +++ b/src/scene/profile.cpp @@ -718,7 +718,6 @@ scripting::LuaLibrary Profile::luaLibrary() { { "saveSettingsToProfile", &luascriptfunctions::saveSettingsToProfile, - {}, "[string, bool]", "Collects all changes that have been made since startup, including all " "property changes and assets required, requested, or removed. All " diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 857040cd88..f13197155b 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -798,7 +798,6 @@ scripting::LuaLibrary Scene::luaLibrary() { { "setPropertyValue", &luascriptfunctions::property_setValue, - {}, "name, value [, duration, easing, optimization]", "Sets all property(s) identified by the URI (with potential wildcards) " "in the first argument. The second argument can be any type, but it has " @@ -823,7 +822,6 @@ scripting::LuaLibrary Scene::luaLibrary() { { "setPropertyValueSingle", &luascriptfunctions::property_setValueSingle, - {}, "URI, value [, duration, easing]", "Sets the property identified by the URI in the first argument. The " "second argument can be any type, but it has to match the type that the " @@ -839,21 +837,18 @@ scripting::LuaLibrary Scene::luaLibrary() { { "hasProperty", &luascriptfunctions::property_hasProperty, - {}, "string", "Returns whether a property with the given URI exists" }, { "getPropertyValue", &luascriptfunctions::property_getValue, - {}, "string", "Returns the value the property, identified by the provided URI." }, { "getProperty", &luascriptfunctions::property_getProperty, - {}, "string", "Returns a list of property identifiers that match the passed regular " "expression" @@ -861,7 +856,6 @@ scripting::LuaLibrary Scene::luaLibrary() { { "loadScene", &luascriptfunctions::loadScene, - {}, "string", "Loads the scene found at the file passed as an " "argument. If a scene is already loaded, it is unloaded first" @@ -869,7 +863,6 @@ scripting::LuaLibrary Scene::luaLibrary() { { "addSceneGraphNode", &luascriptfunctions::addSceneGraphNode, - {}, "table", "Loads the SceneGraphNode described in the table and adds it to the " "SceneGraph" @@ -877,14 +870,12 @@ scripting::LuaLibrary Scene::luaLibrary() { { "removeSceneGraphNode", &luascriptfunctions::removeSceneGraphNode, - {}, "string", "Removes the SceneGraphNode identified by name" }, { "removeSceneGraphNodesFromRegex", &luascriptfunctions::removeSceneGraphNodesFromRegex, - {}, "string", "Removes all SceneGraphNodes with identifiers matching the input regular " "expression" @@ -892,7 +883,6 @@ scripting::LuaLibrary Scene::luaLibrary() { { "hasSceneGraphNode", &luascriptfunctions::hasSceneGraphNode, - {}, "string", "Checks whether the specifies SceneGraphNode is present in the current " "scene" @@ -900,7 +890,6 @@ scripting::LuaLibrary Scene::luaLibrary() { { "addInterestingTime", &luascriptfunctions::addInterestingTime, - {}, "string, string", "Adds an interesting time to the current scene. The first argument is " "the name of the time and the second argument is the time itself in the " @@ -909,7 +898,6 @@ scripting::LuaLibrary Scene::luaLibrary() { { "worldPosition", &luascriptfunctions::worldPosition, - {}, "string", "Returns the world position of the scene graph node with the given " "string as identifier" @@ -917,7 +905,6 @@ scripting::LuaLibrary Scene::luaLibrary() { { "worldRotation", & luascriptfunctions::worldRotation, - {}, "string", "Returns the world rotation matrix of the scene graph node with the " "given string as identifier" @@ -925,7 +912,6 @@ scripting::LuaLibrary Scene::luaLibrary() { { "setParent", &luascriptfunctions::setParent, - {}, "string, string", "The scene graph node identified by the first string is reparented to be " "a child of the scene graph node identified by the second string." diff --git a/src/scripting/lualibrary.cpp b/src/scripting/lualibrary.cpp index 245c40b42c..edd6929671 100644 --- a/src/scripting/lualibrary.cpp +++ b/src/scripting/lualibrary.cpp @@ -24,10 +24,60 @@ #include +#include + namespace openspace::scripting { bool LuaLibrary::operator<(const LuaLibrary& rhs) const { return name < rhs.name; } +void LuaLibrary::merge(LuaLibrary rhs) { + for (const LuaLibrary::Function& fun : rhs.functions) { + const auto itf = std::find_if( + functions.begin(), + functions.end(), + [&fun](const LuaLibrary::Function& function) { + return fun.name == function.name; + } + ); + if (itf != functions.end()) { + // the function with the desired name is already present, but we don't + // want to overwrite it + LERRORC( + "LuaLibrary", + fmt::format( + "Lua function '{}' in library '{}' has been defined twice", + fun.name, rhs.name + ) + ); + return; + } + else { + functions.push_back(fun); + } + } + + for (LuaLibrary s : rhs.subLibraries) { + if (s.name.empty()) { + LERRORC("LuaLibrary", "Sublibraries must have a non-empty name"); + } + + auto it = std::find_if( + subLibraries.begin(), subLibraries.end(), + [&s](const LuaLibrary& lib) { return lib.name == s.name; } + ); + if (it == subLibraries.end()) { + subLibraries.push_back(std::move(s)); + } + else { + it->merge(std::move(s)); + } + } + + for (const std::filesystem::path& script : rhs.scripts) { + scripts.push_back(script); + } +} + } // namespace openspace::scripting diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index dc917b8de8..fc523543cd 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -43,6 +43,80 @@ namespace { constexpr const char* _loggerCat = "ScriptEngine"; constexpr const int TableOffset = -3; // top-first argument-second argument + + std::vector luaFunctions(const openspace::scripting::LuaLibrary& library, + std::string prefix) + { + using namespace openspace::scripting; + + std::vector result; + + std::string total = prefix; + if (!library.name.empty()) { + total += library.name + "."; + } + + for (const LuaLibrary::Function& function : library.functions) { + result.push_back(total + function.name); + } + + for (const LuaLibrary& sl : library.subLibraries) { + std::vector r = luaFunctions(sl, total); + result.insert(result.end(), r.begin(), r.end()); + } + + for (const LuaLibrary::Documentation& doc : library.documentations) { + result.push_back(total + doc.name); + } + + return result; + } + + void toJson(const openspace::scripting::LuaLibrary& library, std::stringstream& json) + { + constexpr const char* replStr = R"("{}": "{}", )"; + constexpr const char* replStr2 = R"("{}": "{}")"; + + using namespace openspace; + using namespace openspace::scripting; + + json << "{"; + json << fmt::format(replStr, "library", library.name); + json << "\"functions\": ["; + + for (const LuaLibrary::Function& f : library.functions) { + json << "{"; + json << fmt::format(replStr, "name", f.name); + json << fmt::format(replStr, "arguments", escapedJson(f.argumentText)); + json << fmt::format(replStr2, "help", escapedJson(f.helpText)); + json << "}"; + if (&f != &library.functions.back() || !library.documentations.empty()) { + json << ","; + } + } + + for (const LuaLibrary::Documentation& doc : library.documentations) { + json << "{"; + json << fmt::format(replStr, "name", doc.name); + json << fmt::format(replStr, "arguments", escapedJson(doc.parameter)); + json << fmt::format(replStr2, "help", escapedJson(doc.description)); + json << "}"; + if (&doc != &library.documentations.back()) { + json << ","; + } + } + + json << "],"; + + json << "\"subLibraries\": ["; + for (const LuaLibrary& sl : library.subLibraries) { + toJson(sl, json); + if (&sl != &library.subLibraries.back()) { + json << ","; + } + } + json << "]}"; + } } // namespace namespace openspace::scripting { @@ -99,8 +173,7 @@ ghoul::lua::LuaState* ScriptEngine::luaState() { void ScriptEngine::addLibrary(LuaLibrary library) { ZoneScoped - auto sortFunc = [](const LuaLibrary::Function& lhs, const LuaLibrary::Function& rhs) - { + auto sortFunc = [](const LuaLibrary::Function& lhs, const LuaLibrary::Function& rhs) { return lhs.name < rhs.name; }; @@ -111,50 +184,18 @@ void ScriptEngine::addLibrary(LuaLibrary library) { [&library](const LuaLibrary& lib) { return lib.name == library.name; } ); - if (it == _registeredLibraries.end()) { - // If not, we can add it after we sorted it - std::sort(library.functions.begin(), library.functions.end(), sortFunc); - _registeredLibraries.push_back(std::move(library)); - std::sort(_registeredLibraries.begin(), _registeredLibraries.end()); - } - else { - // otherwise, we merge the libraries - - LuaLibrary merged = *it; - for (const LuaLibrary::Function& fun : library.functions) { - const auto itf = std::find_if( - merged.functions.begin(), - merged.functions.end(), - [&fun](const LuaLibrary::Function& function) { - return fun.name == function.name; - } - ); - if (itf != merged.functions.end()) { - // the function with the desired name is already present, but we don't - // want to overwrite it - LERROR(fmt::format( - "Lua function '{}' in library '{}' has been defined twice", - fun.name, - library.name - )); - return; - } - else { - merged.functions.push_back(fun); - } - } - - for (const std::filesystem::path& script : library.scripts) { - merged.scripts.push_back(script); - } - + if (it != _registeredLibraries.end()) { + // if we found the library, we want to merge them + LuaLibrary cpy = *it; + cpy.merge(std::move(library)); _registeredLibraries.erase(it); - - // Sort the merged library before inserting it - std::sort(merged.functions.begin(), merged.functions.end(), sortFunc); - _registeredLibraries.push_back(std::move(merged)); - std::sort(_registeredLibraries.begin(), _registeredLibraries.end()); + library = cpy; } + + // If not, we can add it after we sorted it + std::sort(library.functions.begin(), library.functions.end(), sortFunc); + _registeredLibraries.push_back(std::move(library)); + std::sort(_registeredLibraries.begin(), _registeredLibraries.end()); } bool ScriptEngine::hasLibrary(const std::string& name) { @@ -307,13 +348,26 @@ void ScriptEngine::addLibraryFunctions(lua_State* state, LuaLibrary& library, lua_pop(state, 1); } ghoul::lua::push(state, p.name); - for (void* d : p.userdata) { - lua_pushlightuserdata(state, d); - } - lua_pushcclosure(state, p.function, static_cast(p.userdata.size())); + lua_pushcfunction(state, p.function); lua_settable(state, TableOffset); } + for (LuaLibrary& sl : library.subLibraries) { + ghoul::lua::push(state, sl.name); + lua_newtable(state); + lua_settable(state, TableOffset); + + // Retrieve the table + ghoul::lua::push(state, sl.name); + lua_gettable(state, -2); + + // Add the library functions into the table + addLibraryFunctions(state, sl, Replace::No); + + // Pop the table + lua_pop(state, 1); + } + for (const std::filesystem::path& script : library.scripts) { // First we run the script to set its values in the current state ghoul::lua::runScriptFile(state, script.string()); @@ -363,7 +417,6 @@ void ScriptEngine::addBaseLibrary() { { "printTrace", &luascriptfunctions::printTrace, - {}, "*", "Logs the passed value to the installed LogManager with a LogLevel of " "'Trace'" @@ -371,7 +424,6 @@ void ScriptEngine::addBaseLibrary() { { "printDebug", &luascriptfunctions::printDebug, - {}, "*", "Logs the passed value to the installed LogManager with a LogLevel of " "'Debug'" @@ -379,7 +431,6 @@ void ScriptEngine::addBaseLibrary() { { "printInfo", &luascriptfunctions::printInfo, - {}, "*", "Logs the passed value to the installed LogManager with a LogLevel of " "'Info'" @@ -387,7 +438,6 @@ void ScriptEngine::addBaseLibrary() { { "printWarning", &luascriptfunctions::printWarning, - {}, "*", "Logs the passed value to the installed LogManager with a LogLevel of " "'Warning'" @@ -395,7 +445,6 @@ void ScriptEngine::addBaseLibrary() { { "printError", &luascriptfunctions::printError, - {}, "*", "Logs the passed value to the installed LogManager with a LogLevel of " "'Error'" @@ -403,7 +452,6 @@ void ScriptEngine::addBaseLibrary() { { "printFatal", &luascriptfunctions::printFatal, - {}, "*", "Logs the passed value to the installed LogManager with a LogLevel of " "'Fatal'" @@ -411,7 +459,6 @@ void ScriptEngine::addBaseLibrary() { { "absPath", &luascriptfunctions::absolutePath, - {}, "string", "Returns the absolute path to the passed path, resolving path tokens as " "well as resolving relative paths" @@ -419,28 +466,24 @@ void ScriptEngine::addBaseLibrary() { { "fileExists", &luascriptfunctions::fileExists, - {}, "string", "Checks whether the provided file exists." }, { "readFile", &luascriptfunctions::readFile, - {}, "string", "Reads a file from disk and return its contents" }, { "directoryExists", &luascriptfunctions::directoryExists, - {}, "string", "Chckes whether the provided directory exists." }, { "setPathToken", &luascriptfunctions::setPathToken, - {}, "string, string", "Registers a new path token provided by the first argument to the path " "provided in the second argument" @@ -448,7 +491,6 @@ void ScriptEngine::addBaseLibrary() { { "walkDirectory", &luascriptfunctions::walkDirectory, - {}, "string [bool, bool]", "Walks a directory and returns all contents (files and directories) of " "the directory as absolute paths. The first argument is the path of the " @@ -459,7 +501,6 @@ void ScriptEngine::addBaseLibrary() { { "walkDirectoryFiles", &luascriptfunctions::walkDirectoryFiles, - {}, "string [bool, bool]", "Walks a directory and returns the files of the directory as absolute " "paths. The first argument is the path of the directory that should be " @@ -470,7 +511,6 @@ void ScriptEngine::addBaseLibrary() { { "walkDirectoryFolder", &luascriptfunctions::walkDirectoryFolder, - {}, "string [bool, bool]", "Walks a directory and returns the subfolders of the directory as " "absolute paths. The first argument is the path of the directory that " @@ -481,7 +521,6 @@ void ScriptEngine::addBaseLibrary() { { "directoryForPath", &luascriptfunctions::directoryForPath, - {}, "string", "This function extracts the directory part of the passed path. For " "example, if the parameter is 'C:/OpenSpace/foobar/foo.txt', this " @@ -490,7 +529,6 @@ void ScriptEngine::addBaseLibrary() { { "unzipFile", &luascriptfunctions::unzipFile, - {}, "string, string [bool]", "This function extracts the contents of a zip file. The first " "argument is the path to the zip file. The second argument is the " @@ -501,10 +539,9 @@ void ScriptEngine::addBaseLibrary() { { "saveLastChangeToProfile", &luascriptfunctions::saveLastChangeToProfile, - {}, "", - "This function saves the last script log action into the profile " - }, + "This function saves the last script log action into the profile." + } } }; addLibrary(lib); @@ -567,27 +604,10 @@ std::vector ScriptEngine::allLuaFunctions() const { ZoneScoped std::vector result; - for (const LuaLibrary& library : _registeredLibraries) { - for (const LuaLibrary::Function& function : library.functions) { - std::string total = "openspace."; - if (!library.name.empty()) { - total += library.name + "."; - } - total += function.name; - result.push_back(std::move(total)); - } - - for (const LuaLibrary::Documentation& doc : library.documentations) { - std::string total = "openspace."; - if (!library.name.empty()) { - total += library.name + "."; - } - total += doc.name; - result.push_back(std::move(total)); - } + std::vector r = luaFunctions(library, "openspace."); + result.insert(result.end(), r.begin(), r.end()); } - return result; } @@ -600,42 +620,12 @@ std::string ScriptEngine::generateJson() const { bool first = true; for (const LuaLibrary& l : _registeredLibraries) { - constexpr const char* replStr = R"("{}": "{}", )"; - constexpr const char* replStr2 = R"("{}": "{}")"; - if (!first) { json << ","; } first = false; - json << "{"; - json << fmt::format(replStr, "library", l.name); - json << "\"functions\": ["; - - for (const LuaLibrary::Function& f : l.functions) { - json << "{"; - json << fmt::format(replStr, "name", f.name); - json << fmt::format(replStr, "arguments", escapedJson(f.argumentText)); - json << fmt::format(replStr2, "help", escapedJson(f.helpText)); - json << "}"; - if (&f != &l.functions.back() || !l.documentations.empty()) { - json << ","; - } - } - - for (const LuaLibrary::Documentation& doc : l.documentations) { - json << "{"; - json << fmt::format(replStr, "name", doc.name); - json << fmt::format(replStr, "arguments", escapedJson(doc.parameter)); - json << fmt::format(replStr2, "help", escapedJson(doc.description)); - json << "}"; - if (&doc != &l.documentations.back()) { - json << ","; - } - } - - json << "]}"; - + toJson(l, json); } json << "]"; diff --git a/src/scripting/scriptscheduler.cpp b/src/scripting/scriptscheduler.cpp index d0abf88b65..8d3dc0af13 100644 --- a/src/scripting/scriptscheduler.cpp +++ b/src/scripting/scriptscheduler.cpp @@ -297,7 +297,6 @@ LuaLibrary ScriptScheduler::luaLibrary() { { "loadFile", &luascriptfunctions::loadFile, - {}, "string", "Load timed scripts from a Lua script file that returns a list of " "scheduled scripts." @@ -305,7 +304,6 @@ LuaLibrary ScriptScheduler::luaLibrary() { { "loadScheduledScript", &luascriptfunctions::loadScheduledScript, - {}, "string, string, (string, string)", "Load a single scheduled script. The first argument is the time at which " "the scheduled script is triggered, the second argument is the script " @@ -317,7 +315,6 @@ LuaLibrary ScriptScheduler::luaLibrary() { { "setModeApplicationTime", &luascriptfunctions::setModeApplicationTime, - {}, "", "Sets the time reference for scheduled scripts to application time " "(seconds since OpenSpace application started)." @@ -325,7 +322,6 @@ LuaLibrary ScriptScheduler::luaLibrary() { { "setModeRecordedTime", &luascriptfunctions::setModeRecordedTime, - {}, "", "Sets the time reference for scheduled scripts to the time since the " "recording was started (the same relative time applies to playback)." @@ -333,7 +329,6 @@ LuaLibrary ScriptScheduler::luaLibrary() { { "setModeSimulationTime", &luascriptfunctions::setModeSimulationTime, - {}, "", "Sets the time reference for scheduled scripts to the simulated " "date & time (J2000 epoch seconds)." @@ -341,10 +336,9 @@ LuaLibrary ScriptScheduler::luaLibrary() { { "clear", &luascriptfunctions::clear, - {}, "", "Clears all scheduled scripts." - }, + } } }; } diff --git a/src/scripting/systemcapabilitiesbinding.cpp b/src/scripting/systemcapabilitiesbinding.cpp index f48109ce6a..4110b87034 100644 --- a/src/scripting/systemcapabilitiesbinding.cpp +++ b/src/scripting/systemcapabilitiesbinding.cpp @@ -237,7 +237,6 @@ LuaLibrary generalSystemCapabilities() { { "os", &luascripting::general::operatingSystem, - {}, "", "This function returns a string identifying the currently running " "operating system. For Windows, the string is 'windows', for MacOS, it " @@ -247,7 +246,6 @@ LuaLibrary generalSystemCapabilities() { { "fullOperatingSystem", &luascripting::general::fullOperatingSystem, - {}, "", "Returns the operating system as a string. The exact format of the " "returned string is implementation and operating system-dependent but it " @@ -256,7 +254,6 @@ LuaLibrary generalSystemCapabilities() { { "installedMainMemory", &luascripting::general::installedMainMemory, - {}, "", "Returns the amount of available, installed main memory (RAM) on the " "system in MB." @@ -264,35 +261,30 @@ LuaLibrary generalSystemCapabilities() { { "cores", &luascripting::general::cores, - {}, "", "Returns the number of cores." }, { "cacheLineSize", &luascripting::general::cacheLineSize, - {}, "", "Returns the cache line size." }, { "L2Associativity", &luascripting::general::L2Associativity, - {}, "", "Returns the L2 associativity." }, { "cacheSize", &luascripting::general::cacheSize, - {}, "", "Returns the cache size." }, { "extensions", &luascripting::general::extensions, - {}, "", "Returns all supported exteions as comma-separated string." } @@ -307,7 +299,6 @@ LuaLibrary openglSystemCapabilities() { { "hasOpenGLVersion", &luascripting::opengl::hasOpenGLVersion, - {}, "string", "Tests whether the current instance supports the passed OpenGL version. " "The parameter has to have the form 'X.Y' or 'X.Y.Z'." @@ -315,14 +306,12 @@ LuaLibrary openglSystemCapabilities() { { "openGLVersion", &luascripting::opengl::openGLVersion, - {}, "", "Returns the maximum OpenGL version that is supported on this platform." }, { "glslCompiler", &luascripting::opengl::glslCompiler, - {}, "", "Returns the value of a call to glGetString(GL_VENDOR). " "This will give detailed information about the vendor of the main " @@ -332,28 +321,24 @@ LuaLibrary openglSystemCapabilities() { { "gpuVendor", &luascripting::opengl::gpuVendor, - {}, "", "Returns the vendor of the main graphics card." }, { "extensions", &luascripting::opengl::extensions, - {}, "", "Returns all available extensions as a list of names." }, { "isExtensionSupported", &luascripting::opengl::isExtensionSupported, - {}, "string", "Checks is a specific extension is supported or not." }, { "maxTextureUnits", &luascripting::opengl::maxTextureUnits, - {}, "", "Returns the maximum number of texture units that are available on the " "main graphics card." @@ -361,21 +346,18 @@ LuaLibrary openglSystemCapabilities() { { "max2DTextureSize", &luascripting::opengl::max2DTextureSize, - {}, "", "Returns the largest dimension for a 2D texture on this graphics card." }, { "max3DTextureSize", &luascripting::opengl::max3DTextureSize, - {}, "", "Returns the largest dimension for a 3D texture on this graphics card." }, { "maxAtomicCounterBufferBindings", &luascripting::opengl::maxAtomicCounterBufferBindings, - {}, "", "Returns the maximum number of atomic counter buffer bindings that are " "available on the main graphics card." @@ -383,7 +365,6 @@ LuaLibrary openglSystemCapabilities() { { "maxShaderStorageBufferBindings", &luascripting::opengl::maxShaderStorageBufferBindings, - {}, "", "Returns the maximum number of shader storage bindings that are " "available on the main graphics card." @@ -391,7 +372,6 @@ LuaLibrary openglSystemCapabilities() { { "maxUniformBufferBindings", &luascripting::opengl::maxUniformBufferBindings, - {}, "", "Returns the maximum number of uniform buffer bindings that are " "available on the main graphics card." diff --git a/src/util/spicemanager.cpp b/src/util/spicemanager.cpp index 6bb9810180..70bee60797 100644 --- a/src/util/spicemanager.cpp +++ b/src/util/spicemanager.cpp @@ -1345,7 +1345,6 @@ scripting::LuaLibrary SpiceManager::luaLibrary() { { "loadKernel", &luascriptfunctions::loadKernel, - {}, "string", "Loads the provided SPICE kernel by name. The name can contain path " "tokens, which are automatically resolved" @@ -1353,7 +1352,6 @@ scripting::LuaLibrary SpiceManager::luaLibrary() { { "unloadKernel", &luascriptfunctions::unloadKernel, - {}, "{string, number}", "Unloads the provided SPICE kernel. The name can contain path tokens, " "which are automatically resolved" @@ -1361,21 +1359,18 @@ scripting::LuaLibrary SpiceManager::luaLibrary() { { "getSpkCoverage", &luascriptfunctions::spkCoverage, - {}, "string", "Returns a list of SPK coverage intervals for the target." }, { "getCkCoverage", &luascriptfunctions::ckCoverage, - {}, "string", "Returns a list of CK coverage intervals for the target." }, { "rotationMatrix", &luascriptfunctions::rotationMatrix, - {}, "{string, string, string}", "Returns the rotationMatrix for a given body in a frame of reference at " "a specific time. The first agument is the target body, the second is " @@ -1386,7 +1381,6 @@ scripting::LuaLibrary SpiceManager::luaLibrary() { { "position", &luascriptfunctions::position, - {}, "{string, string, string, string}", "Returns the position for a target by an observer in a frame of " "reference at a specific time. The first agument is the target body, the " @@ -1397,7 +1391,6 @@ scripting::LuaLibrary SpiceManager::luaLibrary() { { "getSpiceBodies", &luascriptfunctions::spiceBodies, - {}, "{ builtInFrames [, printValues] }", "Returns a list of Spice Bodies loaded into the system. Returns SPICE " "built in frames if builtInFrames. Returns User loaded frames if " diff --git a/src/util/time.cpp b/src/util/time.cpp index 0f94934e61..5e1be682d9 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -145,7 +145,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "setTime", &luascriptfunctions::time_setTime, - {}, "{number, string}", "Sets the current simulation time to the " "specified value. If the parameter is a number, the value is the number " @@ -157,7 +156,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "setDeltaTime", &luascriptfunctions::time_setDeltaTime, - {}, "number", "Sets the amount of simulation time that happens " "in one second of real time" @@ -165,7 +163,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "setDeltaTimeSteps", &luascriptfunctions::time_setDeltaTimeSteps, - {}, "List of numbers", "Sets the list of discrete delta time steps for the simulation speed " "that can be quickly jumped between. The list will be sorted to be in " @@ -175,7 +172,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "deltaTime", &luascriptfunctions::time_deltaTime, - {}, "", "Returns the amount of simulated time that passes in one " "second of real time" @@ -183,14 +179,12 @@ scripting::LuaLibrary Time::luaLibrary() { { "setPause", &luascriptfunctions::time_setPause, - {}, "bool", "Pauses the simulation time or restores the delta time" }, { "togglePause", &luascriptfunctions::time_togglePause, - {}, "", "Toggles the pause function, i.e. temporarily setting the delta time to " "0 and restoring it afterwards" @@ -198,7 +192,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "interpolateTime", &luascriptfunctions::time_interpolateTime, - {}, "{number, string} [, number]", "Sets the current simulation time to the specified value. " "If the first parameter is a number, the target is the number " @@ -211,7 +204,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "interpolateTimeRelative", &luascriptfunctions::time_interpolateTimeRelative, - {}, "number [, number]", "Increments the current simulation time by the specified number of " "seconds. If a second input value is given, the interpolation is done " @@ -220,7 +212,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "interpolateDeltaTime", &luascriptfunctions::time_interpolateDeltaTime, - {}, "number [, number]", "Sets the amount of simulation time that happens in one second of real " "time. If a second input value is given, the interpolation is done " @@ -229,7 +220,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "setNextDeltaTimeStep", &luascriptfunctions::time_setNextDeltaTimeStep, - {}, "", "Immediately set the simulation speed to the first delta time step in " "the list that is larger than the current choice of simulation speed, " @@ -238,7 +228,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "setPreviousDeltaTimeStep", &luascriptfunctions::time_setPreviousDeltaTimeStep, - {}, "", "Immediately set the simulation speed to the first delta time step in " "the list that is smaller than the current choice of simulation speed. " @@ -247,7 +236,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "interpolateNextDeltaTimeStep", &luascriptfunctions::time_interpolateNextDeltaTimeStep, - {}, "[number]", "Interpolate the simulation speed to the first delta time step in the " "list that is larger than the current simulation speed, if any. If an " @@ -257,7 +245,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "interpolatePreviousDeltaTimeStep", &luascriptfunctions::time_interpolatePreviousDeltaTimeStep, - {}, "[number]", "Interpolate the simulation speed to the first delta time step in the " "list that is smaller than the current simulation speed, if any. If an " @@ -267,7 +254,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "interpolatePause", &luascriptfunctions::time_interpolatePause, - {}, "bool [, number]", "Pauses the simulation time or restores the delta time. If a second " "input value is given, the interpolation is done over the specified " @@ -276,7 +262,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "interpolateTogglePause", &luascriptfunctions::time_interpolateTogglePause, - {}, "[number]", "Toggles the pause function, i.e. temporarily setting the delta time to 0" " and restoring it afterwards. If an input value is given, the " @@ -285,7 +270,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "pauseToggleViaKeyboard", &luascriptfunctions::time_pauseToggleViaKeyboard, - {}, "", "Toggles the pause function from a keypress. This function behaves like" " interpolateTogglePause during normal mode, and behaves like" @@ -294,7 +278,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "currentTime", &luascriptfunctions::time_currentTime, - {}, "", "Returns the current time as the number of seconds since " "the J2000 epoch" @@ -302,7 +285,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "UTC", &luascriptfunctions::time_currentTimeUTC, - {}, "", "Returns the current time as an ISO 8601 date string " "(YYYY-MM-DDTHH:MN:SS)" @@ -310,7 +292,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "currentWallTime", &luascriptfunctions::time_currentWallTime, - {}, "", "Returns the current wall time as an ISO 8601 date string " "(YYYY-MM-DDTHH-MN-SS) in the UTC timezone" @@ -318,7 +299,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "currentApplicationTime", &luascriptfunctions::time_currentApplicationTime, - {}, "", "Returns the current application time as the number of seconds " "since the OpenSpace application started" @@ -326,7 +306,6 @@ scripting::LuaLibrary Time::luaLibrary() { { "advancedTime", &luascriptfunctions::time_advancedTime, - {}, "string or number, string or number", "Modifies the passed time (first argument) by the delta time (second " "argument). The first argument can either be an ISO 8601 date string or " diff --git a/support/cmake/set_openspace_compile_settings.cmake b/support/cmake/set_openspace_compile_settings.cmake index 2cfd0a2e97..433150c308 100644 --- a/support/cmake/set_openspace_compile_settings.cmake +++ b/support/cmake/set_openspace_compile_settings.cmake @@ -87,9 +87,11 @@ function (set_openspace_compile_settings target) "/GL" # Whole program optimization ) else () - set(MSVC_WARNINGS ${MSVC_WARNINGS} - "/ZI" # Edit and continue support - ) + if (GHOUL_ENABLE_EDIT_CONTINUE) + set(MSVC_WARNINGS ${MSVC_WARNINGS} + "/ZI" # Edit and continue support + ) + endif () endif () set(CLANG_WARNINGS