refactor: split the Lua runtime, share test stubs, add a Makefile

lua_app.cpp had grown to 701 lines holding every binding, the module loader and the
app lifecycle, so new bindings landed wherever the cursor was. Each Lua table now has
its own file under bindings/, and the app is recovered from the lua_State's extra
space instead of a file-static, so a second state cannot reach the wrong app.

Three tests each redeclared the binding surface, which broke twice this session when
a binding changed; test/fake_device.lua is now the single stub. `make test` runs all
four suites and pins Lua 5.4, matching the vendored interpreter rather than the 5.2
the tests had silently been using.
This commit is contained in:
2026-08-01 11:17:42 -04:00
parent 36953bb140
commit 393ce3c0ed
15 changed files with 795 additions and 628 deletions
+45
View File
@@ -0,0 +1,45 @@
// Touch panel reads. Coordinates are calibrated and rotated by LuaApp::mapTouch;
// the raw ADC pair is exposed separately because calibration cannot use itself.
#include "../bindings.h"
#include "../lua_app.h"
static int l_input_getTouch(lua_State* L) {
LuaApp* owner = app(L);
if (!owner->touch.touched()) {
lua_pushnil(L);
return 1;
}
TS_Point point = owner->touch.getPoint();
int16_t x, y;
LuaApp::mapTouch(owner->tft, point, x, y);
lua_pushinteger(L, x);
lua_pushinteger(L, y);
return 2;
}
static int l_input_getRawTouch(lua_State* L) {
LuaApp* owner = app(L);
if (!owner->touch.touched()) {
lua_pushnil(L);
return 1;
}
TS_Point point = owner->touch.getPoint();
lua_pushinteger(L, point.x);
lua_pushinteger(L, point.y);
return 2;
}
static int l_input_touched(lua_State* L) {
lua_pushboolean(L, app(L)->touch.touched());
return 1;
}
void registerInput(lua_State* L) {
static const luaL_Reg lib[] = {{"getTouch", l_input_getTouch},
{"getRawTouch", l_input_getRawTouch},
{"touched", l_input_touched},
{nullptr, nullptr}};
luaL_newlib(L, lib);
lua_setglobal(L, "input");
}