aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/embed/embed.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-08-20 11:51:32 +0800
committerchai <chaifix@163.com>2018-08-20 11:51:32 +0800
commit65bafdc682db46f0f115374ad39f1fbc348832ac (patch)
tree7862548cdf01060e89a45c9817afc6e5d263acd7 /src/lua/modules/embed/embed.h
parent9593ae6ecdfcfb876fa7953f25e19f0a97e1453a (diff)
*update
Diffstat (limited to 'src/lua/modules/embed/embed.h')
-rw-r--r--src/lua/modules/embed/embed.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/lua/modules/embed/embed.h b/src/lua/modules/embed/embed.h
new file mode 100644
index 0000000..18ed1d8
--- /dev/null
+++ b/src/lua/modules/embed/embed.h
@@ -0,0 +1,49 @@
+#ifndef __JIN_LUA_EMBED_H
+#define __JIN_LUA_EMBED_H
+#include <cstring>
+
+namespace jin
+{
+namespace embed
+{
+
+ /**
+ * embed lua script to context.
+ */
+#define embed(L, script, name)\
+ if(luax_loadbuffer(L, script, strlen(script), name) == 0)\
+ lua_call(L, 0, 0);
+
+ /**
+ * embed structure.
+ */
+ struct jin_Embed
+ {
+ const char* file, *source;
+ };
+
+ static void boot(lua_State* L)
+ {
+ // embed scripts
+ #include "graphics.lua.h" // graphics
+ #include "keyboard.lua.h" // keyboard
+ #include "mouse.lua.h" // mouse
+ #include "boot.lua.h" // boot
+
+ // embed scripts
+ const jin_Embed scripts[] = {
+ { "graphics.lua", graphics_lua },
+ { "keyboard.lua", keyboard_lua },
+ { "mouse.lua", mouse_lua },
+ { "boot.lua", boot_lua },
+ { 0, 0 }
+ };
+
+ // load all emebd lua scripts
+ for (int i = 0; scripts[i].file; ++i)
+ embed(L, scripts[i].source, scripts[i].file);
+ }
+}
+}
+
+#endif \ No newline at end of file