mirror of
https://github.com/janet-lang/janet
synced 2024-12-26 08:20: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
|
:on-status onsignal
|
||||||
:source "repl"}))
|
:source "repl"}))
|
||||||
|
|
||||||
(defn all-bindings
|
(defn- env-walk
|
||||||
"Get all symbols available in the current environment."
|
[pred]
|
||||||
[]
|
|
||||||
(def env (fiber/getenv (fiber/current)))
|
(def env (fiber/getenv (fiber/current)))
|
||||||
(def envs @[])
|
(def envs @[])
|
||||||
(do (var e env) (while e (array/push envs e) (set e (table/getproto e))))
|
(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
|
(loop [envi :in envs
|
||||||
k :keys envi
|
k :keys envi
|
||||||
:when (symbol? k)]
|
:when (pred k)]
|
||||||
(put symbol-set k true))
|
(put ret-set k true))
|
||||||
(sort (keys symbol-set)))
|
(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
|
# Clean up some extra defs
|
||||||
(put _env 'process/opts nil)
|
(put _env 'process/opts nil)
|
||||||
|
(put _env 'env-walk nil)
|
||||||
(put _env '_env nil)
|
(put _env '_env nil)
|
||||||
|
|
||||||
###
|
###
|
||||||
|
@ -415,7 +415,7 @@ static const JanetReg fiber_cfuns[] = {
|
|||||||
"\tu - block user signals\n"
|
"\tu - block user signals\n"
|
||||||
"\ty - block yield signals\n"
|
"\ty - block yield signals\n"
|
||||||
"\t0-9 - block a specific user signal\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,
|
"fiber/status", cfun_fiber_status,
|
||||||
|
Loading…
Reference in New Issue
Block a user