Add support for c closures in lua

This commit is contained in:
Emil Axelsson
2017-07-06 22:30:57 +02:00
parent ee36a97762
commit 351a246f3a
14 changed files with 86 additions and 1 deletions

View File

@@ -48,6 +48,8 @@ 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<void*> userdata;
/// A text describing the arugments to this function
std::string argumentText;
/// A help text describing what the function does/

View File

@@ -104,6 +104,7 @@ scripting::LuaLibrary ModuleEngine::luaLibrary() {
{
"isLoaded",
&luascriptfunctions::isLoaded,
{},
"string",
"Checks whether a specific module is loaded"
}

View File

@@ -1258,6 +1258,7 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() {
{
"toggleShutdown",
&luascriptfunctions::toggleShutdown,
{},
"",
"Toggles the shutdown mode that will close the application after the count"
"down timer is reached"
@@ -1265,30 +1266,35 @@ 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, [value, minimumValue, maximumValue]",
"Adds a virtual property that will set a group of properties"
},
{
"removeVirtualProperty",
&luascriptfunctions::removeVirtualProperty,
{},
"string",
"Removes a previously added virtual property"
},
{
"removeAllVirtualProperties",
&luascriptfunctions::removeAllVirtualProperties,
{},
"",
"Remove all registered virtual properties"
}

View File

@@ -63,6 +63,7 @@ scripting::LuaLibrary WindowWrapper::luaLibrary() {
{
"setSynchronization",
&luascriptfunctions::setSynchronization,
{},
"bool",
"Enables or disables the frame synchronization of the cluster. If the "
"synchronization is enabled, the computers in the cluster will swap "

View File

@@ -474,12 +474,14 @@ scripting::LuaLibrary InteractionHandler::luaLibrary() {
{
"clearKeys",
&luascriptfunctions::clearKeys,
{},
"",
"Clear all key bindings"
},
{
"bindKey",
&luascriptfunctions::bindKey,
{},
"string, string [,string]",
"Binds a key by name to a lua string command to execute both locally "
"and to broadcast to clients if this is the host of a parallel session. "
@@ -490,6 +492,7 @@ scripting::LuaLibrary InteractionHandler::luaLibrary() {
{
"bindKeyLocal",
&luascriptfunctions::bindKeyLocal,
{},
"string, string [,string]",
"Binds a key by name to a lua string command to execute only locally. "
"The first argument is the key, the second argument is the Lua command "
@@ -499,30 +502,35 @@ scripting::LuaLibrary InteractionHandler::luaLibrary() {
{
"saveCameraStateToFile",
&luascriptfunctions::saveCameraStateToFile,
{},
"string",
"Save the current camera state to file"
},
{
"restoreCameraStateFromFile",
&luascriptfunctions::restoreCameraStateFromFile,
{},
"string",
"Restore the camera state from file"
},
{
"resetCameraDirection",
&luascriptfunctions::resetCameraDirection,
{},
"void",
"Reset the camera direction to point at the focus node"
},
{
"goToChunk",
&luascriptfunctions::goToChunk,
{},
"void",
"Go to chunk with given index x, y, level"
},
{
"goToGeo",
&luascriptfunctions::goToGeo,
{},
"void",
"Go to geographic coordinates latitude and longitude"
},

View File

@@ -95,12 +95,14 @@ scripting::LuaLibrary MissionManager::luaLibrary() {
{
"loadMission",
&luascriptfunctions::loadMission,
{},
"string",
"Load mission phases from file"
},
{
"setCurrentMission",
&luascriptfunctions::setCurrentMission,
{},
"string",
"Set the currnet mission"
},

View File

@@ -1168,24 +1168,28 @@ scripting::LuaLibrary ParallelConnection::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"
},

View File

@@ -695,18 +695,21 @@ scripting::LuaLibrary RenderEngine::luaLibrary() {
{
"setRenderer",
&luascriptfunctions::setRenderer,
{},
"string",
"Sets the renderer (ABuffer or FrameBuffer)"
},
{
"toggleFade",
&luascriptfunctions::toggleFade,
{},
"number",
"Toggles fading in or out"
},
{
"fadeIn",
&luascriptfunctions::fadeIn,
{},
"number",
""
},
@@ -714,18 +717,21 @@ scripting::LuaLibrary RenderEngine::luaLibrary() {
{
"fadeOut",
&luascriptfunctions::fadeOut,
{},
"number",
""
},
{
"registerScreenSpaceRenderable",
&luascriptfunctions::registerScreenSpaceRenderable,
{},
"table",
"Will create a ScreenSpaceRenderable from a lua Table and register it in the RenderEngine"
},
{
"unregisterScreenSpaceRenderable",
&luascriptfunctions::unregisterScreenSpaceRenderable,
{},
"string",
"Given a ScreenSpaceRenderable name this script will remove it from the renderengine"
},

View File

@@ -391,6 +391,7 @@ scripting::LuaLibrary Scene::luaLibrary() {
{
"setPropertyValue",
&luascriptfunctions::property_setValue,
{},
"string, *",
"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 "
@@ -403,6 +404,7 @@ scripting::LuaLibrary Scene::luaLibrary() {
{
"setPropertyValueRegex",
&luascriptfunctions::property_setValueRegex,
{},
"string, *",
"Sets all property(s) that pass the regular expression in the first "
"argument. The second argument can be any type, but it has to match "
@@ -416,6 +418,7 @@ scripting::LuaLibrary Scene::luaLibrary() {
{
"setPropertyValueSingle",
&luascriptfunctions::property_setValueSingle,
{},
"string, *",
"Sets all property(s) identified by the URI in the first argument to the "
"value passed in the second argument. The type of the second argument is "
@@ -428,6 +431,7 @@ scripting::LuaLibrary Scene::luaLibrary() {
{
"getPropertyValue",
&luascriptfunctions::property_getValue,
{},
"string",
"Returns the value the property, identified by "
"the provided URI."
@@ -435,6 +439,7 @@ 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"
@@ -442,6 +447,7 @@ scripting::LuaLibrary Scene::luaLibrary() {
{
"addSceneGraphNode",
&luascriptfunctions::addSceneGraphNode,
{},
"table",
"Loads the SceneGraphNode described in the table and adds it to the "
"SceneGraph"
@@ -449,6 +455,7 @@ scripting::LuaLibrary Scene::luaLibrary() {
{
"removeSceneGraphNode",
&luascriptfunctions::removeSceneGraphNode,
{},
"string",
"Removes the SceneGraphNode identified by name"
}

View File

@@ -369,7 +369,10 @@ void ScriptEngine::addLibraryFunctions(lua_State* state, LuaLibrary& library, bo
lua_pop(state, 1);
}
lua_pushstring(state, p.name.c_str());
lua_pushcfunction(state, p.function);
for (void* d : p.userdata) {
lua_pushlightuserdata(state, d);
}
lua_pushcclosure(state, p.function, p.userdata.size());
lua_settable(state, TableOffset);
}
@@ -421,6 +424,7 @@ void ScriptEngine::addBaseLibrary() {
{
"printTrace",
&luascriptfunctions::printTrace,
{},
"*",
"Logs the passed value to the installed LogManager with a LogLevel of "
"'Trace'"
@@ -428,6 +432,7 @@ void ScriptEngine::addBaseLibrary() {
{
"printDebug",
&luascriptfunctions::printDebug,
{},
"*",
"Logs the passed value to the installed LogManager with a LogLevel of "
"'Debug'"
@@ -435,6 +440,7 @@ void ScriptEngine::addBaseLibrary() {
{
"printInfo",
&luascriptfunctions::printInfo,
{},
"*",
"Logs the passed value to the installed LogManager with a LogLevel of "
"'Info'"
@@ -442,6 +448,7 @@ void ScriptEngine::addBaseLibrary() {
{
"printWarning",
&luascriptfunctions::printWarning,
{},
"*",
"Logs the passed value to the installed LogManager with a LogLevel of "
"'Warning'"
@@ -449,6 +456,7 @@ void ScriptEngine::addBaseLibrary() {
{
"printError",
&luascriptfunctions::printError,
{},
"*",
"Logs the passed value to the installed LogManager with a LogLevel of "
"'Error'"
@@ -456,6 +464,7 @@ void ScriptEngine::addBaseLibrary() {
{
"printFatal",
&luascriptfunctions::printFatal,
{},
"*",
"Logs the passed value to the installed LogManager with a LogLevel of "
"'Fatal'"
@@ -463,6 +472,7 @@ void ScriptEngine::addBaseLibrary() {
{
"absPath",
&luascriptfunctions::absolutePath,
{},
"string",
"Returns the absolute path to the passed path, resolving path tokens as "
"well as resolving relative paths"
@@ -470,12 +480,14 @@ void ScriptEngine::addBaseLibrary() {
{
"fileExists",
&luascriptfunctions::fileExists,
{},
"string",
"Checks whether the provided file exists."
},
{
"setPathToken",
&luascriptfunctions::setPathToken,
{},
"string, string",
"Registers a new path token provided by the first argument to the path "
"provided in the second argument"
@@ -483,6 +495,7 @@ 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 "
@@ -493,6 +506,7 @@ 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 "
@@ -503,6 +517,7 @@ 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 "

View File

@@ -269,6 +269,7 @@ LuaLibrary ScriptScheduler::luaLibrary() {
{
"loadFile",
&luascriptfunctions::loadFile,
{},
"string",
"Load timed scripts from a Lua script file that returns a list of "
"scheduled scripts."
@@ -276,6 +277,7 @@ 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 "
@@ -287,6 +289,7 @@ LuaLibrary ScriptScheduler::luaLibrary() {
{
"clear",
&luascriptfunctions::clear,
{},
"",
"Clears all scheduled scripts."
},

View File

@@ -201,6 +201,7 @@ LuaLibrary generalSystemCapabilities() {
{
"operatingSystem",
&luascripting::general::operatingSystem,
{},
"",
"Returns a parsed string of the operating system type, for example "
"Windows, Linux, MacOS, or others, together with the specific version, "
@@ -209,6 +210,7 @@ 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 "
@@ -217,6 +219,7 @@ LuaLibrary generalSystemCapabilities() {
{
"installedMainMemory",
&luascripting::general::installedMainMemory,
{},
"",
"Returns the amount of available, installed main memory (RAM) on the "
"system in MB."
@@ -224,30 +227,35 @@ 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."
}
@@ -262,6 +270,7 @@ 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'."
@@ -269,12 +278,14 @@ 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 <code>glGetString(GL_VENDOR)</code>. "
"This will give detailed information about the vendor of the main "
@@ -284,24 +295,28 @@ 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 <code>extension</code> is supported or not."
},
{
"maxTextureUnits",
&luascripting::opengl::maxTextureUnits,
{},
"",
"Returns the maximum number of texture units that are available on the "
"main graphics card."
@@ -309,18 +324,21 @@ 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."
@@ -328,6 +346,7 @@ LuaLibrary openglSystemCapabilities() {
{
"maxShaderStorageBufferBindings",
&luascripting::opengl::maxShaderStorageBufferBindings,
{},
"",
"Returns the maximum number of shader storage bindings that are "
"available on the main graphics card."
@@ -335,6 +354,7 @@ LuaLibrary openglSystemCapabilities() {
{
"maxUniformBufferBindings",
&luascripting::opengl::maxUniformBufferBindings,
{},
"",
"Returns the maximum number of uniform buffer bindings that are "
"available on the main graphics card."

View File

@@ -1192,6 +1192,7 @@ 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"
@@ -1199,6 +1200,7 @@ scripting::LuaLibrary SpiceManager::luaLibrary() {
{
"unloadKernel",
&luascriptfunctions::unloadKernel,
{},
"{string, number}",
"Unloads the provided SPICE kernel. The name can contain path tokens, "
"which are automatically resolved"

View File

@@ -160,6 +160,7 @@ scripting::LuaLibrary Time::luaLibrary() {
{
"setDeltaTime",
&luascriptfunctions::time_setDeltaTime,
{},
"number",
"Sets the amount of simulation time that happens "
"in one second of real time"
@@ -167,6 +168,7 @@ scripting::LuaLibrary Time::luaLibrary() {
{
"deltaTime",
&luascriptfunctions::time_deltaTime,
{},
"",
"Returns the amount of simulated time that passes in one "
"second of real time"
@@ -174,12 +176,14 @@ 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"
@@ -187,6 +191,7 @@ 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 "
@@ -196,6 +201,7 @@ scripting::LuaLibrary Time::luaLibrary() {
{
"currentTime",
&luascriptfunctions::time_currentTime,
{},
"",
"Returns the current time as the number of seconds since "
"the J2000 epoch"
@@ -203,6 +209,7 @@ scripting::LuaLibrary Time::luaLibrary() {
{
"UTC",
&luascriptfunctions::time_currentTimeUTC,
{},
"",
"Returns the current time as an ISO 8601 date string "
"(YYYY-MM-DDTHH:MN:SS)"
@@ -210,6 +217,7 @@ 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"