aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..fb77f6d
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,51 @@
+#ifdef _WIN32
+// SDL main entry
+#include <SDL2/SDL_Main.h>
+// directory
+#include <direct.h>
+#endif
+
+#include "libs/luax/luax.h"
+#include "lua/luaopen_jin.h"
+using namespace jin::lua;
+
+#include "fs/filesystem.h"
+
+#include <Windows.h>
+
+int main(int argc, char* argv[])
+{
+ // global lua state, all lua values are here
+ lua_State* L = luax_newstate();
+ luax_openlibs(L);
+
+ /**
+ * open jin module, jin module is on the top
+ * of stack
+ */
+ luaopen_jin(L);
+
+ // add args to global 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");
+
+ /**
+ * jin._dir is the folder of jin binary executable
+ */
+#define BUFFER_SIZE 512
+ char buffer[BUFFER_SIZE];
+#ifdef _WIN32
+ _getcwd(buffer, BUFFER_SIZE);
+#elif defined __unix__
+#elif defined __APPLE__
+#endif
+#undef BUFFER_SIZE
+ luax_setfield_string(L, "_dir", buffer);
+
+ // boot
+ boot(L);
+
+ return 0;
+}