love.joystick.isDown gets multiple arguments too

This commit is contained in:
Bart van Strien
2011-04-07 19:06:36 +02:00
parent fe6d168bf1
commit 529530c198
4 changed files with 25 additions and 10 deletions
+1 -1
View File
@@ -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.
+10 -5
View File
@@ -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)
+2 -2
View File
@@ -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
#endif // LOVE_JOYSTICK_SDL_JOYSTICK_H
+12 -2
View File
@@ -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;
}