From e3ddc74a36e4336d28e9e09586b5194c2e6e6dc6 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 9 Sep 2018 18:03:05 +0800 Subject: *update --- src/main.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 5b6309a..18d873d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,30 +9,35 @@ #include using namespace jin::lua; +using namespace jin::filesystem; int main(int argc, char* argv[]) { lua_State* L = luax_newstate(); + /* open lua standard module */ luax_openlibs(L); + /* open jin module */ luaopen_jin(L); - - // add args to global field + /* add args to field */ luax_newtable(L); for (int i = 0; i < argc; ++i) - luax_setraw_string(L, -2, i + 1, argv[i]); - luax_setfield(L, -2, "_argv"); - - const int BUFFER_SIZE = 512; - char buffer[BUFFER_SIZE]; + luax_setrawstring(L, -2, i + 1, argv[i]); + luax_setfield(L, -2, "args"); + /* push current working directory */ + /* absolute directory */ + Buffer cwd = Buffer(1024); #ifdef _WIN32 - _getcwd(buffer, BUFFER_SIZE); + _getcwd((char*)cwd.data, cwd.size); #elif defined __unix__ #elif defined __APPLE__ #endif - luax_setfield_string(L, "_dir", buffer); + luax_setfieldstring(L, "cwd", (char*)cwd.data); + luax_clear(L); + + /* boot jin and run it */ boot(L); - luax_close(L); + luax_close(L); return 0; } \ No newline at end of file -- cgit v1.1-26-g67d0