You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to attach an indexer function which performs a dynamic lookup on a function registry (basically bunch of Arc<fn>'s with a specifc signature).
I want to be able to:
let my_dynamic_type = ...
my_dynamic_type.dynamic_function("asd")
my_dynamic_type.dynamic_function2("asd")
given:
#[derive(Clone,Debug,Copy,PartialEq)]pubstructRhaiStaticReflectReference(pubTypeId);implCustomTypeforRhaiStaticReflectReference{fnbuild(mutbuilder: rhai::TypeBuilder<Self>){
builder
.with_name(std::any::type_name::<RhaiStaticReflectReference>()).with_indexer_get(|self_:&mutSelf,index:Dynamic| {let world = ThreadWorldContainer.get_world();let type_id = self_.0;let key:ScriptValue = ScriptValue::from_dynamic(index)?;let key = match key.as_string(){// i.e. `dynamic_function` is looked upOk(name) => match world.lookup_function([type_id], name){Ok(func) => returnScriptValue::Function(func).into_dynamic(),Err(key) => ScriptValue::String(key),},Err(key) => key,};let world = ThreadWorldContainer.get_world();Err::<_,Box<EvalAltResult>>(InteropError::missing_function(type_id, key.display_with_world(world.clone())).into(),)});}}
I know that Dynamic supports FnPtr which you can create via a ScriptFuncDef, however that seems to only be appropriate for actual "script defined" functions
The text was updated successfully, but these errors were encountered:
I am trying to attach an indexer function which performs a dynamic lookup on a function registry (basically bunch of
Arc<fn>
's with a specifc signature).I want to be able to:
given:
I know that Dynamic supports
FnPtr
which you can create via aScriptFuncDef
, however that seems to only be appropriate for actual "script defined" functionsThe text was updated successfully, but these errors were encountered: