From fa234f9663b992cf50bcf865a1cde6845b42193c Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 21 May 2018 16:02:00 +0800 Subject: =?UTF-8?q?=E4=BF=AE=E6=94=B9audio=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lua/embed/embed.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/lua/embed/embed.h (limited to 'src/lua/embed/embed.h') diff --git a/src/lua/embed/embed.h b/src/lua/embed/embed.h new file mode 100644 index 0000000..2ef8b75 --- /dev/null +++ b/src/lua/embed/embed.h @@ -0,0 +1,51 @@ +#ifndef __JIN_LUA_EMBED_H +#define __JIN_LUA_EMBED_H +#include + +namespace jin +{ +namespace embed +{ + + /** + * embed lua script to context. + */ +#define embed(L, script, name) \ + if(luaL_loadbuffer(L, script, strlen(script), name) == 0)\ + lua_call(L, 0, 0); + + /** + * embed structure. + */ + struct jin_Embed + { + const char* fname, *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 "debug.lua.h" // debug + #include "boot.lua.h" // boot + + // embed scripts + const jin_Embed scripts[] = { + {"graphics.lua", graphics_lua}, + {"keyboard.lua", keyboard_lua}, + {"mouse.lua", mouse_lua}, + {"debug.lua", debug_lua}, + {"boot.lua", boot_lua}, + {0, 0} + }; + + // load all emebd lua scripts + for (int i = 0; scripts[i].fname; ++i) + embed(L, scripts[i].source, scripts[i].fname); + } +} +} + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0