Add curenv to core.

This commit is contained in:
Calvin Rose 2020-08-22 10:16:14 -05:00
parent 5377e10532
commit f7c556ed8d
2 changed files with 9 additions and 0 deletions

View File

@ -2,6 +2,7 @@
All notable changes to this project will be documented in this file.
## Unreleased - ???
- Add `(curenv)`.
- Change `net/read`, `net/chunk`, and `net/write` to raise errors in the case of failures.
- Add `janet_continue_signal` to C API. This indirectly enables C functions that yield to the event loop
to raise errors or other signals.

View File

@ -2069,6 +2069,14 @@
(if ec "\e[0m" "")))
(eflush))
(defn curenv
"Get the current environment table. Same as (fiber/getenv (fiber/current)). If n
is provided, gets the nth prototype of the environment table."
[&opt n]
(var e (fiber/getenv (fiber/current)))
(if n (repeat n (if (= nil e) (break)) (set e (table/getproto e))))
e)
(defn run-context
"Run a context. This evaluates expressions in an environment,
and is encapsulates the parsing, compilation, and evaluation.