b9f7c9347c
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.
44 lines
1.3 KiB
Lua
44 lines
1.3 KiB
Lua
---@meta
|
|
|
|
-- Generated from native/src/bindings/features/buttons.cpp. Do not edit.
|
|
|
|
---@alias Button "up"|"down"|"left"|"right"|"confirm"|"back"
|
|
|
|
-- Roles, not physical buttons: a device maps whatever hardware it has onto them, and
|
|
-- up/down/left/right are the directions tree.moveFocus already takes.
|
|
|
|
---@class ButtonsLib
|
|
buttons = {}
|
|
|
|
---Returns the roles this device reports, so an app can label only the actions it has.
|
|
---@return Button[]
|
|
function buttons.getAll() end
|
|
|
|
---Whether any button is held.
|
|
---@return boolean
|
|
function buttons.isAnyPressed() end
|
|
|
|
---Whether a button is held.
|
|
---@param button Button
|
|
---@return boolean
|
|
function buttons.isPressed(button) end
|
|
|
|
---Whether a button went down since the last poll.
|
|
---@param button Button
|
|
---@return boolean
|
|
function buttons.wasPressed(button) end
|
|
|
|
---Whether a button came up since the last poll.
|
|
---@param button Button
|
|
---@return boolean
|
|
function buttons.wasReleased(button) end
|
|
|
|
-- What an app implements to see buttons, composed into its own class:
|
|
--
|
|
-- ---@class MenuApp : App, ButtonHandlers
|
|
|
|
---@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.
|