[#38] Support metadata on vars
This commit is contained in:
parent
401aeecf52
commit
973c4e5c9e
5 changed files with 25 additions and 7 deletions
|
|
@ -122,7 +122,13 @@
|
||||||
#(Boolean/parseBoolean %))
|
#(Boolean/parseBoolean %))
|
||||||
name-sym (symbol name)
|
name-sym (symbol name)
|
||||||
sym (symbol ns-name-str name)
|
sym (symbol ns-name-str name)
|
||||||
code (get-maybe-string var "code")]
|
code (get-maybe-string var "code")
|
||||||
|
vmeta (some-> (get var "meta")
|
||||||
|
bytes->string
|
||||||
|
edn/read-string)
|
||||||
|
name-sym (if vmeta
|
||||||
|
(with-meta name-sym vmeta)
|
||||||
|
name-sym)]
|
||||||
[name-sym
|
[name-sym
|
||||||
(or code
|
(or code
|
||||||
(fn [& args]
|
(fn [& args]
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@
|
||||||
(swap! env update-in [:namespaces ns-name]
|
(swap! env update-in [:namespaces ns-name]
|
||||||
(fn [ns-map]
|
(fn [ns-map]
|
||||||
(if ns-map ns-map {:obj sci-ns})))
|
(if ns-map ns-map {:obj sci-ns})))
|
||||||
(doseq [[var-name var-value] vars]
|
(doseq [[var-name var-value :as var] vars]
|
||||||
(cond (ifn? var-value)
|
(cond (ifn? var-value)
|
||||||
(swap! env assoc-in [:namespaces ns-name var-name]
|
(swap! env assoc-in [:namespaces ns-name var-name]
|
||||||
(sci/new-var
|
(sci/new-var
|
||||||
(symbol (str ns-name) (str var-name)) var-value))
|
(symbol (str ns-name) (str var-name)) var-value (meta var-name)))
|
||||||
(string? var-value)
|
(string? var-value)
|
||||||
(sci/eval-string* ctx var-value))))))
|
(sci/eval-string* ctx var-value))))))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,8 @@
|
||||||
"my/other-tag" "pod.test-pod/read-other-tag"}
|
"my/other-tag" "pod.test-pod/read-other-tag"}
|
||||||
"namespaces"
|
"namespaces"
|
||||||
[{"name" "pod.test-pod"
|
[{"name" "pod.test-pod"
|
||||||
"vars" (into [{"name" "add-sync"}
|
"vars" (into [{"name" "add-sync"
|
||||||
|
"meta" "{:doc \"add the arguments\"}"}
|
||||||
{"name" "range-stream"
|
{"name" "range-stream"
|
||||||
"async" "true"}
|
"async" "true"}
|
||||||
{"name" "assoc"}
|
{"name" "assoc"}
|
||||||
|
|
@ -127,7 +128,8 @@
|
||||||
{"name" "other-tag"}
|
{"name" "other-tag"}
|
||||||
;; reads thing with other tag
|
;; reads thing with other tag
|
||||||
{"name" "read-other-tag"
|
{"name" "read-other-tag"
|
||||||
"code" "(defn read-other-tag [x] [x x])"}
|
"code" "(defn read-other-tag [x] [x x])"
|
||||||
|
"meta" "{:doc \"unread\"}"}
|
||||||
{"name" "-local-date-time"}
|
{"name" "-local-date-time"}
|
||||||
{"name" "transit-stuff"
|
{"name" "transit-stuff"
|
||||||
"code" "
|
"code" "
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,10 @@
|
||||||
(def add-result (pod.test-pod/add-sync 1 2 3))
|
(def add-result (pod.test-pod/add-sync 1 2 3))
|
||||||
(def nil-result (pod.test-pod/return-nil))
|
(def nil-result (pod.test-pod/return-nil))
|
||||||
|
|
||||||
|
(def add-sync-meta (:doc (meta #'pod.test-pod/add-sync)))
|
||||||
|
(def error-meta (:doc (meta #'pod.test-pod/error)))
|
||||||
|
(def read-other-tag-meta (:doc (meta #'pod.test-pod/read-other-tag)))
|
||||||
|
|
||||||
(def x9 pod.test-pod/x9)
|
(def x9 pod.test-pod/x9)
|
||||||
|
|
||||||
(def tagged (if (= "edn" fmt)
|
(def tagged (if (= "edn" fmt)
|
||||||
|
|
@ -108,4 +112,7 @@
|
||||||
fn-called
|
fn-called
|
||||||
local-date-time
|
local-date-time
|
||||||
assoc-string-array
|
assoc-string-array
|
||||||
should-be-1]
|
should-be-1
|
||||||
|
add-sync-meta
|
||||||
|
error-meta
|
||||||
|
read-other-tag-meta]
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,10 @@
|
||||||
3
|
3
|
||||||
true ;; local-date
|
true ;; local-date
|
||||||
true ;; roundtrip string array
|
true ;; roundtrip string array
|
||||||
1]
|
1
|
||||||
|
"add the arguments"
|
||||||
|
nil
|
||||||
|
nil]
|
||||||
(concat ret (repeat ::nil)))]
|
(concat ret (repeat ::nil)))]
|
||||||
(if (instance? java.util.regex.Pattern expected)
|
(if (instance? java.util.regex.Pattern expected)
|
||||||
(is (re-find expected actual))
|
(is (re-find expected actual))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue