diff --git a/lyra-reflect/lyra-reflect-derive/src/enum_derive.rs b/lyra-reflect/lyra-reflect-derive/src/enum_derive.rs index 8604151..6a38896 100644 --- a/lyra-reflect/lyra-reflect-derive/src/enum_derive.rs +++ b/lyra-reflect/lyra-reflect-derive/src/enum_derive.rs @@ -1,6 +1,6 @@ use proc_macro2::Ident; use quote::quote; -use syn::{token::Enum, DataEnum, DeriveInput, Generics, GenericParam, parse_quote, Variant}; +use syn::{DataEnum, DeriveInput, parse_quote, Variant}; use crate::add_trait_bounds; @@ -267,7 +267,7 @@ fn gen_if_field_indices_names(variant: &Variant) -> proc_macro2::TokenStream { /// * `by_index`: Should the if statements be generated to check indices. fn gen_enum_if_stmts(enum_id: &proc_macro2::Ident, data: &DataEnum, by_index: bool) -> proc_macro2::TokenStream { let mut if_statement_count = 0; - let struct_vars = data.variants.iter().enumerate().map(|(idx, var)| { + let struct_vars = data.variants.iter().map(|var| { let vty = VariantType::from(var); let prepend_else = if_statement_count > 0; diff --git a/lyra-reflect/lyra-reflect-derive/src/lib.rs b/lyra-reflect/lyra-reflect-derive/src/lib.rs index 766b278..b30e593 100644 --- a/lyra-reflect/lyra-reflect-derive/src/lib.rs +++ b/lyra-reflect/lyra-reflect-derive/src/lib.rs @@ -1,15 +1,16 @@ -use std::slice::Split; - use proc_macro::TokenStream; use quote::{quote, ToTokens}; -use syn::{Generics, parse::ParseBuffer, Path, Attribute, GenericParam, parse_quote, parse_macro_input, DeriveInput, TypeParamBound}; +use syn::{Generics, Path, Attribute, GenericParam, parse_macro_input, DeriveInput, TypeParamBound}; mod enum_derive; +#[allow(unused_imports)] use enum_derive::*; mod struct_derive; +#[allow(unused_imports)] use struct_derive::*; +#[allow(dead_code)] pub(crate) struct ReflectDef { pub type_path: Path, pub generics: Generics, diff --git a/lyra-reflect/lyra-reflect-derive/src/struct_derive.rs b/lyra-reflect/lyra-reflect-derive/src/struct_derive.rs index 34368f6..b5768ee 100644 --- a/lyra-reflect/lyra-reflect-derive/src/struct_derive.rs +++ b/lyra-reflect/lyra-reflect-derive/src/struct_derive.rs @@ -22,7 +22,7 @@ use crate::add_trait_bounds; /// _ => None, /// } /// ``` -fn gen_struct_field_match(struct_id: &proc_macro2::Ident, data: &DataStruct, is_mut: bool) -> proc_macro2::TokenStream { +fn gen_struct_field_match(data: &DataStruct, is_mut: bool) -> proc_macro2::TokenStream { let mut_tkn = if is_mut { quote! { mut @@ -63,7 +63,7 @@ fn gen_struct_field_match(struct_id: &proc_macro2::Ident, data: &DataStruct, is_ /// }, /// } /// ``` -fn gen_struct_set_field_match(struct_id: &proc_macro2::Ident, data: &DataStruct) -> proc_macro2::TokenStream { +fn gen_struct_set_field_match(data: &DataStruct) -> proc_macro2::TokenStream { let field_arms = data.fields.iter().map(|field| { let field_ident = field.ident.as_ref().expect("Struct is missing field ident!"); let field_name_str = field_ident.to_string(); @@ -98,7 +98,7 @@ fn gen_struct_set_field_match(struct_id: &proc_macro2::Ident, data: &DataStruct) /// _ => None, /// } /// ``` -fn gen_struct_field_name_match(struct_id: &proc_macro2::Ident, data: &DataStruct) -> proc_macro2::TokenStream { +fn gen_struct_field_name_match(data: &DataStruct) -> proc_macro2::TokenStream { let field_arms = data.fields.iter().map(|field| { let field_ident = field.ident.as_ref().expect("Struct is missing field ident!"); let field_name_str = field_ident.to_string(); @@ -137,7 +137,7 @@ fn gen_struct_field_name_match(struct_id: &proc_macro2::Ident, data: &DataStruct /// }, /// } /// ``` -fn gen_struct_set_field_match_idx(struct_id: &proc_macro2::Ident, data: &DataStruct) -> proc_macro2::TokenStream { +fn gen_struct_set_field_match_idx(data: &DataStruct) -> proc_macro2::TokenStream { let field_arms = data.fields.iter().enumerate().map(|(idx, field)| { let field_ident = field.ident.as_ref().expect("Struct is missing field ident!"); let field_name_str = field_ident.to_string(); @@ -172,7 +172,7 @@ fn gen_struct_set_field_match_idx(struct_id: &proc_macro2::Ident, data: &DataStr /// _ => None, /// } /// ``` -fn gen_struct_field_name_match_idx(struct_id: &proc_macro2::Ident, data: &DataStruct) -> proc_macro2::TokenStream { +fn gen_struct_field_name_match_idx(data: &DataStruct) -> proc_macro2::TokenStream { let field_arms = data.fields.iter().enumerate().map(|(idx, field)| { let mut field_ty_stream = proc_macro2::TokenStream::new(); field.ty.to_tokens(&mut field_ty_stream); @@ -211,7 +211,7 @@ fn gen_struct_field_name_match_idx(struct_id: &proc_macro2::Ident, data: &DataSt /// _ => None, /// } /// ``` -fn gen_struct_field_match_idx(struct_id: &proc_macro2::Ident, data: &DataStruct, is_mut: bool) -> proc_macro2::TokenStream { +fn gen_struct_field_match_idx(data: &DataStruct, is_mut: bool) -> proc_macro2::TokenStream { let mut_tkn = if is_mut { quote! { mut @@ -245,7 +245,7 @@ fn gen_struct_field_match_idx(struct_id: &proc_macro2::Ident, data: &DataStruct, /// _ => None, /// } /// ``` -fn gen_struct_field_name_idx(struct_id: &proc_macro2::Ident, data: &DataStruct) -> proc_macro2::TokenStream { +fn gen_struct_field_name_idx(data: &DataStruct) -> proc_macro2::TokenStream { let field_arms = data.fields.iter().enumerate().map(|(idx, field)| { let field_ident = field.ident.as_ref().expect("Struct is missing field ident!"); let field_name_str = field_ident.to_string(); @@ -269,15 +269,15 @@ pub fn derive_reflect_struct(input: &DeriveInput, data_struct: &DataStruct) -> p let name = type_path.span().source_text().unwrap(); let field_len = data_struct.fields.len(); - let get_field_match = gen_struct_field_match(type_path, data_struct, false); - let get_field_mut_match = gen_struct_field_match(type_path, data_struct, true); - let get_field_match_idx = gen_struct_field_match_idx(type_path, data_struct, false); - let get_field_mut_match_idx = gen_struct_field_match_idx(type_path, data_struct, true); - let set_field_named = gen_struct_set_field_match(type_path, data_struct); - let set_field_idx = gen_struct_set_field_match_idx(type_path, data_struct); - let get_field_name_match = gen_struct_field_name_match(type_path, data_struct); - let get_field_name_match_idx = gen_struct_field_name_match_idx(type_path, data_struct); - let field_name_at = gen_struct_field_name_idx(type_path, data_struct); + let get_field_match = gen_struct_field_match(data_struct, false); + let get_field_mut_match = gen_struct_field_match(data_struct, true); + let get_field_match_idx = gen_struct_field_match_idx(data_struct, false); + let get_field_mut_match_idx = gen_struct_field_match_idx(data_struct, true); + let set_field_named = gen_struct_set_field_match(data_struct); + let set_field_idx = gen_struct_set_field_match_idx(data_struct); + let get_field_name_match = gen_struct_field_name_match(data_struct); + let get_field_name_match_idx = gen_struct_field_name_match_idx(data_struct); + let field_name_at = gen_struct_field_name_idx(data_struct); let generics = add_trait_bounds(input.generics.clone(), vec![parse_quote!(Reflect), parse_quote!(Clone)]); let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); diff --git a/lyra-reflect/src/dynamic_tuple.rs b/lyra-reflect/src/dynamic_tuple.rs index 8c5ad32..b5237bd 100644 --- a/lyra-reflect/src/dynamic_tuple.rs +++ b/lyra-reflect/src/dynamic_tuple.rs @@ -1,4 +1,4 @@ -use std::{any::TypeId, sync::Arc, ptr::NonNull}; +use std::any::TypeId; use super::{Reflect, Tuple, ReflectRef}; diff --git a/lyra-reflect/src/impl_std.rs b/lyra-reflect/src/impl_std.rs index 8128789..d756f89 100644 --- a/lyra-reflect/src/impl_std.rs +++ b/lyra-reflect/src/impl_std.rs @@ -1,12 +1,10 @@ -use std::any::TypeId; - use lyra_reflect_derive::impl_reflect_trait_value; use crate::List; use crate::lyra_engine; -use super::{Reflect, ReflectRef, ReflectMut, util, TypeData}; +use super::{Reflect, ReflectRef, ReflectMut, util}; impl_reflect_trait_value!(bool); impl_reflect_trait_value!(char); @@ -53,7 +51,11 @@ impl Reflect for [T; N] { } fn apply(&mut self, val: &dyn Reflect) { - todo!() + if let ReflectRef::Array(arr) = val.reflect_ref() { + util::apply_array(self, arr); + } else { + panic!("Provided value was not a List!"); + } } fn clone_inner(&self) -> Box { diff --git a/lyra-reflect/src/lib.rs b/lyra-reflect/src/lib.rs index 8e123c0..ae5c233 100644 --- a/lyra-reflect/src/lib.rs +++ b/lyra-reflect/src/lib.rs @@ -2,7 +2,7 @@ use std::{any::TypeId, any::Any, cell::{Ref, RefMut}}; -use lyra_ecs::{world::World, DynamicBundle, Component, Entity, ComponentInfo, query::dynamic::DynamicType}; +use lyra_ecs::{world::World, DynamicBundle, Component, Entity, ComponentInfo}; extern crate self as lyra_reflect; @@ -186,6 +186,7 @@ impl<'a> ReflectEither<'a> { } } +#[allow(dead_code)] pub struct Value { inner: Box, type_id: TypeId, diff --git a/lyra-reflect/src/method.rs b/lyra-reflect/src/method.rs index 30d2652..72762ca 100644 --- a/lyra-reflect/src/method.rs +++ b/lyra-reflect/src/method.rs @@ -1,7 +1,9 @@ use std::{any::TypeId, sync::Arc}; -use super::{Value, IntoValue}; +use super::Value; +/// Method will probably be completely removed soon +#[allow(dead_code)] #[derive(Clone)] pub struct Method { pub name: Option, diff --git a/lyra-reflect/src/reflected_enum.rs b/lyra-reflect/src/reflected_enum.rs index 1b5ad01..abbdaf9 100644 --- a/lyra-reflect/src/reflected_enum.rs +++ b/lyra-reflect/src/reflected_enum.rs @@ -49,6 +49,7 @@ pub trait Enum: Reflect { fn variant_type(&self) -> EnumType; } +#[allow(unused_variables)] #[cfg(test)] mod tests { use lyra_reflect_derive::Reflect; diff --git a/lyra-reflect/src/reflected_field.rs b/lyra-reflect/src/reflected_field.rs index 2d2c8fe..89065d3 100644 --- a/lyra-reflect/src/reflected_field.rs +++ b/lyra-reflect/src/reflected_field.rs @@ -1,5 +1,4 @@ -use super::{ReflectEither, Reflect, Struct}; - +use super::Reflect; /// A struct that can set fields on different types of reflected values. pub struct ReflectField<'a> { diff --git a/lyra-reflect/src/reflected_list.rs b/lyra-reflect/src/reflected_list.rs index effe95f..830151b 100644 --- a/lyra-reflect/src/reflected_list.rs +++ b/lyra-reflect/src/reflected_list.rs @@ -77,7 +77,7 @@ impl List for Vec { } } - fn push_front(&mut self, item: Box) -> Result<(), Box> { + fn push_front(&mut self, _item: Box) -> Result<(), Box> { unimplemented!("push_front for `List` trait implementation of a `Vec`. Doing so is slow!") } diff --git a/lyra-reflect/src/reflected_struct.rs b/lyra-reflect/src/reflected_struct.rs index 83a78cf..ce3ec1a 100644 --- a/lyra-reflect/src/reflected_struct.rs +++ b/lyra-reflect/src/reflected_struct.rs @@ -1,6 +1,4 @@ -use std::{any::{TypeId, type_name, Any}, collections::HashMap, marker::PhantomData, sync::Arc}; - -use super::{field::Field, method::Method, Reflect, Value}; +use super::{method::Method, Reflect}; /// A trait that a struct would implement pub trait Struct: Reflect { @@ -43,13 +41,8 @@ pub trait Struct: Reflect { #[cfg(test)] mod tests { - use std::any::TypeId; - use lyra_reflect_derive::Reflect; - use crate::{Reflect, ReflectRef, ReflectMut}; - - use super::Struct; use crate::lyra_engine; #[derive(Clone, Copy, Reflect)] diff --git a/lyra-reflect/src/util.rs b/lyra-reflect/src/util.rs index 65d1a9d..17b6269 100644 --- a/lyra-reflect/src/util.rs +++ b/lyra-reflect/src/util.rs @@ -1,3 +1,5 @@ +use crate::Array; + use super::List; /// A helper method that implements apply_list for you @@ -12,6 +14,17 @@ pub fn apply_list(apply_to: &mut dyn List, other: &dyn List) { } } +pub fn apply_array(apply_to: &mut dyn Array, other: &dyn Array) { + assert_eq!(apply_to.len(), other.len(), + "Arrays must be the same length when applying one to the other!"); + + let len = apply_to.len(); + for i in 0..len { + let el = apply_to.get_mut(i).unwrap(); + el.apply(other.get(i).unwrap()); + } +} + /// A helper method that implements [`Reflect::clone_inner`] for you. pub fn clone_inner_list(clone: &dyn List) -> Box { let mut empty = clone.create_empty(); diff --git a/lyra-scripting/src/host.rs b/lyra-scripting/src/host.rs index b453389..f422725 100644 --- a/lyra-scripting/src/host.rs +++ b/lyra-scripting/src/host.rs @@ -1,7 +1,6 @@ -use std::{sync::{Arc, RwLock}, error::Error, collections::HashMap}; +use std::collections::HashMap; -use anyhow::anyhow; -use lyra_ecs::{query::Res, ResourceObject}; +use lyra_ecs::ResourceObject; use crate::ScriptWorldPtr; diff --git a/lyra-scripting/src/lib.rs b/lyra-scripting/src/lib.rs index ddf37c3..f08e7b4 100644 --- a/lyra-scripting/src/lib.rs +++ b/lyra-scripting/src/lib.rs @@ -35,7 +35,7 @@ impl ReflectBranch { pub fn as_component_unchecked(&self) -> &ReflectedComponent { match self { ReflectBranch::Component(c) => c, - _ => panic!("`self` is not an instance of `ReflectBranch::Component`") + //_ => panic!("`self` is not an instance of `ReflectBranch::Component`") } } diff --git a/lyra-scripting/src/world.rs b/lyra-scripting/src/world.rs index b786612..a4e1134 100644 --- a/lyra-scripting/src/world.rs +++ b/lyra-scripting/src/world.rs @@ -2,10 +2,6 @@ use std::ptr::NonNull; use lyra_ecs::{world::World, Entity}; -use mlua::{prelude::{LuaUserData, LuaAnyUserData, LuaValue, LuaResult, Lua, LuaError}, Variadic, AnyUserDataExt, FromLua, IntoLua, MultiValue, IntoLuaMulti}; - -use crate::ScriptBorrow; - #[derive(Clone)] pub struct ScriptEntity(pub Entity);