local last_time = os.clock()
local frame_count = 0
local fps = 0
local sample_interval = 1 -- segundos

function frame() -- llama esto cada frame; recibe dt si tu motor lo proporciona
  frame_count = frame_count + 1
  local now = os.clock()
  local elapsed = now - last_time
  if elapsed >= sample_interval then
    fps = frame_count / elapsed
    frame_count = 0
    last_time = now
  end
  return math.floor(fps)
end

function fps_print()
	local current_fps = frame()
	draw.rectf(0,0,29,7,16)
    draw.text(current_fps.." fps",1,1,2)
end

-- ejemplo de uso dentro de tu bucle:
-- local current_fps = frame()
