diff options
| author | Alexander Gavrilov | 2012-04-14 19:44:07 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-04-14 19:44:07 +0400 |
| commit | cb49c92b99a5aab3f95c811a43fe4dadc1115b99 (patch) | |
| tree | fe2a4bcfc0a11e5ef3e2cbfbc864e5b9e8aa9ceb /library/LuaTools.cpp | |
| parent | 7a34a89f53071a8368ec5bd064accb10354b6d56 (diff) | |
| download | dfhack-cb49c92b99a5aab3f95c811a43fe4dadc1115b99.tar.gz dfhack-cb49c92b99a5aab3f95c811a43fe4dadc1115b99.tar.bz2 dfhack-cb49c92b99a5aab3f95c811a43fe4dadc1115b99.tar.xz | |
Allow plugins to export functions to lua with safe reload support.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.
Diffstat (limited to 'library/LuaTools.cpp')
| -rw-r--r-- | library/LuaTools.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/library/LuaTools.cpp b/library/LuaTools.cpp index 471ffd55..5129ba64 100644 --- a/library/LuaTools.cpp +++ b/library/LuaTools.cpp @@ -745,6 +745,22 @@ static int lua_dfhack_with_suspend(lua_State *L) return lua_gettop(L); } +static int dfhack_open_plugin(lua_State *L) +{ + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checktype(L, 2, LUA_TSTRING); + const char *name = lua_tostring(L, 2); + + PluginManager *pmgr = Core::getInstance().getPluginManager(); + Plugin *plugin = pmgr->getPluginByName(name); + + if (!plugin) + luaL_error(L, "plugin not found: '%s'", name); + + plugin->open_lua(L, 1); + return 0; +} + static const luaL_Reg dfhack_funcs[] = { { "print", lua_dfhack_print }, { "println", lua_dfhack_println }, @@ -757,6 +773,7 @@ static const luaL_Reg dfhack_funcs[] = { { "onerror", dfhack_onerror }, { "call_with_finalizer", dfhack_call_with_finalizer }, { "with_suspend", lua_dfhack_with_suspend }, + { "open_plugin", dfhack_open_plugin }, { NULL, NULL } }; |
