| 93 | // *********************************************************************** |
| 94 | |
| 95 | int BindInput(lua_State* pLua) { |
| 96 | |
| 97 | // Bind static mesh functions |
| 98 | const luaL_Reg gameGlobalFuncs[] = { |
| 99 | { "get_button", LuaGetButton }, |
| 100 | { "get_button_down", LuaGetButtonDown }, |
| 101 | { "get_button_up", LuaGetButtonUp }, |
| 102 | { "get_axis", LuaGetAxis }, |
| 103 | { "get_mouse_position", LuaGetMousePosition }, |
| 104 | { "enable_mouse_relative_mode", LuaEnableMouseRelativeMode }, |
| 105 | { "get_key", LuaGetKey }, |
| 106 | { "get_key_down", LuaGetKeyDown }, |
| 107 | { "get_key_up", LuaGetKeyUp }, |
| 108 | { "input_string", LuaInputString }, |
| 109 | { NULL, NULL } |
| 110 | }; |
| 111 | |
| 112 | lua_pushvalue(pLua, LUA_GLOBALSINDEX); |
| 113 | luaL_register(pLua, NULL, gameGlobalFuncs); |
| 114 | lua_pop(pLua, 1); |
| 115 | |
| 116 | // push enum tables to global |
| 117 | lua_newtable(pLua); |
| 118 | { |
| 119 | PushEnum(pLua, (int)ControllerButton::Invalid, "invalid"); |
| 120 | PushEnum(pLua, (int)ControllerButton::FaceBottom, "face_bottom"); |
| 121 | PushEnum(pLua, (int)ControllerButton::FaceRight, "face_right"); |
| 122 | PushEnum(pLua, (int)ControllerButton::FaceLeft, "face_left"); |
| 123 | PushEnum(pLua, (int)ControllerButton::FaceTop, "face_top"); |
| 124 | PushEnum(pLua, (int)ControllerButton::LeftStick, "left_stick"); |
| 125 | PushEnum(pLua, (int)ControllerButton::RightStick, "right_stick"); |
| 126 | PushEnum(pLua, (int)ControllerButton::LeftShoulder, "left_shoulder"); |
| 127 | PushEnum(pLua, (int)ControllerButton::RightShoulder, "right_shoulder"); |
| 128 | PushEnum(pLua, (int)ControllerButton::DpadDown, "dpad_down"); |
| 129 | PushEnum(pLua, (int)ControllerButton::DpadLeft, "dpad_left"); |
| 130 | PushEnum(pLua, (int)ControllerButton::DpadRight, "dpad_right"); |
| 131 | PushEnum(pLua, (int)ControllerButton::DpadUp, "dpad_up"); |
| 132 | PushEnum(pLua, (int)ControllerButton::Start, "start"); |
| 133 | PushEnum(pLua, (int)ControllerButton::Select, "select"); |
| 134 | } |
| 135 | lua_setglobal(pLua, "Button"); |
| 136 | |
| 137 | lua_newtable(pLua); |
| 138 | { |
| 139 | PushEnum(pLua, (int)ControllerAxis::Invalid, "invalid"); |
| 140 | PushEnum(pLua, (int)ControllerAxis::LeftX, "left_x"); |
| 141 | PushEnum(pLua, (int)ControllerAxis::LeftY, "left_y"); |
| 142 | PushEnum(pLua, (int)ControllerAxis::RightX, "right_x"); |
| 143 | PushEnum(pLua, (int)ControllerAxis::RightY, "right_y"); |
| 144 | PushEnum(pLua, (int)ControllerAxis::TriggerLeft, "trigger_left"); |
| 145 | PushEnum(pLua, (int)ControllerAxis::TriggerRight, "trigger_right"); |
| 146 | } |
| 147 | lua_setglobal(pLua, "Axis"); |
| 148 | |
| 149 | lua_newtable(pLua); |
| 150 | { |
| 151 | PushEnum(pLua, (int)Key::Invalid, "invalid"); |
| 152 | PushEnum(pLua, (int)Key::A, "a"); |