jakobhellermann / bevy_reflect_fns

Experimentation for reflecting methods using bevy_reflect, to be upstreamed later

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bevy_reflect_fns

Experimentation for trying out ways to support method calls using bevy_reflect. This will be used together with bevy_mod_js_scripting to see if the design works out, and then hopefully upstreamed into bevy_reflect.

The core data this crates revolves around is this

pub enum PassMode {
    Ref,
    RefMut,
    Owned,
}

pub enum ReflectArg<'a> {
    Ref(&'a dyn Reflect),
    RefMut(&'a mut dyn Reflect),
    Owned(&'a dyn Reflect),
}

type RawReflectFunction =
    fn(&mut [ReflectArg<'_>]) -> Result<Box<dyn Reflect>, ReflectFunctionError>;

#[derive(Clone)]
pub struct ReflectFunction {
    pub fn_name: &'static str,
    pub signature: Vec<(PassMode, TypeId)>,
    pub f: RawReflectFunction,
}

pub struct ReflectMethods {
    methods: HashMap<&'static str, ReflectFunction>,
}

together with a macro to simplify creating such ReflectFunctions: reflect_function!(Vec3::lerp: (Vec3, Vec3, f32)).

About

Experimentation for reflecting methods using bevy_reflect, to be upstreamed later

License:Apache License 2.0


Languages

Language:Rust 100.0%