lua: scoreboard iter — table.getn/foreach/foreachi + string.reverse (sort.lua unblocked past getn)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
This commit is contained in:
@@ -918,6 +918,21 @@
|
||||
(dict-set! string "gmatch" lua-string-gmatch)
|
||||
(dict-set! string "gsub" lua-string-gsub)
|
||||
(dict-set! string "format" lua-string-format)
|
||||
(define
|
||||
lua-string-reverse
|
||||
(fn (s)
|
||||
(let ((out ""))
|
||||
(begin
|
||||
(define
|
||||
rloop
|
||||
(fn (i)
|
||||
(when (>= i 0)
|
||||
(begin
|
||||
(set! out (str out (char-at s i)))
|
||||
(rloop (- i 1))))))
|
||||
(rloop (- (len s) 1))
|
||||
out))))
|
||||
(dict-set! string "reverse" lua-string-reverse)
|
||||
|
||||
;; ── math library ──────────────────────────────────────────────
|
||||
(define math {})
|
||||
@@ -1167,6 +1182,44 @@
|
||||
(dict-set! table "sort" lua-table-sort)
|
||||
(dict-set! table "unpack" lua-unpack)
|
||||
(dict-set! table "maxn" lua-table-maxn)
|
||||
(dict-set! table "getn" lua-len)
|
||||
(dict-set! table "setn" (fn (t n) nil))
|
||||
(define
|
||||
lua-table-foreach
|
||||
(fn (t f)
|
||||
(let ((ks (keys t)))
|
||||
(begin
|
||||
(define
|
||||
tfl
|
||||
(fn (i)
|
||||
(when (< i (len ks))
|
||||
(let ((k (nth ks i)))
|
||||
(cond
|
||||
((= k "__meta") (tfl (+ i 1)))
|
||||
(else
|
||||
(let ((r (lua-call f (lua-key-to-value k) (get t k))))
|
||||
(cond
|
||||
((lua-truthy? r) r)
|
||||
(else (tfl (+ i 1)))))))))))
|
||||
(tfl 0)
|
||||
nil))))
|
||||
(dict-set! table "foreach" lua-table-foreach)
|
||||
(define
|
||||
lua-table-foreachi
|
||||
(fn (t f)
|
||||
(let ((n (lua-len t)))
|
||||
(begin
|
||||
(define
|
||||
tfi
|
||||
(fn (i)
|
||||
(when (<= i n)
|
||||
(let ((r (lua-call f i (get t (str i)))))
|
||||
(cond
|
||||
((lua-truthy? r) r)
|
||||
(else (tfi (+ i 1))))))))
|
||||
(tfi 1)
|
||||
nil))))
|
||||
(dict-set! table "foreachi" lua-table-foreachi)
|
||||
|
||||
(define unpack lua-unpack)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user