An open API service indexing awesome lists of open source software.

https://github.com/jakobhellermann/bevy_reflect_fns

Experimentation for reflecting methods using bevy_reflect, to be upstreamed later
https://github.com/jakobhellermann/bevy_reflect_fns

Last synced: about 1 month ago
JSON representation

Experimentation for reflecting methods using bevy_reflect, to be upstreamed later

Awesome Lists containing this project

README

          

# 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

```rust
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, 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 `ReflectFunction`s: `reflect_function!(Vec3::lerp: (Vec3, Vec3, f32))`.