lua: string metatable, high-byte chars, multi-return truthy, perf
This commit is contained in:
1
.claude/scheduled_tasks.lock
Normal file
1
.claude/scheduled_tasks.lock
Normal file
@@ -0,0 +1 @@
|
||||
{"sessionId":"31c80255-eb92-43e4-8997-84ad84e27326","pid":90960,"procStart":"564684","acquiredAt":1777049890282}
|
||||
@@ -1,4 +1,4 @@
|
||||
(define lua-truthy? (fn (v) (and (not (= v nil)) (not (= v false)))))
|
||||
(define lua-truthy? (fn (v) (let ((v1 (if (and (= (type-of v) "list") (> (len v) 0) (= (first v) (quote lua-multi))) (if (> (len v) 1) (nth v 1) nil) v))) (and (not (= v1 nil)) (not (= v1 false))))))
|
||||
|
||||
(define
|
||||
lua-to-number
|
||||
@@ -151,18 +151,19 @@
|
||||
lua-eq
|
||||
(fn
|
||||
(a b)
|
||||
(cond
|
||||
((and (= a nil) (= b nil)) true)
|
||||
((or (= a nil) (= b nil)) false)
|
||||
((and (= (type-of a) (type-of b)) (= a b)) true)
|
||||
((and (= (type-of a) "dict") (= (type-of b) "dict"))
|
||||
(let
|
||||
((m (lua-get-mm a "__eq")))
|
||||
(cond
|
||||
((not (= m nil))
|
||||
(let ((r (lua-first (m a b)))) (and (not (= r nil)) (not (= r false)))))
|
||||
(else false))))
|
||||
(else false))))
|
||||
(let ((a (lua-first a)) (b (lua-first b)))
|
||||
(cond
|
||||
((and (= a nil) (= b nil)) true)
|
||||
((or (= a nil) (= b nil)) false)
|
||||
((and (= (type-of a) (type-of b)) (= a b)) true)
|
||||
((and (= (type-of a) "dict") (= (type-of b) "dict"))
|
||||
(let
|
||||
((m (lua-get-mm a "__eq")))
|
||||
(cond
|
||||
((not (= m nil))
|
||||
(let ((r (lua-first (m a b)))) (and (not (= r nil)) (not (= r false)))))
|
||||
(else false))))
|
||||
(else false)))))
|
||||
|
||||
(define lua-neq (fn (a b) (not (lua-eq a b))))
|
||||
|
||||
@@ -170,44 +171,46 @@
|
||||
lua-lt
|
||||
(fn
|
||||
(a b)
|
||||
(cond
|
||||
((and (= (type-of a) "number") (= (type-of b) "number")) (< a b))
|
||||
((and (= (type-of a) "string") (= (type-of b) "string")) (< a b))
|
||||
(else
|
||||
(let
|
||||
((m (lua-get-mm a "__lt")))
|
||||
(cond
|
||||
((not (= m nil))
|
||||
(let ((r (lua-first (m a b)))) (and (not (= r nil)) (not (= r false)))))
|
||||
(else
|
||||
(let
|
||||
((m2 (lua-get-mm b "__lt")))
|
||||
(cond
|
||||
((not (= m2 nil))
|
||||
(let ((r (lua-first (m2 a b)))) (and (not (= r nil)) (not (= r false)))))
|
||||
(else (error "lua: attempt to compare incompatible types")))))))))))
|
||||
(let ((a (lua-first a)) (b (lua-first b)))
|
||||
(cond
|
||||
((and (= (type-of a) "number") (= (type-of b) "number")) (< a b))
|
||||
((and (= (type-of a) "string") (= (type-of b) "string")) (< a b))
|
||||
(else
|
||||
(let
|
||||
((m (lua-get-mm a "__lt")))
|
||||
(cond
|
||||
((not (= m nil))
|
||||
(let ((r (lua-first (m a b)))) (and (not (= r nil)) (not (= r false)))))
|
||||
(else
|
||||
(let
|
||||
((m2 (lua-get-mm b "__lt")))
|
||||
(cond
|
||||
((not (= m2 nil))
|
||||
(let ((r (lua-first (m2 a b)))) (and (not (= r nil)) (not (= r false)))))
|
||||
(else (error "lua: attempt to compare incompatible types"))))))))))))
|
||||
|
||||
(define
|
||||
lua-le
|
||||
(fn
|
||||
(a b)
|
||||
(cond
|
||||
((and (= (type-of a) "number") (= (type-of b) "number")) (<= a b))
|
||||
((and (= (type-of a) "string") (= (type-of b) "string"))
|
||||
(or (< a b) (= a b)))
|
||||
(else
|
||||
(let
|
||||
((m (lua-get-mm a "__le")))
|
||||
(cond
|
||||
((not (= m nil))
|
||||
(let ((r (lua-first (m a b)))) (and (not (= r nil)) (not (= r false)))))
|
||||
(else
|
||||
(let
|
||||
((m2 (lua-get-mm b "__le")))
|
||||
(cond
|
||||
((not (= m2 nil))
|
||||
(let ((r (lua-first (m2 a b)))) (and (not (= r nil)) (not (= r false)))))
|
||||
(else (not (lua-lt b a))))))))))))
|
||||
(let ((a (lua-first a)) (b (lua-first b)))
|
||||
(cond
|
||||
((and (= (type-of a) "number") (= (type-of b) "number")) (<= a b))
|
||||
((and (= (type-of a) "string") (= (type-of b) "string"))
|
||||
(or (< a b) (= a b)))
|
||||
(else
|
||||
(let
|
||||
((m (lua-get-mm a "__le")))
|
||||
(cond
|
||||
((not (= m nil))
|
||||
(let ((r (lua-first (m a b)))) (and (not (= r nil)) (not (= r false)))))
|
||||
(else
|
||||
(let
|
||||
((m2 (lua-get-mm b "__le")))
|
||||
(cond
|
||||
((not (= m2 nil))
|
||||
(let ((r (lua-first (m2 a b)))) (and (not (= r nil)) (not (= r false)))))
|
||||
(else (not (lua-lt b a)))))))))))))
|
||||
|
||||
(define lua-gt (fn (a b) (lua-lt b a)))
|
||||
|
||||
@@ -271,14 +274,16 @@
|
||||
(fn (i)
|
||||
(when (< i (len v))
|
||||
(begin
|
||||
(set! t (assoc t (str array-idx) (nth v i)))
|
||||
(when (not (= (nth v i) nil))
|
||||
(set! t (assoc t (str array-idx) (nth v i))))
|
||||
(set! array-idx (+ array-idx 1))
|
||||
(spread-loop (+ i 1))))))
|
||||
(spread-loop 1)))
|
||||
(else
|
||||
(let ((val (if (lua-multi? v) (lua-first v) v)))
|
||||
(begin
|
||||
(set! t (assoc t (str array-idx) val))
|
||||
(when (not (= val nil))
|
||||
(set! t (assoc t (str array-idx) val)))
|
||||
(set! array-idx (+ array-idx 1))))))))
|
||||
((= (first f) "kv")
|
||||
(let
|
||||
@@ -294,6 +299,7 @@
|
||||
(t k)
|
||||
(cond
|
||||
((= t nil) nil)
|
||||
((= (type-of t) "string") (lua-get string k))
|
||||
((not (= (type-of t) "dict")) nil)
|
||||
(else
|
||||
(let
|
||||
@@ -315,6 +321,8 @@
|
||||
(let
|
||||
((key (str k)))
|
||||
(cond
|
||||
((= v nil)
|
||||
(when (has-key? t key) (dict-delete! t key)))
|
||||
((has-key? t key) (dict-set! t key v))
|
||||
(else
|
||||
(let
|
||||
@@ -1015,14 +1023,21 @@
|
||||
(b-loop ni)
|
||||
out)))))))))))
|
||||
|
||||
(define __lua-ctrl-32 " | ||||