refactor(api)!: declare callbacks as classes an app composes

The runtime has always called fields on the table main.lua returns, but
@lua-global declared them as loose functions, so the stubs type-checked
something that does not exist and read as "define a global".

Callbacks are now @lua-app blocks that generate a class: App for the core
contract, TouchHandlers and ButtonHandlers beside the namespaces they belong
to. An app composes what it implements:

  ---@class PaintApp : App, TouchHandlers

Names follow the rest of the surface: onTouchDown rather than on_touch_down,
with the field names the runtime looks up renamed to match. @lua-field carries
the plain fields (home, data) that were prose in a preamble before.
This commit is contained in:
2026-08-05 10:42:01 -04:00
parent 75b3a2c490
commit b9f7c9347c
11 changed files with 153 additions and 87 deletions
+8 -18
View File
@@ -28,22 +28,12 @@ function touch.isTouched() end
---@return string? error
function touch.setCalibration(x0, y0, x1, y1) end
---Fired when the finger lands.
---@param x integer
---@param y integer
function on_touch_down(x, y) end
-- What an app implements to see raw touch, composed into its own class:
--
-- ---@class PaintApp : App, TouchHandlers
---Fired when the finger moves while down, after the firmware's jitter filter.
---@param x integer
---@param y integer
function on_touch_move(x, y) end
---Fired when the finger lifts.
---@param x integer
---@param y integer
function on_touch_up(x, y) end
---Tap alias, fired on release like a click, after on_touch_up.
---@param x integer
---@param y integer
function on_touch(x, y) end
---@class TouchHandlers
---@field onTouchDown? fun(x: integer, y: integer) Fired when the finger lands.
---@field onTouchMove? fun(x: integer, y: integer) Fired when the finger moves while down, after the firmware's jitter filter.
---@field onTouchUp? fun(x: integer, y: integer) Fired when the finger lifts.
---@field onTouch? fun(x: integer, y: integer) Tap alias, fired on release like a click, after onTouchUp.