mirror of
https://github.com/janet-lang/janet
synced 2025-12-13 12:08:07 +00:00
Allow table/to-struct to take a prototype.
Use this prototype struct in freeze.
This commit is contained in:
@@ -2230,8 +2230,16 @@
|
||||
(tuple/slice (map freeze x))
|
||||
|
||||
(or (= tx :table) (= tx :struct))
|
||||
(let [sorted-kvs (array/join @[] ;(sort (map freeze (pairs x))))]
|
||||
(struct/with-proto (freeze (getproto x)) ;sorted-kvs))
|
||||
(let [temp-tab @{}]
|
||||
# Handle multiple unique keys that freeze. Result should
|
||||
# be independent of iteration order.
|
||||
(eachp [k v] x
|
||||
(def kk (freeze k))
|
||||
(def vv (freeze v))
|
||||
(def old (get temp-tab kk))
|
||||
(def new (if (= nil old) vv (max vv old)))
|
||||
(put temp-tab kk new))
|
||||
(table/to-struct temp-tab (freeze (getproto x))))
|
||||
|
||||
(= tx :buffer)
|
||||
(string x)
|
||||
|
||||
Reference in New Issue
Block a user