New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Operate scope in context #506
Comments
You seem to be using scripts to program event handlers, modifying global state. This may match what you want: https://rhai.rs/book/patterns/events.html |
okay, thank you |
let mut engine = Engine::new();
let ast = engine.compile_(script_code);
let mut scope = Scope::new();
scope.set_or_push("host", "127.0.0.1");
engine.run_ast_with_scope(&mut scope, &ast)?;
fn push_item(s) {
print(host);
}
print(host);
push_item("A");
let mut engine = Engine::new();
let ast = engine.compile_(script_code);
let mut scope = Scope::new();
scope.set_or_push("host", "127.0.0.1");
engine.call_fn(&mut scope, &ast, "verify", (host,))?;
fn push_item(s) {
print(host);
}
fn verify(s){
print(host);
push_item(host);
}
|
Functions cannot access the global scope. Functions are pure. Bind fn push_item(s) {
print(this);
}
host.push_item("A"); If you just want read access, pass it as a parameter. |
No it doesn't. As per the example, it is created once and kept alive inside a |
Has this issue been resolved? |
list
The text was updated successfully, but these errors were encountered: