aboutsummaryrefslogtreecommitdiff
path: root/src/lua/jin.cpp
blob: d9f685b21577b1e4f4ad138d01ed1ccf29d894f1 (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
104
105
106
107
108
109
110
#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "embed/embed.h"
#include "jin.h"

namespace JinEngine
{
    namespace Lua
    {
    
        LUA_PORT int luaopen_core(lua_State* L);
        LUA_PORT int luaopen_graphics(lua_State* L);
        LUA_PORT int luaopen_audio(lua_State* L);
        LUA_PORT int luaopen_net(lua_State* L);
        LUA_PORT int luaopen_event(lua_State* L);
        LUA_PORT int luaopen_time(lua_State* L);
        LUA_PORT int luaopen_mouse(lua_State* L);
        LUA_PORT int luaopen_keyboard(lua_State* L);
        LUA_PORT int luaopen_filesystem(lua_State* L); 
        LUA_PORT int luaopen_joypad(lua_State* L);
        LUA_PORT int luaopen_math(lua_State* L);
        LUA_PORT int luaopen_thread(lua_State* L);
        LUA_PORT int luaopen_bit(lua_State* L);

        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 int luaopen_jin(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);
            }

            return 1;
        }

        LUA_EXPORT void boot(lua_State* L)
        {
            JinEngine::Embed::boot(L);
        }

    } // namespace Lua
} // namespace JinEngine