Comments (9)
You are not using new_raw by any chance?
Yes, an engine is created with Engine::new_raw()
because of safety reasons and side-effects as printing should not be possible.
So it looks like that to solve this the BasicArrayPackage
package has to be registered in the engine.
That's confusing because by using the raw engine (and so only the core package) arrays are supported but their functions not....
But I'm glad it's now clarified. Thanks for your help!
from rhai.
Actually, raw engines do not have anything to do with security and safety. You can always disable printing etc. by calling on_print and on_debug and put in stubs. You can also disable module resolution by setting it to an empty resolver. All these you can do on a standard Engine.
Okay, but safety starts with disabling everything and only enable what you need 😄
from rhai.
You can convert it first into an Array
by making it a Dynamic
.
let v : Dynamic = value.into();
from rhai.
Thanks for your quick reply.
Ok, that was not clear from the documentation:
https://rhai.rs/book/language/arrays.html#arrays
The Rust type of a Rhai array is rhai::Array which is an alias to Vec<Dynamic>.
So the documentation states the elements have to be Dynamic
value.
Unfortunately, it still not works:
let codes: Vec<String> = ....;
let foo: Dynamic = codes.into();
scope.push_constant("bar", foo);
Script contains:
bar.contains("x")
Error:
ErrorFunctionNotFound", error_message: "Function not found: contains (array, &str | ImmutableString | String)
from rhai.
Hhhmmm... It properly recognizes the type as array. So the data is correct.
Just the function is not found, which is strange.
Can you try: "x" in bar
from rhai.
Can you try: "x" in bar
Gives the same error.
"Function not found: contains (array, &str | ImmutableString | String)
AFAICS the Rhai runtime still "interpretes" bar
as a Rust type.
from rhai.
O wait, type_of()
now gives array
for bar
.
That differs with my previous attempts.
from rhai.
O wait,
type_of()
now givesarray
forbar
.That differs with my previous attempts.
Yes, that's the point. The data type is correct.
Just the function is not found.
You are not using new_raw
by any chance?
Or can you share a reproducible snippet?
from rhai.
Yes, an engine is created with
Engine::new_raw()
because of safety reasons and side-effects as printing should not be possible.
Actually, raw engines do not have anything to do with security and safety. You can always disable printing etc. by calling on_print
and on_debug
and put in stubs. You can also disable module resolution by setting it to an empty resolver. All these you can do on a standard Engine.
Raw engines are for environments with limited memory, so they don't load the entire standard library, and you need to pick-and-choose the libraries you need.
For your concerns you may consider:
// Create the new scripting Engine
let mut engine = Self::new();
// Disable stuff with side effects
engine
.set_module_resolver(rhai::module::resolvers::DummyModuleResolver::new())
.on_print(|_| {})
.on_debug(|_, _, _| {});
// Make engine immutable
let engine = engine;
from rhai.
Related Issues (20)
- There seems to be a bug when exporting variables HOT 5
- `Engine::parse_json` significantly slower than `serde_json::from_str` HOT 2
- Question about execution pause HOT 6
- How do I checkpoint and resume Rhai evaluation? HOT 4
- Why can't `()` not be overridden HOT 4
- v1.15 -> v1.16 breaking change: VarDefInfo field visibility HOT 1
- Integration with google/oss-fuzz for continuous fuzz testing HOT 40
- Bug: Parser panics when max_string_size set HOT 2
- Failed to resolve import "env" from "..\pkg\bench_rhai_console_bg.wasm" when using Engine instance HOT 4
- Feature suggestion. Implement is_XXX functions in the scripting language too HOT 1
- Problem compiling 1.16 HOT 4
- Clippy warning `needless-pass-by-ref-mut` by `codegen` HOT 1
- Function parameters and serde HOT 3
- Packing Rhai into 128KB under no-std on STM32 HOT 17
- Can't sort array by string (using closure) HOT 4
- Object `to_json` produces invalid JSON when the `metadata` feature is not enabled HOT 3
- array.index_of: string argument got mistaken as function? HOT 3
- Possible memory leak HOT 4
- Support for builder pattern? HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rhai.