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:
@@ -33,14 +33,11 @@ function buttons.wasPressed(button) end
|
||||
---@return boolean
|
||||
function buttons.wasReleased(button) end
|
||||
|
||||
---Fired when a button goes down.
|
||||
---@param button Button
|
||||
function on_button_down(button) end
|
||||
-- What an app implements to see buttons, composed into its own class:
|
||||
--
|
||||
-- ---@class MenuApp : App, ButtonHandlers
|
||||
|
||||
---Fired when a button comes up.
|
||||
---@param button Button
|
||||
function on_button_up(button) end
|
||||
|
||||
---Tap alias, fired on release like a click, after on_button_up.
|
||||
---@param button Button
|
||||
function on_button(button) end
|
||||
---@class ButtonHandlers
|
||||
---@field onButtonDown? fun(button: Button) Fired when a button goes down.
|
||||
---@field onButtonUp? fun(button: Button) Fired when a button comes up.
|
||||
---@field onButton? fun(button: Button) Tap alias, fired on release like a click, after onButtonUp.
|
||||
|
||||
Reference in New Issue
Block a user