/
ctr.c
60 lines (48 loc) · 1.18 KB
/
ctr.c
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
#include <3ds/types.h>
#include <3ds/services/apt.h>
#include <3ds/os.h>
#include <lua.h>
#include <lauxlib.h>
int load_gfx_lib(lua_State *L);
int load_news_lib(lua_State *L);
int load_ptm_lib(lua_State *L);
int load_hid_lib(lua_State *L);
int load_ir_lib(lua_State *L);
int load_fs_lib(lua_State *L);
int load_httpc_lib(lua_State *L);
static int ctr_run(lua_State *L) {
lua_pushboolean(L, aptMainLoop());
return 1;
}
static int ctr_time(lua_State *L) {
lua_pushinteger(L, osGetTime());
return 1;
}
// Functions
static const struct luaL_Reg ctr_lib[] = {
{ "run", ctr_run },
{ "time", ctr_time},
{ NULL, NULL }
};
// Subtables
struct { char *name; int (*load)(lua_State *L); } ctr_libs[] = {
{ "gfx", load_gfx_lib },
{ "news", load_news_lib },
{ "ptm", load_ptm_lib },
{ "hid", load_hid_lib },
{ "ir", load_ir_lib },
{ "fs", load_fs_lib },
{ "httpc", load_httpc_lib },
{ NULL, NULL }
};
int luaopen_ctr_lib(lua_State *L) {
luaL_newlib(L, ctr_lib);
for (int i = 0; ctr_libs[i].name; i++) {
ctr_libs[i].load(L);
lua_setfield(L, -2, ctr_libs[i].name);
}
return 1;
}
void load_ctr_lib(lua_State *L) {
luaL_requiref(L, "ctr", luaopen_ctr_lib, 0);
}