summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-05 07:17:25 +0200
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-05 07:17:25 +0200
commit90ef024f35c6278b246b8f659bfb1fc1dc97bfde (patch)
treee6b46cd66cbe5ebbe8b5c7583232563378e1e9f6
parent4d77b2060aa76ec194bc643e6b20138a4cd529e9 (diff)
Adding a helper to actually find the LuaMainTask from any Lua context.
-rw-r--r--includes/LuaTask.h1
-rw-r--r--src/LuaTask.cc11
2 files changed, 12 insertions, 0 deletions
diff --git a/includes/LuaTask.h b/includes/LuaTask.h
index 85ce1f8..2ed0156 100644
--- a/includes/LuaTask.h
+++ b/includes/LuaTask.h
@@ -69,6 +69,7 @@ class LuaMainTask : public StacklessTask {
~LuaMainTask();
void stop();
virtual const char * getName() const { return "LuaMainTask"; }
+ static LuaMainTask * getMainTask(Lua &);
private:
void exec(LuaExecCell * cell);
virtual void Do();
diff --git a/src/LuaTask.cc b/src/LuaTask.cc
index 5c03521..e7d78ff 100644
--- a/src/LuaTask.cc
+++ b/src/LuaTask.cc
@@ -25,6 +25,9 @@ Balau::LuaMainTask::LuaMainTask() {
L.open_bit();
L.open_jit();
L.open_ffi();
+ L.push("LuaMainTask");
+ L.push((void *) this);
+ L.settable(LUA_REGISTRYINDEX);
}
Balau::LuaMainTask::~LuaMainTask() {
@@ -61,6 +64,14 @@ void Balau::LuaMainTask::Do() {
}
}
+Balau::LuaMainTask * Balau::LuaMainTask::getMainTask(Lua & L) {
+ L.push("LuaMainTask");
+ L.gettable(LUA_REGISTRYINDEX);
+ LuaMainTask * r = (LuaMainTask *) L.touserdata();
+ L.pop();
+ return r;
+}
+
void Balau::LuaTask::Do() {
while(true) {
try {