diff options
author | chai <chaifix@163.com> | 2018-12-22 13:10:45 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-12-22 13:10:45 +0800 |
commit | 731a8ba6e52aa0b000b46c89e414a248e05778ff (patch) | |
tree | 5e6c62d0469f9a6e6019228a81a23bdfb9b4505e /src/libjin-lua/je_lua_embed.h | |
parent | ef7c4915c20d7f6ceb5484f99f96979fd5a9594d (diff) |
*移动embed script位置
Diffstat (limited to 'src/libjin-lua/je_lua_embed.h')
-rw-r--r-- | src/libjin-lua/je_lua_embed.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/libjin-lua/je_lua_embed.h b/src/libjin-lua/je_lua_embed.h new file mode 100644 index 0000000..a14af5e --- /dev/null +++ b/src/libjin-lua/je_lua_embed.h @@ -0,0 +1,69 @@ +#ifndef __JIN_LUA_EMBED_H__ +#define __JIN_LUA_EMBED_H__ +#include <cstring> + +#include "common/je_lua.h" + +namespace JinEngine +{ + namespace Embed + { + + // Embed structure. + struct jin_Embed + { + const char* file, *source; + }; + + // Embed scripts. + #include "scripts/graphics/graphics.lua.h" + #include "scripts/keyboard/keyboard.lua.h" + #include "scripts/mouse/mouse.lua.h" + #include "scripts/path/path.lua.h" + #include "scripts/app.lua.h" + + // In order. + static const jin_Embed modules[] = { + { "keyboard.lua", keyboard_lua }, + { "mouse.lua", mouse_lua }, + { "graphics.lua", graphics_lua }, + { "path.lua", path_lua }, + { 0, 0 } + }; + + static const jin_Embed bootscript = { "app.lua", app_lua }; + + static void run(lua_State* L) + { + jin_log_info("Load embeded scripts."); + const char* file, *source; + for (int i = 0; modules[i].file != 0; ++i) + { + file = modules[i].file; + source = modules[i].source; + jin_log_info("Embed script \"%s\".", file); + luax_clearstack(L); + if (luax_loadbuffer(L, source, strlen(source), file) == 0) + { + luax_call(L, 0, 0); + jin_log_info("Done."); + } + else + { + jin_log_error("Embed script \"%s\" failed.", file); + } + } + file = bootscript.file; + source = bootscript.source; + jin_log_info("Run boot script \"%s\".", file); + luax_clearstack(L); + if (luax_loadbuffer(L, source, strlen(source), file) == 0) + { + luax_call(L, 0, 0); + } + } + + } // namespace Embed +} // namespace JinEngine + +#endif // __JIN_LUA_EMBED_H__
\ No newline at end of file |