mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
Replaced love.joystick.getJoystick with love.joystick.getJoysticks (returns a table of all connected joysticks), and renamed Joystick:getIndex to Joystick:getConnectedIndex
This commit is contained in:
@@ -196,7 +196,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "isGamepadDown", w_Joystick_isGamepadDown },
|
{ "isGamepadDown", w_Joystick_isGamepadDown },
|
||||||
|
|
||||||
// From wrap_JoystickModule.
|
// From wrap_JoystickModule.
|
||||||
{ "getIndex", w_getIndex },
|
{ "getConnectedIndex", w_getIndex },
|
||||||
{ "getGamepadMapping", w_getGamepadMapping },
|
{ "getGamepadMapping", w_getGamepadMapping },
|
||||||
{ 0, 0 },
|
{ 0, 0 },
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -30,16 +30,18 @@ namespace sdl
|
|||||||
|
|
||||||
static JoystickModule *instance = 0;
|
static JoystickModule *instance = 0;
|
||||||
|
|
||||||
int w_getJoystick(lua_State *L)
|
int w_getJoysticks(lua_State *L)
|
||||||
{
|
{
|
||||||
int index = luaL_checkint(L, 1) - 1;
|
int stickcount = instance->getJoystickCount();
|
||||||
love::joystick::Joystick *stick = instance->getJoystick(index);
|
lua_createtable(L, stickcount, 0);
|
||||||
|
|
||||||
if (!stick)
|
for (int i = 0; i < stickcount; i++)
|
||||||
return luaL_error(L, "Invalid joystick index");
|
{
|
||||||
|
love::joystick::Joystick *stick = instance->getJoystick(i);
|
||||||
stick->retain();
|
stick->retain();
|
||||||
luax_newtype(L, "Joystick", JOYSTICK_JOYSTICK_T, (void *) stick);
|
luax_newtype(L, "Joystick", JOYSTICK_JOYSTICK_T, (void *) stick);
|
||||||
|
lua_rawseti(L, -2, i + 1);
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -197,8 +199,8 @@ int w_getGamepadMapping(lua_State *L)
|
|||||||
// List of functions to wrap.
|
// List of functions to wrap.
|
||||||
static const luaL_Reg functions[] =
|
static const luaL_Reg functions[] =
|
||||||
{
|
{
|
||||||
{ "getJoystick", w_getJoystick },
|
{ "getJoysticks", w_getJoysticks },
|
||||||
{ "getIndex", w_getIndex },
|
// { "getIndex", w_getIndex },
|
||||||
{ "getJoystickCount", w_getJoystickCount },
|
{ "getJoystickCount", w_getJoystickCount },
|
||||||
{ "isGamepad", w_isGamepad },
|
{ "isGamepad", w_isGamepad },
|
||||||
{ "setGamepadMapping", w_setGamepadMapping },
|
{ "setGamepadMapping", w_setGamepadMapping },
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace joystick
|
|||||||
namespace sdl
|
namespace sdl
|
||||||
{
|
{
|
||||||
|
|
||||||
int w_getJoystick(lua_State *L);
|
int w_getJoysticks(lua_State *L);
|
||||||
int w_getIndex(lua_State *L);
|
int w_getIndex(lua_State *L);
|
||||||
int w_getJoystickCount(lua_State *L);
|
int w_getJoystickCount(lua_State *L);
|
||||||
int w_isGamepad(lua_State *L);
|
int w_isGamepad(lua_State *L);
|
||||||
|
|||||||
Reference in New Issue
Block a user