mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 19:19:53 +00:00
Add optional env arguments to eval functions.
This commit is contained in:
parent
2bbf9fdcc5
commit
090a6a8c5c
@ -1508,7 +1508,8 @@ value, one key will be ignored."
|
|||||||
(defn eval-string
|
(defn eval-string
|
||||||
"Evaluates a string in the current environment. If more control over the
|
"Evaluates a string in the current environment. If more control over the
|
||||||
environment is needed, use run-context."
|
environment is needed, use run-context."
|
||||||
[str]
|
[str env &]
|
||||||
|
(default env *env*)
|
||||||
(var state (string str))
|
(var state (string str))
|
||||||
(defn chunks [buf _]
|
(defn chunks [buf _]
|
||||||
(def ret state)
|
(def ret state)
|
||||||
@ -1517,7 +1518,7 @@ value, one key will be ignored."
|
|||||||
(buffer/push-string buf str)
|
(buffer/push-string buf str)
|
||||||
(buffer/push-string buf "\n")))
|
(buffer/push-string buf "\n")))
|
||||||
(var returnval nil)
|
(var returnval nil)
|
||||||
(run-context *env* chunks
|
(run-context env chunks
|
||||||
(fn [sig x f source]
|
(fn [sig x f source]
|
||||||
(if (= sig :dead)
|
(if (= sig :dead)
|
||||||
(set returnval x)
|
(set returnval x)
|
||||||
@ -1528,8 +1529,9 @@ value, one key will be ignored."
|
|||||||
(defn eval
|
(defn eval
|
||||||
"Evaluates a form in the current environment. If more control over the
|
"Evaluates a form in the current environment. If more control over the
|
||||||
environment is needed, use run-context."
|
environment is needed, use run-context."
|
||||||
[form]
|
[form env &]
|
||||||
(def res (compile form *env* "eval"))
|
(default env *env*)
|
||||||
|
(def res (compile form env "eval"))
|
||||||
(if (= (type res) :function)
|
(if (= (type res) :function)
|
||||||
(res)
|
(res)
|
||||||
(error (res :error))))
|
(error (res :error))))
|
||||||
|
Loading…
Reference in New Issue
Block a user