lua: unpack treats explicit nil i/j as missing (defaults to 1 and #t)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-25 00:31:03 +00:00
parent fd32bcf547
commit 1b34d41b33
4 changed files with 62 additions and 54 deletions

View File

@@ -1552,23 +1552,25 @@
(define
lua-unpack
(fn (&rest args)
(let ((t (first args))
(i (if (> (len args) 1) (nth args 1) 1))
(j (if (> (len args) 2) (nth args 2) (lua-len (first args)))))
(cond
((> i j) nil)
(else
(let ((out (list (quote lua-multi))))
(begin
(define
loop
(fn (k)
(when (<= k j)
(begin
(set! out (append out (list (get t (str k)))))
(loop (+ k 1))))))
(loop i)
out)))))))
(let ((t (first args)))
(let ((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))
(j (if (= j-raw nil) (lua-len t) j-raw)))
(cond
((> i j) nil)
(else
(let ((out (list (quote lua-multi))))
(begin
(define
loop
(fn (k)
(when (<= k j)
(begin
(set! out (append out (list (get t (str k)))))
(loop (+ k 1))))))
(loop i)
out)))))))))
(define
lua-table-maxn