summaryrefslogtreecommitdiff
path: root/library/Core.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/Core.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/Core.cpp')
-rw-r--r--library/Core.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/library/Core.cpp b/library/Core.cpp
index a752ae62..e6b9c45f 100644
--- a/library/Core.cpp
+++ b/library/Core.cpp
@@ -861,13 +861,9 @@ int Core::TileUpdate()
// should always be from simulation thread!
int Core::Update()
{
- if(!started)
- Init();
if(errorstate)
return -1;
- color_ostream_proxy out(con);
-
// Pretend this thread has suspended the core in the usual way
{
lock_guard<mutex> lock(d->AccessMutex);
@@ -877,6 +873,22 @@ int Core::Update()
d->df_suspend_depth = 1000;
}
+ // Initialize the core
+ bool first_update = false;
+
+ if(!started)
+ {
+ first_update = true;
+ Init();
+ if(errorstate)
+ return -1;
+ }
+
+ color_ostream_proxy out(con);
+
+ if (first_update)
+ plug_mgr->OnStateChange(out, SC_CORE_INITIALIZED);
+
// detect if the game was loaded or unloaded in the meantime
void *new_wdata = NULL;
void *new_mapdata = NULL;