From 3f6b280d54058b768f3f67cb3ff1a5e16e150a15 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 28 Aug 2013 05:23:02 -0300 Subject: [PATCH] Joystick:getID now returns the Joystick's instance id as a second argument, if the Joystick is connected. The Joystick gets a new unique instance id every time it's connected. --- src/modules/joystick/sdl/wrap_Joystick.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/modules/joystick/sdl/wrap_Joystick.cpp b/src/modules/joystick/sdl/wrap_Joystick.cpp index dbc8a8106..37d07088f 100644 --- a/src/modules/joystick/sdl/wrap_Joystick.cpp +++ b/src/modules/joystick/sdl/wrap_Joystick.cpp @@ -53,8 +53,17 @@ int w_Joystick_getName(lua_State *L) int w_Joystick_getID(lua_State *L) { Joystick *j = luax_checkjoystick(L, 1); - lua_pushinteger(L, j->getID() + 1); // IDs are 1-based in Lua. - return 1; + + // IDs are 1-based in Lua. + lua_pushinteger(L, j->getID() + 1); + + int instanceid = j->getInstanceID(); + if (instanceid >= 0) + lua_pushinteger(L, instanceid + 1); + else + lua_pushnil(L); + + return 2; } int w_Joystick_getProductGUID(lua_State *L)