aboutsummaryrefslogtreecommitdiff
path: root/src/lua/je_lua_jin.cpp
blob: e3af1697625637a735a94387fdb9305319d2af52 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "common/je_lua.h"
#include "common/je_lua_common.h"
#include "modules/je_lua_modules.h"
#include "embed/embed.h"
#include "je_lua_jin.h"

namespace JinEngine
{
    namespace Lua
    {
    
        LUA_IMPLEMENT int l_getversion(lua_State* L)
        {
            luax_pushstring(L, VERSION);
            return 1; 
        }

        LUA_IMPLEMENT int l_getAuthor(lua_State* L)
        {
            luax_pushstring(L, AUTHOR);
            return 1; 
        }

        LUA_IMPLEMENT int l_getOS(lua_State* L)
        {
        #ifdef _WIN32 
            luax_pushstring(L, "windows");
        #elif defined __unix__
            luax_pushstring(L, "unix");
        #elif defined __APPLE__
            luax_pushstring(L, "macos");
        #endif
            return 1;
        }
    
        LUA_IMPLEMENT int l_revision(lua_State* L)
        {
            luax_pushnumber(L, REVISION);
            return 1;
        }

        LUA_IMPLEMENT const luax_Str s[] = {
            { "version",  VERSION   },
            { "author",   AUTHOR    },
            { "codename", CODE_NAME },
            { 0,          0         }
        };

        LUA_IMPLEMENT const luax_Num n[] = {
            { "revision", REVISION },
            { 0,          0        }
        };

        // Register jin module, keep it on the top of stack.
        LUA_EXPORT void open(lua_State* L)
        {
            luax_globaltable(L, MODULE_NAME);

            // Register values.
            luax_setfieldstrings(L, s);
            luax_setfieldnumbers(L, n);

            luax_Reg modules[] = {
                { "core",       luaopen_core       },
                { "event",      luaopen_event      },
                { "graphics",   luaopen_graphics   },
                { "time",       luaopen_time       },
                { "mouse",      luaopen_mouse      },
                { "keyboard",   luaopen_keyboard   },
                { "filesystem", luaopen_filesystem },
                { "net",        luaopen_net        },
                { "audio",      luaopen_audio      },
                { "joypad",     luaopen_joypad     },
                { "math",       luaopen_math       },
                { "thread",     luaopen_thread     },
                { "bit",        luaopen_bit        },
                //{"ai",          luaopen_ai         },
                { 0,            0                  }
            };

            // Register sub modules.
            for (int i = 0; modules[i].name; ++i)
            {
                modules[i].func(L);
                luax_setfield(L, -2, modules[i].name);
            }

            // Pop jin table.
            luax_pop(L, 1);
        }

        LUA_EXPORT void boot(lua_State* L, const char* cwd)
        {
            luax_getglobal(L, MODULE_NAME);
            luax_newtable(L);
            luax_setfieldstring(L, "cwd", cwd);
            luax_setfield(L, -2, "args");
            luax_clearstack(L);
            Embed::run(L);
        }

    } // namespace Lua
} // namespace JinEngine