function
boot.janet on line 2894 , column 1
(run-context opts )
Run a context. This evaluates expressions in an environment , and
encapsulates parsing , compilation , and evaluation. Takes a
dictionary `opts` with the following options:
* `:env` -- environment to compile against ; default is the current
environment.
* `:chunks` -- callback to read into a buffer ; default is
`getline` .
* `:on-status` -- callback when a value is evaluated ; default is
`debug/stacktrace` .
* `:on-compile-error` -- callback when compilation fails ; default
is `bad-compile` .
* `:on-compile-warning` -- callback for any linting error ; default
is `warn-compile` .
* `:on-parse-error` -- callback when parsing fails ; default is
`bad-parse` .
* `:fiber-flags` -- flags to wrap the compilation fiber with ;
default is `:ia` .
* `:evaluator` -- callback that executes thunks ; signature is
`(evaluator thunk source env where)` .
* `:source` -- source path for better errors (use keywords for
non-paths ); default is `:<anonymous>` .
* `:parser` -- custom parser that implements the same interface as
Janet 's built-in parser.
* `:read` -- function to get the next form ; signature is `(read env
source)` ; overrides all parsing.
* `:expander` -- function that is called on each top-level form
before being compiled.
Returns `(in env :exit-value env)` when complete.
(defn eval-string
``Evaluates a string in the current environment. If more control over the
environment is needed, use `run-context`.``
[str ]
(var state (string str ))
(defn chunks [buf _ ]
(def ret state )
(set state nil )
(when ret
(buffer/push-string buf str )
(buffer/push-string buf "\n" )))
(var returnval nil )
(run-context {:chunks chunks
:on-compile-error (fn compile-error [msg errf & ]
(error (string "compile error: " msg )))
:on-parse-error (fn parse-error [p x ]
(error (string "parse error: " (:error p ))))
:fiber-flags :i
:on-status (fn on-status [f val ]
(if-not (= (fiber/status f ) :dead )
(error val ))
(set returnval val ))
:source :eval-string })
returnval )