diff --git a/changes.txt b/changes.txt index f360fe621..6aaecfead 100644 --- a/changes.txt +++ b/changes.txt @@ -3,7 +3,7 @@ LOVE 0.7.2 [Game Slave] * Added Framebuffer:get/setWrap. * Added love.event.clear. - * Added support for any number of arguments to love.keyboard.isDown and love.mouse.isDown. + * Added support for any number of arguments to love.keyboard.isDown, love.mouse.isDown and love.joystick.isDown. * Fixed fused games not working. * Fixed ParticleSystem:setSize ignoring the variation argument. diff --git a/src/modules/joystick/sdl/Joystick.cpp b/src/modules/joystick/sdl/Joystick.cpp index 5c896147a..e3c1e5032 100644 --- a/src/modules/joystick/sdl/Joystick.cpp +++ b/src/modules/joystick/sdl/Joystick.cpp @@ -189,15 +189,20 @@ namespace sdl return 2; } - bool Joystick::isDown(int index, int button) + bool Joystick::isDown(int index, int * buttonlist) { if(!verifyJoystick(index)) return false; + + int num = getNumButtons(index); + + for (int button = *buttonlist; button != -1; button = *(++buttonlist)) + { + if (button < num && SDL_JoystickGetButton(joysticks[index], button) == 1) + return true; + } - if(button >= getNumButtons(index)) - return false; - - return (SDL_JoystickGetButton(joysticks[index], button) == 1); + return false; } Joystick::Hat Joystick::getHat(int index, int hat) diff --git a/src/modules/joystick/sdl/Joystick.h b/src/modules/joystick/sdl/Joystick.h index 6788ebb4d..72cceac2e 100644 --- a/src/modules/joystick/sdl/Joystick.h +++ b/src/modules/joystick/sdl/Joystick.h @@ -59,7 +59,7 @@ namespace sdl float getAxis(int index, int axis); int getAxes(lua_State * L); int getBall(lua_State * L); - bool isDown(int index, int button); + bool isDown(int index, int * buttonlist); Hat getHat(int index, int hat); void close(int index); @@ -74,4 +74,4 @@ namespace sdl } // joystick } // love -#endif // LOVE_JOYSTICK_SDL_JOYSTICK_H \ No newline at end of file +#endif // LOVE_JOYSTICK_SDL_JOYSTICK_H diff --git a/src/modules/joystick/sdl/wrap_Joystick.cpp b/src/modules/joystick/sdl/wrap_Joystick.cpp index 6d82b8a1a..a76e2c60b 100644 --- a/src/modules/joystick/sdl/wrap_Joystick.cpp +++ b/src/modules/joystick/sdl/wrap_Joystick.cpp @@ -104,8 +104,18 @@ namespace sdl int w_isDown(lua_State * L) { int index = luaL_checkint(L, 1); - int button = luaL_checkint(L, 2); - luax_pushboolean(L, instance->isDown(index, button)); + unsigned int num = lua_gettop(L); + int * buttonlist = new int[num]; + unsigned int counter = 0; + + for (unsigned int i = 1; i < num; i++) + { + buttonlist[counter++] = luaL_checknumber(L, i+1); + } + buttonlist[counter] = -1; + + luax_pushboolean(L, instance->isDown(index, buttonlist)); + delete[] buttonlist; return 1; }