summaryrefslogtreecommitdiff
path: root/library/Core.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-04-15 19:09:25 +0400
committerAlexander Gavrilov2012-04-15 19:09:25 +0400
commit14709e5d4598e11ddce6f9d2cce734528d842ca5 (patch)
treeb1370d42d766b329b1ce8fc5431b4e7abf04a4b8 /library/Core.cpp
parentcb27a1d83916b333d1a0d1b5aa24a7f371e120af (diff)
downloaddfhack-14709e5d4598e11ddce6f9d2cce734528d842ca5.tar.gz
dfhack-14709e5d4598e11ddce6f9d2cce734528d842ca5.tar.bz2
dfhack-14709e5d4598e11ddce6f9d2cce734528d842ca5.tar.xz
Add an official core lua context, and allow plugins to send events to it.
- This context requires core suspend lock and asserts it in a few places. - Special 'event' objects are introduced. They can be invoked as functions, in which case they iterate all their fields and call them as functions. Errors are printed and consumed. - When a plugin is opened by the core context, events registered in a special array are linked to it. The system is organized so as to avoid even trying to pass the event to lua if the module isn't loaded.
Diffstat (limited to 'library/Core.cpp')
-rw-r--r--library/Core.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/library/Core.cpp b/library/Core.cpp
index e6b9c45f..16d90bfb 100644
--- a/library/Core.cpp
+++ b/library/Core.cpp
@@ -49,6 +49,8 @@ using namespace std;
#include "modules/Graphic.h"
#include "modules/Windows.h"
#include "RemoteServer.h"
+#include "LuaTools.h"
+
using namespace DFHack;
#include "df/ui.h"
@@ -701,6 +703,9 @@ bool Core::Init()
virtual_identity::Init(this);
df::global::InitGlobals();
+ // initialize common lua context
+ Lua::Core::Init(con);
+
// create mutex for syncing with interactive tasks
misc_data_mutex=new mutex();
cerr << "Initializing Plugins.\n";
@@ -803,6 +808,13 @@ void *Core::GetData( std::string key )
}
}
+bool Core::isSuspended(void)
+{
+ lock_guard<mutex> lock(d->AccessMutex);
+
+ return (d->df_suspend_depth > 0 && d->df_suspend_thread == this_thread::get_id());
+}
+
void Core::Suspend()
{
auto tid = this_thread::get_id();
@@ -882,10 +894,13 @@ int Core::Update()
Init();
if(errorstate)
return -1;
+ Lua::Core::Reset(con, "core init");
}
color_ostream_proxy out(con);
+ Lua::Core::Reset(out, "DF code execution");
+
if (first_update)
plug_mgr->OnStateChange(out, SC_CORE_INITIALIZED);
@@ -976,6 +991,8 @@ int Core::Update()
assert(d->df_suspend_depth == 0);
// destroy condition
delete nc;
+ // check lua stack depth
+ Lua::Core::Reset(con, "suspend");
}
return 0;