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
+4 -20
View File
@@ -1,24 +1,8 @@
-- Run: lua test/ui_layout.lua
-- Stubs the firmware bindings and asserts the rects ui.lua computes.
package.path = "sdcard/lib/?.lua;" .. package.path
local FONT_HEIGHT, CHAR_WIDTH = 8, 6
local now = 0
local painted = {}
gui = {
color = function(r, g, b) return r * 65536 + g * 256 + b end,
width = function() return 320 end,
height = function() return 480 end,
clear = function() end,
fillRect = function() end,
drawText = function(label, x, y) painted[#painted + 1] = {label = label, x = x, y = y} end,
roundRect = function() end,
fontHeight = function() return FONT_HEIGHT end,
textWidth = function(text) return #text * CHAR_WIDTH end,
}
sys = {millis = function() return now end}
-- Asserts the rects ui.lua computes, against the shared fake device.
package.path = "sdcard/lib/?.lua;test/?.lua;" .. package.path
local device = require("fake_device").install()
local ui = require("ui")
local function rect(node)
@@ -85,7 +69,7 @@ assert(fired == 1, "release inside must fire once")
-- The pressed look is held briefly, then cleared on a later draw.
assert(button.pressed, "pressed look must outlast the release")
now = now + 100
device.now = device.now + 100
app:draw()
assert(not button.pressed, "pressed look must clear after the hold")