mirror of
https://github.com/janet-lang/janet
synced 2024-06-17 02:40:00 +00:00
Add module/value
function to make grabbing bindings out module tables.
This commit is contained in:
parent
fe7d35171f
commit
487d333024
|
@ -2,6 +2,7 @@
|
|||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## Unreleased - ???
|
||||
- Add `module/value`.
|
||||
- Remove `file/popen`. Use `os/spawn` with the `:pipe` options instead.
|
||||
- Fix bug in peg `thru` and `to` combinators.
|
||||
- Fix printing issue in `doc` macro.
|
||||
|
|
|
@ -2717,6 +2717,21 @@
|
|||
circular dependencies.`
|
||||
@{})
|
||||
|
||||
(defn module/value
|
||||
``Given a module table, get the value bound to a symbol `sym`. If `private` is
|
||||
truthy, will also resolve private module symbols. If no binding is found, will return
|
||||
nil.``
|
||||
[module sym &opt private]
|
||||
(def entry (get module sym))
|
||||
(if entry
|
||||
(let [v (in entry :value)
|
||||
r (in entry :ref)
|
||||
p (in entry :private)]
|
||||
(if p (if private nil (break)))
|
||||
(if (and r (array? r))
|
||||
(get r 0)
|
||||
v))))
|
||||
|
||||
(defn dofile
|
||||
``Evaluate a file, file path, or stream and return the resulting environment. :env, :expander,
|
||||
:source, :evaluator, :read, and :parser are passed through to the underlying
|
||||
|
|
Loading…
Reference in New Issue
Block a user