/src/bindings/bind_input.cpp
https://bitbucket.org/vivkin/gam3b00bs/ · C++ · 77 lines · 65 code · 12 blank · 0 comment · 0 complexity · f82f623814c865779415424dfb019497 MD5 · raw file
- #include "common.h"
- #include "bind_all.h"
- #include "app/app.h"
-
- namespace luab
- {
- static int bind_input_get_key_state(lua_State *L)
- {
- lua_pushnumber(L, (lua_Number)app::input::get_key_state((uint16)lua_tonumber(L, 1)));
- return 1;
- }
-
- static int bind_input_get_button_state(lua_State *L)
- {
- lua_pushnumber(L, (lua_Number)app::input::get_button_state((uint16)lua_tonumber(L, 1)));
- return 1;
- }
-
- static int bind_input_get_wheel_rel(lua_State *L)
- {
- lua_pushnumber(L, (lua_Number)app::input::get_wheel_rel());
- return 1;
- }
-
- static int bind_input_get_cursor_pos(lua_State *L)
- {
- int16 x, y;
- app::input::get_cursor_pos(&x, &y);
- lua_pushnumber(L, (lua_Number)x);
- lua_pushnumber(L, (lua_Number)y);
- return 2;
- }
-
- static int bind_input_get_cursor_rel(lua_State *L)
- {
- int16 xr, yr;
- app::input::get_cursor_rel(&xr, &yr);
- lua_pushnumber(L, (lua_Number)xr);
- lua_pushnumber(L, (lua_Number)yr);
- return 2;
- }
-
- static int bind_input_tick(lua_State *L)
- {
- lua_pushboolean(L, app::input::tick());
- return 1;
- }
-
- static void bind_input_constants(lua_State *L)
- {
- lua_newtable(L);
-
- lua_pushnumber(L, app::input::UP); lua_setfield(L, -2, "UP");
- lua_pushnumber(L, app::input::DOWN); lua_setfield(L, -2, "DOWN");
- lua_pushnumber(L, app::input::PRESSED); lua_setfield(L, -2, "PRESSED");
-
- lua_setglobal(L, "input");
- }
-
- static const struct luaL_reg funcs[] =
- {
- {"get_key_state", bind_input_get_key_state},
- {"get_button_state", bind_input_get_button_state},
- {"get_wheel_rel", bind_input_get_wheel_rel},
- {"get_cursor_pos", bind_input_get_cursor_pos},
- {"get_cursor_rel", bind_input_get_cursor_rel},
- {"tick", bind_input_tick},
- {0, 0}
- };
-
- void bind_input(lua_State *L)
- {
- bind_input_constants(L);
- luaL_register(L, "input", funcs);
- }
- }