summaryrefslogtreecommitdiff
path: root/library/LuaTypes.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-04-14 19:44:07 +0400
committerAlexander Gavrilov2012-04-14 19:44:07 +0400
commitcb49c92b99a5aab3f95c811a43fe4dadc1115b99 (patch)
treefe2a4bcfc0a11e5ef3e2cbfbc864e5b9e8aa9ceb /library/LuaTypes.cpp
parent7a34a89f53071a8368ec5bd064accb10354b6d56 (diff)
downloaddfhack-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/LuaTypes.cpp')
-rw-r--r--library/LuaTypes.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/library/LuaTypes.cpp b/library/LuaTypes.cpp
index 40269da8..f5ba565d 100644
--- a/library/LuaTypes.cpp
+++ b/library/LuaTypes.cpp
@@ -1030,6 +1030,12 @@ static int meta_global_newindex(lua_State *state)
static int meta_call_function(lua_State *state)
{
auto id = (function_identity_base*)lua_touserdata(state, UPVAL_CONTAINER_ID);
+
+ return method_wrapper_core(state, id);
+}
+
+int LuaWrapper::method_wrapper_core(lua_State *state, function_identity_base *id)
+{
if (lua_gettop(state) != id->getNumArgs())
field_error(state, UPVAL_METHOD_NAME, "invalid argument count", "invoke");