diff options
Diffstat (limited to 'src/libjin-lua/je_lua_jin.cpp')
-rw-r--r-- | src/libjin-lua/je_lua_jin.cpp | 82 |
1 files changed, 80 insertions, 2 deletions
diff --git a/src/libjin-lua/je_lua_jin.cpp b/src/libjin-lua/je_lua_jin.cpp index 5989792..debd79e 100644 --- a/src/libjin-lua/je_lua_jin.cpp +++ b/src/libjin-lua/je_lua_jin.cpp @@ -1,7 +1,7 @@ #include "common/je_lua.h" #include "common/je_lua_common.h" #include "modules/je_lua_modules.h" -#include "je_lua_embed.h" +//#include "je_lua_embed.h" #include "je_lua_jin.h" namespace JinEngine @@ -92,6 +92,83 @@ namespace JinEngine jin_log_info("Done."); } + // Embed structure. + struct jin_Embed + { + const char* file; + const char* source; + }; + + // Embed scripts. + #include "scripts/ai/state_machine.lua.h" + #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/time/time.lua.h" + #include "scripts/utils/json.lua.h" + #include "scripts/utils/xml.lua.h" + #include "scripts/log.lua.h" + #include "scripts/tiledmap/tiledmap.lua.h" + #include "scripts/physics/physics.lua.h" + + #include "scripts/app.lua.h" + + // In order. + static const jin_Embed modules[] = { + // ai + { "state_machine.lua", state_machine_lua }, + // keyboard + { "keyboard.lua", keyboard_lua }, + { "mouse.lua", mouse_lua }, + { "graphics.lua", graphics_lua }, + { "path.lua", path_lua }, + { "time.lua", time_lua }, + { "json.lua", json_lua }, + { "xml.lua", xml_lua }, + { "tiledmap.lua", tiledmap_lua }, + { "physics.lua", physics_lua }, + // + { "log.lua", log_lua }, + { 0, 0 } + }; + + static const jin_Embed bootscript = { "app.lua", app_lua }; + + static void embed(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); + } + else + { + jin_log_error("Embed script \"%s\" failed.", file); + } + } + } + + static void run(lua_State* L) + { + const char* file, *source; + 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); + } + } + LUA_EXPORT void boot(lua_State* L, const char* cwd) { luax_clearstack(L); @@ -100,7 +177,8 @@ namespace JinEngine luax_setfieldstring(L, "cwd", cwd); luax_setfield(L, -2, "args"); luax_clearstack(L); - Embed::run(L); + embed(L); + run(L); } } // namespace Lua |