diff options
Diffstat (limited to 'src/jin/main.cpp')
-rw-r--r-- | src/jin/main.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/jin/main.cpp b/src/jin/main.cpp index 2d65064..2144fbc 100644 --- a/src/jin/main.cpp +++ b/src/jin/main.cpp @@ -11,21 +11,16 @@ using namespace JinEngine::Lua; using namespace JinEngine::Filesystem; -int main(int argc, char* argv[]) +static void setParamters(lua_State* L, int argc, char* args[]) { - lua_State* L = luax_newstate(); - - // Open lua standard module. - luax_openlibs(L); - // Open jin module. - luaopen_jin(L); // Add args to field. luax_newtable(L); for (int i = 0; i < argc; ++i) - luax_setrawstring(L, -2, i + 1, argv[i]); + luax_setrawstring(L, -2, i + 1, args[i]); luax_setfield(L, -2, "args"); // Push current working directory. // Absolute directory. + // An 1KB buffer. Buffer cwd = Buffer(1024); #ifdef _WIN32 _getcwd((char*)&cwd, cwd.size()); @@ -33,11 +28,26 @@ int main(int argc, char* argv[]) #elif defined __APPLE__ #endif luax_setfieldstring(L, "cwd", (char*)&cwd); - luax_clear(L); +} + +int main(int argc, char* args[]) +{ + // Global lua runtime. + lua_State* L = luax_newstate(); + + // Open lua standard module. + luax_openlibs(L); + // Open jin module. + luaopen_jin(L); + // Set parameters. + setParamters(L, argc, args); + // Clear lua stack. + luax_clearstack(L); // Boot jin and run it. boot(L); + // Close lua lib. luax_close(L); return 0; |