love-demo2/main.lua
2026-03-08 16:53:03 -05:00

64 lines
1.5 KiB
Lua

local ffi = require 'ffi'
local joysticks
function init()
joysticks = love.joystick.getJoysticks()
ffi.cdef[[
void load();
void draw();
void update(float lx, float ly, float rx, float ry, float tl, float tr,
int up, int down, int left, int right);
]]
test = ffi.load("./test.so")
test.load()
end
local update = function(dt)
for _, joystick in ipairs(joysticks) do
local lx = joystick:getGamepadAxis("leftx")
local ly = joystick:getGamepadAxis("lefty")
local rx = joystick:getGamepadAxis("rightx")
local ry = joystick:getGamepadAxis("righty")
local tl = joystick:getGamepadAxis("triggerleft")
local tr = joystick:getGamepadAxis("triggerright")
local up = joystick:isGamepadDown("dpup")
local down = joystick:isGamepadDown("dpdown")
local left = joystick:isGamepadDown("dpleft")
local right = joystick:isGamepadDown("dpright")
test.update(lx, ly, rx, ry, tl, tr, up, down, left, right)
end
end
local draw = function()
test.draw()
end
function love.run()
init()
love.timer.step()
return function()
love.event.pump()
for name, a,b,c,d,e,f,g,h in love.event.poll() do
if name == "quit" then
if c or not love.quit or not love.quit() then
return a or 0, b
end
end
end
local dt = love.timer.step()
update(dt)
draw()
love.graphics.present()
love.timer.sleep(0.001)
local fps = love.timer.getFPS( )
--print(fps)
end
end