Closed zwazel closed 9 months ago
I suggest we move the existing Wrapper example into lua, as it only really shows how to work with Lua. I'm working on the example for Rhai right now, so we can test the fixes
btw while working with the Wrappers in Rhai, i noticed that i always have to manually implement RhaiCopy, even though it's completely empty.
#[derive(Resource, Reflect, Default, Clone, Debug)]
#[reflect(Resource, RhaiProxyable)]
pub struct MyThing {
usize: usize,
string: String,
array: Vec<usize>,
}
impl RhaiCopy for MyThing {}
Is this wanted or an oversight?
As i'm working on the wrapper example for rhai, i noticed following thing: When I Reflect on RhaiProxyable, I no longer can access the values of my Struct. seen in: https://github.com/makspll/bevy_mod_scripting/pull/87/commits/c282ada927a822eb88750f5e669df53421ebe543 When I don't use RhaiProxyable, everything works fine. as seen in: https://github.com/makspll/bevy_mod_scripting/pull/87/commits/59ac5629c7559e82619949ee44ef1cace006541f
Am I misunderstanding the need for RhaiProxyable?
As i'm working on the wrapper example for rhai, i noticed following thing: When I Reflect on RhaiProxyable, I no longer can access the values of my Struct. seen in: c282ada When I don't use RhaiProxyable, everything works fine. as seen in: 59ac562
Am I misunderstanding the need for RhaiProxyable?
So the discussion above might shed some more light on this but let me know if you are still confused. Basically if you don't register RhaiProxyable yourself, you will receive a ReflectedValue
type object, which means you are operating using pure reflection, and have no function support.
Registering it yourself is needed when you need a custom proxy type which has custom methods and behaviours attached. But because Rhai doesn't have support for generating those nicely it's not easilly available here yet as seen in lua.
The need for RhaiCopy arises from the automatic implementation for RhaiProxyable which assumes your type is its own proxy and that it is converted into this proxy by copying, hence the name of the trait. This lets you register all Rhai goodies on your type in your APIProvider and use them that way. But of course since you are not using ReflectedValue anymore you lose the automatically generated getters for reflected fields.
Hope this makes sense
So this pull request should be good now, applied all your suggestions. And am looking forward for the wrapper rewrite ;)
This pull request cleans the Rhai side of the project up a bit.
get_children
that didn't even workget_parent
, before it wasn't found by Scripts, presumably because not the correct World was asked for (&ScriptWorld
instead ofScriptWorld
). Also made it return a Entity if a parent was found, and a i32 of value -1 if not, instead of Optionreload_script
as the game often crashed there. This adds on #68