diff --git a/lib/lua/runtime.sx b/lib/lua/runtime.sx index 3f4fa4be..1880f2ed 100644 --- a/lib/lua/runtime.sx +++ b/lib/lua/runtime.sx @@ -990,10 +990,28 @@ lua-string-byte (fn (&rest args) (let ((s (first args)) - (i (if (> (len args) 1) (nth args 1) 1))) - (cond - ((or (< i 1) (> i (len s))) nil) - (else (char-code (char-at s (- i 1)))))))) + (i-raw (if (> (len args) 1) (nth args 1) nil)) + (j-raw (if (> (len args) 2) (nth args 2) nil))) + (let ((i (if (= i-raw nil) 1 i-raw))) + (let ((j (if (= j-raw nil) i j-raw))) + (let ((slen (len s))) + (let ((ni (cond ((< i 0) (+ slen i 1)) ((= i 0) 1) (else i))) + (nj (cond ((< j 0) (+ slen j 1)) (else j)))) + (cond + ((or (< ni 1) (> ni slen) (< nj ni)) nil) + ((= ni nj) (char-code (char-at s (- ni 1)))) + (else + (let ((out (list (quote lua-multi)))) + (begin + (define + b-loop + (fn (k) + (when (and (<= k nj) (<= k slen)) + (begin + (set! out (append out (list (char-code (char-at s (- k 1)))))) + (b-loop (+ k 1)))))) + (b-loop ni) + out))))))))))) (define lua-char-one diff --git a/lib/lua/scoreboard.json b/lib/lua/scoreboard.json index 0946325e..0c1f859b 100644 --- a/lib/lua/scoreboard.json +++ b/lib/lua/scoreboard.json @@ -51,19 +51,19 @@ "name": "attrib.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'C' not found\\\\\\\"\\", - "ms": 6636 + "ms": 6698 }, { "name": "big.lua", "status": "timeout", "reason": "per-test timeout", - "ms": 8008 + "ms": 8002 }, { "name": "calls.lua", "status": "fail", "reason": "undefined symbol: fat\\", - "ms": 5129 + "ms": 5168 }, { "name": "checktable.lua", @@ -87,7 +87,7 @@ "name": "constructs.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to compare incompat", - "ms": 6962 + "ms": 7174 }, { "name": "db.lua", @@ -99,13 +99,13 @@ "name": "errors.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 3442 + "ms": 3446 }, { "name": "events.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 7474 + "ms": 7749 }, { "name": "files.lua", @@ -123,13 +123,13 @@ "name": "literals.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 1965 + "ms": 1931 }, { "name": "locals.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", - "ms": 1784 + "ms": 1767 }, { "name": "main.lua", @@ -141,43 +141,43 @@ "name": "math.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", - "ms": 4413 + "ms": 4412 }, { "name": "nextvar.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 7389 + "ms": 7512 }, { "name": "pm.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 6252 + "ms": 6522 }, { "name": "sort.lua", "status": "timeout", "reason": "per-test timeout", - "ms": 8004 + "ms": 8008 }, { "name": "strings.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 4236 + "ms": 4282 }, { "name": "vararg.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 2348 + "ms": 2373 }, { "name": "verybig.lua", "status": "pass", "reason": "", - "ms": 1074 + "ms": 1080 } ] } \ No newline at end of file diff --git a/lib/lua/scoreboard.md b/lib/lua/scoreboard.md index 2fc7cca1..b2b79717 100644 --- a/lib/lua/scoreboard.md +++ b/lib/lua/scoreboard.md @@ -18,25 +18,25 @@ fail=12 timeout=3 skip=8 total=24 |---|---|---|---:| | all.lua | skip | driver uses dofile to chain other tests | 0 | | api.lua | skip | requires testC (C debug library) | 0 | -| attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\ | 6636 | -| big.lua | timeout | per-test timeout | 8008 | -| calls.lua | fail | undefined symbol: fat\ | 5129 | +| attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\ | 6698 | +| big.lua | timeout | per-test timeout | 8002 | +| calls.lua | fail | undefined symbol: fat\ | 5168 | | checktable.lua | skip | internal debug helpers | 0 | | closure.lua | timeout | per-test timeout | 8001 | | code.lua | skip | bytecode inspection via debug library | 0 | -| constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat | 6962 | +| constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat | 7174 | | db.lua | skip | debug library | 0 | -| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3442 | -| events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7474 | +| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3446 | +| events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7749 | | files.lua | skip | io library | 0 | | gc.lua | skip | collectgarbage / finalisers | 0 | -| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1965 | -| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1784 | +| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1931 | +| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1767 | | main.lua | skip | standalone interpreter driver | 0 | -| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 4413 | -| nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7389 | -| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6252 | -| sort.lua | timeout | per-test timeout | 8004 | -| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4236 | -| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2348 | -| verybig.lua | pass | - | 1074 | +| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 4412 | +| nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7512 | +| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6522 | +| sort.lua | timeout | per-test timeout | 8008 | +| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4282 | +| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2373 | +| verybig.lua | pass | - | 1080 | diff --git a/plans/lua-on-sx.md b/plans/lua-on-sx.md index 42fbad15..2f397799 100644 --- a/plans/lua-on-sx.md +++ b/plans/lua-on-sx.md @@ -82,6 +82,7 @@ Each item: implement → tests → tick box → update progress log. _Newest first. Agent appends on every commit._ +- 2026-04-25: lua: scoreboard iteration — `string.byte(s, i, j)` now returns multi-values for ranges (was single byte only). 393/393 green; scoreboard unchanged. - 2026-04-25: lua: scoreboard iteration — `math.sinh`/`cosh`/`tanh` (Lua 5.1 hyperbolic). 393/393 green; scoreboard unchanged. - 2026-04-25: lua: scoreboard iteration — tried two-phase eval (extract top-level `function f` decls, evaluate them BEFORE the guard so they leak to top-level env, then run the rest inside guard). Broke method-decl tests because `function a:add(...)` requires `a` to exist, and `a = {...}` was in the deferred phase-2. Reverted. Real fix needs `_G` table or AST-level rewriting of top-level returns into chunk-result mutations. 393/393 green. - 2026-04-25: lua: scoreboard iteration — `string.dump` stub (returns string-of-fn). Diagnosed calls.lua: file ENDS with `return deep` (line 295), which makes my `lua-has-top-return?` correctly return true, triggering the guard, which scopes user defines and breaks loadstring's lexical capture of `fat`. The fix would require either rewriting top-level returns into a different mechanism (post-processing the AST) or implementing a real `_G` global table for global assignment/lookup. Both larger.