Skip to content

Commit

Permalink
fix missing GetTypeRegistration bounds (this is good to have anyway)
Browse files Browse the repository at this point in the history
  • Loading branch information
makspll committed Sep 7, 2024
1 parent 3be745f commit f0fa5c4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
10 changes: 6 additions & 4 deletions crates/bevy_script_api/src/common/std.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::marker::PhantomData;

use bevy::reflect::{FromReflect, TypePath};
use bevy::reflect::{FromReflect, GetTypeRegistration, TypePath};

use crate::{error::ReflectionError, ReflectReference, ValueIndex};

Expand All @@ -26,7 +26,9 @@ impl<T> std::fmt::Debug for ScriptVec<T> {
}
}

impl<T: std::fmt::Display + FromReflect + TypePath> std::fmt::Display for ScriptVec<T> {
impl<T: std::fmt::Display + FromReflect + GetTypeRegistration + TypePath> std::fmt::Display
for ScriptVec<T>
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = self
.ref_
Expand All @@ -39,7 +41,7 @@ impl<T: std::fmt::Display + FromReflect + TypePath> std::fmt::Display for Script
}
}

impl<T: FromReflect + TypePath> ScriptVec<T> {
impl<T: FromReflect + TypePath + GetTypeRegistration> ScriptVec<T> {
pub fn new_ref(ref_: ReflectReference) -> Self {
Self {
ref_,
Expand Down Expand Up @@ -116,7 +118,7 @@ impl<T: FromReflect> Iterator for ScriptVecIterator<T> {
}
}

impl<T: FromReflect + TypePath> IntoIterator for ScriptVec<T> {
impl<T: FromReflect + TypePath + GetTypeRegistration> IntoIterator for ScriptVec<T> {
type Item = ReflectReference;

type IntoIter = ScriptVecIterator<T>;
Expand Down
18 changes: 15 additions & 3 deletions crates/bevy_script_api/src/lua/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use bevy::reflect::FromReflect;
use bevy::reflect::Reflect;

use bevy::reflect::TypePath;
use bevy::reflect::{GetTypeRegistration, TypePath};
use bevy_mod_scripting_lua::tealr;

use bevy_mod_scripting_lua::tealr::ToTypename;
Expand Down Expand Up @@ -99,8 +99,15 @@ impl<'lua> IntoLuaProxy<'lua> for String {
}
}

impl<T: LuaProxyable + Reflect + FromReflect + TypePath + for<'a> FromLuaProxy<'a> + Clone>
LuaProxyable for Option<T>
impl<
T: LuaProxyable
+ Reflect
+ FromReflect
+ GetTypeRegistration
+ TypePath
+ for<'a> FromLuaProxy<'a>
+ Clone,
> LuaProxyable for Option<T>
{
fn ref_to_lua(self_: ReflectReference, lua: &Lua) -> mlua::Result<Value> {
self_.get_typed(|s: &Option<T>| match s {
Expand Down Expand Up @@ -236,6 +243,7 @@ pub type LuaVec<T> = ScriptVec<T>;
impl<
T: ToTypename
+ FromReflect
+ GetTypeRegistration
+ TypePath
+ LuaProxyable
+ for<'a> FromLuaProxy<'a>
Expand Down Expand Up @@ -263,6 +271,7 @@ impl<T: ToTypename> ToTypename for LuaVec<T> {
impl<
T: ToTypename
+ FromReflect
+ GetTypeRegistration
+ TypePath
+ LuaProxyable
+ for<'a> FromLuaProxy<'a>
Expand All @@ -282,6 +291,7 @@ impl<
impl<
T: ToTypename
+ FromReflect
+ GetTypeRegistration
+ TypePath
+ LuaProxyable
+ for<'a> FromLuaProxy<'a>
Expand Down Expand Up @@ -371,6 +381,7 @@ impl<
impl<
T: ToTypename
+ FromReflect
+ GetTypeRegistration
+ TypePath
+ LuaProxyable
+ for<'a> FromLuaProxy<'a>
Expand Down Expand Up @@ -432,6 +443,7 @@ impl<
+ for<'a> IntoLuaProxy<'a>
+ Clone
+ FromReflect
+ GetTypeRegistration
+ TypePath
+ LuaProxyable
+ std::fmt::Debug,
Expand Down
10 changes: 10 additions & 0 deletions crates/bevy_script_api/src/lua/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ macro_rules! impl_tealr_generic{

impl ::bevy::reflect::Reflect for $name {

fn try_apply(&mut self, _: &(dyn bevy::prelude::Reflect + 'static)) -> std::result::Result<(), bevy::reflect::ApplyError> {
panic!("This should never be called, I am a dummy implementation");
}

fn into_any(self: Box<Self>) -> Box<dyn std::any::Any> {
panic!("This should never be called, I am a dummy implementation");
}
Expand Down Expand Up @@ -358,6 +362,12 @@ macro_rules! impl_tealr_generic{
}
}

impl ::bevy::reflect::GetTypeRegistration for $name {
fn get_type_registration() -> bevy::reflect::TypeRegistration {
panic!("This should never be called, I am a dummy implementation");
}
}

$crate::impl_tealr_type!($name);
$crate::impl_from_lua_with_clone!($name);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_script_api/src/rhai/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl RegisterForeignRhaiType for App {
&mut self,
) -> &mut Self {
{
let registry = self.world.resource_mut::<AppTypeRegistry>();
let registry = self.world_mut().resource_mut::<AppTypeRegistry>();
let mut registry = registry.write();

let rhai_data = <ReflectRhaiProxyable as FromType<T>>::from_type();
Expand Down
23 changes: 18 additions & 5 deletions crates/bevy_script_api/src/rhai/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
iter::Map,
};

use bevy::reflect::{FromReflect, Reflect, TypePath};
use bevy::reflect::{FromReflect, GetTypeRegistration, Reflect, TypePath};
#[allow(deprecated)]
use bevy_mod_scripting_rhai::rhai::{CustomType, Dynamic, Engine, EvalAltResult, Position};

Expand Down Expand Up @@ -114,8 +114,15 @@ impl_rhai_proxy!(f64 as FLOAT);
impl_rhai_proxy!(bool as bool);
impl_rhai_proxy!(String as Into);

impl<T: RhaiProxyable + Reflect + FromReflect + TypePath + Clone + FromRhaiProxy> RhaiProxyable
for Option<T>
impl<
T: RhaiProxyable
+ Reflect
+ FromReflect
+ TypePath
+ Clone
+ FromRhaiProxy
+ GetTypeRegistration,
> RhaiProxyable for Option<T>
{
fn ref_to_rhai(self_: crate::ReflectReference) -> Result<Dynamic, Box<EvalAltResult>> {
self_.get_typed(|s: &Option<T>| match s {
Expand Down Expand Up @@ -241,8 +248,14 @@ impl<T: ToRhaiProxy> ToRhaiProxy for Option<T> {
}

/// Composite trait composing the various traits required for a type `T` to be used as part of a RhaiVec<T>
pub trait RhaiVecElem: FromReflect + TypePath + RhaiProxyable + FromRhaiProxy + Clone {}
impl<T: FromReflect + TypePath + RhaiProxyable + FromRhaiProxy + Clone> RhaiVecElem for T {}
pub trait RhaiVecElem:
FromReflect + GetTypeRegistration + TypePath + RhaiProxyable + FromRhaiProxy + Clone
{
}
impl<T: FromReflect + GetTypeRegistration + TypePath + RhaiProxyable + FromRhaiProxy + Clone>
RhaiVecElem for T
{
}

/// A ScriptVec wrapper which implements a custom iterator ontop of ScriptVec's
pub struct RhaiVec<T: RhaiVecElem>(pub ScriptVec<T>);
Expand Down

0 comments on commit f0fa5c4

Please sign in to comment.