lua: skip top-level guard when chunk has no top-level return; loadstring sees user globals
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-25 00:14:15 +00:00
parent abc98b7665
commit d170d5fbae
4 changed files with 68 additions and 45 deletions

View File

@@ -568,12 +568,39 @@
(else sx)))))))
(else sx))))
(define
lua-has-top-return?
(fn (node)
(cond
((not (= (type-of node) "list")) false)
((= (len node) 0) false)
((= (first node) (quote lua-return)) true)
((or (= (first node) (quote lua-function))
(= (first node) (quote lua-local-function))
(= (first node) (quote lua-function-decl)))
false)
(else
(lua-has-top-return-children? (rest node) 0)))))
(define
lua-has-top-return-children?
(fn (children i)
(cond
((>= i (len children)) false)
((lua-has-top-return? (nth children i)) true)
(else (lua-has-top-return-children? children (+ i 1))))))
(define
lua-eval-ast
(fn (src)
(let ((sx (lua-transpile src)))
(let ((sx2 (lua-unwrap-final-return sx)))
(eval-expr (lua-tx-function-guard sx2))))))
(let ((parsed (lua-parse src)))
(let ((sx (lua-tx parsed)))
(let ((sx2 (lua-unwrap-final-return sx)))
(cond
((lua-has-top-return? parsed)
(eval-expr (lua-tx-function-guard sx2)))
(else
(eval-expr sx2))))))))
(define
lua-tx-multi-args