summaryrefslogtreecommitdiff
path: root/includes/LuaTask.h
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2012-04-01 12:41:16 -0700
committerPixel <pixel@nobis-crew.org>2012-04-01 12:41:16 -0700
commita4634497c8ada51755249606d8dc4b4c2761c017 (patch)
tree17a969a5f6d4b2be63f8a4a2654445439fc6db41 /includes/LuaTask.h
parent1fdf750ee66ee9e4e872d2810e9ca3bcfa2d555e (diff)
Creating first pass on LuaTasks.
Diffstat (limited to 'includes/LuaTask.h')
-rw-r--r--includes/LuaTask.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/includes/LuaTask.h b/includes/LuaTask.h
new file mode 100644
index 0000000..6dff44e
--- /dev/null
+++ b/includes/LuaTask.h
@@ -0,0 +1,61 @@
+#pragma once
+
+#include <c++11-surrogates.h>
+#include <BLua.h>
+#include <Task.h>
+
+namespace Balau {
+
+class LuaTask;
+class LuaMainTask;
+
+class LuaExecCell {
+ public:
+ LuaExecCell() : m_detached(false) { }
+ void detach() { m_detached = true; }
+ void exec(LuaMainTask * mainTask);
+ protected:
+ virtual void run(Lua &) = 0;
+ private:
+ Events::Async m_event;
+ bool m_detached;
+ friend class LuaTask;
+};
+
+class LuaExecString : public LuaExecCell {
+ public:
+ LuaExecString(const String & str) : m_str(str) { }
+ private:
+ virtual void run(Lua &);
+ String m_str;
+};
+
+class LuaTask : public Task {
+ public:
+ ~LuaTask() { L.weaken(); }
+ virtual const char * getName() const { return "LuaTask"; }
+ private:
+ LuaTask(Lua && __L, LuaExecCell * cell) : L(Move(__L)), m_cell(cell) { }
+ virtual void Do();
+ Lua L;
+ LuaExecCell * m_cell;
+ friend class LuaMainTask;
+};
+
+class LuaMainTask : public Task {
+ public:
+ LuaMainTask() : m_stopping(false) { }
+ ~LuaMainTask() { L.close(); }
+ void stop();
+ virtual const char * getName() const { return "LuaMainTask"; }
+ private:
+ void exec(LuaExecCell * cell);
+ virtual void Do();
+ Lua L;
+ Events::Async m_queueEvent;
+ Queue<LuaExecCell> m_queue;
+ bool m_stopping;
+ friend class LuaExecCell;
+};
+
+};