I have an input library that has a generic "isDown()" function, and the user can ask for either a button number, a keyboard string, or a string that matches a js number.
As such, I don't feel like sanitizing input.
Code: Select all
function isDown(key)
if love.keyboard.isDown(key) or settings.joysticks[1]:isDown(settings.controllerconfig[key]) then
return true
else
return false
end
end
The solution (for now) is something like this
Code: Select all
function isDown(key)
if type(settings.controllerconfig[key]) == "string" then
if love.keyboard.isDown(key) then
return true
end
elseif type(settings.controllerconfig[key]) == "number" then
if love.keyboard.isDown(tostring(key)) or settings.joysticks[1]:isDown(settings.controllerconfig[key]) then
return true
end
end
return false
end