aboutsummaryrefslogtreecommitdiff
path: root/src/lua/embed/embed.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-23 12:23:58 +0800
committerchai <chaifix@163.com>2018-10-23 12:23:58 +0800
commit40fc27154fe754181934dc7ee31375e6bdfb33fc (patch)
tree897ad98d759bc308ef66561181ba88b85f2ccd47 /src/lua/embed/embed.h
parent1480c9445100075c9e1a894eb07c0ef727b509a1 (diff)
*merge from minimal
Diffstat (limited to 'src/lua/embed/embed.h')
-rw-r--r--src/lua/embed/embed.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/lua/embed/embed.h b/src/lua/embed/embed.h
new file mode 100644
index 0000000..18373c8
--- /dev/null
+++ b/src/lua/embed/embed.h
@@ -0,0 +1,46 @@
+#ifndef __JIN_LUA_EMBED_H
+#define __JIN_LUA_EMBED_H
+#include <cstring>
+
+namespace JinEngine
+{
+namespace embed
+{
+
+#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"
+ #include "keyboard.lua.h"
+ #include "mouse.lua.h"
+ #include "boot.lua.h"
+
+ // in order
+ const jin_Embed scripts[] = {
+ { "graphics.lua", graphics_lua },
+ { "keyboard.lua", keyboard_lua },
+ { "mouse.lua", mouse_lua },
+ { "boot.lua", boot_lua },
+ { 0, 0 }
+ };
+
+ for (int i = 0; scripts[i].file; ++i)
+ embed(L, scripts[i].source, scripts[i].file);
+ }
+
+} // embed
+} // namespace JinEngine
+
+#endif \ No newline at end of file