diff --git a/sdcard/3ds/ctruLua/main.lua b/sdcard/3ds/ctruLua/main.lua index 1678a84..4738c1d 100644 --- a/sdcard/3ds/ctruLua/main.lua +++ b/sdcard/3ds/ctruLua/main.lua @@ -30,7 +30,8 @@ local function drawStuffIn3D(depth) gfx.circle(125 - depth*4, 125, 16) end -while os.run() do +while ctr.run() do + hid.read() local keys = hid.keys() if keys.down.start then return end diff --git a/source/ctr.c b/source/ctr.c index a917fd3..72b666e 100644 --- a/source/ctr.c +++ b/source/ctr.c @@ -1,15 +1,21 @@ #include <3ds/types.h> +#include <3ds/services/apt.h> #include <3ds/os.h> #include #include -int load_os_lib(lua_State *L); 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); +static int ctr_run(lua_State *L) { + lua_pushboolean(L, aptMainLoop()); + + return 1; +} + static int ctr_time(lua_State *L) { lua_pushinteger(L, osGetTime()); @@ -18,6 +24,7 @@ static int ctr_time(lua_State *L) { // Functions static const struct luaL_Reg ctr_lib[] = { + { "run", ctr_run }, { "time", ctr_time}, { NULL, NULL } }; @@ -43,6 +50,5 @@ int luaopen_ctr_lib(lua_State *L) { } void load_ctr_lib(lua_State *L) { - load_os_lib(L); luaL_requiref(L, "ctr", luaopen_ctr_lib, 0); } diff --git a/source/hid.c b/source/hid.c index 1d4dabb..0a23583 100644 --- a/source/hid.c +++ b/source/hid.c @@ -38,9 +38,13 @@ struct { PAD_KEY key; char *name; } hid_keys_name[] = { { 0, NULL } }; -static int hid_keys(lua_State *L) { +static int hid_read(lua_State *L) { hidScanInput(); + return 0; +} + +static int hid_keys(lua_State *L) { u32 kDown = hidKeysDown(); u32 kHeld = hidKeysHeld(); u32 kUp = hidKeysUp(); @@ -76,8 +80,6 @@ static int hid_keys(lua_State *L) { } static int hid_touch(lua_State *L) { - hidScanInput(); - touchPosition pos; hidTouchRead(&pos); @@ -88,8 +90,6 @@ static int hid_touch(lua_State *L) { } static int hid_circle(lua_State *L) { - hidScanInput(); - circlePosition pos; hidCircleRead(&pos); @@ -100,8 +100,6 @@ static int hid_circle(lua_State *L) { } static int hid_accel(lua_State *L) { - hidScanInput(); - accelVector pos; hidAccelRead(&pos); @@ -113,8 +111,6 @@ static int hid_accel(lua_State *L) { } static int hid_gyro(lua_State *L) { - hidScanInput(); - angularRate pos; hidGyroRead(&pos); @@ -135,6 +131,7 @@ static int hid_volume(lua_State *L) { } static const struct luaL_Reg hid_lib[] = { + { "read", hid_read }, { "keys", hid_keys }, { "touch", hid_touch }, { "circle", hid_circle }, diff --git a/source/os.c b/source/os.c deleted file mode 100644 index 6f84e48..0000000 --- a/source/os.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <3ds/types.h> -#include <3ds/services/apt.h> - -#include - -static int os_run(lua_State *L) { - bool run = aptMainLoop(); - - lua_pushboolean(L, run); - - return 1; -} - -void load_os_lib(lua_State *L) { - lua_getglobal(L, "os"); - - lua_pushcfunction(L, os_run); - lua_setfield(L, -2, "run"); - - lua_pop(L, 1); - - return; -} \ No newline at end of file