rhaiscript / rhai

Rhai - An embedded scripting language for Rust.
https://crates.io/crates/rhai
Apache License 2.0
3.79k stars 177 forks source link

How to inject values into my script #18

Closed matthiasbeyer closed 4 years ago

matthiasbeyer commented 7 years ago

Following usecase:

I have users input rhai script. I want some environment to be set up for every invocation of the script (Lets think of a global variable that should be available when the script is run).

How do I do that?

luciusmagn commented 7 years ago

I know I am necroing an ancient issue, but currently, the way to do would be modifying your Scope manually. Probably in the (hopefully near) future, there will be a more handy interface.

JoshLambda commented 5 years ago

There could be a big security issue when using Scope for this. Script users could read/temper with the application context through Scope, while these values are only meant for the internal use of rust-side functions.

If Rhai scripting language is ever to have effect on something else than itself, the input data should be provided separately from Scope or any script-user directly accessible data.

schungx commented 4 years ago

@JoshLambda not sure I follow you. The Scope is a sandboxed environment. The script should not be able to affect anything outside of this Scope except through registered functions.