mirror of
https://github.com/janet-lang/janet
synced 2024-12-26 00:10:27 +00:00
Add all-dynamics to list current dynamic bindings.
This commit is contained in:
parent
7918add47d
commit
d1eca1cf52
@ -1735,21 +1735,31 @@
|
||||
:on-status onsignal
|
||||
:source "repl"}))
|
||||
|
||||
(defn all-bindings
|
||||
"Get all symbols available in the current environment."
|
||||
[]
|
||||
(defn- env-walk
|
||||
[pred]
|
||||
(def env (fiber/getenv (fiber/current)))
|
||||
(def envs @[])
|
||||
(do (var e env) (while e (array/push envs e) (set e (table/getproto e))))
|
||||
(def symbol-set @{})
|
||||
(def ret-set @{})
|
||||
(loop [envi :in envs
|
||||
k :keys envi
|
||||
:when (symbol? k)]
|
||||
(put symbol-set k true))
|
||||
(sort (keys symbol-set)))
|
||||
:when (pred k)]
|
||||
(put ret-set k true))
|
||||
(sort (keys ret-set)))
|
||||
|
||||
(defn all-bindings
|
||||
"Get all symbols available in the current environment."
|
||||
[]
|
||||
(env-walk symbol?))
|
||||
|
||||
(defn all-dynamics
|
||||
"Get all dynamic bindings in the current fiber."
|
||||
[]
|
||||
(env-walk keyword?))
|
||||
|
||||
# Clean up some extra defs
|
||||
(put _env 'process/opts nil)
|
||||
(put _env 'env-walk nil)
|
||||
(put _env '_env nil)
|
||||
|
||||
###
|
||||
|
@ -415,7 +415,7 @@ static const JanetReg fiber_cfuns[] = {
|
||||
"\tu - block user signals\n"
|
||||
"\ty - block yield signals\n"
|
||||
"\t0-9 - block a specific user signal\n"
|
||||
"\ti - inherit the environment from the current fiber")
|
||||
"\ti - inherit the environment from the current fiber (not related to signals)")
|
||||
},
|
||||
{
|
||||
"fiber/status", cfun_fiber_status,
|
||||
|
Loading…
Reference in New Issue
Block a user