Closed Imberflur closed 4 years ago
What is wrong with just eval
? Pass in your function script and it gets evaluated...
The function can be defined within the script itself using the fn
keyword.
If you want to run the function multiple times and don't want to keep parsing it, first compile
the function into an AST
then eval_ast
it.
https://github.com/jonathandturner/rhai/pull/98
In this PR, Engine
cleans up after itself.
In some cases, I don't need the script to define any functions instead I want it to perform some calculations and return a value without modifying the engine. This could be accomplished by having the script define a function and then use
engine.call_fn
but this requires that initial mutation of the engine to define that function.