aboutsummaryrefslogtreecommitdiff
path: root/src/lua/main.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-23 12:23:58 +0800
committerchai <chaifix@163.com>2018-10-23 12:23:58 +0800
commit40fc27154fe754181934dc7ee31375e6bdfb33fc (patch)
tree897ad98d759bc308ef66561181ba88b85f2ccd47 /src/lua/main.cpp
parent1480c9445100075c9e1a894eb07c0ef727b509a1 (diff)
*merge from minimal
Diffstat (limited to 'src/lua/main.cpp')
-rw-r--r--src/lua/main.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/lua/main.cpp b/src/lua/main.cpp
new file mode 100644
index 0000000..95862ec
--- /dev/null
+++ b/src/lua/main.cpp
@@ -0,0 +1,44 @@
+#ifdef _WIN32
+ #include <SDL2/SDL_Main.h>
+ #include <direct.h>
+#endif
+
+#include "luax.h"
+#include "jin.h"
+#include "libjin/jin.h"
+#include <Windows.h>
+
+using namespace JinEngine::Lua;
+using namespace JinEngine::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 field */
+ luax_newtable(L);
+ for (int i = 0; i < argc; ++i)
+ 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((char*)&cwd, cwd.size());
+#elif defined __unix__
+#elif defined __APPLE__
+#endif
+ luax_setfieldstring(L, "cwd", (char*)&cwd);
+ luax_clear(L);
+
+ /* boot jin and run it */
+ boot(L);
+
+ luax_close(L);
+
+ return 0;
+} \ No newline at end of file