lua: multi-return + unpack at call sites (+10 tests)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 17:10:52 +00:00
parent 8bfeff8623
commit 2b448d99bc
4 changed files with 187 additions and 8 deletions

View File

@@ -169,3 +169,49 @@
(if (= t nil) nil (let ((v (get t (str k)))) (if (= v nil) nil v)))))
(define lua-set! (fn (t k v) (assoc t (str k) v)))
(define
lua-multi?
(fn
(v)
(and
(= (type-of v) "list")
(> (len v) 0)
(= (first v) (quote lua-multi)))))
(define
lua-first
(fn
(v)
(cond
((lua-multi? v) (if (> (len v) 1) (nth v 1) nil))
(else v))))
(define
lua-nth-ret
(fn
(v i)
(cond
((lua-multi? v)
(let ((idx (+ i 1))) (if (< idx (len v)) (nth v idx) nil)))
(else (if (= i 0) v nil)))))
(define
lua-pack-build
(fn
(vals i)
(cond
((>= i (len vals)) (list))
((= i (- (len vals) 1))
(let
((last (nth vals i)))
(if (lua-multi? last) (rest last) (list last))))
(else (cons (nth vals i) (lua-pack-build vals (+ i 1)))))))
(define
lua-pack-return
(fn
(vals)
(cond
((= (len vals) 0) (list (quote lua-multi)))
(else (cons (quote lua-multi) (lua-pack-build vals 0))))))