From 90ef024f35c6278b246b8f659bfb1fc1dc97bfde Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Mon, 5 Aug 2013 07:17:25 +0200 Subject: Adding a helper to actually find the LuaMainTask from any Lua context. --- includes/LuaTask.h | 1 + src/LuaTask.cc | 11 +++++++++++ 2 files changed, 12 insertions(+) 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 { -- cgit v1.2.3