diff options
Diffstat (limited to 'src/libjin-lua/embed/je_lua_embed.h')
-rw-r--r-- | src/libjin-lua/embed/je_lua_embed.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/libjin-lua/embed/je_lua_embed.h b/src/libjin-lua/embed/je_lua_embed.h new file mode 100644 index 0000000..199de49 --- /dev/null +++ b/src/libjin-lua/embed/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 "graphics.lua.h" + #include "keyboard.lua.h" + #include "mouse.lua.h" + #include "path.lua.h" + #include "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 |