main.lua: joystick hotplug

This commit is contained in:
Zack Buhman 2026-03-23 03:15:07 -05:00
parent 8c7e3edf86
commit a994e54639

View File

@ -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