aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
blob: e54d2c21176da6e964fb09723febb837ff377d5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifdef _WIN32
// SDL main entry
#include <SDL2/SDL_Main.h>
// directory 
#include <direct.h>
#endif

#include "3rdparty/luax/luax.h"
#include "script/luaopen_jin.h"

#include "libjin/jin.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
    */
    jin::lua::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
    jin::lua::boot(L);

    return 0;
}