diff --git a/src/modules/joystick/sdl/wrap_Joystick.cpp b/src/modules/joystick/sdl/wrap_Joystick.cpp index 156b2398f..0883396dd 100644 --- a/src/modules/joystick/sdl/wrap_Joystick.cpp +++ b/src/modules/joystick/sdl/wrap_Joystick.cpp @@ -196,7 +196,7 @@ static const luaL_Reg functions[] = { "isGamepadDown", w_Joystick_isGamepadDown }, // From wrap_JoystickModule. - { "getIndex", w_getIndex }, + { "getConnectedIndex", w_getIndex }, { "getGamepadMapping", w_getGamepadMapping }, { 0, 0 }, }; diff --git a/src/modules/joystick/sdl/wrap_JoystickModule.cpp b/src/modules/joystick/sdl/wrap_JoystickModule.cpp index 99c6454f3..67cad791e 100644 --- a/src/modules/joystick/sdl/wrap_JoystickModule.cpp +++ b/src/modules/joystick/sdl/wrap_JoystickModule.cpp @@ -30,17 +30,19 @@ namespace sdl static JoystickModule *instance = 0; -int w_getJoystick(lua_State *L) +int w_getJoysticks(lua_State *L) { - int index = luaL_checkint(L, 1) - 1; - love::joystick::Joystick *stick = instance->getJoystick(index); + int stickcount = instance->getJoystickCount(); + lua_createtable(L, stickcount, 0); - if (!stick) - return luaL_error(L, "Invalid joystick index"); + for (int i = 0; i < stickcount; i++) + { + love::joystick::Joystick *stick = instance->getJoystick(i); + stick->retain(); + luax_newtype(L, "Joystick", JOYSTICK_JOYSTICK_T, (void *) stick); + lua_rawseti(L, -2, i + 1); + } - stick->retain(); - luax_newtype(L, "Joystick", JOYSTICK_JOYSTICK_T, (void *) stick); - return 1; } @@ -197,8 +199,8 @@ int w_getGamepadMapping(lua_State *L) // List of functions to wrap. static const luaL_Reg functions[] = { - { "getJoystick", w_getJoystick }, - { "getIndex", w_getIndex }, + { "getJoysticks", w_getJoysticks }, +// { "getIndex", w_getIndex }, { "getJoystickCount", w_getJoystickCount }, { "isGamepad", w_isGamepad }, { "setGamepadMapping", w_setGamepadMapping }, diff --git a/src/modules/joystick/sdl/wrap_JoystickModule.h b/src/modules/joystick/sdl/wrap_JoystickModule.h index 533a77a08..492c6c004 100644 --- a/src/modules/joystick/sdl/wrap_JoystickModule.h +++ b/src/modules/joystick/sdl/wrap_JoystickModule.h @@ -32,7 +32,7 @@ namespace joystick namespace sdl { -int w_getJoystick(lua_State *L); +int w_getJoysticks(lua_State *L); int w_getIndex(lua_State *L); int w_getJoystickCount(lua_State *L); int w_isGamepad(lua_State *L);