main.lua: joystick hotplug
This commit is contained in:
parent
8c7e3edf86
commit
a994e54639
17
main.lua
17
main.lua
@ -1,11 +1,17 @@
|
|||||||
local ffi = require 'ffi'
|
local ffi = require 'ffi'
|
||||||
local joysticks
|
local joysticks
|
||||||
|
|
||||||
function init()
|
function init_joysticks()
|
||||||
joysticks = love.joystick.getJoysticks()
|
joysticks = {}
|
||||||
for i, joystick in ipairs(joysticks) do
|
for i, joystick in ipairs(love.joystick.getJoysticks()) do
|
||||||
print(i, joystick:getName())
|
if joystick:isGamepad() then
|
||||||
|
table.insert(joysticks, joystick)
|
||||||
|
print(#joysticks, joystick:getName())
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function init()
|
||||||
|
|
||||||
ffi.cdef[[
|
ffi.cdef[[
|
||||||
void load(const char * source_path);
|
void load(const char * source_path);
|
||||||
@ -229,6 +235,9 @@ function love.run()
|
|||||||
return function()
|
return function()
|
||||||
love.event.pump()
|
love.event.pump()
|
||||||
for name, a,b,c,d,e,f,g,h in love.event.poll() do
|
for name, a,b,c,d,e,f,g,h in love.event.poll() do
|
||||||
|
if name == "joystickadded" or name == "joystickremoved" then
|
||||||
|
init_joysticks()
|
||||||
|
end
|
||||||
if name == "quit" then
|
if name == "quit" then
|
||||||
if c or not love.quit or not love.quit() then
|
if c or not love.quit or not love.quit() then
|
||||||
return a or 0, b
|
return a or 0, b
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user