function
boot.janet on line 2564 , column 1
(run-context opts )
Run a context. This evaluates expressions in an environment , and
encapsulates the parsing , compilation , and evaluation. Returns `(in
environment :exit-value environment)` when complete. `opts` is a
table or struct of options. The options are as follows:
`:chunks` callback to read into a buffer default is getline
`:on-parse-error` callback when parsing fails default is
bad-parse
`:env` the environment to compile against default is the
current env
`:source` source path for better errors (use keywords for
non-paths ) default is `:<anonymous>`
`:on-compile-error` callback when compilation fails default
is bad-compile
`:on-compile-warning` callback for any linting error default
is warn-compile
`:evaluator` callback that executes thunks. Signature is
(evaluator thunk source env where )
`:on-status` callback when a value is evaluated default is
debug/stacktrace.
`:fiber-flags` what flags to wrap the compilation fiber with.
Default is :ia.
`:expander` an optional function that is called on each top
level form before being compiled.
`:parser` provide a custom parser that implements the same
interface as Janet 's built-in parser.
`:read` optional function to get the next form , called like
`(read env source)` . Overrides all parsing.
(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 )