rhai
rhai copied to clipboard
array.index_of: string argument got mistaken as function?
let array = ["hello"];
array.index_of("hello");
EXCEPTION: Function not found: hello (&str | ImmutableString | String, i64)
in call to function 'index_of' (line 2, position 7)
I believe index_of takes a closure that matches items.
If you put in a string, it looks up a script function of the same name.
Thats why it is looking for a function called hello.
There is an index_of that compares the passed value, only works with number
let array = [4, 5, 6, 19];
array.index_of(19);`
https://github.com/rhaiscript/rhai/blob/169af8eccbe7dab7125edecb6fa62afe199ccffd/src/packages/array_basic.rs#L823-L833
It works for all types except string, where it got mistaken as name of a function...
The versions with function names as strings are deprecated but not yet removed for fear of breaking scripts.
Therefore unfortunately the depreciated version override the standard generic version.