initial commit

This commit is contained in:
2026-08-03 16:09:07 -04:00
commit 95fa512047
109 changed files with 35023 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
#include "../helpers.h"
namespace esp32lua {
namespace bindings {
namespace {
int getButtons(lua_State* state) {
pushStrings(state, Runtime::from(state)->buttons().buttons());
return 1;
}
int isAnyPressed(lua_State* state) {
lua_pushboolean(state, Runtime::from(state)->buttons().isAnyPressed());
return 1;
}
int isPressed(lua_State* state) {
const std::string button = checkString(state, 1);
lua_pushboolean(state, Runtime::from(state)->buttons().isPressed(button));
return 1;
}
int wasPressed(lua_State* state) {
const std::string button = checkString(state, 1);
lua_pushboolean(state, Runtime::from(state)->buttons().wasPressed(button));
return 1;
}
int wasReleased(lua_State* state) {
const std::string button = checkString(state, 1);
lua_pushboolean(state, Runtime::from(state)->buttons().wasReleased(button));
return 1;
}
// @lua-augment input InputLib
// @lua-preamble ---@alias Button "up"|"down"|"left"|"right"|"confirm"|"back"
// @lua-preamble
// @lua-preamble -- Roles, not physical buttons: a device maps whatever hardware it has onto them, and
// @lua-preamble -- up/down/left/right are the directions node.moveFocus already takes.
const luaL_Reg INPUT_FUNCTIONS[] = {
// ---Returns the roles this device reports, so an app can label only the actions it has.
// @return Button[]
{"getButtons", getButtons},
// ---Whether any button is held.
// @return boolean
{"isAnyPressed", isAnyPressed},
// ---Whether a button is held.
// @param button Button
// @return boolean
{"isPressed", isPressed},
// ---Whether a button went down since the last poll.
// @param button Button
// @return boolean
{"wasPressed", wasPressed},
// ---Whether a button came up since the last poll.
// @param button Button
// @return boolean
{"wasReleased", wasReleased},
{nullptr, nullptr},
};
} // namespace
void registerButtons(lua_State* state) { augmentGlobal(state, "input", INPUT_FUNCTIONS); }
} // namespace bindings
} // namespace esp32lua
// @lua-global
// ---Fired when a button goes down.
// @param button Button
// @lua-fn on_button_down
// ---Fired when a button comes up.
// @param button Button
// @lua-fn on_button_up
// ---Tap alias, fired on release like a click, after on_button_up.
// @param button Button
// @lua-fn on_button