Dune.eval_string
You're seeing just the function
eval_string
, go back to Dune module for more information.
Specs
eval_string(String.t(), Keyword.t()) :: Dune.Success.t() | Dune.Failure.t()
Evaluates the string in the sandbox.
Available options are detailed in Dune.Parser.Opts
(for parsing-time restrictions)
and in Dune.Eval.Opts
(for runtime restrictions).
Returns a Dune.Success
struct if the execution went successfully,
a Dune.Failure
else.
Examples
iex> Dune.eval_string("IO.puts('Hello world!')")
%Dune.Success{inspected: ":ok", stdio: "Hello world!\n", value: :ok}
iex> Dune.eval_string("File.cwd!()")
%Dune.Failure{message: "** (DuneRestrictedError) function File.cwd!/0 is restricted", type: :restricted}
iex> Dune.eval_string("List.duplicate(:spam, 100_000)")
%Dune.Failure{message: "Execution stopped - memory limit exceeded", stdio: "", type: :memory}
iex> Dune.eval_string("Foo.bar()")
%Dune.Failure{message: "** (UndefinedFunctionError) function Foo.bar/0 is undefined (module Foo is not available)", type: :exception}
iex> Dune.eval_string("][")
%Dune.Failure{message: "unexpected token: ]", type: :parsing}
Atoms used during parsing and execution might be transformed to prevent atom leaks:
iex> Dune.eval_string("some_variable = IO.inspect(:some_atom)")
%Dune.Success{inspected: ":some_atom", stdio: ":some_atom\n", value: :a__Dune_atom_2__}
The value
field shows the actual value, but inspected
and stdio
are safe to display to the user.