summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-07 06:31:41 +0200
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-07 06:31:41 +0200
commit24dbb15bf6f2b513e2fb75345345b7b646ff1a81 (patch)
treee2e81d6960cc81e8bd0b0b4de69455f603ad9aa6
parenta010c6c9e789df00bdaba3ab5e5b52e263d2776b (diff)
Adding skeleton LuaHandle.
-rw-r--r--Makefile2
-rw-r--r--includes/LuaHandle.h33
-rw-r--r--src/LuaHandle.cc121
3 files changed, 156 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 3386bf8..ff7be3c 100644
--- a/Makefile
+++ b/Makefile
@@ -64,6 +64,8 @@ SimpleMustache.cc \
\
BLua.cc \
\
+LuaHandle.cc \
+\
LuaTask.cc \
\
BRegex.cc \
diff --git a/includes/LuaHandle.h b/includes/LuaHandle.h
new file mode 100644
index 0000000..ab165ee
--- /dev/null
+++ b/includes/LuaHandle.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <BLua.h>
+#include <Handle.h>
+#include <Input.h>
+
+namespace Balau {
+
+typedef IO<Handle> IOHandle;
+typedef IOHandle IOInput;
+
+class LuaHandleFactory : public LuaObjectFactory {
+ public:
+ LuaHandleFactory(IO<Handle> h) : m_obj(new IO<Handle>(h)) { }
+ static void pushStatics(Lua & L);
+ protected:
+ LuaHandleFactory(IO<Handle> * h) : m_obj(h) { }
+ void pushObjectAndMembers(Lua & L);
+ private:
+ IO<Handle> * m_obj;
+};
+
+class LuaInputFactory : public LuaHandleFactory {
+ public:
+ LuaInputFactory(IO<Input> h) : LuaHandleFactory(new IO<Handle>(h)) { }
+ static void pushStatics(Lua & L);
+ private:
+ void pushObjectAndMembers(Lua & L);
+};
+
+void registerLuaHandle(Lua &);
+
+};
diff --git a/src/LuaHandle.cc b/src/LuaHandle.cc
new file mode 100644
index 0000000..7607665
--- /dev/null
+++ b/src/LuaHandle.cc
@@ -0,0 +1,121 @@
+#include "LuaHandle.h"
+#include "Handle.h"
+
+// Handle exports
+
+enum IOHandle_methods_t {
+ IOHANDLE_CLOSE,
+};
+
+struct Balau::lua_functypes_t IOHandle_methods[] = {
+ { IOHANDLE_CLOSE, "close", 0, 0, { } },
+ { -1, 0, 0, 0, 0 },
+};
+
+struct sLua_IOHandle {
+ static int IOHandle_proceed(Balau::Lua & L, int n, Balau::IOHandle * obj, int caller);
+};
+
+int sLua_IOHandle::IOHandle_proceed(Balau::Lua & L, int n, Balau::IOHandle * obj, int caller) {
+ int r = 0;
+ Balau::IO<Balau::Handle> h = *obj;
+
+ switch (caller) {
+ case IOHANDLE_CLOSE:
+ h->close();
+ break;
+ }
+
+ return r;
+}
+
+void Balau::LuaHandleFactory::pushStatics(Balau::Lua & L) {
+ CHECK_METHODS(IOHandle);
+ PUSH_CLASS(Handle);
+ PUSH_CLASS_DONE();
+}
+
+void Balau::LuaHandleFactory::pushObjectAndMembers(Lua & L) {
+ pushObj(L, m_obj, "Handle");
+
+ PUSH_METHOD(IOHandle, IOHANDLE_CLOSE);
+}
+
+
+// Input exports
+
+enum IOInput_functions_t {
+ IOINPUT_CONSTRUCTOR,
+};
+
+enum IOInput_methods_t {
+ IOINPUT_OPEN,
+};
+
+struct Balau::lua_functypes_t IOInput_functions[] = {
+ { IOINPUT_CONSTRUCTOR, NULL, 1, 1, { Balau::BLUA_STRING } },
+ { -1, 0, 0, 0, 0 },
+};
+
+struct Balau::lua_functypes_t IOInput_methods[] = {
+ { IOINPUT_OPEN, "open", 0, 0, { } },
+ { -1, 0, 0, 0, 0 },
+};
+
+struct sLua_IOInput {
+ static int IOInput_proceed_static(Balau::Lua & L, int n, int caller);
+ static int IOInput_proceed(Balau::Lua & L, int n, Balau::IOHandle * obj, int caller);
+};
+
+int sLua_IOInput::IOInput_proceed_static(Balau::Lua & L, int n, int caller) {
+ int r;
+
+ switch (caller) {
+ case IOINPUT_CONSTRUCTOR:
+ {
+ Balau::LuaInputFactory factory(new Balau::Input(L.tostring()));
+ factory.pushDestruct(L);
+ }
+ r = 1;
+ break;
+ }
+
+ return r;
+}
+
+int sLua_IOInput::IOInput_proceed(Balau::Lua & L, int n, Balau::IOHandle * obj, int caller) {
+ int r;
+ Balau::IO<Balau::Input> h = *obj;
+
+ switch (caller) {
+ case IOINPUT_OPEN:
+ return L.yield(Balau::Future<int>([h]() mutable { h->open(); return 0; }));
+ break;
+ }
+
+ return r;
+}
+
+void Balau::LuaInputFactory::pushStatics(Balau::Lua & L) {
+ CHECK_FUNCTIONS(IOInput);
+ CHECK_METHODS(IOInput);
+
+ PUSH_SUBCLASS(Input, Handle);
+ PUSH_CONSTRUCTOR(IOInput, IOINPUT_CONSTRUCTOR);
+ PUSH_CLASS_DONE();
+}
+
+void Balau::LuaInputFactory::pushObjectAndMembers(Lua & L) {
+ LuaHandleFactory::pushObjectAndMembers(L);
+
+ L.push("__type");
+ L.getglobal("Input");
+ L.settable(-3, true);
+
+ PUSH_METHOD(IOInput, IOINPUT_OPEN);
+}
+
+void Balau::registerLuaHandle(Lua & L) {
+ LuaHandleFactory::pushStatics(L);
+ LuaInputFactory::pushStatics(L);
+}