diff --git a/include/openspace/scripting/scriptengine.h b/include/openspace/scripting/scriptengine.h index 4fb8671917..6a5c687d73 100644 --- a/include/openspace/scripting/scriptengine.h +++ b/include/openspace/scripting/scriptengine.h @@ -42,6 +42,7 @@ public: struct Function { std::string name; lua_CFunction function; + std::string argumentText; std::string helpText; }; std::string name; diff --git a/src/interaction/interactionhandler.cpp b/src/interaction/interactionhandler.cpp index 7ab85a2b73..6957623518 100644 --- a/src/interaction/interactionhandler.cpp +++ b/src/interaction/interactionhandler.cpp @@ -847,27 +847,32 @@ scripting::ScriptEngine::LuaLibrary InteractionHandler::luaLibrary() { { "setOrigin", &luascriptfunctions::setOrigin, - "setOrigin(): set the camera origin node by name" + "string", + "Set the camera origin node by name" }, { "clearKeys", &luascriptfunctions::clearKeys, - "clearKeys(): Clear all key bindings" + "", + "Clear all key bindings" }, { "bindKey", &luascriptfunctions::bindKey, - "bindKey(): binds a key by name to a lua string command" + "string, string", + "Binds a key by name to a lua string command" }, { "dt", &luascriptfunctions::dt, - "dt(): Get current frame time" + "", + "Get current frame time" }, { "distance", &luascriptfunctions::distance, - "distance(): Change distance to origin" + "number", + "Change distance to origin" } } }; diff --git a/src/interaction/luaconsole.cpp b/src/interaction/luaconsole.cpp index 4c14748453..22c0aea4f4 100644 --- a/src/interaction/luaconsole.cpp +++ b/src/interaction/luaconsole.cpp @@ -469,17 +469,20 @@ scripting::ScriptEngine::LuaLibrary LuaConsole::luaLibrary() { { "show", &luascriptfunctions::show, - "show(): Shows the console" + "", + "Shows the console" }, { "hide", &luascriptfunctions::hide, - "hide(): Hides the console" + "", + "Hides the console" }, { "toggle", &luascriptfunctions::toggle, - "toggle(): Toggles the console" + "", + "Toggles the console" } } }; diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 400382e7b3..09a8093f2a 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -509,12 +509,14 @@ scripting::ScriptEngine::LuaLibrary RenderEngine::luaLibrary() { { "printImage", &luascriptfunctions::printImage, - "printImage(): Renders the current image to a file on disk" + "", + "Renders the current image to a file on disk" }, { "visualizeABuffer", &luascriptfunctions::visualizeABuffer, - "visualizeABuffer(bool): Toggles the visualization of the ABuffer" + "bool", + "Toggles the visualization of the ABuffer" } }, }; diff --git a/src/scenegraph/scenegraph.cpp b/src/scenegraph/scenegraph.cpp index ae19ab2787..2784865358 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scenegraph/scenegraph.cpp @@ -523,20 +523,23 @@ scripting::ScriptEngine::LuaLibrary SceneGraph::luaLibrary() { { "setPropertyValue", &luascriptfunctions::property_setValue, - "setPropertyValue(string, *): Sets a property identified by the URI in " + "string, *", + "Sets a property identified by the URI in " "the first argument. The second argument can be any type, but it has to " " agree with the type that the property expects" }, { "getPropertyValue", &luascriptfunctions::property_getValue, - "getPropertyValue(string): Returns the value the property, identified by " + "string", + "Returns the value the property, identified by " "the provided URI." }, { "loadScene", &luascriptfunctions::loadScene, - "loadScene(string): Loads the scene found at the file passed as an " + "string", + "Loads the scene found at the file passed as an " "argument. If a scene is already loaded, it is unloaded first" } } diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 279285dd23..b99baee59f 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -382,43 +382,50 @@ void ScriptEngine::addBaseLibrary() { { "printDebug", &luascriptfunctions::printDebug, - "printDebug(*): Logs the passed value to the installed LogManager with a " + "*", + "Logs the passed value to the installed LogManager with a " "LogLevel of 'Debug'" }, { "printInfo", &luascriptfunctions::printInfo, - "printInfo(*): Logs the passed value to the installed LogManager with a " + "*", + "Logs the passed value to the installed LogManager with a " " LogLevel of 'Info'" }, { "printWarning", &luascriptfunctions::printWarning, - "printWarning(*): Logs the passed value to the installed LogManager with " + "*", + "Logs the passed value to the installed LogManager with " "a LogLevel of 'Warning'" }, { "printError", &luascriptfunctions::printError, - "printError(*): Logs the passed value to the installed LogManager with a " + "*", + "Logs the passed value to the installed LogManager with a " "LogLevel of 'Error'" }, { "printFatal", &luascriptfunctions::printFatal, - "printFatal(*): Logs the passed value to the installed LogManager with a " + "*", + "Logs the passed value to the installed LogManager with a " "LogLevel of 'Fatal'" }, { "absPath", &luascriptfunctions::absolutePath, - "absPath(string): Returns the absolute path to the passed path, resolving" + "string", + "Returns the absolute path to the passed path, resolving" " path tokens as well as resolving relative paths" }, { "setPathToken", &luascriptfunctions::setPathToken, - "setPathToken(string, string): Registers a new path token provided by the" + "string, string", + "Registers a new path token provided by the" " first argument to the path provided in the second argument" } } @@ -493,41 +500,70 @@ bool ScriptEngine::writeDocumentation(const std::string& filename, const std::st LDEBUG("Writing Lua documentation of type '" << type << "' to file '" << filename << "'"); std::ofstream file(filename); - if (file.good()) { - - auto concatenate = [](std::string library, std::string function) { - std::string total = "openspace."; - if (!library.empty()) - total += std::move(library) + "."; - total += std::move(function); - return std::move(total); - }; - // First iterate over all libraries and functions to find the longest - // combination so that can be used as the 'width' parameter for the output - // stream - size_t maxLength = 0; - for (auto library : _registeredLibraries) { - for (auto function : library.functions) { - std::string functionName = concatenate(library.name, function.name); - maxLength = std::max(maxLength, functionName.size()); - } - } - maxLength += AdditionalSpace; - - // Now write out the functions - for (auto library : _registeredLibraries) { - for (auto function : library.functions) { - std::string functionName = concatenate(library.name, function.name); - file << std::setw(maxLength) << std::left << functionName; - file << std::setw(0) << function.helpText << std::endl; - } - } - return true; - } - else { + if (!file.good()) { LERROR("Could not open file '" << filename << "' for writing documentation"); return false; } + + auto concatenate = [](std::string library, std::string function) { + std::string total = "openspace."; + if (!library.empty()) + total += std::move(library) + "."; + total += std::move(function); + return std::move(total); + }; + + // Settings + const unsigned int lineWidth = 80; + static const std::string whitespace = " \t"; + static const std::string padding = " "; + const bool commandListArguments = true; + + file << "Available commands:\n"; + // Now write out the functions + for (auto library : _registeredLibraries) { + for (auto function : library.functions) { + + std::string functionName = concatenate(library.name, function.name); + file << padding << functionName; + if (commandListArguments) + file << "(" << function.argumentText << ")"; + file << std::endl; + } + } + file << std::endl; + + // Now write out the functions definitions + for (auto library : _registeredLibraries) { + for (auto function : library.functions) { + + std::string functionName = concatenate(library.name, function.name); + file << functionName << "(" << function.argumentText << "):" << std::endl; + + std::string remainingHelptext = function.helpText; + + while (!remainingHelptext.empty()) { + const auto length = remainingHelptext.length(); + const auto paddingLength = padding.length(); + if ((length + paddingLength) > lineWidth) { + auto lastSpace = remainingHelptext.find_last_of(whitespace, lineWidth - 1 - paddingLength); + if (lastSpace == remainingHelptext.npos) + lastSpace = lineWidth; + file << padding << remainingHelptext.substr(0, lastSpace) << std::endl; + auto firstNotSpace = remainingHelptext.find_first_not_of(whitespace, lastSpace); + if (firstNotSpace == remainingHelptext.npos) + firstNotSpace = lastSpace; + remainingHelptext = remainingHelptext.substr(firstNotSpace); + } + else { + file << padding << remainingHelptext << std::endl; + remainingHelptext = ""; + } + } + file << std::endl; + } + } + return true; } else { LERROR("Undefined type '" << type << "' for Lua documentation"); diff --git a/src/util/time.cpp b/src/util/time.cpp index 6e7f919dba..08326054c9 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -212,19 +212,22 @@ scripting::ScriptEngine::LuaLibrary Time::luaLibrary() { { "setDeltaTime", &luascriptfunctions::time_setDeltaTime, - "setDeltaTime(number): Sets the amount of simulation time that happens " + "number", + "Sets the amount of simulation time that happens " "in one second of real time" }, { "deltaTime", &luascriptfunctions::time_deltaTime, - "deltaTime: Returns the amount of simulated time that passes in one " + "", + "Returns the amount of simulated time that passes in one " "second of real time" }, { "setTime", &luascriptfunctions::time_setTime, - "setTime({number, string}): Sets the current simulation time to the " + "{number, string}", + "Sets the current simulation time to the " "specified value. If the parameter is a number, the value is the number " "of seconds past the J2000 epoch. If it is a string, it has to be a " "valid ISO 8601 date string (YYYY-MM-DDTHH:MN:SS)" @@ -232,14 +235,16 @@ scripting::ScriptEngine::LuaLibrary Time::luaLibrary() { { "currentTime", &luascriptfunctions::time_currentTime, - "currentTime(): Returns the current time as the number of seconds since " + "", + "Returns the current time as the number of seconds since " "the J2000 epoch" }, { "currentTimeUTC", &luascriptfunctions::time_currentTimeUTC, - "currentTimeUTC: Returns the current time as an ISO 8601 date string " - "(YYYY-MM-DDTHH:MN:SS" + "", + "Returns the current time as an ISO 8601 date string " + "(YYYY-MM-DDTHH:MN:SS)" } } };