From 16f4652feca048d062239b58c86d169f10ac7fb5 Mon Sep 17 00:00:00 2001 From: makspll Date: Sun, 10 Nov 2024 16:46:22 +0000 Subject: [PATCH 01/22] migrate work on core improvements from feature/better-trait-system to bevy 0.15 --- crates/bevy_mod_scripting_core/Cargo.toml | 16 +- crates/bevy_mod_scripting_core/src/asset.rs | 89 +- .../src/bindings/allocator.rs | 97 + .../src/bindings/mod.rs | 7 + .../src/bindings/proxy.rs | 1117 ++++++++++ .../src/bindings/query.rs | 114 + .../src/bindings/reference.rs | 500 +++++ .../src/bindings/world.rs | 1888 +++++++++++++++++ .../bevy_mod_scripting_core/src/commands.rs | 142 ++ crates/bevy_mod_scripting_core/src/context.rs | 152 ++ crates/bevy_mod_scripting_core/src/docs.rs | 22 +- crates/bevy_mod_scripting_core/src/error.rs | 197 +- crates/bevy_mod_scripting_core/src/event.rs | 242 ++- crates/bevy_mod_scripting_core/src/handler.rs | 37 + crates/bevy_mod_scripting_core/src/lib.rs | 295 ++- crates/bevy_mod_scripting_core/src/runtime.rs | 36 + crates/bevy_mod_scripting_core/src/script.rs | 42 + crates/bevy_mod_scripting_core/src/systems.rs | 587 +++-- 18 files changed, 5165 insertions(+), 415 deletions(-) create mode 100644 crates/bevy_mod_scripting_core/src/bindings/allocator.rs create mode 100644 crates/bevy_mod_scripting_core/src/bindings/mod.rs create mode 100644 crates/bevy_mod_scripting_core/src/bindings/proxy.rs create mode 100644 crates/bevy_mod_scripting_core/src/bindings/query.rs create mode 100644 crates/bevy_mod_scripting_core/src/bindings/reference.rs create mode 100644 crates/bevy_mod_scripting_core/src/bindings/world.rs create mode 100644 crates/bevy_mod_scripting_core/src/commands.rs create mode 100644 crates/bevy_mod_scripting_core/src/context.rs create mode 100644 crates/bevy_mod_scripting_core/src/handler.rs create mode 100644 crates/bevy_mod_scripting_core/src/runtime.rs create mode 100644 crates/bevy_mod_scripting_core/src/script.rs diff --git a/crates/bevy_mod_scripting_core/Cargo.toml b/crates/bevy_mod_scripting_core/Cargo.toml index 027bd286c5..ece7a115a2 100644 --- a/crates/bevy_mod_scripting_core/Cargo.toml +++ b/crates/bevy_mod_scripting_core/Cargo.toml @@ -21,19 +21,9 @@ doc_always = [] [dependencies] -bevy = { workspace = true, default-features = false, features = [ - "bevy_asset", - "bevy_gltf", - "bevy_animation", - "bevy_core_pipeline", - "bevy_ui", - "bevy_pbr", - "bevy_render", - "bevy_text", - "bevy_sprite", -] } -bevy_event_priority = { path = "../bevy_event_priority", version = "0.8.0-alpha.1" } +bevy = { workspace = true, default-features = false, features = ["bevy_asset"] } thiserror = "1.0.31" paste = "1.0.7" parking_lot = "0.12.1" -anyhow = "1.0.75" +lockable = "0.0.8" +smallvec = "1.11" diff --git a/crates/bevy_mod_scripting_core/src/asset.rs b/crates/bevy_mod_scripting_core/src/asset.rs index 1dc86bb292..c61bb7c1bf 100644 --- a/crates/bevy_mod_scripting_core/src/asset.rs +++ b/crates/bevy_mod_scripting_core/src/asset.rs @@ -1,8 +1,85 @@ -use bevy::asset::Asset; +use std::{ + borrow::Cow, + path::{Path, PathBuf}, +}; -/// All code assets share this common interface. -/// When adding a new code asset don't forget to implement asset loading -/// and inserting appropriate systems when registering with the app -pub trait CodeAsset: Asset { - fn bytes(&self) -> &[u8]; +use bevy::{ + asset::{Asset, AssetLoader, AsyncReadExt}, + ecs::system::Resource, + reflect::TypePath, + utils::BoxedFuture, +}; + +use crate::{prelude::ScriptError, script::ScriptId}; + +/// Represents a script loaded into memory as an asset +#[derive(Asset, TypePath)] +pub struct ScriptAsset { + pub content: Box<[u8]>, + /// The virtual filesystem path of the asset, used to map to the script Id for asset backed scripts + pub asset_path: PathBuf, + pub language: Cow<'static, str>, +} + +pub struct ScriptAssetLoader { + /// Used to set the language of the script + pub language: Cow<'static, str>, + /// The file extensions this loader should handle + pub extensions: &'static [&'static str], + /// preprocessor to run on the script before saving the content to an asset + pub preprocessor: Option Result<(), ScriptError> + Send + Sync>>, +} + +impl AssetLoader for ScriptAssetLoader { + type Asset = ScriptAsset; + + type Settings = (); + + type Error = ScriptError; + + async fn load( + &self, + reader: &mut dyn bevy::asset::io::Reader, + _settings: &Self::Settings, + load_context: &mut bevy::asset::LoadContext<'_>, + ) -> Result { + let mut content = Vec::new(); + reader.read_to_end(&mut content).await.map_err(|e| { + ScriptError::new_lifecycle_error(e).with_context(load_context.asset_path()) + })?; + if let Some(processor) = &self.preprocessor { + processor(&mut content)?; + } + let asset = ScriptAsset { + content: content.into_boxed_slice(), + asset_path: load_context.path().to_owned(), + language: self.language.clone(), + }; + Ok(asset) + } + + fn extensions(&self) -> &[&str] { + self.extensions + } +} + +#[derive(Clone, Copy, Resource)] +pub struct ScriptAssetSettings { + pub script_id_mapper: AssetPathToScriptIdMapper, +} + +impl Default for ScriptAssetSettings { + fn default() -> Self { + Self { + script_id_mapper: AssetPathToScriptIdMapper { + map: (|path: &Path| path.to_string_lossy().into_owned().into()), + }, + } + } +} + +/// Strategy for mapping asset paths to script ids, by default this is the identity function +#[derive(Clone, Copy)] +pub struct AssetPathToScriptIdMapper { + pub map: fn(&Path) -> ScriptId, } diff --git a/crates/bevy_mod_scripting_core/src/bindings/allocator.rs b/crates/bevy_mod_scripting_core/src/bindings/allocator.rs new file mode 100644 index 0000000000..c6394bc6f9 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/bindings/allocator.rs @@ -0,0 +1,97 @@ +use bevy::ecs::system::Resource; +use bevy::reflect::{PartialReflect, Reflect}; +use std::any::TypeId; +use std::cell::UnsafeCell; +use std::collections::HashMap; +use std::fmt::{Display, Formatter}; +use std::sync::Arc; + +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct ReflectAllocationId(pub(crate) usize); +impl ReflectAllocationId { + pub fn id(&self) -> usize { + self.0 + } +} + +#[derive(Clone, Debug)] +pub struct ReflectAllocation(pub(self) Arc>); + +unsafe impl Send for ReflectAllocation {} +unsafe impl Sync for ReflectAllocation {} + +impl ReflectAllocation { + pub fn get_ptr(&self) -> *mut dyn PartialReflect { + self.0.get() + } + pub fn new(value: Arc>) -> Self { + Self(value) + } +} + +impl Display for ReflectAllocationId { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } +} + +/// Allocator used to allocate and deallocate `dyn PartialReflect` values +/// Used to be able to ensure we have a "common root" for values allocated outside the world. +#[derive(Resource, Default)] +pub struct ReflectAllocator { + // TODO: experiment with object pools, sparse set etc. + allocations: HashMap, + types: HashMap, +} + +impl ReflectAllocator { + /// Allocates a new [`Reflect`] value and returns an [`AllocationId`] which can be used to access it later + pub fn allocate( + &mut self, + value: T, + ) -> (ReflectAllocationId, ReflectAllocation) { + let id = ReflectAllocationId(self.allocations.len()); + let value = ReflectAllocation::new(Arc::new(UnsafeCell::new(value))); + self.allocations.insert(id, value.clone()); + self.types.insert(id, TypeId::of::()); + (id, value) + } + + pub fn get(&self, id: ReflectAllocationId) -> Option { + self.allocations.get(&id).cloned() + } + + pub fn get_type_id(&self, id: ReflectAllocationId) -> Option { + self.types.get(&id).cloned() + } + + pub fn get_mut(&self, id: ReflectAllocationId) -> Option { + self.allocations.get(&id).cloned() + } + + /// Deallocates the [`PartialReflect`] value with the given [`AllocationId`] + pub fn deallocate(&mut self, id: ReflectAllocationId) { + self.allocations.remove(&id); + } + + /// Runs a garbage collection pass on the allocations, removing any allocations which have no more strong references + /// Needs to be run periodically to prevent memory leaks + pub fn clean_garbage_allocations(&mut self) { + self.allocations.retain(|_, v| Arc::strong_count(&v.0) > 1); + } +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_reflect_allocator() { + let mut allocator = ReflectAllocator::default(); + let (id, val) = allocator.allocate(0); + assert_eq!(allocator.allocations.len(), 1); + drop(val); + allocator.clean_garbage_allocations(); + assert_eq!(allocator.allocations.len(), 0); + } +} diff --git a/crates/bevy_mod_scripting_core/src/bindings/mod.rs b/crates/bevy_mod_scripting_core/src/bindings/mod.rs new file mode 100644 index 0000000000..24f8ddf453 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/bindings/mod.rs @@ -0,0 +1,7 @@ +pub mod allocator; +pub mod proxy; +pub mod query; +pub mod reference; +pub mod world; + +pub use {allocator::*, proxy::*, query::*, reference::*, world::*}; diff --git a/crates/bevy_mod_scripting_core/src/bindings/proxy.rs b/crates/bevy_mod_scripting_core/src/bindings/proxy.rs new file mode 100644 index 0000000000..04c65f8180 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/bindings/proxy.rs @@ -0,0 +1,1117 @@ +//! Set of traits used to define how types are turned into and from proxies in Lua. +//! Proxies can either be logical "copies" or owned "direct representations" of the instance, or references to one via the [`bevy_mod_scripting_core::bindings::ReflectReference`] construct. +use std::{ + cell::UnsafeCell, + marker::PhantomData, + num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize}, + sync::Arc, +}; + +use bevy::reflect::{FromReflect, Reflect, TypeRegistry}; +use smallvec::SmallVec; + +use crate::{ + bindings::ReflectAllocation, + error::ScriptResult, + prelude::{ReflectAllocator, ScriptError}, +}; + +use super::{ + world::{WorldAccessGuard, WorldAccessUnit, WorldAccessWrite}, + ReflectReference, DEFAULT_INTERVAL, DEFAULT_TIMEOUT, +}; + +/// Inverse to [`Unproxy`], packages up a type into a proxy type. +pub trait Proxy: Sized { + type Input<'a>; + + /// Proxies a type without access to the allocator, types which require access to the allocator will throw an error here + fn proxy<'a>(input: Self::Input<'a>) -> ScriptResult { + Err(ScriptError::new_reflection_error(format!( + "Cannot unproxy type: `{}` without allocator access. Use proxy_with_allocator instead.", + std::any::type_name::(), + ))) + } + + /// Proxies a type with access to the allocator + fn proxy_with_allocator<'a>( + input: Self::Input<'a>, + _allocator: &mut ReflectAllocator, + ) -> ScriptResult { + Self::proxy(input) + } +} + +/// A mechanism for converting proxy types into their represented types. +/// Note this can be implemented by 'meta-proxy' types which themselves aren't proxies, but wrap other proxies and provide a specific unproxying mechanism. +/// `RefProxy` and `RefMutProxy` are such 'meta-proxy' types. +/// +/// the [`Unproxy::Output`] type parameter is the type that this `proxy` will be converted to after unwrapping. +/// +pub trait Unproxy { + type Output<'o> + where + Self: 'o; + + fn collect_accesses<'w>( + &self, + _guard: &WorldAccessGuard<'w>, + _accesses: &mut SmallVec<[WorldAccessWrite<'w>; 1]>, + ) -> ScriptResult<()> { + Ok(()) + } + + fn accesses_len(&self) -> usize { + 0 + } + + /// Unproxies a proxy type into the represented type without world access + /// This will fail on proxies which require world access to unproxy (for example those whose proxies are glorified [`ReflectReference`]'s ) + fn unproxy<'o>(&'o mut self) -> ScriptResult> { + Err(ScriptError::new_reflection_error(format!( + "Cannot unproxy type: `{}` without world access. Use unproxy_with_world instead", + std::any::type_name::(), + ))) + } + + /// Unproxies a proxy type into the represented type with world access + /// # Safety + /// - The caller must not use the accesses in the accesses list after the unproxy call at all, as implementors assume they have unique access to the accesses. + unsafe fn unproxy_with_world<'w, 'o>( + &'o mut self, + _guard: &WorldAccessGuard<'w>, + _accesses: &'o [WorldAccessUnit<'w>], + _type_registry: &TypeRegistry, + _allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + self.unproxy() + } +} + +/// A wrapper type which when unproxied will return a `T` value. +/// Requires the type to be constructible from a reference to the proxy type. +#[derive(Debug, PartialEq, Eq)] +pub struct ValProxy(pub P, PhantomData); + +impl ValProxy { + pub fn new(v: P) -> Self { + Self(v, PhantomData) + } +} + +/// A wrapper type which when unproxied will return a `T` value. +/// Assumes that the proxy type contains a [`ReflectReference`] via [`AsRef`] +#[derive(PartialEq, Eq, Debug)] +pub struct ReflectValProxy(pub P, PhantomData); + +impl ReflectValProxy { + pub fn new(v: P) -> Self { + Self(v, PhantomData) + } +} + +/// A proxy type which when unproxied will return a reference to a `T` value. +/// Assumes that the proxy type contains a [`ReflectReference`] via [`AsRef`] +pub struct ReflectRefProxy(pub P, PhantomData); + +impl ReflectRefProxy { + pub fn new(v: P) -> Self { + Self(v, PhantomData) + } +} + +/// A proxy type which when unproxied will return a mutable reference to a `T` value. +/// Assumes that the proxy type contains a [`ReflectReference`] via [`AsRef`] +#[derive(Debug)] +pub struct ReflectRefMutProxy(pub P, PhantomData); + +impl ReflectRefMutProxy { + pub fn new(v: P) -> Self { + Self(v, PhantomData) + } +} + +impl Unproxy for ValProxy +where + T: for<'l> From<&'l P>, +{ + type Output<'o> = T where Self: 'o; + + fn unproxy<'o>(&'o mut self) -> ScriptResult> { + Ok(T::from(&self.0)) + } +} + +impl Proxy for ValProxy +where + T: Into

, +{ + type Input<'a> = T; + + fn proxy<'a>(input: Self::Input<'a>) -> ScriptResult { + Ok(ValProxy::new(input.into())) + } +} + +impl Proxy for ReflectValProxy +where + T: Reflect, + P: From, +{ + type Input<'a> = T; + + fn proxy_with_allocator<'a>( + input: Self::Input<'a>, + allocator: &mut ReflectAllocator, + ) -> ScriptResult { + Ok(Self::new( + ReflectReference::new_allocated(input, allocator).into(), + )) + } +} + +impl Unproxy for ReflectValProxy +where + P: AsRef, + T: FromReflect, +{ + type Output<'o> = T where Self: 'o; + + unsafe fn unproxy_with_world<'w, 'o>( + &'o mut self, + guard: &WorldAccessGuard<'w>, + _accesses: &'o [WorldAccessUnit<'w>], + type_registry: &TypeRegistry, + allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + let reflect_ref: &ReflectReference = self.0.as_ref(); + let access = reflect_ref.base.base_id.get_reflect_access_id(); + let access = guard + .get_access_timeout(access, DEFAULT_TIMEOUT, DEFAULT_INTERVAL) + .ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "Could not unproxy type: `{}`. Aliasing access.", + std::any::type_name::() + )) + })?; + let out = reflect_ref.reflect( + guard.as_unsafe_world_cell(), + &access, + type_registry, + Some(allocator), + )?; + let out = T::from_reflect(out).ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "FromReflect failed for `{}`.", + std::any::type_name::() + )) + })?; + guard.release_access(access); + Ok(out) + } +} + +impl Proxy for ReflectRefProxy +where + T: FromReflect, + P: From, +{ + type Input<'a> = &'a T; + + fn proxy_with_allocator<'a>( + input: Self::Input<'a>, + allocator: &mut ReflectAllocator, + ) -> ScriptResult { + let inner = T::from_reflect(input).ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "FromReflect failed for `{}`.", + std::any::type_name::() + )) + })?; + Ok(Self::new( + ReflectReference::new_allocated(inner, allocator).into(), + )) + } +} + +impl Unproxy for ReflectRefProxy +where + P: AsRef, + T: Reflect, +{ + type Output<'o> = &'o T where Self: 'o; + + fn collect_accesses<'w>( + &self, + guard: &WorldAccessGuard<'w>, + accesses: &mut SmallVec<[WorldAccessUnit<'w>; 1]>, + ) -> ScriptResult<()> { + let reflect_ref: &ReflectReference = self.0.as_ref(); + let access = reflect_ref.base.base_id.get_reflect_access_id(); + let access = guard + .get_access_timeout(access, DEFAULT_TIMEOUT, DEFAULT_INTERVAL) + .ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "Could not unproxy type: `{}`. Aliasing access.", + std::any::type_name::() + )) + })?; + accesses.push(access); + Ok(()) + } + + unsafe fn unproxy_with_world<'w, 'o>( + &'o mut self, + guard: &WorldAccessGuard<'w>, + accesses: &'o [WorldAccessUnit<'w>], + type_registry: &TypeRegistry, + allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + let reflect_ref: &ReflectReference = self.0.as_ref(); + let access = accesses.last().ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "No required access collected when unproxying type: `{}`.", + std::any::type_name::() + )) + })?; + + let out = reflect_ref.reflect( + guard.as_unsafe_world_cell(), + access, + type_registry, + Some(allocator), + )?; + let out = out.try_downcast_ref().ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "Could not downcast value from reflect reference to type: `{}`.", + std::any::type_name::() + )) + })?; + Ok(out) + } + + fn accesses_len(&self) -> usize { + 1 + } +} + +impl Unproxy for ReflectRefMutProxy +where + P: AsRef, + T: Reflect, +{ + type Output<'o> = &'o mut T where Self: 'o; + + fn collect_accesses<'w>( + &self, + guard: &WorldAccessGuard<'w>, + accesses: &mut SmallVec<[WorldAccessUnit<'w>; 1]>, + ) -> ScriptResult<()> { + let reflect_ref: &ReflectReference = self.0.as_ref(); + let access = reflect_ref.base.base_id.get_reflect_access_id(); + let access = guard + .get_access_timeout(access, DEFAULT_TIMEOUT, DEFAULT_INTERVAL) + .ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "Could not unproxy type: `{}`. Aliasing access.", + std::any::type_name::() + )) + })?; + accesses.push(access); + Ok(()) + } + + unsafe fn unproxy_with_world<'w, 'o>( + &'o mut self, + guard: &WorldAccessGuard<'w>, + accesses: &'o [WorldAccessUnit<'w>], + type_registry: &TypeRegistry, + allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + let reflect_ref: &ReflectReference = self.0.as_ref(); + accesses + .last() + .ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "No required access collected when unproxying type: `{}`.", + std::any::type_name::() + )) + }) + .and_then(|access| { + reflect_ref.expect_write_access( + access, + type_registry, + Some(allocator), + guard.as_unsafe_world_cell(), + ) + })?; + + // Safety: + // - we verified and we have the right access + // - the caller promises not to alias it from the root access + let out = unsafe { + reflect_ref.reflect_mut_unsafe( + guard.as_unsafe_world_cell(), + type_registry, + Some(allocator), + )? + }; + let out = out.try_downcast_mut().ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "Could not downcast value from reflect reference to type: `{}`.", + std::any::type_name::() + )) + })?; + Ok(out) + } + + fn accesses_len(&self) -> usize { + 1 + } +} + +macro_rules! impl_unproxy_via_vec { + ($type:ty, $out_type:ty, ($($generics:tt)*)) => { + impl<'c, $($generics)*> Unproxy for $type { + type Output<'o> = $out_type where Self: 'o; + + fn collect_accesses<'w>( + &self, + guard: &WorldAccessGuard<'w>, + accesses: &mut SmallVec<[WorldAccessUnit<'w>; 1]>, + ) -> ScriptResult<()> { + for item in self { + item.collect_accesses(guard, accesses)?; + } + Ok(()) + } + + fn accesses_len(&self) -> usize { + self.iter().map(|item| item.accesses_len()).sum() + } + + fn unproxy(&mut self) -> ScriptResult> { + let mut out = Vec::with_capacity(self.len()); + for item in self { + let unproxied = item.unproxy()?; + out.push(unproxied); + } + Ok(out.try_into().map_err(|_| "something went wrong").unwrap()) + } + + unsafe fn unproxy_with_world<'w, 'o>( + &'o mut self, + guard: &WorldAccessGuard<'w>, + accesses: &'o [WorldAccessUnit<'w>], + type_registry: &TypeRegistry, + allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + let mut out = Vec::with_capacity(self.len()); + let mut offset = 0; + for item in self.iter_mut() { + let width = item.accesses_len(); + let unproxied = item.unproxy_with_world( + guard, + &accesses[offset..offset + width], + type_registry, + allocator, + )?; + out.push(unproxied); + offset += width; + } + Ok(out.try_into().map_err(|_| "something went wrong").unwrap()) + } + } + }; +} + +macro_rules! impl_proxy_via_vec { + ($type:ty, $item_type:ty, $in_type:ty, ($($generics:tt)*)) => { + impl<$($generics)*> Proxy for $type { + type Input<'i> = $in_type; + + fn proxy(input: Self::Input<'_>) -> ScriptResult { + let mut out = Vec::with_capacity(input.len()); + for item in input { + out.push(<$item_type as Proxy>::proxy(item)?); + } + Ok(out.try_into().map_err(|_| "something went wrong").unwrap()) + } + + fn proxy_with_allocator( + input: Self::Input<'_>, + _allocator: &mut ReflectAllocator, + ) -> ScriptResult { + let mut out = Vec::with_capacity(input.len()); + for item in input { + out.push(<$item_type as Proxy>::proxy_with_allocator(item, _allocator)?); + } + Ok(out.try_into().map_err(|_| "something went wrong").unwrap()) + } + } + }; +} + +impl_unproxy_via_vec!(Vec, Vec>, (T: Unproxy)); +impl_proxy_via_vec!(Vec, T, Vec>, (T: Proxy)); +impl_unproxy_via_vec!([T; C], [T::Output<'o>; C], (T: Unproxy, const C: usize)); +impl_proxy_via_vec!([T; C],T,[T::Input<'i>; C], (T: Proxy, const C: usize)); +impl_unproxy_via_vec!(SmallVec<[T; C]>, SmallVec<[T::Output<'o>; C]>, (T: Unproxy, const C: usize)); +impl_proxy_via_vec!(SmallVec<[T; C]>, T, SmallVec<[T::Input<'i>; C]>, (T: Proxy, const C: usize)); + +// impl_proxy_unproxy_via_vec!(T, SmallVec, SmallVec<[T; C]>); +// impl<'c, T: 'c> Unproxy for &'c T { +// type Output<'o> = &'c T where Self: 'o; + +// fn unproxy(&mut self) -> ScriptResult> { +// Ok(self) +// } +// } + +// impl<'s, T> Proxy for &'s T { +// type Input<'b> = &'s T; + +// fn proxy(input: Self::Input<'_>) -> ScriptResult { +// Ok(input) +// } + +// fn proxy_with_allocator( +// input: Self::Input<'_>, +// _allocator: &mut ReflectAllocator, +// ) -> ScriptResult { +// Ok(input) +// } +// } + +// impl Unproxy for &mut T { +// type Output<'o> = &'o mut T where Self: 'o; + +// fn unproxy(&mut self) -> ScriptResult> { +// Ok(self) +// } +// } + +// impl<'s, T> Proxy for &'s mut T { +// type Input<'a> = &'s mut T; + +// fn proxy(input: Self::Input<'_>) -> ScriptResult { +// Ok(input) +// } + +// fn proxy_with_allocator( +// input: Self::Input<'_>, +// _allocator: &mut ReflectAllocator, +// ) -> ScriptResult { +// Ok(input) +// } +// } + +impl Unproxy for Option { + type Output<'o> = Option> where Self: 'o; + + fn unproxy(&mut self) -> ScriptResult> { + if let Some(s) = self { + let inner = s.unproxy()?; + Ok(Some(inner)) + } else { + Ok(None) + } + } + + unsafe fn unproxy_with_world<'w, 'o>( + &'o mut self, + guard: &WorldAccessGuard<'w>, + accesses: &'o [WorldAccessUnit<'w>], + type_registry: &TypeRegistry, + allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + if let Some(s) = self { + let inner = s.unproxy_with_world(guard, accesses, type_registry, allocator)?; + Ok(Some(inner)) + } else { + Ok(None) + } + } + + fn collect_accesses<'w>( + &self, + guard: &WorldAccessGuard<'w>, + accesses: &mut SmallVec<[WorldAccessWrite<'w>; 1]>, + ) -> ScriptResult<()> { + self.as_ref() + .map(|s| s.collect_accesses(guard, accesses)) + .unwrap_or_else(|| Ok(())) + } + + fn accesses_len(&self) -> usize { + self.as_ref().map_or(0, |s| s.accesses_len()) + } +} + +impl Proxy for Option { + type Input<'a> = Option>; + + fn proxy(input: Self::Input<'_>) -> ScriptResult { + input.map(T::proxy).transpose() + } + + fn proxy_with_allocator( + input: Self::Input<'_>, + _allocator: &mut ReflectAllocator, + ) -> ScriptResult { + input + .map(|i| T::proxy_with_allocator(i, _allocator)) + .transpose() + } +} + +impl Proxy for Result { + type Input<'a> = Result, E>; + + fn proxy(input: Self::Input<'_>) -> ScriptResult { + match input { + Ok(i) => Ok(Ok(T::proxy(i)?)), + Err(e) => Ok(Err(e)), + } + } + + fn proxy_with_allocator( + input: Self::Input<'_>, + _allocator: &mut ReflectAllocator, + ) -> ScriptResult { + match input { + Ok(i) => Ok(Ok(T::proxy_with_allocator(i, _allocator)?)), + Err(e) => Ok(Err(e)), + } + } +} + +impl Unproxy for Result { + type Output<'o> = Result, E::Output<'o>> where Self: 'o; + + fn unproxy(&mut self) -> ScriptResult> { + match self { + Ok(s) => Ok(Ok(s.unproxy()?)), + Err(e) => Ok(Err(e.unproxy()?)), + } + } + + unsafe fn unproxy_with_world<'w, 'o>( + &'o mut self, + guard: &WorldAccessGuard<'w>, + accesses: &'o [WorldAccessUnit<'w>], + type_registry: &TypeRegistry, + allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + match self { + Ok(s) => Ok(Ok(s.unproxy_with_world( + guard, + accesses, + type_registry, + allocator, + )?)), + Err(e) => Ok(Err(e.unproxy()?)), + } + } + + fn collect_accesses<'w>( + &self, + guard: &WorldAccessGuard<'w>, + accesses: &mut SmallVec<[WorldAccessWrite<'w>; 1]>, + ) -> ScriptResult<()> { + match self { + Ok(s) => s.collect_accesses(guard, accesses), + Err(_) => Ok(()), + } + } + + fn accesses_len(&self) -> usize { + match self { + Ok(s) => s.accesses_len(), + Err(_) => 0, + } + } +} + +macro_rules! impl_unproxy_by_move { + ($($ty:ty),*) => { + $( + impl Unproxy for $ty { + type Output<'o> = $ty; + + fn unproxy( + &mut self + ) -> ScriptResult> { + Ok(*self) + } + } + + impl Unproxy for &$ty { + type Output<'o> = &'o $ty where Self : 'o; + + fn unproxy( + &mut self + ) -> ScriptResult> { + Ok(self) + } + } + + impl Unproxy for &mut $ty { + type Output<'o> = &'o mut $ty where Self : 'o; + + fn unproxy( + &mut self + ) -> ScriptResult> { + Ok(self) + } + } + )* + }; +} + +macro_rules! impl_proxy_by_move { + ($($ty:ident),*) => { + $( + impl Proxy for $ty { + type Input<'a> = Self; + + fn proxy(input: Self::Input<'_>) -> ScriptResult { + Ok(input) + } + } + + impl <'l>Proxy for &'l $ty { + type Input<'a> = Self; + + fn proxy(input: Self::Input<'_>) -> ScriptResult { + Ok(input) + } + } + + impl <'l>Proxy for &'l mut $ty { + type Input<'a> = Self; + + fn proxy(input: Self::Input<'_>) -> ScriptResult { + Ok(input) + } + } + )* + } +} + +impl_proxy_by_move!( + usize, + u8, + u16, + u32, + u64, + u128, + isize, + i8, + i16, + i32, + i64, + i128, + f32, + f64, + bool, + NonZeroUsize, + NonZeroU8, + NonZeroU16, + NonZeroU32, + NonZeroU64, + NonZeroU128 +); + +impl_unproxy_by_move!( + usize, + u8, + u16, + u32, + u64, + u128, + isize, + i8, + i16, + i32, + i64, + i128, + f32, + f64, + bool, + NonZeroUsize, + NonZeroU8, + NonZeroU16, + NonZeroU32, + NonZeroU64, + NonZeroU128 +); + +macro_rules! impl_unproxy_by_clone { + ($($ty:ty),*) => { + $(impl Unproxy for $ty { + type Output<'o> = $ty; + + fn unproxy(&mut self) -> ScriptResult> { + Ok(self.clone()) + } + })* + }; +} + +impl_unproxy_by_clone!(String); +impl_proxy_by_move!(String); + +macro_rules! impl_tuple_unproxy_proxy { + ($(($ty:ident, $idx:tt)),*) => { + impl <$($ty : Proxy,)*> Proxy for ($($ty,)*) + { + type Input<'a> = ($($ty::Input<'a>,)*); + + #[allow(clippy::unused_unit)] + fn proxy(_input: Self::Input<'_>) -> ScriptResult { + Ok(($($ty::proxy(_input.$idx)?,)*)) + } + + fn proxy_with_allocator(_input: Self::Input<'_>, _allocator: &mut ReflectAllocator) -> ScriptResult { + Ok(($($ty::proxy_with_allocator(_input.$idx, _allocator)?,)*)) + } + } + + impl<$($ty: Unproxy),*> Unproxy for ($($ty,)*) { + type Output<'o> = ($($ty::Output<'o>,)*) where Self: 'o; + + fn collect_accesses<'w>( + &self, + _guard: &WorldAccessGuard<'w>, + _accesses: &mut SmallVec<[WorldAccessWrite<'w>; 1]>, + ) -> ScriptResult<()> { + $(self.$idx.collect_accesses(_guard, _accesses)?;)* + Ok(()) + } + + fn accesses_len(&self) -> usize { + let mut _len = 0; + $(_len += self.$idx.accesses_len();)* + _len + } + + fn unproxy(&mut self) -> ScriptResult> { + Ok(($( + self.$idx.unproxy()? + ,)*)) + } + + #[allow(unused_assignments)] + unsafe fn unproxy_with_world<'w,'o>( + &'o mut self, + _guard: &WorldAccessGuard<'w>, + _accesses: &'o [WorldAccessUnit<'w>], + _type_registry: &TypeRegistry, + _allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + let mut _offset = 0; + + Ok(($( + { + let width = self.$idx.accesses_len(); + let elem = self.$idx.unproxy_with_world(_guard, &_accesses[_offset.._offset+width], _type_registry, _allocator)?; + + _offset += width; + elem + } + ,)*)) + + } + } + }; +} + +impl_tuple_unproxy_proxy!(); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9), (K, 10)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9), (K, 10), (L, 11)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9), (K, 10), (L, 11), (M, 12)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9), (K, 10), (L, 11), (M, 12), (N, 13)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9), (K, 10), (L, 11), (M, 12), (N, 13), (O, 14)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9), (K, 10), (L, 11), (M, 12), (N, 13), (O, 14), (P, 15)); +#[rustfmt::skip] +impl_tuple_unproxy_proxy!((A, 0), (B, 1), (C, 2), (D, 3), (E, 4), (F, 5), (G, 6), (H, 7), (I, 8), (J, 9), (K, 10), (L, 11), (M, 12), (N, 13), (O, 14), (P, 15), (Q, 16)); + +#[cfg(test)] +mod test { + + use bevy::ecs::{component::Component, world::World}; + + use crate::bindings::{ReflectBase, ReflectBaseType}; + + use super::*; + + #[derive(Reflect, Component, PartialEq, Eq, Debug, Clone)] + struct Test(pub &'static str); + + #[derive(Debug, Clone, PartialEq, Eq)] + struct ValTestProxy(Test); + + impl From for ValTestProxy { + fn from(value: Test) -> Self { + Self(value) + } + } + + impl<'a> From<&'a ValTestProxy> for Test { + fn from(value: &'a ValTestProxy) -> Self { + value.0.clone() + } + } + + #[derive(Debug, Clone, PartialEq, Eq)] + struct TestProxy(ReflectReference); + + impl From for TestProxy { + fn from(value: ReflectReference) -> Self { + TestProxy(value) + } + } + + impl AsRef for TestProxy { + fn as_ref(&self) -> &ReflectReference { + &self.0 + } + } + + macro_rules! assert_proxy_invertible { + ($original:expr, $($proxy_ty:tt)*) => { + let mut world = World::new(); + let mut accesses = SmallVec::new(); + let world = WorldAccessGuard::new(&mut world); + let type_registry = TypeRegistry::default(); + let mut allocator = ReflectAllocator::default(); + + // test with world version + let mut proxy = <$($proxy_ty)* as Proxy>::proxy_with_allocator($original, &mut allocator).unwrap(); + proxy.collect_accesses(&world, &mut accesses).unwrap(); + + let unproxied = unsafe { + proxy + .unproxy_with_world(&world, &mut accesses, &type_registry, &allocator) + .unwrap() + }; + assert_eq!( + unproxied, $original, + "Proxy and unproxy does not yield original type, expected {:?}, got {:?}", + $original, unproxied + ); + + let mut proxy = <$($proxy_ty)* as Proxy>::proxy($original).unwrap(); + + let unproxied_without_world = proxy.unproxy().unwrap(); + assert_eq!( + unproxied_without_world, $original, + "Proxy and unproxy does not yield original type, expected {:?}, got {:?}", + $original, unproxied_without_world + ); + + }; + } + + #[test] + pub fn test_non_reflect_val_proxy() { + assert_proxy_invertible!(Test("test"), ValProxy::); + } + + #[test] + pub fn test_complex_types_proxy_is_inverse_of_unproxy() { + assert_proxy_invertible!([32; 4], [usize; 4]); + assert_proxy_invertible!( + core::array::from_fn::<_, 4, _>(|_| vec![Test("test")]), + [Vec::>; 4] + ); + assert_proxy_invertible!(Vec::::default(), Vec::); + assert_proxy_invertible!(Some(Test("test")), Option::>); + assert_proxy_invertible!(None::, Option::>); + assert_proxy_invertible!( + Some(Some(Test("test"))), + Option::>> + ); + assert_proxy_invertible!( + vec![Some(Test("test")), None, Some(Test("test"))], + Vec::>> + ); + assert_proxy_invertible!(vec![&1, &2, &3], Vec::<&usize>); + // assert_proxy_invertible!(vec![&(1, 2)], Vec::<&(usize, usize)>); + assert_proxy_invertible!(vec![vec![1, 2], vec![1, 2, 3]], Vec::>); + assert_proxy_invertible!( + vec![vec![(1, 2), (3, 4)], vec![(1, 2), (3, 4)]], + Vec::> + ); + assert_proxy_invertible!(Some(1), Option::); + assert_proxy_invertible!(Some(Some(1)), Option::>); + assert_proxy_invertible!(None::, Option::); + assert_proxy_invertible!(None::>, Option::>); + assert_proxy_invertible!(vec![Some(1), None, Some(2)], Vec::>); + assert_proxy_invertible!( + vec![Some(vec![1, 2, 3]), None, Some(vec![1, 4])], + Vec::>> + ); + } + + #[test] + pub fn test_val_proxy() { + let mut allocator = ReflectAllocator::default(); + let (alloc_id, _) = allocator.allocate(Test("test")); + + let mut proxy = ReflectValProxy::::new(TestProxy(ReflectReference { + base: ReflectBaseType { + type_id: std::any::TypeId::of::(), + base_id: ReflectBase::Owned(alloc_id), + }, + reflect_path: vec![], + })); + let mut world = World::new(); + let mut accesses = SmallVec::new(); + let world = WorldAccessGuard::new(&mut world); + let type_registry = TypeRegistry::default(); + + proxy.collect_accesses(&world, &mut accesses).unwrap(); + let unproxied = unsafe { + proxy + .unproxy_with_world(&world, &accesses, &type_registry, &allocator) + .unwrap() + }; + assert_eq!(unproxied.0, "test"); + } + + #[test] + pub fn test_proxy_ref() { + let mut allocator = ReflectAllocator::default(); + let (alloc_id, _) = allocator.allocate(Test("test")); + + let mut proxy = ReflectRefProxy::::new(TestProxy(ReflectReference { + base: ReflectBaseType { + type_id: std::any::TypeId::of::(), + base_id: ReflectBase::Owned(alloc_id), + }, + reflect_path: vec![], + })); + let mut world = World::new(); + let mut accesses = SmallVec::new(); + let world = WorldAccessGuard::new(&mut world); + let type_registry = TypeRegistry::default(); + + proxy.collect_accesses(&world, &mut accesses).unwrap(); + let unproxied = unsafe { + proxy + .unproxy_with_world(&world, &accesses, &type_registry, &allocator) + .unwrap() + }; + assert_eq!(unproxied.0, "test"); + } + + #[test] + pub fn test_proxy_ref_mut() { + let mut allocator = ReflectAllocator::default(); + let (alloc_id, _) = allocator.allocate(Test("test")); + + let mut proxy = ReflectRefMutProxy::::new(TestProxy(ReflectReference { + base: ReflectBaseType { + type_id: std::any::TypeId::of::(), + base_id: ReflectBase::Owned(alloc_id), + }, + reflect_path: vec![], + })); + let mut world = World::new(); + let mut accesses = SmallVec::new(); + let world = WorldAccessGuard::new(&mut world); + let type_registry = TypeRegistry::default(); + + proxy.collect_accesses(&world, &mut accesses).unwrap(); + let unproxied = unsafe { + proxy + .unproxy_with_world(&world, &accesses, &type_registry, &allocator) + .unwrap() + }; + assert_eq!(unproxied.0, "test"); + } + + #[test] + pub fn test_vec_proxy_ref_mut() { + let mut allocator = ReflectAllocator::default(); + let (alloc_id, _) = allocator.allocate(Test("test")); + + let mut proxy = vec![Some(ReflectRefMutProxy::::new(TestProxy( + ReflectReference { + base: ReflectBaseType { + type_id: std::any::TypeId::of::(), + base_id: ReflectBase::Owned(alloc_id), + }, + reflect_path: vec![], + }, + )))]; + let mut world = World::new(); + let mut accesses = SmallVec::new(); + let world = WorldAccessGuard::new(&mut world); + let type_registry = TypeRegistry::default(); + + proxy.collect_accesses(&world, &mut accesses).unwrap(); + let unproxied = unsafe { + proxy + .unproxy_with_world(&world, &accesses, &type_registry, &allocator) + .unwrap() + }; + assert_eq!(unproxied[0].as_ref().unwrap().0, "test"); + } + + #[test] + pub fn test_invalid_access() { + let mut allocator = ReflectAllocator::default(); + + let (allocation_id, _) = allocator.allocate(Test("test")); + + let reflect_ref = ReflectReference { + base: ReflectBaseType { + type_id: std::any::TypeId::of::(), + base_id: ReflectBase::Owned(allocation_id), + }, + reflect_path: vec![], + }; + + // mutable access to the same allocation + let proxy = vec![ + ReflectRefMutProxy::::new(TestProxy(reflect_ref.clone())), + ReflectRefMutProxy::::new(TestProxy(reflect_ref)), + ]; + + let mut world = World::new(); + let mut accesses = SmallVec::new(); + let world = WorldAccessGuard::new(&mut world); + + let result = proxy.collect_accesses(&world, &mut accesses); + assert!(matches!(result, Err(..))); + } +} diff --git a/crates/bevy_mod_scripting_core/src/bindings/query.rs b/crates/bevy_mod_scripting_core/src/bindings/query.rs new file mode 100644 index 0000000000..5a7db18a45 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/bindings/query.rs @@ -0,0 +1,114 @@ +use std::{any::TypeId, ops::Deref, sync::Arc}; + +use bevy::{ecs::entity::Entity, reflect::TypeRegistration}; + +use super::{ReflectReference, WorldCallbackAccess, STALE_WORLD_MSG}; +use crate::prelude::{ScriptError, ScriptResult}; + +/// A wrapper around a `TypeRegistration` that provides additional information about the type. +/// +/// This is used as a hook to a rust type from a scripting language. We should be able to easily convert between a type name and a [`ScriptTypeRegistration`]. +#[derive(Clone)] +pub struct ScriptTypeRegistration(pub(crate) Arc); + +impl ScriptTypeRegistration { + pub fn new(arc: Arc) -> Self { + Self(arc) + } + + #[inline(always)] + pub fn short_name(&self) -> &str { + self.0.type_info().type_path_table().short_path() + } + + #[inline(always)] + pub fn type_name(&self) -> &'static str { + self.0.type_info().type_path_table().path() + } + + #[inline(always)] + pub fn type_id(&self) -> TypeId { + self.0.type_info().type_id() + } +} + +impl std::fmt::Debug for ScriptTypeRegistration { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_tuple("ScriptTypeRegistration") + .field(&self.0.type_info().type_path()) + .finish() + } +} + +impl std::fmt::Display for ScriptTypeRegistration { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(self.0.type_info().type_path()) + } +} + +impl Deref for ScriptTypeRegistration { + type Target = Arc; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +#[derive(Clone)] +pub struct ScriptQueryBuilder { + world: WorldCallbackAccess, + components: Vec, + with: Vec, + without: Vec, +} + +impl ScriptQueryBuilder { + pub fn new(world: WorldCallbackAccess) -> Self { + Self { + world, + components: vec![], + with: vec![], + without: vec![], + } + } + + pub fn components(&mut self, components: Vec) -> &mut Self { + self.components.extend(components); + self + } + + pub fn with(&mut self, with: Vec) -> &mut Self { + self.with.extend(with); + self + } + + pub fn without(&mut self, without: Vec) -> &mut Self { + self.without.extend(without); + self + } + + pub fn build(&mut self) -> ScriptResult> { + self.world.query( + std::mem::take(&mut self.components), + std::mem::take(&mut self.with), + std::mem::take(&mut self.without), + ) + } +} + +#[derive(Clone)] +pub struct ScriptQueryResult(pub Entity, pub Vec); + +impl WorldCallbackAccess { + pub fn query( + &mut self, + components: Vec, + with: Vec, + without: Vec, + ) -> ScriptResult> { + // for c in components { + + // } + todo!() + } +} diff --git a/crates/bevy_mod_scripting_core/src/bindings/reference.rs b/crates/bevy_mod_scripting_core/src/bindings/reference.rs new file mode 100644 index 0000000000..b89d146d06 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/bindings/reference.rs @@ -0,0 +1,500 @@ +//! # Motivation +//! +//! Traits and structs needed to support the creation of bindings for scripting languages. +//! reflection gives us access to `dyn PartialReflect` objects via their type name, +//! Scripting languages only really support `Clone` objects so if we want to support references, +//! we need wrapper types which have owned and ref variants. +use lockable::LockableHashMap; + +use std::{ + any::TypeId, + cell::UnsafeCell, + error::Error, + fmt::Debug, + marker::PhantomData, + ops::Index, + sync::{Arc, Weak}, + time::Duration, +}; + +use bevy::{ + ecs::{ + change_detection::MutUntyped, + component::{Component, ComponentId}, + entity::Entity, + reflect::AppTypeRegistry, + system::Resource, + world::{unsafe_world_cell::UnsafeWorldCell, Mut, World}, + }, + ptr::Ptr, + reflect::{ + Access, ParsedPath, PartialReflect, Reflect, ReflectFromPtr, ReflectPath, ReflectPathError, TypeInfo, TypeRegistry + }, +}; +use smallvec::SmallVec; + +use crate::{ + bindings::{ReflectAllocation, ReflectAllocationId}, + prelude::{ReflectAllocator, ScriptError, ScriptResult}, +}; + +use super::{ + proxy::{Proxy, Unproxy}, + ReflectAccessId, ReflectAccessKind, WorldAccessGuard, WorldAccessWrite, DEFAULT_INTERVAL, + DEFAULT_TIMEOUT, +}; + +/// An accessor to a `dyn PartialReflect` struct, stores a base ID of the type and a reflection path +/// safe to build but to reflect on the value inside you need to ensure aliasing rules are upheld +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ReflectReference { + pub base: ReflectBaseType, + // TODO: experiment with Fixed capacity vec, boxed array etc, compromise between heap allocation and runtime cost + // needs benchmarks first though + /// The path from the top level type to the actual value we want to access + pub reflect_path: Vec, +} + +// just a dummy standin for unregistered types +struct UnregisteredType; + +impl ReflectReference { + + pub fn new_allocated( + value: T, + allocator: &mut ReflectAllocator, + ) -> ReflectReference { + let (id, _) = allocator.allocate(value); + ReflectReference { + base: ReflectBaseType { + type_id: TypeId::of::(), + base_id: ReflectBase::Owned(id), + }, + reflect_path: Vec::default(), + } + } + + /// Indexes into the reflect path inside this reference. + /// You can use [`Self::reflect`] and [`Self::reflect_mut`] to get the actual value. + pub fn index_path>(&mut self, index: T) { + self.reflect_path.push(index.into()); + } + + /// A form of [`Self::reflect`] which does the access checks for you. + /// Panics if it waits for access too long to prevent deadlocks. + pub fn with_reflect O>( + &self, + world: &WorldAccessGuard, + type_registry: &TypeRegistry, + allocator: Option<&ReflectAllocator>, + f: F, + ) -> O { + let access = world + .get_access_timeout( + self.base.base_id.get_reflect_access_id(), + DEFAULT_TIMEOUT, + DEFAULT_INTERVAL, + ) + .unwrap_or_else(|| panic!("Timeout when waiting for access for: `{:?}`", self)); + + let reflect = self + .reflect( + world.as_unsafe_world_cell(), + &access, + type_registry, + allocator, + ) + .unwrap(); + let o = f(reflect); + world.release_access(access); + o + } + + pub fn with_reflect_mut O>( + &self, + world: &WorldAccessGuard, + type_registry: &TypeRegistry, + allocator: Option<&ReflectAllocator>, + f: F, + ) -> O { + let mut access = world + .get_access_timeout( + self.base.base_id.get_reflect_access_id(), + DEFAULT_TIMEOUT, + DEFAULT_INTERVAL, + ) + .unwrap_or_else(|| panic!("Timeout when waiting for access for: `{:?}`", self)); + + let reflect = self + .reflect_mut( + world.as_unsafe_world_cell(), + &mut access, + type_registry, + allocator, + ) + .unwrap(); + let o = f(reflect); + world.release_access(access); + o + } + + /// Returns `Ok(())` if the given access is sufficient to read the value or an appropriate error otherwise + pub fn expect_read_access<'w>( + &self, + access: &WorldAccessWrite<'w>, + type_registry: &TypeRegistry, + allocator: Option<&ReflectAllocator>, + world: UnsafeWorldCell<'w>, + ) -> ScriptResult<()> { + if !access.can_read(self.base.base_id.get_reflect_access_id()) { + Err(ScriptError::new_reflection_error(format!( + "Invalid access when trying to read: `{}`, instead got access to `{}`", + self.base.display_with_type_name(type_registry), + access.to_enriched_str(type_registry, allocator, world) + ))) + } else { + Ok(()) + } + } + + /// Returns `Ok(())` if the given access is sufficient to write to the value or an appropriate error otherwise + /// Note that this is not sufficient for write access, you also need to ensure the [`WorldAccessWrite`] won't be used to access the same value mutably elsewhere, + /// if you have a `&mut WorldAccessWrite` you can guarantee this statically. This function just checks that the access itself is for the right base with write access + pub fn expect_write_access<'w>( + &self, + access: &WorldAccessWrite<'w>, + type_registry: &TypeRegistry, + allocator: Option<&ReflectAllocator>, + world: UnsafeWorldCell<'w>, + ) -> ScriptResult<()> { + if !access.can_read(self.base.base_id.get_reflect_access_id()) { + Err(ScriptError::new_reflection_error(format!( + "Invalid access when trying to write: `{}`, instead got access to `{}`", + self.base.display_with_type_name(type_registry), + access.to_enriched_str(type_registry, allocator, world) + ))) + } else { + Ok(()) + } + } + + /// Retrieves a reference to the underlying `dyn PartialReflect` type valid for the 'w lifetime of the world cell. + /// If the underlying componentId is not the same as the one we have access to, an error is returned. + pub fn reflect<'w, 'c>( + &self, + world: UnsafeWorldCell<'w>, + access: &'c WorldAccessWrite<'w>, + type_registry: &TypeRegistry, + allocator: Option<&'c ReflectAllocator>, + ) -> ScriptResult<&'c dyn PartialReflect> { + self.expect_read_access(access, type_registry, allocator, world)?; + // Safety: since we have read access to the underlying componentId we can safely access the component + // and we can return a reference tied to its lifetime, which will prevent invalid aliasing + return unsafe { self.reflect_unsafe(world, type_registry, allocator) }; + } + + /// Retrieves a reference to the underlying `dyn PartialReflect` type valid for the 'w lifetime of the world cell. + /// If the underlying componentId is not the same as the one we have access to, an error is returned. + /// + /// If we are accessing a component or resource, it's marked as changed + pub fn reflect_mut<'w, 'c>( + &self, + world: UnsafeWorldCell<'w>, + access: &'c mut WorldAccessWrite<'w>, + type_registry: &TypeRegistry, + allocator: Option<&'c ReflectAllocator>, + ) -> ScriptResult<&'c mut dyn PartialReflect> { + self.expect_write_access(access, type_registry, allocator, world)?; + // Safety: since we have write access to the underlying reflect access id we can safely access the component + // and we can return a reference tied to its lifetime, which will prevent invalid aliasing + return unsafe { self.reflect_mut_unsafe(world, type_registry, allocator) }; + } + + /// Retrieves a reference to the underlying `dyn PartialReflect` type valid for the 'w lifetime of the world cell + /// # Safety + /// - The caller must ensure the cell has permission to access the underlying value + /// - The caller must ensure no aliasing mut references to the same value exist at all at the same time + pub unsafe fn reflect_unsafe<'w>( + &self, + world: UnsafeWorldCell<'w>, + type_registry: &TypeRegistry, + allocator: Option<&'w ReflectAllocator>, + ) -> ScriptResult<&'w dyn PartialReflect> { + if let ReflectBase::Owned(id) = &self.base.base_id { + let allocator = + allocator.ok_or_else(|| ScriptError::new_reflection_error("Allocator missing"))?; + let arc = allocator + .get(*id) + .ok_or_else(|| ScriptError::new_reflection_error("Missing allocation"))?; + + // safety: caller promises it's fine :) + return self.walk_path(unsafe { &*arc.get_ptr() }); + }; + // all Reflect types should have this derived + let from_ptr_data: &ReflectFromPtr = type_registry + .get_type_data(self.base.type_id) + .expect("FromPtr is not registered for this type, cannot retrieve reflect reference"); + + let ptr = self + .base + .base_id + .clone() + .into_ptr(world) + .ok_or_else(|| + ScriptError::new_reflection_error( + format!("Base reference is invalid, is the component/resource initialized? does the entity exist?. When accessing: `{}`", self.base.display_with_type_name(type_registry))))?; + + // (Ptr) Safety: we use the same type_id to both + // 1) retrieve the ptr + // 2) retrieve the ReflectFromPtr type data + // (UnsafeWorldCell) Safety: + // we already have access to &world so no &mut world exists + debug_assert_eq!( + from_ptr_data.type_id(), + self.base.type_id, + "Invariant violated" + ); + let base = unsafe { from_ptr_data.as_reflect(ptr) }; + self.walk_path(base.as_partial_reflect()) + } + + /// Retrieves mutable reference to the underlying `dyn PartialReflect` type valid for the 'w lifetime of the world cell + /// # Safety + /// - The caller must ensure the cell has permission to access the underlying value + /// - The caller must ensure no other references to the same value exist at all at the same time (even if you have the correct access) + pub unsafe fn reflect_mut_unsafe<'w>( + &self, + world: UnsafeWorldCell<'w>, + type_registry: &TypeRegistry, + allocator: Option<&'w ReflectAllocator>, + ) -> ScriptResult<&'w mut dyn PartialReflect> { + if let ReflectBase::Owned(id) = &self.base.base_id { + let allocator = allocator.ok_or_else(|| ScriptError::new_reflection_error("Allocator missing"))?; + + let arc = allocator + .get_mut(*id) + .ok_or_else(|| ScriptError::new_reflection_error("Missing allocation"))?; + + // Safety: caller promises this is fine :) + return self.walk_path_mut(unsafe { &mut *arc.get_ptr() }); + }; + + // all Reflect types should have this derived + let from_ptr_data: &ReflectFromPtr = type_registry + .get_type_data(self.base.type_id) + .expect("FromPtr is not registered for this type, cannot retrieve reflect reference"); + + let ptr = self + .base + .base_id + .clone() + .into_ptr_mut(world) + .ok_or_else(|| + ScriptError::new_reflection_error( + format!("Base reference is invalid, is the component/resource initialized? does the entity exist?. When accessing: `{}`", self.base.display_with_type_name(type_registry))))? + .into_inner(); + + // (Ptr) Safety: we use the same type_id to both + // 1) retrieve the ptr + // 2) retrieve the ReflectFromPtr type data + // (UnsafeWorldCell) Safety: + // we already have access to &world so no &mut world exists + debug_assert_eq!( + from_ptr_data.type_id(), + self.base.type_id, + "Invariant violated" + ); + let base = unsafe { from_ptr_data.as_reflect_mut(ptr) }; + self.walk_path_mut(base.as_partial_reflect_mut()) + } + + fn walk_path<'a>(&self, root: &'a dyn PartialReflect) -> ScriptResult<&'a dyn PartialReflect> { + let mut current = root; + for elem in self.reflect_path.iter() { + current = elem + .reflect_element(current) + .map_err(|e| ScriptError::new_reflection_error(e.to_string()))?; + } + Ok(current) + } + + fn walk_path_mut<'a>(&self, root: &'a mut dyn PartialReflect) -> ScriptResult<&'a mut dyn PartialReflect> { + let mut current = root; + for elem in self.reflect_path.iter() { + current = elem + .reflect_element_mut(current) + .map_err(|e| ScriptError::new_reflection_error(e.to_string()))?; + } + Ok(current) + } +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct ReflectBaseType { + pub type_id: TypeId, + pub base_id: ReflectBase, +} + +impl ReflectBaseType { + pub fn type_name(type_id: TypeId, type_registry: &TypeRegistry) -> &'static str { + type_registry + .get_type_info(type_id) + .map(TypeInfo::type_path) + .unwrap_or("") + } + + pub fn display_with_type_name(&self, type_registry: &TypeRegistry) -> String { + format!( + "ReflectBase({}, {:?})", + Self::type_name(self.type_id, type_registry), + self.base_id + ) + } +} + +/// The Id of the kind of reflection base being pointed to +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum ReflectBase { + Component(Entity, ComponentId), + Resource(ComponentId), + Owned(ReflectAllocationId), +} + +impl ReflectBase { + /// Retrieves the pointer to the underlying `dyn PartialReflect` object valid for the 'w lifteime of the world cell + /// + /// # Safety + /// - The caller must ensure the cell has permission to access the underlying value + /// - The caller must ensure no aliasing mutable references to the same value exist at the same time + pub unsafe fn into_ptr(self, world: UnsafeWorldCell<'_>) -> Option> { + match self { + ReflectBase::Component(entity, component_id) => { + // Safety: the caller ensures invariants hold + world.get_entity(entity)?.get_by_id(component_id) + } + ReflectBase::Resource(component_id) => { + // Safety: the caller ensures invariants hold + world.get_resource_by_id(component_id) + } + _ => None, + } + } + + /// Retrieves the pointer to the underlying `dyn PartialReflect` object valid for the 'w lifteime of the world cell + /// + /// # Safety + /// - The caller must ensure the cell has permission to access the underlying value + /// - The caller must ensure no aliasing references to the same value exist at all at the same time + pub unsafe fn into_ptr_mut(self, world: UnsafeWorldCell<'_>) -> Option> { + match self { + ReflectBase::Component(entity, component_id) => { + // Safety: the caller ensures invariants hold + world.get_entity(entity)?.get_mut_by_id(component_id) + } + ReflectBase::Resource(component_id) => { + // Safety: the caller ensures invariants hold + world.get_resource_mut_by_id(component_id) + } + _ => None, + } + } + + pub fn get_reflect_access_id(&self) -> ReflectAccessId { + match self { + ReflectBase::Component(_, cid) | ReflectBase::Resource(cid) => (*cid).into(), + ReflectBase::Owned(id) => (*id).into(), + } + } +} + +/// An element in the reflection path, the base reference included +#[derive(Clone, PartialEq, Eq, Debug)] +pub enum ReflectionPathElem { + /// A standard reflection path, i.e. `.field_name[vec_index]`, pre-parsed since we construct once potentially use many times + Reflection(ParsedPath), + /// a deferred reflection + DeferredReflection(DeferredReflection), +} + +impl ReflectionPathElem { + pub fn new_reflection>(path: I) -> Self { + Self::Reflection(path.into()) + } + + pub fn new_deferred>(defref: I) -> Self { + Self::DeferredReflection(defref.into()) + } +} + +impl From<(A, B)> for DeferredReflection +where + A: Fn(&dyn PartialReflect) -> Result<&dyn PartialReflect, ReflectPathError<'static>> + Send + Sync, + B: Fn(&mut dyn PartialReflect) -> Result<&mut dyn PartialReflect, ReflectPathError<'static>> + Send + Sync, +{ + fn from((get, get_mut): (A, B)) -> Self { + Self { + get: Arc::new(get), + get_mut: Arc::new(get_mut), + } + } +} + +impl> From for ReflectionPathElem { + fn from(value: T) -> Self { + Self::DeferredReflection(value.into()) + } +} + +impl From for ReflectionPathElem { + fn from(value: ParsedPath) -> Self { + Self::Reflection(value) + } +} + +impl<'a> ReflectPath<'a> for &'a ReflectionPathElem { + fn reflect_element<'r>( + self, + root: &'r dyn PartialReflect, + ) -> Result<&'r dyn PartialReflect, ReflectPathError<'a>> { + match self { + ReflectionPathElem::Reflection(path) => path.reflect_element(root), + ReflectionPathElem::DeferredReflection(f) => (f.get)(root), + } + } + + fn reflect_element_mut<'r>( + self, + root: &'r mut dyn PartialReflect, + ) -> Result<&'r mut dyn PartialReflect, ReflectPathError<'a>> { + match self { + ReflectionPathElem::Reflection(path) => path.reflect_element_mut(root), + ReflectionPathElem::DeferredReflection(defref) => (defref.get_mut)(root), + } + } +} + +/// A ReflectPath which can perform arbitrary operations on the root object to produce a sub-reference +#[derive(Clone)] +pub struct DeferredReflection { + pub get: + Arc Result<&dyn PartialReflect, ReflectPathError<'static>> + Send + Sync>, + pub get_mut: Arc< + dyn Fn(&mut dyn PartialReflect) -> Result<&mut dyn PartialReflect, ReflectPathError<'static>> + + Send + + Sync, + >, +} + +impl Debug for DeferredReflection { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("DeferredReflection") + } +} + +impl PartialEq for DeferredReflection { + fn eq(&self, other: &Self) -> bool { + Arc::ptr_eq(&self.get, &other.get) && Arc::ptr_eq(&self.get_mut, &other.get_mut) + } +} + +impl Eq for DeferredReflection {} diff --git a/crates/bevy_mod_scripting_core/src/bindings/world.rs b/crates/bevy_mod_scripting_core/src/bindings/world.rs new file mode 100644 index 0000000000..0e60d2478a --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/bindings/world.rs @@ -0,0 +1,1888 @@ +//! # Motivation +//! +//! Traits and structs needed to support the creation of bindings for scripting languages. +//! reflection gives us access to `dyn PartialReflect` objects via their type name, +//! Scripting languages only really support `Clone` objects so if we want to support references, +//! we need wrapper types which have owned and ref variants. +use lockable::LockableHashMap; + +use std::{ + any::TypeId, + cell::UnsafeCell, + error::Error, + fmt::Debug, + marker::PhantomData, + ops::Index, + sync::{ + atomic::{AtomicBool, AtomicUsize, Ordering}, + Arc, Weak, + }, + time::Duration, +}; + +use bevy::{ + ecs::{ + change_detection::MutUntyped, + component::{Component, ComponentId}, + entity::Entity, + reflect::{AppTypeRegistry, ReflectComponent, ReflectFromWorld, ReflectResource}, + system::{Commands, Resource}, + world::{unsafe_world_cell::UnsafeWorldCell, CommandQueue, Mut, World}, + }, + hierarchy::{BuildChildren, Children, DespawnRecursiveExt, Parent}, + ptr::Ptr, + reflect::{ + std_traits::ReflectDefault, Access, ParsedPath, Reflect, ReflectFromPtr, ReflectPath, + ReflectPathError, TypeInfo, TypePath, TypeRegistration, TypeRegistry, + }, +}; + +use smallvec::SmallVec; + +use crate::{ + bindings::{ReflectAllocation, ReflectAllocationId}, + prelude::{ReflectAllocator, ScriptError, ScriptResult}, +}; + +use super::{ + proxy::{Proxy, Unproxy}, + ReflectBase, ReflectBaseType, ReflectReference, ScriptTypeRegistration, +}; + +/// Describes kinds of base value we are accessing via reflection +#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)] +pub enum ReflectAccessKind { + ComponentOrResource, + Allocation, +} + +/// Describes the id pointing to the base value we are accessing via reflection, for components and resources this is the ComponentId +/// for script owned values this is an allocationId, this is used to ensure we have permission to access the value. +#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)] +pub struct ReflectAccessId { + kind: ReflectAccessKind, + id: usize, +} + +impl From for ReflectAccessId { + fn from(value: ComponentId) -> Self { + Self { + kind: ReflectAccessKind::ComponentOrResource, + id: value.index(), + } + } +} + +impl From for ReflectAccessId { + fn from(value: ReflectAllocationId) -> Self { + Self { + kind: ReflectAccessKind::Allocation, + id: value.id(), + } + } +} + +/// While [`WorldAccessGuard`] prevents aliasing at runtime and also makes sure world exists at least as long as the guard itself, +/// borrows sadly do not persist the script-host boundary :(. That is to be expected, but instead we can make an abstraction which removes the lifetime parameter, making the outer type 'static, +/// while making sure the lifetime is still satisfied! +#[derive(Clone, Debug)] +pub struct WorldCallbackAccess(Weak>); + +impl WorldCallbackAccess { + /// Wraps a callback which requires access to the world in a 'static way via [`WorldCallbackAccess`]. + pub fn with_callback_access( + world: &mut World, + callback: impl FnOnce(&WorldCallbackAccess) -> T, + ) -> T { + // - the world cannot be dropped before the world drops since we have mutable reference to it in this entire function + // - nothing can alias inappropriately WorldAccessGuard since it's only instance is behind the raw Arc + let world_guard = Arc::new(WorldAccessGuard::new(world)); + let world_guard = unsafe { WorldCallbackAccess::new(Arc::downgrade(&world_guard)) }; + + callback(&world_guard) + } + + /// Creates a new [`WorldCallbackAccess`] with an erased lifetime. + /// + /// # Safety + /// - The caller must ensure the [`WorldAccessGuard`] must not outlive the 'w lifetime + /// - In practice this means that between the moment the original Arc is dropped, the lifetime 'w must be valid + /// - I.e. you *must* drop the original [`Arc`] before the original 'w scope ends + pub unsafe fn new<'w>(world: Weak>) -> Self { + // Safety: the caller ensures `WorldAccessGuard` does not outlive the original lifetime 'w + + let world = unsafe { + std::mem::transmute::>, Weak>>( + world, + ) + }; + + Self(world) + } + + /// Attempts to read the world access guard, if it still exists + pub fn read(&self) -> Option>> { + self.0.upgrade() + } +} + +pub(crate) const STALE_WORLD_MSG: &str = "Tried to access world via stale reference"; +pub(crate) const CONCURRENT_WORLD_ACCESS_MSG: &str = + "Something else is accessing the world right now!"; +pub(crate) const CONCURRENT_ACCESS_MSG: &str = + "Something else is accessing the resource/component/allocation right now!"; + +/// common world methods, see: +/// - [`crate::bindings::query`] for query related functionality +impl WorldCallbackAccess { + pub fn get_type_by_name(&self, type_name: &str) -> Option { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + world.with_resource(|_, registry: Mut| { + let registry = registry.read(); + registry + .get_with_short_type_path(type_name) + .or_else(|| registry.get_with_type_path(type_name)) + .map(|registration| ScriptTypeRegistration::new(Arc::new(registration.clone()))) + }) + } + + pub fn add_default_component( + &self, + entity: Entity, + registration: ScriptTypeRegistration, + ) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( + "Cannot add default component since type: `{}`, Does not have ReflectComponent data registered.", + registration.type_info().type_path() + )))?; + + // we look for ReflectDefault or ReflectFromWorld data then a ReflectComponent data + let instance = if let Some(default_td) = registration.data::() { + default_td.default() + } else if let Some(from_world_td) = registration.data::() { + if let Some(world) = world.get_whole_world_access() { + from_world_td.from_world(world) + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + } else { + return Err(ScriptError::new_runtime_error(format!( + "Cannot add default component since type: `{}`, Does not have ReflectDefault or ReflectFromWorld data registered.", + registration.type_info().type_path() + ))); + }; + + // TODO: this shouldn't need entire world access it feels + if let Some(world) = world.get_whole_world_access() { + let app_registry = world + .remove_resource::() + .unwrap_or_else(|| panic!("Missing type registry")); + + let mut entity = world.get_entity_mut(entity).map_err(|e| { + ScriptError::new_runtime_error(format!( + "Could not access entity: {:?}. {e}", + entity + )) + })?; + { + let registry = app_registry.read(); + component_data.insert(&mut entity, instance.as_partial_reflect(), ®istry); + } + world.insert_resource(app_registry); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn get_component( + &self, + entity: Entity, + component_id: ComponentId, + ) -> ScriptResult> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let entity = world.cell.get_entity(entity).ok_or_else(|| { + ScriptError::new_runtime_error(format!("Entity does not exist: {:?}", entity)) + })?; + + let component_info = world + .cell + .components() + .get_info(component_id) + .ok_or_else(|| { + ScriptError::new_runtime_error(format!( + "Component does not exist: {:?}", + component_id + )) + })?; + + if entity.contains_id(component_id) { + Ok(Some(ReflectReference { + base: ReflectBaseType { + type_id: component_info + .type_id() + .expect("Component does not have type id"), + base_id: ReflectBase::Component(entity.id(), component_id), + }, + reflect_path: Default::default(), + })) + } else { + Ok(None) + } + } + + pub fn has_component(&self, entity: Entity, component_id: ComponentId) -> ScriptResult { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let entity = world.cell.get_entity(entity).ok_or_else(|| { + ScriptError::new_runtime_error(format!("Entity does not exist: {:?}", entity)) + })?; + + Ok(entity.contains_id(component_id)) + } + + pub fn remove_component( + &self, + entity: Entity, + registration: ScriptTypeRegistration, + ) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( + "Cannot remove component since type: `{}`, Does not have ReflectComponent data registered.", + registration.type_info().type_path() + )))?; + + // TODO: this shouldn't need entire world access it feels + if let Some(world) = world.get_whole_world_access() { + let mut entity = world.get_entity_mut(entity).map_err(|e| { + ScriptError::new_runtime_error(format!( + "Could not retrieve entity: {:?}. {e}", + entity + )) + })?; + + component_data.remove(&mut entity); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + Ok(()) + } + + pub fn get_resource(&self, resource_id: ComponentId) -> ScriptResult { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let component_info = world + .cell + .components() + .get_info(resource_id) + .ok_or_else(|| { + ScriptError::new_runtime_error(format!( + "Resource does not exist: {:?}", + resource_id + )) + })?; + + Ok(ReflectReference { + base: ReflectBaseType { + type_id: component_info + .type_id() + .expect("Resource does not have type id"), + base_id: ReflectBase::Resource(resource_id), + }, + reflect_path: Default::default(), + }) + } + + pub fn remove_resource(&self, registration: ScriptTypeRegistration) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( + "Cannot remove resource since type: `{}`, Does not have ReflectResource data registered.", + registration.type_info().type_path() + )))?; + + // TODO: this shouldn't need entire world access it feels + if let Some(world) = world.get_whole_world_access() { + component_data.remove(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + Ok(()) + } + + pub fn has_resource(&self, resource_id: ComponentId) -> bool { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + world.cell.components().get_info(resource_id).is_some() + } + + pub fn get_children(&self, entity: Entity) -> ScriptResult> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let access = world + .get_component_access_typed::() + .unwrap_or_else(|| panic!("{CONCURRENT_ACCESS_MSG}")); + + Ok(world + .get_component::(&access, entity)? + .map(|c| c.to_vec()) + .unwrap_or_default()) + } + + pub fn get_parent(&self, entity: Entity) -> ScriptResult> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + let access = world + .get_component_access_typed::() + .unwrap_or_else(|| panic!("{CONCURRENT_ACCESS_MSG}")); + + Ok(world + .get_component::(&access, entity)? + .map(|c| c.get())) + } + + pub fn push_children(&self, parent: Entity, children: &[Entity]) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + if let Some(world) = world.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(parent).add_children(children); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn remove_children(&self, parent: Entity, children: &[Entity]) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + if let Some(world) = world.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(parent).remove_children(children); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn insert_children( + &self, + parent: Entity, + index: usize, + children: &[Entity], + ) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + if let Some(world) = world.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(parent).insert_children(index, children); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn despawn_recursive(&self, entity: Entity) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + if let Some(world) = world.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(entity).despawn_recursive(); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn despawn(&self, entity: Entity) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + if let Some(world) = world.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(entity).despawn(); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn despawn_descendants(&self, entity: Entity) -> ScriptResult<()> { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + + if let Some(world) = world.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(entity).despawn_descendants(); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } +} + +/// Unit of world access +pub type WorldAccessUnit<'w> = WorldAccessWrite<'w>; + +pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(5); +pub const DEFAULT_INTERVAL: Duration = Duration::from_millis(10); + +/// Provides safe access to the world via [`WorldAccess`] permissions, which enforce aliasing rules at runtime in multi-thread environments +#[derive(Clone)] +pub struct WorldAccessGuard<'w> { + cell: UnsafeWorldCell<'w>, + // TODO: this is fairly hefty, explore other ways to hand out locks on WorldAccess + accesses: Arc>>>, + /// true if anybody has any access to the world + accesses_count: Arc, + // TODO can we track code/stack locations of things holding onto theese locks for debugging? +} + +impl<'w> WorldAccessGuard<'w> { + /// Creates a new [`WorldAccessGuard`] for the given mutable borrow of the world + pub fn new(world: &'w mut World) -> Self { + Self { + cell: world.as_unsafe_world_cell(), + accesses: Default::default(), + accesses_count: Arc::new(AtomicUsize::new(0)), + } + } + + /// Retrieves the underlying unsafe world cell, with no additional guarantees of safety + /// proceed with caution and only use this if you understand what you're doing + pub fn as_unsafe_world_cell(&self) -> UnsafeWorldCell<'w> { + self.cell + } + + /// Retrieves the underlying read only unsafe world cell, with no additional guarantees of safety + /// proceed with caution and only use this if you understand what you're doing + pub fn as_unsafe_world_cell_readonly(&self) -> UnsafeWorldCell<'w> { + self.cell + } + + /// Checks nobody else is currently accessing the world, and if so locks access to it until + /// [`release_whole_world_access`] is called. + pub fn get_whole_world_access(&self) -> Option<&mut World> { + if self.accesses_count.load(Ordering::Relaxed) == 0 { + Some(unsafe { self.cell.world_mut() }) + } else { + None + } + } + + /// Releases whole world access. Allowing others to access it. + pub fn release_whole_world_access(&self, _world: &mut World) { + // we do not need ot use the world reference, it's there as proof that the caller has claimed access before + assert_eq!(self.accesses_count.load(Ordering::Relaxed), 1); + self.accesses_count.fetch_sub(1, Ordering::Relaxed); + } + + /// Tries to get access to the given reflect access id, if it's already given out returns `None`. If you want to wait for access, use [`WorldAccessGuard::get_access_timeout`] instead. + /// Remember to release this access once done with [`WorldAccessGuard::release_access`] or nobody else will be able to access this id!. + /// + /// Although forgetting to release access is safe, it's frankly quite rude and can lead to deadlocks. + pub fn get_access(&self, raid: ReflectAccessId) -> Option> { + let mut guard = self + .accesses + .blocking_lock(raid, lockable::SyncLimit::no_limit()) + .unwrap(); + let guard = guard.value_or_insert_with(|| { + Some(WorldAccessWrite { + raid, + _ph: PhantomData, + }) + }); + + if guard.is_some() { + self.accesses_count.fetch_add(1, Ordering::Relaxed); + guard.take() + } else { + // somebody has access to this already, we cannot access at the moment + None + } + } + + /// Blocking version of [`WorldAccessGuard::get_access`], waits for access to the given reflect access id. Will busy wait at the given intervals, untill the timeout is reached. + /// If interval is zero this is equivalent to busy waiting. + /// + /// # Panic + /// Will panic once access was not available after the timeout was reached + pub fn get_access_timeout( + &self, + raid: ReflectAccessId, + timeout: Duration, + interval: Duration, + ) -> Option> { + let mut access = self.get_access(raid); + let start = std::time::Instant::now(); + + while access.is_none() { + std::thread::sleep(interval); + access = self.get_access(raid); + if start.elapsed() > timeout { + return None; + } + } + access + } + + /// Releases access to the given reflect access id + pub fn release_access(&self, access: WorldAccessUnit<'w>) { + let mut guard = self + .accesses + .blocking_lock(access.raid, lockable::SyncLimit::no_limit()) + .unwrap(); + + let guard = guard + .value_mut() + .expect("Invariant violated, access should exist"); + + // should not be possible, we are the only ones who can instantiate WorldAccessUnit + assert!( + guard.is_none(), + "Invariant violated, an access has been released by someone else already who shouldn't have been able to do so" + ); + + self.accesses_count.fetch_sub(1, Ordering::Relaxed); + *guard = Some(access); + } + + /// Get access to the given component_id, this is the only way to access a component/resource safely (in the context of the world access guard) + /// since you can only access this component_id through a RwLock, there is no way to break aliasing rules. + /// Additionally the 'w lifetime prevents you from storing this access outside the lifetime of the underlying cell + pub fn get_component_access(&self, cid: ComponentId) -> Option> { + let access_id = ReflectAccessId { + kind: ReflectAccessKind::ComponentOrResource, + id: cid.index(), + }; + self.get_access(access_id) + } + + /// Similar to [`Self::get_component_access`] but typed, additionally panics if the component is not registered + pub fn get_component_access_typed(&self) -> Option> { + self.get_component_access( + self.cell + .components() + .component_id::() + .unwrap_or_else(|| { + panic!("Component not registered: `{}`", std::any::type_name::()) + }), + ) + } + + /// Get access to the given component_id, this is the only way to access a component/resource safely (in the context of the world access guard) + /// since you can only access this component_id through a RwLock, there is no way to break aliasing rules. + /// Additionally the 'w lifetime prevents you from storing this access outside the lifetime of the underlying cell + pub fn get_resource_access(&self, cid: ComponentId) -> Option> { + self.get_component_access(cid) + } + + /// Similar to [`Self::get_resource_access`] but typed, additionally panics if the resource is not registered + pub fn get_resource_access_typed(&self) -> Option> { + self.get_resource_access( + self.cell + .components() + .resource_id::() + .unwrap_or_else(|| { + panic!("Resource not registered: `{}`", std::any::type_name::()) + }), + ) + } + + /// Get access to the given allocation_id, this is the only way to access a script owned value safely (in the context of the world access guard) + pub fn get_allocation_access(&self, id: ReflectAllocationId) -> Option> { + let access_id = ReflectAccessId { + kind: ReflectAccessKind::Allocation, + id: id.id(), + }; + self.get_access(access_id) + } + + /// Provides access to a resource via callback. Panics if the resource does not exist or if waiting for access times out. + pub fn with_resource) -> O>(&self, f: F) -> O { + let cid = self + .cell + .components() + .resource_id::() + .unwrap_or_else(|| panic!("Resource not registered: `{}`", std::any::type_name::())); + + let mut access = self + .get_access_timeout(cid.into(), DEFAULT_TIMEOUT, DEFAULT_INTERVAL) + .unwrap_or_else(|| { + panic!( + "Timed out while waiting for access to resource: `{}`", + std::any::type_name::() + ) + }); + + let resource = self + .get_resource_mut::(&mut access) + .expect("invariant") + .expect("invariant"); + let out = f(self, resource); + self.release_access(access); + out + } + + /// Call a function on a type which can be proxied, first by unproxying the input with world access, + /// then calling the function and finally proxying the output with the allocator. + pub fn proxy_call<'i, O: Proxy, T: Unproxy, F: Fn(T::Output<'_>) -> O::Input<'i>>( + &self, + mut proxied_input: T, + f: F, + ) -> ScriptResult { + self.with_resource(|world, type_registry: Mut| { + world.with_resource(|_, mut allocator: Mut| { + let type_registry = type_registry.read(); + let mut world_acceses = SmallVec::default(); + + proxied_input.collect_accesses(self, &mut world_acceses)?; + let input = unsafe { + proxied_input.unproxy_with_world( + self, + &world_acceses, + &type_registry, + &allocator, + )? + }; + let out = f(input); + + O::proxy_with_allocator(out, &mut allocator) + }) + }) + } + + /// Get access to the given component, this is the only way to access a component/resource safely (in the context of the world access guard) + pub fn get_component( + &self, + access: &WorldAccessWrite, + entity: Entity, + ) -> ScriptResult> { + let component_id = match self.cell.components().component_id::() { + Some(id) => id, + None => return Ok(None), + }; + + if access.can_read(ReflectAccessId { + kind: ReflectAccessKind::ComponentOrResource, + id: component_id.index(), + }) { + // Safety: we have the correct access id + return unsafe { Ok(self.cell.get_entity(entity).and_then(|e| e.get::())) }; + } else { + Err(ScriptError::new_reflection_error( + "Cannot read component, received invalid access".to_string(), + )) + } + } + + /// Get access to the given component, this is the only way to access a component/resource safely (in the context of the world access guard) + pub fn get_component_mut( + &self, + access: &mut WorldAccessWrite, + entity: Entity, + ) -> ScriptResult>> { + let component_id = match self.cell.components().component_id::() { + Some(id) => id, + None => return Ok(None), + }; + + if access.can_write(ReflectAccessId { + kind: ReflectAccessKind::ComponentOrResource, + id: component_id.index(), + }) { + // Safety: we have the correct access id + return unsafe { Ok(self.cell.get_entity(entity).and_then(|e| e.get_mut::())) }; + } else { + Err(ScriptError::new_reflection_error( + "Cannot write component, received invalid access".to_string(), + )) + } + } + + /// Get access to the given resource + pub fn get_resource(&self, access: &WorldAccessWrite) -> ScriptResult> { + let resource_id = match self.cell.components().resource_id::() { + Some(id) => id, + None => return Ok(None), + }; + + if access.can_read(ReflectAccessId { + kind: ReflectAccessKind::ComponentOrResource, + id: resource_id.index(), + }) { + // Safety: we have the correct access id + return unsafe { Ok(self.cell.get_resource::()) }; + } else { + Err(ScriptError::new_reflection_error( + "Cannot read resource, received invalid access".to_string(), + )) + } + } + + /// Get access to the given resource, this is the only way to access a component/resource safely (in the context of the world access guard) + pub fn get_resource_mut( + &self, + access: &mut WorldAccessWrite, + ) -> ScriptResult>> { + let resource_id = match self.cell.components().resource_id::() { + Some(id) => id, + None => return Ok(None), + }; + + if access.can_write(ReflectAccessId { + kind: ReflectAccessKind::ComponentOrResource, + id: resource_id.index(), + }) { + // Safety: we have the correct access id + return unsafe { Ok(self.cell.get_resource_mut::()) }; + } else { + Err(ScriptError::new_reflection_error( + "Cannot write resource, received invalid access".to_string(), + )) + } + } +} + +/// Impl block for higher level world methods +impl<'w> WorldAccessGuard<'w> { + pub fn get_type_by_name(&self, type_name: &str) -> Option { + self.with_resource(|_, registry: Mut| { + let registry = registry.read(); + registry + .get_with_short_type_path(type_name) + .or_else(|| registry.get_with_type_path(type_name)) + .map(|registration| ScriptTypeRegistration::new(Arc::new(registration.clone()))) + }) + } + + pub fn add_default_component( + &self, + entity: Entity, + registration: ScriptTypeRegistration, + ) -> ScriptResult<()> { + let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( + "Cannot add default component since type: `{}`, Does not have ReflectComponent data registered.", + registration.type_info().type_path() + )))?; + + // we look for ReflectDefault or ReflectFromWorld data then a ReflectComponent data + let instance = if let Some(default_td) = registration.data::() { + default_td.default() + } else if let Some(from_world_td) = registration.data::() { + if let Some(world) = self.get_whole_world_access() { + from_world_td.from_world(world) + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + } else { + return Err(ScriptError::new_runtime_error(format!( + "Cannot add default component since type: `{}`, Does not have ReflectDefault or ReflectFromWorld data registered.", + registration.type_info().type_path() + ))); + }; + + // TODO: this shouldn't need entire world access it feels + if let Some(world) = self.get_whole_world_access() { + let app_registry = world + .remove_resource::() + .unwrap_or_else(|| panic!("Missing type registry")); + + let mut entity = world.get_entity_mut(entity).map_err(|e| { + ScriptError::new_runtime_error(format!( + "Could not retrieve entity: {:?}. {e}", + entity + )) + })?; + { + let registry = app_registry.read(); + component_data.insert(&mut entity, instance.as_partial_reflect(), ®istry); + } + world.insert_resource(app_registry); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } +} + +/// Having this is permission to access the contained [`ReflectAccessId`], there is no way to access anything safely through a [`WorldAccessGuard`] +/// without having a [`WorldAccess`] instance for that particular [`ReflectAccessId`]. +/// +/// If you do own a [`WorldAccess`] for some [`ReflectAccessId`], you can read and write to it safely. +/// If you only have an immutable borrow of [`WorldAccess`] you can only read it safely. +/// If you have a mutable borrow of [`WorldAccess`] you can read and write to it safely. +#[derive(Debug)] +pub struct WorldAccessWrite<'a> { + pub raid: ReflectAccessId, + pub(self) _ph: PhantomData<&'a usize>, +} + +impl<'w> WorldAccessWrite<'w> { + pub fn can_read(&self, raid: ReflectAccessId) -> bool { + self.raid == raid + } + + #[inline] + pub fn can_write(&self, raid: ReflectAccessId) -> bool { + self.can_read(raid) + } + + /// Prints the type of access this [`WorldAccessWrite`] entails, enriched with type information from the registry + pub fn to_enriched_str( + &self, + registry: &TypeRegistry, + allocator: Option<&ReflectAllocator>, + cell: UnsafeWorldCell, + ) -> String { + let (base_type, type_id) = match self.raid.kind { + ReflectAccessKind::ComponentOrResource => { + let type_id = cell + .components() + .get_info(ComponentId::new(self.raid.id)) + .and_then(|info| info.type_id()); + + ("Component/Resource", type_id) + } + ReflectAccessKind::Allocation => { + let type_id = allocator + .and_then(|allocator| allocator.get_type_id(ReflectAllocationId(self.raid.id))); + ("Allocation", type_id) + } + }; + + type_id + .and_then(|type_id| registry.get_type_info(type_id)) + .map(|info| format!("{base_type}<{}>", info.type_path())) + .unwrap_or(format!("{:?}", self.raid)) + } +} + +// pub struct + +#[cfg(test)] +mod test { + + use std::{any::Any, cell::UnsafeCell, convert::identity, sync::RwLock}; + + use crate::{ + bindings::{ + DeferredReflection, ReflectBase, ReflectBaseType, ReflectReference, ReflectionPathElem, + }, + bindings::{ReflectAllocation, ReflectAllocator}, + }; + + use super::*; + use bevy::{ + ecs::{component::Component, reflect::ReflectResource, system::Resource, world::World}, + reflect::TypeRegistryArc, + }; + + #[derive(Component, Reflect, PartialEq, Eq, Debug)] + #[reflect(Component)] + pub(crate) struct TestComponent { + pub strings: Vec, + } + + #[derive(Resource, Reflect, Default, PartialEq, Eq, Debug)] + #[reflect(Resource)] + pub(crate) struct TestResource { + pub bytes: Vec, + } + + pub(crate) fn setup_world( + init: F, + ) -> (World, ComponentId, ComponentId) { + let mut world = World::default(); + let allocator = ReflectAllocator::default(); + + let component_id = world.register_component::(); + let resource_id = world.init_resource::(); + + let mut type_registry = TypeRegistry::new(); + type_registry.register::(); + type_registry.register::(); + + init(&mut world, &mut type_registry); + + world.insert_resource(allocator); + + world.insert_resource(AppTypeRegistry(TypeRegistryArc { + internal: Arc::new(RwLock::new(type_registry)), + })); + + (world, component_id, resource_id) + } + + /// Tests that the given ref_ can be accessed and the value is as expected and access is released correctly (not for allocated values) + fn assert_access_yields< + O: Reflect + PartialEq + Debug, + F: FnOnce(&mut World, ComponentId, ComponentId) -> ReflectReference, + G: FnOnce(&WorldAccessGuard, ComponentId, ComponentId), + >( + init: F, + post_check: G, + expected: O, + ) { + let (mut world, component_id, resource_id) = setup_world(|_, _| {}); + let ref_ = init(&mut world, component_id, resource_id); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let world = world.read().unwrap(); + + // test read + world.with_resource(|world, allocator: Mut| { + world.with_resource(|world, type_registry: Mut| { + let type_registry = type_registry.read(); + ref_.with_reflect(world, &type_registry, Some(&allocator), |reflect| { + let orig = reflect.try_downcast_ref::(); + + let orig = match orig { + Some(v) => v, + None => { + panic!( + "Could not downcast value {reflect:?} to {}", + std::any::type_name::() + ) + } + }; + + assert_eq!(orig, &expected); + }) + }) + }); + + assert!( + world.get_component_access(component_id).is_some(), + "access to component was not release correctly" + ); + + assert!( + world.get_resource_access(resource_id).is_some(), + "access to component was not release correctly" + ); + + post_check(&world, component_id, resource_id); + }); + } + + /// Tests that setting to the expected value works as well as follow up reads give the expected value + fn assert_set_then_get_yields< + O: Reflect + PartialEq + Debug + Clone, + F: FnOnce(&mut World, ComponentId, ComponentId) -> ReflectReference, + G: FnOnce(&WorldAccessGuard, ComponentId, ComponentId), + >( + init: F, + post_check: G, + expected: O, + ) { + let (mut world, component_id, resource_id) = setup_world(|_, _| {}); + let ref_ = init(&mut world, component_id, resource_id); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let world = world.read().unwrap(); + // test set + world.with_resource(|world, allocator: Mut| { + world.with_resource(|world, type_registry: Mut| { + let type_registry = type_registry.read(); + ref_.with_reflect_mut(world, &type_registry, Some(&allocator), |reflect| { + let orig = reflect.try_downcast_mut::(); + + let orig = match orig { + Some(v) => v, + None => { + panic!( + "Could not downcast value {reflect:?} to {}", + std::any::type_name::() + ) + } + }; + + *orig = expected.clone(); + }) + }) + }); + + // test read + world.with_resource(|world, allocator: Mut| { + world.with_resource(|world, type_registry: Mut| { + let type_registry = type_registry.read(); + ref_.with_reflect(world, &type_registry, Some(&allocator), |reflect| { + let orig = reflect.try_downcast_ref::(); + + let orig = match orig { + Some(v) => v, + None => { + panic!( + "Could not downcast value {reflect:?} to {}", + std::any::type_name::() + ) + } + }; + + assert_eq!(orig, &expected); + }) + }) + }); + post_check(&world, component_id, resource_id); + }); + } + + #[test] + fn test_component_access() { + let init = |world: &mut World, component_id, _| { + let entity = world + .spawn(TestComponent { + strings: vec![String::from("initial")], + }) + .id(); + + ReflectReference { + base: ReflectBaseType { + base_id: ReflectBase::Component(entity, component_id), + type_id: TypeId::of::(), + }, + reflect_path: vec![ + ReflectionPathElem::Reflection(ParsedPath::parse_static(".strings").unwrap()), + ReflectionPathElem::DeferredReflection(DeferredReflection { + get: Arc::new(|root| { + let strings = root.try_downcast_ref::>().unwrap(); + Ok(strings.first().unwrap()) + }), + get_mut: Arc::new(|root| { + let strings = root.try_downcast_mut::>().unwrap(); + Ok(strings.first_mut().unwrap()) + }), + }), + ], + } + }; + + assert_access_yields(init, |_, _, _| {}, String::from("initial")); + assert_set_then_get_yields(init, |_, _, _| {}, String::from("set")); + } + + #[test] + fn test_resource_access() { + let init = |world: &mut World, _, resource_id| { + world.insert_resource(TestResource { bytes: vec![42u8] }); + + ReflectReference { + base: ReflectBaseType { + base_id: ReflectBase::Resource(resource_id), + type_id: TypeId::of::(), + }, + reflect_path: vec![ + ReflectionPathElem::Reflection(ParsedPath::parse_static(".bytes").unwrap()), + ReflectionPathElem::DeferredReflection(DeferredReflection { + get: Arc::new(|root| { + let strings = root.try_downcast_ref::>().unwrap(); + Ok(strings.first().unwrap()) + }), + get_mut: Arc::new(|root| { + let strings = root.try_downcast_mut::>().unwrap(); + Ok(strings.first_mut().unwrap()) + }), + }), + ], + } + }; + assert_access_yields(init, |_, _, _| {}, 42u8); + assert_set_then_get_yields(init, |_, _, _| {}, 69u8); + } + + #[test] + fn test_script_alloc_access() { + let init = |world: &mut World, _, _| { + let mut script_allocator = ReflectAllocator::default(); + let mut ref_ = ReflectReference::new_allocated( + TestComponent { + strings: vec![String::from("initial")], + }, + &mut script_allocator, + ); + ref_.index_path(ParsedPath::parse_static(".strings").unwrap()); + ref_.index_path(DeferredReflection { + get: Arc::new(|root| { + let strings = root.try_downcast_ref::>().unwrap(); + Ok(strings.first().unwrap()) + }), + get_mut: Arc::new(|root| { + let strings = root.try_downcast_mut::>().unwrap(); + Ok(strings.first_mut().unwrap()) + }), + }); + world.insert_resource(script_allocator); + ref_ + }; + let post_check = |world: &WorldAccessGuard, _, _| { + assert!( + world + .get_allocation_access(ReflectAllocationId(0)) + .is_some(), + "allocation access was not released correctly" + ); + }; + assert_access_yields(init, post_check, String::from("initial")); + assert_set_then_get_yields(init, post_check, String::from("set")); + } + + #[test] + #[allow(clippy::drop_non_drop)] + fn test_invalid_runtime_access() { + let mut world = World::new(); + let world = WorldAccessGuard::new(&mut world); + let access = world.get_component_access(ComponentId::new(0)); + assert!( + world.get_component_access(ComponentId::new(0)).is_none(), + "access was allowed to alias" + ); + drop(access); + } + + #[test] + #[should_panic] + fn test_double_release_panics() { + let mut world = World::new(); + let world = WorldAccessGuard::new(&mut world); + let access = world.get_component_access(ComponentId::new(0)).unwrap(); + world.release_access(access); + // This won't be possible in client code + world.release_access(WorldAccessWrite { + raid: ReflectAccessId { + kind: ReflectAccessKind::ComponentOrResource, + id: 0, + }, + _ph: PhantomData, + }); + } + + #[test] + fn test_count_updated_correctly() { + let mut world = World::new(); + let guard = WorldAccessGuard::new(&mut world); + let access = guard.get_access(ComponentId::new(0).into()).unwrap(); + assert_eq!(1, guard.accesses_count.load(Ordering::Relaxed)); + guard.release_access(access); + assert_eq!(0, guard.accesses_count.load(Ordering::Relaxed)); + } +} + +#[cfg(test)] +mod test_api { + use bevy::ecs::system::Commands; + use bevy::ecs::world::FromWorld; + use bevy::hierarchy::BuildChildren; + + use crate::bindings::ScriptTypeRegistration; + use crate::prelude::{ScriptErrorInner, ScriptErrorKind}; + + use super::test::{setup_world, TestComponent, TestResource}; + + use super::*; + + fn get_reg(world: &WorldCallbackAccess, name: &str) -> ScriptTypeRegistration { + world.get_type_by_name(name).expect("Type not found") + } + + fn test_comp_reg(world: &WorldCallbackAccess) -> ScriptTypeRegistration { + world + .get_type_by_name("TestComponent") + .expect("Component not found") + } + + fn test_resource_reg(world: &WorldCallbackAccess) -> ScriptTypeRegistration { + world + .get_type_by_name("TestResource") + .expect("Resource not found") + } + + #[test] + fn test_get_type_by_name() { + let (mut world, _, _) = setup_world(|_, _| {}); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_reg = world.get_type_by_name("TestComponent").unwrap(); + let resource_reg = world.get_type_by_name("TestResource").unwrap(); + + assert_eq!( + comp_reg.type_info().type_id(), + std::any::TypeId::of::() + ); + assert_eq!( + resource_reg.type_info().type_id(), + std::any::TypeId::of::() + ); + }); + } + + #[test] + fn test_get_type_by_name_invalid() { + let (mut world, _, _) = setup_world(|_, _| {}); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_reg = world.get_type_by_name("x"); + let resource_reg = world.get_type_by_name("z"); + + assert!(comp_reg.is_none()); + assert!(resource_reg.is_none()); + }); + } + + #[test] + fn test_add_default_component_from_world() { + #[derive(Reflect, Component, PartialEq, Debug)] + #[reflect(FromWorld, Component)] + struct CompWithFromWorld(pub String); + impl FromWorld for CompWithFromWorld { + fn from_world(_: &mut World) -> Self { + Self(String::from("FromWorld")) + } + } + + let (mut world, _, _) = setup_world(|w, r| { + w.register_component::(); + r.register::(); + }); + + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_reg = get_reg(world, "CompWithFromWorld"); + world.add_default_component(entity, comp_reg).unwrap() + }); + + assert_eq!( + world.get_entity(entity).unwrap().get::(), + Some(&CompWithFromWorld(String::from("FromWorld"))) + ); + } + + #[test] + fn test_add_default_component_default() { + #[derive(Reflect, Component, PartialEq, Debug)] + #[reflect(Default, Component)] + struct CompWithFromWorld(pub String); + + impl Default for CompWithFromWorld { + fn default() -> Self { + Self(String::from("Default")) + } + } + + let (mut world, _, _) = setup_world(|w, r| { + w.register_component::(); + r.register::(); + }); + + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_reg = get_reg(world, "CompWithFromWorld"); + world.add_default_component(entity, comp_reg).unwrap() + }); + + assert_eq!( + world.get_entity(entity).unwrap().get::(), + Some(&CompWithFromWorld(String::from("Default"))) + ); + } + + #[test] + fn test_add_default_component_missing_from_world_and_default() { + #[derive(Reflect, Component, PartialEq, Debug)] + #[reflect(Component)] + struct CompWithFromWorld(pub String); + + let (mut world, _, _) = setup_world(|w, r| { + w.register_component::(); + r.register::(); + }); + + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_reg = get_reg(world, "CompWithFromWorld"); + match world.add_default_component(entity, comp_reg.clone()) { + Ok(_) => { + panic!("Expected error") + } + Err(ScriptError(inner)) => { + assert_eq!(inner.kind, ScriptErrorKind::RuntimeError); + assert_eq!(inner.reason.to_string(), format!("Cannot add default component since type: `{}`, Does not have ReflectDefault or ReflectFromWorld data registered.", comp_reg.type_info().type_path())); + } + } + }); + } + + #[test] + fn test_add_default_component_missing_component_data() { + #[derive(Reflect, Component, PartialEq, Debug)] + #[reflect(Default)] + struct CompWithFromWorld(pub String); + + impl Default for CompWithFromWorld { + fn default() -> Self { + Self(String::from("Default")) + } + } + + let (mut world, _, _) = setup_world(|w, r| { + w.register_component::(); + r.register::(); + }); + + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_reg = get_reg(world, "CompWithFromWorld"); + match world.add_default_component(entity, comp_reg.clone()) { + Ok(_) => { + panic!("Expected error") + } + Err(ScriptError(inner)) => { + assert_eq!(inner.kind, ScriptErrorKind::RuntimeError); + assert_eq!(inner.reason.to_string(), format!("Cannot add default component since type: `{}`, Does not have ReflectComponent data registered.", comp_reg.type_info().type_path())); + } + } + }); + } + + #[test] + fn test_get_component_existing() { + let (mut world, comp_id, _) = setup_world(|_, _| {}); + let entity = world.spawn(TestComponent { strings: vec![] }).id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_ref = world.get_component(entity, comp_id).unwrap().unwrap(); + assert_eq!( + comp_ref, + ReflectReference { + base: ReflectBaseType { + type_id: std::any::TypeId::of::(), + base_id: ReflectBase::Component(entity, comp_id), + }, + reflect_path: Default::default(), + } + ); + }); + } + + #[test] + fn test_get_component_missing() { + let (mut world, comp_id, _) = setup_world(|_, _| {}); + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_ref = world.get_component(entity, comp_id).unwrap(); + assert_eq!(comp_ref, None); + }); + } + + #[test] + fn test_get_component_missing_entity() { + let (mut world, comp_id, _) = setup_world(|_, _| {}); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_ref = world.get_component(Entity::from_raw(0), comp_id); + match comp_ref { + Ok(_) => { + panic!("Expected error") + } + Err(e) => { + assert_eq!(e.kind, ScriptErrorKind::RuntimeError); + assert_eq!(e.reason.to_string(), "Entity does not exist: 0v1"); + } + } + }); + } + + #[test] + fn test_get_component_unregistered_component() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let entity = world.spawn_empty().id(); + let fake_id = ComponentId::new(999); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_ref = world.get_component(entity, fake_id); + match comp_ref { + Ok(_) => { + panic!("Expected error") + } + Err(e) => { + assert_eq!(e.kind, ScriptErrorKind::RuntimeError); + assert_eq!( + e.reason.to_string(), + format!("Component does not exist: {fake_id:?}"), + ); + } + } + }); + } + + #[test] + fn test_remove_component() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let entity = world + .spawn(TestComponent { + strings: vec![String::from("strings")], + }) + .id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world + .remove_component(entity, test_comp_reg(world)) + .unwrap(); + }); + + assert_eq!( + world.get_entity(entity).unwrap().get::(), + None + ); + } + + #[test] + fn test_remove_component_empty_idempotent() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world + .remove_component(entity, test_comp_reg(world)) + .unwrap(); + }); + + assert_eq!( + world.get_entity(entity).unwrap().get::(), + None + ); + } + + #[test] + fn test_remove_component_missing_comp_registration() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let result = world.remove_component(entity, test_resource_reg(world)); + match result { + Ok(_) => { + panic!("Expected error") + } + Err(e) => { + assert_eq!(e.kind, ScriptErrorKind::RuntimeError); + assert_eq!(e.reason.to_string(), format!("Cannot remove component since type: `{}`, Does not have ReflectComponent data registered.", test_resource_reg(world).type_info().type_path())); + } + } + }); + + assert_eq!( + world.get_entity(entity).unwrap().get::(), + None + ); + } + + #[test] + fn test_remove_component_missing_entity() { + let (mut world, _, _) = setup_world(|_, _| {}); + let fake_entity = Entity::from_raw(0); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let result = world.remove_component(fake_entity, test_comp_reg(world)); + match result { + Ok(_) => { + panic!("Expected error") + } + Err(e) => { + assert_eq!(e.kind, ScriptErrorKind::RuntimeError); + assert_eq!(e.reason.to_string(), "Entity does not exist: 0v1"); + } + } + }); + } + + #[test] + fn test_get_resource_existing() { + let (mut world, _, resource_id) = setup_world(|_, _| {}); + world.insert_resource(TestResource { bytes: vec![1] }); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_ref = world.get_resource(resource_id).unwrap(); + assert_eq!( + comp_ref, + ReflectReference { + base: ReflectBaseType { + type_id: std::any::TypeId::of::(), + base_id: ReflectBase::Resource(resource_id), + }, + reflect_path: Default::default(), + } + ); + }); + } + + #[test] + fn test_get_resource_non_existing() { + let (mut world, _, _) = setup_world(|_, _| {}); + let fake_comp = ComponentId::new(999); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let comp_ref = world.get_resource(fake_comp); + match comp_ref { + Ok(_) => panic!("Expected error"), + Err(e) => { + assert_eq!(e.kind, ScriptErrorKind::RuntimeError); + assert_eq!( + e.reason.to_string(), + format!("Resource does not exist: {fake_comp:?}") + ) + } + } + }); + } + + #[test] + fn test_remove_resource() { + let (mut world, _, _) = setup_world(|_, _| {}); + + world.insert_resource(TestResource { bytes: vec![1] }); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.remove_resource(test_resource_reg(world)).unwrap(); + }); + + assert_eq!(world.get_resource::(), None); + } + + #[test] + fn test_remove_resource_missing_idempotent() { + let (mut world, _, _) = setup_world(|_, _| {}); + + world.remove_resource::(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.remove_resource(test_resource_reg(world)).unwrap(); + }); + + assert_eq!(world.get_resource::(), None); + } + + #[test] + fn test_remove_resource_missing_resource_registration() { + let (mut world, _, _) = setup_world(|_, _| {}); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + match world.remove_resource(test_comp_reg(world)) { + Ok(_) => panic!("Expected error"), + Err(e) => { + assert_eq!(e.kind, ScriptErrorKind::RuntimeError); + assert_eq!(e.reason.to_string(), format!("Cannot remove resource since type: `{}`, Does not have ReflectResource data registered.", test_comp_reg(world).type_info().type_path())); + } + } + }); + } + + #[test] + fn test_has_resource_existing() { + let (mut world, _, res_reg) = setup_world(|_, _| {}); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + assert!(world.has_resource(res_reg)); + }); + } + + #[test] + fn test_has_resource_missing() { + let (mut world, _, res_reg) = setup_world(|_, _| {}); + + world.remove_resource::(); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + assert!(world.has_resource(res_reg)); + }); + } + + #[test] + fn test_get_children_1_child() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).add_children(&[child]); + cmnds.apply(&mut world); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let children = world.get_children(parent).unwrap(); + assert_eq!(children.len(), 1); + assert_eq!(children[0], child); + }); + } + + #[test] + #[should_panic( + expected = "Component not registered: `bevy_hierarchy::components::children::Children`" + )] + fn test_get_children_children_component_unregistered() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.get_children(parent).unwrap(); + }); + } + + #[test] + fn test_get_children_no_children() { + let (mut world, _, _) = setup_world(|_, _| {}); + + world.register_component::(); + let parent = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let children = world.get_children(parent).unwrap(); + assert_eq!(children.len(), 0); + }); + } + + #[test] + fn test_get_parent_1_parent() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).add_children(&[child]); + cmnds.apply(&mut world); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let found_parent = world.get_parent(child).unwrap(); + assert_eq!(found_parent, Some(parent)); + }); + } + + #[test] + fn test_get_parent_no_parent() { + let (mut world, _, _) = setup_world(|_, _| {}); + world.register_component::(); + + let child = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + let found_parent = world.get_parent(child).unwrap(); + assert_eq!(found_parent, None); + }); + } + + #[test] + #[should_panic( + expected = "Component not registered: `bevy_hierarchy::components::parent::Parent`" + )] + fn test_get_parent_parent_component_unregistered() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let child = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.get_parent(child).unwrap(); + }); + } + + #[test] + fn test_push_children_empty_entity() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.push_children(parent, &[child]).unwrap(); + }); + + let children = world.get::(parent).unwrap(); + assert_eq!(children.len(), 1); + assert_eq!(children[0], child); + } + + #[test] + fn test_push_children_entity_with_1_child() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).add_children(&[child]); + cmnds.apply(&mut world); + + let child_2 = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.push_children(parent, &[child_2]).unwrap(); + }); + + let children = world.get::(parent).unwrap(); + assert_eq!(children.len(), 2); + assert_eq!(children[0], child); + assert_eq!(children[1], child_2); + } + + #[test] + fn test_remove_children_entity_with_1_child() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).add_children(&[child]); + cmnds.apply(&mut world); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.remove_children(parent, &[child]).unwrap(); + }); + + let children = world.get::(parent); + assert!(children.is_none()); + } + + #[test] + fn test_remove_children_remove_half_children() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let child_2 = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).add_children(&[child, child_2]); + cmnds.apply(&mut world); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.remove_children(parent, &[child]).unwrap(); + }); + + let children = world.get::(parent).unwrap(); + assert_eq!(children.len(), 1); + assert_eq!(children[0], child_2); + } + + #[test] + fn test_insert_children_empty() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.insert_children(parent, 0, &[child]).unwrap(); + }); + + let children = world.get::(parent).unwrap(); + assert_eq!(children.len(), 1); + assert_eq!(children[0], child); + } + + #[test] + fn test_insert_children_middle() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let child_2 = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).add_children(&[child, child_2]); + cmnds.apply(&mut world); + + let child_to_insert = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world + .insert_children(parent, 1, &[child_to_insert]) + .unwrap(); + }); + + let children = world.get::(parent).unwrap(); + assert_eq!(children.len(), 3); + assert_eq!(children[0], child); + assert_eq!(children[1], child_to_insert); + assert_eq!(children[2], child_2); + } + + #[test] + fn test_despawn_entity() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let entity = world.spawn_empty().id(); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.despawn(entity).unwrap(); + }); + + assert!(world.get_entity(entity).is_err()); + } + + #[test] + fn test_despawn_recursive() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).add_children(&[child]); + cmnds.apply(&mut world); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.despawn_recursive(parent).unwrap(); + }); + + assert!(world.get_entity(parent).is_err()); + assert!(world.get_entity(child).is_err()); + } + + #[test] + fn test_despawn_descendants() { + let (mut world, _, _) = setup_world(|_, _| {}); + + let parent = world.spawn_empty().id(); + let child = world.spawn_empty().id(); + let mut cmnds = CommandQueue::default(); + let mut cmnd = Commands::new(&mut cmnds, &world); + cmnd.entity(parent).add_children(&[child]); + cmnds.apply(&mut world); + + WorldCallbackAccess::with_callback_access(&mut world, |world| { + world.despawn_descendants(parent).unwrap(); + }); + + assert!(world.get_entity(parent).is_ok()); + assert!(world.get_entity(child).is_err()); + } +} diff --git a/crates/bevy_mod_scripting_core/src/commands.rs b/crates/bevy_mod_scripting_core/src/commands.rs new file mode 100644 index 0000000000..d2b3618445 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/commands.rs @@ -0,0 +1,142 @@ +use std::marker::PhantomData; + +use bevy::{asset::Handle, ecs::world::Mut, log::debug, prelude::Command}; + +use crate::{ + asset::ScriptAsset, + context::{Context, ContextLoadingSettings, ScriptContexts}, + prelude::{Runtime, RuntimeContainer}, + script::{Script, ScriptId, Scripts}, +}; + +pub struct DeleteScript { + pub id: ScriptId, + // hack to make this Send, C does not need to be Send since it is not stored in the command + pub _ph: PhantomData, +} + +impl DeleteScript { + pub fn new(id: ScriptId) -> Self { + Self { + id, + _ph: PhantomData, + } + } +} + +impl Command for DeleteScript { + fn apply(self, world: &mut bevy::prelude::World) { + let settings = world + .get_resource::>() + .expect("No ScriptLoadingSettings resource found") + .clone(); + + world.resource_scope(|world, mut scripts: Mut| { + if let Some(script) = scripts.scripts.remove(&self.id) { + debug!("Deleting script with id: {}", self.id); + let mut ctxts = world.get_non_send_resource_mut::>(); + let ctxts = ctxts.as_deref_mut().unwrap(); + let assigner = settings + .assigner + .as_ref() + .expect("Could not find context assigner in settings"); + debug!("Removing script with id: {}", self.id); + (assigner.remove)(script.context_id, &script, ctxts) + } else { + bevy::log::error!( + "Attempted to delete script with id: {} but it does not exist, doing nothing!", + self.id + ); + } + }); + + world.insert_resource(settings); + } +} + +/// Creates new script with the given ID, if a script with the given ID already exists, this is treated as an update +/// +/// If script comes from an asset, expects it to be loaded, otherwise this command will fail to process the script. +pub struct CreateOrUpdateScript { + id: ScriptId, + content: Box<[u8]>, + asset: Option>, + // Hack to make this Send, C does not need to be Send since it is not stored in the command + _ph: std::marker::PhantomData, +} + +impl CreateOrUpdateScript { + pub fn new(id: ScriptId, content: Box<[u8]>, asset: Option>) -> Self { + Self { + id, + content, + asset, + _ph: std::marker::PhantomData, + } + } +} + +impl Command for CreateOrUpdateScript { + fn apply(self, world: &mut bevy::prelude::World) { + let settings = world + .get_resource::>() + .unwrap() + .clone(); + let mut contexts = world + .remove_non_send_resource::>() + .unwrap(); + let mut runtime = world + .remove_non_send_resource::>() + .unwrap(); + // assign context + let assigner = settings.assigner.clone().expect("No context assigner set"); + let builder = settings.loader.clone().expect("No context loader set"); + + world.resource_scope(|world, mut scripts: Mut| { + + // check if script already exists + + let mut script = scripts.scripts.get_mut(&self.id); + let previous_context_id = script.as_ref().map(|s| s.context_id); + debug!( + "CreateOrUpdateScript command applying with to (script_id: {}, previous_context_id: {:?})", + self.id, previous_context_id + ); + + // If None assign new context ID, otherwise assign the old one + // If re-loading and different from the previous one, the old one will be removed + let current_context_id = (assigner.assign)(script.as_deref(), &self.id, &self.content, &mut contexts); + let current_context_id = if let Some(id) = current_context_id { + id + } else { + let ctxt = (builder.load)(&self.id, &self.content, &settings.context_initializers, &settings.context_pre_handling_initializers, world, runtime.runtime.as_mut().unwrap()).unwrap(); + contexts.insert(ctxt) + }; + + if let Some(previous) = previous_context_id { + if previous != current_context_id { + debug!( + "Script is being moved to a new context with id: {}, removing up old context.", + current_context_id + ); + script.as_deref_mut().unwrap().context_id = current_context_id; + (assigner.remove)(previous, script.unwrap(), &mut contexts); + } + } + + + // now we can insert the actual script + scripts.scripts.insert( + self.id.clone(), + Script { + id: self.id, + asset: self.asset, + context_id: current_context_id, + }, + ); + }); + world.insert_resource(settings); + world.insert_non_send_resource(runtime); + world.insert_non_send_resource(contexts); + } +} diff --git a/crates/bevy_mod_scripting_core/src/context.rs b/crates/bevy_mod_scripting_core/src/context.rs new file mode 100644 index 0000000000..169cd831da --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/context.rs @@ -0,0 +1,152 @@ +use std::{collections::HashMap, sync::atomic::AtomicU32}; + +use bevy::ecs::{entity::Entity, system::Resource, world::World}; + +use crate::{ + prelude::{Runtime, ScriptError}, + script::{Script, ScriptId}, +}; + +pub trait Context: 'static {} +impl Context for T {} + +pub type ContextId = u32; + +#[derive(Resource)] +pub struct ScriptContexts { + pub(crate) contexts: HashMap, +} + +impl Default for ScriptContexts { + fn default() -> Self { + Self { + contexts: Default::default(), + } + } +} + +static CONTEXT_ID_COUNTER: AtomicU32 = AtomicU32::new(0); +impl ScriptContexts { + pub fn new() -> Self { + Self { + contexts: HashMap::new(), + } + } + + /// Allocates a new ContextId and inserts the context into the map + pub fn insert(&mut self, ctxt: T) -> ContextId { + let id = CONTEXT_ID_COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + self.contexts.insert(id, ctxt); + id + } + + /// Allocate new context id without inserting a context + pub fn allocate_id(&self) -> ContextId { + CONTEXT_ID_COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + } + + pub fn remove(&mut self, id: ContextId) -> Option { + self.contexts.remove(&id) + } +} + +/// Initializer run once after creating a context but before executing it for the first time +pub type ContextInitializer = fn(&ScriptId, &mut C) -> Result<(), ScriptError>; +/// Initializer run every time before executing or loading a script +pub type ContextPreHandlingInitializer = + fn(&ScriptId, Entity, &mut C) -> Result<(), ScriptError>; + +#[derive(Resource)] +pub struct ContextLoadingSettings { + pub loader: Option>, + pub assigner: Option>, + pub context_initializers: Vec>, + pub context_pre_handling_initializers: Vec>, +} + +impl Default for ContextLoadingSettings { + fn default() -> Self { + Self { + loader: None, + assigner: None, + context_initializers: Default::default(), + context_pre_handling_initializers: Default::default(), + } + } +} + +impl Clone for ContextLoadingSettings { + fn clone(&self) -> Self { + Self { + loader: self.loader.clone(), + assigner: self.assigner.clone(), + context_initializers: self.context_initializers.clone(), + context_pre_handling_initializers: self.context_pre_handling_initializers.clone(), + } + } +} + +/// A strategy for loading and reloading contexts +pub struct ContextBuilder { + pub load: fn( + script: &ScriptId, + content: &[u8], + &[ContextInitializer], + &[ContextPreHandlingInitializer], + &mut World, + runtime: &mut R, + ) -> Result, + pub reload: fn( + script: &ScriptId, + new_content: &[u8], + context: &mut C, + &[ContextInitializer], + &[ContextPreHandlingInitializer], + &mut World, + &mut R, + ) -> Result<(), ScriptError>, +} + +impl Clone for ContextBuilder { + fn clone(&self) -> Self { + Self { + load: self.load, + reload: self.reload, + } + } +} + +/// A strategy for assigning contexts to new and existing but re-loaded scripts as well as for managing old contexts +pub struct ContextAssigner { + /// Assign a context to the script, if script is `None`, this is a new script, otherwise it is an existing script with a context inside `contexts`. + /// Returning None means the script should be assigned a new context + pub assign: fn( + old_script: Option<&Script>, + script_id: &ScriptId, + new_content: &[u8], + contexts: &ScriptContexts, + ) -> Option, + + /// Handle the removal of the script, if any clean up in contexts is necessary perform it here. + /// This will also be called, when a script is assigned a contextId on reload different from the previous one + /// the context_id in that case will be the old context_id and the one stored in the script will be the old one + pub remove: fn(context_id: ContextId, script: &Script, contexts: &mut ScriptContexts), +} + +impl Default for ContextAssigner { + fn default() -> Self { + Self { + assign: |_, _, _, c| Some(c.allocate_id()), + remove: |id, _, c| _ = c.remove(id), + } + } +} + +impl Clone for ContextAssigner { + fn clone(&self) -> Self { + Self { + assign: self.assign, + remove: self.remove, + } + } +} diff --git a/crates/bevy_mod_scripting_core/src/docs.rs b/crates/bevy_mod_scripting_core/src/docs.rs index 8a2a2dfd3d..d186bcfe96 100644 --- a/crates/bevy_mod_scripting_core/src/docs.rs +++ b/crates/bevy_mod_scripting_core/src/docs.rs @@ -1,10 +1,24 @@ -use crate::error::ScriptError; +use bevy::ecs::system::Resource; -/// A documentation piece exported by an `APIProvider` -pub trait DocFragment: 'static { +/// A documentation piece which can be used to make a piece of documentation, most often a module. +pub trait DocumentationFragment: 'static + Sized { + /// Merges two documentation fragments into one, retaining the title of the first fragment. fn merge(self, o: Self) -> Self; - fn gen_docs(self) -> Result<(), ScriptError>; + fn gen_docs(self) -> Result<(), Box>; /// Retrieves the name of the documentation fragment, most likely the name of your game! fn name(&self) -> &'static str; } + +#[derive(Resource)] +pub struct Documentation { + pub fragments: Vec, +} + +impl Default for Documentation { + fn default() -> Self { + Self { + fragments: Default::default(), + } + } +} diff --git a/crates/bevy_mod_scripting_core/src/error.rs b/crates/bevy_mod_scripting_core/src/error.rs index 3f0dd2be2b..ad1113489a 100644 --- a/crates/bevy_mod_scripting_core/src/error.rs +++ b/crates/bevy_mod_scripting_core/src/error.rs @@ -1,30 +1,181 @@ +use std::{ + ops::{Deref, DerefMut}, + sync::Arc, +}; + +use bevy::reflect::Reflect; use thiserror::Error; -#[derive(Error, Debug, Clone)] -pub enum ScriptError { - #[error("Runtime error in script `{script}` {msg}")] - RuntimeError { script: String, msg: String }, - #[error("Failed to load script asset for `{script}` {msg}")] - FailedToLoad { script: String, msg: String }, - #[error("Syntax error for script `{script}` {msg}")] - SyntaxError { script: String, msg: String }, - #[error("Callback method `{callback}` invalid for script `{script}` {msg}")] - InvalidCallback { - script: String, - callback: String, - msg: String, - }, - #[error("Failed to attach API for script `{script}` {msg}")] - FailedToAttachAPI { script: String, msg: String }, - #[error("Failed to generate documentation `{0}`")] - DocGenError(String), - #[error("{0}")] - Other(String), +use crate::{bindings::ReflectAllocationId, bindings::ReflectReference}; + +pub type ScriptResult = Result; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum ScriptErrorKind { + /// Any other error, default for script errors generated via Into conversions + Other, + /// Errors specifically to do with reflecting & reading/writing stuff from the world + ReflectionError, + /// Erorrs to do with invalid script API usage, invalid arguments etc. + RuntimeError, + /// Errors to do with the script lifecycle, loading, unloading etc. + Lifecycle, +} + +impl std::fmt::Display for ScriptErrorKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + ScriptErrorKind::ReflectionError => f.write_str("Reflection Error"), + ScriptErrorKind::Lifecycle => f.write_str("Script Lifecycle Error"), + ScriptErrorKind::Other => f.write_str("Error"), + ScriptErrorKind::RuntimeError => f.write_str("Runtime Error"), + }; + Ok(()) + } +} + +#[derive(Error, Debug)] +pub struct ScriptErrorWrapper(ScriptError); + +impl std::fmt::Display for ScriptErrorWrapper { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } +} + +impl From for Box { + fn from(val: ScriptError) -> Self { + ScriptErrorWrapper(val).into() + } +} +/// An error with an optional script Context +#[derive(Debug, Clone)] +pub struct ScriptError(pub Arc); + +impl Deref for ScriptError { + type Target = ScriptErrorInner; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +/// The innards are separated to reduce the size of this error +#[derive(Debug)] +pub struct ScriptErrorInner { + pub script: Option, + pub kind: ScriptErrorKind, + pub context: String, + pub reason: Arc, } impl ScriptError { - /// Create new `ScriptError::Other` from another error - pub fn new_other(other: T) -> Self { - Self::Other(other.to_string()) + pub fn new_reflection_error>>( + reason: E, + ) -> Self { + Self(Arc::new(ScriptErrorInner { + script: None, + kind: ScriptErrorKind::ReflectionError, + reason: Arc::from(reason.into()), + context: Default::default(), + })) + } + + pub fn new_generic_error>>(reason: E) -> Self { + Self(Arc::new(ScriptErrorInner { + script: None, + kind: ScriptErrorKind::Other, + reason: Arc::from(reason.into()), + context: Default::default(), + })) + } + + pub fn new_lifecycle_error>>( + reason: E, + ) -> Self { + Self(Arc::new(ScriptErrorInner { + script: None, + kind: ScriptErrorKind::Lifecycle, + reason: Arc::from(reason.into()), + context: Default::default(), + })) + } + + pub fn new_runtime_error>>(reason: E) -> Self { + Self(Arc::new(ScriptErrorInner { + script: None, + kind: ScriptErrorKind::RuntimeError, + reason: Arc::from(reason.into()), + context: Default::default(), + })) + } + + pub fn with_context(self, context: S) -> Self { + Self(Arc::new(ScriptErrorInner { + script: self.0.script.clone(), + kind: self.0.kind.clone(), + context: context.to_string(), + reason: self.0.reason.clone(), + })) } } + +impl From for ScriptError { + fn from(value: T) -> Self { + Self::new_generic_error(value) + } +} + +impl std::fmt::Display for ScriptError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + if let Some(script) = &self.0.script { + write!( + f, + "Encountered {} error in script `{}`: {}", + self.0.kind, script, self.0.reason + ) + } else { + write!( + f, + "Encountered {} error in a script: {}", + self.0.kind, self.0.reason + ) + } + } +} + +// #[derive(Error, Debug, Clone)] +// pub enum ReflectionError { +// #[error("Base reference `{base}` is invalid. {reason}")] +// InvalidBaseReference { base: String, reason: String }, +// #[error("Cannot safely access `{base}`. {reason}")] +// InsufficientAccess { base: String, reason: String }, +// #[error("Tried to access `{base:?}` with insufficient provenance. {reason}")] +// InsufficientProvenance { +// base: ReflectReference, +// reason: String, +// }, +// #[error("Cannot downcast reference: {reference:?} to: {to}")] +// CannotDowncast { +// reference: ReflectReference, +// to: String, +// }, +// #[error("Could not assign `{rhs}` to `{lhs:?}`. {reason}")] +// InvalidAssignment { +// lhs: ReflectReference, +// rhs: String, +// reason: String, +// }, +// #[error("Failed to build concrete type from &Reflect type: `{ref_}`. Does this type have a FromReflect type data?")] +// FromReflectFailure { ref_: String }, +// #[error("Could not dereference script allocation with ID: {id}. {reason}")] +// AllocationError { +// id: ReflectAllocationId, +// reason: String, +// }, +// #[error("Attempted to access world via stale world reference. Did you store a reference to a world across a frame boundary?")] +// StaleWorldAccess, + +// #[error("{0}")] +// Other(String), +// } diff --git a/crates/bevy_mod_scripting_core/src/event.rs b/crates/bevy_mod_scripting_core/src/event.rs index 7ba3470709..2921d19c58 100644 --- a/crates/bevy_mod_scripting_core/src/event.rs +++ b/crates/bevy_mod_scripting_core/src/event.rs @@ -1,6 +1,6 @@ -use bevy::prelude::Event; +use bevy::{ecs::entity::Entity, prelude::Event}; -use crate::{error::ScriptError, hosts::Recipients}; +use crate::{error::ScriptError, handler::Args, script::ScriptId}; /// An error coming from a script #[derive(Debug, Event)] @@ -8,15 +8,235 @@ pub struct ScriptErrorEvent { pub error: ScriptError, } -/// An event emitted when a script was loaded or re-loaded (with a hot-reload), -/// guaranteed to be sent for every script at least once and immediately after it's loaded. -#[derive(Clone, Debug, Event)] -pub struct ScriptLoaded { - pub sid: u32, +/// A string which disallows common invalid characters in callback labels, +/// particularly at the start of the string +/// +/// a valid callback label starts with a letter or underscore, and contains only ascii characters, as well as disallows some common keywords +#[derive(Clone, PartialEq, Eq, Hash, Debug)] +pub struct CallbackLabel(String); + +impl CallbackLabel { + fn filter_invalid(s: &str) -> String { + let mut out = String::with_capacity(s.len()); + let mut first = true; + for char in s.chars() { + if char == '_' + || ((!first && char.is_ascii_alphanumeric()) || char.is_ascii_alphabetic()) + { + out.push(char); + first = false; + } else { + continue; + } + } + if FORBIDDEN_KEYWORDS.contains(&s) { + String::default() + } else { + out + } + } + + pub fn new_lossy(label: &str) -> Self { + Self(Self::filter_invalid(label)) + } + + pub fn new(label: &str) -> Option { + let new_lossy = Self::new_lossy(label); + if new_lossy.0.len() != label.len() { + None + } else { + Some(new_lossy) + } + } +} + +pub trait IntoCallbackLabel { + fn into_callback_label() -> CallbackLabel; +} + +impl From<&str> for CallbackLabel { + fn from(s: &str) -> Self { + Self::new_lossy(s) + } +} +impl From for CallbackLabel { + fn from(s: String) -> Self { + Self::from(s.as_str()) + } +} + +impl AsRef for CallbackLabel { + fn as_ref(&self) -> &str { + &self.0 + } +} + +impl std::fmt::Display for CallbackLabel { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.as_ref()) + } } -/// A trait for events to be handled by scripts -pub trait ScriptEvent: Send + Sync + Clone + Event + 'static { - /// Retrieves the recipient scripts for this event - fn recipients(&self) -> &Recipients; +/// Describes the designated recipients of a script event +#[derive(Clone, Debug)] +pub enum Recipients { + /// The event needs to be handled by all scripts + All, + /// The event is to be handled by a specific script + Script(ScriptId), + /// The event is to be handled by all the scripts on the specified entity + Entity(Entity), +} + +/// A callback event meant to trigger a callback in a subset/set of scripts in the world with the given arguments +#[derive(Clone, Event, Debug)] +pub struct ScriptCallbackEvent { + pub label: CallbackLabel, + pub recipients: Recipients, + pub args: A, +} + +impl ScriptCallbackEvent { + pub fn new>(label: L, args: A, recipients: Recipients) -> Self { + Self { + label: label.into(), + args, + recipients, + } + } + + pub fn new_for_all>(label: L, args: A) -> Self { + Self::new(label, args, Recipients::All) + } +} + +static FORBIDDEN_KEYWORDS: [&str; 82] = [ + // Lua + "and", + "break", + "do", + "else", + "elseif", + "end", + "false", + "for", + "function", + "if", + "in", + "local", + "nil", + "not", + "or", + "repeat", + "return", + "then", + "true", + "until", + "while", + // Rhai + "true", + "false", + "let", + "const", + "is_shared", + "if", + "else", + "switch", + "do", + "while", + "loop", + "until", + "for", + "in", + "continue", + "break", + "fn", + "private", + "is_def_fn", + "this", + "return", + "throw", + "try", + "catch", + "import", + "export", + "as", + "global", + "Fn", + "call", + "curry", + "type_of", + "print", + "debug", + "eval", + "is_def_var", + "var", + "static", + "is", + "goto", + "match", + "case", + "public", + "protected", + "new", + "use", + "with", + "module", + "package", + "super", + "spawn", + "thread", + "go", + "sync", + "async", + "await", + "yield", + "default", + "void", + "null", + "nil", +]; + +#[cfg(test)] +mod test { + use super::FORBIDDEN_KEYWORDS; + + #[test] + fn test_invalid_strings() { + FORBIDDEN_KEYWORDS.iter().for_each(|keyword| { + assert_eq!(super::CallbackLabel::new(keyword), None); + }); + } + + #[test] + fn test_bad_chars() { + let bad_chars = [ + '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '=', '{', '}', '[', ']', + '|', '\\', ':', ';', '"', '\'', '<', '>', ',', '.', '?', '/', '`', '~', + ]; + bad_chars.iter().for_each(|char| { + assert_eq!(super::CallbackLabel::new(&format!("bad{}", char)), None); + }); + } + + #[test] + fn bad_first_letter() { + let bad_chars = [ + '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '@', '#', '$', '%', '^', '&', '*', + '(', ')', '-', '+', '=', '{', '}', '[', ']', '|', '\\', ':', ';', '"', '\'', '<', '>', + ',', '.', '?', '/', '`', '~', + ]; + bad_chars.iter().for_each(|char| { + assert_eq!(super::CallbackLabel::new(&format!("{}bad", char)), None); + }); + } + + #[test] + fn test_valid_idents() { + let valid = ["h", "_v", "hello", "_2d", "heloo_2", "_1231412"]; + valid.iter().for_each(|ident| { + assert!(super::CallbackLabel::new(ident).is_some()); + assert_eq!(super::CallbackLabel::new_lossy(ident).as_ref(), *ident); + }); + } } diff --git a/crates/bevy_mod_scripting_core/src/handler.rs b/crates/bevy_mod_scripting_core/src/handler.rs new file mode 100644 index 0000000000..63bc1e0819 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/handler.rs @@ -0,0 +1,37 @@ +use bevy::ecs::{entity::Entity, system::Resource, world::World}; + +use crate::{ + context::{Context, ContextPreHandlingInitializer}, + event::CallbackLabel, + prelude::ScriptError, + runtime::Runtime, + script::ScriptId, +}; + +pub trait Args: Clone + Send + Sync + 'static {} +impl Args for T {} + +pub type HandlerFn = fn( + args: A, + entity: Entity, + script_id: &ScriptId, + callback: &CallbackLabel, + context: &mut C, + pre_handling_initializers: &[ContextPreHandlingInitializer], + runtime: &mut R, + world: &mut World, +) -> Result<(), ScriptError>; + +/// A resource that holds the settings for the callback handler for a specific combination of type parameters +#[derive(Resource)] +pub struct CallbackSettings { + pub callback_handler: Option>, +} + +impl Default for CallbackSettings { + fn default() -> Self { + Self { + callback_handler: None, + } + } +} diff --git a/crates/bevy_mod_scripting_core/src/lib.rs b/crates/bevy_mod_scripting_core/src/lib.rs index 2022dad31b..92ed2a219f 100644 --- a/crates/bevy_mod_scripting_core/src/lib.rs +++ b/crates/bevy_mod_scripting_core/src/lib.rs @@ -1,211 +1,182 @@ -use crate::{ - event::ScriptErrorEvent, - hosts::{APIProvider, APIProviders, ScriptHost}, +#![allow(clippy::arc_with_non_send_sync)] + +use crate::event::ScriptErrorEvent; +use asset::{ScriptAsset, ScriptAssetLoader, ScriptAssetSettings}; +use bevy::prelude::*; +use bindings::ReflectAllocator; +use context::{ + Context, ContextAssigner, ContextBuilder, ContextInitializer, ContextLoadingSettings, + ContextPreHandlingInitializer, ScriptContexts, }; -use bevy::{ecs::schedule::ScheduleLabel, prelude::*}; -use event::ScriptLoaded; -use systems::script_event_handler; +use handler::{Args, CallbackSettings, HandlerFn}; +use prelude::{ + initialize_runtime, + runtime::{RuntimeInitializer, RuntimeSettings}, + sync_script_data, Documentation, DocumentationFragment, ScriptCallbackEvent, +}; +use runtime::{Runtime, RuntimeContainer}; +use script::Scripts; +use systems::garbage_collector; pub mod asset; +pub mod bindings; +pub mod commands; +pub mod context; pub mod docs; pub mod error; pub mod event; -pub mod hosts; +pub mod handler; +pub mod runtime; +pub mod script; pub mod systems; pub mod world; pub mod prelude { - // general - pub use { - crate::asset::CodeAsset, - crate::docs::DocFragment, - crate::error::ScriptError, - crate::event::{ScriptErrorEvent, ScriptEvent}, - crate::hosts::{ - APIProvider, APIProviders, Recipients, Script, ScriptCollection, ScriptContexts, - ScriptData, ScriptHost, - }, - crate::systems::script_event_handler, - crate::{ - AddScriptApiProvider, AddScriptHost, AddScriptHostHandler, GenDocumentation, - ScriptingPlugin, - }, - bevy_event_priority::{ - AddPriorityEvent, PriorityEvent, PriorityEventReader, PriorityEventWriter, - PriorityEvents, PriorityIterator, - }, - }; + pub use {crate::docs::*, crate::error::*, crate::event::*, crate::systems::*, crate::*}; } -pub use bevy_event_priority as events; #[derive(Default)] -/// Bevy plugin enabling run-time scripting -pub struct ScriptingPlugin; +/// Bevy plugin enabling scripting within the bevy mod scripting framework +pub struct ScriptingPlugin { + /// Callback for initiating the runtime + pub runtime_builder: Option R>, + /// The handler used for executing callbacks in scripts + pub callback_handler: Option>, + /// The context builder for loading contexts + pub context_builder: Option>, + /// The context assigner for assigning contexts to scripts, if not provided default strategy of keeping each script in its own context is used + pub context_assigner: Option>, +} -impl Plugin for ScriptingPlugin { +impl Plugin for ScriptingPlugin { fn build(&self, app: &mut bevy::prelude::App) { - app.add_event::(); + app.add_event::() + .add_event::>() + .init_resource::() + .init_resource::() + .init_resource::() + .init_asset::() + .register_asset_loader(ScriptAssetLoader { + language: "<>".into(), + extensions: &[], + preprocessor: None, + }) + // not every script host will have a runtime, for convenience we add a dummy runtime + .insert_non_send_resource::>(RuntimeContainer { + runtime: self.runtime_builder.map(|f| f()), + }) + .init_non_send_resource::>() + .init_non_send_resource::>() + .insert_resource::>(CallbackSettings { + callback_handler: self.callback_handler, + }) + .insert_resource::>(ContextLoadingSettings { + loader: self.context_builder.clone(), + assigner: Some(self.context_assigner.clone().unwrap_or_default()), + context_initializers: vec![], + context_pre_handling_initializers: vec![], + }) + .add_systems(PostUpdate, (garbage_collector, sync_script_data::)) + .add_systems(PostStartup, initialize_runtime::); } } -pub trait GenDocumentation { - fn update_documentation(&mut self) -> &mut Self; +pub trait AddRuntimeInitializer { + fn add_runtime_initializer(&mut self, initializer: RuntimeInitializer) -> &mut Self; } -impl GenDocumentation for App { - /// Updates/Generates documentation and any other artifacts required for script API's. Disabled in optimized builds unless `doc_always` feature is enabled. - fn update_documentation(&mut self) -> &mut Self { - #[cfg(any(debug_assertions, feature = "doc_always"))] - { - info!("Generating documentation"); - let w = &mut self.world_mut(); - let providers: &APIProviders = w.resource(); - if let Err(e) = providers.gen_all() { - error!("{}", e); - } - info!("Documentation generated"); - } - +impl AddRuntimeInitializer for App { + fn add_runtime_initializer(&mut self, initializer: RuntimeInitializer) -> &mut Self { + self.world_mut().init_resource::>(); + self.world_mut() + .resource_mut::>() + .as_mut() + .initializers + .push(initializer); self } } -/// Trait for app builder notation -pub trait AddScriptHost { - /// registers the given script host with your app, - /// the given system set will contain systems handling script loading, re-loading, removal etc. - /// This system set will also send events related to the script lifecycle. - /// - /// Note: any systems which need to run the same frame a script is loaded must run after this set. - fn add_script_host(&mut self, schedule: impl ScheduleLabel) -> &mut Self; - - /// Similar to `add_script_host` but allows you to specify a system set to add the script host to. - fn add_script_host_to_set( +pub trait AddContextInitializer { + fn add_context_initializer( &mut self, - schedule: impl ScheduleLabel, - set: impl SystemSet, + initializer: ContextInitializer, ) -> &mut Self; } -impl AddScriptHost for App { - fn add_script_host_to_set( +impl AddContextInitializer for App { + fn add_context_initializer( &mut self, - schedule: impl ScheduleLabel, - set: impl SystemSet, - ) -> &mut Self - where - T: ScriptHost, - { - T::register_with_app_in_set(self, schedule, set); - self.init_resource::(); - self.add_event::(); - self - } - - fn add_script_host(&mut self, schedule: impl ScheduleLabel) -> &mut Self - where - T: ScriptHost, - { - T::register_with_app(self, schedule); - self.init_resource::(); - self.add_event::(); + initializer: ContextInitializer, + ) -> &mut Self { + self.world_mut() + .init_resource::>(); + self.world_mut() + .resource_mut::>() + .as_mut() + .context_initializers + .push(initializer); self } } -pub trait AddScriptApiProvider { - fn add_api_provider( +pub trait AddContextPreHandlingInitializer { + fn add_context_pre_handling_initializer( &mut self, - provider: Box< - dyn APIProvider< - APITarget = T::APITarget, - DocTarget = T::DocTarget, - ScriptContext = T::ScriptContext, - >, - >, + initializer: ContextPreHandlingInitializer, ) -> &mut Self; } -impl AddScriptApiProvider for App { - fn add_api_provider( +impl AddContextPreHandlingInitializer for App { + fn add_context_pre_handling_initializer( &mut self, - provider: Box< - dyn APIProvider< - APITarget = T::APITarget, - DocTarget = T::DocTarget, - ScriptContext = T::ScriptContext, - >, - >, + initializer: ContextPreHandlingInitializer, ) -> &mut Self { - provider.register_with_app(self); - let w = &mut self.world_mut(); - let providers: &mut APIProviders = &mut w.resource_mut(); - providers.providers.push(provider); + self.world_mut() + .resource_mut::>() + .as_mut() + .context_pre_handling_initializers + .push(initializer); self } } -pub trait AddScriptHostHandler { - /// Enables this script host to handle events with priorities in the range [0,min_prio] (inclusive), - /// during from within the given set. - /// - /// Note: this is identical to adding the script_event_handler system manually, so if you require more complex setup, you can use the following: - /// ```rust,ignore - /// self.add_systems( - /// MySchedule, - /// script_event_handler:: - /// ); - /// ``` - /// - /// Think of event handler systems as event sinks, which collect and "unpack" the instructions in each event every frame. - /// Because events are also prioritised, you can enforce a particular order of execution for your events (within each frame) - /// regardless of where they were fired from. - /// - /// A good example of this is Unity [game loop's](https://docs.unity3d.com/Manual/ExecutionOrder.html) `onUpdate` and `onFixedUpdate`. - /// FixedUpdate runs *before* any physics while Update runs after physics and input events. - /// - /// In this crate you can achieve this by using a separate system set before and after your physics, - /// then assigning event priorities such that your events are forced to run at the points you want them to, for example: - /// - /// PrePhysics priority range [0,1] - /// PostPhysics priority range [2,4] - /// - /// | Priority | Handler | Event | - /// | -------- | ----------- | ------------ | - /// | 0 | PrePhysics | Start 0 | - /// | 1 | PrePhysics | FixedUpdate 1 | - /// | 2 | PostPhysics | OnCollision 2 | - /// | 3 | PostPhysics | OnMouse 3 | - /// | 4 | PostPhysics | Update 4 | - /// - /// Note: in this example, if your FixedUpdate event is fired *after* the handler system set has run, it will be discarded (since other handlers discard events of higher priority). - fn add_script_handler( - &mut self, - schedule: impl ScheduleLabel, - ) -> &mut Self; - - /// The same as `add_script_handler` but allows you to specify a system set to add the handler to. - fn add_script_handler_to_set( - &mut self, - schedule: impl ScheduleLabel, - set: impl SystemSet, - ) -> &mut Self; +pub trait StoreDocumentation { + /// Adds a documentation fragment to the documentation store. + fn add_documentation_fragment(&mut self, fragment: D) -> &mut Self; + /// Consumes all the stored documentation fragments, and merges them into one, then generates the documentation. + fn generate_docs(&mut self) -> Result<(), Box>; } -impl AddScriptHostHandler for App { - fn add_script_handler_to_set( - &mut self, - schedule: impl ScheduleLabel, - set: impl SystemSet, - ) -> &mut Self { - self.add_systems(schedule, script_event_handler::.in_set(set)); +impl StoreDocumentation for App { + fn add_documentation_fragment(&mut self, fragment: D) -> &mut Self { + self.world_mut() + .init_non_send_resource::>(); + self.world_mut() + .non_send_resource_mut::>() + .as_mut() + .fragments + .push(fragment); self } - fn add_script_handler( - &mut self, - schedule: impl ScheduleLabel, - ) -> &mut Self { - self.add_systems(schedule, script_event_handler::); - self + fn generate_docs(&mut self) -> Result<(), Box> { + let mut docs = match self + .world_mut() + .remove_non_send_resource::>() + { + Some(docs) => docs, + None => return Ok(()), + }; + + let mut top_fragment = match docs.fragments.pop() { + Some(fragment) => fragment, + None => return Ok(()), + }; + + for fragment in docs.fragments.into_iter() { + top_fragment = top_fragment.merge(fragment); + } + + top_fragment.gen_docs() } } diff --git a/crates/bevy_mod_scripting_core/src/runtime.rs b/crates/bevy_mod_scripting_core/src/runtime.rs new file mode 100644 index 0000000000..6530829904 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/runtime.rs @@ -0,0 +1,36 @@ +//! "Runtime" here refers to the execution evironment of scripts. This might be the VM executing bytecode or the interpreter executing source code. +//! The important thing is that there is only one runtime which is used to execute all scripts of a particular type or `context`. + +use bevy::ecs::system::Resource; + +pub trait Runtime: 'static {} +impl Runtime for T {} + +pub type RuntimeInitializer = fn(&mut R); + +#[derive(Clone, Resource)] +pub struct RuntimeSettings { + pub initializers: Vec>, +} + +impl Default for RuntimeSettings { + fn default() -> Self { + Self { + initializers: Default::default(), + } + } +} + +/// Stores a particular runtime. +#[derive(Resource)] +pub struct RuntimeContainer { + pub runtime: Option, +} + +impl Default for RuntimeContainer { + fn default() -> Self { + Self { + runtime: Default::default(), + } + } +} diff --git a/crates/bevy_mod_scripting_core/src/script.rs b/crates/bevy_mod_scripting_core/src/script.rs new file mode 100644 index 0000000000..4d39427b29 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/script.rs @@ -0,0 +1,42 @@ +//! Everything to do with the way scripts and their contexts are stored and handled. + +use std::{borrow::Cow, collections::HashMap, ops::Deref}; + +use bevy::{asset::Handle, ecs::system::Resource, reflect::Reflect}; + +use crate::{asset::ScriptAsset, context::ContextId}; + +pub type ScriptId = Cow<'static, str>; + +#[derive(bevy::ecs::component::Component, Reflect)] +pub struct ScriptComponent(pub Vec); + +impl Deref for ScriptComponent { + type Target = Vec; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl ScriptComponent { + pub fn new(components: Vec) -> Self { + Self(components) + } +} + +/// All the scripts which are currently loaded or loading and their mapping to contexts +#[derive(Resource, Default, Clone)] +pub struct Scripts { + pub(crate) scripts: HashMap, +} + +/// A script +#[derive(Clone)] +pub struct Script { + pub id: ScriptId, + /// the asset holding the content of the script if it comes from an asset + pub asset: Option>, + /// The id of the context this script is currently assigned to + pub context_id: ContextId, +} diff --git a/crates/bevy_mod_scripting_core/src/systems.rs b/crates/bevy_mod_scripting_core/src/systems.rs index d7512a4174..78ea221327 100644 --- a/crates/bevy_mod_scripting_core/src/systems.rs +++ b/crates/bevy_mod_scripting_core/src/systems.rs @@ -1,233 +1,428 @@ -use std::collections::HashSet; - use bevy::{ecs::system::SystemState, prelude::*}; -use bevy_event_priority::PriorityEventReader; +use std::any::type_name; use crate::{ - event::ScriptLoaded, - prelude::{APIProviders, Script, ScriptCollection, ScriptContexts, ScriptData, ScriptHost}, - ScriptErrorEvent, + asset::{ScriptAsset, ScriptAssetSettings}, + bindings::ReflectAllocator, + commands::{CreateOrUpdateScript, DeleteScript}, + context::{Context, ContextLoadingSettings, ScriptContexts}, + event::{IntoCallbackLabel, ScriptCallbackEvent, ScriptErrorEvent}, + handler::{Args, CallbackSettings}, + prelude::RuntimeSettings, + runtime::{Runtime, RuntimeContainer}, + script::{ScriptComponent, Scripts}, }; -/// Labels for scripting related systems -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, SystemSet)] -pub enum ScriptSystemSet { - /// event handling systems are always marked with this label - EventHandling, +/// Cleans up dangling script allocations +pub fn garbage_collector(mut allocator: ResMut) { + allocator.clean_garbage_allocations() } -/// Handles creating contexts for new/modified scripts -/// Scripts are likely not loaded instantly at this point, so most of the time -/// this system simply inserts an empty context -pub fn script_add_synchronizer( - query: Query< - ( - Entity, - &ScriptCollection, - Ref>, - ), - Changed>, - >, - mut host: ResMut, - mut providers: ResMut>, - script_assets: Res>, - mut contexts: ResMut>, - mut event_writer: EventWriter, - mut error_writer: EventWriter, +pub fn initialize_runtime( + mut runtime: NonSendMut>, + settings: Res>, ) { - debug!("Handling addition/modification of scripts"); - - query.iter().for_each(|(entity, new_scripts, tracker)| { - if tracker.is_added() { - new_scripts.scripts.iter().for_each(|new_script| { - Script::::insert_new_script_context::( - &mut host, - new_script, - entity, - &script_assets, - &mut providers, - &mut contexts, - &mut event_writer, - &mut error_writer, - ) - }) - } else { - // changed but structure already exists in contexts - // find out what's changed - // we only care about added or removed scripts here - // if the script asset gets changed we deal with that elsewhere - - let context_ids = contexts - .context_entities - .iter() - .filter_map(|(sid, (e, _, _))| if *e == entity { Some(sid) } else { None }) - .cloned() - .collect::>(); - let script_ids = new_scripts - .scripts - .iter() - .map(|s| s.id()) - .collect::>(); + if let Some(r) = runtime.runtime.as_mut() { + for initializer in settings.initializers.iter() { + (initializer)(r); + } + }; +} - let removed_scripts = context_ids.difference(&script_ids); - let added_scripts = script_ids.difference(&context_ids); +/// Processes and reacts appropriately to script asset events, and queues commands to update the internal script state +pub fn sync_script_data( + mut events: EventReader>, + script_assets: Res>, + asset_settings: Res, + mut commands: Commands, +) { + for event in events.read() { + debug!("Responding to script asset event: {:?}", event); + let (id, remove) = match event { + // emitted when a new script asset is loaded for the first time + AssetEvent::Added { id } => (id, false), + AssetEvent::Modified { id } => (id, false), + AssetEvent::Removed { id } | AssetEvent::Unused { id } => (id, true), + _ => continue, + }; + // get the path + let asset = script_assets.get(*id); + let asset = asset.as_ref().expect("Asset was expected to be loaded!"); - for r in removed_scripts { - contexts.remove_context(*r); - } + let path = &asset.asset_path; + // convert it to script id + let converter = asset_settings.script_id_mapper.map; + let script_id = converter(path); - for a in added_scripts { - let script = new_scripts.scripts.iter().find(|e| &e.id() == a).unwrap(); - Script::::insert_new_script_context::( - &mut host, - script, - entity, - &script_assets, - &mut providers, - &mut contexts, - &mut event_writer, - &mut error_writer, - ) - } + if !remove { + commands.queue(CreateOrUpdateScript::::new( + script_id, + asset.content.clone(), + Some(script_assets.reserve_handle()), + )); + } else { + commands.queue(DeleteScript::::new(script_id)); } - }) + } } -/// Handles the removal of script components and their contexts -pub fn script_remove_synchronizer( - mut query: RemovedComponents>, - mut contexts: ResMut>, -) { - for v in query.read() { - // we know that this entity used to have a script component - // ergo a script context must exist in ctxts, remove all scripts on the entity - let script_ids = contexts - .context_entities - .iter() - .filter_map(|(script_id, (entity, ..))| { - (entity.index() == v.index()).then_some(*script_id) - }) - .collect::>(); - for script_id in script_ids { - contexts.remove_context(script_id); +macro_rules! push_err_and_continue { + ($errors:ident, $expr:expr) => { + match $expr { + Ok(v) => v, + Err(e) => { + $errors.push(e); + continue; + } } - } + }; } -/// Reloads hot-reloaded scripts, or loads missing contexts for scripts which were added but not loaded -pub fn script_hot_reload_handler( - mut events: EventReader>, - mut host: ResMut, - scripts: Query<&ScriptCollection>, - script_assets: Res>, - mut providers: ResMut>, - mut contexts: ResMut>, - mut event_writer: EventWriter, - mut error_writer: EventWriter, +/// Passes events with the specified label to the script callback with the same name and runs the callback +pub fn event_handler( + world: &mut World, + params: &mut SystemState<( + EventReader>, + Res>, + Res>, + Res, + Query<(Entity, Ref)>, + )>, ) { - for e in events.read() { - let (handle, created) = match e { - AssetEvent::Modified { id } => (id, false), - AssetEvent::Added { id } => (id, true), - _ => continue, - }; + debug!("Handling events with label `{}`", L::into_callback_label()); + + let mut runtime_container = world + .remove_non_send_resource::>() + .unwrap_or_else(|| { + panic!( + "No runtime container for runtime {} found", + type_name::() + ) + }); + let runtime = runtime_container.runtime.as_mut().unwrap_or_else(|| { + panic!( + "No valid runtime in runtime container for runtime {}", + type_name::() + ) + }); + let mut script_contexts = world + .remove_non_send_resource::>() + .unwrap_or_else(|| panic!("No script contexts found for context {}", type_name::())); - // find script using this handle by handle id - // whether this script was modified or created - // if a script exists with this handle, we should reload it to load in a new context - // which at this point will be either None or Some(outdated context) - // both ways are fine - for scripts in scripts.iter() { - for script in &scripts.scripts { - // the script could have well loaded in the same frame that it was added - // in that case it will have a context attached and we do not want to reload it - if script.handle().id() == *handle - && !(contexts.has_context(script.id()) && created) - { - Script::::reload_script::( - &mut host, - script, - &script_assets, - &mut providers, - &mut contexts, - &mut event_writer, - &mut error_writer, - ); + let (mut script_events, callback_settings, context_settings, scripts, entities) = + params.get_mut(world); + + let handler = *callback_settings + .callback_handler + .as_ref() + .unwrap_or_else(|| { + panic!( + "No handler registered for - Runtime: {}, Context: {}, Args: {}", + type_name::(), + type_name::(), + type_name::() + ) + }); + let pre_handling_initializers = context_settings.context_pre_handling_initializers.clone(); + let scripts = scripts.clone(); + let mut errors = Vec::default(); + + let events = script_events.read().cloned().collect::>(); + let entity_scripts = entities + .iter() + .map(|(e, s)| (e, s.0.clone())) + .collect::>(); + + for event in events + .into_iter() + .filter(|e| e.label == L::into_callback_label()) + { + for (entity, entity_scripts) in entity_scripts.iter() { + for script_id in entity_scripts.iter() { + match &event.recipients { + crate::event::Recipients::Script(target_script_id) + if target_script_id != script_id => + { + continue + } + crate::event::Recipients::Entity(target_entity) if target_entity != entity => { + continue + } + _ => (), } + debug!( + "Handling event for script {} on entity {:?}", + script_id, entity + ); + let script = match scripts.scripts.get(script_id) { + Some(s) => s, + None => { + info!( + "Script `{}` on entity `{:?}` is either still loading or doesn't exist, ignoring.", + script_id, entity + ); + continue; + } + }; + let ctxt = script_contexts + .contexts + .get_mut(&script.context_id) + .unwrap(); + + let handler_result = (handler)( + event.args.clone(), + *entity, + &script.id, + &L::into_callback_label(), + ctxt, + &pre_handling_initializers, + runtime, + world, + ); + + push_err_and_continue!(errors, handler_result) } } } + + world.insert_non_send_resource(runtime_container); + world.insert_non_send_resource(script_contexts); + + for error in errors { + let mut error_events = world + .get_resource_mut::>() + .expect("Missing events resource"); + + bevy::log::error!( + "Encountered error in event handling for - Runtime {}, Context: {}, Args: {}. {}", + type_name::(), + type_name::(), + type_name::(), + error.to_string() + ); + error_events.send(ScriptErrorEvent { error }); + } } -/// Lets the script host handle all script events -pub fn script_event_handler(world: &mut World) { - // we need to collect the events to drop the borrow of the world - let mut state: CachedScriptState = world.remove_resource().unwrap(); +#[cfg(test)] +mod test { + use std::{borrow::Cow, collections::HashMap}; - let events = state - .event_state - .get_mut(world) - .0 - .iter_prio_range(MAX, MIN) - .collect::>(); + use crate::{ + event::CallbackLabel, + handler::HandlerFn, + script::{Script, ScriptId}, + }; - world.insert_resource(state); + use super::*; + struct OnTestCallback; - // should help a lot with performance on frames where no events are fired - if events.is_empty() { - return; + impl IntoCallbackLabel for OnTestCallback { + fn into_callback_label() -> CallbackLabel { + "OnTest".into() + } } - let mut ctxts: ScriptContexts = world.remove_resource().unwrap(); - - let mut host: H = world.remove_resource().unwrap(); - let mut providers: APIProviders = world.remove_resource().unwrap(); - - // we need a resource scope to be able to simultaneously access the contexts as well - // as provide world access to scripts - // afaik there is not really a better way to do this in bevy just now - let ctx_iter = ctxts - .context_entities - .iter_mut() - .filter_map(|(sid, (entity, o, name))| { - let ctx = match o { - Some(v) => v, - None => return None, - }; - - Some(( - ScriptData { - sid: *sid, - entity: *entity, - name, - }, - ctx, - )) + struct TestRuntime { + pub invocations: Vec<(Entity, ScriptId)>, + } + + struct TestContext { + pub invocations: Vec, + } + + fn setup_app( + handler_fn: HandlerFn, + runtime: R, + contexts: HashMap, + scripts: HashMap, + ) -> App { + let mut app = App::new(); + + app.add_event::>(); + app.add_event::(); + app.insert_resource::>(CallbackSettings { + callback_handler: Some(handler_fn), + }); + app.add_systems(Update, event_handler::); + app.insert_resource::(Scripts { scripts }); + app.insert_non_send_resource::>(RuntimeContainer { + runtime: Some(runtime), }); + app.insert_non_send_resource::>(ScriptContexts { contexts }); + app + } - // safety: we have unique access to world, future accesses are protected - // by the lock in the pointer - host.handle_events(world, &events, ctx_iter, &mut providers); + #[test] + fn test_handler_called_with_right_args() { + let test_script_id = Cow::Borrowed("test_script"); + let test_ctxt_id = 0; + let test_script = Script { + id: test_script_id.clone(), + asset: None, + context_id: test_ctxt_id, + }; + let scripts = HashMap::from_iter(vec![(test_script_id.clone(), test_script.clone())]); + let contexts = HashMap::from_iter(vec![( + test_ctxt_id, + TestContext { + invocations: vec![], + }, + )]); + let runtime = TestRuntime { + invocations: vec![], + }; + let mut app = setup_app::( + |args, entity, script, _, ctxt, _, runtime, _| { + ctxt.invocations.push(args); + runtime.invocations.push((entity, script.clone())); + Ok(()) + }, + runtime, + contexts, + scripts, + ); + let test_entity_id = app + .world_mut() + .spawn(ScriptComponent(vec![test_script_id.clone()])) + .id(); - world.insert_resource(ctxts); - world.insert_resource(host); - world.insert_resource(providers); -} + app.world_mut() + .send_event(ScriptCallbackEvent::::new_for_all( + OnTestCallback::into_callback_label(), + "test_args".to_owned(), + )); + app.update(); -#[derive(Resource)] -/// system state for exclusive systems dealing with script events -pub struct CachedScriptState { - pub event_state: SystemState<( - PriorityEventReader<'static, 'static, H::ScriptEvent>, - EventWriter<'static, ScriptErrorEvent>, - EventReader<'static, 'static, ScriptLoaded>, - )>, -} + let test_context = app + .world() + .get_non_send_resource::>() + .unwrap(); + let test_runtime = app + .world() + .get_non_send_resource::>() + .unwrap(); -impl FromWorld for CachedScriptState { - fn from_world(world: &mut World) -> Self { - Self { - event_state: SystemState::new(world), - } + assert_eq!( + test_context + .contexts + .get(&test_ctxt_id) + .unwrap() + .invocations, + vec!["test_args"] + ); + + assert_eq!( + test_runtime + .runtime + .as_ref() + .unwrap() + .invocations + .iter() + .map(|(e, s)| (*e, s.clone())) + .collect::>(), + vec![(test_entity_id, test_script_id.clone())] + ); + } + + #[test] + fn test_handler_called_on_right_recipients() { + let test_script_id = Cow::Borrowed("test_script"); + let test_ctxt_id = 0; + let test_script = Script { + id: test_script_id.clone(), + asset: None, + context_id: test_ctxt_id, + }; + let scripts = HashMap::from_iter(vec![ + (test_script_id.clone(), test_script.clone()), + ( + "wrong".into(), + Script { + id: "wrong".into(), + asset: None, + context_id: 1, + }, + ), + ]); + let contexts = HashMap::from_iter(vec![ + ( + test_ctxt_id, + TestContext { + invocations: vec![], + }, + ), + ( + 1, + TestContext { + invocations: vec![], + }, + ), + ]); + let runtime = TestRuntime { + invocations: vec![], + }; + let mut app = setup_app::( + |args, entity, script, _, ctxt, _, runtime, _| { + ctxt.invocations.push(args); + runtime.invocations.push((entity, script.clone())); + Ok(()) + }, + runtime, + contexts, + scripts, + ); + let test_entity_id = app + .world_mut() + .spawn(ScriptComponent(vec![test_script_id.clone()])) + .id(); + + app.world_mut() + .send_event(ScriptCallbackEvent::::new( + OnTestCallback::into_callback_label(), + "test_args_script".to_owned(), + crate::event::Recipients::Script(test_script_id.clone()), + )); + + app.world_mut() + .send_event(ScriptCallbackEvent::::new( + OnTestCallback::into_callback_label(), + "test_args_entity".to_owned(), + crate::event::Recipients::Entity(test_entity_id), + )); + app.update(); + + let test_context = app + .world() + .get_non_send_resource::>() + .unwrap(); + let test_runtime = app + .world() + .get_non_send_resource::>() + .unwrap(); + + assert_eq!( + test_context + .contexts + .get(&test_ctxt_id) + .unwrap() + .invocations, + vec!["test_args_script", "test_args_entity"] + ); + + assert_eq!( + test_runtime + .runtime + .as_ref() + .unwrap() + .invocations + .iter() + .map(|(e, s)| (*e, s.clone())) + .collect::>(), + vec![ + (test_entity_id, test_script_id.clone()), + (test_entity_id, test_script_id.clone()) + ] + ); } } From 1eb98b44664d7e50480e84f6775722c6676f653f Mon Sep 17 00:00:00 2001 From: makspll Date: Sun, 10 Nov 2024 17:47:47 +0000 Subject: [PATCH 02/22] bring over bevy api gen work --- crates/bevy_api_gen/Cargo.bootstrap.toml | 2 +- crates/bevy_api_gen/Cargo.toml | 7 +- crates/bevy_api_gen/readme.md | 14 +- crates/bevy_api_gen/src/args.rs | 7 +- crates/bevy_api_gen/src/bin/main.rs | 1 + crates/bevy_api_gen/src/callback.rs | 1 + crates/bevy_api_gen/src/context.rs | 16 +- crates/bevy_api_gen/src/import_path.rs | 2 +- crates/bevy_api_gen/src/lib.rs | 5 +- crates/bevy_api_gen/src/meta.rs | 24 +- .../bevy_api_gen/src/modifying_file_loader.rs | 10 +- .../bevy_api_gen/src/passes/cache_traits.rs | 11 +- crates/bevy_api_gen/src/passes/codegen.rs | 1 + .../src/passes/find_methods_and_fields.rs | 23 +- .../src/passes/find_reflect_types.rs | 3 +- .../src/passes/find_trait_impls.rs | 1 + .../src/passes/populate_template_data.rs | 344 +- crates/bevy_api_gen/src/plugin.rs | 4 +- crates/bevy_api_gen/src/template.rs | 9 +- crates/bevy_api_gen/templates/field.tera | 6 +- crates/bevy_api_gen/templates/footer.tera | 81 +- crates/bevy_api_gen/templates/function.tera | 24 +- crates/bevy_api_gen/templates/header.tera | 11 +- crates/bevy_api_gen/templates/item.tera | 20 +- crates/bevy_api_gen/templates/macros.tera | 56 +- crates/bevy_api_gen/templates/mod.tera | 62 +- .../src/bindings/mod.rs | 3 + .../src/bindings/providers/bevy_a11y.rs | 69 + .../src/bindings/providers/bevy_core.rs | 95 + .../src/bindings/providers/bevy_ecs.rs | 547 + .../src/bindings/providers/bevy_hierarchy.rs | 161 + .../src/bindings/providers/bevy_input.rs | 1846 ++ .../src/bindings/providers/bevy_math.rs | 5532 ++++ .../src/bindings/providers/bevy_reflect.rs | 22743 ++++++++++++++++ .../src/bindings/providers/bevy_time.rs | 736 + .../src/bindings/providers/bevy_transform.rs | 819 + .../src/bindings/providers/bevy_window.rs | 1879 ++ .../src/bindings/providers/mod.rs | 88 + .../bevy_mod_scripting_lua/src/lib.rs | 390 +- makefile | 6 +- 40 files changed, 35200 insertions(+), 459 deletions(-) create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/mod.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_a11y.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_core.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/providers/mod.rs diff --git a/crates/bevy_api_gen/Cargo.bootstrap.toml b/crates/bevy_api_gen/Cargo.bootstrap.toml index 74afa48681..b7557099fc 100644 --- a/crates/bevy_api_gen/Cargo.bootstrap.toml +++ b/crates/bevy_api_gen/Cargo.bootstrap.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] mlua = { version = "0.9.2", features = ["lua54", "vendored", "send", "macros"] } -bevy_reflect = { version = "0.14", features = [ +bevy_reflect = { version = "0.15.0-rc.3", features = [ "bevy", "glam", "petgraph", diff --git a/crates/bevy_api_gen/Cargo.toml b/crates/bevy_api_gen/Cargo.toml index 501fca03d5..9e4ecd7c98 100644 --- a/crates/bevy_api_gen/Cargo.toml +++ b/crates/bevy_api_gen/Cargo.toml @@ -36,15 +36,12 @@ source = "discover" [package.metadata.rust-analyzer] rustc_private = true -[rust-analyzer.check] -overrideCommand = ["cargo", "+nightly-2024-11-05", "a", "--message-format=json"] - [dependencies] -log = "0.4" -env_logger = "0.11" rustc_plugin = { git = "https://github.com/makspll/rustc_plugin", branch = "feature/rust-1.82.0" } indexmap = "2" +log = "0.4" +env_logger = "0.11" tempdir = "0.3" cargo_metadata = "0.18" serde_json = "1" diff --git a/crates/bevy_api_gen/readme.md b/crates/bevy_api_gen/readme.md index 93f556bb94..0831b6fc9b 100644 --- a/crates/bevy_api_gen/readme.md +++ b/crates/bevy_api_gen/readme.md @@ -8,7 +8,7 @@ bevy_api_gen is a Cargo plugin that generates reflection-powered wrappers for Be To install bevy_api_gen, use the following command: ```bash -cargo +nightly-2024-11-05 install bevy_api_gen +cargo +nightly-2024-01-24 install bevy_api_gen ``` # Usage @@ -18,17 +18,17 @@ cargo +nightly-2024-11-05 install bevy_api_gen To run the main codegen process, use the following command: ```bash -cargo +nightly-2024-11-05 bevy-api-gen generate +cargo +nightly-2024-01-24 bevy-api-gen generate ``` -This will perform all parts of the process and generate meta as well as .rs files for each crate in your workspace in your `/target/plugin-nightly-2024-11-05/bevy_api_gen` directory +This will perform all parts of the process and generate meta as well as .rs files for each crate in your workspace in your `/target/plugin-nightly-2024-01-24/bevy_api_gen` directory ## Collect After generating all the files, you can 'collect' them in a mod.rs file like so: ```bash -cargo +nightly-2024-11-05 bevy-api-gen collect +cargo +nightly-2024-01-24 bevy-api-gen collect ``` ## List Types @@ -36,7 +36,7 @@ cargo +nightly-2024-11-05 bevy-api-gen collect To see a list of all `Reflect` implementing types in your workspace run: ```bash -cargo +nightly-2024-11-05 bevy-api-gen list-types > all_types.txt +cargo +nightly-2024-01-24 bevy-api-gen list-types > all_types.txt ``` ## List Templates @@ -44,7 +44,7 @@ cargo +nightly-2024-11-05 bevy-api-gen list-types > all_types.txt To see the list of all templates which you can override use: ```bash -cargo +nightly-2024-11-05 bevy-api-gen list-templates +cargo +nightly-2024-01-24 bevy-api-gen list-templates ``` ## Print Template @@ -52,5 +52,5 @@ cargo +nightly-2024-11-05 bevy-api-gen list-templates You can also print any of the templates to stdout: ```bash -cargo +nightly-2024-11-05 bevy-api-gen print item.tera +cargo +nightly-2024-01-24 bevy-api-gen print item.tera ``` \ No newline at end of file diff --git a/crates/bevy_api_gen/src/args.rs b/crates/bevy_api_gen/src/args.rs index 848d0a9335..63898dc098 100644 --- a/crates/bevy_api_gen/src/args.rs +++ b/crates/bevy_api_gen/src/args.rs @@ -189,7 +189,12 @@ pub enum Command { /// The name of the API, this will be passed to the `collect.rs` template, which by default will be used as the APIProvider name and the /// title of the documentation. - #[arg(short, long, value_name = "NAME", default_value = "LuaBevyAPIProvider")] + #[arg( + short, + long, + value_name = "NAME", + default_value = "LuaBevyScriptingPlugin" + )] api_name: String, }, } diff --git a/crates/bevy_api_gen/src/bin/main.rs b/crates/bevy_api_gen/src/bin/main.rs index 658afed6a0..56ced9d33e 100644 --- a/crates/bevy_api_gen/src/bin/main.rs +++ b/crates/bevy_api_gen/src/bin/main.rs @@ -1,4 +1,5 @@ #![feature(rustc_private)] + use std::{ collections::HashMap, env, diff --git a/crates/bevy_api_gen/src/callback.rs b/crates/bevy_api_gen/src/callback.rs index a762ed766d..71f0a9f91a 100644 --- a/crates/bevy_api_gen/src/callback.rs +++ b/crates/bevy_api_gen/src/callback.rs @@ -87,6 +87,7 @@ impl rustc_driver::Callbacks for BevyAnalyzerCallbacks { if !continue_ { break; } + trace!("Finished pass, continuing"); } }); rustc_driver::Compilation::Continue diff --git a/crates/bevy_api_gen/src/context.rs b/crates/bevy_api_gen/src/context.rs index 498a958c42..83ed871bbb 100644 --- a/crates/bevy_api_gen/src/context.rs +++ b/crates/bevy_api_gen/src/context.rs @@ -138,13 +138,13 @@ impl CachedTraits { .all(|t| self.std_source_traits.contains_key(*t)) } - // pub(crate) fn missing_std_source_traits(&self) -> Vec { - // STD_SOURCE_TRAITS - // .iter() - // .filter(|t| !self.std_source_traits.contains_key(**t)) - // .map(|s| (*s).to_owned()) - // .collect() - // } + pub(crate) fn missing_std_source_traits(&self) -> Vec { + STD_SOURCE_TRAITS + .iter() + .filter(|t| !self.std_source_traits.contains_key(**t)) + .map(|s| (*s).to_owned()) + .collect() + } } #[derive(Clone, Debug)] @@ -152,7 +152,7 @@ pub(crate) struct FunctionContext { pub(crate) def_id: DefId, pub(crate) has_self: bool, pub(crate) is_unsafe: bool, - pub(crate) trait_did: Option, + pub(crate) trait_and_impl_did: Option<(DefId, DefId)>, /// strategies for input and output (last element is the output) pub(crate) reflection_strategies: Vec, } diff --git a/crates/bevy_api_gen/src/import_path.rs b/crates/bevy_api_gen/src/import_path.rs index 2f26fd1276..c8f5522685 100644 --- a/crates/bevy_api_gen/src/import_path.rs +++ b/crates/bevy_api_gen/src/import_path.rs @@ -27,7 +27,7 @@ impl std::fmt::Debug for ImportPathElement { /// Because we do not need ALL the items in the crate, we start searching from the item itself and traverse up the tree. /// Caches results for already found items. pub(crate) struct ImportPathFinder<'tcx> { - tcx: TyCtxt<'tcx>, + pub(crate) tcx: TyCtxt<'tcx>, pub(crate) cache: IndexMap>>, pub(crate) include_private_paths: bool, pub(crate) import_path_processor: Option String>>, diff --git a/crates/bevy_api_gen/src/lib.rs b/crates/bevy_api_gen/src/lib.rs index 23d294032e..3388d68b0b 100644 --- a/crates/bevy_api_gen/src/lib.rs +++ b/crates/bevy_api_gen/src/lib.rs @@ -1,13 +1,16 @@ #![feature(rustc_private, let_chains)] #![deny(rustc::internal)] - extern crate rustc_ast; +extern crate rustc_const_eval; extern crate rustc_driver; extern crate rustc_errors; extern crate rustc_hir; +extern crate rustc_hir_analysis; extern crate rustc_infer; extern crate rustc_interface; +extern crate rustc_lint; extern crate rustc_middle; +extern crate rustc_session; extern crate rustc_span; extern crate rustc_trait_selection; diff --git a/crates/bevy_api_gen/src/meta.rs b/crates/bevy_api_gen/src/meta.rs index a9861da384..029c438cb3 100644 --- a/crates/bevy_api_gen/src/meta.rs +++ b/crates/bevy_api_gen/src/meta.rs @@ -66,6 +66,28 @@ impl MetaLoader { self.meta_for_retry(crate_name, 3) } + /// Searches the given meta sources in order for the provided DefPathHash, once a meta file containing this hash is found + /// the search stops and returns true, if no meta file is found containing the hash, false is returned + /// + /// if a curr_source argument is provided, the search will skip this source as it is assumed that the current crate is still being compiled and not meta file for it exists yet + pub fn one_of_meta_files_contains( + &self, + meta_sources: &[&str], + curr_source: Option<&str>, + target_def_path_hash: DefPathHash, + ) -> bool { + let meta = match meta_sources + .iter() + .filter(|s| curr_source.is_none() || curr_source.is_some_and(|cs| cs == **s)) + .find_map(|s| self.meta_for(s)) + { + Some(meta) => meta, + None => return false, // TODO: is it possible we get false negatives here ? perhaps due to parallel compilation ? or possibly because of dependency order + }; + + meta.contains_def_path_hash(target_def_path_hash) + } + fn meta_for_retry(&self, crate_name: &str, _try_attempts: usize) -> Option { let meta = self .meta_dirs @@ -94,7 +116,7 @@ impl MetaLoader { let cache = self.cache.borrow(); if cache.contains_key(crate_name) { trace!("Loading meta from cache for: {}", crate_name); - cache.get(crate_name).cloned() + return cache.get(crate_name).cloned(); } else { trace!("Loading meta from filesystem for: {}", crate_name); drop(cache); diff --git a/crates/bevy_api_gen/src/modifying_file_loader.rs b/crates/bevy_api_gen/src/modifying_file_loader.rs index 7fab22dd3b..5458080dd1 100644 --- a/crates/bevy_api_gen/src/modifying_file_loader.rs +++ b/crates/bevy_api_gen/src/modifying_file_loader.rs @@ -1,11 +1,12 @@ use std::{ io, - sync::atomic::{AtomicBool, Ordering}, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, }; use log::trace; -use rustc_middle::ty::data_structures::Lrc; -// use rustc_data_structures::sync::{AtomicBool, Lrc}; use rustc_span::source_map::{FileLoader, RealFileLoader}; /// Injects extern statements into the first loaded file (crate root) @@ -41,7 +42,6 @@ impl FileLoader for ModifyingFileLoader { } } } - f }) } else { @@ -49,7 +49,7 @@ impl FileLoader for ModifyingFileLoader { } } - fn read_binary_file(&self, path: &std::path::Path) -> io::Result> { + fn read_binary_file(&self, path: &std::path::Path) -> io::Result> { RealFileLoader.read_binary_file(path) } } diff --git a/crates/bevy_api_gen/src/passes/cache_traits.rs b/crates/bevy_api_gen/src/passes/cache_traits.rs index 12e2972bfe..bdbd956815 100644 --- a/crates/bevy_api_gen/src/passes/cache_traits.rs +++ b/crates/bevy_api_gen/src/passes/cache_traits.rs @@ -66,12 +66,11 @@ pub(crate) fn cache_traits(ctxt: &mut BevyCtxt<'_>, _args: &Args) -> bool { .join(", ") ); - // TODO: figure out why some crates are missing std::fmt::Display etc - // panic!( - // "Could not find traits: [{}] in crate: {}, did bootstrapping go wrong?", - // ctxt.cached_traits.missing_std_source_traits().join(", "), - // tcx.crate_name(LOCAL_CRATE) - // ) + panic!( + "Could not find traits: [{}] in crate: {}, did bootstrapping go wrong?", + ctxt.cached_traits.missing_std_source_traits().join(", "), + tcx.crate_name(LOCAL_CRATE) + ) } true diff --git a/crates/bevy_api_gen/src/passes/codegen.rs b/crates/bevy_api_gen/src/passes/codegen.rs index 6a2a1a6812..cd2e9ccdc5 100644 --- a/crates/bevy_api_gen/src/passes/codegen.rs +++ b/crates/bevy_api_gen/src/passes/codegen.rs @@ -37,6 +37,7 @@ pub(crate) fn codegen(ctxt: &mut BevyCtxt<'_>, args: &Args) -> bool { .expect("Failed to render crate artifact"); file.flush().unwrap(); + log::trace!("Written files"); true } diff --git a/crates/bevy_api_gen/src/passes/find_methods_and_fields.rs b/crates/bevy_api_gen/src/passes/find_methods_and_fields.rs index 8034681a41..170744c7a1 100644 --- a/crates/bevy_api_gen/src/passes/find_methods_and_fields.rs +++ b/crates/bevy_api_gen/src/passes/find_methods_and_fields.rs @@ -206,7 +206,7 @@ pub(crate) fn find_methods_and_fields(ctxt: &mut BevyCtxt<'_>, _args: &Args) -> is_unsafe, def_id: fn_did, has_self, - trait_did, + trait_and_impl_did: trait_did.map(|td| (td, *impl_did)), reflection_strategies, }) }) @@ -332,6 +332,7 @@ fn type_is_adt_and_reflectable<'tcx>( ty.ty_adt_def().is_some_and(|adt_def| { let did = adt_def.did(); + // even though our meta might already be written at this point, we use this as a quick out if reflect_types.contains_key(&did) { // local types are easy to check return true; @@ -344,24 +345,18 @@ fn type_is_adt_and_reflectable<'tcx>( // so search for these metas! let crate_name = tcx.crate_name(did.krate).to_ident_string(); - let meta_sources = if tcx.crate_name(LOCAL_CRATE).as_str() == "bevy_reflect" { - // otherwise meta loader might expect the meta to exist - vec![crate_name] - } else { - vec![crate_name, "bevy_reflect".to_string()] - }; - - let meta = match meta_sources.iter().find_map(|s| meta_loader.meta_for(s)) { - Some(meta) => meta, - None => return false, // TODO: is it possible we get false negatives here ? perhaps due to parallel compilation ? or possibly because of dependency order - }; + let contains_hash = meta_loader.one_of_meta_files_contains( + &[&crate_name, "bevy_reflect"], + Some(&tcx.crate_name(LOCAL_CRATE).to_ident_string()), + tcx.def_path_hash(did), + ); - let contains_hash = meta.contains_def_path_hash(tcx.def_path_hash(did)); log::trace!( "Meta for type: `{}`, contained in meta `{}`", tcx.item_name(did), contains_hash ); + contains_hash }) } @@ -391,7 +386,7 @@ fn type_is_supported_as_non_proxy_return_val<'tcx>( ) -> bool { trace!("Checkign type is supported as non proxy return val: '{ty:?}' with param_env: '{param_env:?}'"); if let TyKind::Ref(region, _, _) = ty.kind() { - if region.get_name().is_none_or(|rn| rn.as_str() != "'static") { + if !region.get_name().is_some_and(|rn| rn.as_str() == "'static") { return false; } } diff --git a/crates/bevy_api_gen/src/passes/find_reflect_types.rs b/crates/bevy_api_gen/src/passes/find_reflect_types.rs index f808922c94..22096759ef 100644 --- a/crates/bevy_api_gen/src/passes/find_reflect_types.rs +++ b/crates/bevy_api_gen/src/passes/find_reflect_types.rs @@ -45,8 +45,7 @@ pub(crate) fn find_reflect_types(ctxt: &mut BevyCtxt<'_>, args: &Args) -> bool { generics.count() == 0 && self_ty.def().is_some_and(|did| { let short_form = format!("{}::{}",ctxt.tcx.crate_name(LOCAL_CRATE),ctxt.tcx.item_name(did)); - if ignored_types.contains(&short_form) || ignored_types.contains(&tcx.def_path_str(did)) { - info!("Ignoring type: {:?}", tcx.def_path_str(did)); + if ignored_types.contains(&short_form) || ignored_types.contains(&tcx.def_path_str(did)) { info!("Ignoring type: {:?}", tcx.def_path_str(did)); return false; }; let adt_generics = tcx.generics_of(did); diff --git a/crates/bevy_api_gen/src/passes/find_trait_impls.rs b/crates/bevy_api_gen/src/passes/find_trait_impls.rs index 9541869012..ba542ab9e4 100644 --- a/crates/bevy_api_gen/src/passes/find_trait_impls.rs +++ b/crates/bevy_api_gen/src/passes/find_trait_impls.rs @@ -136,6 +136,7 @@ fn impl_matches<'tcx>(infcx: &InferCtxt<'tcx>, ty: Ty<'tcx>, impl_def_id: DefId) let ocx = ObligationCtxt::new(infcx); let param_env = tcx.param_env_reveal_all_normalized(impl_def_id); let impl_args = infcx.fresh_args_for_item(DUMMY_SP, impl_def_id); + let impl_trait_ref = tcx .impl_trait_ref(impl_def_id) .expect("Expected defid to be an impl for a trait") diff --git a/crates/bevy_api_gen/src/passes/populate_template_data.rs b/crates/bevy_api_gen/src/passes/populate_template_data.rs index e5aff8e684..0254ee73b7 100644 --- a/crates/bevy_api_gen/src/passes/populate_template_data.rs +++ b/crates/bevy_api_gen/src/passes/populate_template_data.rs @@ -1,9 +1,12 @@ -use std::fmt::Write; +use std::{any::Any, borrow::Cow, convert::identity}; -use log::trace; +use log::{trace, warn}; use rustc_ast::Attribute; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; -use rustc_middle::ty::{FieldDef, ParamTy, Ty, TyKind, TypeFoldable}; +use rustc_middle::ty::{ + print::Print, AdtDef, FieldDef, GenericArg, GenericParamDefKind, ParamTy, TraitRef, Ty, TyKind, + TypeFoldable, +}; use rustc_span::Symbol; use crate::{ @@ -126,7 +129,7 @@ pub(crate) fn process_fields<'f, I: Iterator>( .map(|field| Field { docstrings: docstrings(ctxt.tcx.get_attrs_unchecked(field.did)), ident: field.name.to_ident_string(), - ty: ty_to_string(ctxt, ctxt.tcx.type_of(field.did).skip_binder()), + ty: ty_to_string(ctxt, ctxt.tcx.type_of(field.did).skip_binder(), false), reflection_strategy: *ty_ctxt .get_field_reflection_strat(field.did) .unwrap_or_else(|| panic!("{ty_ctxt:#?}")), @@ -145,52 +148,25 @@ pub(crate) fn process_functions(ctxt: &BevyCtxt, fns: &[FunctionContext]) -> Vec .zip(fn_sig.inputs()) .enumerate() .map(|(idx, (ident, ty))| { - let (ident, ty) = if fn_ctxt.has_self && idx == 0 { - // self argument, we want to map to something like `&self` instead of `&Component` - // we do that by renaming every adt inside to "self" - // this is a bit hacky but it works, might not work if we decide to support generics in the future - // TODO: fix to work with generics - let ty = ty.fold_with(&mut rustc_middle::ty::fold::BottomUpFolder { - tcx: ctxt.tcx, - ty_op: |ty| { - if ty.is_adt() { - ctxt.tcx.mk_ty_from_kind(TyKind::Param(ParamTy::new( - 0, - Symbol::intern("self"), - ))) - } else { - ty - } - }, - lt_op: |lt| lt, - ct_op: |ct| ct, - }); - (None, ty) - } else { - (ident.to_string().into(), *ty) - }; - // remove projections like `::AssocType` - let ty = ty_to_string( - ctxt, - ctxt.tcx - .normalize_erasing_regions(ctxt.tcx.param_env(fn_ctxt.def_id), ty), - ); + let normalized_ty = ctxt + .tcx + .normalize_erasing_regions(ctxt.tcx.param_env(fn_ctxt.def_id), *ty); Arg { - ident, - ty, + ident: ident.to_string(), + ty: ty_to_string(ctxt, normalized_ty, false), + proxy_ty: ty_to_string(ctxt, normalized_ty, true), reflection_strategy: fn_ctxt.reflection_strategies[idx], } }) .collect(); - let ty = ty_to_string( - ctxt, - ctxt.tcx - .normalize_erasing_regions(ctxt.tcx.param_env(fn_ctxt.def_id), fn_sig.output()), - ); + let out_ty = ctxt + .tcx + .normalize_erasing_regions(ctxt.tcx.param_env(fn_ctxt.def_id), fn_sig.output()); let output = Output { - ty, + ty: ty_to_string(ctxt, out_ty, false), + proxy_ty: ty_to_string(ctxt, out_ty, true), reflection_strategy: *fn_ctxt.reflection_strategies.last().unwrap(), }; @@ -203,9 +179,11 @@ pub(crate) fn process_functions(ctxt: &BevyCtxt, fns: &[FunctionContext]) -> Vec output, has_self: fn_ctxt.has_self, docstrings: docstrings(ctxt.tcx.get_attrs_unchecked(fn_ctxt.def_id)), - from_trait_path: fn_ctxt - .trait_did - .map(|trait_did| import_path(ctxt, trait_did)), + from_trait_path: fn_ctxt.trait_and_impl_did.map(|(_, impl_did)| { + let trait_ref = ctxt.tcx.impl_trait_ref(impl_did).unwrap().skip_binder(); + + trait_ref_to_string(ctxt, trait_ref) + }), } }) .collect() @@ -236,51 +214,271 @@ pub(crate) fn import_path(ctxt: &BevyCtxt, def_id: DefId) -> String { } /// Normalizes type import paths in types before printing them -fn ty_to_string<'tcx>(ctxt: &BevyCtxt<'tcx>, ty: Ty<'tcx>) -> String { +fn ty_to_string<'tcx>(ctxt: &BevyCtxt<'tcx>, ty: Ty<'tcx>, proxy_types: bool) -> String { // walk through the type and replace all paths with their standardised import paths - TyPrinter::new().print(&ctxt.path_finder, ty) + TyPrinter::new( + Box::new(|ty| { + ty.ty_adt_def() + .map(|def| { + let def_id = def.did(); + let def_path_hash = ctxt.tcx.def_path_hash(def_id); + let meta_sources = [ + &ctxt.tcx.crate_name(def_id.krate).to_ident_string(), + "bevy_reflect", + ]; + + ctxt.meta_loader.one_of_meta_files_contains( + &meta_sources, + Some(&ctxt.tcx.crate_name(LOCAL_CRATE).to_ident_string()), + def_path_hash, + ) + }) + .is_some_and(identity) + }), + Box::new(|did| Cow::Owned(import_path(ctxt, did))), + proxy_types, + ) + .print(ty) } -struct TyPrinter { +/// Converts a specific trait instantiation (in the context of an impl) into a string taking into account correctly the +/// import transformations and generics +/// TODO: this doesn't explicitly print out associated types, because I don't think it's necessary yet and annoying to do (idk how to do it) +fn trait_ref_to_string<'tcx>(ctxt: &BevyCtxt<'tcx>, trait_ref: TraitRef<'tcx>) -> String { + let generics_def = ctxt.tcx.generics_of(trait_ref.def_id); + + let generic_args = trait_ref + .args + .iter() + .enumerate() + .skip(if generics_def.has_self { 1 } else { 0 }) + .map(|(idx, a)| (a, generics_def.param_at(idx, ctxt.tcx))) + // filter out non const | type generics and the compiler generated ones + .filter(|(_, arg_def)| match arg_def.kind { + GenericParamDefKind::Lifetime => false, + GenericParamDefKind::Const { synthetic, .. } => !synthetic, + _ => true, + }) + .map(|(arg, arg_def)| { + log::trace!("Printing for trait: `{trait_ref}` arg: `{arg}`, with def: `{arg_def:#?}`"); + + let arg_ty = if let Some(ty) = arg.as_type() { + ty + } else if arg.as_const().is_some() { + arg.as_type().unwrap() + } else { + unreachable!("should be filtered") + }; + + ty_to_string(ctxt, arg_ty, false) + }) + .collect::>(); + + let trait_path = import_path(ctxt, trait_ref.def_id); + + if generic_args.is_empty() { + trait_path + } else { + format!("{trait_path}::<{}>", generic_args.join(", ")) + } +} + +#[derive(Clone, Copy)] +pub(crate) enum ProxyType { + Ref, + RefMut, + Val, + NonReflectVal, +} + +impl ProxyType { + pub fn to_ident_str(self) -> &'static str { + match self { + ProxyType::Ref => "LuaReflectRefProxy", + ProxyType::RefMut => "LuaReflectRefMutProxy", + ProxyType::Val => "LuaReflectValProxy", + ProxyType::NonReflectVal => "LuaValProxy", + } + } +} +/// Pretty prints types fully using the given import path finder or ADT's +struct TyPrinter<'a> { buffer: String, + path_finder: Box Cow<'static, str> + 'a>, + is_proxied_check: Box) -> bool + 'a>, + /// If true will wrap types in appropriate proxies instead of directly pringting the type + proxy_types: bool, } -impl TyPrinter { - pub fn new() -> Self { +impl<'a> TyPrinter<'a> { + pub fn new( + is_proxied_check: Box) -> bool + 'a>, + path_finder: Box Cow<'static, str> + 'a>, + proxy_types: bool, + ) -> Self { TyPrinter { buffer: String::new(), + is_proxied_check, + proxy_types, + path_finder, } } - pub fn print(mut self, path_finder: &ImportPathFinder, ty: Ty<'_>) -> String { - self.build_str(path_finder, ty); + + pub fn print(mut self, ty: Ty<'_>) -> String { + log::trace!("Printing type: {:#?}", ty); + self.print_ty(ty); self.buffer } - fn build_str(&mut self, path_finder: &ImportPathFinder, ty: Ty<'_>) { + fn print_args<'tcx, I: Iterator>>(&mut self, mut args: I) { + let mut next = args.next(); + if next.is_some() { + self.buffer.push('<'); + while let Some(arg) = next { + let ty = if let Some(ty) = arg.as_type() { + ty + } else if arg.as_const().is_some() { + arg.as_type().unwrap() + } else { + next = args.next(); + continue; + }; + self.print_ty(ty); + + next = args.next(); + if next.is_some() { + self.buffer.push_str(", "); + } + } + + self.buffer.push('>'); + } + } + + fn print_adt<'tcx, I: Iterator>>(&mut self, ty: AdtDef<'tcx>, args: I) { + log::trace!("Printing ADT: {:#?}", ty); + let did = ty.did(); + let import_path = (self.path_finder)(did); + self.buffer.push_str(&import_path); + self.print_args(args); + } + + fn print_ty(&mut self, ty: Ty<'_>) { + log::trace!("Printing type: {:#?}", ty); + match ty.kind() { - TyKind::Adt(adt_def, args) => { - let did = adt_def.did(); - let import_path = path_finder - .find_import_paths(did) - .first() - .unwrap() - .to_owned(); - self.buffer.push_str(&import_path); - if args.len() > 0 { - self.buffer.push('<'); - for (idx, a) in args.iter().enumerate() { - match a.as_type() { - Some(ty) => self.build_str(path_finder, ty), - None => _ = self.buffer.write_str(&a.to_string()), - } - if idx != args.len() - 1 { - self.buffer.push_str(", "); - } + TyKind::Bool => self.print_literal("bool"), + TyKind::Char => self.print_literal("char"), + TyKind::Str => self.print_literal("str"), + TyKind::Int(ty) => self.print_literal(ty.name_str()), + TyKind::Uint(ty) => self.print_literal(ty.name_str()), + TyKind::Float(ty) => self.print_literal(ty.name_str()), + TyKind::Adt(adt_ty, args) => { + if self.proxy_types { + self.print_proxied_ty(ty, ProxyType::Val); + } else { + self.print_adt(*adt_ty, args.iter()); + } + } + TyKind::Array(ty, const_) => { + self.buffer.push('['); + self.print_ty(*ty); + self.buffer.push(';'); + // shortcut, we won't encounter ADT's here just use native printer + self.buffer.push_str(&const_.to_string()); + self.buffer.push(']'); + } + TyKind::Slice(ty) => { + self.buffer.push('['); + self.print_ty(*ty); + self.buffer.push(']'); + } + TyKind::RawPtr(ptr, mutability) => { + self.buffer.push('*'); + if mutability.is_mut() { + self.buffer.push_str("mut "); + } + self.print_ty(*ptr); + } + TyKind::Ref(_, ty, mut_) => { + if self.proxy_types { + let proxy_type = if mut_.is_mut() { + ProxyType::RefMut + } else { + ProxyType::Ref + }; + self.print_proxied_ty(*ty, proxy_type); + } else { + self.buffer.push('&'); + if mut_.is_mut() { + self.buffer.push_str("mut "); + } + self.print_ty(*ty); + } + } + TyKind::Tuple(tys) => { + self.buffer.push('('); + for (idx, ty) in tys.iter().enumerate() { + self.print_ty(ty); + if idx != tys.len() - 1 { + self.buffer.push(','); } - self.buffer.push('>'); } + self.buffer.push(')'); + } + TyKind::Alias(_, ty) => { + self.buffer.push_str(&(self.path_finder)(ty.def_id)); + self.print_args(ty.args.iter()); + } + // self is one I think + TyKind::Param(param) => self.print_literal(param.name.as_str()), + _ => { + warn!( + "Type outside the scope of the TyPrinter being printed: pretty=`{}` kind=`{:?}`", + ty, ty.kind() + ); + self.buffer.push_str(&ty.to_string()) } - _ => self.buffer.push_str(&ty.to_string()), } } + + /// prints a type but without making further proxies at this level + /// i.e. a &T will be printed as RefProxy instead of RefProxy> since the T will not be printed via print_ty but directly here + /// But only for ADT's, other types are printed as normal + fn print_proxied_ty(&mut self, ty: Ty<'_>, proxy_type: ProxyType) { + match ty.kind() { + TyKind::Adt(adt_ty, args) => { + if (self.is_proxied_check)(ty) { + self.print_literal_surround_content( + proxy_type.to_ident_str(), + '<', + '>', + |self_| { + self_.print_adt(*adt_ty, args.iter()); + }, + ); + } else { + self.print_adt(*adt_ty, args.iter()) + } + } + _ => self.print_ty(ty), + } + } + + fn print_literal_surround_content( + &mut self, + literal: &str, + start: char, + end: char, + f: F, + ) { + self.buffer.push_str(literal); + self.buffer.push(start); + f(self); + self.buffer.push(end); + } + + fn print_literal(&mut self, literal: &str) { + self.buffer.push_str(literal); + } } diff --git a/crates/bevy_api_gen/src/plugin.rs b/crates/bevy_api_gen/src/plugin.rs index b365458ee9..1e0d73a245 100644 --- a/crates/bevy_api_gen/src/plugin.rs +++ b/crates/bevy_api_gen/src/plugin.rs @@ -53,7 +53,9 @@ impl RustcPlugin for BevyAnalyzer { let mut callbacks = BevyAnalyzerCallbacks::new(plugin_args); let mut compiler = rustc_driver::RunCompiler::new(&compiler_args, &mut callbacks); compiler.set_file_loader(Some(Box::new(ModifyingFileLoader))); - compiler.run() + let out = compiler.run(); + log::trace!("Finished compiling with plugin"); + out } fn modify_cargo(&self, cmd: &mut std::process::Command, args: &Self::Args) { diff --git a/crates/bevy_api_gen/src/template.rs b/crates/bevy_api_gen/src/template.rs index e9219d0013..ddb9d02960 100644 --- a/crates/bevy_api_gen/src/template.rs +++ b/crates/bevy_api_gen/src/template.rs @@ -111,17 +111,21 @@ pub(crate) struct Function { pub(crate) struct Arg { /// the name of the argument as in source code /// None if this is a receiver, in which case ty contains the ident - pub(crate) ident: Option, + pub(crate) ident: String, /// the type of argument /// i.e. `&Vec` pub(crate) ty: String, + /// The proxied type of argument for use in Unproxy and Proxy targetted code + /// i.e. AppropriateRefProxy instead of &MyTy for a reference + pub(crate) proxy_ty: String, pub(crate) reflection_strategy: ReflectionStrategy, } #[derive(Serialize)] pub(crate) struct Output { pub(crate) ty: String, + pub(crate) proxy_ty: String, pub(crate) reflection_strategy: ReflectionStrategy, } @@ -195,8 +199,9 @@ pub(crate) fn configure_tera_env(tera: &mut Tera, crate_name: &str) { let file = syn::parse_file(&str) .map_err(|e| tera::Error::msg(e.to_string())) - .inspect_err(|_| { + .map_err(|e| { log::error!("prettyplease error on input: ```\n{}\n```", str); + e })?; let out = prettyplease::unparse(&file); diff --git a/crates/bevy_api_gen/templates/field.tera b/crates/bevy_api_gen/templates/field.tera index bf9baae508..ea5fb1450a 100644 --- a/crates/bevy_api_gen/templates/field.tera +++ b/crates/bevy_api_gen/templates/field.tera @@ -1,6 +1,4 @@ -{%- if field.reflection_strategy == "Proxy" -%} - #[lua(output(proxy))] -{%- elif field.reflection_strategy == "Filtered" -%} +{%- if field.reflection_strategy == "Filtered" -%} #[lua(skip)] {%- endif -%} @@ -10,6 +8,6 @@ {% if field.reflection_strategy != "Reflection" -%} {{- field.ty -}} {%- else -%} -ReflectedValue +ReflectReference {%- endif -%} , diff --git a/crates/bevy_api_gen/templates/footer.tera b/crates/bevy_api_gen/templates/footer.tera index b14a4794a1..87a76308e2 100644 --- a/crates/bevy_api_gen/templates/footer.tera +++ b/crates/bevy_api_gen/templates/footer.tera @@ -1,70 +1,53 @@ +{% if args.self_is_bms_lua %} +{% set bms_lua_path="crate" %} +{% else %} +{% set bms_lua_path="bevy_mod_scripting::lua"%} +{% endif %} + #[derive(Default)] pub(crate) struct Globals; -impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { - fn add_instances<'lua, T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>>( +impl {{bms_lua_path}}::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: {{bms_lua_path}}::tealr::mlu::InstanceCollector<'lua>>( self, instances: &mut T, - ) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { + ) -> {{bms_lua_path}}::tealr::mlu::mlua::Result<()> { {% for item in items %} {% if item.has_static_methods %} instances.add_instance("{{ item.ident }}", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::<{{item.ident | prefix_lua}}>::new)?; + {{bms_lua_path}}::tealr::mlu::UserDataProxy::<{{item.ident | prefix_lua}}>::new)?; {% endif %} {% endfor %} Ok(()) } } -pub struct {{ "A P I Provider" | prefix_cratename | convert_case(case="upper_camel")}}; - -impl bevy_mod_scripting_core::hosts::APIProvider for {{ "A P I Provider" | prefix_cratename | convert_case(case="upper_camel") }} { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; - - fn attach_api(&mut self, ctx: &mut Self::APITarget) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - let ctx = ctx - .get_mut() - .expect("Unable to acquire lock on Lua context"); - bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) - .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other(e.to_string())) - } - - fn get_doc_fragment(&self) -> Option { - Some(bevy_mod_scripting_lua::docs::LuaDocFragment::new("{{ "A P I" | prefix_cratename | convert_case(case="upper_camel") }}", |tw| { - tw - .document_global_instance::().expect("Something went wrong documenting globals") - {% for item in items %} - .process_type::<{{ item.ident | prefix_lua }}>() - {% if item.has_static_methods %} - .process_type::>() - {% endif %} - {% endfor %} - } - )) - } - fn setup_script( - &mut self, - script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } +fn {{ "ContextInitializer" | prefix_cratename | convert_case(case="snake") }} (_: &bevy_mod_scripting_core::script::ScriptId, ctx: &mut {{bms_lua_path}}::prelude::Lua) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + {{bms_lua_path}}::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} - fn setup_script_runtime( - &mut self, - world_ptr: bevy_mod_scripting_core::world::WorldPointer, - _script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } +pub struct {{ "ScriptingPlugin" | prefix_cratename | convert_case(case="upper_camel")}}; - fn register_with_app(&self, app: &mut bevy::app::App) { +impl bevy::app::Plugin for {{ "ScriptingPlugin" | prefix_cratename | convert_case(case="upper_camel")}} { + fn build(&self, app: &mut bevy::prelude::App) { {% for item in items %} - app.register_foreign_lua_type::<{{ item.import_path }}>(); + app.register_proxy::<{{ item.import_path }}>(); {% endfor %} + app.add_context_initializer::<()>({{ "ContextInitializer" | prefix_cratename | convert_case(case="snake") }}); + app.add_documentation_fragment( + {{bms_lua_path}}::docs::LuaDocumentationFragment::new("{{ "A P I" | prefix_cratename | convert_case(case="upper_camel") }}", |tw| { + tw + .document_global_instance::().expect("Something went wrong documenting globals") + {% for item in items %} + .process_type::<{{ item.ident | prefix_lua }}>() + {% if item.has_static_methods %} + .process_type::<{{bms_lua_path}}::tealr::mlu::UserDataProxy<{{ item.ident | prefix_lua }}>>() + {% endif %} + {% endfor %} + } + ) + ); } } \ No newline at end of file diff --git a/crates/bevy_api_gen/templates/function.tera b/crates/bevy_api_gen/templates/function.tera index a525af9bd4..970eebdfcc 100644 --- a/crates/bevy_api_gen/templates/function.tera +++ b/crates/bevy_api_gen/templates/function.tera @@ -13,6 +13,11 @@ r#" as_trait="{{ function.from_trait_path }}", {%- endif -%} +{% if is_op %} +composite="{{ function.ident }}", +{% endif %} + +{# {% if function.has_self and not is_op %} kind="{% if function.args.0.ty is starting_with("&mut") %}Mutating{% endif %}Method", {% elif is_op %} @@ -25,9 +30,7 @@ kind="Function", output(proxy), {%- endif -%} -{% if is_op %} -composite="{{ function.ident }}", -{% endif %} + {% if function.from_trait_path == "std::ops::Neg" %} metamethod="Unm", @@ -44,23 +47,22 @@ metamethod="Mod", {% elif function.from_trait_path == "std::cmp::PartialEq" %} metamethod="Eq", {% endif %} - +#} )] {% if function.is_unsafe %}unsafe {% endif -%}fn {{ function.ident }} ( {%- filter separated(delimeter=", ", split_at="---", ignore_first=true) -%} {%- for arg in function.args -%} --- - {%- if arg.ident and arg.reflection_strategy == "Proxy" -%} - #[proxy] - {%- endif -%} - {%- if arg.ident -%} - {{- arg.ident }} : {# -#} + {%- if arg.ident != "self" -%} + {{- arg.ident -}} + {%- else -%} + _{{- arg.ident -}} {%- endif -%} - {{- arg.ty -}} + : {{- arg.proxy_ty -}} {%- endfor -%} {%- endfilter -%} -) -> {{ function.output.ty -}}; +) -> {{ function.output.proxy_ty -}}; {%- endfilter %} "# \ No newline at end of file diff --git a/crates/bevy_api_gen/templates/header.tera b/crates/bevy_api_gen/templates/header.tera index e40a725a12..2cdbb5745e 100644 --- a/crates/bevy_api_gen/templates/header.tera +++ b/crates/bevy_api_gen/templates/header.tera @@ -8,8 +8,11 @@ use super::{{crate}}::*; {% endif %} {% endfor %} -{% if args.self_is_bevy_script_api %} -extern crate self as bevy_script_api; -{% endif %} -use bevy_script_api::{lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld}; \ No newline at end of file +use bevy_mod_scripting_core::{AddContextInitializer, StoreDocumentation, bindings::ReflectReference}; + +{% if args.self_is_bms_lua %} +use crate::{bindings::proxy::{LuaReflectRefProxy,LuaReflectRefMutProxy,LuaReflectValProxy,LuaValProxy,IdentityProxy},RegisterLuaProxy, tealr::mlu::mlua::IntoLua}; +{% else %} +use bevy_mod_scripting::{lua::bindings::proxy::{LuaReflectRefProxy,LuaReflectRefMutProxy,LuaReflectValProxy,LuaValProxy,IdentityProxy}, RegisterLuaProxy, tealr::mlu::mlua::IntoLua}; +{% endif %} \ No newline at end of file diff --git a/crates/bevy_api_gen/templates/item.tera b/crates/bevy_api_gen/templates/item.tera index 3a8a8bfacb..43bb345ec7 100644 --- a/crates/bevy_api_gen/templates/item.tera +++ b/crates/bevy_api_gen/templates/item.tera @@ -3,14 +3,20 @@ {# for now #} {% endfor %} +{% if args.self_is_bms_lua %} +{% set bms_core_path="bevy_mod_scripting_core" %} +{% set bms_lua_path="crate" %} +{% else %} +{% set bms_core_path="bevy_mod_scripting::core" %} +{% set bms_lua_path="bevy_mod_scripting::lua" %} +{% endif %} + #[derive(bevy_mod_scripting_lua_derive::LuaProxy)] #[proxy( -derive( - {%- if item.impls_clone -%} - clone, - {%- endif -%} -), remote="{{ item.import_path }}", +bms_core_path="{{bms_core_path}}", +bms_lua_path="{{bms_lua_path}}", + functions[ {%- filter separated(delimeter=",\n\t\t\t", split_at="---", ignore_first=true) -%} {%- for function in item.functions -%} @@ -61,7 +67,7 @@ functions[ r#" {%- set mat_type = item.import_path | split(pat="::") | last -%} {%- set col_type = mat_type | replace(from="Mat", to="Vec")-%} - {{- macros::matrix_index(col_type=col_type,mat_type=mat_type)-}} + {{- macros::matrix_index(col_type=col_type,mat_type=mat_type,bms_core_path=bms_core_path)-}} "# {% endif %} {%- endfilter -%} @@ -76,7 +82,7 @@ functions[ {% set close_item = "}" %} {% endif %} -struct {{ item.ident -}} {{ open_item }} +pub struct {{ item.ident -}} {{ open_item }} {% if not item.is_enum %} {% for field in item.variants[0].fields %} {% if field.reflection_strategy != "Filtered" %} diff --git a/crates/bevy_api_gen/templates/macros.tera b/crates/bevy_api_gen/templates/macros.tera index 4e75fc50bd..ef5b578334 100644 --- a/crates/bevy_api_gen/templates/macros.tera +++ b/crates/bevy_api_gen/templates/macros.tera @@ -1,51 +1,47 @@ {% macro vector_index(num_type) %} -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result<{{ num_type }},_> { - Ok(self.inner()?[*idx]) +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> IdentityProxy<{{ num_type }}> { + _self[idx - 1] } {% endmacro vector_index %} {% macro vector_newindex(num_type) %} -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: {{ num_type }}) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: {{ num_type }}) -> () { + _self[idx - 1] = val } {% endmacro vector_newindex %} -{% macro matrix_index(col_type, mat_type) %} -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result<{{ col_type | prefix_lua }},_> { - Ok({{ col_type | prefix_lua }}::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) +{% macro matrix_index(col_type, mat_type, bms_core_path) %} +#[lua(metamethod="Index")] +fn index(_self: IdentityProxy, idx: usize) -> IdentityProxy<{{ col_type | prefix_lua }}> { + let mut curr_ref = _self.0.clone(); + let def_ref = {{bms_core_path}}::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push({{bms_core_path}}::bindings::ReflectionPathElem::new_deferred(def_ref)); + {{ col_type | prefix_lua }}(curr_ref) } {% endmacro matrix_index %} {% macro debug_as_to_string() %} -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } {% endmacro debug_as_to_string %} {% macro display_as_to_string() %} -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{}", _self) } diff --git a/crates/bevy_api_gen/templates/mod.tera b/crates/bevy_api_gen/templates/mod.tera index 186b98ace2..44530bb555 100644 --- a/crates/bevy_api_gen/templates/mod.tera +++ b/crates/bevy_api_gen/templates/mod.tera @@ -4,69 +4,17 @@ #![cfg_attr(rustfmt, rustfmt_skip)] {% filter prettyplease %} {%- for crate in crates %} - pub mod {{ crate.name }}; + pub(crate) mod {{ crate.name }}; {% endfor -%} -{% if args.self_is_bevy_script_api %} -extern crate self as bevy_script_api; -{% endif %} - -use bevy_mod_scripting_core::docs::DocFragment; - - pub struct {{ api_name }}; -impl bevy_mod_scripting_core::hosts::APIProvider for {{ api_name }} { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; - - fn attach_api(&mut self, ctx: &mut Self::APITarget) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { +impl bevy::app::Plugin for {{ api_name }} { + fn build(&self, app: &mut bevy::prelude::App) { {% for crate in crates %} - {% set crate_name = crate.name %} - {{ crate_name }}::{{ "A P I Provider" | prefix(val=crate_name) | convert_case(case="upper_camel")}}.attach_api(ctx)?; - {% endfor %} - Ok(()) - } - - fn get_doc_fragment(&self) -> Option { - [ - {% for crate in crates %} - {% set crate_name = crate.name %} - {{ crate_name }}::{{ "A P I Provider" | prefix(val=crate_name) | convert_case(case="upper_camel")}}.get_doc_fragment(), - {% endfor %} - ] - .into_iter() - .filter_map(|a: Option<_>| a) - .fold(None, |a, b| match a { - Some(a) => Some(a.merge(b)), - None => Some(b), - }) - } - - fn setup_script( - &mut self, - script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - - fn setup_script_runtime( - &mut self, - world_ptr: bevy_mod_scripting_core::world::WorldPointer, - _script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - - fn register_with_app(&self, app: &mut bevy::app::App) { - {% for crate in crates %} - {% set crate_name = crate.name %} - {{ crate_name }}::{{ "A P I Provider" | prefix(val=crate_name) | convert_case(case="upper_camel")}}.register_with_app(app); + {% set crate_name = crate.name %} + {{ crate_name }}::{{ "ScriptingPlugin" | prefix(val=crate_name) | convert_case(case="upper_camel")}}.build(app); {% endfor %} } } - {% endfilter %} \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/mod.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/mod.rs new file mode 100644 index 0000000000..384af4032b --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/mod.rs @@ -0,0 +1,3 @@ +use bevy_mod_scripting_core::bindings::WorldCallbackAccess; + +pub mod providers; diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_a11y.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_a11y.rs new file mode 100644 index 0000000000..b6ef3788e4 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_a11y.rs @@ -0,0 +1,69 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use super::bevy_ecs::*; +use super::bevy_reflect::*; +extern crate self as bevy_script_api; +use bevy_script_api::{ + lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy(derive(), remote = "bevy::a11y::Focus", functions[])] +struct Focus(ReflectedValue); +#[derive(Default)] +pub(crate) struct Globals; +impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { + fn add_instances< + 'lua, + T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, + >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { + Ok(()) + } +} +pub struct BevyA11YAPIProvider; +impl bevy_mod_scripting_core::hosts::APIProvider for BevyA11YAPIProvider { + type APITarget = std::sync::Mutex; + type ScriptContext = std::sync::Mutex; + type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; + fn attach_api( + &mut self, + ctx: &mut Self::APITarget, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); + bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) + .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( + e.to_string(), + )) + } + fn get_doc_fragment(&self) -> Option { + Some( + bevy_mod_scripting_lua::docs::LuaDocFragment::new( + "BevyA11YAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + }, + ), + ) + } + fn setup_script( + &mut self, + script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn setup_script_runtime( + &mut self, + world_ptr: bevy_mod_scripting_core::world::WorldPointer, + _script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn register_with_app(&self, app: &mut bevy::app::App) { + app.register_foreign_lua_type::(); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_core.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_core.rs new file mode 100644 index 0000000000..f205ff73bd --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_core.rs @@ -0,0 +1,95 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use super::bevy_ecs::*; +use super::bevy_reflect::*; +extern crate self as bevy_script_api; +use bevy_script_api::{ + lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::core::prelude::Name", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::core::prelude::Name; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &name::Name) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{}", _self) +} +"#] +)] +struct Name {} +#[derive(Default)] +pub(crate) struct Globals; +impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { + fn add_instances< + 'lua, + T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, + >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { + Ok(()) + } +} +pub struct BevyCoreAPIProvider; +impl bevy_mod_scripting_core::hosts::APIProvider for BevyCoreAPIProvider { + type APITarget = std::sync::Mutex; + type ScriptContext = std::sync::Mutex; + type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; + fn attach_api( + &mut self, + ctx: &mut Self::APITarget, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); + bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) + .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( + e.to_string(), + )) + } + fn get_doc_fragment(&self) -> Option { + Some( + bevy_mod_scripting_lua::docs::LuaDocFragment::new( + "BevyCoreAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + }, + ), + ) + } + fn setup_script( + &mut self, + script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn setup_script_runtime( + &mut self, + world_ptr: bevy_mod_scripting_core::world::WorldPointer, + _script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn register_with_app(&self, app: &mut bevy::app::App) { + app.register_foreign_lua_type::(); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs new file mode 100644 index 0000000000..8f3b5d4e27 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs @@ -0,0 +1,547 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use super::bevy_reflect::*; +extern crate self as bevy_script_api; +use bevy_script_api::{ + lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::ecs::entity::Entity", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::ecs::entity::Entity; + +"#, + r#" +/// Creates a new entity ID with the specified `index` and a generation of 1. +/// # Note +/// Spawning a specific `entity` value is __rarely the right choice__. Most apps should favor +/// [`Commands::spawn`](crate::system::Commands::spawn). This method should generally +/// only be used for sharing entities across apps, and only when they have a scheme +/// worked out to share an index space (which doesn't happen by default). +/// In general, one should not try to synchronize the ECS by attempting to ensure that +/// `Entity` lines up between instances, but instead insert a secondary identifier as +/// a component. + + #[lua(kind = "Function", output(proxy))] + fn from_raw(index: u32) -> bevy::ecs::entity::Entity; + +"#, + r#" +/// Convert to a form convenient for passing outside of rust. +/// Only useful for identifying entities within the same instance of an application. Do not use +/// for serialization between runs. +/// No particular structure is guaranteed for the returned bits. + + #[lua(kind = "Method")] + fn to_bits(self) -> u64; + +"#, + r#" +/// Reconstruct an `Entity` previously destructured with [`Entity::to_bits`]. +/// Only useful when applied to results from `to_bits` in the same instance of an application. +/// # Panics +/// This method will likely panic if given `u64` values that did not come from [`Entity::to_bits`]. + + #[lua(kind = "Function", output(proxy))] + fn from_bits(bits: u64) -> bevy::ecs::entity::Entity; + +"#, + r#" +/// Return a transiently unique identifier. +/// No two simultaneously-live entities share the same index, but dead entities' indices may collide +/// with both live and dead entities. Useful for compactly representing entities within a +/// specific snapshot of the world, such as when serializing. + + #[lua(kind = "Method")] + fn index(self) -> u32; + +"#, + r#" +/// Returns the generation of this Entity's index. The generation is incremented each time an +/// entity with a given index is despawned. This serves as a "count" of the number of times a +/// given index has been reused (index, generation) pairs uniquely identify a given Entity. + + #[lua(kind = "Method")] + fn generation(self) -> u32; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &entity::Entity) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Entity {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "bevy::ecs::world::OnAdd", + functions[r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct OnAdd {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "bevy::ecs::world::OnInsert", + functions[r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct OnInsert {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "bevy::ecs::world::OnRemove", + functions[r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct OnRemove {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "bevy::ecs::world::OnReplace", + functions[r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct OnReplace {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::ecs::component::ComponentId", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &component::ComponentId) -> bool; + +"#, + r#" +/// Creates a new [`ComponentId`]. +/// The `index` is a unique value associated with each type of component in a given world. +/// Usually, this value is taken from a counter incremented for each type of component registered with the world. + + #[lua(kind = "Function", output(proxy))] + fn new(index: usize) -> bevy::ecs::component::ComponentId; + +"#, + r#" +/// Returns the index of the current component. + + #[lua(kind = "Method")] + fn index(self) -> usize; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::ecs::component::ComponentId; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct ComponentId(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::ecs::component::Tick", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &component::Tick) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::ecs::component::Tick; + +"#, + r#" +/// Creates a new [`Tick`] wrapping the given value. + + #[lua(kind = "Function", output(proxy))] + fn new(tick: u32) -> bevy::ecs::component::Tick; + +"#, + r#" +/// Gets the value of this change tick. + + #[lua(kind = "Method")] + fn get(self) -> u32; + +"#, + r#" +/// Sets the value of this change tick. + + #[lua(kind = "MutatingMethod")] + fn set(&mut self, tick: u32) -> (); + +"#, + r#" +/// Returns `true` if this `Tick` occurred since the system's `last_run`. +/// `this_run` is the current tick of the system, used as a reference to help deal with wraparound. + + #[lua(kind = "Method")] + fn is_newer_than( + self, + #[proxy] + last_run: bevy::ecs::component::Tick, + #[proxy] + this_run: bevy::ecs::component::Tick, + ) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Tick {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::ecs::component::ComponentTicks", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::ecs::component::ComponentTicks; + +"#, + r#" +/// Returns `true` if the component or resource was added after the system last ran +/// (or the system is running for the first time). + + #[lua(kind = "Method")] + fn is_added( + &self, + #[proxy] + last_run: bevy::ecs::component::Tick, + #[proxy] + this_run: bevy::ecs::component::Tick, + ) -> bool; + +"#, + r#" +/// Returns `true` if the component or resource was added or mutably dereferenced after the system last ran +/// (or the system is running for the first time). + + #[lua(kind = "Method")] + fn is_changed( + &self, + #[proxy] + last_run: bevy::ecs::component::Tick, + #[proxy] + this_run: bevy::ecs::component::Tick, + ) -> bool; + +"#, + r#" +/// Returns the tick recording the time this component or resource was most recently changed. + + #[lua(kind = "Method", output(proxy))] + fn last_changed_tick(&self) -> bevy::ecs::component::Tick; + +"#, + r#" +/// Returns the tick recording the time this component or resource was added. + + #[lua(kind = "Method", output(proxy))] + fn added_tick(&self) -> bevy::ecs::component::Tick; + +"#, + r#" +/// Manually sets the change tick. +/// This is normally done automatically via the [`DerefMut`](std::ops::DerefMut) implementation +/// on [`Mut`](crate::change_detection::Mut), [`ResMut`](crate::change_detection::ResMut), etc. +/// However, components and resources that make use of interior mutability might require manual updates. +/// # Example +/// ```no_run +/// # use bevy_ecs::{world::World, component::ComponentTicks}; +/// let world: World = unimplemented!(); +/// let component_ticks: ComponentTicks = unimplemented!(); +/// component_ticks.set_changed(world.read_change_tick()); +/// ``` + + #[lua(kind = "MutatingMethod")] + fn set_changed(&mut self, #[proxy] change_tick: bevy::ecs::component::Tick) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct ComponentTicks {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::ecs::identifier::Identifier", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::ecs::identifier::Identifier; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &identifier::Identifier) -> bool; + +"#, + r#" +/// Returns the value of the low segment of the [`Identifier`]. + + #[lua(kind = "Method")] + fn low(self) -> u32; + +"#, + r#" +/// Returns the masked value of the high segment of the [`Identifier`]. +/// Does not include the flag bits. + + #[lua(kind = "Method")] + fn masked_high(self) -> u32; + +"#, + r#" +/// Convert the [`Identifier`] into a `u64`. + + #[lua(kind = "Method")] + fn to_bits(self) -> u64; + +"#, + r#" +/// Convert a `u64` into an [`Identifier`]. +/// # Panics +/// This method will likely panic if given `u64` values that did not come from [`Identifier::to_bits`]. + + #[lua(kind = "Function", output(proxy))] + fn from_bits(value: u64) -> bevy::ecs::identifier::Identifier; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Identifier {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::ecs::entity::EntityHash", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::ecs::entity::EntityHash; + +"#] +)] +struct EntityHash {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::ecs::removal_detection::RemovedComponentEntity", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::ecs::removal_detection::RemovedComponentEntity; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct RemovedComponentEntity(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy(derive(), remote = "bevy::ecs::system::SystemIdMarker", functions[])] +struct SystemIdMarker {} +#[derive(Default)] +pub(crate) struct Globals; +impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { + fn add_instances< + 'lua, + T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, + >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { + instances + .add_instance( + "Entity", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "ComponentId", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Tick", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Identifier", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + Ok(()) + } +} +pub struct BevyEcsAPIProvider; +impl bevy_mod_scripting_core::hosts::APIProvider for BevyEcsAPIProvider { + type APITarget = std::sync::Mutex; + type ScriptContext = std::sync::Mutex; + type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; + fn attach_api( + &mut self, + ctx: &mut Self::APITarget, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); + bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) + .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( + e.to_string(), + )) + } + fn get_doc_fragment(&self) -> Option { + Some( + bevy_mod_scripting_lua::docs::LuaDocFragment::new( + "BevyEcsAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaComponentId, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaIdentifier, + >, + >() + .process_type::() + .process_type::() + .process_type::() + }, + ), + ) + } + fn setup_script( + &mut self, + script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn setup_script_runtime( + &mut self, + world_ptr: bevy_mod_scripting_core::world::WorldPointer, + _script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn register_with_app(&self, app: &mut bevy::app::App) { + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::< + bevy::ecs::removal_detection::RemovedComponentEntity, + >(); + app.register_foreign_lua_type::(); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs new file mode 100644 index 0000000000..2cb1efa99e --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs @@ -0,0 +1,161 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use super::bevy_ecs::*; +use super::bevy_reflect::*; +use super::bevy_core::*; +extern crate self as bevy_script_api; +use bevy_script_api::{ + lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "bevy::hierarchy::prelude::Children", + functions[r#" +/// Swaps the child at `a_index` with the child at `b_index`. + + #[lua(kind = "MutatingMethod")] + fn swap(&mut self, a_index: usize, b_index: usize) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Children(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "bevy::hierarchy::prelude::Parent", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &components::parent::Parent) -> bool; + +"#, + r#" +/// Gets the [`Entity`] ID of the parent. + + #[lua(kind = "Method", output(proxy))] + fn get(&self) -> bevy::ecs::entity::Entity; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Parent(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::hierarchy::HierarchyEvent", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &events::HierarchyEvent) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::hierarchy::HierarchyEvent; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct HierarchyEvent {} +#[derive(Default)] +pub(crate) struct Globals; +impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { + fn add_instances< + 'lua, + T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, + >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { + Ok(()) + } +} +pub struct BevyHierarchyAPIProvider; +impl bevy_mod_scripting_core::hosts::APIProvider for BevyHierarchyAPIProvider { + type APITarget = std::sync::Mutex; + type ScriptContext = std::sync::Mutex; + type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; + fn attach_api( + &mut self, + ctx: &mut Self::APITarget, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); + bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) + .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( + e.to_string(), + )) + } + fn get_doc_fragment(&self) -> Option { + Some( + bevy_mod_scripting_lua::docs::LuaDocFragment::new( + "BevyHierarchyAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + .process_type::() + .process_type::() + }, + ), + ) + } + fn setup_script( + &mut self, + script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn setup_script_runtime( + &mut self, + world_ptr: bevy_mod_scripting_core::world::WorldPointer, + _script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn register_with_app(&self, app: &mut bevy::app::App) { + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs new file mode 100644 index 0000000000..f13ae2f8ef --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs @@ -0,0 +1,1846 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use super::bevy_ecs::*; +use super::bevy_reflect::*; +use super::bevy_core::*; +use super::bevy_math::*; +extern crate self as bevy_script_api; +use bevy_script_api::{ + lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "bevy::input::gamepad::Gamepad", + functions[r#" +/// Returns the left stick as a [`Vec2`] + + #[lua(kind = "Method", output(proxy))] + fn left_stick(&self) -> bevy::math::Vec2; + +"#, + r#" +/// Returns the right stick as a [`Vec2`] + + #[lua(kind = "Method", output(proxy))] + fn right_stick(&self) -> bevy::math::Vec2; + +"#, + r#" +/// Returns the directional pad as a [`Vec2`] + + #[lua(kind = "Method", output(proxy))] + fn dpad(&self) -> bevy::math::Vec2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Gamepad { + vendor_id: std::option::Option, + product_id: std::option::Option, + digital: ReflectedValue, + analog: ReflectedValue, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::GamepadAxis", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gamepad::GamepadAxis) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::GamepadAxis; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct GamepadAxis {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::GamepadButton", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::GamepadButton; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gamepad::GamepadButton) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct GamepadButton {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::GamepadSettings", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::GamepadSettings; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct GamepadSettings { + #[lua(output(proxy))] + default_button_settings: bevy::input::gamepad::ButtonSettings, + #[lua(output(proxy))] + default_axis_settings: bevy::input::gamepad::AxisSettings, + #[lua(output(proxy))] + default_button_axis_settings: bevy::input::gamepad::ButtonAxisSettings, + button_settings: ReflectedValue, + axis_settings: ReflectedValue, + button_axis_settings: ReflectedValue, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::keyboard::KeyCode", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &keyboard::KeyCode) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::keyboard::KeyCode; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct KeyCode {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::mouse::MouseButton", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::mouse::MouseButton; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &mouse::MouseButton) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct MouseButton {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::touch::TouchInput", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::touch::TouchInput; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &touch::TouchInput) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct TouchInput { + #[lua(output(proxy))] + phase: bevy::input::touch::TouchPhase, + #[lua(output(proxy))] + position: bevy::math::Vec2, + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, + force: ReflectedValue, + id: u64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::keyboard::KeyboardFocusLost", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &keyboard::KeyboardFocusLost) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::keyboard::KeyboardFocusLost; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct KeyboardFocusLost {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::keyboard::KeyboardInput", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &keyboard::KeyboardInput) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::keyboard::KeyboardInput; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct KeyboardInput { + #[lua(output(proxy))] + key_code: bevy::input::keyboard::KeyCode, + #[lua(output(proxy))] + logical_key: bevy::input::keyboard::Key, + #[lua(output(proxy))] + state: bevy::input::ButtonState, + repeat: bool, + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::mouse::AccumulatedMouseMotion", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &mouse::AccumulatedMouseMotion) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::mouse::AccumulatedMouseMotion; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AccumulatedMouseMotion { + #[lua(output(proxy))] + delta: bevy::math::Vec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::mouse::AccumulatedMouseScroll", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::mouse::AccumulatedMouseScroll; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &mouse::AccumulatedMouseScroll) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AccumulatedMouseScroll { + #[lua(output(proxy))] + unit: bevy::input::mouse::MouseScrollUnit, + #[lua(output(proxy))] + delta: bevy::math::Vec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::mouse::MouseButtonInput", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &mouse::MouseButtonInput) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::mouse::MouseButtonInput; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct MouseButtonInput { + #[lua(output(proxy))] + button: bevy::input::mouse::MouseButton, + #[lua(output(proxy))] + state: bevy::input::ButtonState, + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::mouse::MouseMotion", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &mouse::MouseMotion) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::mouse::MouseMotion; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct MouseMotion { + #[lua(output(proxy))] + delta: bevy::math::Vec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::mouse::MouseWheel", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::mouse::MouseWheel; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &mouse::MouseWheel) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct MouseWheel { + #[lua(output(proxy))] + unit: bevy::input::mouse::MouseScrollUnit, + x: f32, + y: f32, + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::GamepadAxisChangedEvent", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gamepad::GamepadAxisChangedEvent) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::GamepadAxisChangedEvent; + +"#, + r#" +/// Creates a new [`GamepadAxisChangedEvent`] + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + entity: bevy::ecs::entity::Entity, + #[proxy] + axis: bevy::input::gamepad::GamepadAxis, + value: f32, + ) -> bevy::input::gamepad::GamepadAxisChangedEvent; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct GamepadAxisChangedEvent { + #[lua(output(proxy))] + entity: bevy::ecs::entity::Entity, + #[lua(output(proxy))] + axis: bevy::input::gamepad::GamepadAxis, + value: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::GamepadButtonChangedEvent", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gamepad::GamepadButtonChangedEvent) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::GamepadButtonChangedEvent; + +"#, + r#" +/// Creates a new [`GamepadButtonChangedEvent`] + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + entity: bevy::ecs::entity::Entity, + #[proxy] + button: bevy::input::gamepad::GamepadButton, + #[proxy] + state: bevy::input::ButtonState, + value: f32, + ) -> bevy::input::gamepad::GamepadButtonChangedEvent; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct GamepadButtonChangedEvent { + #[lua(output(proxy))] + entity: bevy::ecs::entity::Entity, + #[lua(output(proxy))] + button: bevy::input::gamepad::GamepadButton, + #[lua(output(proxy))] + state: bevy::input::ButtonState, + value: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::GamepadButtonStateChangedEvent", + functions[r#" +/// Creates a new [`GamepadButtonStateChangedEvent`] + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + entity: bevy::ecs::entity::Entity, + #[proxy] + button: bevy::input::gamepad::GamepadButton, + #[proxy] + state: bevy::input::ButtonState, + ) -> bevy::input::gamepad::GamepadButtonStateChangedEvent; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::GamepadButtonStateChangedEvent; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gamepad::GamepadButtonStateChangedEvent) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct GamepadButtonStateChangedEvent { + #[lua(output(proxy))] + entity: bevy::ecs::entity::Entity, + #[lua(output(proxy))] + button: bevy::input::gamepad::GamepadButton, + #[lua(output(proxy))] + state: bevy::input::ButtonState, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::GamepadConnection", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gamepad::GamepadConnection) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::GamepadConnection; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct GamepadConnection {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::GamepadConnectionEvent", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::GamepadConnectionEvent; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gamepad::GamepadConnectionEvent) -> bool; + +"#, + r#" +/// Creates a [`GamepadConnectionEvent`]. + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + gamepad: bevy::ecs::entity::Entity, + #[proxy] + connection: bevy::input::gamepad::GamepadConnection, + ) -> bevy::input::gamepad::GamepadConnectionEvent; + +"#, + r#" +/// Is the gamepad connected? + + #[lua(kind = "Method")] + fn connected(&self) -> bool; + +"#, + r#" +/// Is the gamepad disconnected? + + #[lua(kind = "Method")] + fn disconnected(&self) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct GamepadConnectionEvent { + #[lua(output(proxy))] + gamepad: bevy::ecs::entity::Entity, + #[lua(output(proxy))] + connection: bevy::input::gamepad::GamepadConnection, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::GamepadEvent", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gamepad::GamepadEvent) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::GamepadEvent; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct GamepadEvent {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::GamepadInput", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gamepad::GamepadInput) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::GamepadInput; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct GamepadInput {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::GamepadRumbleRequest", + functions[r#" +/// Get the [`Entity`] associated with this request. + + #[lua(kind = "Method", output(proxy))] + fn gamepad(&self) -> bevy::ecs::entity::Entity; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::GamepadRumbleRequest; + +"#] +)] +struct GamepadRumbleRequest {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::RawGamepadAxisChangedEvent", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gamepad::RawGamepadAxisChangedEvent) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::RawGamepadAxisChangedEvent; + +"#, + r#" +/// Creates a [`RawGamepadAxisChangedEvent`]. + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + gamepad: bevy::ecs::entity::Entity, + #[proxy] + axis_type: bevy::input::gamepad::GamepadAxis, + value: f32, + ) -> bevy::input::gamepad::RawGamepadAxisChangedEvent; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct RawGamepadAxisChangedEvent { + #[lua(output(proxy))] + gamepad: bevy::ecs::entity::Entity, + #[lua(output(proxy))] + axis: bevy::input::gamepad::GamepadAxis, + value: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::RawGamepadButtonChangedEvent", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::RawGamepadButtonChangedEvent; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gamepad::RawGamepadButtonChangedEvent) -> bool; + +"#, + r#" +/// Creates a [`RawGamepadButtonChangedEvent`]. + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + gamepad: bevy::ecs::entity::Entity, + #[proxy] + button_type: bevy::input::gamepad::GamepadButton, + value: f32, + ) -> bevy::input::gamepad::RawGamepadButtonChangedEvent; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct RawGamepadButtonChangedEvent { + #[lua(output(proxy))] + gamepad: bevy::ecs::entity::Entity, + #[lua(output(proxy))] + button: bevy::input::gamepad::GamepadButton, + value: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::RawGamepadEvent", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gamepad::RawGamepadEvent) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::RawGamepadEvent; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct RawGamepadEvent {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gestures::PinchGesture", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gestures::PinchGesture) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gestures::PinchGesture; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct PinchGesture(f32); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gestures::RotationGesture", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gestures::RotationGesture) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gestures::RotationGesture; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct RotationGesture(f32); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gestures::DoubleTapGesture", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gestures::DoubleTapGesture) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gestures::DoubleTapGesture; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct DoubleTapGesture {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gestures::PanGesture", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gestures::PanGesture; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gestures::PanGesture) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct PanGesture(#[lua(output(proxy))] bevy::math::Vec2); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::ButtonState", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +/// Is this button pressed? + + #[lua(kind = "Method")] + fn is_pressed(&self) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &ButtonState) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::ButtonState; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct ButtonState {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::ButtonSettings", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gamepad::ButtonSettings) -> bool; + +"#, + r#" +/// Returns `true` if the button is pressed. +/// A button is considered pressed if the `value` passed is greater than or equal to the press threshold. + + #[lua(kind = "Method")] + fn is_pressed(&self, value: f32) -> bool; + +"#, + r#" +/// Returns `true` if the button is released. +/// A button is considered released if the `value` passed is lower than or equal to the release threshold. + + #[lua(kind = "Method")] + fn is_released(&self, value: f32) -> bool; + +"#, + r#" +/// Get the button input threshold above which the button is considered pressed. + + #[lua(kind = "Method")] + fn press_threshold(&self) -> f32; + +"#, + r#" +/// Try to set the button input threshold above which the button is considered pressed. +/// If the value passed is outside the range [release threshold..=1.0], the value will not be changed. +/// Returns the new value of the press threshold. + + #[lua(kind = "MutatingMethod")] + fn set_press_threshold(&mut self, value: f32) -> f32; + +"#, + r#" +/// Get the button input threshold below which the button is considered released. + + #[lua(kind = "Method")] + fn release_threshold(&self) -> f32; + +"#, + r#" +/// Try to set the button input threshold below which the button is considered released. If the +/// value passed is outside the range [0.0..=press threshold], the value will not be changed. +/// Returns the new value of the release threshold. + + #[lua(kind = "MutatingMethod")] + fn set_release_threshold(&mut self, value: f32) -> f32; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::ButtonSettings; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct ButtonSettings {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::AxisSettings", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::AxisSettings; + +"#, + r#" +/// Get the value above which inputs will be rounded up to 1.0. + + #[lua(kind = "Method")] + fn livezone_upperbound(&self) -> f32; + +"#, + r#" +/// Try to set the value above which inputs will be rounded up to 1.0. +/// If the value passed is negative or less than `deadzone_upperbound`, +/// the value will not be changed. +/// Returns the new value of `livezone_upperbound`. + + #[lua(kind = "MutatingMethod")] + fn set_livezone_upperbound(&mut self, value: f32) -> f32; + +"#, + r#" +/// Get the value below which positive inputs will be rounded down to 0.0. + + #[lua(kind = "Method")] + fn deadzone_upperbound(&self) -> f32; + +"#, + r#" +/// Try to set the value below which positive inputs will be rounded down to 0.0. +/// If the value passed is negative or greater than `livezone_upperbound`, +/// the value will not be changed. +/// Returns the new value of `deadzone_upperbound`. + + #[lua(kind = "MutatingMethod")] + fn set_deadzone_upperbound(&mut self, value: f32) -> f32; + +"#, + r#" +/// Get the value below which negative inputs will be rounded down to -1.0. + + #[lua(kind = "Method")] + fn livezone_lowerbound(&self) -> f32; + +"#, + r#" +/// Try to set the value below which negative inputs will be rounded down to -1.0. +/// If the value passed is positive or greater than `deadzone_lowerbound`, +/// the value will not be changed. +/// Returns the new value of `livezone_lowerbound`. + + #[lua(kind = "MutatingMethod")] + fn set_livezone_lowerbound(&mut self, value: f32) -> f32; + +"#, + r#" +/// Get the value above which inputs will be rounded up to 0.0. + + #[lua(kind = "Method")] + fn deadzone_lowerbound(&self) -> f32; + +"#, + r#" +/// Try to set the value above which inputs will be rounded up to 0.0. +/// If the value passed is less than -1.0 or less than `livezone_lowerbound`, +/// the value will not be changed. +/// Returns the new value of `deadzone_lowerbound`. + + #[lua(kind = "MutatingMethod")] + fn set_deadzone_lowerbound(&mut self, value: f32) -> f32; + +"#, + r#" +/// Get the minimum value by which input must change before the change is registered. + + #[lua(kind = "Method")] + fn threshold(&self) -> f32; + +"#, + r#" +/// Try to set the minimum value by which input must change before the changes will be applied. +/// If the value passed is not within [0.0..=2.0], the value will not be changed. +/// Returns the new value of threshold. + + #[lua(kind = "MutatingMethod")] + fn set_threshold(&mut self, value: f32) -> f32; + +"#, + r#" +/// Clamps the `raw_value` according to the `AxisSettings`. + + #[lua(kind = "Method")] + fn clamp(&self, new_value: f32) -> f32; + +"#, + r#" +/// Filters the `new_value` based on the `old_value`, according to the [`AxisSettings`]. +/// Returns the clamped `new_value` if the change exceeds the settings threshold, +/// and `None` otherwise. + + #[lua(kind = "Method")] + fn filter( + &self, + new_value: f32, + old_value: std::option::Option, + ) -> std::option::Option; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gamepad::AxisSettings) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AxisSettings {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::ButtonAxisSettings", + functions[r#" +/// Filters the `new_value` based on the `old_value`, according to the [`ButtonAxisSettings`]. +/// Returns the clamped `new_value`, according to the [`ButtonAxisSettings`], if the change +/// exceeds the settings threshold, and `None` otherwise. + + #[lua(kind = "Method")] + fn filter( + &self, + new_value: f32, + old_value: std::option::Option, + ) -> std::option::Option; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::ButtonAxisSettings; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct ButtonAxisSettings { + high: f32, + low: f32, + threshold: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::gamepad::GamepadRumbleIntensity", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::gamepad::GamepadRumbleIntensity; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &gamepad::GamepadRumbleIntensity) -> bool; + +"#, + r#" +/// Creates a new rumble intensity with weak motor intensity set to the given value. +/// Clamped within the `0.0` to `1.0` range. + + #[lua(kind = "Function", output(proxy))] + fn weak_motor(intensity: f32) -> bevy::input::gamepad::GamepadRumbleIntensity; + +"#, + r#" +/// Creates a new rumble intensity with strong motor intensity set to the given value. +/// Clamped within the `0.0` to `1.0` range. + + #[lua(kind = "Function", output(proxy))] + fn strong_motor(intensity: f32) -> bevy::input::gamepad::GamepadRumbleIntensity; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct GamepadRumbleIntensity { + strong_motor: f32, + weak_motor: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::keyboard::Key", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::keyboard::Key; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &keyboard::Key) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Key {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::keyboard::NativeKeyCode", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::keyboard::NativeKeyCode; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &keyboard::NativeKeyCode) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct NativeKeyCode {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::keyboard::NativeKey", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &keyboard::NativeKey) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::keyboard::NativeKey; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct NativeKey {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::mouse::MouseScrollUnit", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::mouse::MouseScrollUnit; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &mouse::MouseScrollUnit) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct MouseScrollUnit {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::touch::TouchPhase", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &touch::TouchPhase) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::touch::TouchPhase; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct TouchPhase {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::input::touch::ForceTouch", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::input::touch::ForceTouch; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &touch::ForceTouch) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct ForceTouch {} +#[derive(Default)] +pub(crate) struct Globals; +impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { + fn add_instances< + 'lua, + T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, + >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { + instances + .add_instance( + "GamepadAxisChangedEvent", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaGamepadAxisChangedEvent, + >::new, + )?; + instances + .add_instance( + "GamepadButtonChangedEvent", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaGamepadButtonChangedEvent, + >::new, + )?; + instances + .add_instance( + "GamepadButtonStateChangedEvent", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaGamepadButtonStateChangedEvent, + >::new, + )?; + instances + .add_instance( + "GamepadConnectionEvent", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaGamepadConnectionEvent, + >::new, + )?; + instances + .add_instance( + "RawGamepadAxisChangedEvent", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaRawGamepadAxisChangedEvent, + >::new, + )?; + instances + .add_instance( + "RawGamepadButtonChangedEvent", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaRawGamepadButtonChangedEvent, + >::new, + )?; + instances + .add_instance( + "GamepadRumbleIntensity", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaGamepadRumbleIntensity, + >::new, + )?; + Ok(()) + } +} +pub struct BevyInputAPIProvider; +impl bevy_mod_scripting_core::hosts::APIProvider for BevyInputAPIProvider { + type APITarget = std::sync::Mutex; + type ScriptContext = std::sync::Mutex; + type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; + fn attach_api( + &mut self, + ctx: &mut Self::APITarget, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); + bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) + .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( + e.to_string(), + )) + } + fn get_doc_fragment(&self) -> Option { + Some( + bevy_mod_scripting_lua::docs::LuaDocFragment::new( + "BevyInputAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaGamepadAxisChangedEvent, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaGamepadButtonChangedEvent, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaGamepadButtonStateChangedEvent, + >, + >() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaGamepadConnectionEvent, + >, + >() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaRawGamepadAxisChangedEvent, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaRawGamepadButtonChangedEvent, + >, + >() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaGamepadRumbleIntensity, + >, + >() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + }, + ), + ) + } + fn setup_script( + &mut self, + script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn setup_script_runtime( + &mut self, + world_ptr: bevy_mod_scripting_core::world::WorldPointer, + _script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn register_with_app(&self, app: &mut bevy::app::App) { + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::< + bevy::input::gamepad::GamepadButtonChangedEvent, + >(); + app.register_foreign_lua_type::< + bevy::input::gamepad::GamepadButtonStateChangedEvent, + >(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::< + bevy::input::gamepad::RawGamepadAxisChangedEvent, + >(); + app.register_foreign_lua_type::< + bevy::input::gamepad::RawGamepadButtonChangedEvent, + >(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs new file mode 100644 index 0000000000..822cdb30a3 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs @@ -0,0 +1,5532 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use super::bevy_reflect::*; +extern crate self as bevy_script_api; +use bevy_script_api::{ + lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::AspectRatio", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &aspect_ratio::AspectRatio) -> bool; + +"#, + r#" +/// Returns the aspect ratio as a f32 value. + + #[lua(kind = "Method")] + fn ratio(&self) -> f32; + +"#, + r#" +/// Returns the inverse of this aspect ratio (height/width). + + #[lua(kind = "Method", output(proxy))] + fn inverse(&self) -> bevy::math::AspectRatio; + +"#, + r#" +/// Returns true if the aspect ratio represents a landscape orientation. + + #[lua(kind = "Method")] + fn is_landscape(&self) -> bool; + +"#, + r#" +/// Returns true if the aspect ratio represents a portrait orientation. + + #[lua(kind = "Method")] + fn is_portrait(&self) -> bool; + +"#, + r#" +/// Returns true if the aspect ratio is exactly square. + + #[lua(kind = "Method")] + fn is_square(&self) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::AspectRatio; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AspectRatio(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::CompassOctant", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::CompassOctant; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &compass::CompassOctant) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct CompassOctant {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::CompassQuadrant", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &compass::CompassQuadrant) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::CompassQuadrant; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct CompassQuadrant {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Isometry2d", + functions[r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Isometry2d) -> bevy::math::Isometry2d; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::Isometry2d; + +"#, + r#" +/// Create a two-dimensional isometry from a rotation and a translation. + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + translation: bevy::math::prelude::Vec2, + #[proxy] + rotation: bevy::math::Rot2, + ) -> bevy::math::Isometry2d; + +"#, + r#" +/// Create a two-dimensional isometry from a rotation. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation(#[proxy] rotation: bevy::math::Rot2) -> bevy::math::Isometry2d; + +"#, + r#" +/// Create a two-dimensional isometry from a translation. + + #[lua(kind = "Function", output(proxy))] + fn from_translation( + #[proxy] + translation: bevy::math::prelude::Vec2, + ) -> bevy::math::Isometry2d; + +"#, + r#" +/// Create a two-dimensional isometry from a translation with the given `x` and `y` components. + + #[lua(kind = "Function", output(proxy))] + fn from_xy(x: f32, y: f32) -> bevy::math::Isometry2d; + +"#, + r#" +/// The inverse isometry that undoes this one. + + #[lua(kind = "Method", output(proxy))] + fn inverse(&self) -> bevy::math::Isometry2d; + +"#, + r#" +/// Compute `iso1.inverse() * iso2` in a more efficient way for one-shot cases. +/// If the same isometry is used multiple times, it is more efficient to instead compute +/// the inverse once and use that for each transformation. + + #[lua(kind = "Method", output(proxy))] + fn inverse_mul( + &self, + #[proxy] + rhs: bevy::math::Isometry2d, + ) -> bevy::math::Isometry2d; + +"#, + r#" +/// Transform a point by rotating and translating it using this isometry. + + #[lua(kind = "Method", output(proxy))] + fn transform_point( + &self, + #[proxy] + point: bevy::math::prelude::Vec2, + ) -> bevy::math::prelude::Vec2; + +"#, + r#" +/// Transform a point by rotating and translating it using the inverse of this isometry. +/// This is more efficient than `iso.inverse().transform_point(point)` for one-shot cases. +/// If the same isometry is used multiple times, it is more efficient to instead compute +/// the inverse once and use that for each transformation. + + #[lua(kind = "Method", output(proxy))] + fn inverse_transform_point( + &self, + #[proxy] + point: bevy::math::prelude::Vec2, + ) -> bevy::math::prelude::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::prelude::Vec2) -> bevy::math::prelude::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &isometry::Isometry2d) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::prelude::Dir2) -> bevy::math::prelude::Dir2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Isometry2d { + #[lua(output(proxy))] + rotation: bevy::math::Rot2, + #[lua(output(proxy))] + translation: bevy::math::prelude::Vec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Isometry3d", + functions[r#" +/// Create a three-dimensional isometry from a rotation. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation( + #[proxy] + rotation: bevy::math::prelude::Quat, + ) -> bevy::math::Isometry3d; + +"#, + r#" +/// Create a three-dimensional isometry from a translation with the given `x`, `y`, and `z` components. + + #[lua(kind = "Function", output(proxy))] + fn from_xyz(x: f32, y: f32, z: f32) -> bevy::math::Isometry3d; + +"#, + r#" +/// The inverse isometry that undoes this one. + + #[lua(kind = "Method", output(proxy))] + fn inverse(&self) -> bevy::math::Isometry3d; + +"#, + r#" +/// Compute `iso1.inverse() * iso2` in a more efficient way for one-shot cases. +/// If the same isometry is used multiple times, it is more efficient to instead compute +/// the inverse once and use that for each transformation. + + #[lua(kind = "Method", output(proxy))] + fn inverse_mul( + &self, + #[proxy] + rhs: bevy::math::Isometry3d, + ) -> bevy::math::Isometry3d; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::prelude::Vec3) -> bevy::math::prelude::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &isometry::Isometry3d) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::Isometry3d; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::prelude::Dir3) -> bevy::math::prelude::Dir3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Isometry3d) -> bevy::math::Isometry3d; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Isometry3d { + #[lua(output(proxy))] + rotation: bevy::math::prelude::Quat, + #[lua(output(proxy))] + translation: bevy::math::Vec3A, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Ray2d", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::Ray2d; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &ray::Ray2d) -> bool; + +"#, + r#" +/// Create a new `Ray2d` from a given origin and direction + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + origin: bevy::math::prelude::Vec2, + #[proxy] + direction: bevy::math::prelude::Dir2, + ) -> bevy::math::Ray2d; + +"#, + r#" +/// Get a point at a given distance along the ray + + #[lua(kind = "Method", output(proxy))] + fn get_point(&self, distance: f32) -> bevy::math::prelude::Vec2; + +"#, + r#" +/// Get the distance to a plane if the ray intersects it + + #[lua(kind = "Method")] + fn intersect_plane( + &self, + #[proxy] + plane_origin: bevy::math::prelude::Vec2, + #[proxy] + plane: bevy::math::primitives::Plane2d, + ) -> std::option::Option; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Ray2d { + #[lua(output(proxy))] + origin: bevy::math::prelude::Vec2, + #[lua(output(proxy))] + direction: bevy::math::prelude::Dir2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Ray3d", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::Ray3d; + +"#, + r#" +/// Create a new `Ray3d` from a given origin and direction + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + origin: bevy::math::prelude::Vec3, + #[proxy] + direction: bevy::math::prelude::Dir3, + ) -> bevy::math::Ray3d; + +"#, + r#" +/// Get a point at a given distance along the ray + + #[lua(kind = "Method", output(proxy))] + fn get_point(&self, distance: f32) -> bevy::math::prelude::Vec3; + +"#, + r#" +/// Get the distance to a plane if the ray intersects it + + #[lua(kind = "Method")] + fn intersect_plane( + &self, + #[proxy] + plane_origin: bevy::math::prelude::Vec3, + #[proxy] + plane: bevy::math::primitives::InfinitePlane3d, + ) -> std::option::Option; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &ray::Ray3d) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Ray3d { + #[lua(output(proxy))] + origin: bevy::math::prelude::Vec3, + #[lua(output(proxy))] + direction: bevy::math::prelude::Dir3, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Rot2", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::Rot2; + +"#, + r#" +/// Rotates a [`Vec2`] by a [`Rot2`]. + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::prelude::Vec2) -> bevy::math::prelude::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Rot2) -> bevy::math::Rot2; + +"#, + r#" +/// Rotates the [`Dir2`] using a [`Rot2`]. + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul( + self, + #[proxy] + direction: bevy::math::prelude::Dir2, + ) -> bevy::math::prelude::Dir2; + +"#, + r#" +/// Creates a [`Rot2`] from a counterclockwise angle in radians. +/// # Note +/// The input rotation will always be clamped to the range `(-Ï€, Ï€]` by design. +/// # Example +/// ``` +/// # use bevy_math::Rot2; +/// # use approx::assert_relative_eq; +/// # use std::f32::consts::{FRAC_PI_2, PI}; +/// let rot1 = Rot2::radians(3.0 * FRAC_PI_2); +/// let rot2 = Rot2::radians(-FRAC_PI_2); +/// assert_relative_eq!(rot1, rot2); +/// let rot3 = Rot2::radians(PI); +/// assert_relative_eq!(rot1 * rot1, rot3); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn radians(radians: f32) -> bevy::math::Rot2; + +"#, + r#" +/// Creates a [`Rot2`] from a counterclockwise angle in degrees. +/// # Note +/// The input rotation will always be clamped to the range `(-180°, 180°]` by design. +/// # Example +/// ``` +/// # use bevy_math::Rot2; +/// # use approx::assert_relative_eq; +/// let rot1 = Rot2::degrees(270.0); +/// let rot2 = Rot2::degrees(-90.0); +/// assert_relative_eq!(rot1, rot2); +/// let rot3 = Rot2::degrees(180.0); +/// assert_relative_eq!(rot1 * rot1, rot3); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn degrees(degrees: f32) -> bevy::math::Rot2; + +"#, + r#" +/// Creates a [`Rot2`] from a counterclockwise fraction of a full turn of 360 degrees. +/// # Note +/// The input rotation will always be clamped to the range `(-50%, 50%]` by design. +/// # Example +/// ``` +/// # use bevy_math::Rot2; +/// # use approx::assert_relative_eq; +/// let rot1 = Rot2::turn_fraction(0.75); +/// let rot2 = Rot2::turn_fraction(-0.25); +/// assert_relative_eq!(rot1, rot2); +/// let rot3 = Rot2::turn_fraction(0.5); +/// assert_relative_eq!(rot1 * rot1, rot3); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn turn_fraction(fraction: f32) -> bevy::math::Rot2; + +"#, + r#" +/// Creates a [`Rot2`] from the sine and cosine of an angle in radians. +/// The rotation is only valid if `sin * sin + cos * cos == 1.0`. +/// # Panics +/// Panics if `sin * sin + cos * cos != 1.0` when the `glam_assert` feature is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_sin_cos(sin: f32, cos: f32) -> bevy::math::Rot2; + +"#, + r#" +/// Returns the rotation in radians in the `(-pi, pi]` range. + + #[lua(kind = "Method")] + fn as_radians(self) -> f32; + +"#, + r#" +/// Returns the rotation in degrees in the `(-180, 180]` range. + + #[lua(kind = "Method")] + fn as_degrees(self) -> f32; + +"#, + r#" +/// Returns the rotation as a fraction of a full 360 degree turn. + + #[lua(kind = "Method")] + fn as_turn_fraction(self) -> f32; + +"#, + r#" +/// Returns the sine and cosine of the rotation angle in radians. + + #[lua(kind = "Method")] + fn sin_cos(self) -> (f32, f32); + +"#, + r#" +/// Computes the length or norm of the complex number used to represent the rotation. +/// The length is typically expected to be `1.0`. Unexpectedly denormalized rotations +/// can be a result of incorrect construction or floating point error caused by +/// successive operations. + + #[lua(kind = "Method")] + fn length(self) -> f32; + +"#, + r#" +/// Computes the squared length or norm of the complex number used to represent the rotation. +/// This is generally faster than [`Rot2::length()`], as it avoids a square +/// root operation. +/// The length is typically expected to be `1.0`. Unexpectedly denormalized rotations +/// can be a result of incorrect construction or floating point error caused by +/// successive operations. + + #[lua(kind = "Method")] + fn length_squared(self) -> f32; + +"#, + r#" +/// Computes `1.0 / self.length()`. +/// For valid results, `self` must _not_ have a length of zero. + + #[lua(kind = "Method")] + fn length_recip(self) -> f32; + +"#, + r#" +/// Returns `self` with a length of `1.0`. +/// Note that [`Rot2`] should typically already be normalized by design. +/// Manual normalization is only needed when successive operations result in +/// accumulated floating point error, or if the rotation was constructed +/// with invalid values. +/// # Panics +/// Panics if `self` has a length of zero, NaN, or infinity when debug assertions are enabled. + + #[lua(kind = "Method", output(proxy))] + fn normalize(self) -> bevy::math::Rot2; + +"#, + r#" +/// Returns `self` after an approximate normalization, assuming the value is already nearly normalized. +/// Useful for preventing numerical error accumulation. +/// See [`Dir3::fast_renormalize`](crate::Dir3::fast_renormalize) for an example of when such error accumulation might occur. + + #[lua(kind = "Method", output(proxy))] + fn fast_renormalize(self) -> bevy::math::Rot2; + +"#, + r#" +/// Returns `true` if the rotation is neither infinite nor NaN. + + #[lua(kind = "Method")] + fn is_finite(self) -> bool; + +"#, + r#" +/// Returns `true` if the rotation is NaN. + + #[lua(kind = "Method")] + fn is_nan(self) -> bool; + +"#, + r#" +/// Returns whether `self` has a length of `1.0` or not. +/// Uses a precision threshold of approximately `1e-4`. + + #[lua(kind = "Method")] + fn is_normalized(self) -> bool; + +"#, + r#" +/// Returns `true` if the rotation is near [`Rot2::IDENTITY`]. + + #[lua(kind = "Method")] + fn is_near_identity(self) -> bool; + +"#, + r#" +/// Returns the angle in radians needed to make `self` and `other` coincide. + + #[lua(kind = "Method")] + fn angle_between(self, #[proxy] other: bevy::math::Rot2) -> f32; + +"#, + r#" +/// Returns the inverse of the rotation. This is also the conjugate +/// of the unit complex number representing the rotation. + + #[lua(kind = "Method", output(proxy))] + fn inverse(self) -> bevy::math::Rot2; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on +/// the value `s`, and normalizes the rotation afterwards. +/// When `s == 0.0`, the result will be equal to `self`. +/// When `s == 1.0`, the result will be equal to `rhs`. +/// This is slightly more efficient than [`slerp`](Self::slerp), and produces a similar result +/// when the difference between the two rotations is small. At larger differences, +/// the result resembles a kind of ease-in-out effect. +/// If you would like the angular velocity to remain constant, consider using [`slerp`](Self::slerp) instead. +/// # Details +/// `nlerp` corresponds to computing an angle for a point at position `s` on a line drawn +/// between the endpoints of the arc formed by `self` and `rhs` on a unit circle, +/// and normalizing the result afterwards. +/// Note that if the angles are opposite like 0 and Ï€, the line will pass through the origin, +/// and the resulting angle will always be either `self` or `rhs` depending on `s`. +/// If `s` happens to be `0.5` in this case, a valid rotation cannot be computed, and `self` +/// will be returned as a fallback. +/// # Example +/// ``` +/// # use bevy_math::Rot2; +/// # +/// let rot1 = Rot2::IDENTITY; +/// let rot2 = Rot2::degrees(135.0); +/// let result1 = rot1.nlerp(rot2, 1.0 / 3.0); +/// assert_eq!(result1.as_degrees(), 28.675055); +/// let result2 = rot1.nlerp(rot2, 0.5); +/// assert_eq!(result2.as_degrees(), 67.5); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn nlerp(self, #[proxy] end: bevy::math::Rot2, s: f32) -> bevy::math::Rot2; + +"#, + r#" +/// Performs a spherical linear interpolation between `self` and `end` +/// based on the value `s`. +/// This corresponds to interpolating between the two angles at a constant angular velocity. +/// When `s == 0.0`, the result will be equal to `self`. +/// When `s == 1.0`, the result will be equal to `rhs`. +/// If you would like the rotation to have a kind of ease-in-out effect, consider +/// using the slightly more efficient [`nlerp`](Self::nlerp) instead. +/// # Example +/// ``` +/// # use bevy_math::Rot2; +/// # +/// let rot1 = Rot2::IDENTITY; +/// let rot2 = Rot2::degrees(135.0); +/// let result1 = rot1.slerp(rot2, 1.0 / 3.0); +/// assert_eq!(result1.as_degrees(), 45.0); +/// let result2 = rot1.slerp(rot2, 0.5); +/// assert_eq!(result2.as_degrees(), 67.5); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn slerp(self, #[proxy] end: bevy::math::Rot2, s: f32) -> bevy::math::Rot2; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &rotation2d::Rot2) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Rot2 { + cos: f32, + sin: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::prelude::Dir2", + functions[r#" +/// Create a [`Dir2`] from a [`Vec2`] that is already normalized. +/// # Warning +/// `value` must be normalized, i.e its length must be `1.0`. + + #[lua(kind = "Function", output(proxy))] + fn new_unchecked( + #[proxy] + value: bevy::math::prelude::Vec2, + ) -> bevy::math::prelude::Dir2; + +"#, + r#" +/// Create a direction from its `x` and `y` components, assuming the resulting vector is normalized. +/// # Warning +/// The vector produced from `x` and `y` must be normalized, i.e its length must be `1.0`. + + #[lua(kind = "Function", output(proxy))] + fn from_xy_unchecked(x: f32, y: f32) -> bevy::math::prelude::Dir2; + +"#, + r#" +/// Returns the inner [`Vec2`] + + #[lua(kind = "Method", output(proxy))] + fn as_vec2(&self) -> bevy::math::prelude::Vec2; + +"#, + r#" +/// Performs a spherical linear interpolation between `self` and `rhs` +/// based on the value `s`. +/// This corresponds to interpolating between the two directions at a constant angular velocity. +/// When `s == 0.0`, the result will be equal to `self`. +/// When `s == 1.0`, the result will be equal to `rhs`. +/// # Example +/// ``` +/// # use bevy_math::Dir2; +/// # use approx::{assert_relative_eq, RelativeEq}; +/// # +/// let dir1 = Dir2::X; +/// let dir2 = Dir2::Y; +/// let result1 = dir1.slerp(dir2, 1.0 / 3.0); +/// assert_relative_eq!(result1, Dir2::from_xy(0.75_f32.sqrt(), 0.5).unwrap()); +/// let result2 = dir1.slerp(dir2, 0.5); +/// assert_relative_eq!(result2, Dir2::from_xy(0.5_f32.sqrt(), 0.5_f32.sqrt()).unwrap()); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn slerp( + self, + #[proxy] + rhs: bevy::math::prelude::Dir2, + s: f32, + ) -> bevy::math::prelude::Dir2; + +"#, + r#" +/// Get the rotation that rotates this direction to `other`. + + #[lua(kind = "Method", output(proxy))] + fn rotation_to(self, #[proxy] other: bevy::math::prelude::Dir2) -> bevy::math::Rot2; + +"#, + r#" +/// Get the rotation that rotates `other` to this direction. + + #[lua(kind = "Method", output(proxy))] + fn rotation_from( + self, + #[proxy] + other: bevy::math::prelude::Dir2, + ) -> bevy::math::Rot2; + +"#, + r#" +/// Get the rotation that rotates the X-axis to this direction. + + #[lua(kind = "Method", output(proxy))] + fn rotation_from_x(self) -> bevy::math::Rot2; + +"#, + r#" +/// Get the rotation that rotates this direction to the X-axis. + + #[lua(kind = "Method", output(proxy))] + fn rotation_to_x(self) -> bevy::math::Rot2; + +"#, + r#" +/// Get the rotation that rotates the Y-axis to this direction. + + #[lua(kind = "Method", output(proxy))] + fn rotation_from_y(self) -> bevy::math::Rot2; + +"#, + r#" +/// Get the rotation that rotates this direction to the Y-axis. + + #[lua(kind = "Method", output(proxy))] + fn rotation_to_y(self) -> bevy::math::Rot2; + +"#, + r#" +/// Returns `self` after an approximate normalization, assuming the value is already nearly normalized. +/// Useful for preventing numerical error accumulation. +/// See [`Dir3::fast_renormalize`] for an example of when such error accumulation might occur. + + #[lua(kind = "Method", output(proxy))] + fn fast_renormalize(self) -> bevy::math::prelude::Dir2; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &direction::Dir2) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::prelude::Dir2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::prelude::Dir2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f32) -> bevy::math::prelude::Vec2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Dir2(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::prelude::Dir3", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &direction::Dir3) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f32) -> bevy::math::prelude::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::prelude::Dir3; + +"#, + r#" +/// Create a [`Dir3`] from a [`Vec3`] that is already normalized. +/// # Warning +/// `value` must be normalized, i.e its length must be `1.0`. + + #[lua(kind = "Function", output(proxy))] + fn new_unchecked( + #[proxy] + value: bevy::math::prelude::Vec3, + ) -> bevy::math::prelude::Dir3; + +"#, + r#" +/// Create a direction from its `x`, `y`, and `z` components, assuming the resulting vector is normalized. +/// # Warning +/// The vector produced from `x`, `y`, and `z` must be normalized, i.e its length must be `1.0`. + + #[lua(kind = "Function", output(proxy))] + fn from_xyz_unchecked(x: f32, y: f32, z: f32) -> bevy::math::prelude::Dir3; + +"#, + r#" +/// Returns the inner [`Vec3`] + + #[lua(kind = "Method", output(proxy))] + fn as_vec3(&self) -> bevy::math::prelude::Vec3; + +"#, + r#" +/// Performs a spherical linear interpolation between `self` and `rhs` +/// based on the value `s`. +/// This corresponds to interpolating between the two directions at a constant angular velocity. +/// When `s == 0.0`, the result will be equal to `self`. +/// When `s == 1.0`, the result will be equal to `rhs`. +/// # Example +/// ``` +/// # use bevy_math::Dir3; +/// # use approx::{assert_relative_eq, RelativeEq}; +/// # +/// let dir1 = Dir3::X; +/// let dir2 = Dir3::Y; +/// let result1 = dir1.slerp(dir2, 1.0 / 3.0); +/// assert_relative_eq!( +/// result1, +/// Dir3::from_xyz(0.75_f32.sqrt(), 0.5, 0.0).unwrap(), +/// epsilon = 0.000001 +/// ); +/// let result2 = dir1.slerp(dir2, 0.5); +/// assert_relative_eq!(result2, Dir3::from_xyz(0.5_f32.sqrt(), 0.5_f32.sqrt(), 0.0).unwrap()); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn slerp( + self, + #[proxy] + rhs: bevy::math::prelude::Dir3, + s: f32, + ) -> bevy::math::prelude::Dir3; + +"#, + r#" +/// Returns `self` after an approximate normalization, assuming the value is already nearly normalized. +/// Useful for preventing numerical error accumulation. +/// # Example +/// The following seemingly benign code would start accumulating errors over time, +/// leading to `dir` eventually not being normalized anymore. +/// ``` +/// # use bevy_math::prelude::*; +/// # let N: usize = 200; +/// let mut dir = Dir3::X; +/// let quaternion = Quat::from_euler(EulerRot::XYZ, 1.0, 2.0, 3.0); +/// for i in 0..N { +/// dir = quaternion * dir; +/// } +/// ``` +/// Instead, do the following. +/// ``` +/// # use bevy_math::prelude::*; +/// # let N: usize = 200; +/// let mut dir = Dir3::X; +/// let quaternion = Quat::from_euler(EulerRot::XYZ, 1.0, 2.0, 3.0); +/// for i in 0..N { +/// dir = quaternion * dir; +/// dir = dir.fast_renormalize(); +/// } +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn fast_renormalize(self) -> bevy::math::prelude::Dir3; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::prelude::Dir3; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Dir3(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::prelude::Dir3A", + functions[r#" +/// Create a [`Dir3A`] from a [`Vec3A`] that is already normalized. +/// # Warning +/// `value` must be normalized, i.e its length must be `1.0`. + + #[lua(kind = "Function", output(proxy))] + fn new_unchecked(#[proxy] value: bevy::math::Vec3A) -> bevy::math::prelude::Dir3A; + +"#, + r#" +/// Create a direction from its `x`, `y`, and `z` components, assuming the resulting vector is normalized. +/// # Warning +/// The vector produced from `x`, `y`, and `z` must be normalized, i.e its length must be `1.0`. + + #[lua(kind = "Function", output(proxy))] + fn from_xyz_unchecked(x: f32, y: f32, z: f32) -> bevy::math::prelude::Dir3A; + +"#, + r#" +/// Returns the inner [`Vec3A`] + + #[lua(kind = "Method", output(proxy))] + fn as_vec3a(&self) -> bevy::math::Vec3A; + +"#, + r#" +/// Performs a spherical linear interpolation between `self` and `rhs` +/// based on the value `s`. +/// This corresponds to interpolating between the two directions at a constant angular velocity. +/// When `s == 0.0`, the result will be equal to `self`. +/// When `s == 1.0`, the result will be equal to `rhs`. +/// # Example +/// ``` +/// # use bevy_math::Dir3A; +/// # use approx::{assert_relative_eq, RelativeEq}; +/// # +/// let dir1 = Dir3A::X; +/// let dir2 = Dir3A::Y; +/// let result1 = dir1.slerp(dir2, 1.0 / 3.0); +/// assert_relative_eq!( +/// result1, +/// Dir3A::from_xyz(0.75_f32.sqrt(), 0.5, 0.0).unwrap(), +/// epsilon = 0.000001 +/// ); +/// let result2 = dir1.slerp(dir2, 0.5); +/// assert_relative_eq!(result2, Dir3A::from_xyz(0.5_f32.sqrt(), 0.5_f32.sqrt(), 0.0).unwrap()); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn slerp( + self, + #[proxy] + rhs: bevy::math::prelude::Dir3A, + s: f32, + ) -> bevy::math::prelude::Dir3A; + +"#, + r#" +/// Returns `self` after an approximate normalization, assuming the value is already nearly normalized. +/// Useful for preventing numerical error accumulation. +/// See [`Dir3::fast_renormalize`] for an example of when such error accumulation might occur. + + #[lua(kind = "Method", output(proxy))] + fn fast_renormalize(self) -> bevy::math::prelude::Dir3A; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::prelude::Dir3A; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &direction::Dir3A) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::prelude::Dir3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f32) -> bevy::math::Vec3A; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Dir3A(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::prelude::IRect", + functions[r#" +/// Create a new rectangle from two corner points. +/// The two points do not need to be the minimum and/or maximum corners. +/// They only need to be two opposite corners. +/// # Examples +/// ``` +/// # use bevy_math::IRect; +/// let r = IRect::new(0, 4, 10, 6); // w=10 h=2 +/// let r = IRect::new(2, 3, 5, -1); // w=3 h=4 +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new(x0: i32, y0: i32, x1: i32, y1: i32) -> bevy::math::prelude::IRect; + +"#, + r#" +/// Create a new rectangle from two corner points. +/// The two points do not need to be the minimum and/or maximum corners. +/// They only need to be two opposite corners. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// // Unit rect from [0,0] to [1,1] +/// let r = IRect::from_corners(IVec2::ZERO, IVec2::ONE); // w=1 h=1 +/// // Same; the points do not need to be ordered +/// let r = IRect::from_corners(IVec2::ONE, IVec2::ZERO); // w=1 h=1 +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_corners( + #[proxy] + p0: bevy::math::prelude::IVec2, + #[proxy] + p1: bevy::math::prelude::IVec2, + ) -> bevy::math::prelude::IRect; + +"#, + r#" +/// Create a new rectangle from its center and size. +/// # Rounding Behavior +/// If the size contains odd numbers they will be rounded down to the nearest whole number. +/// # Panics +/// This method panics if any of the components of the size is negative. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::from_center_size(IVec2::ZERO, IVec2::new(3, 2)); // w=2 h=2 +/// assert_eq!(r.min, IVec2::splat(-1)); +/// assert_eq!(r.max, IVec2::splat(1)); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_center_size( + #[proxy] + origin: bevy::math::prelude::IVec2, + #[proxy] + size: bevy::math::prelude::IVec2, + ) -> bevy::math::prelude::IRect; + +"#, + r#" +/// Create a new rectangle from its center and half-size. +/// # Panics +/// This method panics if any of the components of the half-size is negative. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::from_center_half_size(IVec2::ZERO, IVec2::ONE); // w=2 h=2 +/// assert_eq!(r.min, IVec2::splat(-1)); +/// assert_eq!(r.max, IVec2::splat(1)); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_center_half_size( + #[proxy] + origin: bevy::math::prelude::IVec2, + #[proxy] + half_size: bevy::math::prelude::IVec2, + ) -> bevy::math::prelude::IRect; + +"#, + r#" +/// Check if the rectangle is empty. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::from_corners(IVec2::ZERO, IVec2::new(0, 1)); // w=0 h=1 +/// assert!(r.is_empty()); +/// ``` + + #[lua(kind = "Method")] + fn is_empty(&self) -> bool; + +"#, + r#" +/// Rectangle width (max.x - min.x). +/// # Examples +/// ``` +/// # use bevy_math::IRect; +/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// assert_eq!(r.width(), 5); +/// ``` + + #[lua(kind = "Method")] + fn width(&self) -> i32; + +"#, + r#" +/// Rectangle height (max.y - min.y). +/// # Examples +/// ``` +/// # use bevy_math::IRect; +/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// assert_eq!(r.height(), 1); +/// ``` + + #[lua(kind = "Method")] + fn height(&self) -> i32; + +"#, + r#" +/// Rectangle size. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// assert_eq!(r.size(), IVec2::new(5, 1)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn size(&self) -> bevy::math::prelude::IVec2; + +"#, + r#" +/// Rectangle half-size. +/// # Rounding Behavior +/// If the full size contains odd numbers they will be rounded down to the nearest whole number when calculating the half size. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::new(0, 0, 4, 3); // w=4 h=3 +/// assert_eq!(r.half_size(), IVec2::new(2, 1)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn half_size(&self) -> bevy::math::prelude::IVec2; + +"#, + r#" +/// The center point of the rectangle. +/// # Rounding Behavior +/// If the (min + max) contains odd numbers they will be rounded down to the nearest whole number when calculating the center. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::new(0, 0, 5, 2); // w=5 h=2 +/// assert_eq!(r.center(), IVec2::new(2, 1)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn center(&self) -> bevy::math::prelude::IVec2; + +"#, + r#" +/// Check if a point lies within this rectangle, inclusive of its edges. +/// # Examples +/// ``` +/// # use bevy_math::IRect; +/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// assert!(r.contains(r.center())); +/// assert!(r.contains(r.min)); +/// assert!(r.contains(r.max)); +/// ``` + + #[lua(kind = "Method")] + fn contains(&self, #[proxy] point: bevy::math::prelude::IVec2) -> bool; + +"#, + r#" +/// Build a new rectangle formed of the union of this rectangle and another rectangle. +/// The union is the smallest rectangle enclosing both rectangles. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r1 = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// let r2 = IRect::new(1, -1, 3, 3); // w=2 h=4 +/// let r = r1.union(r2); +/// assert_eq!(r.min, IVec2::new(0, -1)); +/// assert_eq!(r.max, IVec2::new(5, 3)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn union( + &self, + #[proxy] + other: bevy::math::prelude::IRect, + ) -> bevy::math::prelude::IRect; + +"#, + r#" +/// Build a new rectangle formed of the union of this rectangle and a point. +/// The union is the smallest rectangle enclosing both the rectangle and the point. If the +/// point is already inside the rectangle, this method returns a copy of the rectangle. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// let u = r.union_point(IVec2::new(3, 6)); +/// assert_eq!(u.min, IVec2::ZERO); +/// assert_eq!(u.max, IVec2::new(5, 6)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn union_point( + &self, + #[proxy] + other: bevy::math::prelude::IVec2, + ) -> bevy::math::prelude::IRect; + +"#, + r#" +/// Build a new rectangle formed of the intersection of this rectangle and another rectangle. +/// The intersection is the largest rectangle enclosed in both rectangles. If the intersection +/// is empty, this method returns an empty rectangle ([`IRect::is_empty()`] returns `true`), but +/// the actual values of [`IRect::min`] and [`IRect::max`] are implementation-dependent. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r1 = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// let r2 = IRect::new(1, -1, 3, 3); // w=2 h=4 +/// let r = r1.intersect(r2); +/// assert_eq!(r.min, IVec2::new(1, 0)); +/// assert_eq!(r.max, IVec2::new(3, 1)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn intersect( + &self, + #[proxy] + other: bevy::math::prelude::IRect, + ) -> bevy::math::prelude::IRect; + +"#, + r#" +/// Create a new rectangle by expanding it evenly on all sides. +/// A positive expansion value produces a larger rectangle, +/// while a negative expansion value produces a smaller rectangle. +/// If this would result in zero or negative width or height, [`IRect::EMPTY`] is returned instead. +/// # Examples +/// ``` +/// # use bevy_math::{IRect, IVec2}; +/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 +/// let r2 = r.inflate(3); // w=11 h=7 +/// assert_eq!(r2.min, IVec2::splat(-3)); +/// assert_eq!(r2.max, IVec2::new(8, 4)); +/// let r = IRect::new(0, -1, 4, 3); // w=4 h=4 +/// let r2 = r.inflate(-1); // w=2 h=2 +/// assert_eq!(r2.min, IVec2::new(1, 0)); +/// assert_eq!(r2.max, IVec2::new(3, 2)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn inflate(&self, expansion: i32) -> bevy::math::prelude::IRect; + +"#, + r#" +/// Returns self as [`Rect`] (f32) + + #[lua(kind = "Method", output(proxy))] + fn as_rect(&self) -> bevy::math::prelude::Rect; + +"#, + r#" +/// Returns self as [`URect`] (u32) + + #[lua(kind = "Method", output(proxy))] + fn as_urect(&self) -> bevy::math::prelude::URect; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &rects::irect::IRect) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::prelude::IRect; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct IRect { + #[lua(output(proxy))] + min: bevy::math::prelude::IVec2, + #[lua(output(proxy))] + max: bevy::math::prelude::IVec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::prelude::Rect", + functions[r#" +/// Create a new rectangle from two corner points. +/// The two points do not need to be the minimum and/or maximum corners. +/// They only need to be two opposite corners. +/// # Examples +/// ``` +/// # use bevy_math::Rect; +/// let r = Rect::new(0., 4., 10., 6.); // w=10 h=2 +/// let r = Rect::new(2., 3., 5., -1.); // w=3 h=4 +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new(x0: f32, y0: f32, x1: f32, y1: f32) -> bevy::math::prelude::Rect; + +"#, + r#" +/// Create a new rectangle from two corner points. +/// The two points do not need to be the minimum and/or maximum corners. +/// They only need to be two opposite corners. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// // Unit rect from [0,0] to [1,1] +/// let r = Rect::from_corners(Vec2::ZERO, Vec2::ONE); // w=1 h=1 +/// // Same; the points do not need to be ordered +/// let r = Rect::from_corners(Vec2::ONE, Vec2::ZERO); // w=1 h=1 +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_corners( + #[proxy] + p0: bevy::math::prelude::Vec2, + #[proxy] + p1: bevy::math::prelude::Vec2, + ) -> bevy::math::prelude::Rect; + +"#, + r#" +/// Create a new rectangle from its center and size. +/// # Panics +/// This method panics if any of the components of the size is negative. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::from_center_size(Vec2::ZERO, Vec2::ONE); // w=1 h=1 +/// assert!(r.min.abs_diff_eq(Vec2::splat(-0.5), 1e-5)); +/// assert!(r.max.abs_diff_eq(Vec2::splat(0.5), 1e-5)); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_center_size( + #[proxy] + origin: bevy::math::prelude::Vec2, + #[proxy] + size: bevy::math::prelude::Vec2, + ) -> bevy::math::prelude::Rect; + +"#, + r#" +/// Create a new rectangle from its center and half-size. +/// # Panics +/// This method panics if any of the components of the half-size is negative. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::from_center_half_size(Vec2::ZERO, Vec2::ONE); // w=2 h=2 +/// assert!(r.min.abs_diff_eq(Vec2::splat(-1.), 1e-5)); +/// assert!(r.max.abs_diff_eq(Vec2::splat(1.), 1e-5)); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_center_half_size( + #[proxy] + origin: bevy::math::prelude::Vec2, + #[proxy] + half_size: bevy::math::prelude::Vec2, + ) -> bevy::math::prelude::Rect; + +"#, + r#" +/// Check if the rectangle is empty. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::from_corners(Vec2::ZERO, Vec2::new(0., 1.)); // w=0 h=1 +/// assert!(r.is_empty()); +/// ``` + + #[lua(kind = "Method")] + fn is_empty(&self) -> bool; + +"#, + r#" +/// Rectangle width (max.x - min.x). +/// # Examples +/// ``` +/// # use bevy_math::Rect; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// assert!((r.width() - 5.).abs() <= 1e-5); +/// ``` + + #[lua(kind = "Method")] + fn width(&self) -> f32; + +"#, + r#" +/// Rectangle height (max.y - min.y). +/// # Examples +/// ``` +/// # use bevy_math::Rect; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// assert!((r.height() - 1.).abs() <= 1e-5); +/// ``` + + #[lua(kind = "Method")] + fn height(&self) -> f32; + +"#, + r#" +/// Rectangle size. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// assert!(r.size().abs_diff_eq(Vec2::new(5., 1.), 1e-5)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn size(&self) -> bevy::math::prelude::Vec2; + +"#, + r#" +/// Rectangle half-size. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// assert!(r.half_size().abs_diff_eq(Vec2::new(2.5, 0.5), 1e-5)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn half_size(&self) -> bevy::math::prelude::Vec2; + +"#, + r#" +/// The center point of the rectangle. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// assert!(r.center().abs_diff_eq(Vec2::new(2.5, 0.5), 1e-5)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn center(&self) -> bevy::math::prelude::Vec2; + +"#, + r#" +/// Check if a point lies within this rectangle, inclusive of its edges. +/// # Examples +/// ``` +/// # use bevy_math::Rect; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// assert!(r.contains(r.center())); +/// assert!(r.contains(r.min)); +/// assert!(r.contains(r.max)); +/// ``` + + #[lua(kind = "Method")] + fn contains(&self, #[proxy] point: bevy::math::prelude::Vec2) -> bool; + +"#, + r#" +/// Build a new rectangle formed of the union of this rectangle and another rectangle. +/// The union is the smallest rectangle enclosing both rectangles. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r1 = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// let r2 = Rect::new(1., -1., 3., 3.); // w=2 h=4 +/// let r = r1.union(r2); +/// assert!(r.min.abs_diff_eq(Vec2::new(0., -1.), 1e-5)); +/// assert!(r.max.abs_diff_eq(Vec2::new(5., 3.), 1e-5)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn union( + &self, + #[proxy] + other: bevy::math::prelude::Rect, + ) -> bevy::math::prelude::Rect; + +"#, + r#" +/// Build a new rectangle formed of the union of this rectangle and a point. +/// The union is the smallest rectangle enclosing both the rectangle and the point. If the +/// point is already inside the rectangle, this method returns a copy of the rectangle. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// let u = r.union_point(Vec2::new(3., 6.)); +/// assert!(u.min.abs_diff_eq(Vec2::ZERO, 1e-5)); +/// assert!(u.max.abs_diff_eq(Vec2::new(5., 6.), 1e-5)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn union_point( + &self, + #[proxy] + other: bevy::math::prelude::Vec2, + ) -> bevy::math::prelude::Rect; + +"#, + r#" +/// Build a new rectangle formed of the intersection of this rectangle and another rectangle. +/// The intersection is the largest rectangle enclosed in both rectangles. If the intersection +/// is empty, this method returns an empty rectangle ([`Rect::is_empty()`] returns `true`), but +/// the actual values of [`Rect::min`] and [`Rect::max`] are implementation-dependent. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r1 = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// let r2 = Rect::new(1., -1., 3., 3.); // w=2 h=4 +/// let r = r1.intersect(r2); +/// assert!(r.min.abs_diff_eq(Vec2::new(1., 0.), 1e-5)); +/// assert!(r.max.abs_diff_eq(Vec2::new(3., 1.), 1e-5)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn intersect( + &self, + #[proxy] + other: bevy::math::prelude::Rect, + ) -> bevy::math::prelude::Rect; + +"#, + r#" +/// Create a new rectangle by expanding it evenly on all sides. +/// A positive expansion value produces a larger rectangle, +/// while a negative expansion value produces a smaller rectangle. +/// If this would result in zero or negative width or height, [`Rect::EMPTY`] is returned instead. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 +/// let r2 = r.inflate(3.); // w=11 h=7 +/// assert!(r2.min.abs_diff_eq(Vec2::splat(-3.), 1e-5)); +/// assert!(r2.max.abs_diff_eq(Vec2::new(8., 4.), 1e-5)); +/// let r = Rect::new(0., -1., 6., 7.); // w=6 h=8 +/// let r2 = r.inflate(-2.); // w=11 h=7 +/// assert!(r2.min.abs_diff_eq(Vec2::new(2., 1.), 1e-5)); +/// assert!(r2.max.abs_diff_eq(Vec2::new(4., 5.), 1e-5)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn inflate(&self, expansion: f32) -> bevy::math::prelude::Rect; + +"#, + r#" +/// Build a new rectangle from this one with its coordinates expressed +/// relative to `other` in a normalized ([0..1] x [0..1]) coordinate system. +/// # Examples +/// ``` +/// # use bevy_math::{Rect, Vec2}; +/// let r = Rect::new(2., 3., 4., 6.); +/// let s = Rect::new(0., 0., 10., 10.); +/// let n = r.normalize(s); +/// assert_eq!(n.min.x, 0.2); +/// assert_eq!(n.min.y, 0.3); +/// assert_eq!(n.max.x, 0.4); +/// assert_eq!(n.max.y, 0.6); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn normalize( + &self, + #[proxy] + other: bevy::math::prelude::Rect, + ) -> bevy::math::prelude::Rect; + +"#, + r#" +/// Returns self as [`IRect`] (i32) + + #[lua(kind = "Method", output(proxy))] + fn as_irect(&self) -> bevy::math::prelude::IRect; + +"#, + r#" +/// Returns self as [`URect`] (u32) + + #[lua(kind = "Method", output(proxy))] + fn as_urect(&self) -> bevy::math::prelude::URect; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &rects::rect::Rect) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::prelude::Rect; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Rect { + #[lua(output(proxy))] + min: bevy::math::prelude::Vec2, + #[lua(output(proxy))] + max: bevy::math::prelude::Vec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::prelude::URect", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::prelude::URect; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &rects::urect::URect) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +/// Create a new rectangle from two corner points. +/// The two points do not need to be the minimum and/or maximum corners. +/// They only need to be two opposite corners. +/// # Examples +/// ``` +/// # use bevy_math::URect; +/// let r = URect::new(0, 4, 10, 6); // w=10 h=2 +/// let r = URect::new(2, 4, 5, 0); // w=3 h=4 +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new(x0: u32, y0: u32, x1: u32, y1: u32) -> bevy::math::prelude::URect; + +"#, + r#" +/// Create a new rectangle from two corner points. +/// The two points do not need to be the minimum and/or maximum corners. +/// They only need to be two opposite corners. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// // Unit rect from [0,0] to [1,1] +/// let r = URect::from_corners(UVec2::ZERO, UVec2::ONE); // w=1 h=1 +/// // Same; the points do not need to be ordered +/// let r = URect::from_corners(UVec2::ONE, UVec2::ZERO); // w=1 h=1 +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_corners( + #[proxy] + p0: bevy::math::prelude::UVec2, + #[proxy] + p1: bevy::math::prelude::UVec2, + ) -> bevy::math::prelude::URect; + +"#, + r#" +/// Create a new rectangle from its center and size. +/// # Rounding Behavior +/// If the size contains odd numbers they will be rounded down to the nearest whole number. +/// # Panics +/// This method panics if any of the components of the size is negative or if `origin - (size / 2)` results in any negatives. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::from_center_size(UVec2::ONE, UVec2::splat(2)); // w=2 h=2 +/// assert_eq!(r.min, UVec2::splat(0)); +/// assert_eq!(r.max, UVec2::splat(2)); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_center_size( + #[proxy] + origin: bevy::math::prelude::UVec2, + #[proxy] + size: bevy::math::prelude::UVec2, + ) -> bevy::math::prelude::URect; + +"#, + r#" +/// Create a new rectangle from its center and half-size. +/// # Panics +/// This method panics if any of the components of the half-size is negative or if `origin - half_size` results in any negatives. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::from_center_half_size(UVec2::ONE, UVec2::ONE); // w=2 h=2 +/// assert_eq!(r.min, UVec2::splat(0)); +/// assert_eq!(r.max, UVec2::splat(2)); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_center_half_size( + #[proxy] + origin: bevy::math::prelude::UVec2, + #[proxy] + half_size: bevy::math::prelude::UVec2, + ) -> bevy::math::prelude::URect; + +"#, + r#" +/// Check if the rectangle is empty. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::from_corners(UVec2::ZERO, UVec2::new(0, 1)); // w=0 h=1 +/// assert!(r.is_empty()); +/// ``` + + #[lua(kind = "Method")] + fn is_empty(&self) -> bool; + +"#, + r#" +/// Rectangle width (max.x - min.x). +/// # Examples +/// ``` +/// # use bevy_math::URect; +/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 +/// assert_eq!(r.width(), 5); +/// ``` + + #[lua(kind = "Method")] + fn width(&self) -> u32; + +"#, + r#" +/// Rectangle height (max.y - min.y). +/// # Examples +/// ``` +/// # use bevy_math::URect; +/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 +/// assert_eq!(r.height(), 1); +/// ``` + + #[lua(kind = "Method")] + fn height(&self) -> u32; + +"#, + r#" +/// Rectangle size. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 +/// assert_eq!(r.size(), UVec2::new(5, 1)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn size(&self) -> bevy::math::prelude::UVec2; + +"#, + r#" +/// Rectangle half-size. +/// # Rounding Behavior +/// If the full size contains odd numbers they will be rounded down to the nearest whole number when calculating the half size. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::new(0, 0, 4, 2); // w=4 h=2 +/// assert_eq!(r.half_size(), UVec2::new(2, 1)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn half_size(&self) -> bevy::math::prelude::UVec2; + +"#, + r#" +/// The center point of the rectangle. +/// # Rounding Behavior +/// If the (min + max) contains odd numbers they will be rounded down to the nearest whole number when calculating the center. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::new(0, 0, 4, 2); // w=4 h=2 +/// assert_eq!(r.center(), UVec2::new(2, 1)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn center(&self) -> bevy::math::prelude::UVec2; + +"#, + r#" +/// Check if a point lies within this rectangle, inclusive of its edges. +/// # Examples +/// ``` +/// # use bevy_math::URect; +/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 +/// assert!(r.contains(r.center())); +/// assert!(r.contains(r.min)); +/// assert!(r.contains(r.max)); +/// ``` + + #[lua(kind = "Method")] + fn contains(&self, #[proxy] point: bevy::math::prelude::UVec2) -> bool; + +"#, + r#" +/// Build a new rectangle formed of the union of this rectangle and another rectangle. +/// The union is the smallest rectangle enclosing both rectangles. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r1 = URect::new(0, 0, 5, 1); // w=5 h=1 +/// let r2 = URect::new(1, 0, 3, 8); // w=2 h=4 +/// let r = r1.union(r2); +/// assert_eq!(r.min, UVec2::new(0, 0)); +/// assert_eq!(r.max, UVec2::new(5, 8)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn union( + &self, + #[proxy] + other: bevy::math::prelude::URect, + ) -> bevy::math::prelude::URect; + +"#, + r#" +/// Build a new rectangle formed of the union of this rectangle and a point. +/// The union is the smallest rectangle enclosing both the rectangle and the point. If the +/// point is already inside the rectangle, this method returns a copy of the rectangle. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 +/// let u = r.union_point(UVec2::new(3, 6)); +/// assert_eq!(u.min, UVec2::ZERO); +/// assert_eq!(u.max, UVec2::new(5, 6)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn union_point( + &self, + #[proxy] + other: bevy::math::prelude::UVec2, + ) -> bevy::math::prelude::URect; + +"#, + r#" +/// Build a new rectangle formed of the intersection of this rectangle and another rectangle. +/// The intersection is the largest rectangle enclosed in both rectangles. If the intersection +/// is empty, this method returns an empty rectangle ([`URect::is_empty()`] returns `true`), but +/// the actual values of [`URect::min`] and [`URect::max`] are implementation-dependent. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r1 = URect::new(0, 0, 2, 2); // w=2 h=2 +/// let r2 = URect::new(1, 1, 3, 3); // w=2 h=2 +/// let r = r1.intersect(r2); +/// assert_eq!(r.min, UVec2::new(1, 1)); +/// assert_eq!(r.max, UVec2::new(2, 2)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn intersect( + &self, + #[proxy] + other: bevy::math::prelude::URect, + ) -> bevy::math::prelude::URect; + +"#, + r#" +/// Create a new rectangle by expanding it evenly on all sides. +/// A positive expansion value produces a larger rectangle, +/// while a negative expansion value produces a smaller rectangle. +/// If this would result in zero width or height, [`URect::EMPTY`] is returned instead. +/// # Examples +/// ``` +/// # use bevy_math::{URect, UVec2}; +/// let r = URect::new(4, 4, 6, 6); // w=2 h=2 +/// let r2 = r.inflate(1); // w=4 h=4 +/// assert_eq!(r2.min, UVec2::splat(3)); +/// assert_eq!(r2.max, UVec2::splat(7)); +/// let r = URect::new(4, 4, 8, 8); // w=4 h=4 +/// let r2 = r.inflate(-1); // w=2 h=2 +/// assert_eq!(r2.min, UVec2::splat(5)); +/// assert_eq!(r2.max, UVec2::splat(7)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn inflate(&self, expansion: i32) -> bevy::math::prelude::URect; + +"#, + r#" +/// Returns self as [`Rect`] (f32) + + #[lua(kind = "Method", output(proxy))] + fn as_rect(&self) -> bevy::math::prelude::Rect; + +"#, + r#" +/// Returns self as [`IRect`] (i32) + + #[lua(kind = "Method", output(proxy))] + fn as_irect(&self) -> bevy::math::prelude::IRect; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct URect { + #[lua(output(proxy))] + min: bevy::math::prelude::UVec2, + #[lua(output(proxy))] + max: bevy::math::prelude::UVec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy(derive(), remote = "bevy::math::Affine3", functions[])] +struct Affine3 { + #[lua(output(proxy))] + matrix3: bevy::math::prelude::Mat3, + #[lua(output(proxy))] + translation: bevy::math::prelude::Vec3, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::bounding::Aabb2d", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::bounding::Aabb2d; + +"#, + r#" +/// Constructs an AABB from its center and half-size. + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + center: bevy::math::prelude::Vec2, + #[proxy] + half_size: bevy::math::prelude::Vec2, + ) -> bevy::math::bounding::Aabb2d; + +"#, + r#" +/// Computes the smallest [`BoundingCircle`] containing this [`Aabb2d`]. + + #[lua(kind = "Method", output(proxy))] + fn bounding_circle(&self) -> bevy::math::bounding::BoundingCircle; + +"#, + r#" +/// Finds the point on the AABB that is closest to the given `point`. +/// If the point is outside the AABB, the returned point will be on the perimeter of the AABB. +/// Otherwise, it will be inside the AABB and returned as is. + + #[lua(kind = "Method", output(proxy))] + fn closest_point( + &self, + #[proxy] + point: bevy::math::prelude::Vec2, + ) -> bevy::math::prelude::Vec2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Aabb2d { + #[lua(output(proxy))] + min: bevy::math::prelude::Vec2, + #[lua(output(proxy))] + max: bevy::math::prelude::Vec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::bounding::BoundingCircle", + functions[r#" +/// Constructs a bounding circle from its center and radius. + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + center: bevy::math::prelude::Vec2, + radius: f32, + ) -> bevy::math::bounding::BoundingCircle; + +"#, + r#" +/// Get the radius of the bounding circle + + #[lua(kind = "Method")] + fn radius(&self) -> f32; + +"#, + r#" +/// Computes the smallest [`Aabb2d`] containing this [`BoundingCircle`]. + + #[lua(kind = "Method", output(proxy))] + fn aabb_2d(&self) -> bevy::math::bounding::Aabb2d; + +"#, + r#" +/// Finds the point on the bounding circle that is closest to the given `point`. +/// If the point is outside the circle, the returned point will be on the perimeter of the circle. +/// Otherwise, it will be inside the circle and returned as is. + + #[lua(kind = "Method", output(proxy))] + fn closest_point( + &self, + #[proxy] + point: bevy::math::prelude::Vec2, + ) -> bevy::math::prelude::Vec2; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::bounding::BoundingCircle; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct BoundingCircle { + #[lua(output(proxy))] + center: bevy::math::prelude::Vec2, + #[lua(output(proxy))] + circle: bevy::math::primitives::Circle, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Circle", + functions[r#" +/// Create a new [`Circle`] from a `radius` + + #[lua(kind = "Function", output(proxy))] + fn new(radius: f32) -> bevy::math::primitives::Circle; + +"#, + r#" +/// Get the diameter of the circle + + #[lua(kind = "Method")] + fn diameter(&self) -> f32; + +"#, + r#" +/// Finds the point on the circle that is closest to the given `point`. +/// If the point is outside the circle, the returned point will be on the perimeter of the circle. +/// Otherwise, it will be inside the circle and returned as is. + + #[lua(kind = "Method", output(proxy))] + fn closest_point( + &self, + #[proxy] + point: bevy::math::prelude::Vec2, + ) -> bevy::math::prelude::Vec2; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Circle; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim2::Circle) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Circle { + radius: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Annulus", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Annulus; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim2::Annulus) -> bool; + +"#, + r#" +/// Create a new [`Annulus`] from the radii of the inner and outer circle + + #[lua(kind = "Function", output(proxy))] + fn new(inner_radius: f32, outer_radius: f32) -> bevy::math::primitives::Annulus; + +"#, + r#" +/// Get the diameter of the annulus + + #[lua(kind = "Method")] + fn diameter(&self) -> f32; + +"#, + r#" +/// Get the thickness of the annulus + + #[lua(kind = "Method")] + fn thickness(&self) -> f32; + +"#, + r#" +/// Finds the point on the annulus that is closest to the given `point`: +/// - If the point is outside of the annulus completely, the returned point will be on the outer perimeter. +/// - If the point is inside of the inner circle (hole) of the annulus, the returned point will be on the inner perimeter. +/// - Otherwise, the returned point is overlapping the annulus and returned as is. + + #[lua(kind = "Method", output(proxy))] + fn closest_point( + &self, + #[proxy] + point: bevy::math::prelude::Vec2, + ) -> bevy::math::prelude::Vec2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Annulus { + #[lua(output(proxy))] + inner_circle: bevy::math::primitives::Circle, + #[lua(output(proxy))] + outer_circle: bevy::math::primitives::Circle, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Arc2d", + functions[r#" +/// Create a new [`Arc2d`] from a `radius` and a `half_angle` + + #[lua(kind = "Function", output(proxy))] + fn new(radius: f32, half_angle: f32) -> bevy::math::primitives::Arc2d; + +"#, + r#" +/// Create a new [`Arc2d`] from a `radius` and an `angle` in radians + + #[lua(kind = "Function", output(proxy))] + fn from_radians(radius: f32, angle: f32) -> bevy::math::primitives::Arc2d; + +"#, + r#" +/// Create a new [`Arc2d`] from a `radius` and an `angle` in degrees. + + #[lua(kind = "Function", output(proxy))] + fn from_degrees(radius: f32, angle: f32) -> bevy::math::primitives::Arc2d; + +"#, + r#" +/// Create a new [`Arc2d`] from a `radius` and a `fraction` of a single turn. +/// For instance, `0.5` turns is a semicircle. + + #[lua(kind = "Function", output(proxy))] + fn from_turns(radius: f32, fraction: f32) -> bevy::math::primitives::Arc2d; + +"#, + r#" +/// Get the angle of the arc + + #[lua(kind = "Method")] + fn angle(&self) -> f32; + +"#, + r#" +/// Get the length of the arc + + #[lua(kind = "Method")] + fn length(&self) -> f32; + +"#, + r#" +/// Get the right-hand end point of the arc + + #[lua(kind = "Method", output(proxy))] + fn right_endpoint(&self) -> bevy::math::prelude::Vec2; + +"#, + r#" +/// Get the left-hand end point of the arc + + #[lua(kind = "Method", output(proxy))] + fn left_endpoint(&self) -> bevy::math::prelude::Vec2; + +"#, + r#" +/// Get the midpoint of the arc + + #[lua(kind = "Method", output(proxy))] + fn midpoint(&self) -> bevy::math::prelude::Vec2; + +"#, + r#" +/// Get half the distance between the endpoints (half the length of the chord) + + #[lua(kind = "Method")] + fn half_chord_length(&self) -> f32; + +"#, + r#" +/// Get the distance between the endpoints (the length of the chord) + + #[lua(kind = "Method")] + fn chord_length(&self) -> f32; + +"#, + r#" +/// Get the midpoint of the two endpoints (the midpoint of the chord) + + #[lua(kind = "Method", output(proxy))] + fn chord_midpoint(&self) -> bevy::math::prelude::Vec2; + +"#, + r#" +/// Get the length of the apothem of this arc, that is, +/// the distance from the center of the circle to the midpoint of the chord, in the direction of the midpoint of the arc. +/// Equivalently, the [`radius`](Self::radius) minus the [`sagitta`](Self::sagitta). +/// Note that for a [`major`](Self::is_major) arc, the apothem will be negative. + + #[lua(kind = "Method")] + fn apothem(&self) -> f32; + +"#, + r#" +/// Get the length of the sagitta of this arc, that is, +/// the length of the line between the midpoints of the arc and its chord. +/// Equivalently, the height of the triangle whose base is the chord and whose apex is the midpoint of the arc. +/// The sagitta is also the sum of the [`radius`](Self::radius) and the [`apothem`](Self::apothem). + + #[lua(kind = "Method")] + fn sagitta(&self) -> f32; + +"#, + r#" +/// Produces true if the arc is at most half a circle. +/// **Note:** This is not the negation of [`is_major`](Self::is_major): an exact semicircle is both major and minor. + + #[lua(kind = "Method")] + fn is_minor(&self) -> bool; + +"#, + r#" +/// Produces true if the arc is at least half a circle. +/// **Note:** This is not the negation of [`is_minor`](Self::is_minor): an exact semicircle is both major and minor. + + #[lua(kind = "Method")] + fn is_major(&self) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Arc2d; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim2::Arc2d) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Arc2d { + radius: f32, + half_angle: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Capsule2d", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim2::Capsule2d) -> bool; + +"#, + r#" +/// Create a new `Capsule2d` from a radius and length + + #[lua(kind = "Function", output(proxy))] + fn new(radius: f32, length: f32) -> bevy::math::primitives::Capsule2d; + +"#, + r#" +/// Get the part connecting the semicircular ends of the capsule as a [`Rectangle`] + + #[lua(kind = "Method", output(proxy))] + fn to_inner_rectangle(&self) -> bevy::math::primitives::Rectangle; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Capsule2d; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Capsule2d { + radius: f32, + half_length: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::CircularSector", + functions[r#" +/// Create a new [`CircularSector`] from a `radius` and an `angle` + + #[lua(kind = "Function", output(proxy))] + fn new(radius: f32, angle: f32) -> bevy::math::primitives::CircularSector; + +"#, + r#" +/// Create a new [`CircularSector`] from a `radius` and an `angle` in radians. + + #[lua(kind = "Function", output(proxy))] + fn from_radians(radius: f32, angle: f32) -> bevy::math::primitives::CircularSector; + +"#, + r#" +/// Create a new [`CircularSector`] from a `radius` and an `angle` in degrees. + + #[lua(kind = "Function", output(proxy))] + fn from_degrees(radius: f32, angle: f32) -> bevy::math::primitives::CircularSector; + +"#, + r#" +/// Create a new [`CircularSector`] from a `radius` and a number of `turns` of a circle. +/// For instance, `0.5` turns is a semicircle. + + #[lua(kind = "Function", output(proxy))] + fn from_turns(radius: f32, fraction: f32) -> bevy::math::primitives::CircularSector; + +"#, + r#" +/// Get half the angle of the sector + + #[lua(kind = "Method")] + fn half_angle(&self) -> f32; + +"#, + r#" +/// Get the angle of the sector + + #[lua(kind = "Method")] + fn angle(&self) -> f32; + +"#, + r#" +/// Get the radius of the sector + + #[lua(kind = "Method")] + fn radius(&self) -> f32; + +"#, + r#" +/// Get the length of the arc defining the sector + + #[lua(kind = "Method")] + fn arc_length(&self) -> f32; + +"#, + r#" +/// Get half the length of the chord defined by the sector +/// See [`Arc2d::half_chord_length`] + + #[lua(kind = "Method")] + fn half_chord_length(&self) -> f32; + +"#, + r#" +/// Get the length of the chord defined by the sector +/// See [`Arc2d::chord_length`] + + #[lua(kind = "Method")] + fn chord_length(&self) -> f32; + +"#, + r#" +/// Get the midpoint of the chord defined by the sector +/// See [`Arc2d::chord_midpoint`] + + #[lua(kind = "Method", output(proxy))] + fn chord_midpoint(&self) -> bevy::math::prelude::Vec2; + +"#, + r#" +/// Get the length of the apothem of this sector +/// See [`Arc2d::apothem`] + + #[lua(kind = "Method")] + fn apothem(&self) -> f32; + +"#, + r#" +/// Get the length of the sagitta of this sector +/// See [`Arc2d::sagitta`] + + #[lua(kind = "Method")] + fn sagitta(&self) -> f32; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::CircularSector; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim2::CircularSector) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct CircularSector { + #[lua(output(proxy))] + arc: bevy::math::primitives::Arc2d, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::CircularSegment", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::CircularSegment; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim2::CircularSegment) -> bool; + +"#, + r#" +/// Create a new [`CircularSegment`] from a `radius`, and an `angle` + + #[lua(kind = "Function", output(proxy))] + fn new(radius: f32, angle: f32) -> bevy::math::primitives::CircularSegment; + +"#, + r#" +/// Create a new [`CircularSegment`] from a `radius` and an `angle` in radians. + + #[lua(kind = "Function", output(proxy))] + fn from_radians(radius: f32, angle: f32) -> bevy::math::primitives::CircularSegment; + +"#, + r#" +/// Create a new [`CircularSegment`] from a `radius` and an `angle` in degrees. + + #[lua(kind = "Function", output(proxy))] + fn from_degrees(radius: f32, angle: f32) -> bevy::math::primitives::CircularSegment; + +"#, + r#" +/// Create a new [`CircularSegment`] from a `radius` and a number of `turns` of a circle. +/// For instance, `0.5` turns is a semicircle. + + #[lua(kind = "Function", output(proxy))] + fn from_turns(radius: f32, fraction: f32) -> bevy::math::primitives::CircularSegment; + +"#, + r#" +/// Get the half-angle of the segment + + #[lua(kind = "Method")] + fn half_angle(&self) -> f32; + +"#, + r#" +/// Get the angle of the segment + + #[lua(kind = "Method")] + fn angle(&self) -> f32; + +"#, + r#" +/// Get the radius of the segment + + #[lua(kind = "Method")] + fn radius(&self) -> f32; + +"#, + r#" +/// Get the length of the arc defining the segment + + #[lua(kind = "Method")] + fn arc_length(&self) -> f32; + +"#, + r#" +/// Get half the length of the segment's base, also known as its chord + + #[lua(kind = "Method")] + fn half_chord_length(&self) -> f32; + +"#, + r#" +/// Get the length of the segment's base, also known as its chord + + #[lua(kind = "Method")] + fn chord_length(&self) -> f32; + +"#, + r#" +/// Get the midpoint of the segment's base, also known as its chord + + #[lua(kind = "Method", output(proxy))] + fn chord_midpoint(&self) -> bevy::math::prelude::Vec2; + +"#, + r#" +/// Get the length of the apothem of this segment, +/// which is the signed distance between the segment and the center of its circle +/// See [`Arc2d::apothem`] + + #[lua(kind = "Method")] + fn apothem(&self) -> f32; + +"#, + r#" +/// Get the length of the sagitta of this segment, also known as its height +/// See [`Arc2d::sagitta`] + + #[lua(kind = "Method")] + fn sagitta(&self) -> f32; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct CircularSegment { + #[lua(output(proxy))] + arc: bevy::math::primitives::Arc2d, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Ellipse", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim2::Ellipse) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Ellipse; + +"#, + r#" +/// Create a new `Ellipse` from half of its width and height. +/// This corresponds to the two perpendicular radii defining the ellipse. + + #[lua(kind = "Function", output(proxy))] + fn new(half_width: f32, half_height: f32) -> bevy::math::primitives::Ellipse; + +"#, + r#" +/// Create a new `Ellipse` from a given full size. +/// `size.x` is the diameter along the X axis, and `size.y` is the diameter along the Y axis. + + #[lua(kind = "Function", output(proxy))] + fn from_size( + #[proxy] + size: bevy::math::prelude::Vec2, + ) -> bevy::math::primitives::Ellipse; + +"#, + r#" +/// Returns the [eccentricity](https://en.wikipedia.org/wiki/Eccentricity_(mathematics)) of the ellipse. +/// It can be thought of as a measure of how "stretched" or elongated the ellipse is. +/// The value should be in the range [0, 1), where 0 represents a circle, and 1 represents a parabola. + + #[lua(kind = "Method")] + fn eccentricity(&self) -> f32; + +"#, + r#" +/// Get the focal length of the ellipse. This corresponds to the distance between one of the foci and the center of the ellipse. +/// The focal length of an ellipse is related to its eccentricity by `eccentricity = focal_length / semi_major` + + #[lua(kind = "Method")] + fn focal_length(&self) -> f32; + +"#, + r#" +/// Returns the length of the semi-major axis. This corresponds to the longest radius of the ellipse. + + #[lua(kind = "Method")] + fn semi_major(&self) -> f32; + +"#, + r#" +/// Returns the length of the semi-minor axis. This corresponds to the shortest radius of the ellipse. + + #[lua(kind = "Method")] + fn semi_minor(&self) -> f32; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Ellipse { + #[lua(output(proxy))] + half_size: bevy::math::prelude::Vec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Line2d", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Line2d; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim2::Line2d) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Line2d { + #[lua(output(proxy))] + direction: bevy::math::prelude::Dir2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Plane2d", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Plane2d; + +"#, + r#" +/// Create a new `Plane2d` from a normal +/// # Panics +/// Panics if the given `normal` is zero (or very close to zero), or non-finite. + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + normal: bevy::math::prelude::Vec2, + ) -> bevy::math::primitives::Plane2d; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim2::Plane2d) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Plane2d { + #[lua(output(proxy))] + normal: bevy::math::prelude::Dir2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Rectangle", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Rectangle; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim2::Rectangle) -> bool; + +"#, + r#" +/// Create a new `Rectangle` from a full width and height + + #[lua(kind = "Function", output(proxy))] + fn new(width: f32, height: f32) -> bevy::math::primitives::Rectangle; + +"#, + r#" +/// Create a new `Rectangle` from a given full size + + #[lua(kind = "Function", output(proxy))] + fn from_size( + #[proxy] + size: bevy::math::prelude::Vec2, + ) -> bevy::math::primitives::Rectangle; + +"#, + r#" +/// Create a new `Rectangle` from two corner points + + #[lua(kind = "Function", output(proxy))] + fn from_corners( + #[proxy] + point1: bevy::math::prelude::Vec2, + #[proxy] + point2: bevy::math::prelude::Vec2, + ) -> bevy::math::primitives::Rectangle; + +"#, + r#" +/// Create a `Rectangle` from a single length. +/// The resulting `Rectangle` will be the same size in every direction. + + #[lua(kind = "Function", output(proxy))] + fn from_length(length: f32) -> bevy::math::primitives::Rectangle; + +"#, + r#" +/// Get the size of the rectangle + + #[lua(kind = "Method", output(proxy))] + fn size(&self) -> bevy::math::prelude::Vec2; + +"#, + r#" +/// Finds the point on the rectangle that is closest to the given `point`. +/// If the point is outside the rectangle, the returned point will be on the perimeter of the rectangle. +/// Otherwise, it will be inside the rectangle and returned as is. + + #[lua(kind = "Method", output(proxy))] + fn closest_point( + &self, + #[proxy] + point: bevy::math::prelude::Vec2, + ) -> bevy::math::prelude::Vec2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Rectangle { + #[lua(output(proxy))] + half_size: bevy::math::prelude::Vec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::RegularPolygon", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::RegularPolygon; + +"#, + r#" +/// Create a new `RegularPolygon` +/// from the radius of the circumcircle and a number of sides +/// # Panics +/// Panics if `circumradius` is negative + + #[lua(kind = "Function", output(proxy))] + fn new(circumradius: f32, sides: u32) -> bevy::math::primitives::RegularPolygon; + +"#, + r#" +/// Get the radius of the circumcircle on which all vertices +/// of the regular polygon lie + + #[lua(kind = "Method")] + fn circumradius(&self) -> f32; + +"#, + r#" +/// Get the inradius or apothem of the regular polygon. +/// This is the radius of the largest circle that can +/// be drawn within the polygon + + #[lua(kind = "Method")] + fn inradius(&self) -> f32; + +"#, + r#" +/// Get the length of one side of the regular polygon + + #[lua(kind = "Method")] + fn side_length(&self) -> f32; + +"#, + r#" +/// Get the internal angle of the regular polygon in degrees. +/// This is the angle formed by two adjacent sides with points +/// within the angle being in the interior of the polygon + + #[lua(kind = "Method")] + fn internal_angle_degrees(&self) -> f32; + +"#, + r#" +/// Get the internal angle of the regular polygon in radians. +/// This is the angle formed by two adjacent sides with points +/// within the angle being in the interior of the polygon + + #[lua(kind = "Method")] + fn internal_angle_radians(&self) -> f32; + +"#, + r#" +/// Get the external angle of the regular polygon in degrees. +/// This is the angle formed by two adjacent sides with points +/// within the angle being in the exterior of the polygon + + #[lua(kind = "Method")] + fn external_angle_degrees(&self) -> f32; + +"#, + r#" +/// Get the external angle of the regular polygon in radians. +/// This is the angle formed by two adjacent sides with points +/// within the angle being in the exterior of the polygon + + #[lua(kind = "Method")] + fn external_angle_radians(&self) -> f32; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim2::RegularPolygon) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct RegularPolygon { + #[lua(output(proxy))] + circumcircle: bevy::math::primitives::Circle, + sides: u32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Rhombus", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Rhombus; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim2::Rhombus) -> bool; + +"#, + r#" +/// Create a new `Rhombus` from a vertical and horizontal diagonal sizes. + + #[lua(kind = "Function", output(proxy))] + fn new( + horizontal_diagonal: f32, + vertical_diagonal: f32, + ) -> bevy::math::primitives::Rhombus; + +"#, + r#" +/// Create a new `Rhombus` from a side length with all inner angles equal. + + #[lua(kind = "Function", output(proxy))] + fn from_side(side: f32) -> bevy::math::primitives::Rhombus; + +"#, + r#" +/// Create a new `Rhombus` from a given inradius with all inner angles equal. + + #[lua(kind = "Function", output(proxy))] + fn from_inradius(inradius: f32) -> bevy::math::primitives::Rhombus; + +"#, + r#" +/// Get the length of each side of the rhombus + + #[lua(kind = "Method")] + fn side(&self) -> f32; + +"#, + r#" +/// Get the radius of the circumcircle on which all vertices +/// of the rhombus lie + + #[lua(kind = "Method")] + fn circumradius(&self) -> f32; + +"#, + r#" +/// Get the radius of the largest circle that can +/// be drawn within the rhombus + + #[lua(kind = "Method")] + fn inradius(&self) -> f32; + +"#, + r#" +/// Finds the point on the rhombus that is closest to the given `point`. +/// If the point is outside the rhombus, the returned point will be on the perimeter of the rhombus. +/// Otherwise, it will be inside the rhombus and returned as is. + + #[lua(kind = "Method", output(proxy))] + fn closest_point( + &self, + #[proxy] + point: bevy::math::prelude::Vec2, + ) -> bevy::math::prelude::Vec2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Rhombus { + #[lua(output(proxy))] + half_diagonals: bevy::math::prelude::Vec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Segment2d", + functions[r#" +/// Create a new `Segment2d` from a direction and full length of the segment + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + direction: bevy::math::prelude::Dir2, + length: f32, + ) -> bevy::math::primitives::Segment2d; + +"#, + r#" +/// Get the position of the first point on the line segment + + #[lua(kind = "Method", output(proxy))] + fn point1(&self) -> bevy::math::prelude::Vec2; + +"#, + r#" +/// Get the position of the second point on the line segment + + #[lua(kind = "Method", output(proxy))] + fn point2(&self) -> bevy::math::prelude::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim2::Segment2d) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Segment2d; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Segment2d { + #[lua(output(proxy))] + direction: bevy::math::prelude::Dir2, + half_length: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Triangle2d", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim2::Triangle2d) -> bool; + +"#, + r#" +/// Create a new `Triangle2d` from points `a`, `b`, and `c` + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + a: bevy::math::prelude::Vec2, + #[proxy] + b: bevy::math::prelude::Vec2, + #[proxy] + c: bevy::math::prelude::Vec2, + ) -> bevy::math::primitives::Triangle2d; + +"#, + r#" +/// Checks if the triangle is degenerate, meaning it has zero area. +/// A triangle is degenerate if the cross product of the vectors `ab` and `ac` has a length less than `10e-7`. +/// This indicates that the three vertices are collinear or nearly collinear. + + #[lua(kind = "Method")] + fn is_degenerate(&self) -> bool; + +"#, + r#" +/// Checks if the triangle is acute, meaning all angles are less than 90 degrees + + #[lua(kind = "Method")] + fn is_acute(&self) -> bool; + +"#, + r#" +/// Checks if the triangle is obtuse, meaning one angle is greater than 90 degrees + + #[lua(kind = "Method")] + fn is_obtuse(&self) -> bool; + +"#, + r#" +/// Reverse the [`WindingOrder`] of the triangle +/// by swapping the first and last vertices. + + #[lua(kind = "MutatingMethod")] + fn reverse(&mut self) -> (); + +"#, + r#" +/// This triangle but reversed. + + #[lua(kind = "Method", output(proxy))] + fn reversed(self) -> bevy::math::primitives::Triangle2d; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Triangle2d; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Triangle2d { + vertices: ReflectedValue, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::bounding::Aabb3d", + functions[r#" +/// Computes the smallest [`BoundingSphere`] containing this [`Aabb3d`]. + + #[lua(kind = "Method", output(proxy))] + fn bounding_sphere(&self) -> bevy::math::bounding::BoundingSphere; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::bounding::Aabb3d; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Aabb3d { + #[lua(output(proxy))] + min: bevy::math::Vec3A, + #[lua(output(proxy))] + max: bevy::math::Vec3A, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::bounding::BoundingSphere", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::bounding::BoundingSphere; + +"#, + r#" +/// Get the radius of the bounding sphere + + #[lua(kind = "Method")] + fn radius(&self) -> f32; + +"#, + r#" +/// Computes the smallest [`Aabb3d`] containing this [`BoundingSphere`]. + + #[lua(kind = "Method", output(proxy))] + fn aabb_3d(&self) -> bevy::math::bounding::Aabb3d; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct BoundingSphere { + #[lua(output(proxy))] + center: bevy::math::Vec3A, + #[lua(output(proxy))] + sphere: bevy::math::primitives::Sphere, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Sphere", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Sphere; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim3::Sphere) -> bool; + +"#, + r#" +/// Create a new [`Sphere`] from a `radius` + + #[lua(kind = "Function", output(proxy))] + fn new(radius: f32) -> bevy::math::primitives::Sphere; + +"#, + r#" +/// Get the diameter of the sphere + + #[lua(kind = "Method")] + fn diameter(&self) -> f32; + +"#, + r#" +/// Finds the point on the sphere that is closest to the given `point`. +/// If the point is outside the sphere, the returned point will be on the surface of the sphere. +/// Otherwise, it will be inside the sphere and returned as is. + + #[lua(kind = "Method", output(proxy))] + fn closest_point( + &self, + #[proxy] + point: bevy::math::prelude::Vec3, + ) -> bevy::math::prelude::Vec3; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Sphere { + radius: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Cuboid", + functions[r#" +/// Create a new `Cuboid` from a full x, y, and z length + + #[lua(kind = "Function", output(proxy))] + fn new( + x_length: f32, + y_length: f32, + z_length: f32, + ) -> bevy::math::primitives::Cuboid; + +"#, + r#" +/// Create a new `Cuboid` from a given full size + + #[lua(kind = "Function", output(proxy))] + fn from_size( + #[proxy] + size: bevy::math::prelude::Vec3, + ) -> bevy::math::primitives::Cuboid; + +"#, + r#" +/// Create a new `Cuboid` from two corner points + + #[lua(kind = "Function", output(proxy))] + fn from_corners( + #[proxy] + point1: bevy::math::prelude::Vec3, + #[proxy] + point2: bevy::math::prelude::Vec3, + ) -> bevy::math::primitives::Cuboid; + +"#, + r#" +/// Create a `Cuboid` from a single length. +/// The resulting `Cuboid` will be the same size in every direction. + + #[lua(kind = "Function", output(proxy))] + fn from_length(length: f32) -> bevy::math::primitives::Cuboid; + +"#, + r#" +/// Get the size of the cuboid + + #[lua(kind = "Method", output(proxy))] + fn size(&self) -> bevy::math::prelude::Vec3; + +"#, + r#" +/// Finds the point on the cuboid that is closest to the given `point`. +/// If the point is outside the cuboid, the returned point will be on the surface of the cuboid. +/// Otherwise, it will be inside the cuboid and returned as is. + + #[lua(kind = "Method", output(proxy))] + fn closest_point( + &self, + #[proxy] + point: bevy::math::prelude::Vec3, + ) -> bevy::math::prelude::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim3::Cuboid) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Cuboid; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Cuboid { + #[lua(output(proxy))] + half_size: bevy::math::prelude::Vec3, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Cylinder", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Cylinder; + +"#, + r#" +/// Create a new `Cylinder` from a radius and full height + + #[lua(kind = "Function", output(proxy))] + fn new(radius: f32, height: f32) -> bevy::math::primitives::Cylinder; + +"#, + r#" +/// Get the base of the cylinder as a [`Circle`] + + #[lua(kind = "Method", output(proxy))] + fn base(&self) -> bevy::math::primitives::Circle; + +"#, + r#" +/// Get the surface area of the side of the cylinder, +/// also known as the lateral area + + #[lua(kind = "Method")] + fn lateral_area(&self) -> f32; + +"#, + r#" +/// Get the surface area of one base of the cylinder + + #[lua(kind = "Method")] + fn base_area(&self) -> f32; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim3::Cylinder) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Cylinder { + radius: f32, + half_height: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Capsule3d", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim3::Capsule3d) -> bool; + +"#, + r#" +/// Create a new `Capsule3d` from a radius and length + + #[lua(kind = "Function", output(proxy))] + fn new(radius: f32, length: f32) -> bevy::math::primitives::Capsule3d; + +"#, + r#" +/// Get the part connecting the hemispherical ends +/// of the capsule as a [`Cylinder`] + + #[lua(kind = "Method", output(proxy))] + fn to_cylinder(&self) -> bevy::math::primitives::Cylinder; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Capsule3d; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Capsule3d { + radius: f32, + half_length: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Cone", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim3::Cone) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Cone; + +"#, + r#" +/// Create a new [`Cone`] from a radius and height. + + #[lua(kind = "Function", output(proxy))] + fn new(radius: f32, height: f32) -> bevy::math::primitives::Cone; + +"#, + r#" +/// Get the base of the cone as a [`Circle`] + + #[lua(kind = "Method", output(proxy))] + fn base(&self) -> bevy::math::primitives::Circle; + +"#, + r#" +/// Get the slant height of the cone, the length of the line segment +/// connecting a point on the base to the apex + + #[lua(kind = "Method")] + fn slant_height(&self) -> f32; + +"#, + r#" +/// Get the surface area of the side of the cone, +/// also known as the lateral area + + #[lua(kind = "Method")] + fn lateral_area(&self) -> f32; + +"#, + r#" +/// Get the surface area of the base of the cone + + #[lua(kind = "Method")] + fn base_area(&self) -> f32; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Cone { + radius: f32, + height: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::ConicalFrustum", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::ConicalFrustum; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim3::ConicalFrustum) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct ConicalFrustum { + radius_top: f32, + radius_bottom: f32, + height: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::InfinitePlane3d", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::InfinitePlane3d; + +"#, + r#" +/// Computes an [`Isometry3d`] which transforms points from the plane in 3D space with the given +/// `origin` to the XY-plane. +/// ## Guarantees +/// * the transformation is a [congruence] meaning it will preserve all distances and angles of +/// the transformed geometry +/// * uses the least rotation possible to transform the geometry +/// * if two geometries are transformed with the same isometry, then the relations between +/// them, like distances, are also preserved +/// * compared to projections, the transformation is lossless (up to floating point errors) +/// reversible +/// ## Non-Guarantees +/// * the rotation used is generally not unique +/// * the orientation of the transformed geometry in the XY plane might be arbitrary, to +/// enforce some kind of alignment the user has to use an extra transformation ontop of this +/// one +/// See [`isometries_xy`] for example usescases. +/// [congruence]: https://en.wikipedia.org/wiki/Congruence_(geometry) +/// [`isometries_xy`]: `InfinitePlane3d::isometries_xy` + + #[lua(kind = "Method", output(proxy))] + fn isometry_into_xy( + &self, + #[proxy] + origin: bevy::math::prelude::Vec3, + ) -> bevy::math::Isometry3d; + +"#, + r#" +/// Computes an [`Isometry3d`] which transforms points from the XY-plane to this plane with the +/// given `origin`. +/// ## Guarantees +/// * the transformation is a [congruence] meaning it will preserve all distances and angles of +/// the transformed geometry +/// * uses the least rotation possible to transform the geometry +/// * if two geometries are transformed with the same isometry, then the relations between +/// them, like distances, are also preserved +/// * compared to projections, the transformation is lossless (up to floating point errors) +/// reversible +/// ## Non-Guarantees +/// * the rotation used is generally not unique +/// * the orientation of the transformed geometry in the XY plane might be arbitrary, to +/// enforce some kind of alignment the user has to use an extra transformation ontop of this +/// one +/// See [`isometries_xy`] for example usescases. +/// [congruence]: https://en.wikipedia.org/wiki/Congruence_(geometry) +/// [`isometries_xy`]: `InfinitePlane3d::isometries_xy` + + #[lua(kind = "Method", output(proxy))] + fn isometry_from_xy( + &self, + #[proxy] + origin: bevy::math::prelude::Vec3, + ) -> bevy::math::Isometry3d; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim3::InfinitePlane3d) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct InfinitePlane3d { + #[lua(output(proxy))] + normal: bevy::math::prelude::Dir3, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Line3d", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim3::Line3d) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Line3d; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Line3d { + #[lua(output(proxy))] + direction: bevy::math::prelude::Dir3, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Segment3d", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim3::Segment3d) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Segment3d; + +"#, + r#" +/// Create a new `Segment3d` from a direction and full length of the segment + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + direction: bevy::math::prelude::Dir3, + length: f32, + ) -> bevy::math::primitives::Segment3d; + +"#, + r#" +/// Get the position of the first point on the line segment + + #[lua(kind = "Method", output(proxy))] + fn point1(&self) -> bevy::math::prelude::Vec3; + +"#, + r#" +/// Get the position of the second point on the line segment + + #[lua(kind = "Method", output(proxy))] + fn point2(&self) -> bevy::math::prelude::Vec3; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Segment3d { + #[lua(output(proxy))] + direction: bevy::math::prelude::Dir3, + half_length: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Torus", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim3::Torus) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Torus; + +"#, + r#" +/// Create a new `Torus` from an inner and outer radius. +/// The inner radius is the radius of the hole, and the outer radius +/// is the radius of the entire object + + #[lua(kind = "Function", output(proxy))] + fn new(inner_radius: f32, outer_radius: f32) -> bevy::math::primitives::Torus; + +"#, + r#" +/// Get the inner radius of the torus. +/// For a ring torus, this corresponds to the radius of the hole, +/// or `major_radius - minor_radius` + + #[lua(kind = "Method")] + fn inner_radius(&self) -> f32; + +"#, + r#" +/// Get the outer radius of the torus. +/// This corresponds to the overall radius of the entire object, +/// or `major_radius + minor_radius` + + #[lua(kind = "Method")] + fn outer_radius(&self) -> f32; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Torus { + minor_radius: f32, + major_radius: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Triangle3d", + functions[r#" +/// Create a new [`Triangle3d`] from points `a`, `b`, and `c`. + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + a: bevy::math::prelude::Vec3, + #[proxy] + b: bevy::math::prelude::Vec3, + #[proxy] + c: bevy::math::prelude::Vec3, + ) -> bevy::math::primitives::Triangle3d; + +"#, + r#" +/// Checks if the triangle is degenerate, meaning it has zero area. +/// A triangle is degenerate if the cross product of the vectors `ab` and `ac` has a length less than `10e-7`. +/// This indicates that the three vertices are collinear or nearly collinear. + + #[lua(kind = "Method")] + fn is_degenerate(&self) -> bool; + +"#, + r#" +/// Checks if the triangle is acute, meaning all angles are less than 90 degrees + + #[lua(kind = "Method")] + fn is_acute(&self) -> bool; + +"#, + r#" +/// Checks if the triangle is obtuse, meaning one angle is greater than 90 degrees + + #[lua(kind = "Method")] + fn is_obtuse(&self) -> bool; + +"#, + r#" +/// Reverse the triangle by swapping the first and last vertices. + + #[lua(kind = "MutatingMethod")] + fn reverse(&mut self) -> (); + +"#, + r#" +/// This triangle but reversed. + + #[lua(kind = "Method", output(proxy))] + fn reversed(self) -> bevy::math::primitives::Triangle3d; + +"#, + r#" +/// Get the centroid of the triangle. +/// This function finds the geometric center of the triangle by averaging the vertices: +/// `centroid = (a + b + c) / 3`. + + #[lua(kind = "Method", output(proxy))] + fn centroid(&self) -> bevy::math::prelude::Vec3; + +"#, + r#" +/// Get the circumcenter of the triangle. + + #[lua(kind = "Method", output(proxy))] + fn circumcenter(&self) -> bevy::math::prelude::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim3::Triangle3d) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Triangle3d; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Triangle3d { + vertices: ReflectedValue, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::bounding::RayCast2d", + functions[r#" +/// Construct a [`RayCast2d`] from an origin, [`Dir2`], and max distance. + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + origin: bevy::math::prelude::Vec2, + #[proxy] + direction: bevy::math::prelude::Dir2, + max: f32, + ) -> bevy::math::bounding::RayCast2d; + +"#, + r#" +/// Construct a [`RayCast2d`] from a [`Ray2d`] and max distance. + + #[lua(kind = "Function", output(proxy))] + fn from_ray( + #[proxy] + ray: bevy::math::Ray2d, + max: f32, + ) -> bevy::math::bounding::RayCast2d; + +"#, + r#" +/// Get the cached multiplicative inverse of the direction of the ray. + + #[lua(kind = "Method", output(proxy))] + fn direction_recip(&self) -> bevy::math::prelude::Vec2; + +"#, + r#" +/// Get the distance of an intersection with an [`Aabb2d`], if any. + + #[lua(kind = "Method")] + fn aabb_intersection_at( + &self, + #[proxy] + aabb: &bounding::bounded2d::Aabb2d, + ) -> std::option::Option; + +"#, + r#" +/// Get the distance of an intersection with a [`BoundingCircle`], if any. + + #[lua(kind = "Method")] + fn circle_intersection_at( + &self, + #[proxy] + circle: &bounding::bounded2d::BoundingCircle, + ) -> std::option::Option; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::bounding::RayCast2d; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct RayCast2d { + #[lua(output(proxy))] + ray: bevy::math::Ray2d, + max: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::bounding::AabbCast2d", + functions[r#" +/// Construct an [`AabbCast2d`] from an [`Aabb2d`], origin, [`Dir2`], and max distance. + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + aabb: bevy::math::bounding::Aabb2d, + #[proxy] + origin: bevy::math::prelude::Vec2, + #[proxy] + direction: bevy::math::prelude::Dir2, + max: f32, + ) -> bevy::math::bounding::AabbCast2d; + +"#, + r#" +/// Construct an [`AabbCast2d`] from an [`Aabb2d`], [`Ray2d`], and max distance. + + #[lua(kind = "Function", output(proxy))] + fn from_ray( + #[proxy] + aabb: bevy::math::bounding::Aabb2d, + #[proxy] + ray: bevy::math::Ray2d, + max: f32, + ) -> bevy::math::bounding::AabbCast2d; + +"#, + r#" +/// Get the distance at which the [`Aabb2d`]s collide, if at all. + + #[lua(kind = "Method")] + fn aabb_collision_at( + &self, + #[proxy] + aabb: bevy::math::bounding::Aabb2d, + ) -> std::option::Option; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::bounding::AabbCast2d; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AabbCast2d { + #[lua(output(proxy))] + ray: bevy::math::bounding::RayCast2d, + #[lua(output(proxy))] + aabb: bevy::math::bounding::Aabb2d, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::bounding::BoundingCircleCast", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::bounding::BoundingCircleCast; + +"#, + r#" +/// Construct a [`BoundingCircleCast`] from a [`BoundingCircle`], origin, [`Dir2`], and max distance. + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + circle: bevy::math::bounding::BoundingCircle, + #[proxy] + origin: bevy::math::prelude::Vec2, + #[proxy] + direction: bevy::math::prelude::Dir2, + max: f32, + ) -> bevy::math::bounding::BoundingCircleCast; + +"#, + r#" +/// Construct a [`BoundingCircleCast`] from a [`BoundingCircle`], [`Ray2d`], and max distance. + + #[lua(kind = "Function", output(proxy))] + fn from_ray( + #[proxy] + circle: bevy::math::bounding::BoundingCircle, + #[proxy] + ray: bevy::math::Ray2d, + max: f32, + ) -> bevy::math::bounding::BoundingCircleCast; + +"#, + r#" +/// Get the distance at which the [`BoundingCircle`]s collide, if at all. + + #[lua(kind = "Method")] + fn circle_collision_at( + &self, + #[proxy] + circle: bevy::math::bounding::BoundingCircle, + ) -> std::option::Option; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct BoundingCircleCast { + #[lua(output(proxy))] + ray: bevy::math::bounding::RayCast2d, + #[lua(output(proxy))] + circle: bevy::math::bounding::BoundingCircle, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::bounding::RayCast3d", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::bounding::RayCast3d; + +"#, + r#" +/// Construct a [`RayCast3d`] from a [`Ray3d`] and max distance. + + #[lua(kind = "Function", output(proxy))] + fn from_ray( + #[proxy] + ray: bevy::math::Ray3d, + max: f32, + ) -> bevy::math::bounding::RayCast3d; + +"#, + r#" +/// Get the cached multiplicative inverse of the direction of the ray. + + #[lua(kind = "Method", output(proxy))] + fn direction_recip(&self) -> bevy::math::Vec3A; + +"#, + r#" +/// Get the distance of an intersection with an [`Aabb3d`], if any. + + #[lua(kind = "Method")] + fn aabb_intersection_at( + &self, + #[proxy] + aabb: &bounding::bounded3d::Aabb3d, + ) -> std::option::Option; + +"#, + r#" +/// Get the distance of an intersection with a [`BoundingSphere`], if any. + + #[lua(kind = "Method")] + fn sphere_intersection_at( + &self, + #[proxy] + sphere: &bounding::bounded3d::BoundingSphere, + ) -> std::option::Option; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct RayCast3d { + #[lua(output(proxy))] + origin: bevy::math::Vec3A, + #[lua(output(proxy))] + direction: bevy::math::prelude::Dir3A, + max: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::bounding::AabbCast3d", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::bounding::AabbCast3d; + +"#, + r#" +/// Construct an [`AabbCast3d`] from an [`Aabb3d`], [`Ray3d`], and max distance. + + #[lua(kind = "Function", output(proxy))] + fn from_ray( + #[proxy] + aabb: bevy::math::bounding::Aabb3d, + #[proxy] + ray: bevy::math::Ray3d, + max: f32, + ) -> bevy::math::bounding::AabbCast3d; + +"#, + r#" +/// Get the distance at which the [`Aabb3d`]s collide, if at all. + + #[lua(kind = "Method")] + fn aabb_collision_at( + &self, + #[proxy] + aabb: bevy::math::bounding::Aabb3d, + ) -> std::option::Option; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AabbCast3d { + #[lua(output(proxy))] + ray: bevy::math::bounding::RayCast3d, + #[lua(output(proxy))] + aabb: bevy::math::bounding::Aabb3d, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::bounding::BoundingSphereCast", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::bounding::BoundingSphereCast; + +"#, + r#" +/// Construct a [`BoundingSphereCast`] from a [`BoundingSphere`], [`Ray3d`], and max distance. + + #[lua(kind = "Function", output(proxy))] + fn from_ray( + #[proxy] + sphere: bevy::math::bounding::BoundingSphere, + #[proxy] + ray: bevy::math::Ray3d, + max: f32, + ) -> bevy::math::bounding::BoundingSphereCast; + +"#, + r#" +/// Get the distance at which the [`BoundingSphere`]s collide, if at all. + + #[lua(kind = "Method")] + fn sphere_collision_at( + &self, + #[proxy] + sphere: bevy::math::bounding::BoundingSphere, + ) -> std::option::Option; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct BoundingSphereCast { + #[lua(output(proxy))] + ray: bevy::math::bounding::RayCast3d, + #[lua(output(proxy))] + sphere: bevy::math::bounding::BoundingSphere, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::curve::interval::Interval", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &curve::interval::Interval) -> bool; + +"#, + r#" +/// Get the start of this interval. + + #[lua(kind = "Method")] + fn start(self) -> f32; + +"#, + r#" +/// Get the end of this interval. + + #[lua(kind = "Method")] + fn end(self) -> f32; + +"#, + r#" +/// Get the length of this interval. Note that the result may be infinite (`f32::INFINITY`). + + #[lua(kind = "Method")] + fn length(self) -> f32; + +"#, + r#" +/// Returns `true` if this interval is bounded — that is, if both its start and end are finite. +/// Equivalently, an interval is bounded if its length is finite. + + #[lua(kind = "Method")] + fn is_bounded(self) -> bool; + +"#, + r#" +/// Returns `true` if this interval has a finite start. + + #[lua(kind = "Method")] + fn has_finite_start(self) -> bool; + +"#, + r#" +/// Returns `true` if this interval has a finite end. + + #[lua(kind = "Method")] + fn has_finite_end(self) -> bool; + +"#, + r#" +/// Returns `true` if `item` is contained in this interval. + + #[lua(kind = "Method")] + fn contains(self, item: f32) -> bool; + +"#, + r#" +/// Returns `true` if the other interval is contained in this interval. +/// This is non-strict: each interval will contain itself. + + #[lua(kind = "Method")] + fn contains_interval( + self, + #[proxy] + other: bevy::math::curve::interval::Interval, + ) -> bool; + +"#, + r#" +/// Clamp the given `value` to lie within this interval. + + #[lua(kind = "Method")] + fn clamp(self, value: f32) -> f32; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::curve::interval::Interval; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Interval {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::FloatOrd", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &float_ord::FloatOrd) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::FloatOrd; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::FloatOrd; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialOrd", kind = "Method")] + fn lt(&self, #[proxy] other: &float_ord::FloatOrd) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialOrd", kind = "Method")] + fn le(&self, #[proxy] other: &float_ord::FloatOrd) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialOrd", kind = "Method")] + fn gt(&self, #[proxy] other: &float_ord::FloatOrd) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialOrd", kind = "Method")] + fn ge(&self, #[proxy] other: &float_ord::FloatOrd) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct FloatOrd(f32); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Plane3d", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim3::Plane3d) -> bool; + +"#, + r#" +/// Create a new `Plane3d` from a normal and a half size +/// # Panics +/// Panics if the given `normal` is zero (or very close to zero), or non-finite. + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + normal: bevy::math::prelude::Vec3, + #[proxy] + half_size: bevy::math::prelude::Vec2, + ) -> bevy::math::primitives::Plane3d; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Plane3d; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Plane3d { + #[lua(output(proxy))] + normal: bevy::math::prelude::Dir3, + #[lua(output(proxy))] + half_size: bevy::math::prelude::Vec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::primitives::Tetrahedron", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &primitives::dim3::Tetrahedron) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::primitives::Tetrahedron; + +"#, + r#" +/// Create a new [`Tetrahedron`] from points `a`, `b`, `c` and `d`. + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + a: bevy::math::prelude::Vec3, + #[proxy] + b: bevy::math::prelude::Vec3, + #[proxy] + c: bevy::math::prelude::Vec3, + #[proxy] + d: bevy::math::prelude::Vec3, + ) -> bevy::math::primitives::Tetrahedron; + +"#, + r#" +/// Get the signed volume of the tetrahedron. +/// If it's negative, the normal vector of the face defined by +/// the first three points using the right-hand rule points +/// away from the fourth vertex. + + #[lua(kind = "Method")] + fn signed_volume(&self) -> f32; + +"#, + r#" +/// Get the centroid of the tetrahedron. +/// This function finds the geometric center of the tetrahedron +/// by averaging the vertices: `centroid = (a + b + c + d) / 4`. + + #[lua(kind = "Method", output(proxy))] + fn centroid(&self) -> bevy::math::prelude::Vec3; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Tetrahedron { + vertices: ReflectedValue, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::curve::easing::EaseFunction", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &curve::easing::EaseFunction) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::math::curve::easing::EaseFunction; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct EaseFunction {} +#[derive(Default)] +pub(crate) struct Globals; +impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { + fn add_instances< + 'lua, + T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, + >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { + instances + .add_instance( + "Isometry2d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Isometry3d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Ray2d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Ray3d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Rot2", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Dir2", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Dir3", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Dir3A", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "IRect", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Rect", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "URect", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Aabb2d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "BoundingCircle", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaBoundingCircle, + >::new, + )?; + instances + .add_instance( + "Circle", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Annulus", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Arc2d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Capsule2d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "CircularSector", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaCircularSector, + >::new, + )?; + instances + .add_instance( + "CircularSegment", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaCircularSegment, + >::new, + )?; + instances + .add_instance( + "Ellipse", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Plane2d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Rectangle", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "RegularPolygon", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaRegularPolygon, + >::new, + )?; + instances + .add_instance( + "Rhombus", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Segment2d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Triangle2d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Sphere", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Cuboid", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Cylinder", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Capsule3d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Cone", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Segment3d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Torus", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Triangle3d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "RayCast2d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "AabbCast2d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "BoundingCircleCast", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaBoundingCircleCast, + >::new, + )?; + instances + .add_instance( + "RayCast3d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "AabbCast3d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "BoundingSphereCast", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaBoundingSphereCast, + >::new, + )?; + instances + .add_instance( + "Plane3d", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Tetrahedron", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + Ok(()) + } +} +pub struct BevyMathAPIProvider; +impl bevy_mod_scripting_core::hosts::APIProvider for BevyMathAPIProvider { + type APITarget = std::sync::Mutex; + type ScriptContext = std::sync::Mutex; + type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; + fn attach_api( + &mut self, + ctx: &mut Self::APITarget, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); + bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) + .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( + e.to_string(), + )) + } + fn get_doc_fragment(&self) -> Option { + Some( + bevy_mod_scripting_lua::docs::LuaDocFragment::new( + "BevyMathAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaIsometry2d, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaIsometry3d, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaBoundingCircle, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaCapsule2d, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaCircularSector, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaCircularSegment, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaRectangle, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaRegularPolygon, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaSegment2d, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaTriangle2d, + >, + >() + .process_type::() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaCylinder, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaCapsule3d, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaSegment3d, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaTriangle3d, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaRayCast2d, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaAabbCast2d, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaBoundingCircleCast, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaRayCast3d, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaAabbCast3d, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaBoundingSphereCast, + >, + >() + .process_type::() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaTetrahedron, + >, + >() + .process_type::() + }, + ), + ) + } + fn setup_script( + &mut self, + script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn setup_script_runtime( + &mut self, + world_ptr: bevy_mod_scripting_core::world::WorldPointer, + _script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn register_with_app(&self, app: &mut bevy::app::App) { + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs new file mode 100644 index 0000000000..9c6497b6a5 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs @@ -0,0 +1,22743 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +extern crate self as bevy_script_api; +use bevy_script_api::{ + lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "std::sync::atomic::AtomicBool", + functions[r#" +/// Creates a new `AtomicBool`. +/// # Examples +/// ``` +/// use std::sync::atomic::AtomicBool; +/// let atomic_true = AtomicBool::new(true); +/// let atomic_false = AtomicBool::new(false); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new(v: bool) -> std::sync::atomic::AtomicBool; + +"#, + r#" +/// Consumes the atomic and returns the contained value. +/// This is safe because passing `self` by value guarantees that no other threads are +/// concurrently accessing the atomic data. +/// # Examples +/// ``` +/// use std::sync::atomic::AtomicBool; +/// let some_bool = AtomicBool::new(true); +/// assert_eq!(some_bool.into_inner(), true); +/// ``` + + #[lua(kind = "Method")] + fn into_inner(self) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AtomicBool {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "std::sync::atomic::AtomicI16", + functions[r#" +/// Creates a new atomic integer. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicI16; +///let atomic_forty_two = AtomicI16::new(42); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new(v: i16) -> std::sync::atomic::AtomicI16; + +"#, + r#" +/// Consumes the atomic and returns the contained value. +/// This is safe because passing `self` by value guarantees that no other threads are +/// concurrently accessing the atomic data. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicI16; +///let some_var = AtomicI16::new(5); +/// assert_eq!(some_var.into_inner(), 5); +/// ``` + + #[lua(kind = "Method")] + fn into_inner(self) -> i16; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AtomicI16 {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "std::sync::atomic::AtomicI32", + functions[r#" +/// Creates a new atomic integer. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicI32; +///let atomic_forty_two = AtomicI32::new(42); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new(v: i32) -> std::sync::atomic::AtomicI32; + +"#, + r#" +/// Consumes the atomic and returns the contained value. +/// This is safe because passing `self` by value guarantees that no other threads are +/// concurrently accessing the atomic data. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicI32; +///let some_var = AtomicI32::new(5); +/// assert_eq!(some_var.into_inner(), 5); +/// ``` + + #[lua(kind = "Method")] + fn into_inner(self) -> i32; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AtomicI32 {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "std::sync::atomic::AtomicI64", + functions[r#" +/// Creates a new atomic integer. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicI64; +///let atomic_forty_two = AtomicI64::new(42); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new(v: i64) -> std::sync::atomic::AtomicI64; + +"#, + r#" +/// Consumes the atomic and returns the contained value. +/// This is safe because passing `self` by value guarantees that no other threads are +/// concurrently accessing the atomic data. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicI64; +///let some_var = AtomicI64::new(5); +/// assert_eq!(some_var.into_inner(), 5); +/// ``` + + #[lua(kind = "Method")] + fn into_inner(self) -> i64; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AtomicI64 {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "std::sync::atomic::AtomicI8", + functions[r#" +/// Creates a new atomic integer. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicI8; +///let atomic_forty_two = AtomicI8::new(42); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new(v: i8) -> std::sync::atomic::AtomicI8; + +"#, + r#" +/// Consumes the atomic and returns the contained value. +/// This is safe because passing `self` by value guarantees that no other threads are +/// concurrently accessing the atomic data. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicI8; +///let some_var = AtomicI8::new(5); +/// assert_eq!(some_var.into_inner(), 5); +/// ``` + + #[lua(kind = "Method")] + fn into_inner(self) -> i8; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AtomicI8 {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "std::sync::atomic::AtomicIsize", + functions[r#" +/// Creates a new atomic integer. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicIsize; +///let atomic_forty_two = AtomicIsize::new(42); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new(v: isize) -> std::sync::atomic::AtomicIsize; + +"#, + r#" +/// Consumes the atomic and returns the contained value. +/// This is safe because passing `self` by value guarantees that no other threads are +/// concurrently accessing the atomic data. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicIsize; +///let some_var = AtomicIsize::new(5); +/// assert_eq!(some_var.into_inner(), 5); +/// ``` + + #[lua(kind = "Method")] + fn into_inner(self) -> isize; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AtomicIsize {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "std::sync::atomic::AtomicU16", + functions[r#" +/// Creates a new atomic integer. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicU16; +///let atomic_forty_two = AtomicU16::new(42); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new(v: u16) -> std::sync::atomic::AtomicU16; + +"#, + r#" +/// Consumes the atomic and returns the contained value. +/// This is safe because passing `self` by value guarantees that no other threads are +/// concurrently accessing the atomic data. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicU16; +///let some_var = AtomicU16::new(5); +/// assert_eq!(some_var.into_inner(), 5); +/// ``` + + #[lua(kind = "Method")] + fn into_inner(self) -> u16; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AtomicU16 {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "std::sync::atomic::AtomicU32", + functions[r#" +/// Creates a new atomic integer. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicU32; +///let atomic_forty_two = AtomicU32::new(42); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new(v: u32) -> std::sync::atomic::AtomicU32; + +"#, + r#" +/// Consumes the atomic and returns the contained value. +/// This is safe because passing `self` by value guarantees that no other threads are +/// concurrently accessing the atomic data. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicU32; +///let some_var = AtomicU32::new(5); +/// assert_eq!(some_var.into_inner(), 5); +/// ``` + + #[lua(kind = "Method")] + fn into_inner(self) -> u32; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AtomicU32 {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "std::sync::atomic::AtomicU64", + functions[r#" +/// Creates a new atomic integer. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicU64; +///let atomic_forty_two = AtomicU64::new(42); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new(v: u64) -> std::sync::atomic::AtomicU64; + +"#, + r#" +/// Consumes the atomic and returns the contained value. +/// This is safe because passing `self` by value guarantees that no other threads are +/// concurrently accessing the atomic data. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicU64; +///let some_var = AtomicU64::new(5); +/// assert_eq!(some_var.into_inner(), 5); +/// ``` + + #[lua(kind = "Method")] + fn into_inner(self) -> u64; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AtomicU64 {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "std::sync::atomic::AtomicU8", + functions[r#" +/// Creates a new atomic integer. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicU8; +///let atomic_forty_two = AtomicU8::new(42); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new(v: u8) -> std::sync::atomic::AtomicU8; + +"#, + r#" +/// Consumes the atomic and returns the contained value. +/// This is safe because passing `self` by value guarantees that no other threads are +/// concurrently accessing the atomic data. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicU8; +///let some_var = AtomicU8::new(5); +/// assert_eq!(some_var.into_inner(), 5); +/// ``` + + #[lua(kind = "Method")] + fn into_inner(self) -> u8; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AtomicU8 {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(), + remote = "std::sync::atomic::AtomicUsize", + functions[r#" +/// Creates a new atomic integer. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicUsize; +///let atomic_forty_two = AtomicUsize::new(42); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new(v: usize) -> std::sync::atomic::AtomicUsize; + +"#, + r#" +/// Consumes the atomic and returns the contained value. +/// This is safe because passing `self` by value guarantees that no other threads are +/// concurrently accessing the atomic data. +/// # Examples +/// ``` +///use std::sync::atomic::AtomicUsize; +///let some_var = AtomicUsize::new(5); +/// assert_eq!(some_var.into_inner(), 5); +/// ``` + + #[lua(kind = "Method")] + fn into_inner(self) -> usize; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AtomicUsize {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::utils::Duration", + functions[r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: u32) -> bevy::utils::Duration; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::utils::Duration; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::utils::Duration) -> bevy::utils::Duration; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &bevy_utils::Duration) -> bool; + +"#, + r#" +/// Creates a new `Duration` from the specified number of whole seconds and +/// additional nanoseconds. +/// If the number of nanoseconds is greater than 1 billion (the number of +/// nanoseconds in a second), then it will carry over into the seconds provided. +/// # Panics +/// This constructor will panic if the carry from the nanoseconds overflows +/// the seconds counter. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let five_seconds = Duration::new(5, 0); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new(secs: u64, nanos: u32) -> bevy::utils::Duration; + +"#, + r#" +/// Creates a new `Duration` from the specified number of whole seconds. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::from_secs(5); +/// assert_eq!(5, duration.as_secs()); +/// assert_eq!(0, duration.subsec_nanos()); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_secs(secs: u64) -> bevy::utils::Duration; + +"#, + r#" +/// Creates a new `Duration` from the specified number of milliseconds. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::from_millis(2_569); +/// assert_eq!(2, duration.as_secs()); +/// assert_eq!(569_000_000, duration.subsec_nanos()); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_millis(millis: u64) -> bevy::utils::Duration; + +"#, + r#" +/// Creates a new `Duration` from the specified number of microseconds. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::from_micros(1_000_002); +/// assert_eq!(1, duration.as_secs()); +/// assert_eq!(2_000, duration.subsec_nanos()); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_micros(micros: u64) -> bevy::utils::Duration; + +"#, + r#" +/// Creates a new `Duration` from the specified number of nanoseconds. +/// Note: Using this on the return value of `as_nanos()` might cause unexpected behavior: +/// `as_nanos()` returns a u128, and can return values that do not fit in u64, e.g. 585 years. +/// Instead, consider using the pattern `Duration::new(d.as_secs(), d.subsec_nanos())` +/// if you cannot copy/clone the Duration directly. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::from_nanos(1_000_000_123); +/// assert_eq!(1, duration.as_secs()); +/// assert_eq!(123, duration.subsec_nanos()); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_nanos(nanos: u64) -> bevy::utils::Duration; + +"#, + r#" +/// Returns true if this `Duration` spans no time. +/// # Examples +/// ``` +/// use std::time::Duration; +/// assert!(Duration::ZERO.is_zero()); +/// assert!(Duration::new(0, 0).is_zero()); +/// assert!(Duration::from_nanos(0).is_zero()); +/// assert!(Duration::from_secs(0).is_zero()); +/// assert!(!Duration::new(1, 1).is_zero()); +/// assert!(!Duration::from_nanos(1).is_zero()); +/// assert!(!Duration::from_secs(1).is_zero()); +/// ``` + + #[lua(kind = "Method")] + fn is_zero(&self) -> bool; + +"#, + r#" +/// Returns the number of _whole_ seconds contained by this `Duration`. +/// The returned value does not include the fractional (nanosecond) part of the +/// duration, which can be obtained using [`subsec_nanos`]. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::new(5, 730_023_852); +/// assert_eq!(duration.as_secs(), 5); +/// ``` +/// To determine the total number of seconds represented by the `Duration` +/// including the fractional part, use [`as_secs_f64`] or [`as_secs_f32`] +/// [`as_secs_f64`]: Duration::as_secs_f64 +/// [`as_secs_f32`]: Duration::as_secs_f32 +/// [`subsec_nanos`]: Duration::subsec_nanos + + #[lua(kind = "Method")] + fn as_secs(&self) -> u64; + +"#, + r#" +/// Returns the fractional part of this `Duration`, in whole milliseconds. +/// This method does **not** return the length of the duration when +/// represented by milliseconds. The returned number always represents a +/// fractional portion of a second (i.e., it is less than one thousand). +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::from_millis(5_432); +/// assert_eq!(duration.as_secs(), 5); +/// assert_eq!(duration.subsec_millis(), 432); +/// ``` + + #[lua(kind = "Method")] + fn subsec_millis(&self) -> u32; + +"#, + r#" +/// Returns the fractional part of this `Duration`, in whole microseconds. +/// This method does **not** return the length of the duration when +/// represented by microseconds. The returned number always represents a +/// fractional portion of a second (i.e., it is less than one million). +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::from_micros(1_234_567); +/// assert_eq!(duration.as_secs(), 1); +/// assert_eq!(duration.subsec_micros(), 234_567); +/// ``` + + #[lua(kind = "Method")] + fn subsec_micros(&self) -> u32; + +"#, + r#" +/// Returns the fractional part of this `Duration`, in nanoseconds. +/// This method does **not** return the length of the duration when +/// represented by nanoseconds. The returned number always represents a +/// fractional portion of a second (i.e., it is less than one billion). +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::from_millis(5_010); +/// assert_eq!(duration.as_secs(), 5); +/// assert_eq!(duration.subsec_nanos(), 10_000_000); +/// ``` + + #[lua(kind = "Method")] + fn subsec_nanos(&self) -> u32; + +"#, + r#" +/// Returns the total number of whole milliseconds contained by this `Duration`. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::new(5, 730_023_852); +/// assert_eq!(duration.as_millis(), 5_730); +/// ``` + + #[lua(kind = "Method")] + fn as_millis(&self) -> u128; + +"#, + r#" +/// Returns the total number of whole microseconds contained by this `Duration`. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::new(5, 730_023_852); +/// assert_eq!(duration.as_micros(), 5_730_023); +/// ``` + + #[lua(kind = "Method")] + fn as_micros(&self) -> u128; + +"#, + r#" +/// Returns the total number of nanoseconds contained by this `Duration`. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let duration = Duration::new(5, 730_023_852); +/// assert_eq!(duration.as_nanos(), 5_730_023_852); +/// ``` + + #[lua(kind = "Method")] + fn as_nanos(&self) -> u128; + +"#, + r#" +/// Computes the absolute difference between `self` and `other`. +/// # Examples +/// ``` +/// use std::time::Duration; +/// assert_eq!(Duration::new(100, 0).abs_diff(Duration::new(80, 0)), Duration::new(20, 0)); +/// assert_eq!(Duration::new(100, 400_000_000).abs_diff(Duration::new(110, 0)), Duration::new(9, 600_000_000)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn abs_diff(self, #[proxy] other: bevy::utils::Duration) -> bevy::utils::Duration; + +"#, + r#" +/// Saturating `Duration` addition. Computes `self + other`, returning [`Duration::MAX`] +/// if overflow occurred. +/// # Examples +/// ``` +/// #![feature(duration_constants)] +/// use std::time::Duration; +/// assert_eq!(Duration::new(0, 0).saturating_add(Duration::new(0, 1)), Duration::new(0, 1)); +/// assert_eq!(Duration::new(1, 0).saturating_add(Duration::new(u64::MAX, 0)), Duration::MAX); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn saturating_add( + self, + #[proxy] + rhs: bevy::utils::Duration, + ) -> bevy::utils::Duration; + +"#, + r#" +/// Saturating `Duration` subtraction. Computes `self - other`, returning [`Duration::ZERO`] +/// if the result would be negative or if overflow occurred. +/// # Examples +/// ``` +/// use std::time::Duration; +/// assert_eq!(Duration::new(0, 1).saturating_sub(Duration::new(0, 0)), Duration::new(0, 1)); +/// assert_eq!(Duration::new(0, 0).saturating_sub(Duration::new(0, 1)), Duration::ZERO); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub( + self, + #[proxy] + rhs: bevy::utils::Duration, + ) -> bevy::utils::Duration; + +"#, + r#" +/// Saturating `Duration` multiplication. Computes `self * other`, returning +/// [`Duration::MAX`] if overflow occurred. +/// # Examples +/// ``` +/// #![feature(duration_constants)] +/// use std::time::Duration; +/// assert_eq!(Duration::new(0, 500_000_001).saturating_mul(2), Duration::new(1, 2)); +/// assert_eq!(Duration::new(u64::MAX - 1, 0).saturating_mul(2), Duration::MAX); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn saturating_mul(self, rhs: u32) -> bevy::utils::Duration; + +"#, + r#" +/// Returns the number of seconds contained by this `Duration` as `f64`. +/// The returned value includes the fractional (nanosecond) part of the duration. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let dur = Duration::new(2, 700_000_000); +/// assert_eq!(dur.as_secs_f64(), 2.7); +/// ``` + + #[lua(kind = "Method")] + fn as_secs_f64(&self) -> f64; + +"#, + r#" +/// Returns the number of seconds contained by this `Duration` as `f32`. +/// The returned value includes the fractional (nanosecond) part of the duration. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let dur = Duration::new(2, 700_000_000); +/// assert_eq!(dur.as_secs_f32(), 2.7); +/// ``` + + #[lua(kind = "Method")] + fn as_secs_f32(&self) -> f32; + +"#, + r#" +/// Creates a new `Duration` from the specified number of seconds represented +/// as `f64`. +/// # Panics +/// This constructor will panic if `secs` is negative, overflows `Duration` or not finite. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let res = Duration::from_secs_f64(0.0); +/// assert_eq!(res, Duration::new(0, 0)); +/// let res = Duration::from_secs_f64(1e-20); +/// assert_eq!(res, Duration::new(0, 0)); +/// let res = Duration::from_secs_f64(4.2e-7); +/// assert_eq!(res, Duration::new(0, 420)); +/// let res = Duration::from_secs_f64(2.7); +/// assert_eq!(res, Duration::new(2, 700_000_000)); +/// let res = Duration::from_secs_f64(3e10); +/// assert_eq!(res, Duration::new(30_000_000_000, 0)); +/// // subnormal float +/// let res = Duration::from_secs_f64(f64::from_bits(1)); +/// assert_eq!(res, Duration::new(0, 0)); +/// // conversion uses rounding +/// let res = Duration::from_secs_f64(0.999e-9); +/// assert_eq!(res, Duration::new(0, 1)); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_secs_f64(secs: f64) -> bevy::utils::Duration; + +"#, + r#" +/// Creates a new `Duration` from the specified number of seconds represented +/// as `f32`. +/// # Panics +/// This constructor will panic if `secs` is negative, overflows `Duration` or not finite. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let res = Duration::from_secs_f32(0.0); +/// assert_eq!(res, Duration::new(0, 0)); +/// let res = Duration::from_secs_f32(1e-20); +/// assert_eq!(res, Duration::new(0, 0)); +/// let res = Duration::from_secs_f32(4.2e-7); +/// assert_eq!(res, Duration::new(0, 420)); +/// let res = Duration::from_secs_f32(2.7); +/// assert_eq!(res, Duration::new(2, 700_000_048)); +/// let res = Duration::from_secs_f32(3e10); +/// assert_eq!(res, Duration::new(30_000_001_024, 0)); +/// // subnormal float +/// let res = Duration::from_secs_f32(f32::from_bits(1)); +/// assert_eq!(res, Duration::new(0, 0)); +/// // conversion uses rounding +/// let res = Duration::from_secs_f32(0.999e-9); +/// assert_eq!(res, Duration::new(0, 1)); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_secs_f32(secs: f32) -> bevy::utils::Duration; + +"#, + r#" +/// Multiplies `Duration` by `f64`. +/// # Panics +/// This method will panic if result is negative, overflows `Duration` or not finite. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let dur = Duration::new(2, 700_000_000); +/// assert_eq!(dur.mul_f64(3.14), Duration::new(8, 478_000_000)); +/// assert_eq!(dur.mul_f64(3.14e5), Duration::new(847_800, 0)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn mul_f64(self, rhs: f64) -> bevy::utils::Duration; + +"#, + r#" +/// Multiplies `Duration` by `f32`. +/// # Panics +/// This method will panic if result is negative, overflows `Duration` or not finite. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let dur = Duration::new(2, 700_000_000); +/// assert_eq!(dur.mul_f32(3.14), Duration::new(8, 478_000_641)); +/// assert_eq!(dur.mul_f32(3.14e5), Duration::new(847_800, 0)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn mul_f32(self, rhs: f32) -> bevy::utils::Duration; + +"#, + r#" +/// Divides `Duration` by `f64`. +/// # Panics +/// This method will panic if result is negative, overflows `Duration` or not finite. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let dur = Duration::new(2, 700_000_000); +/// assert_eq!(dur.div_f64(3.14), Duration::new(0, 859_872_611)); +/// assert_eq!(dur.div_f64(3.14e5), Duration::new(0, 8_599)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn div_f64(self, rhs: f64) -> bevy::utils::Duration; + +"#, + r#" +/// Divides `Duration` by `f32`. +/// # Panics +/// This method will panic if result is negative, overflows `Duration` or not finite. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let dur = Duration::new(2, 700_000_000); +/// // note that due to rounding errors result is slightly +/// // different from 0.859_872_611 +/// assert_eq!(dur.div_f32(3.14), Duration::new(0, 859_872_580)); +/// assert_eq!(dur.div_f32(3.14e5), Duration::new(0, 8_599)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn div_f32(self, rhs: f32) -> bevy::utils::Duration; + +"#, + r#" +/// Divides `Duration` by `Duration` and returns `f64`. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let dur1 = Duration::new(2, 700_000_000); +/// let dur2 = Duration::new(5, 400_000_000); +/// assert_eq!(dur1.div_duration_f64(dur2), 0.5); +/// ``` + + #[lua(kind = "Method")] + fn div_duration_f64(self, #[proxy] rhs: bevy::utils::Duration) -> f64; + +"#, + r#" +/// Divides `Duration` by `Duration` and returns `f32`. +/// # Examples +/// ``` +/// use std::time::Duration; +/// let dur1 = Duration::new(2, 700_000_000); +/// let dur2 = Duration::new(5, 400_000_000); +/// assert_eq!(dur1.div_duration_f32(dur2), 0.5); +/// ``` + + #[lua(kind = "Method")] + fn div_duration_f32(self, #[proxy] rhs: bevy::utils::Duration) -> f32; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::utils::Duration) -> bevy::utils::Duration; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: u32) -> bevy::utils::Duration; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Duration {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::utils::Instant", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &bevy_utils::Instant) -> bool; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::utils::Instant; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] other: bevy::utils::Duration) -> bevy::utils::Instant; + +"#, + r#" +/// Returns the amount of time elapsed from another instant to this one, +/// or zero duration if that instant is later than this one. +/// # Panics +/// Previous Rust versions panicked when `other` was later than `self`. Currently this +/// method saturates. Future versions may reintroduce the panic in some circumstances. +/// See [Monotonicity]. +/// [Monotonicity]: Instant#monotonicity + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] other: bevy::utils::Instant) -> bevy::utils::Duration; + +"#, + r#" +/// Returns an instant corresponding to "now". +/// # Examples +/// ``` +/// use std::time::Instant; +/// let now = Instant::now(); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn now() -> bevy::utils::Instant; + +"#, + r#" +/// Returns the amount of time elapsed from another instant to this one, +/// or zero duration if that instant is later than this one. +/// # Panics +/// Previous Rust versions panicked when `earlier` was later than `self`. Currently this +/// method saturates. Future versions may reintroduce the panic in some circumstances. +/// See [Monotonicity]. +/// [Monotonicity]: Instant#monotonicity +/// # Examples +/// ```no_run +/// use std::time::{Duration, Instant}; +/// use std::thread::sleep; +/// let now = Instant::now(); +/// sleep(Duration::new(1, 0)); +/// let new_now = Instant::now(); +/// println!("{:?}", new_now.duration_since(now)); +/// println!("{:?}", now.duration_since(new_now)); // 0ns +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn duration_since( + &self, + #[proxy] + earlier: bevy::utils::Instant, + ) -> bevy::utils::Duration; + +"#, + r#" +/// Returns the amount of time elapsed from another instant to this one, +/// or zero duration if that instant is later than this one. +/// # Examples +/// ```no_run +/// use std::time::{Duration, Instant}; +/// use std::thread::sleep; +/// let now = Instant::now(); +/// sleep(Duration::new(1, 0)); +/// let new_now = Instant::now(); +/// println!("{:?}", new_now.saturating_duration_since(now)); +/// println!("{:?}", now.saturating_duration_since(new_now)); // 0ns +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn saturating_duration_since( + &self, + #[proxy] + earlier: bevy::utils::Instant, + ) -> bevy::utils::Duration; + +"#, + r#" +/// Returns the amount of time elapsed since this instant. +/// # Panics +/// Previous Rust versions panicked when the current time was earlier than self. Currently this +/// method returns a Duration of zero in that case. Future versions may reintroduce the panic. +/// See [Monotonicity]. +/// [Monotonicity]: Instant#monotonicity +/// # Examples +/// ```no_run +/// use std::thread::sleep; +/// use std::time::{Duration, Instant}; +/// let instant = Instant::now(); +/// let three_secs = Duration::from_secs(3); +/// sleep(three_secs); +/// assert!(instant.elapsed() >= three_secs); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn elapsed(&self) -> bevy::utils::Duration; + +"#, + r#" +/// # Panics +/// This function may panic if the resulting point in time cannot be represented by the +/// underlying data structure. See [`Instant::checked_add`] for a version without panic. + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] other: bevy::utils::Duration) -> bevy::utils::Instant; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Instant(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "std::path::PathBuf", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &std::path::PathBuf) -> bool; + +"#, + r#" +/// Allocates an empty `PathBuf`. +/// # Examples +/// ``` +/// use std::path::PathBuf; +/// let path = PathBuf::new(); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new() -> std::path::PathBuf; + +"#, + r#" +/// Creates a new `PathBuf` with a given capacity used to create the +/// internal [`OsString`]. See [`with_capacity`] defined on [`OsString`]. +/// # Examples +/// ``` +/// use std::path::PathBuf; +/// let mut path = PathBuf::with_capacity(10); +/// let capacity = path.capacity(); +/// // This push is done without reallocating +/// path.push(r"C:\"); +/// assert_eq!(capacity, path.capacity()); +/// ``` +/// [`with_capacity`]: OsString::with_capacity + + #[lua(kind = "Function", output(proxy))] + fn with_capacity(capacity: usize) -> std::path::PathBuf; + +"#, + r#" +/// Truncates `self` to [`self.parent`]. +/// Returns `false` and does nothing if [`self.parent`] is [`None`]. +/// Otherwise, returns `true`. +/// [`self.parent`]: Path::parent +/// # Examples +/// ``` +/// use std::path::{Path, PathBuf}; +/// let mut p = PathBuf::from("/spirited/away.rs"); +/// p.pop(); +/// assert_eq!(Path::new("/spirited"), p); +/// p.pop(); +/// assert_eq!(Path::new("/"), p); +/// ``` + + #[lua(kind = "MutatingMethod")] + fn pop(&mut self) -> bool; + +"#, + r#" +/// Invokes [`capacity`] on the underlying instance of [`OsString`]. +/// [`capacity`]: OsString::capacity + + #[lua(kind = "Method")] + fn capacity(&self) -> usize; + +"#, + r#" +/// Invokes [`clear`] on the underlying instance of [`OsString`]. +/// [`clear`]: OsString::clear + + #[lua(kind = "MutatingMethod")] + fn clear(&mut self) -> (); + +"#, + r#" +/// Invokes [`reserve`] on the underlying instance of [`OsString`]. +/// [`reserve`]: OsString::reserve + + #[lua(kind = "MutatingMethod")] + fn reserve(&mut self, additional: usize) -> (); + +"#, + r#" +/// Invokes [`reserve_exact`] on the underlying instance of [`OsString`]. +/// [`reserve_exact`]: OsString::reserve_exact + + #[lua(kind = "MutatingMethod")] + fn reserve_exact(&mut self, additional: usize) -> (); + +"#, + r#" +/// Invokes [`shrink_to_fit`] on the underlying instance of [`OsString`]. +/// [`shrink_to_fit`]: OsString::shrink_to_fit + + #[lua(kind = "MutatingMethod")] + fn shrink_to_fit(&mut self) -> (); + +"#, + r#" +/// Invokes [`shrink_to`] on the underlying instance of [`OsString`]. +/// [`shrink_to`]: OsString::shrink_to + + #[lua(kind = "MutatingMethod")] + fn shrink_to(&mut self, min_capacity: usize) -> (); + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> std::path::PathBuf; + +"#, + r#" +/// Clones the contents of `source` into `self`. +/// This method is preferred over simply assigning `source.clone()` to `self`, +/// as it avoids reallocation if possible. + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "MutatingMethod", + )] + fn clone_from(&mut self, #[proxy] source: &std::path::PathBuf) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct PathBuf {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "std::ops::RangeFull", + functions[r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> std::ops::RangeFull; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &std::ops::RangeFull) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct RangeFull {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Quat", + functions[r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::Quat; + +"#, + r#" +/// Divides a quaternion by a scalar value. +/// The quotient is not guaranteed to be normalized. + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f32) -> bevy::math::Quat; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::Quat) -> bool; + +"#, + r#" +/// Multiplies a quaternion by a scalar value. +/// The product is not guaranteed to be normalized. + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f32) -> bevy::math::Quat; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::Quat; + +"#, + r#" +/// Multiplies two quaternions. If they each represent a rotation, the result will +/// represent the combined rotation. +/// Note that due to floating point rounding the result may not be perfectly +/// normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Quat) -> bevy::math::Quat; + +"#, + r#" +/// Subtracts the `rhs` quaternion from `self`. +/// The difference is not guaranteed to be normalized. + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::Quat) -> bevy::math::Quat; + +"#, + r#" +/// Adds two quaternions. +/// The sum is not guaranteed to be normalized. +/// Note that addition is not the same as combining the rotations represented by the +/// two quaternions! That corresponds to multiplication. + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::Quat) -> bevy::math::Quat; + +"#, + r#" +/// Creates a new rotation quaternion. +/// This should generally not be called manually unless you know what you are doing. +/// Use one of the other constructors instead such as `identity` or `from_axis_angle`. +/// `from_xyzw` is mostly used by unit tests and `serde` deserialization. +/// # Preconditions +/// This function does not check if the input is normalized, it is up to the user to +/// provide normalized input or to normalized the resulting quaternion. + + #[lua(kind = "Function", output(proxy))] + fn from_xyzw(x: f32, y: f32, z: f32, w: f32) -> bevy::math::Quat; + +"#, + r#" +/// Creates a rotation quaternion from an array. +/// # Preconditions +/// This function does not check if the input is normalized, it is up to the user to +/// provide normalized input or to normalized the resulting quaternion. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [f32; 4]) -> bevy::math::Quat; + +"#, + r#" +/// Creates a new rotation quaternion from a 4D vector. +/// # Preconditions +/// This function does not check if the input is normalized, it is up to the user to +/// provide normalized input or to normalized the resulting quaternion. + + #[lua(kind = "Function", output(proxy))] + fn from_vec4(#[proxy] v: bevy::math::Vec4) -> bevy::math::Quat; + +"#, + r#" +/// Create a quaternion for a normalized rotation `axis` and `angle` (in radians). +/// The axis must be a unit vector. +/// # Panics +/// Will panic if `axis` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_axis_angle(#[proxy] axis: bevy::math::Vec3, angle: f32) -> bevy::math::Quat; + +"#, + r#" +/// Create a quaternion that rotates `v.length()` radians around `v.normalize()`. +/// `from_scaled_axis(Vec3::ZERO)` results in the identity quaternion. + + #[lua(kind = "Function", output(proxy))] + fn from_scaled_axis(#[proxy] v: bevy::math::Vec3) -> bevy::math::Quat; + +"#, + r#" +/// Creates a quaternion from the `angle` (in radians) around the x axis. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_x(angle: f32) -> bevy::math::Quat; + +"#, + r#" +/// Creates a quaternion from the `angle` (in radians) around the y axis. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_y(angle: f32) -> bevy::math::Quat; + +"#, + r#" +/// Creates a quaternion from the `angle` (in radians) around the z axis. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_z(angle: f32) -> bevy::math::Quat; + +"#, + r#" +/// Creates a quaternion from the given Euler rotation sequence and the angles (in radians). + + #[lua(kind = "Function", output(proxy))] + fn from_euler( + #[proxy] + euler: bevy::math::EulerRot, + a: f32, + b: f32, + c: f32, + ) -> bevy::math::Quat; + +"#, + r#" +/// Creates a quaternion from a 3x3 rotation matrix. +/// Note if the input matrix contain scales, shears, or other non-rotation transformations then +/// the resulting quaternion will be ill-defined. +/// # Panics +/// Will panic if any input matrix column is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_mat3(#[proxy] mat: &glam::Mat3) -> bevy::math::Quat; + +"#, + r#" +/// Creates a quaternion from a 3x3 SIMD aligned rotation matrix. +/// Note if the input matrix contain scales, shears, or other non-rotation transformations then +/// the resulting quaternion will be ill-defined. +/// # Panics +/// Will panic if any input matrix column is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_mat3a(#[proxy] mat: &glam::Mat3A) -> bevy::math::Quat; + +"#, + r#" +/// Creates a quaternion from the upper 3x3 rotation matrix inside a homogeneous 4x4 matrix. +/// Note if the upper 3x3 matrix contain scales, shears, or other non-rotation transformations +/// then the resulting quaternion will be ill-defined. +/// # Panics +/// Will panic if any column of the upper 3x3 rotation matrix is not normalized when +/// `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_mat4(#[proxy] mat: &glam::Mat4) -> bevy::math::Quat; + +"#, + r#" +/// Gets the minimal rotation for transforming `from` to `to`. The rotation is in the +/// plane spanned by the two vectors. Will rotate at most 180 degrees. +/// The inputs must be unit vectors. +/// `from_rotation_arc(from, to) * from ≈ to`. +/// For near-singular cases (from≈to and from≈-to) the current implementation +/// is only accurate to about 0.001 (for `f32`). +/// # Panics +/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_arc( + #[proxy] + from: bevy::math::Vec3, + #[proxy] + to: bevy::math::Vec3, + ) -> bevy::math::Quat; + +"#, + r#" +/// Gets the minimal rotation for transforming `from` to either `to` or `-to`. This means +/// that the resulting quaternion will rotate `from` so that it is colinear with `to`. +/// The rotation is in the plane spanned by the two vectors. Will rotate at most 90 +/// degrees. +/// The inputs must be unit vectors. +/// `to.dot(from_rotation_arc_colinear(from, to) * from).abs() ≈ 1`. +/// # Panics +/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_arc_colinear( + #[proxy] + from: bevy::math::Vec3, + #[proxy] + to: bevy::math::Vec3, + ) -> bevy::math::Quat; + +"#, + r#" +/// Gets the minimal rotation for transforming `from` to `to`. The resulting rotation is +/// around the z axis. Will rotate at most 180 degrees. +/// The inputs must be unit vectors. +/// `from_rotation_arc_2d(from, to) * from ≈ to`. +/// For near-singular cases (from≈to and from≈-to) the current implementation +/// is only accurate to about 0.001 (for `f32`). +/// # Panics +/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_arc_2d( + #[proxy] + from: bevy::math::Vec2, + #[proxy] + to: bevy::math::Vec2, + ) -> bevy::math::Quat; + +"#, + r#" +/// Returns the rotation axis scaled by the rotation in radians. + + #[lua(kind = "Method", output(proxy))] + fn to_scaled_axis(self) -> bevy::math::Vec3; + +"#, + r#" +/// Returns the rotation angles for the given euler rotation sequence. + + #[lua(kind = "Method")] + fn to_euler(self, #[proxy] order: bevy::math::EulerRot) -> (f32, f32, f32); + +"#, + r#" +/// `[x, y, z, w]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [f32; 4]; + +"#, + r#" +/// Returns the vector part of the quaternion. + + #[lua(kind = "Method", output(proxy))] + fn xyz(self) -> bevy::math::Vec3; + +"#, + r#" +/// Returns the quaternion conjugate of `self`. For a unit quaternion the +/// conjugate is also the inverse. + + #[lua(kind = "Method", output(proxy))] + fn conjugate(self) -> bevy::math::Quat; + +"#, + r#" +/// Returns the inverse of a normalized quaternion. +/// Typically quaternion inverse returns the conjugate of a normalized quaternion. +/// Because `self` is assumed to already be unit length this method *does not* normalize +/// before returning the conjugate. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn inverse(self) -> bevy::math::Quat; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. The dot product is +/// equal to the cosine of the angle between two quaternion rotations. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::Quat) -> f32; + +"#, + r#" +/// Computes the length of `self`. + + #[lua(kind = "Method")] + fn length(self) -> f32; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is generally faster than `length()` as it avoids a square +/// root operation. + + #[lua(kind = "Method")] + fn length_squared(self) -> f32; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua(kind = "Method")] + fn length_recip(self) -> f32; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must _not_ be of length zero. +/// Panics +/// Will panic if `self` is zero length when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn normalize(self) -> bevy::math::Quat; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(self) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NAN`. + + #[lua(kind = "Method")] + fn is_nan(self) -> bool; + +"#, + r#" +/// Returns whether `self` of length `1.0` or not. +/// Uses a precision threshold of `1e-6`. + + #[lua(kind = "Method")] + fn is_normalized(self) -> bool; + +"#, + r#" + + #[lua(kind = "Method")] + fn is_near_identity(self) -> bool; + +"#, + r#" +/// Returns the angle (in radians) for the minimal rotation +/// for transforming this quaternion into another. +/// Both quaternions must be normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method")] + fn angle_between(self, #[proxy] rhs: bevy::math::Quat) -> f32; + +"#, + r#" +/// Rotates towards `rhs` up to `max_angle` (in radians). +/// When `max_angle` is `0.0`, the result will be equal to `self`. When `max_angle` is equal to +/// `self.angle_between(rhs)`, the result will be equal to `rhs`. If `max_angle` is negative, +/// rotates towards the exact opposite of `rhs`. Will not go past the target. +/// Both quaternions must be normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn rotate_towards( + &self, + #[proxy] + rhs: bevy::math::Quat, + max_angle: f32, + ) -> bevy::math::Quat; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two quaternions contain similar elements. It works +/// best when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(self, #[proxy] rhs: bevy::math::Quat, max_abs_diff: f32) -> bool; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on +/// the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` +/// is `1.0`, the result will be equal to `rhs`. +/// # Panics +/// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn lerp(self, #[proxy] end: bevy::math::Quat, s: f32) -> bevy::math::Quat; + +"#, + r#" +/// Performs a spherical linear interpolation between `self` and `end` +/// based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` +/// is `1.0`, the result will be equal to `end`. +/// # Panics +/// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn slerp(self, #[proxy] end: bevy::math::Quat, s: f32) -> bevy::math::Quat; + +"#, + r#" +/// Multiplies a quaternion and a 3D vector, returning the rotated vector. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn mul_vec3(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Multiplies two quaternions. If they each represent a rotation, the result will +/// represent the combined rotation. +/// Note that due to floating point rounding the result may not be perfectly normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn mul_quat(self, #[proxy] rhs: bevy::math::Quat) -> bevy::math::Quat; + +"#, + r#" +/// Creates a quaternion from a 3x3 rotation matrix inside a 3D affine transform. +/// Note if the input affine matrix contain scales, shears, or other non-rotation +/// transformations then the resulting quaternion will be ill-defined. +/// # Panics +/// Will panic if any input affine matrix column is not normalized when `glam_assert` is +/// enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_affine3(#[proxy] a: &glam::Affine3A) -> bevy::math::Quat; + +"#, + r#" +/// Multiplies a quaternion and a 3D vector, returning the rotated vector. + + #[lua(kind = "Method", output(proxy))] + fn mul_vec3a(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua(kind = "Method", output(proxy))] + fn as_dquat(self) -> bevy::math::DQuat; + +"#, + r#" +/// Multiplies a quaternion and a 3D vector, returning the rotated vector. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Quat(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Vec3", + functions[r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f32) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::Vec3) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::Vec3) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::Vec3) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: f32, y: f32, z: f32) -> bevy::math::Vec3; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: f32) -> bevy::math::Vec3; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec3, + #[proxy] + if_true: bevy::math::Vec3, + #[proxy] + if_false: bevy::math::Vec3, + ) -> bevy::math::Vec3; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [f32; 3]) -> bevy::math::Vec3; + +"#, + r#" +/// `[x, y, z]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [f32; 3]; + +"#, + r#" +/// Creates a 4D vector from `self` and the given `w` value. + + #[lua(kind = "Method", output(proxy))] + fn extend(self, w: f32) -> bevy::math::Vec4; + +"#, + r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. + + #[lua(kind = "Method", output(proxy))] + fn truncate(self) -> bevy::math::Vec2; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: f32) -> bevy::math::Vec3; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: f32) -> bevy::math::Vec3; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `z`. + + #[lua(kind = "Method", output(proxy))] + fn with_z(self, z: f32) -> bevy::math::Vec3; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::Vec3) -> f32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Computes the cross product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn cross(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Component-wise clamping of values, similar to [`f32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::Vec3, + #[proxy] + max: bevy::math::Vec3, + ) -> bevy::math::Vec3; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> f32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> f32; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> f32; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> f32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn abs(self) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `1.0` if the number is positive, `+0.0` or `INFINITY` +/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` +/// - `NAN` if the number is `NAN` + + #[lua(kind = "Method", output(proxy))] + fn signum(self) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a vector with signs of `rhs` and the magnitudes of `self`. + + #[lua(kind = "Method", output(proxy))] + fn copysign(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn is_negative_bitmask(self) -> u32; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. If any element is either +/// `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(self) -> bool; + +"#, + r#" +/// Performs `is_finite` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`. + + #[lua(kind = "Method", output(proxy))] + fn is_finite_mask(self) -> bevy::math::BVec3; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(self) -> bool; + +"#, + r#" +/// Performs `is_nan` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`. + + #[lua(kind = "Method", output(proxy))] + fn is_nan_mask(self) -> bevy::math::BVec3; + +"#, + r#" +/// Computes the length of `self`. + + #[lua(kind = "Method")] + fn length(self) -> f32; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is faster than `length()` as it avoids a square root operation. + + #[lua(kind = "Method")] + fn length_squared(self) -> f32; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua(kind = "Method")] + fn length_recip(self) -> f32; + +"#, + r#" +/// Computes the Euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance(self, #[proxy] rhs: bevy::math::Vec3) -> f32; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance_squared(self, #[proxy] rhs: bevy::math::Vec3) -> f32; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn div_euclid(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// [Euclidean division]: f32::rem_euclid + + #[lua(kind = "Method", output(proxy))] + fn rem_euclid(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must be finite and _not_ of length zero, nor very close to zero. +/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. +/// Panics +/// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn normalize(self) -> bevy::math::Vec3; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns a +/// fallback value. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be the fallback value. +/// See also [`Self::try_normalize()`]. + + #[lua(kind = "Method", output(proxy))] + fn normalize_or(self, #[proxy] fallback: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns zero. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be zero. +/// See also [`Self::try_normalize()`]. + + #[lua(kind = "Method", output(proxy))] + fn normalize_or_zero(self) -> bevy::math::Vec3; + +"#, + r#" +/// Returns whether `self` is length `1.0` or not. +/// Uses a precision threshold of approximately `1e-4`. + + #[lua(kind = "Method")] + fn is_normalized(self) -> bool; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` is zero length when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn project_onto(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reject_from(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn project_onto_normalized(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reject_from_normalized(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a vector containing the nearest integer to a number for each element of `self`. +/// Round half-way cases away from 0.0. + + #[lua(kind = "Method", output(proxy))] + fn round(self) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a vector containing the largest integer less than or equal to a number for each +/// element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn floor(self) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a vector containing the smallest integer greater than or equal to a number for +/// each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn ceil(self) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a vector containing the integer part each element of `self`. This means numbers are +/// always truncated towards zero. + + #[lua(kind = "Method", output(proxy))] + fn trunc(self) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`. +/// Note that this differs from the GLSL implementation of `fract` which returns +/// `self - self.floor()`. +/// Note that this is fast but not precise for large numbers. + + #[lua(kind = "Method", output(proxy))] + fn fract(self) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector as `self - self.floor()`. +/// Note that this differs from the Rust implementation of `fract` which returns +/// `self - self.trunc()`. +/// Note that this is fast but not precise for large numbers. + + #[lua(kind = "Method", output(proxy))] + fn fract_gl(self) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a vector containing `e^self` (the exponential function) for each element of +/// `self`. + + #[lua(kind = "Method", output(proxy))] + fn exp(self) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a vector containing each element of `self` raised to the power of `n`. + + #[lua(kind = "Method", output(proxy))] + fn powf(self, n: f32) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn recip(self) -> bevy::math::Vec3; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result +/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly +/// extrapolated. + + #[lua(kind = "Method", output(proxy))] + fn lerp(self, #[proxy] rhs: bevy::math::Vec3, s: f32) -> bevy::math::Vec3; + +"#, + r#" +/// Moves towards `rhs` based on the value `d`. +/// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to +/// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn move_towards(&self, #[proxy] rhs: bevy::math::Vec3, d: f32) -> bevy::math::Vec3; + +"#, + r#" +/// Calculates the midpoint between `self` and `rhs`. +/// The midpoint is the average of, or halfway point between, two vectors. +/// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)` +/// while being slightly cheaper to compute. + + #[lua(kind = "Method", output(proxy))] + fn midpoint(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` is +/// less than or equal to `max_abs_diff`. +/// This can be used to compare if two vectors contain similar elements. It works best when +/// comparing with a known value. The `max_abs_diff` that should be used used depends on +/// the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(self, #[proxy] rhs: bevy::math::Vec3, max_abs_diff: f32) -> bool; + +"#, + r#" +/// Returns a vector with a length no less than `min` and no more than `max`. +/// # Panics +/// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length(self, min: f32, max: f32) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a vector with a length no more than `max`. +/// # Panics +/// Will panic if `max` is negative when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length_max(self, max: f32) -> bevy::math::Vec3; + +"#, + r#" +/// Returns a vector with a length no less than `min`. +/// # Panics +/// Will panic if `min` is negative when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length_min(self, min: f32) -> bevy::math::Vec3; + +"#, + r#" +/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding +/// error, yielding a more accurate result than an unfused multiply-add. +/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target +/// architecture has a dedicated fma CPU instruction. However, this is not always true, +/// and will be heavily dependant on designing algorithms with specific target hardware in +/// mind. + + #[lua(kind = "Method", output(proxy))] + fn mul_add( + self, + #[proxy] + a: bevy::math::Vec3, + #[proxy] + b: bevy::math::Vec3, + ) -> bevy::math::Vec3; + +"#, + r#" +/// Returns the reflection vector for a given incident vector `self` and surface normal +/// `normal`. +/// `normal` must be normalized. +/// # Panics +/// Will panic if `normal` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reflect(self, #[proxy] normal: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Returns the refraction direction for a given incident vector `self`, surface normal +/// `normal` and ratio of indices of refraction, `eta`. When total internal reflection occurs, +/// a zero vector will be returned. +/// `self` and `normal` must be normalized. +/// # Panics +/// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn refract(self, #[proxy] normal: bevy::math::Vec3, eta: f32) -> bevy::math::Vec3; + +"#, + r#" +/// Returns the angle (in radians) between two vectors in the range `[0, +Ï€]`. +/// The inputs do not need to be unit vectors however they must be non-zero. + + #[lua(kind = "Method")] + fn angle_between(self, #[proxy] rhs: bevy::math::Vec3) -> f32; + +"#, + r#" +/// Returns some vector that is orthogonal to the given one. +/// The input vector must be finite and non-zero. +/// The output vector is not necessarily unit length. For that use +/// [`Self::any_orthonormal_vector()`] instead. + + #[lua(kind = "Method", output(proxy))] + fn any_orthogonal_vector(&self) -> bevy::math::Vec3; + +"#, + r#" +/// Returns any unit vector that is orthogonal to the given one. +/// The input vector must be unit length. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn any_orthonormal_vector(&self) -> bevy::math::Vec3; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec3(&self) -> bevy::math::DVec3; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec3(&self) -> bevy::math::IVec3; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec3(&self) -> bevy::math::UVec3; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec3(&self) -> bevy::math::I64Vec3; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec3(&self) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: f32) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::Vec3) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f32) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::Vec3) -> bool; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: f32) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: f32) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::Vec3) -> bevy::math::Vec3; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind="MetaMethod", raw , metamethod="Index")] +fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(self.inner()?[*idx]) +} +"#, + r#" +#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] +fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f32) -> Result<(),_> { + self.val_mut(|s| Ok(s[*idx] = val))? +} +"#] +)] +struct Vec3 { + x: f32, + y: f32, + z: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::IVec2", + functions[r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: i32) -> bevy::math::IVec2; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: i32, y: i32) -> bevy::math::IVec2; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: i32) -> bevy::math::IVec2; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec2, + #[proxy] + if_true: bevy::math::IVec2, + #[proxy] + if_false: bevy::math::IVec2, + ) -> bevy::math::IVec2; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [i32; 2]) -> bevy::math::IVec2; + +"#, + r#" +/// `[x, y]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [i32; 2]; + +"#, + r#" +/// Creates a 3D vector from `self` and the given `z` value. + + #[lua(kind = "Method", output(proxy))] + fn extend(self, z: i32) -> bevy::math::IVec3; + +"#, + r#" +/// Creates a 2D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: i32) -> bevy::math::IVec2; + +"#, + r#" +/// Creates a 2D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: i32) -> bevy::math::IVec2; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::IVec2) -> i32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" +/// Component-wise clamping of values, similar to [`i32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::IVec2, + #[proxy] + max: bevy::math::IVec2, + ) -> bevy::math::IVec2; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> i32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> i32; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> i32; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> i32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn abs(self) -> bevy::math::IVec2; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `0` if the number is zero +/// - `1` if the number is positive +/// - `-1` if the number is negative + + #[lua(kind = "Method", output(proxy))] + fn signum(self) -> bevy::math::IVec2; + +"#, + r#" +/// Returns a bitmask with the lowest 2 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn is_negative_bitmask(self) -> u32; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua(kind = "Method")] + fn length_squared(self) -> i32; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance_squared(self, #[proxy] rhs: bevy::math::IVec2) -> i32; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. + + #[lua(kind = "Method", output(proxy))] + fn div_euclid(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. +/// [Euclidean division]: i32::rem_euclid + + #[lua(kind = "Method", output(proxy))] + fn rem_euclid(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" +/// Returns a vector that is equal to `self` rotated by 90 degrees. + + #[lua(kind = "Method", output(proxy))] + fn perp(self) -> bevy::math::IVec2; + +"#, + r#" +/// The perpendicular dot product of `self` and `rhs`. +/// Also known as the wedge product, 2D cross product, and determinant. + + #[lua(kind = "Method")] + fn perp_dot(self, #[proxy] rhs: bevy::math::IVec2) -> i32; + +"#, + r#" +/// Returns `rhs` rotated by the angle of `self`. If `self` is normalized, +/// then this just rotation. This is what you usually want. Otherwise, +/// it will be like a rotation with a multiplication by `self`'s length. + + #[lua(kind = "Method", output(proxy))] + fn rotate(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec2(&self) -> bevy::math::Vec2; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec2(&self) -> bevy::math::DVec2; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec2(&self) -> bevy::math::UVec2; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec2(&self) -> bevy::math::I64Vec2; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec2(&self) -> bevy::math::U64Vec2; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_mul(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_div(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_mul(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_div(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.wrapping_add_unsigned(rhs.x), self.y.wrapping_add_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add_unsigned(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::IVec2; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.wrapping_sub_unsigned(rhs.x), self.y.wrapping_sub_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub_unsigned(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::IVec2; + +"#, + r#" +/// In other words this computes `[self.x.saturating_add_unsigned(rhs.x), self.y.saturating_add_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add_unsigned( + self, + #[proxy] + rhs: bevy::math::UVec2, + ) -> bevy::math::IVec2; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.saturating_sub_unsigned(rhs.x), self.y.saturating_sub_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub_unsigned( + self, + #[proxy] + rhs: bevy::math::UVec2, + ) -> bevy::math::IVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::IVec2) -> bevy::math::IVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::IVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: i32) -> bevy::math::IVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::IVec2) -> bevy::math::IVec2; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::IVec2; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::IVec2) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: i32) -> bevy::math::IVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::IVec2) -> bevy::math::IVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::IVec2) -> bevy::math::IVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: i32) -> bevy::math::IVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::IVec2) -> bevy::math::IVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: i32) -> bevy::math::IVec2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind="MetaMethod", raw , metamethod="Index")] +fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(self.inner()?[*idx]) +} +"#, + r#" +#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] +fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: i32) -> Result<(),_> { + self.val_mut(|s| Ok(s[*idx] = val))? +} +"#] +)] +struct IVec2 { + x: i32, + y: i32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::IVec3", + functions[r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: i32) -> bevy::math::IVec3; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::IVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: i32) -> bevy::math::IVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::IVec3) -> bevy::math::IVec3; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::IVec3) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: i32) -> bevy::math::IVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::IVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: i32) -> bevy::math::IVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::IVec3) -> bevy::math::IVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::IVec3) -> bevy::math::IVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::IVec3) -> bevy::math::IVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::IVec3) -> bevy::math::IVec3; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: i32) -> bevy::math::IVec3; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: i32, y: i32, z: i32) -> bevy::math::IVec3; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: i32) -> bevy::math::IVec3; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec3, + #[proxy] + if_true: bevy::math::IVec3, + #[proxy] + if_false: bevy::math::IVec3, + ) -> bevy::math::IVec3; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [i32; 3]) -> bevy::math::IVec3; + +"#, + r#" +/// `[x, y, z]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [i32; 3]; + +"#, + r#" +/// Creates a 4D vector from `self` and the given `w` value. + + #[lua(kind = "Method", output(proxy))] + fn extend(self, w: i32) -> bevy::math::IVec4; + +"#, + r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. + + #[lua(kind = "Method", output(proxy))] + fn truncate(self) -> bevy::math::IVec2; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: i32) -> bevy::math::IVec3; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: i32) -> bevy::math::IVec3; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `z`. + + #[lua(kind = "Method", output(proxy))] + fn with_z(self, z: i32) -> bevy::math::IVec3; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::IVec3) -> i32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" +/// Computes the cross product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn cross(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" +/// Component-wise clamping of values, similar to [`i32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::IVec3, + #[proxy] + max: bevy::math::IVec3, + ) -> bevy::math::IVec3; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> i32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> i32; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> i32; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> i32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn abs(self) -> bevy::math::IVec3; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `0` if the number is zero +/// - `1` if the number is positive +/// - `-1` if the number is negative + + #[lua(kind = "Method", output(proxy))] + fn signum(self) -> bevy::math::IVec3; + +"#, + r#" +/// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn is_negative_bitmask(self) -> u32; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua(kind = "Method")] + fn length_squared(self) -> i32; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance_squared(self, #[proxy] rhs: bevy::math::IVec3) -> i32; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. + + #[lua(kind = "Method", output(proxy))] + fn div_euclid(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. +/// [Euclidean division]: i32::rem_euclid + + #[lua(kind = "Method", output(proxy))] + fn rem_euclid(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec3(&self) -> bevy::math::Vec3; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec3a(&self) -> bevy::math::Vec3A; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec3(&self) -> bevy::math::DVec3; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec3(&self) -> bevy::math::UVec3; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec3(&self) -> bevy::math::I64Vec3; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec3(&self) -> bevy::math::U64Vec3; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_mul(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_div(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_mul(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_div(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.wrapping_add_unsigned(rhs.x), self.y.wrapping_add_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add_unsigned(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::IVec3; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.wrapping_sub_unsigned(rhs.x), self.y.wrapping_sub_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub_unsigned(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::IVec3; + +"#, + r#" +/// In other words this computes `[self.x.saturating_add_unsigned(rhs.x), self.y.saturating_add_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add_unsigned( + self, + #[proxy] + rhs: bevy::math::UVec3, + ) -> bevy::math::IVec3; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.saturating_sub_unsigned(rhs.x), self.y.saturating_sub_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub_unsigned( + self, + #[proxy] + rhs: bevy::math::UVec3, + ) -> bevy::math::IVec3; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind="MetaMethod", raw , metamethod="Index")] +fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(self.inner()?[*idx]) +} +"#, + r#" +#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] +fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: i32) -> Result<(),_> { + self.val_mut(|s| Ok(s[*idx] = val))? +} +"#] +)] +struct IVec3 { + x: i32, + y: i32, + z: i32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::IVec4", + functions[r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: i32) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: i32) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::IVec4) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: i32) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: i32) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: i32) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::IVec4) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::IVec4; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: i32, y: i32, z: i32, w: i32) -> bevy::math::IVec4; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: i32) -> bevy::math::IVec4; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec4, + #[proxy] + if_true: bevy::math::IVec4, + #[proxy] + if_false: bevy::math::IVec4, + ) -> bevy::math::IVec4; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [i32; 4]) -> bevy::math::IVec4; + +"#, + r#" +/// `[x, y, z, w]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [i32; 4]; + +"#, + r#" +/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. +/// Truncation to [`IVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. + + #[lua(kind = "Method", output(proxy))] + fn truncate(self) -> bevy::math::IVec3; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: i32) -> bevy::math::IVec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: i32) -> bevy::math::IVec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `z`. + + #[lua(kind = "Method", output(proxy))] + fn with_z(self, z: i32) -> bevy::math::IVec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `w`. + + #[lua(kind = "Method", output(proxy))] + fn with_w(self, w: i32) -> bevy::math::IVec4; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::IVec4) -> i32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" +/// Component-wise clamping of values, similar to [`i32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::IVec4, + #[proxy] + max: bevy::math::IVec4, + ) -> bevy::math::IVec4; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> i32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> i32; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> i32; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> i32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn abs(self) -> bevy::math::IVec4; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `0` if the number is zero +/// - `1` if the number is positive +/// - `-1` if the number is negative + + #[lua(kind = "Method", output(proxy))] + fn signum(self) -> bevy::math::IVec4; + +"#, + r#" +/// Returns a bitmask with the lowest 4 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn is_negative_bitmask(self) -> u32; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua(kind = "Method")] + fn length_squared(self) -> i32; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance_squared(self, #[proxy] rhs: bevy::math::IVec4) -> i32; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. + + #[lua(kind = "Method", output(proxy))] + fn div_euclid(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. +/// [Euclidean division]: i32::rem_euclid + + #[lua(kind = "Method", output(proxy))] + fn rem_euclid(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec4(&self) -> bevy::math::Vec4; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec4(&self) -> bevy::math::DVec4; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec4(&self) -> bevy::math::UVec4; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec4(&self) -> bevy::math::I64Vec4; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec4(&self) -> bevy::math::U64Vec4; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_mul(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_div(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_mul(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_div(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.wrapping_add_unsigned(rhs.x), self.y.wrapping_add_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add_unsigned(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::IVec4; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.wrapping_sub_unsigned(rhs.x), self.y.wrapping_sub_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub_unsigned(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::IVec4; + +"#, + r#" +/// In other words this computes `[self.x.saturating_add_unsigned(rhs.x), self.y.saturating_add_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add_unsigned( + self, + #[proxy] + rhs: bevy::math::UVec4, + ) -> bevy::math::IVec4; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.saturating_sub_unsigned(rhs.x), self.y.saturating_sub_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub_unsigned( + self, + #[proxy] + rhs: bevy::math::UVec4, + ) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::IVec4) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::IVec4) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::IVec4) -> bevy::math::IVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::IVec4) -> bevy::math::IVec4; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind="MetaMethod", raw , metamethod="Index")] +fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(self.inner()?[*idx]) +} +"#, + r#" +#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] +fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: i32) -> Result<(),_> { + self.val_mut(|s| Ok(s[*idx] = val))? +} +"#] +)] +struct IVec4 { + x: i32, + y: i32, + z: i32, + w: i32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::I64Vec2", + functions[r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: i64, y: i64) -> bevy::math::I64Vec2; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: i64) -> bevy::math::I64Vec2; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec2, + #[proxy] + if_true: bevy::math::I64Vec2, + #[proxy] + if_false: bevy::math::I64Vec2, + ) -> bevy::math::I64Vec2; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [i64; 2]) -> bevy::math::I64Vec2; + +"#, + r#" +/// `[x, y]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [i64; 2]; + +"#, + r#" +/// Creates a 3D vector from `self` and the given `z` value. + + #[lua(kind = "Method", output(proxy))] + fn extend(self, z: i64) -> bevy::math::I64Vec3; + +"#, + r#" +/// Creates a 2D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: i64) -> bevy::math::I64Vec2; + +"#, + r#" +/// Creates a 2D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: i64) -> bevy::math::I64Vec2; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::I64Vec2) -> i64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" +/// Component-wise clamping of values, similar to [`i64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::I64Vec2, + #[proxy] + max: bevy::math::I64Vec2, + ) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> i64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> i64; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> i64; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> i64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn abs(self) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `0` if the number is zero +/// - `1` if the number is positive +/// - `-1` if the number is negative + + #[lua(kind = "Method", output(proxy))] + fn signum(self) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a bitmask with the lowest 2 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn is_negative_bitmask(self) -> u32; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua(kind = "Method")] + fn length_squared(self) -> i64; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance_squared(self, #[proxy] rhs: bevy::math::I64Vec2) -> i64; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. + + #[lua(kind = "Method", output(proxy))] + fn div_euclid(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. +/// [Euclidean division]: i64::rem_euclid + + #[lua(kind = "Method", output(proxy))] + fn rem_euclid(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a vector that is equal to `self` rotated by 90 degrees. + + #[lua(kind = "Method", output(proxy))] + fn perp(self) -> bevy::math::I64Vec2; + +"#, + r#" +/// The perpendicular dot product of `self` and `rhs`. +/// Also known as the wedge product, 2D cross product, and determinant. + + #[lua(kind = "Method")] + fn perp_dot(self, #[proxy] rhs: bevy::math::I64Vec2) -> i64; + +"#, + r#" +/// Returns `rhs` rotated by the angle of `self`. If `self` is normalized, +/// then this just rotation. This is what you usually want. Otherwise, +/// it will be like a rotation with a multiplication by `self`'s length. + + #[lua(kind = "Method", output(proxy))] + fn rotate(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec2(&self) -> bevy::math::Vec2; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec2(&self) -> bevy::math::DVec2; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec2(&self) -> bevy::math::IVec2; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec2(&self) -> bevy::math::UVec2; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec2(&self) -> bevy::math::U64Vec2; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_mul(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_div(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_mul(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_div(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.wrapping_add_unsigned(rhs.x), self.y.wrapping_add_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add_unsigned( + self, + #[proxy] + rhs: bevy::math::U64Vec2, + ) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.wrapping_sub_unsigned(rhs.x), self.y.wrapping_sub_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub_unsigned( + self, + #[proxy] + rhs: bevy::math::U64Vec2, + ) -> bevy::math::I64Vec2; + +"#, + r#" +/// In other words this computes `[self.x.saturating_add_unsigned(rhs.x), self.y.saturating_add_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add_unsigned( + self, + #[proxy] + rhs: bevy::math::U64Vec2, + ) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.saturating_sub_unsigned(rhs.x), self.y.saturating_sub_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub_unsigned( + self, + #[proxy] + rhs: bevy::math::U64Vec2, + ) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: i64) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: i64) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: i64) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: i64) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::I64Vec2) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: i64) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct I64Vec2 { + x: i64, + y: i64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::I64Vec3", + functions[r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: i64, y: i64, z: i64) -> bevy::math::I64Vec3; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: i64) -> bevy::math::I64Vec3; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec3, + #[proxy] + if_true: bevy::math::I64Vec3, + #[proxy] + if_false: bevy::math::I64Vec3, + ) -> bevy::math::I64Vec3; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [i64; 3]) -> bevy::math::I64Vec3; + +"#, + r#" +/// `[x, y, z]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [i64; 3]; + +"#, + r#" +/// Creates a 4D vector from `self` and the given `w` value. + + #[lua(kind = "Method", output(proxy))] + fn extend(self, w: i64) -> bevy::math::I64Vec4; + +"#, + r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. + + #[lua(kind = "Method", output(proxy))] + fn truncate(self) -> bevy::math::I64Vec2; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: i64) -> bevy::math::I64Vec3; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: i64) -> bevy::math::I64Vec3; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `z`. + + #[lua(kind = "Method", output(proxy))] + fn with_z(self, z: i64) -> bevy::math::I64Vec3; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::I64Vec3) -> i64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" +/// Computes the cross product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn cross(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" +/// Component-wise clamping of values, similar to [`i64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::I64Vec3, + #[proxy] + max: bevy::math::I64Vec3, + ) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> i64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> i64; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> i64; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> i64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn abs(self) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `0` if the number is zero +/// - `1` if the number is positive +/// - `-1` if the number is negative + + #[lua(kind = "Method", output(proxy))] + fn signum(self) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn is_negative_bitmask(self) -> u32; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua(kind = "Method")] + fn length_squared(self) -> i64; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance_squared(self, #[proxy] rhs: bevy::math::I64Vec3) -> i64; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. + + #[lua(kind = "Method", output(proxy))] + fn div_euclid(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. +/// [Euclidean division]: i64::rem_euclid + + #[lua(kind = "Method", output(proxy))] + fn rem_euclid(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec3(&self) -> bevy::math::Vec3; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec3a(&self) -> bevy::math::Vec3A; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec3(&self) -> bevy::math::DVec3; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec3(&self) -> bevy::math::IVec3; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec3(&self) -> bevy::math::UVec3; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec3(&self) -> bevy::math::U64Vec3; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_mul(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_div(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_mul(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_div(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.wrapping_add_unsigned(rhs.x), self.y.wrapping_add_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add_unsigned( + self, + #[proxy] + rhs: bevy::math::U64Vec3, + ) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.wrapping_sub_unsigned(rhs.x), self.y.wrapping_sub_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub_unsigned( + self, + #[proxy] + rhs: bevy::math::U64Vec3, + ) -> bevy::math::I64Vec3; + +"#, + r#" +/// In other words this computes `[self.x.saturating_add_unsigned(rhs.x), self.y.saturating_add_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add_unsigned( + self, + #[proxy] + rhs: bevy::math::U64Vec3, + ) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.saturating_sub_unsigned(rhs.x), self.y.saturating_sub_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub_unsigned( + self, + #[proxy] + rhs: bevy::math::U64Vec3, + ) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: i64) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: i64) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::I64Vec3) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: i64) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: i64) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: i64) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::I64Vec3) -> bevy::math::I64Vec3; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct I64Vec3 { + x: i64, + y: i64, + z: i64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::I64Vec4", + functions[r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: i64) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::I64Vec4) -> bool; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: i64, y: i64, z: i64, w: i64) -> bevy::math::I64Vec4; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: i64) -> bevy::math::I64Vec4; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec4, + #[proxy] + if_true: bevy::math::I64Vec4, + #[proxy] + if_false: bevy::math::I64Vec4, + ) -> bevy::math::I64Vec4; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [i64; 4]) -> bevy::math::I64Vec4; + +"#, + r#" +/// `[x, y, z, w]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [i64; 4]; + +"#, + r#" +/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. +/// Truncation to [`I64Vec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. + + #[lua(kind = "Method", output(proxy))] + fn truncate(self) -> bevy::math::I64Vec3; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: i64) -> bevy::math::I64Vec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: i64) -> bevy::math::I64Vec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `z`. + + #[lua(kind = "Method", output(proxy))] + fn with_z(self, z: i64) -> bevy::math::I64Vec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `w`. + + #[lua(kind = "Method", output(proxy))] + fn with_w(self, w: i64) -> bevy::math::I64Vec4; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::I64Vec4) -> i64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" +/// Component-wise clamping of values, similar to [`i64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::I64Vec4, + #[proxy] + max: bevy::math::I64Vec4, + ) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> i64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> i64; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> i64; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> i64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn abs(self) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `0` if the number is zero +/// - `1` if the number is positive +/// - `-1` if the number is negative + + #[lua(kind = "Method", output(proxy))] + fn signum(self) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns a bitmask with the lowest 4 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn is_negative_bitmask(self) -> u32; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua(kind = "Method")] + fn length_squared(self) -> i64; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance_squared(self, #[proxy] rhs: bevy::math::I64Vec4) -> i64; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. + + #[lua(kind = "Method", output(proxy))] + fn div_euclid(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// # Panics +/// This function will panic if any `rhs` element is 0 or the division results in overflow. +/// [Euclidean division]: i64::rem_euclid + + #[lua(kind = "Method", output(proxy))] + fn rem_euclid(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec4(&self) -> bevy::math::Vec4; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec4(&self) -> bevy::math::DVec4; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec4(&self) -> bevy::math::IVec4; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec4(&self) -> bevy::math::UVec4; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec4(&self) -> bevy::math::U64Vec4; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_mul(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_div(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_mul(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_div(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.wrapping_add_unsigned(rhs.x), self.y.wrapping_add_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add_unsigned( + self, + #[proxy] + rhs: bevy::math::U64Vec4, + ) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.wrapping_sub_unsigned(rhs.x), self.y.wrapping_sub_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub_unsigned( + self, + #[proxy] + rhs: bevy::math::U64Vec4, + ) -> bevy::math::I64Vec4; + +"#, + r#" +/// In other words this computes `[self.x.saturating_add_unsigned(rhs.x), self.y.saturating_add_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add_unsigned( + self, + #[proxy] + rhs: bevy::math::U64Vec4, + ) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and unsigned vector `rhs`. +/// In other words this computes `[self.x.saturating_sub_unsigned(rhs.x), self.y.saturating_sub_unsigned(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub_unsigned( + self, + #[proxy] + rhs: bevy::math::U64Vec4, + ) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: i64) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: i64) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: i64) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: i64) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct I64Vec4 { + x: i64, + y: i64, + z: i64, + w: i64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::UVec2", + functions[r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::UVec2) -> bevy::math::UVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::UVec2) -> bevy::math::UVec2; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::UVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: u32) -> bevy::math::UVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: u32) -> bevy::math::UVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::UVec2) -> bevy::math::UVec2; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: u32, y: u32) -> bevy::math::UVec2; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: u32) -> bevy::math::UVec2; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec2, + #[proxy] + if_true: bevy::math::UVec2, + #[proxy] + if_false: bevy::math::UVec2, + ) -> bevy::math::UVec2; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [u32; 2]) -> bevy::math::UVec2; + +"#, + r#" +/// `[x, y]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [u32; 2]; + +"#, + r#" +/// Creates a 3D vector from `self` and the given `z` value. + + #[lua(kind = "Method", output(proxy))] + fn extend(self, z: u32) -> bevy::math::UVec3; + +"#, + r#" +/// Creates a 2D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: u32) -> bevy::math::UVec2; + +"#, + r#" +/// Creates a 2D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: u32) -> bevy::math::UVec2; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::UVec2) -> u32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" +/// Component-wise clamping of values, similar to [`u32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::UVec2, + #[proxy] + max: bevy::math::UVec2, + ) -> bevy::math::UVec2; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> u32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> u32; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> u32; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> u32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua(kind = "Method")] + fn length_squared(self) -> u32; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec2(&self) -> bevy::math::Vec2; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec2(&self) -> bevy::math::DVec2; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec2(&self) -> bevy::math::IVec2; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec2(&self) -> bevy::math::I64Vec2; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec2(&self) -> bevy::math::U64Vec2; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_mul(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_div(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_mul(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_div(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`. +/// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add_signed(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::UVec2; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and signed vector `rhs`. +/// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add_signed(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::UVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: u32) -> bevy::math::UVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: u32) -> bevy::math::UVec2; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::UVec2) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: u32) -> bevy::math::UVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::UVec2) -> bevy::math::UVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::UVec2) -> bevy::math::UVec2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind="MetaMethod", raw , metamethod="Index")] +fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(self.inner()?[*idx]) +} +"#, + r#" +#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] +fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: u32) -> Result<(),_> { + self.val_mut(|s| Ok(s[*idx] = val))? +} +"#] +)] +struct UVec2 { + x: u32, + y: u32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::UVec3", + functions[r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::UVec3) -> bevy::math::UVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::UVec3) -> bevy::math::UVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::UVec3) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::UVec3) -> bevy::math::UVec3; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::UVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: u32) -> bevy::math::UVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: u32) -> bevy::math::UVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: u32) -> bevy::math::UVec3; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: u32, y: u32, z: u32) -> bevy::math::UVec3; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: u32) -> bevy::math::UVec3; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec3, + #[proxy] + if_true: bevy::math::UVec3, + #[proxy] + if_false: bevy::math::UVec3, + ) -> bevy::math::UVec3; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [u32; 3]) -> bevy::math::UVec3; + +"#, + r#" +/// `[x, y, z]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [u32; 3]; + +"#, + r#" +/// Creates a 4D vector from `self` and the given `w` value. + + #[lua(kind = "Method", output(proxy))] + fn extend(self, w: u32) -> bevy::math::UVec4; + +"#, + r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. + + #[lua(kind = "Method", output(proxy))] + fn truncate(self) -> bevy::math::UVec2; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: u32) -> bevy::math::UVec3; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: u32) -> bevy::math::UVec3; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `z`. + + #[lua(kind = "Method", output(proxy))] + fn with_z(self, z: u32) -> bevy::math::UVec3; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::UVec3) -> u32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" +/// Computes the cross product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn cross(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" +/// Component-wise clamping of values, similar to [`u32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::UVec3, + #[proxy] + max: bevy::math::UVec3, + ) -> bevy::math::UVec3; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> u32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> u32; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> u32; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> u32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua(kind = "Method")] + fn length_squared(self) -> u32; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec3(&self) -> bevy::math::Vec3; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec3a(&self) -> bevy::math::Vec3A; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec3(&self) -> bevy::math::DVec3; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec3(&self) -> bevy::math::IVec3; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec3(&self) -> bevy::math::I64Vec3; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec3(&self) -> bevy::math::U64Vec3; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_mul(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_div(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_mul(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_div(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`. +/// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add_signed(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::UVec3; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and signed vector `rhs`. +/// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add_signed(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::UVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::UVec3) -> bevy::math::UVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: u32) -> bevy::math::UVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::UVec3) -> bevy::math::UVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: u32) -> bevy::math::UVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind="MetaMethod", raw , metamethod="Index")] +fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(self.inner()?[*idx]) +} +"#, + r#" +#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] +fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: u32) -> Result<(),_> { + self.val_mut(|s| Ok(s[*idx] = val))? +} +"#] +)] +struct UVec3 { + x: u32, + y: u32, + z: u32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::UVec4", + functions[r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::UVec4) -> bevy::math::UVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::UVec4) -> bevy::math::UVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: u32) -> bevy::math::UVec4; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: u32, y: u32, z: u32, w: u32) -> bevy::math::UVec4; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: u32) -> bevy::math::UVec4; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec4, + #[proxy] + if_true: bevy::math::UVec4, + #[proxy] + if_false: bevy::math::UVec4, + ) -> bevy::math::UVec4; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [u32; 4]) -> bevy::math::UVec4; + +"#, + r#" +/// `[x, y, z, w]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [u32; 4]; + +"#, + r#" +/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. +/// Truncation to [`UVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. + + #[lua(kind = "Method", output(proxy))] + fn truncate(self) -> bevy::math::UVec3; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: u32) -> bevy::math::UVec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: u32) -> bevy::math::UVec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `z`. + + #[lua(kind = "Method", output(proxy))] + fn with_z(self, z: u32) -> bevy::math::UVec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `w`. + + #[lua(kind = "Method", output(proxy))] + fn with_w(self, w: u32) -> bevy::math::UVec4; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::UVec4) -> u32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" +/// Component-wise clamping of values, similar to [`u32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::UVec4, + #[proxy] + max: bevy::math::UVec4, + ) -> bevy::math::UVec4; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> u32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> u32; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> u32; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> u32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua(kind = "Method")] + fn length_squared(self) -> u32; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec4(&self) -> bevy::math::Vec4; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec4(&self) -> bevy::math::DVec4; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec4(&self) -> bevy::math::IVec4; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec4(&self) -> bevy::math::I64Vec4; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec4(&self) -> bevy::math::U64Vec4; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_mul(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_div(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_mul(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_div(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`. +/// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add_signed(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::UVec4; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and signed vector `rhs`. +/// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add_signed(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::UVec4; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::UVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::UVec4) -> bevy::math::UVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: u32) -> bevy::math::UVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::UVec4) -> bevy::math::UVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: u32) -> bevy::math::UVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: u32) -> bevy::math::UVec4; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::UVec4) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: u32) -> bevy::math::UVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::UVec4) -> bevy::math::UVec4; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind="MetaMethod", raw , metamethod="Index")] +fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(self.inner()?[*idx]) +} +"#, + r#" +#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] +fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: u32) -> Result<(),_> { + self.val_mut(|s| Ok(s[*idx] = val))? +} +"#] +)] +struct UVec4 { + x: u32, + y: u32, + z: u32, + w: u32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::U64Vec2", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: u64, y: u64) -> bevy::math::U64Vec2; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: u64) -> bevy::math::U64Vec2; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec2, + #[proxy] + if_true: bevy::math::U64Vec2, + #[proxy] + if_false: bevy::math::U64Vec2, + ) -> bevy::math::U64Vec2; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [u64; 2]) -> bevy::math::U64Vec2; + +"#, + r#" +/// `[x, y]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [u64; 2]; + +"#, + r#" +/// Creates a 3D vector from `self` and the given `z` value. + + #[lua(kind = "Method", output(proxy))] + fn extend(self, z: u64) -> bevy::math::U64Vec3; + +"#, + r#" +/// Creates a 2D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: u64) -> bevy::math::U64Vec2; + +"#, + r#" +/// Creates a 2D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: u64) -> bevy::math::U64Vec2; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::U64Vec2) -> u64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" +/// Component-wise clamping of values, similar to [`u64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::U64Vec2, + #[proxy] + max: bevy::math::U64Vec2, + ) -> bevy::math::U64Vec2; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> u64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> u64; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> u64; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> u64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua(kind = "Method")] + fn length_squared(self) -> u64; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec2(&self) -> bevy::math::Vec2; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec2(&self) -> bevy::math::DVec2; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec2(&self) -> bevy::math::IVec2; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec2(&self) -> bevy::math::UVec2; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec2(&self) -> bevy::math::I64Vec2; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_mul(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_div(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_mul(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_div(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`. +/// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add_signed( + self, + #[proxy] + rhs: bevy::math::I64Vec2, + ) -> bevy::math::U64Vec2; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and signed vector `rhs`. +/// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add_signed( + self, + #[proxy] + rhs: bevy::math::I64Vec2, + ) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: u64) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: u64) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: u64) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: u64) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::U64Vec2) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::U64Vec2) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: u64) -> bevy::math::U64Vec2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct U64Vec2 { + x: u64, + y: u64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::U64Vec3", + functions[r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: u64) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: u64) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: u64) -> bevy::math::U64Vec3; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: u64, y: u64, z: u64) -> bevy::math::U64Vec3; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: u64) -> bevy::math::U64Vec3; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec3, + #[proxy] + if_true: bevy::math::U64Vec3, + #[proxy] + if_false: bevy::math::U64Vec3, + ) -> bevy::math::U64Vec3; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [u64; 3]) -> bevy::math::U64Vec3; + +"#, + r#" +/// `[x, y, z]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [u64; 3]; + +"#, + r#" +/// Creates a 4D vector from `self` and the given `w` value. + + #[lua(kind = "Method", output(proxy))] + fn extend(self, w: u64) -> bevy::math::U64Vec4; + +"#, + r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. + + #[lua(kind = "Method", output(proxy))] + fn truncate(self) -> bevy::math::U64Vec2; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: u64) -> bevy::math::U64Vec3; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: u64) -> bevy::math::U64Vec3; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `z`. + + #[lua(kind = "Method", output(proxy))] + fn with_z(self, z: u64) -> bevy::math::U64Vec3; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::U64Vec3) -> u64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" +/// Computes the cross product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn cross(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" +/// Component-wise clamping of values, similar to [`u64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::U64Vec3, + #[proxy] + max: bevy::math::U64Vec3, + ) -> bevy::math::U64Vec3; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> u64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> u64; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> u64; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> u64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua(kind = "Method")] + fn length_squared(self) -> u64; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec3(&self) -> bevy::math::Vec3; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec3a(&self) -> bevy::math::Vec3A; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec3(&self) -> bevy::math::DVec3; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec3(&self) -> bevy::math::IVec3; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec3(&self) -> bevy::math::UVec3; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec3(&self) -> bevy::math::I64Vec3; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_mul(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_div(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_mul(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_div(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`. +/// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add_signed( + self, + #[proxy] + rhs: bevy::math::I64Vec3, + ) -> bevy::math::U64Vec3; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and signed vector `rhs`. +/// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add_signed( + self, + #[proxy] + rhs: bevy::math::I64Vec3, + ) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::U64Vec3) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: u64) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: u64) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct U64Vec3 { + x: u64, + y: u64, + z: u64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::U64Vec4", + functions[r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: u64) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: u64) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::U64Vec4) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: u64) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: u64, y: u64, z: u64, w: u64) -> bevy::math::U64Vec4; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: u64) -> bevy::math::U64Vec4; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec4, + #[proxy] + if_true: bevy::math::U64Vec4, + #[proxy] + if_false: bevy::math::U64Vec4, + ) -> bevy::math::U64Vec4; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [u64; 4]) -> bevy::math::U64Vec4; + +"#, + r#" +/// `[x, y, z, w]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [u64; 4]; + +"#, + r#" +/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. +/// Truncation to [`U64Vec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. + + #[lua(kind = "Method", output(proxy))] + fn truncate(self) -> bevy::math::U64Vec3; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: u64) -> bevy::math::U64Vec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: u64) -> bevy::math::U64Vec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `z`. + + #[lua(kind = "Method", output(proxy))] + fn with_z(self, z: u64) -> bevy::math::U64Vec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `w`. + + #[lua(kind = "Method", output(proxy))] + fn with_w(self, w: u64) -> bevy::math::U64Vec4; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::U64Vec4) -> u64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" +/// Component-wise clamping of values, similar to [`u64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::U64Vec4, + #[proxy] + max: bevy::math::U64Vec4, + ) -> bevy::math::U64Vec4; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> u64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> u64; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> u64; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> u64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; + +"#, + r#" +/// Computes the squared length of `self`. + + #[lua(kind = "Method")] + fn length_squared(self) -> u64; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec4(&self) -> bevy::math::Vec4; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec4(&self) -> bevy::math::DVec4; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec4(&self) -> bevy::math::IVec4; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec4(&self) -> bevy::math::UVec4; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec4(&self) -> bevy::math::I64Vec4; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" +/// Returns a vector containing the wrapping subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_sub(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" +/// Returns a vector containing the wrapping multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_mul(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" +/// Returns a vector containing the wrapping division of `self` and `rhs`. +/// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_div(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" +/// Returns a vector containing the saturating subtraction of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_sub(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" +/// Returns a vector containing the saturating multiplication of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_mul(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_div(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" +/// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`. +/// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn wrapping_add_signed( + self, + #[proxy] + rhs: bevy::math::I64Vec4, + ) -> bevy::math::U64Vec4; + +"#, + r#" +/// Returns a vector containing the saturating addition of `self` and signed vector `rhs`. +/// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn saturating_add_signed( + self, + #[proxy] + rhs: bevy::math::I64Vec4, + ) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: u64) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::U64Vec4) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: u64) -> bevy::math::U64Vec4; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct U64Vec4 { + x: u64, + y: u64, + z: u64, + w: u64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Vec2", + functions[r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: f32) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: f32) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::Vec2) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::Vec2) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::Vec2) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: f32) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: f32, y: f32) -> bevy::math::Vec2; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: f32) -> bevy::math::Vec2; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec2, + #[proxy] + if_true: bevy::math::Vec2, + #[proxy] + if_false: bevy::math::Vec2, + ) -> bevy::math::Vec2; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [f32; 2]) -> bevy::math::Vec2; + +"#, + r#" +/// `[x, y]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [f32; 2]; + +"#, + r#" +/// Creates a 3D vector from `self` and the given `z` value. + + #[lua(kind = "Method", output(proxy))] + fn extend(self, z: f32) -> bevy::math::Vec3; + +"#, + r#" +/// Creates a 2D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: f32) -> bevy::math::Vec2; + +"#, + r#" +/// Creates a 2D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: f32) -> bevy::math::Vec2; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::Vec2) -> f32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Component-wise clamping of values, similar to [`f32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::Vec2, + #[proxy] + max: bevy::math::Vec2, + ) -> bevy::math::Vec2; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> f32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> f32; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> f32; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> f32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn abs(self) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `1.0` if the number is positive, `+0.0` or `INFINITY` +/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` +/// - `NAN` if the number is `NAN` + + #[lua(kind = "Method", output(proxy))] + fn signum(self) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a vector with signs of `rhs` and the magnitudes of `self`. + + #[lua(kind = "Method", output(proxy))] + fn copysign(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a bitmask with the lowest 2 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn is_negative_bitmask(self) -> u32; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. If any element is either +/// `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(self) -> bool; + +"#, + r#" +/// Performs `is_finite` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`. + + #[lua(kind = "Method", output(proxy))] + fn is_finite_mask(self) -> bevy::math::BVec2; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(self) -> bool; + +"#, + r#" +/// Performs `is_nan` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`. + + #[lua(kind = "Method", output(proxy))] + fn is_nan_mask(self) -> bevy::math::BVec2; + +"#, + r#" +/// Computes the length of `self`. + + #[lua(kind = "Method")] + fn length(self) -> f32; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is faster than `length()` as it avoids a square root operation. + + #[lua(kind = "Method")] + fn length_squared(self) -> f32; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua(kind = "Method")] + fn length_recip(self) -> f32; + +"#, + r#" +/// Computes the Euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance(self, #[proxy] rhs: bevy::math::Vec2) -> f32; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance_squared(self, #[proxy] rhs: bevy::math::Vec2) -> f32; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn div_euclid(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// [Euclidean division]: f32::rem_euclid + + #[lua(kind = "Method", output(proxy))] + fn rem_euclid(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must be finite and _not_ of length zero, nor very close to zero. +/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. +/// Panics +/// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn normalize(self) -> bevy::math::Vec2; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns a +/// fallback value. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be the fallback value. +/// See also [`Self::try_normalize()`]. + + #[lua(kind = "Method", output(proxy))] + fn normalize_or(self, #[proxy] fallback: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns zero. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be zero. +/// See also [`Self::try_normalize()`]. + + #[lua(kind = "Method", output(proxy))] + fn normalize_or_zero(self) -> bevy::math::Vec2; + +"#, + r#" +/// Returns whether `self` is length `1.0` or not. +/// Uses a precision threshold of approximately `1e-4`. + + #[lua(kind = "Method")] + fn is_normalized(self) -> bool; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` is zero length when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn project_onto(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reject_from(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn project_onto_normalized(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reject_from_normalized(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a vector containing the nearest integer to a number for each element of `self`. +/// Round half-way cases away from 0.0. + + #[lua(kind = "Method", output(proxy))] + fn round(self) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a vector containing the largest integer less than or equal to a number for each +/// element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn floor(self) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a vector containing the smallest integer greater than or equal to a number for +/// each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn ceil(self) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a vector containing the integer part each element of `self`. This means numbers are +/// always truncated towards zero. + + #[lua(kind = "Method", output(proxy))] + fn trunc(self) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`. +/// Note that this differs from the GLSL implementation of `fract` which returns +/// `self - self.floor()`. +/// Note that this is fast but not precise for large numbers. + + #[lua(kind = "Method", output(proxy))] + fn fract(self) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector as `self - self.floor()`. +/// Note that this differs from the Rust implementation of `fract` which returns +/// `self - self.trunc()`. +/// Note that this is fast but not precise for large numbers. + + #[lua(kind = "Method", output(proxy))] + fn fract_gl(self) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a vector containing `e^self` (the exponential function) for each element of +/// `self`. + + #[lua(kind = "Method", output(proxy))] + fn exp(self) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a vector containing each element of `self` raised to the power of `n`. + + #[lua(kind = "Method", output(proxy))] + fn powf(self, n: f32) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn recip(self) -> bevy::math::Vec2; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result +/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly +/// extrapolated. + + #[lua(kind = "Method", output(proxy))] + fn lerp(self, #[proxy] rhs: bevy::math::Vec2, s: f32) -> bevy::math::Vec2; + +"#, + r#" +/// Moves towards `rhs` based on the value `d`. +/// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to +/// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn move_towards(&self, #[proxy] rhs: bevy::math::Vec2, d: f32) -> bevy::math::Vec2; + +"#, + r#" +/// Calculates the midpoint between `self` and `rhs`. +/// The midpoint is the average of, or halfway point between, two vectors. +/// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)` +/// while being slightly cheaper to compute. + + #[lua(kind = "Method", output(proxy))] + fn midpoint(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` is +/// less than or equal to `max_abs_diff`. +/// This can be used to compare if two vectors contain similar elements. It works best when +/// comparing with a known value. The `max_abs_diff` that should be used used depends on +/// the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(self, #[proxy] rhs: bevy::math::Vec2, max_abs_diff: f32) -> bool; + +"#, + r#" +/// Returns a vector with a length no less than `min` and no more than `max`. +/// # Panics +/// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length(self, min: f32, max: f32) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a vector with a length no more than `max`. +/// # Panics +/// Will panic if `max` is negative when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length_max(self, max: f32) -> bevy::math::Vec2; + +"#, + r#" +/// Returns a vector with a length no less than `min`. +/// # Panics +/// Will panic if `min` is negative when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length_min(self, min: f32) -> bevy::math::Vec2; + +"#, + r#" +/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding +/// error, yielding a more accurate result than an unfused multiply-add. +/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target +/// architecture has a dedicated fma CPU instruction. However, this is not always true, +/// and will be heavily dependant on designing algorithms with specific target hardware in +/// mind. + + #[lua(kind = "Method", output(proxy))] + fn mul_add( + self, + #[proxy] + a: bevy::math::Vec2, + #[proxy] + b: bevy::math::Vec2, + ) -> bevy::math::Vec2; + +"#, + r#" +/// Returns the reflection vector for a given incident vector `self` and surface normal +/// `normal`. +/// `normal` must be normalized. +/// # Panics +/// Will panic if `normal` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reflect(self, #[proxy] normal: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Returns the refraction direction for a given incident vector `self`, surface normal +/// `normal` and ratio of indices of refraction, `eta`. When total internal reflection occurs, +/// a zero vector will be returned. +/// `self` and `normal` must be normalized. +/// # Panics +/// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn refract(self, #[proxy] normal: bevy::math::Vec2, eta: f32) -> bevy::math::Vec2; + +"#, + r#" +/// Creates a 2D vector containing `[angle.cos(), angle.sin()]`. This can be used in +/// conjunction with the [`rotate()`][Self::rotate()] method, e.g. +/// `Vec2::from_angle(PI).rotate(Vec2::Y)` will create the vector `[-1, 0]` +/// and rotate [`Vec2::Y`] around it returning `-Vec2::Y`. + + #[lua(kind = "Function", output(proxy))] + fn from_angle(angle: f32) -> bevy::math::Vec2; + +"#, + r#" +/// Returns the angle (in radians) of this vector in the range `[-Ï€, +Ï€]`. +/// The input does not need to be a unit vector however it must be non-zero. + + #[lua(kind = "Method")] + fn to_angle(self) -> f32; + +"#, + r#" + + #[lua(kind = "Method")] + fn angle_between(self, #[proxy] rhs: bevy::math::Vec2) -> f32; + +"#, + r#" +/// Returns the angle of rotation (in radians) from `self` to `rhs` in the range `[-Ï€, +Ï€]`. +/// The inputs do not need to be unit vectors however they must be non-zero. + + #[lua(kind = "Method")] + fn angle_to(self, #[proxy] rhs: bevy::math::Vec2) -> f32; + +"#, + r#" +/// Returns a vector that is equal to `self` rotated by 90 degrees. + + #[lua(kind = "Method", output(proxy))] + fn perp(self) -> bevy::math::Vec2; + +"#, + r#" +/// The perpendicular dot product of `self` and `rhs`. +/// Also known as the wedge product, 2D cross product, and determinant. + + #[lua(kind = "Method")] + fn perp_dot(self, #[proxy] rhs: bevy::math::Vec2) -> f32; + +"#, + r#" +/// Returns `rhs` rotated by the angle of `self`. If `self` is normalized, +/// then this just rotation. This is what you usually want. Otherwise, +/// it will be like a rotation with a multiplication by `self`'s length. + + #[lua(kind = "Method", output(proxy))] + fn rotate(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Rotates towards `rhs` up to `max_angle` (in radians). +/// When `max_angle` is `0.0`, the result will be equal to `self`. When `max_angle` is equal to +/// `self.angle_between(rhs)`, the result will be equal to `rhs`. If `max_angle` is negative, +/// rotates towards the exact opposite of `rhs`. Will not go past the target. + + #[lua(kind = "Method", output(proxy))] + fn rotate_towards( + &self, + #[proxy] + rhs: bevy::math::Vec2, + max_angle: f32, + ) -> bevy::math::Vec2; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec2(&self) -> bevy::math::DVec2; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec2(&self) -> bevy::math::IVec2; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec2(&self) -> bevy::math::UVec2; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec2(&self) -> bevy::math::I64Vec2; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec2(&self) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f32) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::Vec2) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::Vec2) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::Vec2) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f32) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::Vec2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind="MetaMethod", raw , metamethod="Index")] +fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(self.inner()?[*idx]) +} +"#, + r#" +#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] +fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f32) -> Result<(),_> { + self.val_mut(|s| Ok(s[*idx] = val))? +} +"#] +)] +struct Vec2 { + x: f32, + y: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Vec3A", + functions[r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: f32) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f32) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f32) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: f32) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: f32) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::Vec3A) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: f32, y: f32, z: f32) -> bevy::math::Vec3A; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: f32) -> bevy::math::Vec3A; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec3A, + #[proxy] + if_true: bevy::math::Vec3A, + #[proxy] + if_false: bevy::math::Vec3A, + ) -> bevy::math::Vec3A; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [f32; 3]) -> bevy::math::Vec3A; + +"#, + r#" +/// `[x, y, z]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [f32; 3]; + +"#, + r#" +/// Creates a [`Vec3A`] from the `x`, `y` and `z` elements of `self` discarding `w`. +/// On architectures where SIMD is supported such as SSE2 on `x86_64` this conversion is a noop. + + #[lua(kind = "Function", output(proxy))] + fn from_vec4(#[proxy] v: bevy::math::Vec4) -> bevy::math::Vec3A; + +"#, + r#" +/// Creates a 4D vector from `self` and the given `w` value. + + #[lua(kind = "Method", output(proxy))] + fn extend(self, w: f32) -> bevy::math::Vec4; + +"#, + r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. + + #[lua(kind = "Method", output(proxy))] + fn truncate(self) -> bevy::math::Vec2; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: f32) -> bevy::math::Vec3A; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: f32) -> bevy::math::Vec3A; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `z`. + + #[lua(kind = "Method", output(proxy))] + fn with_z(self, z: f32) -> bevy::math::Vec3A; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::Vec3A) -> f32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Computes the cross product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn cross(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Component-wise clamping of values, similar to [`f32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::Vec3A, + #[proxy] + max: bevy::math::Vec3A, + ) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> f32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> f32; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> f32; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> f32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn abs(self) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `1.0` if the number is positive, `+0.0` or `INFINITY` +/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` +/// - `NAN` if the number is `NAN` + + #[lua(kind = "Method", output(proxy))] + fn signum(self) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a vector with signs of `rhs` and the magnitudes of `self`. + + #[lua(kind = "Method", output(proxy))] + fn copysign(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn is_negative_bitmask(self) -> u32; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. If any element is either +/// `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(self) -> bool; + +"#, + r#" +/// Performs `is_finite` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`. + + #[lua(kind = "Method", output(proxy))] + fn is_finite_mask(self) -> bevy::math::BVec3A; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(self) -> bool; + +"#, + r#" +/// Performs `is_nan` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`. + + #[lua(kind = "Method", output(proxy))] + fn is_nan_mask(self) -> bevy::math::BVec3A; + +"#, + r#" +/// Computes the length of `self`. + + #[lua(kind = "Method")] + fn length(self) -> f32; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is faster than `length()` as it avoids a square root operation. + + #[lua(kind = "Method")] + fn length_squared(self) -> f32; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua(kind = "Method")] + fn length_recip(self) -> f32; + +"#, + r#" +/// Computes the Euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance(self, #[proxy] rhs: bevy::math::Vec3A) -> f32; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance_squared(self, #[proxy] rhs: bevy::math::Vec3A) -> f32; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn div_euclid(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// [Euclidean division]: f32::rem_euclid + + #[lua(kind = "Method", output(proxy))] + fn rem_euclid(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must be finite and _not_ of length zero, nor very close to zero. +/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. +/// Panics +/// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn normalize(self) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns a +/// fallback value. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be the fallback value. +/// See also [`Self::try_normalize()`]. + + #[lua(kind = "Method", output(proxy))] + fn normalize_or(self, #[proxy] fallback: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns zero. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be zero. +/// See also [`Self::try_normalize()`]. + + #[lua(kind = "Method", output(proxy))] + fn normalize_or_zero(self) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns whether `self` is length `1.0` or not. +/// Uses a precision threshold of approximately `1e-4`. + + #[lua(kind = "Method")] + fn is_normalized(self) -> bool; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` is zero length when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn project_onto(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reject_from(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn project_onto_normalized( + self, + #[proxy] + rhs: bevy::math::Vec3A, + ) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reject_from_normalized( + self, + #[proxy] + rhs: bevy::math::Vec3A, + ) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a vector containing the nearest integer to a number for each element of `self`. +/// Round half-way cases away from 0.0. + + #[lua(kind = "Method", output(proxy))] + fn round(self) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a vector containing the largest integer less than or equal to a number for each +/// element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn floor(self) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a vector containing the smallest integer greater than or equal to a number for +/// each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn ceil(self) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a vector containing the integer part each element of `self`. This means numbers are +/// always truncated towards zero. + + #[lua(kind = "Method", output(proxy))] + fn trunc(self) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`. +/// Note that this differs from the GLSL implementation of `fract` which returns +/// `self - self.floor()`. +/// Note that this is fast but not precise for large numbers. + + #[lua(kind = "Method", output(proxy))] + fn fract(self) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector as `self - self.floor()`. +/// Note that this differs from the Rust implementation of `fract` which returns +/// `self - self.trunc()`. +/// Note that this is fast but not precise for large numbers. + + #[lua(kind = "Method", output(proxy))] + fn fract_gl(self) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a vector containing `e^self` (the exponential function) for each element of +/// `self`. + + #[lua(kind = "Method", output(proxy))] + fn exp(self) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a vector containing each element of `self` raised to the power of `n`. + + #[lua(kind = "Method", output(proxy))] + fn powf(self, n: f32) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn recip(self) -> bevy::math::Vec3A; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result +/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly +/// extrapolated. + + #[lua(kind = "Method", output(proxy))] + fn lerp(self, #[proxy] rhs: bevy::math::Vec3A, s: f32) -> bevy::math::Vec3A; + +"#, + r#" +/// Moves towards `rhs` based on the value `d`. +/// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to +/// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn move_towards(&self, #[proxy] rhs: bevy::math::Vec3A, d: f32) -> bevy::math::Vec3A; + +"#, + r#" +/// Calculates the midpoint between `self` and `rhs`. +/// The midpoint is the average of, or halfway point between, two vectors. +/// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)` +/// while being slightly cheaper to compute. + + #[lua(kind = "Method", output(proxy))] + fn midpoint(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` is +/// less than or equal to `max_abs_diff`. +/// This can be used to compare if two vectors contain similar elements. It works best when +/// comparing with a known value. The `max_abs_diff` that should be used used depends on +/// the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(self, #[proxy] rhs: bevy::math::Vec3A, max_abs_diff: f32) -> bool; + +"#, + r#" +/// Returns a vector with a length no less than `min` and no more than `max`. +/// # Panics +/// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length(self, min: f32, max: f32) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a vector with a length no more than `max`. +/// # Panics +/// Will panic if `max` is negative when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length_max(self, max: f32) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns a vector with a length no less than `min`. +/// # Panics +/// Will panic if `min` is negative when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length_min(self, min: f32) -> bevy::math::Vec3A; + +"#, + r#" +/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding +/// error, yielding a more accurate result than an unfused multiply-add. +/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target +/// architecture has a dedicated fma CPU instruction. However, this is not always true, +/// and will be heavily dependant on designing algorithms with specific target hardware in +/// mind. + + #[lua(kind = "Method", output(proxy))] + fn mul_add( + self, + #[proxy] + a: bevy::math::Vec3A, + #[proxy] + b: bevy::math::Vec3A, + ) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns the reflection vector for a given incident vector `self` and surface normal +/// `normal`. +/// `normal` must be normalized. +/// # Panics +/// Will panic if `normal` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reflect(self, #[proxy] normal: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns the refraction direction for a given incident vector `self`, surface normal +/// `normal` and ratio of indices of refraction, `eta`. When total internal reflection occurs, +/// a zero vector will be returned. +/// `self` and `normal` must be normalized. +/// # Panics +/// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn refract(self, #[proxy] normal: bevy::math::Vec3A, eta: f32) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns the angle (in radians) between two vectors in the range `[0, +Ï€]`. +/// The inputs do not need to be unit vectors however they must be non-zero. + + #[lua(kind = "Method")] + fn angle_between(self, #[proxy] rhs: bevy::math::Vec3A) -> f32; + +"#, + r#" +/// Returns some vector that is orthogonal to the given one. +/// The input vector must be finite and non-zero. +/// The output vector is not necessarily unit length. For that use +/// [`Self::any_orthonormal_vector()`] instead. + + #[lua(kind = "Method", output(proxy))] + fn any_orthogonal_vector(&self) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns any unit vector that is orthogonal to the given one. +/// The input vector must be unit length. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn any_orthonormal_vector(&self) -> bevy::math::Vec3A; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec3(&self) -> bevy::math::DVec3; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec3(&self) -> bevy::math::IVec3; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec3(&self) -> bevy::math::UVec3; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec3(&self) -> bevy::math::I64Vec3; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec3(&self) -> bevy::math::U64Vec3; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind="MetaMethod", raw , metamethod="Index")] +fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(self.inner()?[*idx]) +} +"#, + r#" +#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] +fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f32) -> Result<(),_> { + self.val_mut(|s| Ok(s[*idx] = val))? +} +"#] +)] +struct Vec3A(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Vec4", + functions[r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f32) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f32) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::Vec4) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: f32) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::Vec4) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::Vec4) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::Vec4) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: f32) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::Vec4) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::Vec4) -> bevy::math::Vec4; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: f32, y: f32, z: f32, w: f32) -> bevy::math::Vec4; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: f32) -> bevy::math::Vec4; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec4A, + #[proxy] + if_true: bevy::math::Vec4, + #[proxy] + if_false: bevy::math::Vec4, + ) -> bevy::math::Vec4; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [f32; 4]) -> bevy::math::Vec4; + +"#, + r#" +/// `[x, y, z, w]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [f32; 4]; + +"#, + r#" +/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. +/// Truncation to [`Vec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. +/// To truncate to [`Vec3A`] use [`Vec3A::from()`]. + + #[lua(kind = "Method", output(proxy))] + fn truncate(self) -> bevy::math::Vec3; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: f32) -> bevy::math::Vec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: f32) -> bevy::math::Vec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `z`. + + #[lua(kind = "Method", output(proxy))] + fn with_z(self, z: f32) -> bevy::math::Vec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `w`. + + #[lua(kind = "Method", output(proxy))] + fn with_w(self, w: f32) -> bevy::math::Vec4; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::Vec4) -> f32; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" +/// Component-wise clamping of values, similar to [`f32::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::Vec4, + #[proxy] + max: bevy::math::Vec4, + ) -> bevy::math::Vec4; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> f32; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> f32; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> f32; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> f32; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn abs(self) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `1.0` if the number is positive, `+0.0` or `INFINITY` +/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` +/// - `NAN` if the number is `NAN` + + #[lua(kind = "Method", output(proxy))] + fn signum(self) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a vector with signs of `rhs` and the magnitudes of `self`. + + #[lua(kind = "Method", output(proxy))] + fn copysign(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a bitmask with the lowest 4 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn is_negative_bitmask(self) -> u32; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. If any element is either +/// `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(self) -> bool; + +"#, + r#" +/// Performs `is_finite` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`. + + #[lua(kind = "Method", output(proxy))] + fn is_finite_mask(self) -> bevy::math::BVec4A; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(self) -> bool; + +"#, + r#" +/// Performs `is_nan` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`. + + #[lua(kind = "Method", output(proxy))] + fn is_nan_mask(self) -> bevy::math::BVec4A; + +"#, + r#" +/// Computes the length of `self`. + + #[lua(kind = "Method")] + fn length(self) -> f32; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is faster than `length()` as it avoids a square root operation. + + #[lua(kind = "Method")] + fn length_squared(self) -> f32; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua(kind = "Method")] + fn length_recip(self) -> f32; + +"#, + r#" +/// Computes the Euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance(self, #[proxy] rhs: bevy::math::Vec4) -> f32; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance_squared(self, #[proxy] rhs: bevy::math::Vec4) -> f32; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn div_euclid(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// [Euclidean division]: f32::rem_euclid + + #[lua(kind = "Method", output(proxy))] + fn rem_euclid(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must be finite and _not_ of length zero, nor very close to zero. +/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. +/// Panics +/// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn normalize(self) -> bevy::math::Vec4; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns a +/// fallback value. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be the fallback value. +/// See also [`Self::try_normalize()`]. + + #[lua(kind = "Method", output(proxy))] + fn normalize_or(self, #[proxy] fallback: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns zero. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be zero. +/// See also [`Self::try_normalize()`]. + + #[lua(kind = "Method", output(proxy))] + fn normalize_or_zero(self) -> bevy::math::Vec4; + +"#, + r#" +/// Returns whether `self` is length `1.0` or not. +/// Uses a precision threshold of approximately `1e-4`. + + #[lua(kind = "Method")] + fn is_normalized(self) -> bool; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` is zero length when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn project_onto(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reject_from(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn project_onto_normalized(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reject_from_normalized(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a vector containing the nearest integer to a number for each element of `self`. +/// Round half-way cases away from 0.0. + + #[lua(kind = "Method", output(proxy))] + fn round(self) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a vector containing the largest integer less than or equal to a number for each +/// element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn floor(self) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a vector containing the smallest integer greater than or equal to a number for +/// each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn ceil(self) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a vector containing the integer part each element of `self`. This means numbers are +/// always truncated towards zero. + + #[lua(kind = "Method", output(proxy))] + fn trunc(self) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`. +/// Note that this differs from the GLSL implementation of `fract` which returns +/// `self - self.floor()`. +/// Note that this is fast but not precise for large numbers. + + #[lua(kind = "Method", output(proxy))] + fn fract(self) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector as `self - self.floor()`. +/// Note that this differs from the Rust implementation of `fract` which returns +/// `self - self.trunc()`. +/// Note that this is fast but not precise for large numbers. + + #[lua(kind = "Method", output(proxy))] + fn fract_gl(self) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a vector containing `e^self` (the exponential function) for each element of +/// `self`. + + #[lua(kind = "Method", output(proxy))] + fn exp(self) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a vector containing each element of `self` raised to the power of `n`. + + #[lua(kind = "Method", output(proxy))] + fn powf(self, n: f32) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn recip(self) -> bevy::math::Vec4; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result +/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly +/// extrapolated. + + #[lua(kind = "Method", output(proxy))] + fn lerp(self, #[proxy] rhs: bevy::math::Vec4, s: f32) -> bevy::math::Vec4; + +"#, + r#" +/// Moves towards `rhs` based on the value `d`. +/// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to +/// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn move_towards(&self, #[proxy] rhs: bevy::math::Vec4, d: f32) -> bevy::math::Vec4; + +"#, + r#" +/// Calculates the midpoint between `self` and `rhs`. +/// The midpoint is the average of, or halfway point between, two vectors. +/// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)` +/// while being slightly cheaper to compute. + + #[lua(kind = "Method", output(proxy))] + fn midpoint(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` is +/// less than or equal to `max_abs_diff`. +/// This can be used to compare if two vectors contain similar elements. It works best when +/// comparing with a known value. The `max_abs_diff` that should be used used depends on +/// the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(self, #[proxy] rhs: bevy::math::Vec4, max_abs_diff: f32) -> bool; + +"#, + r#" +/// Returns a vector with a length no less than `min` and no more than `max`. +/// # Panics +/// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length(self, min: f32, max: f32) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a vector with a length no more than `max`. +/// # Panics +/// Will panic if `max` is negative when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length_max(self, max: f32) -> bevy::math::Vec4; + +"#, + r#" +/// Returns a vector with a length no less than `min`. +/// # Panics +/// Will panic if `min` is negative when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length_min(self, min: f32) -> bevy::math::Vec4; + +"#, + r#" +/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding +/// error, yielding a more accurate result than an unfused multiply-add. +/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target +/// architecture has a dedicated fma CPU instruction. However, this is not always true, +/// and will be heavily dependant on designing algorithms with specific target hardware in +/// mind. + + #[lua(kind = "Method", output(proxy))] + fn mul_add( + self, + #[proxy] + a: bevy::math::Vec4, + #[proxy] + b: bevy::math::Vec4, + ) -> bevy::math::Vec4; + +"#, + r#" +/// Returns the reflection vector for a given incident vector `self` and surface normal +/// `normal`. +/// `normal` must be normalized. +/// # Panics +/// Will panic if `normal` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reflect(self, #[proxy] normal: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" +/// Returns the refraction direction for a given incident vector `self`, surface normal +/// `normal` and ratio of indices of refraction, `eta`. When total internal reflection occurs, +/// a zero vector will be returned. +/// `self` and `normal` must be normalized. +/// # Panics +/// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn refract(self, #[proxy] normal: bevy::math::Vec4, eta: f32) -> bevy::math::Vec4; + +"#, + r#" +/// Casts all elements of `self` to `f64`. + + #[lua(kind = "Method", output(proxy))] + fn as_dvec4(&self) -> bevy::math::DVec4; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec4(&self) -> bevy::math::IVec4; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec4(&self) -> bevy::math::UVec4; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec4(&self) -> bevy::math::I64Vec4; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec4(&self) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: f32) -> bevy::math::Vec4; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind="MetaMethod", raw , metamethod="Index")] +fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(self.inner()?[*idx]) +} +"#, + r#" +#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] +fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f32) -> Result<(),_> { + self.val_mut(|s| Ok(s[*idx] = val))? +} +"#] +)] +struct Vec4(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::BVec2", + functions[r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::BVec2; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +/// Creates a new vector mask. + + #[lua(kind = "Function", output(proxy))] + fn new(x: bool, y: bool) -> bevy::math::BVec2; + +"#, + r#" +/// Creates a vector mask with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: bool) -> bevy::math::BVec2; + +"#, + r#" +/// Creates a new vector mask from a bool array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [bool; 2]) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a bitmask with the lowest 2 bits set from the elements of `self`. +/// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn bitmask(self) -> u32; + +"#, + r#" +/// Returns true if any of the elements are true, false otherwise. + + #[lua(kind = "Method")] + fn any(self) -> bool; + +"#, + r#" +/// Returns true if all the elements are true, false otherwise. + + #[lua(kind = "Method")] + fn all(self) -> bool; + +"#, + r#" +/// Tests the value at `index`. +/// Panics if `index` is greater than 1. + + #[lua(kind = "Method")] + fn test(&self, index: usize) -> bool; + +"#, + r#" +/// Sets the element at `index`. +/// Panics if `index` is greater than 1. + + #[lua(kind = "MutatingMethod")] + fn set(&mut self, index: usize, value: bool) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::BVec2) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct BVec2 { + x: bool, + y: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::BVec3", + functions[r#" +/// Creates a new vector mask. + + #[lua(kind = "Function", output(proxy))] + fn new(x: bool, y: bool, z: bool) -> bevy::math::BVec3; + +"#, + r#" +/// Creates a vector mask with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: bool) -> bevy::math::BVec3; + +"#, + r#" +/// Creates a new vector mask from a bool array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [bool; 3]) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a bitmask with the lowest 3 bits set from the elements of `self`. +/// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn bitmask(self) -> u32; + +"#, + r#" +/// Returns true if any of the elements are true, false otherwise. + + #[lua(kind = "Method")] + fn any(self) -> bool; + +"#, + r#" +/// Returns true if all the elements are true, false otherwise. + + #[lua(kind = "Method")] + fn all(self) -> bool; + +"#, + r#" +/// Tests the value at `index`. +/// Panics if `index` is greater than 2. + + #[lua(kind = "Method")] + fn test(&self, index: usize) -> bool; + +"#, + r#" +/// Sets the element at `index`. +/// Panics if `index` is greater than 2. + + #[lua(kind = "MutatingMethod")] + fn set(&mut self, index: usize, value: bool) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::BVec3) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::BVec3; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct BVec3 { + x: bool, + y: bool, + z: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::BVec4", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::BVec4) -> bool; + +"#, + r#" +/// Creates a new vector mask. + + #[lua(kind = "Function", output(proxy))] + fn new(x: bool, y: bool, z: bool, w: bool) -> bevy::math::BVec4; + +"#, + r#" +/// Creates a vector mask with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: bool) -> bevy::math::BVec4; + +"#, + r#" +/// Creates a new vector mask from a bool array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [bool; 4]) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a bitmask with the lowest 4 bits set from the elements of `self`. +/// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn bitmask(self) -> u32; + +"#, + r#" +/// Returns true if any of the elements are true, false otherwise. + + #[lua(kind = "Method")] + fn any(self) -> bool; + +"#, + r#" +/// Returns true if all the elements are true, false otherwise. + + #[lua(kind = "Method")] + fn all(self) -> bool; + +"#, + r#" +/// Tests the value at `index`. +/// Panics if `index` is greater than 3. + + #[lua(kind = "Method")] + fn test(&self, index: usize) -> bool; + +"#, + r#" +/// Sets the element at `index`. +/// Panics if `index` is greater than 3. + + #[lua(kind = "MutatingMethod")] + fn set(&mut self, index: usize, value: bool) -> (); + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::BVec4; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct BVec4 { + x: bool, + y: bool, + z: bool, + w: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::DVec2", + functions[r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::DVec2) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::DVec2) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f64) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::DVec2) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::DVec2) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: f64) -> bevy::math::DVec2; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: f64, y: f64) -> bevy::math::DVec2; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: f64) -> bevy::math::DVec2; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec2, + #[proxy] + if_true: bevy::math::DVec2, + #[proxy] + if_false: bevy::math::DVec2, + ) -> bevy::math::DVec2; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [f64; 2]) -> bevy::math::DVec2; + +"#, + r#" +/// `[x, y]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [f64; 2]; + +"#, + r#" +/// Creates a 3D vector from `self` and the given `z` value. + + #[lua(kind = "Method", output(proxy))] + fn extend(self, z: f64) -> bevy::math::DVec3; + +"#, + r#" +/// Creates a 2D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: f64) -> bevy::math::DVec2; + +"#, + r#" +/// Creates a 2D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: f64) -> bevy::math::DVec2; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::DVec2) -> f64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Component-wise clamping of values, similar to [`f64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::DVec2, + #[proxy] + max: bevy::math::DVec2, + ) -> bevy::math::DVec2; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> f64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> f64; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> f64; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> f64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn abs(self) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `1.0` if the number is positive, `+0.0` or `INFINITY` +/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` +/// - `NAN` if the number is `NAN` + + #[lua(kind = "Method", output(proxy))] + fn signum(self) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a vector with signs of `rhs` and the magnitudes of `self`. + + #[lua(kind = "Method", output(proxy))] + fn copysign(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a bitmask with the lowest 2 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn is_negative_bitmask(self) -> u32; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. If any element is either +/// `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(self) -> bool; + +"#, + r#" +/// Performs `is_finite` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`. + + #[lua(kind = "Method", output(proxy))] + fn is_finite_mask(self) -> bevy::math::BVec2; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(self) -> bool; + +"#, + r#" +/// Performs `is_nan` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`. + + #[lua(kind = "Method", output(proxy))] + fn is_nan_mask(self) -> bevy::math::BVec2; + +"#, + r#" +/// Computes the length of `self`. + + #[lua(kind = "Method")] + fn length(self) -> f64; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is faster than `length()` as it avoids a square root operation. + + #[lua(kind = "Method")] + fn length_squared(self) -> f64; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua(kind = "Method")] + fn length_recip(self) -> f64; + +"#, + r#" +/// Computes the Euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance(self, #[proxy] rhs: bevy::math::DVec2) -> f64; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance_squared(self, #[proxy] rhs: bevy::math::DVec2) -> f64; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn div_euclid(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// [Euclidean division]: f64::rem_euclid + + #[lua(kind = "Method", output(proxy))] + fn rem_euclid(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must be finite and _not_ of length zero, nor very close to zero. +/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. +/// Panics +/// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn normalize(self) -> bevy::math::DVec2; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns a +/// fallback value. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be the fallback value. +/// See also [`Self::try_normalize()`]. + + #[lua(kind = "Method", output(proxy))] + fn normalize_or(self, #[proxy] fallback: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns zero. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be zero. +/// See also [`Self::try_normalize()`]. + + #[lua(kind = "Method", output(proxy))] + fn normalize_or_zero(self) -> bevy::math::DVec2; + +"#, + r#" +/// Returns whether `self` is length `1.0` or not. +/// Uses a precision threshold of approximately `1e-4`. + + #[lua(kind = "Method")] + fn is_normalized(self) -> bool; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` is zero length when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn project_onto(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reject_from(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn project_onto_normalized( + self, + #[proxy] + rhs: bevy::math::DVec2, + ) -> bevy::math::DVec2; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reject_from_normalized( + self, + #[proxy] + rhs: bevy::math::DVec2, + ) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a vector containing the nearest integer to a number for each element of `self`. +/// Round half-way cases away from 0.0. + + #[lua(kind = "Method", output(proxy))] + fn round(self) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a vector containing the largest integer less than or equal to a number for each +/// element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn floor(self) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a vector containing the smallest integer greater than or equal to a number for +/// each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn ceil(self) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a vector containing the integer part each element of `self`. This means numbers are +/// always truncated towards zero. + + #[lua(kind = "Method", output(proxy))] + fn trunc(self) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`. +/// Note that this differs from the GLSL implementation of `fract` which returns +/// `self - self.floor()`. +/// Note that this is fast but not precise for large numbers. + + #[lua(kind = "Method", output(proxy))] + fn fract(self) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector as `self - self.floor()`. +/// Note that this differs from the Rust implementation of `fract` which returns +/// `self - self.trunc()`. +/// Note that this is fast but not precise for large numbers. + + #[lua(kind = "Method", output(proxy))] + fn fract_gl(self) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a vector containing `e^self` (the exponential function) for each element of +/// `self`. + + #[lua(kind = "Method", output(proxy))] + fn exp(self) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a vector containing each element of `self` raised to the power of `n`. + + #[lua(kind = "Method", output(proxy))] + fn powf(self, n: f64) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn recip(self) -> bevy::math::DVec2; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result +/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly +/// extrapolated. + + #[lua(kind = "Method", output(proxy))] + fn lerp(self, #[proxy] rhs: bevy::math::DVec2, s: f64) -> bevy::math::DVec2; + +"#, + r#" +/// Moves towards `rhs` based on the value `d`. +/// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to +/// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn move_towards(&self, #[proxy] rhs: bevy::math::DVec2, d: f64) -> bevy::math::DVec2; + +"#, + r#" +/// Calculates the midpoint between `self` and `rhs`. +/// The midpoint is the average of, or halfway point between, two vectors. +/// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)` +/// while being slightly cheaper to compute. + + #[lua(kind = "Method", output(proxy))] + fn midpoint(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` is +/// less than or equal to `max_abs_diff`. +/// This can be used to compare if two vectors contain similar elements. It works best when +/// comparing with a known value. The `max_abs_diff` that should be used used depends on +/// the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(self, #[proxy] rhs: bevy::math::DVec2, max_abs_diff: f64) -> bool; + +"#, + r#" +/// Returns a vector with a length no less than `min` and no more than `max`. +/// # Panics +/// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length(self, min: f64, max: f64) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a vector with a length no more than `max`. +/// # Panics +/// Will panic if `max` is negative when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length_max(self, max: f64) -> bevy::math::DVec2; + +"#, + r#" +/// Returns a vector with a length no less than `min`. +/// # Panics +/// Will panic if `min` is negative when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length_min(self, min: f64) -> bevy::math::DVec2; + +"#, + r#" +/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding +/// error, yielding a more accurate result than an unfused multiply-add. +/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target +/// architecture has a dedicated fma CPU instruction. However, this is not always true, +/// and will be heavily dependant on designing algorithms with specific target hardware in +/// mind. + + #[lua(kind = "Method", output(proxy))] + fn mul_add( + self, + #[proxy] + a: bevy::math::DVec2, + #[proxy] + b: bevy::math::DVec2, + ) -> bevy::math::DVec2; + +"#, + r#" +/// Returns the reflection vector for a given incident vector `self` and surface normal +/// `normal`. +/// `normal` must be normalized. +/// # Panics +/// Will panic if `normal` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reflect(self, #[proxy] normal: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Returns the refraction direction for a given incident vector `self`, surface normal +/// `normal` and ratio of indices of refraction, `eta`. When total internal reflection occurs, +/// a zero vector will be returned. +/// `self` and `normal` must be normalized. +/// # Panics +/// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn refract(self, #[proxy] normal: bevy::math::DVec2, eta: f64) -> bevy::math::DVec2; + +"#, + r#" +/// Creates a 2D vector containing `[angle.cos(), angle.sin()]`. This can be used in +/// conjunction with the [`rotate()`][Self::rotate()] method, e.g. +/// `DVec2::from_angle(PI).rotate(DVec2::Y)` will create the vector `[-1, 0]` +/// and rotate [`DVec2::Y`] around it returning `-DVec2::Y`. + + #[lua(kind = "Function", output(proxy))] + fn from_angle(angle: f64) -> bevy::math::DVec2; + +"#, + r#" +/// Returns the angle (in radians) of this vector in the range `[-Ï€, +Ï€]`. +/// The input does not need to be a unit vector however it must be non-zero. + + #[lua(kind = "Method")] + fn to_angle(self) -> f64; + +"#, + r#" + + #[lua(kind = "Method")] + fn angle_between(self, #[proxy] rhs: bevy::math::DVec2) -> f64; + +"#, + r#" +/// Returns the angle of rotation (in radians) from `self` to `rhs` in the range `[-Ï€, +Ï€]`. +/// The inputs do not need to be unit vectors however they must be non-zero. + + #[lua(kind = "Method")] + fn angle_to(self, #[proxy] rhs: bevy::math::DVec2) -> f64; + +"#, + r#" +/// Returns a vector that is equal to `self` rotated by 90 degrees. + + #[lua(kind = "Method", output(proxy))] + fn perp(self) -> bevy::math::DVec2; + +"#, + r#" +/// The perpendicular dot product of `self` and `rhs`. +/// Also known as the wedge product, 2D cross product, and determinant. + + #[lua(kind = "Method")] + fn perp_dot(self, #[proxy] rhs: bevy::math::DVec2) -> f64; + +"#, + r#" +/// Returns `rhs` rotated by the angle of `self`. If `self` is normalized, +/// then this just rotation. This is what you usually want. Otherwise, +/// it will be like a rotation with a multiplication by `self`'s length. + + #[lua(kind = "Method", output(proxy))] + fn rotate(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Rotates towards `rhs` up to `max_angle` (in radians). +/// When `max_angle` is `0.0`, the result will be equal to `self`. When `max_angle` is equal to +/// `self.angle_between(rhs)`, the result will be equal to `rhs`. If `max_angle` is negative, +/// rotates towards the exact opposite of `rhs`. Will not go past the target. + + #[lua(kind = "Method", output(proxy))] + fn rotate_towards( + &self, + #[proxy] + rhs: bevy::math::DVec2, + max_angle: f64, + ) -> bevy::math::DVec2; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec2(&self) -> bevy::math::Vec2; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec2(&self) -> bevy::math::IVec2; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec2(&self) -> bevy::math::UVec2; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec2(&self) -> bevy::math::I64Vec2; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec2(&self) -> bevy::math::U64Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f64) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: f64) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::DVec2) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: f64) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::DVec2) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind="MetaMethod", raw , metamethod="Index")] +fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(self.inner()?[*idx]) +} +"#, + r#" +#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] +fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f64) -> Result<(),_> { + self.val_mut(|s| Ok(s[*idx] = val))? +} +"#] +)] +struct DVec2 { + x: f64, + y: f64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::DVec3", + functions[r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::DVec3) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::DVec3) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f64) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::DVec3) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: f64) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: f64) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: f64) -> bevy::math::DVec3; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: f64, y: f64, z: f64) -> bevy::math::DVec3; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: f64) -> bevy::math::DVec3; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec3, + #[proxy] + if_true: bevy::math::DVec3, + #[proxy] + if_false: bevy::math::DVec3, + ) -> bevy::math::DVec3; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [f64; 3]) -> bevy::math::DVec3; + +"#, + r#" +/// `[x, y, z]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [f64; 3]; + +"#, + r#" +/// Creates a 4D vector from `self` and the given `w` value. + + #[lua(kind = "Method", output(proxy))] + fn extend(self, w: f64) -> bevy::math::DVec4; + +"#, + r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. + + #[lua(kind = "Method", output(proxy))] + fn truncate(self) -> bevy::math::DVec2; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: f64) -> bevy::math::DVec3; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: f64) -> bevy::math::DVec3; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `z`. + + #[lua(kind = "Method", output(proxy))] + fn with_z(self, z: f64) -> bevy::math::DVec3; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::DVec3) -> f64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Computes the cross product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn cross(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Component-wise clamping of values, similar to [`f64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::DVec3, + #[proxy] + max: bevy::math::DVec3, + ) -> bevy::math::DVec3; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> f64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> f64; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> f64; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> f64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn abs(self) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `1.0` if the number is positive, `+0.0` or `INFINITY` +/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` +/// - `NAN` if the number is `NAN` + + #[lua(kind = "Method", output(proxy))] + fn signum(self) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a vector with signs of `rhs` and the magnitudes of `self`. + + #[lua(kind = "Method", output(proxy))] + fn copysign(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn is_negative_bitmask(self) -> u32; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. If any element is either +/// `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(self) -> bool; + +"#, + r#" +/// Performs `is_finite` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`. + + #[lua(kind = "Method", output(proxy))] + fn is_finite_mask(self) -> bevy::math::BVec3; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(self) -> bool; + +"#, + r#" +/// Performs `is_nan` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`. + + #[lua(kind = "Method", output(proxy))] + fn is_nan_mask(self) -> bevy::math::BVec3; + +"#, + r#" +/// Computes the length of `self`. + + #[lua(kind = "Method")] + fn length(self) -> f64; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is faster than `length()` as it avoids a square root operation. + + #[lua(kind = "Method")] + fn length_squared(self) -> f64; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua(kind = "Method")] + fn length_recip(self) -> f64; + +"#, + r#" +/// Computes the Euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance(self, #[proxy] rhs: bevy::math::DVec3) -> f64; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance_squared(self, #[proxy] rhs: bevy::math::DVec3) -> f64; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn div_euclid(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// [Euclidean division]: f64::rem_euclid + + #[lua(kind = "Method", output(proxy))] + fn rem_euclid(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must be finite and _not_ of length zero, nor very close to zero. +/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. +/// Panics +/// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn normalize(self) -> bevy::math::DVec3; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns a +/// fallback value. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be the fallback value. +/// See also [`Self::try_normalize()`]. + + #[lua(kind = "Method", output(proxy))] + fn normalize_or(self, #[proxy] fallback: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns zero. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be zero. +/// See also [`Self::try_normalize()`]. + + #[lua(kind = "Method", output(proxy))] + fn normalize_or_zero(self) -> bevy::math::DVec3; + +"#, + r#" +/// Returns whether `self` is length `1.0` or not. +/// Uses a precision threshold of approximately `1e-4`. + + #[lua(kind = "Method")] + fn is_normalized(self) -> bool; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` is zero length when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn project_onto(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reject_from(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn project_onto_normalized( + self, + #[proxy] + rhs: bevy::math::DVec3, + ) -> bevy::math::DVec3; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reject_from_normalized( + self, + #[proxy] + rhs: bevy::math::DVec3, + ) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a vector containing the nearest integer to a number for each element of `self`. +/// Round half-way cases away from 0.0. + + #[lua(kind = "Method", output(proxy))] + fn round(self) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a vector containing the largest integer less than or equal to a number for each +/// element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn floor(self) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a vector containing the smallest integer greater than or equal to a number for +/// each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn ceil(self) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a vector containing the integer part each element of `self`. This means numbers are +/// always truncated towards zero. + + #[lua(kind = "Method", output(proxy))] + fn trunc(self) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`. +/// Note that this differs from the GLSL implementation of `fract` which returns +/// `self - self.floor()`. +/// Note that this is fast but not precise for large numbers. + + #[lua(kind = "Method", output(proxy))] + fn fract(self) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector as `self - self.floor()`. +/// Note that this differs from the Rust implementation of `fract` which returns +/// `self - self.trunc()`. +/// Note that this is fast but not precise for large numbers. + + #[lua(kind = "Method", output(proxy))] + fn fract_gl(self) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a vector containing `e^self` (the exponential function) for each element of +/// `self`. + + #[lua(kind = "Method", output(proxy))] + fn exp(self) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a vector containing each element of `self` raised to the power of `n`. + + #[lua(kind = "Method", output(proxy))] + fn powf(self, n: f64) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn recip(self) -> bevy::math::DVec3; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result +/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly +/// extrapolated. + + #[lua(kind = "Method", output(proxy))] + fn lerp(self, #[proxy] rhs: bevy::math::DVec3, s: f64) -> bevy::math::DVec3; + +"#, + r#" +/// Moves towards `rhs` based on the value `d`. +/// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to +/// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn move_towards(&self, #[proxy] rhs: bevy::math::DVec3, d: f64) -> bevy::math::DVec3; + +"#, + r#" +/// Calculates the midpoint between `self` and `rhs`. +/// The midpoint is the average of, or halfway point between, two vectors. +/// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)` +/// while being slightly cheaper to compute. + + #[lua(kind = "Method", output(proxy))] + fn midpoint(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` is +/// less than or equal to `max_abs_diff`. +/// This can be used to compare if two vectors contain similar elements. It works best when +/// comparing with a known value. The `max_abs_diff` that should be used used depends on +/// the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(self, #[proxy] rhs: bevy::math::DVec3, max_abs_diff: f64) -> bool; + +"#, + r#" +/// Returns a vector with a length no less than `min` and no more than `max`. +/// # Panics +/// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length(self, min: f64, max: f64) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a vector with a length no more than `max`. +/// # Panics +/// Will panic if `max` is negative when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length_max(self, max: f64) -> bevy::math::DVec3; + +"#, + r#" +/// Returns a vector with a length no less than `min`. +/// # Panics +/// Will panic if `min` is negative when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length_min(self, min: f64) -> bevy::math::DVec3; + +"#, + r#" +/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding +/// error, yielding a more accurate result than an unfused multiply-add. +/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target +/// architecture has a dedicated fma CPU instruction. However, this is not always true, +/// and will be heavily dependant on designing algorithms with specific target hardware in +/// mind. + + #[lua(kind = "Method", output(proxy))] + fn mul_add( + self, + #[proxy] + a: bevy::math::DVec3, + #[proxy] + b: bevy::math::DVec3, + ) -> bevy::math::DVec3; + +"#, + r#" +/// Returns the reflection vector for a given incident vector `self` and surface normal +/// `normal`. +/// `normal` must be normalized. +/// # Panics +/// Will panic if `normal` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reflect(self, #[proxy] normal: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Returns the refraction direction for a given incident vector `self`, surface normal +/// `normal` and ratio of indices of refraction, `eta`. When total internal reflection occurs, +/// a zero vector will be returned. +/// `self` and `normal` must be normalized. +/// # Panics +/// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn refract(self, #[proxy] normal: bevy::math::DVec3, eta: f64) -> bevy::math::DVec3; + +"#, + r#" +/// Returns the angle (in radians) between two vectors in the range `[0, +Ï€]`. +/// The inputs do not need to be unit vectors however they must be non-zero. + + #[lua(kind = "Method")] + fn angle_between(self, #[proxy] rhs: bevy::math::DVec3) -> f64; + +"#, + r#" +/// Returns some vector that is orthogonal to the given one. +/// The input vector must be finite and non-zero. +/// The output vector is not necessarily unit length. For that use +/// [`Self::any_orthonormal_vector()`] instead. + + #[lua(kind = "Method", output(proxy))] + fn any_orthogonal_vector(&self) -> bevy::math::DVec3; + +"#, + r#" +/// Returns any unit vector that is orthogonal to the given one. +/// The input vector must be unit length. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn any_orthonormal_vector(&self) -> bevy::math::DVec3; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec3(&self) -> bevy::math::Vec3; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec3a(&self) -> bevy::math::Vec3A; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec3(&self) -> bevy::math::IVec3; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec3(&self) -> bevy::math::UVec3; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec3(&self) -> bevy::math::I64Vec3; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec3(&self) -> bevy::math::U64Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::DVec3) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::DVec3) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::DVec3) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f64) -> bevy::math::DVec3; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind="MetaMethod", raw , metamethod="Index")] +fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(self.inner()?[*idx]) +} +"#, + r#" +#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] +fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f64) -> Result<(),_> { + self.val_mut(|s| Ok(s[*idx] = val))? +} +"#] +)] +struct DVec3 { + x: f64, + y: f64, + z: f64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::DVec4", + functions[r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::DVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: &glam::DVec4) -> bevy::math::DVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, rhs: f64) -> bevy::math::DVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: &glam::DVec4) -> bevy::math::DVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, rhs: f64) -> bevy::math::DVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f64) -> bevy::math::DVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: &glam::DVec4) -> bevy::math::DVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: &glam::DVec4) -> bevy::math::DVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: &glam::DVec4) -> bevy::math::DVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f64) -> bevy::math::DVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::DVec4; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::DVec4) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Rem", + kind = "MetaFunction", + output(proxy), + composite = "rem", + metamethod = "Mod", + )] + fn rem(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" +/// Creates a new vector. + + #[lua(kind = "Function", output(proxy))] + fn new(x: f64, y: f64, z: f64, w: f64) -> bevy::math::DVec4; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: f64) -> bevy::math::DVec4; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua(kind = "Function", output(proxy))] + fn select( + #[proxy] + mask: bevy::math::BVec4, + #[proxy] + if_true: bevy::math::DVec4, + #[proxy] + if_false: bevy::math::DVec4, + ) -> bevy::math::DVec4; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [f64; 4]) -> bevy::math::DVec4; + +"#, + r#" +/// `[x, y, z, w]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [f64; 4]; + +"#, + r#" +/// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. +/// Truncation to [`DVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. + + #[lua(kind = "Method", output(proxy))] + fn truncate(self) -> bevy::math::DVec3; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `x`. + + #[lua(kind = "Method", output(proxy))] + fn with_x(self, x: f64) -> bevy::math::DVec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `y`. + + #[lua(kind = "Method", output(proxy))] + fn with_y(self, y: f64) -> bevy::math::DVec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `z`. + + #[lua(kind = "Method", output(proxy))] + fn with_z(self, z: f64) -> bevy::math::DVec4; + +"#, + r#" +/// Creates a 4D vector from `self` with the given value of `w`. + + #[lua(kind = "Method", output(proxy))] + fn with_w(self, w: f64) -> bevy::math::DVec4; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::DVec4) -> f64; + +"#, + r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn dot_into_vec(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn min(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a vector containing the maximum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + + #[lua(kind = "Method", output(proxy))] + fn max(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" +/// Component-wise clamping of values, similar to [`f64::clamp`]. +/// Each element in `min` must be less-or-equal to the corresponding element in `max`. +/// # Panics +/// Will panic if `min` is greater than `max` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp( + self, + #[proxy] + min: bevy::math::DVec4, + #[proxy] + max: bevy::math::DVec4, + ) -> bevy::math::DVec4; + +"#, + r#" +/// Returns the horizontal minimum of `self`. +/// In other words this computes `min(x, y, ..)`. + + #[lua(kind = "Method")] + fn min_element(self) -> f64; + +"#, + r#" +/// Returns the horizontal maximum of `self`. +/// In other words this computes `max(x, y, ..)`. + + #[lua(kind = "Method")] + fn max_element(self) -> f64; + +"#, + r#" +/// Returns the sum of all elements of `self`. +/// In other words, this computes `self.x + self.y + ..`. + + #[lua(kind = "Method")] + fn element_sum(self) -> f64; + +"#, + r#" +/// Returns the product of all elements of `self`. +/// In other words, this computes `self.x * self.y * ..`. + + #[lua(kind = "Method")] + fn element_product(self) -> f64; + +"#, + r#" +/// Returns a vector mask containing the result of a `==` comparison for each element of +/// `self` and `rhs`. +/// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpeq(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `!=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpne(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `>=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpge(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `>` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmpgt(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `<=` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmple(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector mask containing the result of a `<` comparison for each element of +/// `self` and `rhs`. +/// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all +/// elements. + + #[lua(kind = "Method", output(proxy))] + fn cmplt(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; + +"#, + r#" +/// Returns a vector containing the absolute value of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn abs(self) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a vector with elements representing the sign of `self`. +/// - `1.0` if the number is positive, `+0.0` or `INFINITY` +/// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` +/// - `NAN` if the number is `NAN` + + #[lua(kind = "Method", output(proxy))] + fn signum(self) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a vector with signs of `rhs` and the magnitudes of `self`. + + #[lua(kind = "Method", output(proxy))] + fn copysign(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a bitmask with the lowest 4 bits set to the sign bits from the elements of `self`. +/// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn is_negative_bitmask(self) -> u32; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. If any element is either +/// `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(self) -> bool; + +"#, + r#" +/// Performs `is_finite` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`. + + #[lua(kind = "Method", output(proxy))] + fn is_finite_mask(self) -> bevy::math::BVec4; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(self) -> bool; + +"#, + r#" +/// Performs `is_nan` on each element of self, returning a vector mask of the results. +/// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`. + + #[lua(kind = "Method", output(proxy))] + fn is_nan_mask(self) -> bevy::math::BVec4; + +"#, + r#" +/// Computes the length of `self`. + + #[lua(kind = "Method")] + fn length(self) -> f64; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is faster than `length()` as it avoids a square root operation. + + #[lua(kind = "Method")] + fn length_squared(self) -> f64; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua(kind = "Method")] + fn length_recip(self) -> f64; + +"#, + r#" +/// Computes the Euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance(self, #[proxy] rhs: bevy::math::DVec4) -> f64; + +"#, + r#" +/// Compute the squared euclidean distance between two points in space. + + #[lua(kind = "Method")] + fn distance_squared(self, #[proxy] rhs: bevy::math::DVec4) -> f64; + +"#, + r#" +/// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn div_euclid(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" +/// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. +/// [Euclidean division]: f64::rem_euclid + + #[lua(kind = "Method", output(proxy))] + fn rem_euclid(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must be finite and _not_ of length zero, nor very close to zero. +/// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`]. +/// Panics +/// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn normalize(self) -> bevy::math::DVec4; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns a +/// fallback value. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be the fallback value. +/// See also [`Self::try_normalize()`]. + + #[lua(kind = "Method", output(proxy))] + fn normalize_or(self, #[proxy] fallback: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" +/// Returns `self` normalized to length 1.0 if possible, else returns zero. +/// In particular, if the input is zero (or very close to zero), or non-finite, +/// the result of this operation will be zero. +/// See also [`Self::try_normalize()`]. + + #[lua(kind = "Method", output(proxy))] + fn normalize_or_zero(self) -> bevy::math::DVec4; + +"#, + r#" +/// Returns whether `self` is length `1.0` or not. +/// Uses a precision threshold of approximately `1e-4`. + + #[lua(kind = "Method")] + fn is_normalized(self) -> bool; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` is zero length when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn project_onto(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be of non-zero length. +/// # Panics +/// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reject_from(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" +/// Returns the vector projection of `self` onto `rhs`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn project_onto_normalized( + self, + #[proxy] + rhs: bevy::math::DVec4, + ) -> bevy::math::DVec4; + +"#, + r#" +/// Returns the vector rejection of `self` from `rhs`. +/// The vector rejection is the vector perpendicular to the projection of `self` onto +/// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`. +/// `rhs` must be normalized. +/// # Panics +/// Will panic if `rhs` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reject_from_normalized( + self, + #[proxy] + rhs: bevy::math::DVec4, + ) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a vector containing the nearest integer to a number for each element of `self`. +/// Round half-way cases away from 0.0. + + #[lua(kind = "Method", output(proxy))] + fn round(self) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a vector containing the largest integer less than or equal to a number for each +/// element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn floor(self) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a vector containing the smallest integer greater than or equal to a number for +/// each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn ceil(self) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a vector containing the integer part each element of `self`. This means numbers are +/// always truncated towards zero. + + #[lua(kind = "Method", output(proxy))] + fn trunc(self) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector as `self - self.trunc()`. +/// Note that this differs from the GLSL implementation of `fract` which returns +/// `self - self.floor()`. +/// Note that this is fast but not precise for large numbers. + + #[lua(kind = "Method", output(proxy))] + fn fract(self) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a vector containing the fractional part of the vector as `self - self.floor()`. +/// Note that this differs from the Rust implementation of `fract` which returns +/// `self - self.trunc()`. +/// Note that this is fast but not precise for large numbers. + + #[lua(kind = "Method", output(proxy))] + fn fract_gl(self) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a vector containing `e^self` (the exponential function) for each element of +/// `self`. + + #[lua(kind = "Method", output(proxy))] + fn exp(self) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a vector containing each element of `self` raised to the power of `n`. + + #[lua(kind = "Method", output(proxy))] + fn powf(self, n: f64) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + + #[lua(kind = "Method", output(proxy))] + fn recip(self) -> bevy::math::DVec4; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result +/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly +/// extrapolated. + + #[lua(kind = "Method", output(proxy))] + fn lerp(self, #[proxy] rhs: bevy::math::DVec4, s: f64) -> bevy::math::DVec4; + +"#, + r#" +/// Moves towards `rhs` based on the value `d`. +/// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to +/// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`. + + #[lua(kind = "Method", output(proxy))] + fn move_towards(&self, #[proxy] rhs: bevy::math::DVec4, d: f64) -> bevy::math::DVec4; + +"#, + r#" +/// Calculates the midpoint between `self` and `rhs`. +/// The midpoint is the average of, or halfway point between, two vectors. +/// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)` +/// while being slightly cheaper to compute. + + #[lua(kind = "Method", output(proxy))] + fn midpoint(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` is +/// less than or equal to `max_abs_diff`. +/// This can be used to compare if two vectors contain similar elements. It works best when +/// comparing with a known value. The `max_abs_diff` that should be used used depends on +/// the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(self, #[proxy] rhs: bevy::math::DVec4, max_abs_diff: f64) -> bool; + +"#, + r#" +/// Returns a vector with a length no less than `min` and no more than `max`. +/// # Panics +/// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length(self, min: f64, max: f64) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a vector with a length no more than `max`. +/// # Panics +/// Will panic if `max` is negative when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length_max(self, max: f64) -> bevy::math::DVec4; + +"#, + r#" +/// Returns a vector with a length no less than `min`. +/// # Panics +/// Will panic if `min` is negative when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn clamp_length_min(self, min: f64) -> bevy::math::DVec4; + +"#, + r#" +/// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding +/// error, yielding a more accurate result than an unfused multiply-add. +/// Using `mul_add` *may* be more performant than an unfused multiply-add if the target +/// architecture has a dedicated fma CPU instruction. However, this is not always true, +/// and will be heavily dependant on designing algorithms with specific target hardware in +/// mind. + + #[lua(kind = "Method", output(proxy))] + fn mul_add( + self, + #[proxy] + a: bevy::math::DVec4, + #[proxy] + b: bevy::math::DVec4, + ) -> bevy::math::DVec4; + +"#, + r#" +/// Returns the reflection vector for a given incident vector `self` and surface normal +/// `normal`. +/// `normal` must be normalized. +/// # Panics +/// Will panic if `normal` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn reflect(self, #[proxy] normal: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" +/// Returns the refraction direction for a given incident vector `self`, surface normal +/// `normal` and ratio of indices of refraction, `eta`. When total internal reflection occurs, +/// a zero vector will be returned. +/// `self` and `normal` must be normalized. +/// # Panics +/// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn refract(self, #[proxy] normal: bevy::math::DVec4, eta: f64) -> bevy::math::DVec4; + +"#, + r#" +/// Casts all elements of `self` to `f32`. + + #[lua(kind = "Method", output(proxy))] + fn as_vec4(&self) -> bevy::math::Vec4; + +"#, + r#" +/// Casts all elements of `self` to `i32`. + + #[lua(kind = "Method", output(proxy))] + fn as_ivec4(&self) -> bevy::math::IVec4; + +"#, + r#" +/// Casts all elements of `self` to `u32`. + + #[lua(kind = "Method", output(proxy))] + fn as_uvec4(&self) -> bevy::math::UVec4; + +"#, + r#" +/// Casts all elements of `self` to `i64`. + + #[lua(kind = "Method", output(proxy))] + fn as_i64vec4(&self) -> bevy::math::I64Vec4; + +"#, + r#" +/// Casts all elements of `self` to `u64`. + + #[lua(kind = "Method", output(proxy))] + fn as_u64vec4(&self) -> bevy::math::U64Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, rhs: f64) -> bevy::math::DVec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind="MetaMethod", raw , metamethod="Index")] +fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(self.inner()?[*idx]) +} +"#, + r#" +#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] +fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f64) -> Result<(),_> { + self.val_mut(|s| Ok(s[*idx] = val))? +} +"#] +)] +struct DVec4 { + x: f64, + y: f64, + z: f64, + w: f64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Mat2", + functions[r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::Mat2; + +"#, + r#" +/// Creates a 2x2 matrix from two column vectors. + + #[lua(kind = "Function", output(proxy))] + fn from_cols( + #[proxy] + x_axis: bevy::math::Vec2, + #[proxy] + y_axis: bevy::math::Vec2, + ) -> bevy::math::Mat2; + +"#, + r#" +/// Creates a `[f32; 4]` array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array(&self) -> [f32; 4]; + +"#, + r#" +/// Creates a `[[f32; 2]; 2]` 2D array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array_2d(&self) -> [[f32; 2]; 2]; + +"#, + r#" +/// Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0. + + #[lua(kind = "Function", output(proxy))] + fn from_diagonal(#[proxy] diagonal: bevy::math::Vec2) -> bevy::math::Mat2; + +"#, + r#" +/// Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of +/// `angle` (in radians). + + #[lua(kind = "Function", output(proxy))] + fn from_scale_angle( + #[proxy] + scale: bevy::math::Vec2, + angle: f32, + ) -> bevy::math::Mat2; + +"#, + r#" +/// Creates a 2x2 matrix containing a rotation of `angle` (in radians). + + #[lua(kind = "Function", output(proxy))] + fn from_angle(angle: f32) -> bevy::math::Mat2; + +"#, + r#" +/// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. + + #[lua(kind = "Function", output(proxy))] + fn from_mat3(#[proxy] m: bevy::math::Mat3) -> bevy::math::Mat2; + +"#, + r#" +/// Creates a 2x2 matrix from the minor of the given 3x3 matrix, discarding the `i`th column +/// and `j`th row. +/// # Panics +/// Panics if `i` or `j` is greater than 2. + + #[lua(kind = "Function", output(proxy))] + fn from_mat3_minor( + #[proxy] + m: bevy::math::Mat3, + i: usize, + j: usize, + ) -> bevy::math::Mat2; + +"#, + r#" +/// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. + + #[lua(kind = "Function", output(proxy))] + fn from_mat3a(#[proxy] m: bevy::math::Mat3A) -> bevy::math::Mat2; + +"#, + r#" +/// Creates a 2x2 matrix from the minor of the given 3x3 matrix, discarding the `i`th column +/// and `j`th row. +/// # Panics +/// Panics if `i` or `j` is greater than 2. + + #[lua(kind = "Function", output(proxy))] + fn from_mat3a_minor( + #[proxy] + m: bevy::math::Mat3A, + i: usize, + j: usize, + ) -> bevy::math::Mat2; + +"#, + r#" +/// Returns the matrix column for the given `index`. +/// # Panics +/// Panics if `index` is greater than 1. + + #[lua(kind = "Method", output(proxy))] + fn col(&self, index: usize) -> bevy::math::Vec2; + +"#, + r#" +/// Returns the matrix row for the given `index`. +/// # Panics +/// Panics if `index` is greater than 1. + + #[lua(kind = "Method", output(proxy))] + fn row(&self, index: usize) -> bevy::math::Vec2; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(&self) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(&self) -> bool; + +"#, + r#" +/// Returns the transpose of `self`. + + #[lua(kind = "Method", output(proxy))] + fn transpose(&self) -> bevy::math::Mat2; + +"#, + r#" +/// Returns the determinant of `self`. + + #[lua(kind = "Method")] + fn determinant(&self) -> f32; + +"#, + r#" +/// Returns the inverse of `self`. +/// If the matrix is not invertible the returned matrix will be invalid. +/// # Panics +/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn inverse(&self) -> bevy::math::Mat2; + +"#, + r#" +/// Transforms a 2D vector. + + #[lua(kind = "Method", output(proxy))] + fn mul_vec2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Multiplies two 2x2 matrices. + + #[lua(kind = "Method", output(proxy))] + fn mul_mat2(&self, #[proxy] rhs: &glam::Mat2) -> bevy::math::Mat2; + +"#, + r#" +/// Adds two 2x2 matrices. + + #[lua(kind = "Method", output(proxy))] + fn add_mat2(&self, #[proxy] rhs: &glam::Mat2) -> bevy::math::Mat2; + +"#, + r#" +/// Subtracts two 2x2 matrices. + + #[lua(kind = "Method", output(proxy))] + fn sub_mat2(&self, #[proxy] rhs: &glam::Mat2) -> bevy::math::Mat2; + +"#, + r#" +/// Multiplies a 2x2 matrix by a scalar. + + #[lua(kind = "Method", output(proxy))] + fn mul_scalar(&self, rhs: f32) -> bevy::math::Mat2; + +"#, + r#" +/// Divides a 2x2 matrix by a scalar. + + #[lua(kind = "Method", output(proxy))] + fn div_scalar(&self, rhs: f32) -> bevy::math::Mat2; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two matrices contain similar elements. It works best +/// when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Mat2, max_abs_diff: f32) -> bool; + +"#, + r#" +/// Takes the absolute value of each element in `self` + + #[lua(kind = "Method", output(proxy))] + fn abs(&self) -> bevy::math::Mat2; + +"#, + r#" + + #[lua(kind = "Method", output(proxy))] + fn as_dmat2(&self) -> bevy::math::DMat2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Mat2) -> bevy::math::Mat2; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::Mat2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f32) -> bevy::math::Mat2; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::Mat2) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::Mat2) -> bevy::math::Mat2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f32) -> bevy::math::Mat2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::Mat2) -> bevy::math::Mat2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind = "MetaMethod", raw, metamethod="Index")] +fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(LuaVec2::new_ref( + self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ + label:"col", + get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + })), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(*idx)) + } else { + Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) + } + }) + }) + ) + ) +} +"#] +)] +struct Mat2(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Mat3", + functions[r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::Mat3) -> bevy::math::Mat3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f32) -> bevy::math::Mat3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Mat3) -> bevy::math::Mat3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::Mat3; + +"#, + r#" +/// Creates a 3x3 matrix from three column vectors. + + #[lua(kind = "Function", output(proxy))] + fn from_cols( + #[proxy] + x_axis: bevy::math::Vec3, + #[proxy] + y_axis: bevy::math::Vec3, + #[proxy] + z_axis: bevy::math::Vec3, + ) -> bevy::math::Mat3; + +"#, + r#" +/// Creates a `[f32; 9]` array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array(&self) -> [f32; 9]; + +"#, + r#" +/// Creates a `[[f32; 3]; 3]` 3D array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array_2d(&self) -> [[f32; 3]; 3]; + +"#, + r#" +/// Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. + + #[lua(kind = "Function", output(proxy))] + fn from_diagonal(#[proxy] diagonal: bevy::math::Vec3) -> bevy::math::Mat3; + +"#, + r#" +/// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column. + + #[lua(kind = "Function", output(proxy))] + fn from_mat4(#[proxy] m: bevy::math::Mat4) -> bevy::math::Mat3; + +"#, + r#" +/// Creates a 3x3 matrix from the minor of the given 4x4 matrix, discarding the `i`th column +/// and `j`th row. +/// # Panics +/// Panics if `i` or `j` is greater than 3. + + #[lua(kind = "Function", output(proxy))] + fn from_mat4_minor( + #[proxy] + m: bevy::math::Mat4, + i: usize, + j: usize, + ) -> bevy::math::Mat3; + +"#, + r#" +/// Creates a 3D rotation matrix from the given quaternion. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_quat(#[proxy] rotation: bevy::math::Quat) -> bevy::math::Mat3; + +"#, + r#" +/// Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in +/// radians). +/// # Panics +/// Will panic if `axis` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_axis_angle(#[proxy] axis: bevy::math::Vec3, angle: f32) -> bevy::math::Mat3; + +"#, + r#" +/// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in +/// radians). + + #[lua(kind = "Function", output(proxy))] + fn from_euler( + #[proxy] + order: bevy::math::EulerRot, + a: f32, + b: f32, + c: f32, + ) -> bevy::math::Mat3; + +"#, + r#" +/// Extract Euler angles with the given Euler rotation order. +/// Note if the input matrix contains scales, shears, or other non-rotation transformations then +/// the resulting Euler angles will be ill-defined. +/// # Panics +/// Will panic if any input matrix column is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method")] + fn to_euler(&self, #[proxy] order: bevy::math::EulerRot) -> (f32, f32, f32); + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_x(angle: f32) -> bevy::math::Mat3; + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the y axis. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_y(angle: f32) -> bevy::math::Mat3; + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the z axis. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_z(angle: f32) -> bevy::math::Mat3; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D `translation`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_translation(#[proxy] translation: bevy::math::Vec2) -> bevy::math::Mat3; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D rotation `angle` (in +/// radians). +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_angle(angle: f32) -> bevy::math::Mat3; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in +/// radians) and `translation`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_scale_angle_translation( + #[proxy] + scale: bevy::math::Vec2, + angle: f32, + #[proxy] + translation: bevy::math::Vec2, + ) -> bevy::math::Mat3; + +"#, + r#" +/// Creates an affine transformation matrix from the given non-uniform 2D `scale`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. +/// # Panics +/// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_scale(#[proxy] scale: bevy::math::Vec2) -> bevy::math::Mat3; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2x2 matrix. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_mat2(#[proxy] m: bevy::math::Mat2) -> bevy::math::Mat3; + +"#, + r#" +/// Returns the matrix column for the given `index`. +/// # Panics +/// Panics if `index` is greater than 2. + + #[lua(kind = "Method", output(proxy))] + fn col(&self, index: usize) -> bevy::math::Vec3; + +"#, + r#" +/// Returns the matrix row for the given `index`. +/// # Panics +/// Panics if `index` is greater than 2. + + #[lua(kind = "Method", output(proxy))] + fn row(&self, index: usize) -> bevy::math::Vec3; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(&self) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(&self) -> bool; + +"#, + r#" +/// Returns the transpose of `self`. + + #[lua(kind = "Method", output(proxy))] + fn transpose(&self) -> bevy::math::Mat3; + +"#, + r#" +/// Returns the determinant of `self`. + + #[lua(kind = "Method")] + fn determinant(&self) -> f32; + +"#, + r#" +/// Returns the inverse of `self`. +/// If the matrix is not invertible the returned matrix will be invalid. +/// # Panics +/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn inverse(&self) -> bevy::math::Mat3; + +"#, + r#" +/// Transforms the given 2D vector as a point. +/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn transform_point2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Rotates the given 2D vector. +/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn transform_vector2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Transforms a 3D vector. + + #[lua(kind = "Method", output(proxy))] + fn mul_vec3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Transforms a [`Vec3A`]. + + #[lua(kind = "Method", output(proxy))] + fn mul_vec3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Multiplies two 3x3 matrices. + + #[lua(kind = "Method", output(proxy))] + fn mul_mat3(&self, #[proxy] rhs: &glam::Mat3) -> bevy::math::Mat3; + +"#, + r#" +/// Adds two 3x3 matrices. + + #[lua(kind = "Method", output(proxy))] + fn add_mat3(&self, #[proxy] rhs: &glam::Mat3) -> bevy::math::Mat3; + +"#, + r#" +/// Subtracts two 3x3 matrices. + + #[lua(kind = "Method", output(proxy))] + fn sub_mat3(&self, #[proxy] rhs: &glam::Mat3) -> bevy::math::Mat3; + +"#, + r#" +/// Multiplies a 3x3 matrix by a scalar. + + #[lua(kind = "Method", output(proxy))] + fn mul_scalar(&self, rhs: f32) -> bevy::math::Mat3; + +"#, + r#" +/// Divides a 3x3 matrix by a scalar. + + #[lua(kind = "Method", output(proxy))] + fn div_scalar(&self, rhs: f32) -> bevy::math::Mat3; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two matrices contain similar elements. It works best +/// when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Mat3, max_abs_diff: f32) -> bool; + +"#, + r#" +/// Takes the absolute value of each element in `self` + + #[lua(kind = "Method", output(proxy))] + fn abs(&self) -> bevy::math::Mat3; + +"#, + r#" + + #[lua(kind = "Method", output(proxy))] + fn as_dmat3(&self) -> bevy::math::DMat3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::Mat3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f32) -> bevy::math::Mat3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::Mat3) -> bevy::math::Mat3; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::Mat3) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Affine2) -> bevy::math::Mat3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind = "MetaMethod", raw, metamethod="Index")] +fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(LuaVec3::new_ref( + self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ + label:"col", + get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + })), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(*idx)) + } else { + Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) + } + }) + }) + ) + ) +} +"#] +)] +struct Mat3 { + #[lua(output(proxy))] + x_axis: bevy::math::Vec3, + #[lua(output(proxy))] + y_axis: bevy::math::Vec3, + #[lua(output(proxy))] + z_axis: bevy::math::Vec3, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Mat3A", + functions[r#" +/// Creates a 3x3 matrix from three column vectors. + + #[lua(kind = "Function", output(proxy))] + fn from_cols( + #[proxy] + x_axis: bevy::math::Vec3A, + #[proxy] + y_axis: bevy::math::Vec3A, + #[proxy] + z_axis: bevy::math::Vec3A, + ) -> bevy::math::Mat3A; + +"#, + r#" +/// Creates a `[f32; 9]` array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array(&self) -> [f32; 9]; + +"#, + r#" +/// Creates a `[[f32; 3]; 3]` 3D array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array_2d(&self) -> [[f32; 3]; 3]; + +"#, + r#" +/// Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. + + #[lua(kind = "Function", output(proxy))] + fn from_diagonal(#[proxy] diagonal: bevy::math::Vec3) -> bevy::math::Mat3A; + +"#, + r#" +/// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column. + + #[lua(kind = "Function", output(proxy))] + fn from_mat4(#[proxy] m: bevy::math::Mat4) -> bevy::math::Mat3A; + +"#, + r#" +/// Creates a 3x3 matrix from the minor of the given 4x4 matrix, discarding the `i`th column +/// and `j`th row. +/// # Panics +/// Panics if `i` or `j` is greater than 3. + + #[lua(kind = "Function", output(proxy))] + fn from_mat4_minor( + #[proxy] + m: bevy::math::Mat4, + i: usize, + j: usize, + ) -> bevy::math::Mat3A; + +"#, + r#" +/// Creates a 3D rotation matrix from the given quaternion. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_quat(#[proxy] rotation: bevy::math::Quat) -> bevy::math::Mat3A; + +"#, + r#" +/// Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in +/// radians). +/// # Panics +/// Will panic if `axis` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_axis_angle(#[proxy] axis: bevy::math::Vec3, angle: f32) -> bevy::math::Mat3A; + +"#, + r#" +/// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in +/// radians). + + #[lua(kind = "Function", output(proxy))] + fn from_euler( + #[proxy] + order: bevy::math::EulerRot, + a: f32, + b: f32, + c: f32, + ) -> bevy::math::Mat3A; + +"#, + r#" +/// Extract Euler angles with the given Euler rotation order. +/// Note if the input matrix contains scales, shears, or other non-rotation transformations then +/// the resulting Euler angles will be ill-defined. +/// # Panics +/// Will panic if any input matrix column is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method")] + fn to_euler(&self, #[proxy] order: bevy::math::EulerRot) -> (f32, f32, f32); + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_x(angle: f32) -> bevy::math::Mat3A; + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the y axis. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_y(angle: f32) -> bevy::math::Mat3A; + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the z axis. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_z(angle: f32) -> bevy::math::Mat3A; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D `translation`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_translation(#[proxy] translation: bevy::math::Vec2) -> bevy::math::Mat3A; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D rotation `angle` (in +/// radians). +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_angle(angle: f32) -> bevy::math::Mat3A; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in +/// radians) and `translation`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_scale_angle_translation( + #[proxy] + scale: bevy::math::Vec2, + angle: f32, + #[proxy] + translation: bevy::math::Vec2, + ) -> bevy::math::Mat3A; + +"#, + r#" +/// Creates an affine transformation matrix from the given non-uniform 2D `scale`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. +/// # Panics +/// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_scale(#[proxy] scale: bevy::math::Vec2) -> bevy::math::Mat3A; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2x2 matrix. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_mat2(#[proxy] m: bevy::math::Mat2) -> bevy::math::Mat3A; + +"#, + r#" +/// Returns the matrix column for the given `index`. +/// # Panics +/// Panics if `index` is greater than 2. + + #[lua(kind = "Method", output(proxy))] + fn col(&self, index: usize) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns the matrix row for the given `index`. +/// # Panics +/// Panics if `index` is greater than 2. + + #[lua(kind = "Method", output(proxy))] + fn row(&self, index: usize) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(&self) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(&self) -> bool; + +"#, + r#" +/// Returns the transpose of `self`. + + #[lua(kind = "Method", output(proxy))] + fn transpose(&self) -> bevy::math::Mat3A; + +"#, + r#" +/// Returns the determinant of `self`. + + #[lua(kind = "Method")] + fn determinant(&self) -> f32; + +"#, + r#" +/// Returns the inverse of `self`. +/// If the matrix is not invertible the returned matrix will be invalid. +/// # Panics +/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn inverse(&self) -> bevy::math::Mat3A; + +"#, + r#" +/// Transforms the given 2D vector as a point. +/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn transform_point2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Rotates the given 2D vector. +/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn transform_vector2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Transforms a 3D vector. + + #[lua(kind = "Method", output(proxy))] + fn mul_vec3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Transforms a [`Vec3A`]. + + #[lua(kind = "Method", output(proxy))] + fn mul_vec3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Multiplies two 3x3 matrices. + + #[lua(kind = "Method", output(proxy))] + fn mul_mat3(&self, #[proxy] rhs: &glam::Mat3A) -> bevy::math::Mat3A; + +"#, + r#" +/// Adds two 3x3 matrices. + + #[lua(kind = "Method", output(proxy))] + fn add_mat3(&self, #[proxy] rhs: &glam::Mat3A) -> bevy::math::Mat3A; + +"#, + r#" +/// Subtracts two 3x3 matrices. + + #[lua(kind = "Method", output(proxy))] + fn sub_mat3(&self, #[proxy] rhs: &glam::Mat3A) -> bevy::math::Mat3A; + +"#, + r#" +/// Multiplies a 3x3 matrix by a scalar. + + #[lua(kind = "Method", output(proxy))] + fn mul_scalar(&self, rhs: f32) -> bevy::math::Mat3A; + +"#, + r#" +/// Divides a 3x3 matrix by a scalar. + + #[lua(kind = "Method", output(proxy))] + fn div_scalar(&self, rhs: f32) -> bevy::math::Mat3A; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two matrices contain similar elements. It works best +/// when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Mat3A, max_abs_diff: f32) -> bool; + +"#, + r#" +/// Takes the absolute value of each element in `self` + + #[lua(kind = "Method", output(proxy))] + fn abs(&self) -> bevy::math::Mat3A; + +"#, + r#" + + #[lua(kind = "Method", output(proxy))] + fn as_dmat3(&self) -> bevy::math::DMat3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::Mat3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::Mat3A) -> bevy::math::Mat3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::Mat3A) -> bevy::math::Mat3A; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::Mat3A) -> bool; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::Mat3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Mat3A) -> bevy::math::Mat3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f32) -> bevy::math::Mat3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Affine2) -> bevy::math::Mat3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f32) -> bevy::math::Mat3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind = "MetaMethod", raw, metamethod="Index")] +fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(LuaVec3A::new_ref( + self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ + label:"col", + get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + })), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(*idx)) + } else { + Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) + } + }) + }) + ) + ) +} +"#] +)] +struct Mat3A { + #[lua(output(proxy))] + x_axis: bevy::math::Vec3A, + #[lua(output(proxy))] + y_axis: bevy::math::Vec3A, + #[lua(output(proxy))] + z_axis: bevy::math::Vec3A, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Mat4", + functions[r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f32) -> bevy::math::Mat4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Mat4) -> bevy::math::Mat4; + +"#, + r#" +/// Creates a 4x4 matrix from four column vectors. + + #[lua(kind = "Function", output(proxy))] + fn from_cols( + #[proxy] + x_axis: bevy::math::Vec4, + #[proxy] + y_axis: bevy::math::Vec4, + #[proxy] + z_axis: bevy::math::Vec4, + #[proxy] + w_axis: bevy::math::Vec4, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates a `[f32; 16]` array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array(&self) -> [f32; 16]; + +"#, + r#" +/// Creates a `[[f32; 4]; 4]` 4D array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array_2d(&self) -> [[f32; 4]; 4]; + +"#, + r#" +/// Creates a 4x4 matrix with its diagonal set to `diagonal` and all other entries set to 0. + + #[lua(kind = "Function", output(proxy))] + fn from_diagonal(#[proxy] diagonal: bevy::math::Vec4) -> bevy::math::Mat4; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3D `scale`, `rotation` and +/// `translation`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_scale_rotation_translation( + #[proxy] + scale: bevy::math::Vec3, + #[proxy] + rotation: bevy::math::Quat, + #[proxy] + translation: bevy::math::Vec3, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3D `translation`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_translation( + #[proxy] + rotation: bevy::math::Quat, + #[proxy] + translation: bevy::math::Vec3, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates an affine transformation matrix from the given `rotation` quaternion. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_quat(#[proxy] rotation: bevy::math::Quat) -> bevy::math::Mat4; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3x3 linear transformation +/// matrix. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_mat3(#[proxy] m: bevy::math::Mat3) -> bevy::math::Mat4; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3x3 linear transformation +/// matrix. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_mat3a(#[proxy] m: bevy::math::Mat3A) -> bevy::math::Mat4; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3D `translation`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_translation(#[proxy] translation: bevy::math::Vec3) -> bevy::math::Mat4; + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around a normalized +/// rotation `axis` of `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `axis` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_axis_angle(#[proxy] axis: bevy::math::Vec3, angle: f32) -> bevy::math::Mat4; + +"#, + r#" +/// Creates a affine transformation matrix containing a rotation from the given euler +/// rotation sequence and angles (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_euler( + #[proxy] + order: bevy::math::EulerRot, + a: f32, + b: f32, + c: f32, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Extract Euler angles with the given Euler rotation order. +/// Note if the upper 3x3 matrix contain scales, shears, or other non-rotation transformations +/// then the resulting Euler angles will be ill-defined. +/// # Panics +/// Will panic if any column of the upper 3x3 rotation matrix is not normalized when +/// `glam_assert` is enabled. + + #[lua(kind = "Method")] + fn to_euler(&self, #[proxy] order: bevy::math::EulerRot) -> (f32, f32, f32); + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around the x axis of +/// `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_x(angle: f32) -> bevy::math::Mat4; + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around the y axis of +/// `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_y(angle: f32) -> bevy::math::Mat4; + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around the z axis of +/// `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_z(angle: f32) -> bevy::math::Mat4; + +"#, + r#" +/// Creates an affine transformation matrix containing the given 3D non-uniform `scale`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_scale(#[proxy] scale: bevy::math::Vec3) -> bevy::math::Mat4; + +"#, + r#" +/// Returns the matrix column for the given `index`. +/// # Panics +/// Panics if `index` is greater than 3. + + #[lua(kind = "Method", output(proxy))] + fn col(&self, index: usize) -> bevy::math::Vec4; + +"#, + r#" +/// Returns the matrix row for the given `index`. +/// # Panics +/// Panics if `index` is greater than 3. + + #[lua(kind = "Method", output(proxy))] + fn row(&self, index: usize) -> bevy::math::Vec4; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(&self) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(&self) -> bool; + +"#, + r#" +/// Returns the transpose of `self`. + + #[lua(kind = "Method", output(proxy))] + fn transpose(&self) -> bevy::math::Mat4; + +"#, + r#" +/// Returns the determinant of `self`. + + #[lua(kind = "Method")] + fn determinant(&self) -> f32; + +"#, + r#" +/// Returns the inverse of `self`. +/// If the matrix is not invertible the returned matrix will be invalid. +/// # Panics +/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn inverse(&self) -> bevy::math::Mat4; + +"#, + r#" +/// Creates a left-handed view matrix using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + + #[lua(kind = "Function", output(proxy))] + fn look_to_lh( + #[proxy] + eye: bevy::math::Vec3, + #[proxy] + dir: bevy::math::Vec3, + #[proxy] + up: bevy::math::Vec3, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates a right-handed view matrix using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + + #[lua(kind = "Function", output(proxy))] + fn look_to_rh( + #[proxy] + eye: bevy::math::Vec3, + #[proxy] + dir: bevy::math::Vec3, + #[proxy] + up: bevy::math::Vec3, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates a left-handed view matrix using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn look_at_lh( + #[proxy] + eye: bevy::math::Vec3, + #[proxy] + center: bevy::math::Vec3, + #[proxy] + up: bevy::math::Vec3, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates a right-handed view matrix using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn look_at_rh( + #[proxy] + eye: bevy::math::Vec3, + #[proxy] + center: bevy::math::Vec3, + #[proxy] + up: bevy::math::Vec3, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates a right-handed perspective projection matrix with `[-1,1]` depth range. +/// Useful to map the standard right-handed coordinate system into what OpenGL expects. +/// This is the same as the OpenGL `gluPerspective` function. +/// See + + #[lua(kind = "Function", output(proxy))] + fn perspective_rh_gl( + fov_y_radians: f32, + aspect_ratio: f32, + z_near: f32, + z_far: f32, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates a left-handed perspective projection matrix with `[0,1]` depth range. +/// Useful to map the standard left-handed coordinate system into what WebGPU/Metal/Direct3D expect. +/// # Panics +/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is +/// enabled. + + #[lua(kind = "Function", output(proxy))] + fn perspective_lh( + fov_y_radians: f32, + aspect_ratio: f32, + z_near: f32, + z_far: f32, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates a right-handed perspective projection matrix with `[0,1]` depth range. +/// Useful to map the standard right-handed coordinate system into what WebGPU/Metal/Direct3D expect. +/// # Panics +/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is +/// enabled. + + #[lua(kind = "Function", output(proxy))] + fn perspective_rh( + fov_y_radians: f32, + aspect_ratio: f32, + z_near: f32, + z_far: f32, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. +/// Like `perspective_lh`, but with an infinite value for `z_far`. +/// The result is that points near `z_near` are mapped to depth `0`, and as they move towards infinity the depth approaches `1`. +/// # Panics +/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is +/// enabled. + + #[lua(kind = "Function", output(proxy))] + fn perspective_infinite_lh( + fov_y_radians: f32, + aspect_ratio: f32, + z_near: f32, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates an infinite reverse left-handed perspective projection matrix with `[0,1]` depth range. +/// Similar to `perspective_infinite_lh`, but maps `Z = z_near` to a depth of `1` and `Z = infinity` to a depth of `0`. +/// # Panics +/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn perspective_infinite_reverse_lh( + fov_y_radians: f32, + aspect_ratio: f32, + z_near: f32, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates an infinite right-handed perspective projection matrix with `[0,1]` depth range. +/// Like `perspective_rh`, but with an infinite value for `z_far`. +/// The result is that points near `z_near` are mapped to depth `0`, and as they move towards infinity the depth approaches `1`. +/// # Panics +/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is +/// enabled. + + #[lua(kind = "Function", output(proxy))] + fn perspective_infinite_rh( + fov_y_radians: f32, + aspect_ratio: f32, + z_near: f32, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates an infinite reverse right-handed perspective projection matrix with `[0,1]` depth range. +/// Similar to `perspective_infinite_rh`, but maps `Z = z_near` to a depth of `1` and `Z = infinity` to a depth of `0`. +/// # Panics +/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn perspective_infinite_reverse_rh( + fov_y_radians: f32, + aspect_ratio: f32, + z_near: f32, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates a right-handed orthographic projection matrix with `[-1,1]` depth +/// range. This is the same as the OpenGL `glOrtho` function in OpenGL. +/// See +/// +/// Useful to map a right-handed coordinate system to the normalized device coordinates that OpenGL expects. + + #[lua(kind = "Function", output(proxy))] + fn orthographic_rh_gl( + left: f32, + right: f32, + bottom: f32, + top: f32, + near: f32, + far: f32, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates a left-handed orthographic projection matrix with `[0,1]` depth range. +/// Useful to map a left-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect. + + #[lua(kind = "Function", output(proxy))] + fn orthographic_lh( + left: f32, + right: f32, + bottom: f32, + top: f32, + near: f32, + far: f32, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Creates a right-handed orthographic projection matrix with `[0,1]` depth range. +/// Useful to map a right-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect. + + #[lua(kind = "Function", output(proxy))] + fn orthographic_rh( + left: f32, + right: f32, + bottom: f32, + top: f32, + near: f32, + far: f32, + ) -> bevy::math::Mat4; + +"#, + r#" +/// Transforms the given 3D vector as a point, applying perspective correction. +/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is `1.0`. +/// The perspective divide is performed meaning the resulting 3D vector is divided by `w`. +/// This method assumes that `self` contains a projective transform. + + #[lua(kind = "Method", output(proxy))] + fn project_point3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Transforms the given 3D vector as a point. +/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is +/// `1.0`. +/// This method assumes that `self` contains a valid affine transform. It does not perform +/// a perspective divide, if `self` contains a perspective transform, or if you are unsure, +/// the [`Self::project_point3()`] method should be used instead. +/// # Panics +/// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn transform_point3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Transforms the give 3D vector as a direction. +/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is +/// `0.0`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn transform_vector3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Transforms the given [`Vec3A`] as a 3D point, applying perspective correction. +/// This is the equivalent of multiplying the [`Vec3A`] as a 4D vector where `w` is `1.0`. +/// The perspective divide is performed meaning the resulting 3D vector is divided by `w`. +/// This method assumes that `self` contains a projective transform. + + #[lua(kind = "Method", output(proxy))] + fn project_point3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Transforms the given [`Vec3A`] as 3D point. +/// This is the equivalent of multiplying the [`Vec3A`] as a 4D vector where `w` is `1.0`. + + #[lua(kind = "Method", output(proxy))] + fn transform_point3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Transforms the give [`Vec3A`] as 3D vector. +/// This is the equivalent of multiplying the [`Vec3A`] as a 4D vector where `w` is `0.0`. + + #[lua(kind = "Method", output(proxy))] + fn transform_vector3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Transforms a 4D vector. + + #[lua(kind = "Method", output(proxy))] + fn mul_vec4(&self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" +/// Multiplies two 4x4 matrices. + + #[lua(kind = "Method", output(proxy))] + fn mul_mat4(&self, #[proxy] rhs: &glam::Mat4) -> bevy::math::Mat4; + +"#, + r#" +/// Adds two 4x4 matrices. + + #[lua(kind = "Method", output(proxy))] + fn add_mat4(&self, #[proxy] rhs: &glam::Mat4) -> bevy::math::Mat4; + +"#, + r#" +/// Subtracts two 4x4 matrices. + + #[lua(kind = "Method", output(proxy))] + fn sub_mat4(&self, #[proxy] rhs: &glam::Mat4) -> bevy::math::Mat4; + +"#, + r#" +/// Multiplies a 4x4 matrix by a scalar. + + #[lua(kind = "Method", output(proxy))] + fn mul_scalar(&self, rhs: f32) -> bevy::math::Mat4; + +"#, + r#" +/// Divides a 4x4 matrix by a scalar. + + #[lua(kind = "Method", output(proxy))] + fn div_scalar(&self, rhs: f32) -> bevy::math::Mat4; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two matrices contain similar elements. It works best +/// when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Mat4, max_abs_diff: f32) -> bool; + +"#, + r#" +/// Takes the absolute value of each element in `self` + + #[lua(kind = "Method", output(proxy))] + fn abs(&self) -> bevy::math::Mat4; + +"#, + r#" + + #[lua(kind = "Method", output(proxy))] + fn as_dmat4(&self) -> bevy::math::DMat4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::Mat4) -> bevy::math::Mat4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f32) -> bevy::math::Mat4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::Mat4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Affine3A) -> bevy::math::Mat4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::Mat4) -> bevy::math::Mat4; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::Mat4) -> bool; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::Mat4; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind = "MetaMethod", raw, metamethod="Index")] +fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(LuaVec4::new_ref( + self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ + label:"col", + get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + })), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(*idx)) + } else { + Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) + } + }) + }) + ) + ) +} +"#] +)] +struct Mat4 { + #[lua(output(proxy))] + x_axis: bevy::math::Vec4, + #[lua(output(proxy))] + y_axis: bevy::math::Vec4, + #[lua(output(proxy))] + z_axis: bevy::math::Vec4, + #[lua(output(proxy))] + w_axis: bevy::math::Vec4, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::DMat2", + functions[r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f64) -> bevy::math::DMat2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::DMat2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::DMat2) -> bevy::math::DMat2; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::DMat2; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::DMat2) -> bool; + +"#, + r#" +/// Creates a 2x2 matrix from two column vectors. + + #[lua(kind = "Function", output(proxy))] + fn from_cols( + #[proxy] + x_axis: bevy::math::DVec2, + #[proxy] + y_axis: bevy::math::DVec2, + ) -> bevy::math::DMat2; + +"#, + r#" +/// Creates a `[f64; 4]` array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array(&self) -> [f64; 4]; + +"#, + r#" +/// Creates a `[[f64; 2]; 2]` 2D array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array_2d(&self) -> [[f64; 2]; 2]; + +"#, + r#" +/// Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0. + + #[lua(kind = "Function", output(proxy))] + fn from_diagonal(#[proxy] diagonal: bevy::math::DVec2) -> bevy::math::DMat2; + +"#, + r#" +/// Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of +/// `angle` (in radians). + + #[lua(kind = "Function", output(proxy))] + fn from_scale_angle( + #[proxy] + scale: bevy::math::DVec2, + angle: f64, + ) -> bevy::math::DMat2; + +"#, + r#" +/// Creates a 2x2 matrix containing a rotation of `angle` (in radians). + + #[lua(kind = "Function", output(proxy))] + fn from_angle(angle: f64) -> bevy::math::DMat2; + +"#, + r#" +/// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. + + #[lua(kind = "Function", output(proxy))] + fn from_mat3(#[proxy] m: bevy::math::DMat3) -> bevy::math::DMat2; + +"#, + r#" +/// Creates a 2x2 matrix from the minor of the given 3x3 matrix, discarding the `i`th column +/// and `j`th row. +/// # Panics +/// Panics if `i` or `j` is greater than 2. + + #[lua(kind = "Function", output(proxy))] + fn from_mat3_minor( + #[proxy] + m: bevy::math::DMat3, + i: usize, + j: usize, + ) -> bevy::math::DMat2; + +"#, + r#" +/// Returns the matrix column for the given `index`. +/// # Panics +/// Panics if `index` is greater than 1. + + #[lua(kind = "Method", output(proxy))] + fn col(&self, index: usize) -> bevy::math::DVec2; + +"#, + r#" +/// Returns the matrix row for the given `index`. +/// # Panics +/// Panics if `index` is greater than 1. + + #[lua(kind = "Method", output(proxy))] + fn row(&self, index: usize) -> bevy::math::DVec2; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(&self) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(&self) -> bool; + +"#, + r#" +/// Returns the transpose of `self`. + + #[lua(kind = "Method", output(proxy))] + fn transpose(&self) -> bevy::math::DMat2; + +"#, + r#" +/// Returns the determinant of `self`. + + #[lua(kind = "Method")] + fn determinant(&self) -> f64; + +"#, + r#" +/// Returns the inverse of `self`. +/// If the matrix is not invertible the returned matrix will be invalid. +/// # Panics +/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn inverse(&self) -> bevy::math::DMat2; + +"#, + r#" +/// Transforms a 2D vector. + + #[lua(kind = "Method", output(proxy))] + fn mul_vec2(&self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Multiplies two 2x2 matrices. + + #[lua(kind = "Method", output(proxy))] + fn mul_mat2(&self, #[proxy] rhs: &glam::DMat2) -> bevy::math::DMat2; + +"#, + r#" +/// Adds two 2x2 matrices. + + #[lua(kind = "Method", output(proxy))] + fn add_mat2(&self, #[proxy] rhs: &glam::DMat2) -> bevy::math::DMat2; + +"#, + r#" +/// Subtracts two 2x2 matrices. + + #[lua(kind = "Method", output(proxy))] + fn sub_mat2(&self, #[proxy] rhs: &glam::DMat2) -> bevy::math::DMat2; + +"#, + r#" +/// Multiplies a 2x2 matrix by a scalar. + + #[lua(kind = "Method", output(proxy))] + fn mul_scalar(&self, rhs: f64) -> bevy::math::DMat2; + +"#, + r#" +/// Divides a 2x2 matrix by a scalar. + + #[lua(kind = "Method", output(proxy))] + fn div_scalar(&self, rhs: f64) -> bevy::math::DMat2; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two matrices contain similar elements. It works best +/// when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::DMat2, max_abs_diff: f64) -> bool; + +"#, + r#" +/// Takes the absolute value of each element in `self` + + #[lua(kind = "Method", output(proxy))] + fn abs(&self) -> bevy::math::DMat2; + +"#, + r#" + + #[lua(kind = "Method", output(proxy))] + fn as_mat2(&self) -> bevy::math::Mat2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::DMat2) -> bevy::math::DMat2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DMat2) -> bevy::math::DMat2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f64) -> bevy::math::DMat2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind = "MetaMethod", raw, metamethod="Index")] +fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(LuaDVec2::new_ref( + self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ + label:"col", + get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + })), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(*idx)) + } else { + Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) + } + }) + }) + ) + ) +} +"#] +)] +struct DMat2 { + #[lua(output(proxy))] + x_axis: bevy::math::DVec2, + #[lua(output(proxy))] + y_axis: bevy::math::DVec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::DMat3", + functions[r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DAffine2) -> bevy::math::DMat3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::DMat3) -> bevy::math::DMat3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::DMat3) -> bevy::math::DMat3; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::DMat3; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::DMat3) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::DMat3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f64) -> bevy::math::DMat3; + +"#, + r#" +/// Creates a 3x3 matrix from three column vectors. + + #[lua(kind = "Function", output(proxy))] + fn from_cols( + #[proxy] + x_axis: bevy::math::DVec3, + #[proxy] + y_axis: bevy::math::DVec3, + #[proxy] + z_axis: bevy::math::DVec3, + ) -> bevy::math::DMat3; + +"#, + r#" +/// Creates a `[f64; 9]` array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array(&self) -> [f64; 9]; + +"#, + r#" +/// Creates a `[[f64; 3]; 3]` 3D array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array_2d(&self) -> [[f64; 3]; 3]; + +"#, + r#" +/// Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. + + #[lua(kind = "Function", output(proxy))] + fn from_diagonal(#[proxy] diagonal: bevy::math::DVec3) -> bevy::math::DMat3; + +"#, + r#" +/// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column. + + #[lua(kind = "Function", output(proxy))] + fn from_mat4(#[proxy] m: bevy::math::DMat4) -> bevy::math::DMat3; + +"#, + r#" +/// Creates a 3x3 matrix from the minor of the given 4x4 matrix, discarding the `i`th column +/// and `j`th row. +/// # Panics +/// Panics if `i` or `j` is greater than 3. + + #[lua(kind = "Function", output(proxy))] + fn from_mat4_minor( + #[proxy] + m: bevy::math::DMat4, + i: usize, + j: usize, + ) -> bevy::math::DMat3; + +"#, + r#" +/// Creates a 3D rotation matrix from the given quaternion. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_quat(#[proxy] rotation: bevy::math::DQuat) -> bevy::math::DMat3; + +"#, + r#" +/// Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in +/// radians). +/// # Panics +/// Will panic if `axis` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_axis_angle( + #[proxy] + axis: bevy::math::DVec3, + angle: f64, + ) -> bevy::math::DMat3; + +"#, + r#" +/// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in +/// radians). + + #[lua(kind = "Function", output(proxy))] + fn from_euler( + #[proxy] + order: bevy::math::EulerRot, + a: f64, + b: f64, + c: f64, + ) -> bevy::math::DMat3; + +"#, + r#" +/// Extract Euler angles with the given Euler rotation order. +/// Note if the input matrix contains scales, shears, or other non-rotation transformations then +/// the resulting Euler angles will be ill-defined. +/// # Panics +/// Will panic if any input matrix column is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method")] + fn to_euler(&self, #[proxy] order: bevy::math::EulerRot) -> (f64, f64, f64); + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the x axis. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_x(angle: f64) -> bevy::math::DMat3; + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the y axis. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_y(angle: f64) -> bevy::math::DMat3; + +"#, + r#" +/// Creates a 3D rotation matrix from `angle` (in radians) around the z axis. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_z(angle: f64) -> bevy::math::DMat3; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D `translation`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_translation(#[proxy] translation: bevy::math::DVec2) -> bevy::math::DMat3; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D rotation `angle` (in +/// radians). +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_angle(angle: f64) -> bevy::math::DMat3; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in +/// radians) and `translation`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_scale_angle_translation( + #[proxy] + scale: bevy::math::DVec2, + angle: f64, + #[proxy] + translation: bevy::math::DVec2, + ) -> bevy::math::DMat3; + +"#, + r#" +/// Creates an affine transformation matrix from the given non-uniform 2D `scale`. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. +/// # Panics +/// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_scale(#[proxy] scale: bevy::math::DVec2) -> bevy::math::DMat3; + +"#, + r#" +/// Creates an affine transformation matrix from the given 2x2 matrix. +/// The resulting matrix can be used to transform 2D points and vectors. See +/// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_mat2(#[proxy] m: bevy::math::DMat2) -> bevy::math::DMat3; + +"#, + r#" +/// Returns the matrix column for the given `index`. +/// # Panics +/// Panics if `index` is greater than 2. + + #[lua(kind = "Method", output(proxy))] + fn col(&self, index: usize) -> bevy::math::DVec3; + +"#, + r#" +/// Returns the matrix row for the given `index`. +/// # Panics +/// Panics if `index` is greater than 2. + + #[lua(kind = "Method", output(proxy))] + fn row(&self, index: usize) -> bevy::math::DVec3; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(&self) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(&self) -> bool; + +"#, + r#" +/// Returns the transpose of `self`. + + #[lua(kind = "Method", output(proxy))] + fn transpose(&self) -> bevy::math::DMat3; + +"#, + r#" +/// Returns the determinant of `self`. + + #[lua(kind = "Method")] + fn determinant(&self) -> f64; + +"#, + r#" +/// Returns the inverse of `self`. +/// If the matrix is not invertible the returned matrix will be invalid. +/// # Panics +/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn inverse(&self) -> bevy::math::DMat3; + +"#, + r#" +/// Transforms the given 2D vector as a point. +/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn transform_point2(&self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Rotates the given 2D vector. +/// This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn transform_vector2(&self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Transforms a 3D vector. + + #[lua(kind = "Method", output(proxy))] + fn mul_vec3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Multiplies two 3x3 matrices. + + #[lua(kind = "Method", output(proxy))] + fn mul_mat3(&self, #[proxy] rhs: &glam::DMat3) -> bevy::math::DMat3; + +"#, + r#" +/// Adds two 3x3 matrices. + + #[lua(kind = "Method", output(proxy))] + fn add_mat3(&self, #[proxy] rhs: &glam::DMat3) -> bevy::math::DMat3; + +"#, + r#" +/// Subtracts two 3x3 matrices. + + #[lua(kind = "Method", output(proxy))] + fn sub_mat3(&self, #[proxy] rhs: &glam::DMat3) -> bevy::math::DMat3; + +"#, + r#" +/// Multiplies a 3x3 matrix by a scalar. + + #[lua(kind = "Method", output(proxy))] + fn mul_scalar(&self, rhs: f64) -> bevy::math::DMat3; + +"#, + r#" +/// Divides a 3x3 matrix by a scalar. + + #[lua(kind = "Method", output(proxy))] + fn div_scalar(&self, rhs: f64) -> bevy::math::DMat3; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two matrices contain similar elements. It works best +/// when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::DMat3, max_abs_diff: f64) -> bool; + +"#, + r#" +/// Takes the absolute value of each element in `self` + + #[lua(kind = "Method", output(proxy))] + fn abs(&self) -> bevy::math::DMat3; + +"#, + r#" + + #[lua(kind = "Method", output(proxy))] + fn as_mat3(&self) -> bevy::math::Mat3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DMat3) -> bevy::math::DMat3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f64) -> bevy::math::DMat3; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind = "MetaMethod", raw, metamethod="Index")] +fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(LuaDVec3::new_ref( + self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ + label:"col", + get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + })), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(*idx)) + } else { + Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) + } + }) + }) + ) + ) +} +"#] +)] +struct DMat3 { + #[lua(output(proxy))] + x_axis: bevy::math::DVec3, + #[lua(output(proxy))] + y_axis: bevy::math::DVec3, + #[lua(output(proxy))] + z_axis: bevy::math::DVec3, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::DMat4", + functions[r#" + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::DMat4) -> bevy::math::DMat4; + +"#, + r#" +/// Creates a 4x4 matrix from four column vectors. + + #[lua(kind = "Function", output(proxy))] + fn from_cols( + #[proxy] + x_axis: bevy::math::DVec4, + #[proxy] + y_axis: bevy::math::DVec4, + #[proxy] + z_axis: bevy::math::DVec4, + #[proxy] + w_axis: bevy::math::DVec4, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates a `[f64; 16]` array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array(&self) -> [f64; 16]; + +"#, + r#" +/// Creates a `[[f64; 4]; 4]` 4D array storing data in column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array_2d(&self) -> [[f64; 4]; 4]; + +"#, + r#" +/// Creates a 4x4 matrix with its diagonal set to `diagonal` and all other entries set to 0. + + #[lua(kind = "Function", output(proxy))] + fn from_diagonal(#[proxy] diagonal: bevy::math::DVec4) -> bevy::math::DMat4; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3D `scale`, `rotation` and +/// `translation`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_scale_rotation_translation( + #[proxy] + scale: bevy::math::DVec3, + #[proxy] + rotation: bevy::math::DQuat, + #[proxy] + translation: bevy::math::DVec3, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3D `translation`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_translation( + #[proxy] + rotation: bevy::math::DQuat, + #[proxy] + translation: bevy::math::DVec3, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates an affine transformation matrix from the given `rotation` quaternion. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `rotation` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_quat(#[proxy] rotation: bevy::math::DQuat) -> bevy::math::DMat4; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3x3 linear transformation +/// matrix. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_mat3(#[proxy] m: bevy::math::DMat3) -> bevy::math::DMat4; + +"#, + r#" +/// Creates an affine transformation matrix from the given 3D `translation`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_translation(#[proxy] translation: bevy::math::DVec3) -> bevy::math::DMat4; + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around a normalized +/// rotation `axis` of `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if `axis` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_axis_angle( + #[proxy] + axis: bevy::math::DVec3, + angle: f64, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates a affine transformation matrix containing a rotation from the given euler +/// rotation sequence and angles (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_euler( + #[proxy] + order: bevy::math::EulerRot, + a: f64, + b: f64, + c: f64, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Extract Euler angles with the given Euler rotation order. +/// Note if the upper 3x3 matrix contain scales, shears, or other non-rotation transformations +/// then the resulting Euler angles will be ill-defined. +/// # Panics +/// Will panic if any column of the upper 3x3 rotation matrix is not normalized when +/// `glam_assert` is enabled. + + #[lua(kind = "Method")] + fn to_euler(&self, #[proxy] order: bevy::math::EulerRot) -> (f64, f64, f64); + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around the x axis of +/// `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_x(angle: f64) -> bevy::math::DMat4; + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around the y axis of +/// `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_y(angle: f64) -> bevy::math::DMat4; + +"#, + r#" +/// Creates an affine transformation matrix containing a 3D rotation around the z axis of +/// `angle` (in radians). +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_z(angle: f64) -> bevy::math::DMat4; + +"#, + r#" +/// Creates an affine transformation matrix containing the given 3D non-uniform `scale`. +/// The resulting matrix can be used to transform 3D points and vectors. See +/// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. +/// # Panics +/// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_scale(#[proxy] scale: bevy::math::DVec3) -> bevy::math::DMat4; + +"#, + r#" +/// Returns the matrix column for the given `index`. +/// # Panics +/// Panics if `index` is greater than 3. + + #[lua(kind = "Method", output(proxy))] + fn col(&self, index: usize) -> bevy::math::DVec4; + +"#, + r#" +/// Returns the matrix row for the given `index`. +/// # Panics +/// Panics if `index` is greater than 3. + + #[lua(kind = "Method", output(proxy))] + fn row(&self, index: usize) -> bevy::math::DVec4; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(&self) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(&self) -> bool; + +"#, + r#" +/// Returns the transpose of `self`. + + #[lua(kind = "Method", output(proxy))] + fn transpose(&self) -> bevy::math::DMat4; + +"#, + r#" +/// Returns the determinant of `self`. + + #[lua(kind = "Method")] + fn determinant(&self) -> f64; + +"#, + r#" +/// Returns the inverse of `self`. +/// If the matrix is not invertible the returned matrix will be invalid. +/// # Panics +/// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn inverse(&self) -> bevy::math::DMat4; + +"#, + r#" +/// Creates a left-handed view matrix using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + + #[lua(kind = "Function", output(proxy))] + fn look_to_lh( + #[proxy] + eye: bevy::math::DVec3, + #[proxy] + dir: bevy::math::DVec3, + #[proxy] + up: bevy::math::DVec3, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates a right-handed view matrix using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + + #[lua(kind = "Function", output(proxy))] + fn look_to_rh( + #[proxy] + eye: bevy::math::DVec3, + #[proxy] + dir: bevy::math::DVec3, + #[proxy] + up: bevy::math::DVec3, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates a left-handed view matrix using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn look_at_lh( + #[proxy] + eye: bevy::math::DVec3, + #[proxy] + center: bevy::math::DVec3, + #[proxy] + up: bevy::math::DVec3, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates a right-handed view matrix using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn look_at_rh( + #[proxy] + eye: bevy::math::DVec3, + #[proxy] + center: bevy::math::DVec3, + #[proxy] + up: bevy::math::DVec3, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates a right-handed perspective projection matrix with `[-1,1]` depth range. +/// Useful to map the standard right-handed coordinate system into what OpenGL expects. +/// This is the same as the OpenGL `gluPerspective` function. +/// See + + #[lua(kind = "Function", output(proxy))] + fn perspective_rh_gl( + fov_y_radians: f64, + aspect_ratio: f64, + z_near: f64, + z_far: f64, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates a left-handed perspective projection matrix with `[0,1]` depth range. +/// Useful to map the standard left-handed coordinate system into what WebGPU/Metal/Direct3D expect. +/// # Panics +/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is +/// enabled. + + #[lua(kind = "Function", output(proxy))] + fn perspective_lh( + fov_y_radians: f64, + aspect_ratio: f64, + z_near: f64, + z_far: f64, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates a right-handed perspective projection matrix with `[0,1]` depth range. +/// Useful to map the standard right-handed coordinate system into what WebGPU/Metal/Direct3D expect. +/// # Panics +/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is +/// enabled. + + #[lua(kind = "Function", output(proxy))] + fn perspective_rh( + fov_y_radians: f64, + aspect_ratio: f64, + z_near: f64, + z_far: f64, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. +/// Like `perspective_lh`, but with an infinite value for `z_far`. +/// The result is that points near `z_near` are mapped to depth `0`, and as they move towards infinity the depth approaches `1`. +/// # Panics +/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is +/// enabled. + + #[lua(kind = "Function", output(proxy))] + fn perspective_infinite_lh( + fov_y_radians: f64, + aspect_ratio: f64, + z_near: f64, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates an infinite reverse left-handed perspective projection matrix with `[0,1]` depth range. +/// Similar to `perspective_infinite_lh`, but maps `Z = z_near` to a depth of `1` and `Z = infinity` to a depth of `0`. +/// # Panics +/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn perspective_infinite_reverse_lh( + fov_y_radians: f64, + aspect_ratio: f64, + z_near: f64, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates an infinite right-handed perspective projection matrix with `[0,1]` depth range. +/// Like `perspective_rh`, but with an infinite value for `z_far`. +/// The result is that points near `z_near` are mapped to depth `0`, and as they move towards infinity the depth approaches `1`. +/// # Panics +/// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is +/// enabled. + + #[lua(kind = "Function", output(proxy))] + fn perspective_infinite_rh( + fov_y_radians: f64, + aspect_ratio: f64, + z_near: f64, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates an infinite reverse right-handed perspective projection matrix with `[0,1]` depth range. +/// Similar to `perspective_infinite_rh`, but maps `Z = z_near` to a depth of `1` and `Z = infinity` to a depth of `0`. +/// # Panics +/// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn perspective_infinite_reverse_rh( + fov_y_radians: f64, + aspect_ratio: f64, + z_near: f64, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates a right-handed orthographic projection matrix with `[-1,1]` depth +/// range. This is the same as the OpenGL `glOrtho` function in OpenGL. +/// See +/// +/// Useful to map a right-handed coordinate system to the normalized device coordinates that OpenGL expects. + + #[lua(kind = "Function", output(proxy))] + fn orthographic_rh_gl( + left: f64, + right: f64, + bottom: f64, + top: f64, + near: f64, + far: f64, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates a left-handed orthographic projection matrix with `[0,1]` depth range. +/// Useful to map a left-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect. + + #[lua(kind = "Function", output(proxy))] + fn orthographic_lh( + left: f64, + right: f64, + bottom: f64, + top: f64, + near: f64, + far: f64, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Creates a right-handed orthographic projection matrix with `[0,1]` depth range. +/// Useful to map a right-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect. + + #[lua(kind = "Function", output(proxy))] + fn orthographic_rh( + left: f64, + right: f64, + bottom: f64, + top: f64, + near: f64, + far: f64, + ) -> bevy::math::DMat4; + +"#, + r#" +/// Transforms the given 3D vector as a point, applying perspective correction. +/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is `1.0`. +/// The perspective divide is performed meaning the resulting 3D vector is divided by `w`. +/// This method assumes that `self` contains a projective transform. + + #[lua(kind = "Method", output(proxy))] + fn project_point3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Transforms the given 3D vector as a point. +/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is +/// `1.0`. +/// This method assumes that `self` contains a valid affine transform. It does not perform +/// a perspective divide, if `self` contains a perspective transform, or if you are unsure, +/// the [`Self::project_point3()`] method should be used instead. +/// # Panics +/// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn transform_point3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Transforms the give 3D vector as a direction. +/// This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is +/// `0.0`. +/// This method assumes that `self` contains a valid affine transform. +/// # Panics +/// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn transform_vector3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Transforms a 4D vector. + + #[lua(kind = "Method", output(proxy))] + fn mul_vec4(&self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" +/// Multiplies two 4x4 matrices. + + #[lua(kind = "Method", output(proxy))] + fn mul_mat4(&self, #[proxy] rhs: &glam::DMat4) -> bevy::math::DMat4; + +"#, + r#" +/// Adds two 4x4 matrices. + + #[lua(kind = "Method", output(proxy))] + fn add_mat4(&self, #[proxy] rhs: &glam::DMat4) -> bevy::math::DMat4; + +"#, + r#" +/// Subtracts two 4x4 matrices. + + #[lua(kind = "Method", output(proxy))] + fn sub_mat4(&self, #[proxy] rhs: &glam::DMat4) -> bevy::math::DMat4; + +"#, + r#" +/// Multiplies a 4x4 matrix by a scalar. + + #[lua(kind = "Method", output(proxy))] + fn mul_scalar(&self, rhs: f64) -> bevy::math::DMat4; + +"#, + r#" +/// Divides a 4x4 matrix by a scalar. + + #[lua(kind = "Method", output(proxy))] + fn div_scalar(&self, rhs: f64) -> bevy::math::DMat4; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two matrices contain similar elements. It works best +/// when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::DMat4, max_abs_diff: f64) -> bool; + +"#, + r#" +/// Takes the absolute value of each element in `self` + + #[lua(kind = "Method", output(proxy))] + fn abs(&self) -> bevy::math::DMat4; + +"#, + r#" + + #[lua(kind = "Method", output(proxy))] + fn as_mat4(&self) -> bevy::math::Mat4; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::DMat4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::DMat4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::DMat4) -> bevy::math::DMat4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DAffine3) -> bevy::math::DMat4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DMat4) -> bevy::math::DMat4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f64) -> bevy::math::DMat4; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::DMat4) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f64) -> bevy::math::DMat4; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(kind = "MetaMethod", raw, metamethod="Index")] +fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { + Ok(LuaDVec4::new_ref( + self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ + label:"col", + get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + })), + get_mut: std::sync::Arc::new(move |ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(*idx)) + } else { + Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) + } + }) + }) + ) + ) +} +"#] +)] +struct DMat4 { + #[lua(output(proxy))] + x_axis: bevy::math::DVec4, + #[lua(output(proxy))] + y_axis: bevy::math::DVec4, + #[lua(output(proxy))] + z_axis: bevy::math::DVec4, + #[lua(output(proxy))] + w_axis: bevy::math::DVec4, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Affine2", + functions[r#" +/// Creates an affine transform from three column vectors. + + #[lua(kind = "Function", output(proxy))] + fn from_cols( + #[proxy] + x_axis: bevy::math::Vec2, + #[proxy] + y_axis: bevy::math::Vec2, + #[proxy] + z_axis: bevy::math::Vec2, + ) -> bevy::math::Affine2; + +"#, + r#" +/// Creates a `[f32; 6]` array storing data in column major order. + + #[lua(kind = "Method")] + fn to_cols_array(&self) -> [f32; 6]; + +"#, + r#" +/// Creates a `[[f32; 2]; 3]` 2D array storing data in +/// column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array_2d(&self) -> [[f32; 2]; 3]; + +"#, + r#" +/// Creates an affine transform that changes scale. +/// Note that if any scale is zero the transform will be non-invertible. + + #[lua(kind = "Function", output(proxy))] + fn from_scale(#[proxy] scale: bevy::math::Vec2) -> bevy::math::Affine2; + +"#, + r#" +/// Creates an affine transform from the given rotation `angle`. + + #[lua(kind = "Function", output(proxy))] + fn from_angle(angle: f32) -> bevy::math::Affine2; + +"#, + r#" +/// Creates an affine transformation from the given 2D `translation`. + + #[lua(kind = "Function", output(proxy))] + fn from_translation(#[proxy] translation: bevy::math::Vec2) -> bevy::math::Affine2; + +"#, + r#" +/// Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) + + #[lua(kind = "Function", output(proxy))] + fn from_mat2(#[proxy] matrix2: bevy::math::Mat2) -> bevy::math::Affine2; + +"#, + r#" +/// Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) and a +/// translation vector. +/// Equivalent to +/// `Affine2::from_translation(translation) * Affine2::from_mat2(mat2)` + + #[lua(kind = "Function", output(proxy))] + fn from_mat2_translation( + #[proxy] + matrix2: bevy::math::Mat2, + #[proxy] + translation: bevy::math::Vec2, + ) -> bevy::math::Affine2; + +"#, + r#" +/// Creates an affine transform from the given 2D `scale`, rotation `angle` (in radians) and +/// `translation`. +/// Equivalent to `Affine2::from_translation(translation) * +/// Affine2::from_angle(angle) * Affine2::from_scale(scale)` + + #[lua(kind = "Function", output(proxy))] + fn from_scale_angle_translation( + #[proxy] + scale: bevy::math::Vec2, + angle: f32, + #[proxy] + translation: bevy::math::Vec2, + ) -> bevy::math::Affine2; + +"#, + r#" +/// Creates an affine transform from the given 2D rotation `angle` (in radians) and +/// `translation`. +/// Equivalent to `Affine2::from_translation(translation) * Affine2::from_angle(angle)` + + #[lua(kind = "Function", output(proxy))] + fn from_angle_translation( + angle: f32, + #[proxy] + translation: bevy::math::Vec2, + ) -> bevy::math::Affine2; + +"#, + r#" +/// The given `Mat3` must be an affine transform, + + #[lua(kind = "Function", output(proxy))] + fn from_mat3(#[proxy] m: bevy::math::Mat3) -> bevy::math::Affine2; + +"#, + r#" +/// The given [`Mat3A`] must be an affine transform, + + #[lua(kind = "Function", output(proxy))] + fn from_mat3a(#[proxy] m: bevy::math::Mat3A) -> bevy::math::Affine2; + +"#, + r#" +/// Transforms the given 2D point, applying shear, scale, rotation and translation. + + #[lua(kind = "Method", output(proxy))] + fn transform_point2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Transforms the given 2D vector, applying shear, scale and rotation (but NOT +/// translation). +/// To also apply translation, use [`Self::transform_point2()`] instead. + + #[lua(kind = "Method", output(proxy))] + fn transform_vector2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return +/// `false`. + + #[lua(kind = "Method")] + fn is_finite(&self) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(&self) -> bool; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two 3x4 matrices contain similar elements. It works +/// best when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Affine2, max_abs_diff: f32) -> bool; + +"#, + r#" +/// Return the inverse of this transform. +/// Note that if the transform is not invertible the result will be invalid. + + #[lua(kind = "Method", output(proxy))] + fn inverse(&self) -> bevy::math::Affine2; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Affine2) -> bevy::math::Affine2; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::Affine2) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Mat3) -> bevy::math::Mat3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Mat3A) -> bevy::math::Mat3A; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::Affine2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Affine2 { + #[lua(output(proxy))] + matrix2: bevy::math::Mat2, + #[lua(output(proxy))] + translation: bevy::math::Vec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::Affine3A", + functions[r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Affine3A) -> bevy::math::Affine3A; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::Affine3A; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::Mat4) -> bevy::math::Mat4; + +"#, + r#" +/// Creates an affine transform from three column vectors. + + #[lua(kind = "Function", output(proxy))] + fn from_cols( + #[proxy] + x_axis: bevy::math::Vec3A, + #[proxy] + y_axis: bevy::math::Vec3A, + #[proxy] + z_axis: bevy::math::Vec3A, + #[proxy] + w_axis: bevy::math::Vec3A, + ) -> bevy::math::Affine3A; + +"#, + r#" +/// Creates a `[f32; 12]` array storing data in column major order. + + #[lua(kind = "Method")] + fn to_cols_array(&self) -> [f32; 12]; + +"#, + r#" +/// Creates a `[[f32; 3]; 4]` 3D array storing data in +/// column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array_2d(&self) -> [[f32; 3]; 4]; + +"#, + r#" +/// Creates an affine transform that changes scale. +/// Note that if any scale is zero the transform will be non-invertible. + + #[lua(kind = "Function", output(proxy))] + fn from_scale(#[proxy] scale: bevy::math::Vec3) -> bevy::math::Affine3A; + +"#, + r#" +/// Creates an affine transform from the given `rotation` quaternion. + + #[lua(kind = "Function", output(proxy))] + fn from_quat(#[proxy] rotation: bevy::math::Quat) -> bevy::math::Affine3A; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around a normalized +/// rotation `axis` of `angle` (in radians). + + #[lua(kind = "Function", output(proxy))] + fn from_axis_angle( + #[proxy] + axis: bevy::math::Vec3, + angle: f32, + ) -> bevy::math::Affine3A; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around the x axis of +/// `angle` (in radians). + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_x(angle: f32) -> bevy::math::Affine3A; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around the y axis of +/// `angle` (in radians). + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_y(angle: f32) -> bevy::math::Affine3A; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around the z axis of +/// `angle` (in radians). + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_z(angle: f32) -> bevy::math::Affine3A; + +"#, + r#" +/// Creates an affine transformation from the given 3D `translation`. + + #[lua(kind = "Function", output(proxy))] + fn from_translation(#[proxy] translation: bevy::math::Vec3) -> bevy::math::Affine3A; + +"#, + r#" +/// Creates an affine transform from a 3x3 matrix (expressing scale, shear and +/// rotation) + + #[lua(kind = "Function", output(proxy))] + fn from_mat3(#[proxy] mat3: bevy::math::Mat3) -> bevy::math::Affine3A; + +"#, + r#" +/// Creates an affine transform from a 3x3 matrix (expressing scale, shear and rotation) +/// and a translation vector. +/// Equivalent to `Affine3A::from_translation(translation) * Affine3A::from_mat3(mat3)` + + #[lua(kind = "Function", output(proxy))] + fn from_mat3_translation( + #[proxy] + mat3: bevy::math::Mat3, + #[proxy] + translation: bevy::math::Vec3, + ) -> bevy::math::Affine3A; + +"#, + r#" +/// Creates an affine transform from the given 3D `scale`, `rotation` and +/// `translation`. +/// Equivalent to `Affine3A::from_translation(translation) * +/// Affine3A::from_quat(rotation) * Affine3A::from_scale(scale)` + + #[lua(kind = "Function", output(proxy))] + fn from_scale_rotation_translation( + #[proxy] + scale: bevy::math::Vec3, + #[proxy] + rotation: bevy::math::Quat, + #[proxy] + translation: bevy::math::Vec3, + ) -> bevy::math::Affine3A; + +"#, + r#" +/// Creates an affine transform from the given 3D `rotation` and `translation`. +/// Equivalent to `Affine3A::from_translation(translation) * Affine3A::from_quat(rotation)` + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_translation( + #[proxy] + rotation: bevy::math::Quat, + #[proxy] + translation: bevy::math::Vec3, + ) -> bevy::math::Affine3A; + +"#, + r#" +/// The given `Mat4` must be an affine transform, +/// i.e. contain no perspective transform. + + #[lua(kind = "Function", output(proxy))] + fn from_mat4(#[proxy] m: bevy::math::Mat4) -> bevy::math::Affine3A; + +"#, + r#" +/// Creates a left-handed view transform using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + + #[lua(kind = "Function", output(proxy))] + fn look_to_lh( + #[proxy] + eye: bevy::math::Vec3, + #[proxy] + dir: bevy::math::Vec3, + #[proxy] + up: bevy::math::Vec3, + ) -> bevy::math::Affine3A; + +"#, + r#" +/// Creates a right-handed view transform using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + + #[lua(kind = "Function", output(proxy))] + fn look_to_rh( + #[proxy] + eye: bevy::math::Vec3, + #[proxy] + dir: bevy::math::Vec3, + #[proxy] + up: bevy::math::Vec3, + ) -> bevy::math::Affine3A; + +"#, + r#" +/// Creates a left-handed view transform using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn look_at_lh( + #[proxy] + eye: bevy::math::Vec3, + #[proxy] + center: bevy::math::Vec3, + #[proxy] + up: bevy::math::Vec3, + ) -> bevy::math::Affine3A; + +"#, + r#" +/// Creates a right-handed view transform using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn look_at_rh( + #[proxy] + eye: bevy::math::Vec3, + #[proxy] + center: bevy::math::Vec3, + #[proxy] + up: bevy::math::Vec3, + ) -> bevy::math::Affine3A; + +"#, + r#" +/// Transforms the given 3D points, applying shear, scale, rotation and translation. + + #[lua(kind = "Method", output(proxy))] + fn transform_point3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Transforms the given 3D vector, applying shear, scale and rotation (but NOT +/// translation). +/// To also apply translation, use [`Self::transform_point3()`] instead. + + #[lua(kind = "Method", output(proxy))] + fn transform_vector3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Transforms the given [`Vec3A`], applying shear, scale, rotation and translation. + + #[lua(kind = "Method", output(proxy))] + fn transform_point3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Transforms the given [`Vec3A`], applying shear, scale and rotation (but NOT +/// translation). +/// To also apply translation, use [`Self::transform_point3a()`] instead. + + #[lua(kind = "Method", output(proxy))] + fn transform_vector3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return +/// `false`. + + #[lua(kind = "Method")] + fn is_finite(&self) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(&self) -> bool; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two 3x4 matrices contain similar elements. It works +/// best when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Affine3A, max_abs_diff: f32) -> bool; + +"#, + r#" +/// Return the inverse of this transform. +/// Note that if the transform is not invertible the result will be invalid. + + #[lua(kind = "Method", output(proxy))] + fn inverse(&self) -> bevy::math::Affine3A; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::Affine3A) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Affine3A { + #[lua(output(proxy))] + matrix3: bevy::math::Mat3A, + #[lua(output(proxy))] + translation: bevy::math::Vec3A, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::DAffine2", + functions[r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DMat3) -> bevy::math::DMat3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DAffine2) -> bevy::math::DAffine2; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::DAffine2) -> bool; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::DAffine2; + +"#, + r#" +/// Creates an affine transform from three column vectors. + + #[lua(kind = "Function", output(proxy))] + fn from_cols( + #[proxy] + x_axis: bevy::math::DVec2, + #[proxy] + y_axis: bevy::math::DVec2, + #[proxy] + z_axis: bevy::math::DVec2, + ) -> bevy::math::DAffine2; + +"#, + r#" +/// Creates a `[f64; 6]` array storing data in column major order. + + #[lua(kind = "Method")] + fn to_cols_array(&self) -> [f64; 6]; + +"#, + r#" +/// Creates a `[[f64; 2]; 3]` 2D array storing data in +/// column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array_2d(&self) -> [[f64; 2]; 3]; + +"#, + r#" +/// Creates an affine transform that changes scale. +/// Note that if any scale is zero the transform will be non-invertible. + + #[lua(kind = "Function", output(proxy))] + fn from_scale(#[proxy] scale: bevy::math::DVec2) -> bevy::math::DAffine2; + +"#, + r#" +/// Creates an affine transform from the given rotation `angle`. + + #[lua(kind = "Function", output(proxy))] + fn from_angle(angle: f64) -> bevy::math::DAffine2; + +"#, + r#" +/// Creates an affine transformation from the given 2D `translation`. + + #[lua(kind = "Function", output(proxy))] + fn from_translation(#[proxy] translation: bevy::math::DVec2) -> bevy::math::DAffine2; + +"#, + r#" +/// Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) + + #[lua(kind = "Function", output(proxy))] + fn from_mat2(#[proxy] matrix2: bevy::math::DMat2) -> bevy::math::DAffine2; + +"#, + r#" +/// Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) and a +/// translation vector. +/// Equivalent to +/// `DAffine2::from_translation(translation) * DAffine2::from_mat2(mat2)` + + #[lua(kind = "Function", output(proxy))] + fn from_mat2_translation( + #[proxy] + matrix2: bevy::math::DMat2, + #[proxy] + translation: bevy::math::DVec2, + ) -> bevy::math::DAffine2; + +"#, + r#" +/// Creates an affine transform from the given 2D `scale`, rotation `angle` (in radians) and +/// `translation`. +/// Equivalent to `DAffine2::from_translation(translation) * +/// DAffine2::from_angle(angle) * DAffine2::from_scale(scale)` + + #[lua(kind = "Function", output(proxy))] + fn from_scale_angle_translation( + #[proxy] + scale: bevy::math::DVec2, + angle: f64, + #[proxy] + translation: bevy::math::DVec2, + ) -> bevy::math::DAffine2; + +"#, + r#" +/// Creates an affine transform from the given 2D rotation `angle` (in radians) and +/// `translation`. +/// Equivalent to `DAffine2::from_translation(translation) * DAffine2::from_angle(angle)` + + #[lua(kind = "Function", output(proxy))] + fn from_angle_translation( + angle: f64, + #[proxy] + translation: bevy::math::DVec2, + ) -> bevy::math::DAffine2; + +"#, + r#" +/// The given `DMat3` must be an affine transform, + + #[lua(kind = "Function", output(proxy))] + fn from_mat3(#[proxy] m: bevy::math::DMat3) -> bevy::math::DAffine2; + +"#, + r#" +/// Transforms the given 2D point, applying shear, scale, rotation and translation. + + #[lua(kind = "Method", output(proxy))] + fn transform_point2(&self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Transforms the given 2D vector, applying shear, scale and rotation (but NOT +/// translation). +/// To also apply translation, use [`Self::transform_point2()`] instead. + + #[lua(kind = "Method", output(proxy))] + fn transform_vector2(&self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return +/// `false`. + + #[lua(kind = "Method")] + fn is_finite(&self) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(&self) -> bool; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two 3x4 matrices contain similar elements. It works +/// best when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::DAffine2, max_abs_diff: f64) -> bool; + +"#, + r#" +/// Return the inverse of this transform. +/// Note that if the transform is not invertible the result will be invalid. + + #[lua(kind = "Method", output(proxy))] + fn inverse(&self) -> bevy::math::DAffine2; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct DAffine2 { + #[lua(output(proxy))] + matrix2: bevy::math::DMat2, + #[lua(output(proxy))] + translation: bevy::math::DVec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::DAffine3", + functions[r#" +/// Creates an affine transform from three column vectors. + + #[lua(kind = "Function", output(proxy))] + fn from_cols( + #[proxy] + x_axis: bevy::math::DVec3, + #[proxy] + y_axis: bevy::math::DVec3, + #[proxy] + z_axis: bevy::math::DVec3, + #[proxy] + w_axis: bevy::math::DVec3, + ) -> bevy::math::DAffine3; + +"#, + r#" +/// Creates a `[f64; 12]` array storing data in column major order. + + #[lua(kind = "Method")] + fn to_cols_array(&self) -> [f64; 12]; + +"#, + r#" +/// Creates a `[[f64; 3]; 4]` 3D array storing data in +/// column major order. +/// If you require data in row major order `transpose` the matrix first. + + #[lua(kind = "Method")] + fn to_cols_array_2d(&self) -> [[f64; 3]; 4]; + +"#, + r#" +/// Creates an affine transform that changes scale. +/// Note that if any scale is zero the transform will be non-invertible. + + #[lua(kind = "Function", output(proxy))] + fn from_scale(#[proxy] scale: bevy::math::DVec3) -> bevy::math::DAffine3; + +"#, + r#" +/// Creates an affine transform from the given `rotation` quaternion. + + #[lua(kind = "Function", output(proxy))] + fn from_quat(#[proxy] rotation: bevy::math::DQuat) -> bevy::math::DAffine3; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around a normalized +/// rotation `axis` of `angle` (in radians). + + #[lua(kind = "Function", output(proxy))] + fn from_axis_angle( + #[proxy] + axis: bevy::math::DVec3, + angle: f64, + ) -> bevy::math::DAffine3; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around the x axis of +/// `angle` (in radians). + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_x(angle: f64) -> bevy::math::DAffine3; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around the y axis of +/// `angle` (in radians). + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_y(angle: f64) -> bevy::math::DAffine3; + +"#, + r#" +/// Creates an affine transform containing a 3D rotation around the z axis of +/// `angle` (in radians). + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_z(angle: f64) -> bevy::math::DAffine3; + +"#, + r#" +/// Creates an affine transformation from the given 3D `translation`. + + #[lua(kind = "Function", output(proxy))] + fn from_translation(#[proxy] translation: bevy::math::DVec3) -> bevy::math::DAffine3; + +"#, + r#" +/// Creates an affine transform from a 3x3 matrix (expressing scale, shear and +/// rotation) + + #[lua(kind = "Function", output(proxy))] + fn from_mat3(#[proxy] mat3: bevy::math::DMat3) -> bevy::math::DAffine3; + +"#, + r#" +/// Creates an affine transform from a 3x3 matrix (expressing scale, shear and rotation) +/// and a translation vector. +/// Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_mat3(mat3)` + + #[lua(kind = "Function", output(proxy))] + fn from_mat3_translation( + #[proxy] + mat3: bevy::math::DMat3, + #[proxy] + translation: bevy::math::DVec3, + ) -> bevy::math::DAffine3; + +"#, + r#" +/// Creates an affine transform from the given 3D `scale`, `rotation` and +/// `translation`. +/// Equivalent to `DAffine3::from_translation(translation) * +/// DAffine3::from_quat(rotation) * DAffine3::from_scale(scale)` + + #[lua(kind = "Function", output(proxy))] + fn from_scale_rotation_translation( + #[proxy] + scale: bevy::math::DVec3, + #[proxy] + rotation: bevy::math::DQuat, + #[proxy] + translation: bevy::math::DVec3, + ) -> bevy::math::DAffine3; + +"#, + r#" +/// Creates an affine transform from the given 3D `rotation` and `translation`. +/// Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_quat(rotation)` + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_translation( + #[proxy] + rotation: bevy::math::DQuat, + #[proxy] + translation: bevy::math::DVec3, + ) -> bevy::math::DAffine3; + +"#, + r#" +/// The given `DMat4` must be an affine transform, +/// i.e. contain no perspective transform. + + #[lua(kind = "Function", output(proxy))] + fn from_mat4(#[proxy] m: bevy::math::DMat4) -> bevy::math::DAffine3; + +"#, + r#" +/// Creates a left-handed view transform using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + + #[lua(kind = "Function", output(proxy))] + fn look_to_lh( + #[proxy] + eye: bevy::math::DVec3, + #[proxy] + dir: bevy::math::DVec3, + #[proxy] + up: bevy::math::DVec3, + ) -> bevy::math::DAffine3; + +"#, + r#" +/// Creates a right-handed view transform using a camera position, an up direction, and a facing +/// direction. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + + #[lua(kind = "Function", output(proxy))] + fn look_to_rh( + #[proxy] + eye: bevy::math::DVec3, + #[proxy] + dir: bevy::math::DVec3, + #[proxy] + up: bevy::math::DVec3, + ) -> bevy::math::DAffine3; + +"#, + r#" +/// Creates a left-handed view transform using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn look_at_lh( + #[proxy] + eye: bevy::math::DVec3, + #[proxy] + center: bevy::math::DVec3, + #[proxy] + up: bevy::math::DVec3, + ) -> bevy::math::DAffine3; + +"#, + r#" +/// Creates a right-handed view transform using a camera position, an up direction, and a focal +/// point. +/// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. +/// # Panics +/// Will panic if `up` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn look_at_rh( + #[proxy] + eye: bevy::math::DVec3, + #[proxy] + center: bevy::math::DVec3, + #[proxy] + up: bevy::math::DVec3, + ) -> bevy::math::DAffine3; + +"#, + r#" +/// Transforms the given 3D points, applying shear, scale, rotation and translation. + + #[lua(kind = "Method", output(proxy))] + fn transform_point3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Transforms the given 3D vector, applying shear, scale and rotation (but NOT +/// translation). +/// To also apply translation, use [`Self::transform_point3()`] instead. + + #[lua(kind = "Method", output(proxy))] + fn transform_vector3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return +/// `false`. + + #[lua(kind = "Method")] + fn is_finite(&self) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NaN`. + + #[lua(kind = "Method")] + fn is_nan(&self) -> bool; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two 3x4 matrices contain similar elements. It works +/// best when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::DAffine3, max_abs_diff: f64) -> bool; + +"#, + r#" +/// Return the inverse of this transform. +/// Note that if the transform is not invertible the result will be invalid. + + #[lua(kind = "Method", output(proxy))] + fn inverse(&self) -> bevy::math::DAffine3; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::DAffine3) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DAffine3) -> bevy::math::DAffine3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DMat4) -> bevy::math::DMat4; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::DAffine3; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct DAffine3 { + #[lua(output(proxy))] + matrix3: bevy::math::DMat3, + #[lua(output(proxy))] + translation: bevy::math::DVec3, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::DQuat", + functions[r#" +/// Subtracts the `rhs` quaternion from `self`. +/// The difference is not guaranteed to be normalized. + + #[lua( + as_trait = "std::ops::Sub", + kind = "MetaFunction", + output(proxy), + composite = "sub", + metamethod = "Sub", + )] + fn sub(self, #[proxy] rhs: bevy::math::DQuat) -> bevy::math::DQuat; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Neg", + kind = "MetaFunction", + output(proxy), + composite = "neg", + metamethod = "Unm", + )] + fn neg(self) -> bevy::math::DQuat; + +"#, + r#" +/// Multiplies a quaternion by a scalar value. +/// The product is not guaranteed to be normalized. + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, rhs: f64) -> bevy::math::DQuat; + +"#, + r#" +/// Adds two quaternions. +/// The sum is not guaranteed to be normalized. +/// Note that addition is not the same as combining the rotations represented by the +/// two quaternions! That corresponds to multiplication. + + #[lua( + as_trait = "std::ops::Add", + kind = "MetaFunction", + output(proxy), + composite = "add", + metamethod = "Add", + )] + fn add(self, #[proxy] rhs: bevy::math::DQuat) -> bevy::math::DQuat; + +"#, + r#" +/// Multiplies a quaternion and a 3D vector, returning the rotated vector. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::DQuat; + +"#, + r#" +/// Divides a quaternion by a scalar value. +/// The quotient is not guaranteed to be normalized. + + #[lua( + as_trait = "std::ops::Div", + kind = "MetaFunction", + output(proxy), + composite = "div", + metamethod = "Div", + )] + fn div(self, rhs: f64) -> bevy::math::DQuat; + +"#, + r#" +/// Multiplies two quaternions. If they each represent a rotation, the result will +/// represent the combined rotation. +/// Note that due to floating point rounding the result may not be perfectly +/// normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] rhs: bevy::math::DQuat) -> bevy::math::DQuat; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::DQuat) -> bool; + +"#, + r#" +/// Creates a new rotation quaternion. +/// This should generally not be called manually unless you know what you are doing. +/// Use one of the other constructors instead such as `identity` or `from_axis_angle`. +/// `from_xyzw` is mostly used by unit tests and `serde` deserialization. +/// # Preconditions +/// This function does not check if the input is normalized, it is up to the user to +/// provide normalized input or to normalized the resulting quaternion. + + #[lua(kind = "Function", output(proxy))] + fn from_xyzw(x: f64, y: f64, z: f64, w: f64) -> bevy::math::DQuat; + +"#, + r#" +/// Creates a rotation quaternion from an array. +/// # Preconditions +/// This function does not check if the input is normalized, it is up to the user to +/// provide normalized input or to normalized the resulting quaternion. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [f64; 4]) -> bevy::math::DQuat; + +"#, + r#" +/// Creates a new rotation quaternion from a 4D vector. +/// # Preconditions +/// This function does not check if the input is normalized, it is up to the user to +/// provide normalized input or to normalized the resulting quaternion. + + #[lua(kind = "Function", output(proxy))] + fn from_vec4(#[proxy] v: bevy::math::DVec4) -> bevy::math::DQuat; + +"#, + r#" +/// Create a quaternion for a normalized rotation `axis` and `angle` (in radians). +/// The axis must be a unit vector. +/// # Panics +/// Will panic if `axis` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_axis_angle( + #[proxy] + axis: bevy::math::DVec3, + angle: f64, + ) -> bevy::math::DQuat; + +"#, + r#" +/// Create a quaternion that rotates `v.length()` radians around `v.normalize()`. +/// `from_scaled_axis(Vec3::ZERO)` results in the identity quaternion. + + #[lua(kind = "Function", output(proxy))] + fn from_scaled_axis(#[proxy] v: bevy::math::DVec3) -> bevy::math::DQuat; + +"#, + r#" +/// Creates a quaternion from the `angle` (in radians) around the x axis. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_x(angle: f64) -> bevy::math::DQuat; + +"#, + r#" +/// Creates a quaternion from the `angle` (in radians) around the y axis. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_y(angle: f64) -> bevy::math::DQuat; + +"#, + r#" +/// Creates a quaternion from the `angle` (in radians) around the z axis. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_z(angle: f64) -> bevy::math::DQuat; + +"#, + r#" +/// Creates a quaternion from the given Euler rotation sequence and the angles (in radians). + + #[lua(kind = "Function", output(proxy))] + fn from_euler( + #[proxy] + euler: bevy::math::EulerRot, + a: f64, + b: f64, + c: f64, + ) -> bevy::math::DQuat; + +"#, + r#" +/// Creates a quaternion from a 3x3 rotation matrix. +/// Note if the input matrix contain scales, shears, or other non-rotation transformations then +/// the resulting quaternion will be ill-defined. +/// # Panics +/// Will panic if any input matrix column is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_mat3(#[proxy] mat: &glam::DMat3) -> bevy::math::DQuat; + +"#, + r#" +/// Creates a quaternion from the upper 3x3 rotation matrix inside a homogeneous 4x4 matrix. +/// Note if the upper 3x3 matrix contain scales, shears, or other non-rotation transformations +/// then the resulting quaternion will be ill-defined. +/// # Panics +/// Will panic if any column of the upper 3x3 rotation matrix is not normalized when +/// `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_mat4(#[proxy] mat: &glam::DMat4) -> bevy::math::DQuat; + +"#, + r#" +/// Gets the minimal rotation for transforming `from` to `to`. The rotation is in the +/// plane spanned by the two vectors. Will rotate at most 180 degrees. +/// The inputs must be unit vectors. +/// `from_rotation_arc(from, to) * from ≈ to`. +/// For near-singular cases (from≈to and from≈-to) the current implementation +/// is only accurate to about 0.001 (for `f32`). +/// # Panics +/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_arc( + #[proxy] + from: bevy::math::DVec3, + #[proxy] + to: bevy::math::DVec3, + ) -> bevy::math::DQuat; + +"#, + r#" +/// Gets the minimal rotation for transforming `from` to either `to` or `-to`. This means +/// that the resulting quaternion will rotate `from` so that it is colinear with `to`. +/// The rotation is in the plane spanned by the two vectors. Will rotate at most 90 +/// degrees. +/// The inputs must be unit vectors. +/// `to.dot(from_rotation_arc_colinear(from, to) * from).abs() ≈ 1`. +/// # Panics +/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_arc_colinear( + #[proxy] + from: bevy::math::DVec3, + #[proxy] + to: bevy::math::DVec3, + ) -> bevy::math::DQuat; + +"#, + r#" +/// Gets the minimal rotation for transforming `from` to `to`. The resulting rotation is +/// around the z axis. Will rotate at most 180 degrees. +/// The inputs must be unit vectors. +/// `from_rotation_arc_2d(from, to) * from ≈ to`. +/// For near-singular cases (from≈to and from≈-to) the current implementation +/// is only accurate to about 0.001 (for `f32`). +/// # Panics +/// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation_arc_2d( + #[proxy] + from: bevy::math::DVec2, + #[proxy] + to: bevy::math::DVec2, + ) -> bevy::math::DQuat; + +"#, + r#" +/// Returns the rotation axis scaled by the rotation in radians. + + #[lua(kind = "Method", output(proxy))] + fn to_scaled_axis(self) -> bevy::math::DVec3; + +"#, + r#" +/// Returns the rotation angles for the given euler rotation sequence. + + #[lua(kind = "Method")] + fn to_euler(self, #[proxy] order: bevy::math::EulerRot) -> (f64, f64, f64); + +"#, + r#" +/// `[x, y, z, w]` + + #[lua(kind = "Method")] + fn to_array(&self) -> [f64; 4]; + +"#, + r#" +/// Returns the vector part of the quaternion. + + #[lua(kind = "Method", output(proxy))] + fn xyz(self) -> bevy::math::DVec3; + +"#, + r#" +/// Returns the quaternion conjugate of `self`. For a unit quaternion the +/// conjugate is also the inverse. + + #[lua(kind = "Method", output(proxy))] + fn conjugate(self) -> bevy::math::DQuat; + +"#, + r#" +/// Returns the inverse of a normalized quaternion. +/// Typically quaternion inverse returns the conjugate of a normalized quaternion. +/// Because `self` is assumed to already be unit length this method *does not* normalize +/// before returning the conjugate. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn inverse(self) -> bevy::math::DQuat; + +"#, + r#" +/// Computes the dot product of `self` and `rhs`. The dot product is +/// equal to the cosine of the angle between two quaternion rotations. + + #[lua(kind = "Method")] + fn dot(self, #[proxy] rhs: bevy::math::DQuat) -> f64; + +"#, + r#" +/// Computes the length of `self`. + + #[lua(kind = "Method")] + fn length(self) -> f64; + +"#, + r#" +/// Computes the squared length of `self`. +/// This is generally faster than `length()` as it avoids a square +/// root operation. + + #[lua(kind = "Method")] + fn length_squared(self) -> f64; + +"#, + r#" +/// Computes `1.0 / length()`. +/// For valid results, `self` must _not_ be of length zero. + + #[lua(kind = "Method")] + fn length_recip(self) -> f64; + +"#, + r#" +/// Returns `self` normalized to length 1.0. +/// For valid results, `self` must _not_ be of length zero. +/// Panics +/// Will panic if `self` is zero length when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn normalize(self) -> bevy::math::DQuat; + +"#, + r#" +/// Returns `true` if, and only if, all elements are finite. +/// If any element is either `NaN`, positive or negative infinity, this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(self) -> bool; + +"#, + r#" +/// Returns `true` if any elements are `NAN`. + + #[lua(kind = "Method")] + fn is_nan(self) -> bool; + +"#, + r#" +/// Returns whether `self` of length `1.0` or not. +/// Uses a precision threshold of `1e-6`. + + #[lua(kind = "Method")] + fn is_normalized(self) -> bool; + +"#, + r#" + + #[lua(kind = "Method")] + fn is_near_identity(self) -> bool; + +"#, + r#" +/// Returns the angle (in radians) for the minimal rotation +/// for transforming this quaternion into another. +/// Both quaternions must be normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method")] + fn angle_between(self, #[proxy] rhs: bevy::math::DQuat) -> f64; + +"#, + r#" +/// Rotates towards `rhs` up to `max_angle` (in radians). +/// When `max_angle` is `0.0`, the result will be equal to `self`. When `max_angle` is equal to +/// `self.angle_between(rhs)`, the result will be equal to `rhs`. If `max_angle` is negative, +/// rotates towards the exact opposite of `rhs`. Will not go past the target. +/// Both quaternions must be normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn rotate_towards( + &self, + #[proxy] + rhs: bevy::math::DQuat, + max_angle: f64, + ) -> bevy::math::DQuat; + +"#, + r#" +/// Returns true if the absolute difference of all elements between `self` and `rhs` +/// is less than or equal to `max_abs_diff`. +/// This can be used to compare if two quaternions contain similar elements. It works +/// best when comparing with a known value. The `max_abs_diff` that should be used used +/// depends on the values being compared against. +/// For more see +/// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + + #[lua(kind = "Method")] + fn abs_diff_eq(self, #[proxy] rhs: bevy::math::DQuat, max_abs_diff: f64) -> bool; + +"#, + r#" +/// Performs a linear interpolation between `self` and `rhs` based on +/// the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` +/// is `1.0`, the result will be equal to `rhs`. +/// # Panics +/// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn lerp(self, #[proxy] end: bevy::math::DQuat, s: f64) -> bevy::math::DQuat; + +"#, + r#" +/// Performs a spherical linear interpolation between `self` and `end` +/// based on the value `s`. +/// When `s` is `0.0`, the result will be equal to `self`. When `s` +/// is `1.0`, the result will be equal to `end`. +/// # Panics +/// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn slerp(self, #[proxy] end: bevy::math::DQuat, s: f64) -> bevy::math::DQuat; + +"#, + r#" +/// Multiplies a quaternion and a 3D vector, returning the rotated vector. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn mul_vec3(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + +"#, + r#" +/// Multiplies two quaternions. If they each represent a rotation, the result will +/// represent the combined rotation. +/// Note that due to floating point rounding the result may not be perfectly normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + + #[lua(kind = "Method", output(proxy))] + fn mul_quat(self, #[proxy] rhs: bevy::math::DQuat) -> bevy::math::DQuat; + +"#, + r#" +/// Creates a quaternion from a 3x3 rotation matrix inside a 3D affine transform. +/// Note if the input affine matrix contain scales, shears, or other non-rotation +/// transformations then the resulting quaternion will be ill-defined. +/// # Panics +/// Will panic if any input affine matrix column is not normalized when `glam_assert` is +/// enabled. + + #[lua(kind = "Function", output(proxy))] + fn from_affine3(#[proxy] a: &glam::DAffine3) -> bevy::math::DQuat; + +"#, + r#" + + #[lua(kind = "Method", output(proxy))] + fn as_quat(self) -> bevy::math::Quat; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct DQuat { + x: f64, + y: f64, + z: f64, + w: f64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::EulerRot", + functions[r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::EulerRot; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &glam::EulerRot) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct EulerRot {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::BVec3A", + functions[r#" +/// Creates a new vector mask. + + #[lua(kind = "Function", output(proxy))] + fn new(x: bool, y: bool, z: bool) -> bevy::math::BVec3A; + +"#, + r#" +/// Creates a vector mask with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: bool) -> bevy::math::BVec3A; + +"#, + r#" +/// Creates a new vector mask from a bool array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [bool; 3]) -> bevy::math::BVec3A; + +"#, + r#" +/// Returns a bitmask with the lowest 3 bits set from the elements of `self`. +/// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn bitmask(self) -> u32; + +"#, + r#" +/// Returns true if any of the elements are true, false otherwise. + + #[lua(kind = "Method")] + fn any(self) -> bool; + +"#, + r#" +/// Returns true if all the elements are true, false otherwise. + + #[lua(kind = "Method")] + fn all(self) -> bool; + +"#, + r#" +/// Tests the value at `index`. +/// Panics if `index` is greater than 2. + + #[lua(kind = "Method")] + fn test(&self, index: usize) -> bool; + +"#, + r#" +/// Sets the element at `index`. +/// Panics if `index` is greater than 2. + + #[lua(kind = "MutatingMethod")] + fn set(&mut self, index: usize, value: bool) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::BVec3A) -> bool; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::BVec3A; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct BVec3A(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::math::BVec4A", + functions[r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> bevy::math::BVec4A; + +"#, + r#" +/// Creates a new vector mask. + + #[lua(kind = "Function", output(proxy))] + fn new(x: bool, y: bool, z: bool, w: bool) -> bevy::math::BVec4A; + +"#, + r#" +/// Creates a vector mask with all elements set to `v`. + + #[lua(kind = "Function", output(proxy))] + fn splat(v: bool) -> bevy::math::BVec4A; + +"#, + r#" +/// Creates a new vector mask from a bool array. + + #[lua(kind = "Function", output(proxy))] + fn from_array(a: [bool; 4]) -> bevy::math::BVec4A; + +"#, + r#" +/// Returns a bitmask with the lowest 4 bits set from the elements of `self`. +/// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes +/// into the first lowest bit, element `y` into the second, etc. + + #[lua(kind = "Method")] + fn bitmask(self) -> u32; + +"#, + r#" +/// Returns true if any of the elements are true, false otherwise. + + #[lua(kind = "Method")] + fn any(self) -> bool; + +"#, + r#" +/// Returns true if all the elements are true, false otherwise. + + #[lua(kind = "Method")] + fn all(self) -> bool; + +"#, + r#" +/// Tests the value at `index`. +/// Panics if `index` is greater than 3. + + #[lua(kind = "Method")] + fn test(&self, index: usize) -> bool; + +"#, + r#" +/// Sets the element at `index`. +/// Panics if `index` is greater than 3. + + #[lua(kind = "MutatingMethod")] + fn set(&mut self, index: usize, value: bool) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] rhs: &glam::BVec4A) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct BVec4A(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "smol_str::SmolStr", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &smol_str::SmolStr) -> bool; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> smol_str::SmolStr; + +"#, + r#" + + #[lua(kind = "Method")] + fn to_string(&self) -> std::string::String; + +"#, + r#" + + #[lua(kind = "Method")] + fn len(&self) -> usize; + +"#, + r#" + + #[lua(kind = "Method")] + fn is_empty(&self) -> bool; + +"#, + r#" + + #[lua(kind = "Method")] + fn is_heap_allocated(&self) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct SmolStr(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "uuid::Uuid", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +/// Creates a random UUID. +/// This uses the [`getrandom`] crate to utilise the operating system's RNG +/// as the source of random numbers. If you'd like to use a custom +/// generator, don't use this method: generate random bytes using your +/// custom generator and pass them to the +/// [`uuid::Builder::from_random_bytes`][from_random_bytes] function +/// instead. +/// Note that usage of this method requires the `v4` feature of this crate +/// to be enabled. +/// # Examples +/// Basic usage: +/// ``` +/// # use uuid::{Uuid, Version}; +/// let uuid = Uuid::new_v4(); +/// assert_eq!(Some(Version::Random), uuid.get_version()); +/// ``` +/// # References +/// * [UUID Version 4 in RFC 9562](https://www.ietf.org/rfc/rfc9562.html#section-5.4) +/// [`getrandom`]: https://crates.io/crates/getrandom +/// [from_random_bytes]: struct.Builder.html#method.from_random_bytes + + #[lua(kind = "Function", output(proxy))] + fn new_v4() -> uuid::Uuid; + +"#, + r#" +/// Returns the version number of the UUID. +/// This represents the algorithm used to generate the value. +/// This method is the future-proof alternative to [`Uuid::get_version`]. +/// # Examples +/// Basic usage: +/// ``` +/// # use uuid::Uuid; +/// # fn main() -> Result<(), uuid::Error> { +/// let my_uuid = Uuid::parse_str("02f09a3f-1624-3b1d-8409-44eff7708208")?; +/// assert_eq!(3, my_uuid.get_version_num()); +/// # Ok(()) +/// # } +/// ``` +/// # References +/// * [Version Field in RFC 9562](https://www.ietf.org/rfc/rfc9562.html#section-4.2) + + #[lua(kind = "Method")] + fn get_version_num(&self) -> usize; + +"#, + r#" +/// Returns a 128bit value containing the value. +/// The bytes in the UUID will be packed directly into a `u128`. +/// # Examples +/// ``` +/// # use uuid::Uuid; +/// # fn main() -> Result<(), uuid::Error> { +/// let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?; +/// assert_eq!( +/// uuid.as_u128(), +/// 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8, +/// ); +/// # Ok(()) +/// # } +/// ``` + + #[lua(kind = "Method")] + fn as_u128(&self) -> u128; + +"#, + r#" +/// Returns a 128bit little-endian value containing the value. +/// The bytes in the `u128` will be flipped to convert into big-endian +/// order. This is based on the endianness of the UUID, rather than the +/// target environment so bytes will be flipped on both big and little +/// endian machines. +/// Note that this will produce a different result than +/// [`Uuid::to_fields_le`], because the entire UUID is reversed, rather +/// than reversing the individual fields in-place. +/// # Examples +/// ``` +/// # use uuid::Uuid; +/// # fn main() -> Result<(), uuid::Error> { +/// let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?; +/// assert_eq!( +/// uuid.to_u128_le(), +/// 0xd8d7d6d5d4d3d2d1c2c1b2b1a4a3a2a1, +/// ); +/// # Ok(()) +/// # } +/// ``` + + #[lua(kind = "Method")] + fn to_u128_le(&self) -> u128; + +"#, + r#" +/// Returns two 64bit values containing the value. +/// The bytes in the UUID will be split into two `u64`. +/// The first u64 represents the 64 most significant bits, +/// the second one represents the 64 least significant. +/// # Examples +/// ``` +/// # use uuid::Uuid; +/// # fn main() -> Result<(), uuid::Error> { +/// let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?; +/// assert_eq!( +/// uuid.as_u64_pair(), +/// (0xa1a2a3a4b1b2c1c2, 0xd1d2d3d4d5d6d7d8), +/// ); +/// # Ok(()) +/// # } +/// ``` + + #[lua(kind = "Method")] + fn as_u64_pair(&self) -> (u64, u64); + +"#, + r#" +/// Consumes self and returns the underlying byte value of the UUID. +/// # Examples +/// ``` +/// # use uuid::Uuid; +/// let bytes = [ +/// 0xa1, 0xa2, 0xa3, 0xa4, +/// 0xb1, 0xb2, +/// 0xc1, 0xc2, +/// 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, +/// ]; +/// let uuid = Uuid::from_bytes(bytes); +/// assert_eq!(bytes, uuid.into_bytes()); +/// ``` + + #[lua(kind = "Method")] + fn into_bytes(self) -> [u8; 16]; + +"#, + r#" +/// Returns the bytes of the UUID in little-endian order. +/// The bytes will be flipped to convert into little-endian order. This is +/// based on the endianness of the UUID, rather than the target environment +/// so bytes will be flipped on both big and little endian machines. +/// # Examples +/// ``` +/// use uuid::Uuid; +/// # fn main() -> Result<(), uuid::Error> { +/// let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?; +/// assert_eq!( +/// uuid.to_bytes_le(), +/// ([ +/// 0xa4, 0xa3, 0xa2, 0xa1, 0xb2, 0xb1, 0xc2, 0xc1, 0xd1, 0xd2, +/// 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8 +/// ]) +/// ); +/// # Ok(()) +/// # } +/// ``` + + #[lua(kind = "Method")] + fn to_bytes_le(&self) -> [u8; 16]; + +"#, + r#" +/// Tests if the UUID is nil (all zeros). + + #[lua(kind = "Method")] + fn is_nil(&self) -> bool; + +"#, + r#" +/// Tests if the UUID is max (all ones). + + #[lua(kind = "Method")] + fn is_max(&self) -> bool; + +"#, + r#" +/// A buffer that can be used for `encode_...` calls, that is +/// guaranteed to be long enough for any of the format adapters. +/// # Examples +/// ``` +/// # use uuid::Uuid; +/// let uuid = Uuid::nil(); +/// assert_eq!( +/// uuid.simple().encode_lower(&mut Uuid::encode_buffer()), +/// "00000000000000000000000000000000" +/// ); +/// assert_eq!( +/// uuid.hyphenated() +/// .encode_lower(&mut Uuid::encode_buffer()), +/// "00000000-0000-0000-0000-000000000000" +/// ); +/// assert_eq!( +/// uuid.urn().encode_lower(&mut Uuid::encode_buffer()), +/// "urn:uuid:00000000-0000-0000-0000-000000000000" +/// ); +/// ``` + + #[lua(kind = "Function")] + fn encode_buffer() -> [u8; 45]; + +"#, + r#" +/// If the UUID is the correct version (v1, or v6) this will return the +/// node value as a 6-byte array. For other versions this will return `None`. + + #[lua(kind = "Method")] + fn get_node_id( + &self, + ) -> bevy::reflect::erased_serde::__private::serde::__private::Option<[u8; 6]>; + +"#, + r#" +/// The 'nil UUID' (all zeros). +/// The nil UUID is a special form of UUID that is specified to have all +/// 128 bits set to zero. +/// # References +/// * [Nil UUID in RFC 9562](https://www.ietf.org/rfc/rfc9562.html#section-5.9) +/// # Examples +/// Basic usage: +/// ``` +/// # use uuid::Uuid; +/// let uuid = Uuid::nil(); +/// assert_eq!( +/// "00000000-0000-0000-0000-000000000000", +/// uuid.hyphenated().to_string(), +/// ); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn nil() -> uuid::Uuid; + +"#, + r#" +/// The 'max UUID' (all ones). +/// The max UUID is a special form of UUID that is specified to have all +/// 128 bits set to one. +/// # References +/// * [Max UUID in RFC 9562](https://www.ietf.org/rfc/rfc9562.html#section-5.10) +/// # Examples +/// Basic usage: +/// ``` +/// # use uuid::Uuid; +/// let uuid = Uuid::max(); +/// assert_eq!( +/// "ffffffff-ffff-ffff-ffff-ffffffffffff", +/// uuid.hyphenated().to_string(), +/// ); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn max() -> uuid::Uuid; + +"#, + r#" +/// Creates a UUID from a 128bit value. +/// # Examples +/// Basic usage: +/// ``` +/// # use uuid::Uuid; +/// let v = 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8u128; +/// let uuid = Uuid::from_u128(v); +/// assert_eq!( +/// "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8", +/// uuid.hyphenated().to_string(), +/// ); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_u128(v: u128) -> uuid::Uuid; + +"#, + r#" +/// Creates a UUID from a 128bit value in little-endian order. +/// The entire value will be flipped to convert into big-endian order. +/// This is based on the endianness of the UUID, rather than the target +/// environment so bytes will be flipped on both big and little endian +/// machines. +/// # Examples +/// Basic usage: +/// ``` +/// # use uuid::Uuid; +/// let v = 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8u128; +/// let uuid = Uuid::from_u128_le(v); +/// assert_eq!( +/// "d8d7d6d5-d4d3-d2d1-c2c1-b2b1a4a3a2a1", +/// uuid.hyphenated().to_string(), +/// ); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_u128_le(v: u128) -> uuid::Uuid; + +"#, + r#" +/// Creates a UUID from two 64bit values. +/// # Examples +/// Basic usage: +/// ``` +/// # use uuid::Uuid; +/// let hi = 0xa1a2a3a4b1b2c1c2u64; +/// let lo = 0xd1d2d3d4d5d6d7d8u64; +/// let uuid = Uuid::from_u64_pair(hi, lo); +/// assert_eq!( +/// "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8", +/// uuid.hyphenated().to_string(), +/// ); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_u64_pair(high_bits: u64, low_bits: u64) -> uuid::Uuid; + +"#, + r#" +/// Creates a UUID using the supplied bytes. +/// # Examples +/// Basic usage: +/// ``` +/// # fn main() -> Result<(), uuid::Error> { +/// # use uuid::Uuid; +/// let bytes = [ +/// 0xa1, 0xa2, 0xa3, 0xa4, +/// 0xb1, 0xb2, +/// 0xc1, 0xc2, +/// 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, +/// ]; +/// let uuid = Uuid::from_bytes(bytes); +/// assert_eq!( +/// uuid.hyphenated().to_string(), +/// "a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8" +/// ); +/// # Ok(()) +/// # } +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_bytes(bytes: [u8; 16]) -> uuid::Uuid; + +"#, + r#" +/// Creates a UUID using the supplied bytes in little endian order. +/// The individual fields encoded in the buffer will be flipped. +/// # Examples +/// Basic usage: +/// ``` +/// # fn main() -> Result<(), uuid::Error> { +/// # use uuid::Uuid; +/// let bytes = [ +/// 0xa1, 0xa2, 0xa3, 0xa4, +/// 0xb1, 0xb2, +/// 0xc1, 0xc2, +/// 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, +/// ]; +/// let uuid = Uuid::from_bytes_le(bytes); +/// assert_eq!( +/// "a4a3a2a1-b2b1-c2c1-d1d2-d3d4d5d6d7d8", +/// uuid.hyphenated().to_string(), +/// ); +/// # Ok(()) +/// # } +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_bytes_le(b: [u8; 16]) -> uuid::Uuid; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &uuid::Uuid) -> bool; + +"#, + r#" + + #[lua( + as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", + kind = "Method", + output(proxy), + )] + fn clone(&self) -> uuid::Uuid; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Uuid(); +#[derive(Default)] +pub(crate) struct Globals; +impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { + fn add_instances< + 'lua, + T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, + >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { + instances + .add_instance( + "AtomicBool", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "AtomicI16", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "AtomicI32", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "AtomicI64", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "AtomicI8", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "AtomicIsize", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "AtomicU16", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "AtomicU32", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "AtomicU64", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "AtomicU8", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "AtomicUsize", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Duration", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Instant", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "PathBuf", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Quat", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Vec3", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "IVec2", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "IVec3", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "IVec4", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "I64Vec2", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "I64Vec3", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "I64Vec4", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "UVec2", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "UVec3", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "UVec4", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "U64Vec2", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "U64Vec3", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "U64Vec4", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Vec2", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Vec3A", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Vec4", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "BVec2", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "BVec3", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "BVec4", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "DVec2", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "DVec3", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "DVec4", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Mat2", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Mat3", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Mat3A", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Mat4", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "DMat2", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "DMat3", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "DMat4", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Affine2", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Affine3A", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "DAffine2", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "DAffine3", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "DQuat", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "BVec3A", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "BVec4A", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Uuid", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + Ok(()) + } +} +pub struct BevyReflectAPIProvider; +impl bevy_mod_scripting_core::hosts::APIProvider for BevyReflectAPIProvider { + type APITarget = std::sync::Mutex; + type ScriptContext = std::sync::Mutex; + type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; + fn attach_api( + &mut self, + ctx: &mut Self::APITarget, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); + bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) + .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( + e.to_string(), + )) + } + fn get_doc_fragment(&self) -> Option { + Some( + bevy_mod_scripting_lua::docs::LuaDocFragment::new( + "BevyReflectAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaAtomicBool, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaAtomicI16, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaAtomicI32, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaAtomicI64, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaAtomicI8, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaAtomicIsize, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaAtomicU16, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaAtomicU32, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaAtomicU64, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaAtomicU8, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaAtomicUsize, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaDuration, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaAffine3A, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaDAffine2, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaDAffine3, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + }, + ), + ) + } + fn setup_script( + &mut self, + script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn setup_script_runtime( + &mut self, + world_ptr: bevy_mod_scripting_core::world::WorldPointer, + _script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn register_with_app(&self, app: &mut bevy::app::App) { + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs new file mode 100644 index 0000000000..8910927aea --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs @@ -0,0 +1,736 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use super::bevy_ecs::*; +use super::bevy_reflect::*; +extern crate self as bevy_script_api; +use bevy_script_api::{ + lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::time::prelude::Fixed", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::time::prelude::Fixed; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Fixed {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::time::prelude::Real", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::time::prelude::Real; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Real {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::time::prelude::Timer", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +/// Creates a new timer with a given duration. +/// See also [`Timer::from_seconds`](Timer::from_seconds). + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + duration: bevy::utils::Duration, + #[proxy] + mode: bevy::time::prelude::TimerMode, + ) -> bevy::time::prelude::Timer; + +"#, + r#" +/// Creates a new timer with a given duration in seconds. +/// # Example +/// ``` +/// # use bevy_time::*; +/// let mut timer = Timer::from_seconds(1.0, TimerMode::Once); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn from_seconds( + duration: f32, + #[proxy] + mode: bevy::time::prelude::TimerMode, + ) -> bevy::time::prelude::Timer; + +"#, + r#" +/// Returns `true` if the timer has reached its duration. +/// For repeating timers, this method behaves identically to [`Timer::just_finished`]. +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut timer_once = Timer::from_seconds(1.0, TimerMode::Once); +/// timer_once.tick(Duration::from_secs_f32(1.5)); +/// assert!(timer_once.finished()); +/// timer_once.tick(Duration::from_secs_f32(0.5)); +/// assert!(timer_once.finished()); +/// let mut timer_repeating = Timer::from_seconds(1.0, TimerMode::Repeating); +/// timer_repeating.tick(Duration::from_secs_f32(1.1)); +/// assert!(timer_repeating.finished()); +/// timer_repeating.tick(Duration::from_secs_f32(0.8)); +/// assert!(!timer_repeating.finished()); +/// timer_repeating.tick(Duration::from_secs_f32(0.6)); +/// assert!(timer_repeating.finished()); +/// ``` + + #[lua(kind = "Method")] + fn finished(&self) -> bool; + +"#, + r#" +/// Returns `true` only on the tick the timer reached its duration. +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut timer = Timer::from_seconds(1.0, TimerMode::Once); +/// timer.tick(Duration::from_secs_f32(1.5)); +/// assert!(timer.just_finished()); +/// timer.tick(Duration::from_secs_f32(0.5)); +/// assert!(!timer.just_finished()); +/// ``` + + #[lua(kind = "Method")] + fn just_finished(&self) -> bool; + +"#, + r#" +/// Returns the time elapsed on the timer. Guaranteed to be between 0.0 and `duration`. +/// Will only equal `duration` when the timer is finished and non repeating. +/// See also [`Stopwatch::elapsed`](Stopwatch::elapsed). +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut timer = Timer::from_seconds(1.0, TimerMode::Once); +/// timer.tick(Duration::from_secs_f32(0.5)); +/// assert_eq!(timer.elapsed(), Duration::from_secs_f32(0.5)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn elapsed(&self) -> bevy::utils::Duration; + +"#, + r#" +/// Returns the time elapsed on the timer as an `f32`. +/// See also [`Timer::elapsed`](Timer::elapsed). + + #[lua(kind = "Method")] + fn elapsed_secs(&self) -> f32; + +"#, + r#" +/// Returns the time elapsed on the timer as an `f64`. +/// See also [`Timer::elapsed`](Timer::elapsed). + + #[lua(kind = "Method")] + fn elapsed_secs_f64(&self) -> f64; + +"#, + r#" +/// Sets the elapsed time of the timer without any other considerations. +/// See also [`Stopwatch::set`](Stopwatch::set). +/// # +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut timer = Timer::from_seconds(1.0, TimerMode::Once); +/// timer.set_elapsed(Duration::from_secs(2)); +/// assert_eq!(timer.elapsed(), Duration::from_secs(2)); +/// // the timer is not finished even if the elapsed time is greater than the duration. +/// assert!(!timer.finished()); +/// ``` + + #[lua(kind = "MutatingMethod")] + fn set_elapsed(&mut self, #[proxy] time: bevy::utils::Duration) -> (); + +"#, + r#" +/// Returns the duration of the timer. +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let timer = Timer::new(Duration::from_secs(1), TimerMode::Once); +/// assert_eq!(timer.duration(), Duration::from_secs(1)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn duration(&self) -> bevy::utils::Duration; + +"#, + r#" +/// Sets the duration of the timer. +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut timer = Timer::from_seconds(1.5, TimerMode::Once); +/// timer.set_duration(Duration::from_secs(1)); +/// assert_eq!(timer.duration(), Duration::from_secs(1)); +/// ``` + + #[lua(kind = "MutatingMethod")] + fn set_duration(&mut self, #[proxy] duration: bevy::utils::Duration) -> (); + +"#, + r#" +/// Returns the mode of the timer. +/// # Examples +/// ``` +/// # use bevy_time::*; +/// let mut timer = Timer::from_seconds(1.0, TimerMode::Repeating); +/// assert_eq!(timer.mode(), TimerMode::Repeating); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn mode(&self) -> bevy::time::prelude::TimerMode; + +"#, + r#" +/// Sets the mode of the timer. +/// # Examples +/// ``` +/// # use bevy_time::*; +/// let mut timer = Timer::from_seconds(1.0, TimerMode::Repeating); +/// timer.set_mode(TimerMode::Once); +/// assert_eq!(timer.mode(), TimerMode::Once); +/// ``` + + #[lua(kind = "MutatingMethod")] + fn set_mode(&mut self, #[proxy] mode: bevy::time::prelude::TimerMode) -> (); + +"#, + r#" +/// Pauses the Timer. Disables the ticking of the timer. +/// See also [`Stopwatch::pause`](Stopwatch::pause). +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut timer = Timer::from_seconds(1.0, TimerMode::Once); +/// timer.pause(); +/// timer.tick(Duration::from_secs_f32(0.5)); +/// assert_eq!(timer.elapsed_secs(), 0.0); +/// ``` + + #[lua(kind = "MutatingMethod")] + fn pause(&mut self) -> (); + +"#, + r#" +/// Unpauses the Timer. Resumes the ticking of the timer. +/// See also [`Stopwatch::unpause()`](Stopwatch::unpause). +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut timer = Timer::from_seconds(1.0, TimerMode::Once); +/// timer.pause(); +/// timer.tick(Duration::from_secs_f32(0.5)); +/// timer.unpause(); +/// timer.tick(Duration::from_secs_f32(0.5)); +/// assert_eq!(timer.elapsed_secs(), 0.5); +/// ``` + + #[lua(kind = "MutatingMethod")] + fn unpause(&mut self) -> (); + +"#, + r#" +/// Returns `true` if the timer is paused. +/// See also [`Stopwatch::is_paused`](Stopwatch::is_paused). +/// # Examples +/// ``` +/// # use bevy_time::*; +/// let mut timer = Timer::from_seconds(1.0, TimerMode::Once); +/// assert!(!timer.paused()); +/// timer.pause(); +/// assert!(timer.paused()); +/// timer.unpause(); +/// assert!(!timer.paused()); +/// ``` + + #[lua(kind = "Method")] + fn paused(&self) -> bool; + +"#, + r#" +/// Resets the timer. The reset doesn't affect the `paused` state of the timer. +/// See also [`Stopwatch::reset`](Stopwatch::reset). +/// Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut timer = Timer::from_seconds(1.0, TimerMode::Once); +/// timer.tick(Duration::from_secs_f32(1.5)); +/// timer.reset(); +/// assert!(!timer.finished()); +/// assert!(!timer.just_finished()); +/// assert_eq!(timer.elapsed_secs(), 0.0); +/// ``` + + #[lua(kind = "MutatingMethod")] + fn reset(&mut self) -> (); + +"#, + r#" +/// Returns the fraction of the timer elapsed time (goes from 0.0 to 1.0). +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut timer = Timer::from_seconds(2.0, TimerMode::Once); +/// timer.tick(Duration::from_secs_f32(0.5)); +/// assert_eq!(timer.fraction(), 0.25); +/// ``` + + #[lua(kind = "Method")] + fn fraction(&self) -> f32; + +"#, + r#" +/// Returns the fraction of the timer remaining time (goes from 1.0 to 0.0). +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut timer = Timer::from_seconds(2.0, TimerMode::Once); +/// timer.tick(Duration::from_secs_f32(0.5)); +/// assert_eq!(timer.fraction_remaining(), 0.75); +/// ``` + + #[lua(kind = "Method")] + fn fraction_remaining(&self) -> f32; + +"#, + r#" +/// Returns the remaining time in seconds +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::cmp::Ordering; +/// use std::time::Duration; +/// let mut timer = Timer::from_seconds(2.0, TimerMode::Once); +/// timer.tick(Duration::from_secs_f32(0.5)); +/// let result = timer.remaining_secs().total_cmp(&1.5); +/// assert_eq!(Ordering::Equal, result); +/// ``` + + #[lua(kind = "Method")] + fn remaining_secs(&self) -> f32; + +"#, + r#" +/// Returns the remaining time using Duration +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut timer = Timer::from_seconds(2.0, TimerMode::Once); +/// timer.tick(Duration::from_secs_f32(0.5)); +/// assert_eq!(timer.remaining(), Duration::from_secs_f32(1.5)); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn remaining(&self) -> bevy::utils::Duration; + +"#, + r#" +/// Returns the number of times a repeating timer +/// finished during the last [`tick`](Timer::tick) call. +/// For non repeating-timers, this method will only ever +/// return 0 or 1. +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut timer = Timer::from_seconds(1.0, TimerMode::Repeating); +/// timer.tick(Duration::from_secs_f32(6.0)); +/// assert_eq!(timer.times_finished_this_tick(), 6); +/// timer.tick(Duration::from_secs_f32(2.0)); +/// assert_eq!(timer.times_finished_this_tick(), 2); +/// timer.tick(Duration::from_secs_f32(0.5)); +/// assert_eq!(timer.times_finished_this_tick(), 0); +/// ``` + + #[lua(kind = "Method")] + fn times_finished_this_tick(&self) -> u32; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::time::prelude::Timer; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &timer::Timer) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Timer {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::time::prelude::TimerMode", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &timer::TimerMode) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::time::prelude::TimerMode; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct TimerMode {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::time::prelude::Virtual", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::time::prelude::Virtual; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Virtual {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::time::Stopwatch", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::time::Stopwatch; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &stopwatch::Stopwatch) -> bool; + +"#, + r#" +/// Create a new unpaused `Stopwatch` with no elapsed time. +/// # Examples +/// ``` +/// # use bevy_time::*; +/// let stopwatch = Stopwatch::new(); +/// assert_eq!(stopwatch.elapsed_secs(), 0.0); +/// assert_eq!(stopwatch.is_paused(), false); +/// ``` + + #[lua(kind = "Function", output(proxy))] + fn new() -> bevy::time::Stopwatch; + +"#, + r#" +/// Returns the elapsed time since the last [`reset`](Stopwatch::reset) +/// of the stopwatch. +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut stopwatch = Stopwatch::new(); +/// stopwatch.tick(Duration::from_secs(1)); +/// assert_eq!(stopwatch.elapsed(), Duration::from_secs(1)); +/// ``` +/// # See Also +/// [`elapsed_secs`](Stopwatch::elapsed_secs) - if an `f32` value is desirable instead. +/// [`elapsed_secs_f64`](Stopwatch::elapsed_secs_f64) - if an `f64` is desirable instead. + + #[lua(kind = "Method", output(proxy))] + fn elapsed(&self) -> bevy::utils::Duration; + +"#, + r#" +/// Returns the elapsed time since the last [`reset`](Stopwatch::reset) +/// of the stopwatch, in seconds. +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut stopwatch = Stopwatch::new(); +/// stopwatch.tick(Duration::from_secs(1)); +/// assert_eq!(stopwatch.elapsed_secs(), 1.0); +/// ``` +/// # See Also +/// [`elapsed`](Stopwatch::elapsed) - if a `Duration` is desirable instead. +/// [`elapsed_secs_f64`](Stopwatch::elapsed_secs_f64) - if an `f64` is desirable instead. + + #[lua(kind = "Method")] + fn elapsed_secs(&self) -> f32; + +"#, + r#" +/// Returns the elapsed time since the last [`reset`](Stopwatch::reset) +/// of the stopwatch, in seconds, as f64. +/// # See Also +/// [`elapsed`](Stopwatch::elapsed) - if a `Duration` is desirable instead. +/// [`elapsed_secs`](Stopwatch::elapsed_secs) - if an `f32` is desirable instead. + + #[lua(kind = "Method")] + fn elapsed_secs_f64(&self) -> f64; + +"#, + r#" +/// Sets the elapsed time of the stopwatch. +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut stopwatch = Stopwatch::new(); +/// stopwatch.set_elapsed(Duration::from_secs_f32(1.0)); +/// assert_eq!(stopwatch.elapsed_secs(), 1.0); +/// ``` + + #[lua(kind = "MutatingMethod")] + fn set_elapsed(&mut self, #[proxy] time: bevy::utils::Duration) -> (); + +"#, + r#" +/// Pauses the stopwatch. Any call to [`tick`](Stopwatch::tick) while +/// paused will not have any effect on the elapsed time. +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut stopwatch = Stopwatch::new(); +/// stopwatch.pause(); +/// stopwatch.tick(Duration::from_secs_f32(1.5)); +/// assert!(stopwatch.is_paused()); +/// assert_eq!(stopwatch.elapsed_secs(), 0.0); +/// ``` + + #[lua(kind = "MutatingMethod")] + fn pause(&mut self) -> (); + +"#, + r#" +/// Unpauses the stopwatch. Resume the effect of ticking on elapsed time. +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut stopwatch = Stopwatch::new(); +/// stopwatch.pause(); +/// stopwatch.tick(Duration::from_secs_f32(1.0)); +/// stopwatch.unpause(); +/// stopwatch.tick(Duration::from_secs_f32(1.0)); +/// assert!(!stopwatch.is_paused()); +/// assert_eq!(stopwatch.elapsed_secs(), 1.0); +/// ``` + + #[lua(kind = "MutatingMethod")] + fn unpause(&mut self) -> (); + +"#, + r#" +/// Returns `true` if the stopwatch is paused. +/// # Examples +/// ``` +/// # use bevy_time::*; +/// let mut stopwatch = Stopwatch::new(); +/// assert!(!stopwatch.is_paused()); +/// stopwatch.pause(); +/// assert!(stopwatch.is_paused()); +/// stopwatch.unpause(); +/// assert!(!stopwatch.is_paused()); +/// ``` + + #[lua(kind = "Method")] + fn is_paused(&self) -> bool; + +"#, + r#" +/// Resets the stopwatch. The reset doesn't affect the paused state of the stopwatch. +/// # Examples +/// ``` +/// # use bevy_time::*; +/// use std::time::Duration; +/// let mut stopwatch = Stopwatch::new(); +/// stopwatch.tick(Duration::from_secs_f32(1.5)); +/// stopwatch.reset(); +/// assert_eq!(stopwatch.elapsed_secs(), 0.0); +/// ``` + + #[lua(kind = "MutatingMethod")] + fn reset(&mut self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Stopwatch {} +#[derive(Default)] +pub(crate) struct Globals; +impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { + fn add_instances< + 'lua, + T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, + >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { + instances + .add_instance( + "Timer", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + instances + .add_instance( + "Stopwatch", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + Ok(()) + } +} +pub struct BevyTimeAPIProvider; +impl bevy_mod_scripting_core::hosts::APIProvider for BevyTimeAPIProvider { + type APITarget = std::sync::Mutex; + type ScriptContext = std::sync::Mutex; + type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; + fn attach_api( + &mut self, + ctx: &mut Self::APITarget, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); + bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) + .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( + e.to_string(), + )) + } + fn get_doc_fragment(&self) -> Option { + Some( + bevy_mod_scripting_lua::docs::LuaDocFragment::new( + "BevyTimeAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, + >() + .process_type::() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaStopwatch, + >, + >() + }, + ), + ) + } + fn setup_script( + &mut self, + script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn setup_script_runtime( + &mut self, + world_ptr: bevy_mod_scripting_core::world::WorldPointer, + _script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn register_with_app(&self, app: &mut bevy::app::App) { + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs new file mode 100644 index 0000000000..d6e093de4a --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs @@ -0,0 +1,819 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use super::bevy_ecs::*; +use super::bevy_reflect::*; +use super::bevy_core::*; +use super::bevy_math::*; +use super::bevy_hierarchy::*; +extern crate self as bevy_script_api; +use bevy_script_api::{ + lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::transform::components::GlobalTransform", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &components::global_transform::GlobalTransform) -> bool; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul( + self, + #[proxy] + transform: bevy::transform::components::Transform, + ) -> bevy::transform::components::GlobalTransform; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] value: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::transform::components::GlobalTransform; + +"#, + r#" + + #[lua(kind = "Function", output(proxy))] + fn from_xyz(x: f32, y: f32, z: f32) -> bevy::transform::components::GlobalTransform; + +"#, + r#" + + #[lua(kind = "Function", output(proxy))] + fn from_translation( + #[proxy] + translation: bevy::math::Vec3, + ) -> bevy::transform::components::GlobalTransform; + +"#, + r#" + + #[lua(kind = "Function", output(proxy))] + fn from_rotation( + #[proxy] + rotation: bevy::math::Quat, + ) -> bevy::transform::components::GlobalTransform; + +"#, + r#" + + #[lua(kind = "Function", output(proxy))] + fn from_scale( + #[proxy] + scale: bevy::math::Vec3, + ) -> bevy::transform::components::GlobalTransform; + +"#, + r#" + + #[lua(kind = "Function", output(proxy))] + fn from_isometry( + #[proxy] + iso: bevy::math::Isometry3d, + ) -> bevy::transform::components::GlobalTransform; + +"#, + r#" +/// Returns the 3d affine transformation matrix as a [`Mat4`]. + + #[lua(kind = "Method", output(proxy))] + fn compute_matrix(&self) -> bevy::math::Mat4; + +"#, + r#" +/// Returns the 3d affine transformation matrix as an [`Affine3A`]. + + #[lua(kind = "Method", output(proxy))] + fn affine(&self) -> bevy::math::Affine3A; + +"#, + r#" +/// Returns the transformation as a [`Transform`]. +/// The transform is expected to be non-degenerate and without shearing, or the output +/// will be invalid. + + #[lua(kind = "Method", output(proxy))] + fn compute_transform(&self) -> bevy::transform::components::Transform; + +"#, + r#" +/// Returns the isometric part of the transformation as an [isometry]. Any scaling done by the +/// transformation will be ignored. +/// The transform is expected to be non-degenerate and without shearing, or the output +/// will be invalid. +/// [isometry]: Isometry3d + + #[lua(kind = "Method", output(proxy))] + fn to_isometry(&self) -> bevy::math::Isometry3d; + +"#, + r#" +/// Returns the [`Transform`] `self` would have if it was a child of an entity +/// with the `parent` [`GlobalTransform`]. +/// This is useful if you want to "reparent" an [`Entity`](bevy_ecs::entity::Entity). +/// Say you have an entity `e1` that you want to turn into a child of `e2`, +/// but you want `e1` to keep the same global transform, even after re-parenting. You would use: +/// ``` +/// # use bevy_transform::prelude::{GlobalTransform, Transform}; +/// # use bevy_ecs::prelude::{Entity, Query, Component, Commands}; +/// # use bevy_hierarchy::{prelude::Parent, BuildChildren}; +/// #[derive(Component)] +/// struct ToReparent { +/// new_parent: Entity, +/// } +/// fn reparent_system( +/// mut commands: Commands, +/// mut targets: Query<(&mut Transform, Entity, &GlobalTransform, &ToReparent)>, +/// transforms: Query<&GlobalTransform>, +/// ) { +/// for (mut transform, entity, initial, to_reparent) in targets.iter_mut() { +/// if let Ok(parent_transform) = transforms.get(to_reparent.new_parent) { +/// *transform = initial.reparented_to(parent_transform); +/// commands.entity(entity) +/// .remove::() +/// .set_parent(to_reparent.new_parent); +/// } +/// } +/// } +/// ``` +/// The transform is expected to be non-degenerate and without shearing, or the output +/// will be invalid. + + #[lua(kind = "Method", output(proxy))] + fn reparented_to( + &self, + #[proxy] + parent: &components::global_transform::GlobalTransform, + ) -> bevy::transform::components::Transform; + +"#, + r#" +///Return the local right vector (X). + + #[lua(kind = "Method", output(proxy))] + fn right(&self) -> bevy::math::Dir3; + +"#, + r#" +///Return the local left vector (-X). + + #[lua(kind = "Method", output(proxy))] + fn left(&self) -> bevy::math::Dir3; + +"#, + r#" +///Return the local up vector (Y). + + #[lua(kind = "Method", output(proxy))] + fn up(&self) -> bevy::math::Dir3; + +"#, + r#" +///Return the local down vector (-Y). + + #[lua(kind = "Method", output(proxy))] + fn down(&self) -> bevy::math::Dir3; + +"#, + r#" +///Return the local back vector (Z). + + #[lua(kind = "Method", output(proxy))] + fn back(&self) -> bevy::math::Dir3; + +"#, + r#" +///Return the local forward vector (-Z). + + #[lua(kind = "Method", output(proxy))] + fn forward(&self) -> bevy::math::Dir3; + +"#, + r#" +/// Get the translation as a [`Vec3`]. + + #[lua(kind = "Method", output(proxy))] + fn translation(&self) -> bevy::math::Vec3; + +"#, + r#" +/// Get the translation as a [`Vec3A`]. + + #[lua(kind = "Method", output(proxy))] + fn translation_vec3a(&self) -> bevy::math::Vec3A; + +"#, + r#" +/// Get the rotation as a [`Quat`]. +/// The transform is expected to be non-degenerate and without shearing, or the output will be invalid. +/// # Warning +/// This is calculated using `to_scale_rotation_translation`, meaning that you +/// should probably use it directly if you also need translation or scale. + + #[lua(kind = "Method", output(proxy))] + fn rotation(&self) -> bevy::math::Quat; + +"#, + r#" +/// Get the scale as a [`Vec3`]. +/// The transform is expected to be non-degenerate and without shearing, or the output will be invalid. +/// Some of the computations overlap with `to_scale_rotation_translation`, which means you should use +/// it instead if you also need rotation. + + #[lua(kind = "Method", output(proxy))] + fn scale(&self) -> bevy::math::Vec3; + +"#, + r#" +/// Get an upper bound of the radius from the given `extents`. + + #[lua(kind = "Method")] + fn radius_vec3a(&self, #[proxy] extents: bevy::math::Vec3A) -> f32; + +"#, + r#" +/// Transforms the given point from local space to global space, applying shear, scale, rotation and translation. +/// It can be used like this: +/// ``` +/// # use bevy_transform::prelude::{GlobalTransform}; +/// # use bevy_math::prelude::Vec3; +/// let global_transform = GlobalTransform::from_xyz(1., 2., 3.); +/// let local_point = Vec3::new(1., 2., 3.); +/// let global_point = global_transform.transform_point(local_point); +/// assert_eq!(global_point, Vec3::new(2., 4., 6.)); +/// ``` +/// ``` +/// # use bevy_transform::prelude::{GlobalTransform}; +/// # use bevy_math::Vec3; +/// let global_point = Vec3::new(2., 4., 6.); +/// let global_transform = GlobalTransform::from_xyz(1., 2., 3.); +/// let local_point = global_transform.affine().inverse().transform_point3(global_point); +/// assert_eq!(local_point, Vec3::new(1., 2., 3.)) +/// ``` +/// To apply shear, scale, and rotation *without* applying translation, different functions are available: +/// ``` +/// # use bevy_transform::prelude::{GlobalTransform}; +/// # use bevy_math::prelude::Vec3; +/// let global_transform = GlobalTransform::from_xyz(1., 2., 3.); +/// let local_direction = Vec3::new(1., 2., 3.); +/// let global_direction = global_transform.affine().transform_vector3(local_direction); +/// assert_eq!(global_direction, Vec3::new(1., 2., 3.)); +/// let roundtripped_local_direction = global_transform.affine().inverse().transform_vector3(global_direction); +/// assert_eq!(roundtripped_local_direction, local_direction); +/// ``` + + #[lua(kind = "Method", output(proxy))] + fn transform_point(&self, #[proxy] point: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Multiplies `self` with `transform` component by component, returning the +/// resulting [`GlobalTransform`] + + #[lua(kind = "Method", output(proxy))] + fn mul_transform( + &self, + #[proxy] + transform: bevy::transform::components::Transform, + ) -> bevy::transform::components::GlobalTransform; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul( + self, + #[proxy] + global_transform: bevy::transform::components::GlobalTransform, + ) -> bevy::transform::components::GlobalTransform; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct GlobalTransform(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::transform::components::Transform", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &components::transform::Transform) -> bool; + +"#, + r#" +/// Creates a new [`Transform`] at the position `(x, y, z)`. In 2d, the `z` component +/// is used for z-ordering elements: higher `z`-value will be in front of lower +/// `z`-value. + + #[lua(kind = "Function", output(proxy))] + fn from_xyz(x: f32, y: f32, z: f32) -> bevy::transform::components::Transform; + +"#, + r#" +/// Extracts the translation, rotation, and scale from `matrix`. It must be a 3d affine +/// transformation matrix. + + #[lua(kind = "Function", output(proxy))] + fn from_matrix( + #[proxy] + world_from_local: bevy::math::Mat4, + ) -> bevy::transform::components::Transform; + +"#, + r#" +/// Creates a new [`Transform`], with `translation`. Rotation will be 0 and scale 1 on +/// all axes. + + #[lua(kind = "Function", output(proxy))] + fn from_translation( + #[proxy] + translation: bevy::math::Vec3, + ) -> bevy::transform::components::Transform; + +"#, + r#" +/// Creates a new [`Transform`], with `rotation`. Translation will be 0 and scale 1 on +/// all axes. + + #[lua(kind = "Function", output(proxy))] + fn from_rotation( + #[proxy] + rotation: bevy::math::Quat, + ) -> bevy::transform::components::Transform; + +"#, + r#" +/// Creates a new [`Transform`], with `scale`. Translation will be 0 and rotation 0 on +/// all axes. + + #[lua(kind = "Function", output(proxy))] + fn from_scale( + #[proxy] + scale: bevy::math::Vec3, + ) -> bevy::transform::components::Transform; + +"#, + r#" +/// Creates a new [`Transform`] that is equivalent to the given [isometry]. +/// [isometry]: Isometry3d + + #[lua(kind = "Function", output(proxy))] + fn from_isometry( + #[proxy] + iso: bevy::math::Isometry3d, + ) -> bevy::transform::components::Transform; + +"#, + r#" +/// Returns this [`Transform`] with a new translation. + + #[lua(kind = "Method", output(proxy))] + fn with_translation( + self, + #[proxy] + translation: bevy::math::Vec3, + ) -> bevy::transform::components::Transform; + +"#, + r#" +/// Returns this [`Transform`] with a new rotation. + + #[lua(kind = "Method", output(proxy))] + fn with_rotation( + self, + #[proxy] + rotation: bevy::math::Quat, + ) -> bevy::transform::components::Transform; + +"#, + r#" +/// Returns this [`Transform`] with a new scale. + + #[lua(kind = "Method", output(proxy))] + fn with_scale( + self, + #[proxy] + scale: bevy::math::Vec3, + ) -> bevy::transform::components::Transform; + +"#, + r#" +/// Returns the 3d affine transformation matrix from this transforms translation, +/// rotation, and scale. + + #[lua(kind = "Method", output(proxy))] + fn compute_matrix(&self) -> bevy::math::Mat4; + +"#, + r#" +/// Returns the 3d affine transformation matrix from this transforms translation, +/// rotation, and scale. + + #[lua(kind = "Method", output(proxy))] + fn compute_affine(&self) -> bevy::math::Affine3A; + +"#, + r#" +/// Get the unit vector in the local `X` direction. + + #[lua(kind = "Method", output(proxy))] + fn local_x(&self) -> bevy::math::Dir3; + +"#, + r#" +/// Equivalent to [`-local_x()`][Transform::local_x()] + + #[lua(kind = "Method", output(proxy))] + fn left(&self) -> bevy::math::Dir3; + +"#, + r#" +/// Equivalent to [`local_x()`][Transform::local_x()] + + #[lua(kind = "Method", output(proxy))] + fn right(&self) -> bevy::math::Dir3; + +"#, + r#" +/// Get the unit vector in the local `Y` direction. + + #[lua(kind = "Method", output(proxy))] + fn local_y(&self) -> bevy::math::Dir3; + +"#, + r#" +/// Equivalent to [`local_y()`][Transform::local_y] + + #[lua(kind = "Method", output(proxy))] + fn up(&self) -> bevy::math::Dir3; + +"#, + r#" +/// Equivalent to [`-local_y()`][Transform::local_y] + + #[lua(kind = "Method", output(proxy))] + fn down(&self) -> bevy::math::Dir3; + +"#, + r#" +/// Get the unit vector in the local `Z` direction. + + #[lua(kind = "Method", output(proxy))] + fn local_z(&self) -> bevy::math::Dir3; + +"#, + r#" +/// Equivalent to [`-local_z()`][Transform::local_z] + + #[lua(kind = "Method", output(proxy))] + fn forward(&self) -> bevy::math::Dir3; + +"#, + r#" +/// Equivalent to [`local_z()`][Transform::local_z] + + #[lua(kind = "Method", output(proxy))] + fn back(&self) -> bevy::math::Dir3; + +"#, + r#" +/// Rotates this [`Transform`] by the given rotation. +/// If this [`Transform`] has a parent, the `rotation` is relative to the rotation of the parent. +/// # Examples +/// - [`3d_rotation`] +/// [`3d_rotation`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/3d_rotation.rs + + #[lua(kind = "MutatingMethod")] + fn rotate(&mut self, #[proxy] rotation: bevy::math::Quat) -> (); + +"#, + r#" +/// Rotates this [`Transform`] around the given `axis` by `angle` (in radians). +/// If this [`Transform`] has a parent, the `axis` is relative to the rotation of the parent. + + #[lua(kind = "MutatingMethod")] + fn rotate_axis(&mut self, #[proxy] axis: bevy::math::Dir3, angle: f32) -> (); + +"#, + r#" +/// Rotates this [`Transform`] around the `X` axis by `angle` (in radians). +/// If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. + + #[lua(kind = "MutatingMethod")] + fn rotate_x(&mut self, angle: f32) -> (); + +"#, + r#" +/// Rotates this [`Transform`] around the `Y` axis by `angle` (in radians). +/// If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. + + #[lua(kind = "MutatingMethod")] + fn rotate_y(&mut self, angle: f32) -> (); + +"#, + r#" +/// Rotates this [`Transform`] around the `Z` axis by `angle` (in radians). +/// If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. + + #[lua(kind = "MutatingMethod")] + fn rotate_z(&mut self, angle: f32) -> (); + +"#, + r#" +/// Rotates this [`Transform`] by the given `rotation`. +/// The `rotation` is relative to this [`Transform`]'s current rotation. + + #[lua(kind = "MutatingMethod")] + fn rotate_local(&mut self, #[proxy] rotation: bevy::math::Quat) -> (); + +"#, + r#" +/// Rotates this [`Transform`] around its local `axis` by `angle` (in radians). + + #[lua(kind = "MutatingMethod")] + fn rotate_local_axis(&mut self, #[proxy] axis: bevy::math::Dir3, angle: f32) -> (); + +"#, + r#" +/// Rotates this [`Transform`] around its local `X` axis by `angle` (in radians). + + #[lua(kind = "MutatingMethod")] + fn rotate_local_x(&mut self, angle: f32) -> (); + +"#, + r#" +/// Rotates this [`Transform`] around its local `Y` axis by `angle` (in radians). + + #[lua(kind = "MutatingMethod")] + fn rotate_local_y(&mut self, angle: f32) -> (); + +"#, + r#" +/// Rotates this [`Transform`] around its local `Z` axis by `angle` (in radians). + + #[lua(kind = "MutatingMethod")] + fn rotate_local_z(&mut self, angle: f32) -> (); + +"#, + r#" +/// Translates this [`Transform`] around a `point` in space. +/// If this [`Transform`] has a parent, the `point` is relative to the [`Transform`] of the parent. + + #[lua(kind = "MutatingMethod")] + fn translate_around( + &mut self, + #[proxy] + point: bevy::math::Vec3, + #[proxy] + rotation: bevy::math::Quat, + ) -> (); + +"#, + r#" +/// Rotates this [`Transform`] around a `point` in space. +/// If this [`Transform`] has a parent, the `point` is relative to the [`Transform`] of the parent. + + #[lua(kind = "MutatingMethod")] + fn rotate_around( + &mut self, + #[proxy] + point: bevy::math::Vec3, + #[proxy] + rotation: bevy::math::Quat, + ) -> (); + +"#, + r#" +/// Multiplies `self` with `transform` component by component, returning the +/// resulting [`Transform`] + + #[lua(kind = "Method", output(proxy))] + fn mul_transform( + &self, + #[proxy] + transform: bevy::transform::components::Transform, + ) -> bevy::transform::components::Transform; + +"#, + r#" +/// Transforms the given `point`, applying scale, rotation and translation. +/// If this [`Transform`] has an ancestor entity with a [`Transform`] component, +/// [`Transform::transform_point`] will transform a point in local space into its +/// parent transform's space. +/// If this [`Transform`] does not have a parent, [`Transform::transform_point`] will +/// transform a point in local space into worldspace coordinates. +/// If you always want to transform a point in local space to worldspace, or if you need +/// the inverse transformations, see [`GlobalTransform::transform_point()`]. + + #[lua(kind = "Method", output(proxy))] + fn transform_point(&self, #[proxy] point: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" +/// Returns `true` if, and only if, translation, rotation and scale all are +/// finite. If any of them contains a `NaN`, positive or negative infinity, +/// this will return `false`. + + #[lua(kind = "Method")] + fn is_finite(&self) -> bool; + +"#, + r#" +/// Get the [isometry] defined by this transform's rotation and translation, ignoring scale. +/// [isometry]: Isometry3d + + #[lua(kind = "Method", output(proxy))] + fn to_isometry(&self) -> bevy::math::Isometry3d; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul( + self, + #[proxy] + global_transform: bevy::transform::components::GlobalTransform, + ) -> bevy::transform::components::GlobalTransform; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::transform::components::Transform; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul(self, #[proxy] value: bevy::math::Vec3) -> bevy::math::Vec3; + +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul", + kind = "MetaFunction", + output(proxy), + composite = "mul", + metamethod = "Mul", + )] + fn mul( + self, + #[proxy] + transform: bevy::transform::components::Transform, + ) -> bevy::transform::components::Transform; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Transform { + #[lua(output(proxy))] + translation: bevy::math::Vec3, + #[lua(output(proxy))] + rotation: bevy::math::Quat, + #[lua(output(proxy))] + scale: bevy::math::Vec3, +} +#[derive(Default)] +pub(crate) struct Globals; +impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { + fn add_instances< + 'lua, + T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, + >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { + instances + .add_instance( + "GlobalTransform", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaGlobalTransform, + >::new, + )?; + instances + .add_instance( + "Transform", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + )?; + Ok(()) + } +} +pub struct BevyTransformAPIProvider; +impl bevy_mod_scripting_core::hosts::APIProvider for BevyTransformAPIProvider { + type APITarget = std::sync::Mutex; + type ScriptContext = std::sync::Mutex; + type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; + fn attach_api( + &mut self, + ctx: &mut Self::APITarget, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); + bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) + .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( + e.to_string(), + )) + } + fn get_doc_fragment(&self) -> Option { + Some( + bevy_mod_scripting_lua::docs::LuaDocFragment::new( + "BevyTransformAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaGlobalTransform, + >, + >() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaTransform, + >, + >() + }, + ), + ) + } + fn setup_script( + &mut self, + script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn setup_script_runtime( + &mut self, + world_ptr: bevy_mod_scripting_core::world::WorldPointer, + _script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn register_with_app(&self, app: &mut bevy::app::App) { + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs new file mode 100644 index 0000000000..75ee99eaa8 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs @@ -0,0 +1,1879 @@ +// @generated by cargo bevy-api-gen generate, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +use super::bevy_a11y::*; +use super::bevy_ecs::*; +use super::bevy_reflect::*; +use super::bevy_core::*; +use super::bevy_input::*; +use super::bevy_math::*; +extern crate self as bevy_script_api; +use bevy_script_api::{ + lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +}; +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::prelude::CursorEntered", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::CursorEntered) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::prelude::CursorEntered; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct CursorEntered { + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::prelude::CursorLeft", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::prelude::CursorLeft; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::CursorLeft) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct CursorLeft { + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::prelude::CursorMoved", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::CursorMoved) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::prelude::CursorMoved; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct CursorMoved { + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, + #[lua(output(proxy))] + position: bevy::math::Vec2, + delta: ReflectedValue, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::prelude::FileDragAndDrop", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::FileDragAndDrop) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::prelude::FileDragAndDrop; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct FileDragAndDrop {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::prelude::Ime", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::prelude::Ime; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::Ime) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Ime {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::prelude::MonitorSelection", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::prelude::MonitorSelection; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &window::MonitorSelection) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct MonitorSelection {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::prelude::Window", + functions[r#" +/// Setting to true will attempt to maximize the window. +/// Setting to false will attempt to un-maximize the window. + + #[lua(kind = "MutatingMethod")] + fn set_maximized(&mut self, maximized: bool) -> (); + +"#, + r#" +/// Setting to true will attempt to minimize the window. +/// Setting to false will attempt to un-minimize the window. + + #[lua(kind = "MutatingMethod")] + fn set_minimized(&mut self, minimized: bool) -> (); + +"#, + r#" +/// Calling this will attempt to start a drag-move of the window. +/// There is no guarantee that this will work unless the left mouse button was +/// pressed immediately before this function was called. + + #[lua(kind = "MutatingMethod")] + fn start_drag_move(&mut self) -> (); + +"#, + r#" +/// Calling this will attempt to start a drag-resize of the window. +/// There is no guarantee that this will work unless the left mouse button was +/// pressed immediately before this function was called. + + #[lua(kind = "MutatingMethod")] + fn start_drag_resize(&mut self, #[proxy] direction: bevy::math::CompassOctant) -> (); + +"#, + r#" +/// The window's client area width in logical pixels. +/// See [`WindowResolution`] for an explanation about logical/physical sizes. + + #[lua(kind = "Method")] + fn width(&self) -> f32; + +"#, + r#" +/// The window's client area height in logical pixels. +/// See [`WindowResolution`] for an explanation about logical/physical sizes. + + #[lua(kind = "Method")] + fn height(&self) -> f32; + +"#, + r#" +/// The window's client size in logical pixels +/// See [`WindowResolution`] for an explanation about logical/physical sizes. + + #[lua(kind = "Method", output(proxy))] + fn size(&self) -> bevy::math::Vec2; + +"#, + r#" +/// The window's client area width in physical pixels. +/// See [`WindowResolution`] for an explanation about logical/physical sizes. + + #[lua(kind = "Method")] + fn physical_width(&self) -> u32; + +"#, + r#" +/// The window's client area height in physical pixels. +/// See [`WindowResolution`] for an explanation about logical/physical sizes. + + #[lua(kind = "Method")] + fn physical_height(&self) -> u32; + +"#, + r#" +/// The window's client size in physical pixels +/// See [`WindowResolution`] for an explanation about logical/physical sizes. + + #[lua(kind = "Method", output(proxy))] + fn physical_size(&self) -> bevy::math::UVec2; + +"#, + r#" +/// The window's scale factor. +/// Ratio of physical size to logical size, see [`WindowResolution`]. + + #[lua(kind = "Method")] + fn scale_factor(&self) -> f32; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::prelude::Window; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Window { + #[lua(output(proxy))] + cursor_options: bevy::window::CursorOptions, + #[lua(output(proxy))] + present_mode: bevy::window::PresentMode, + #[lua(output(proxy))] + mode: bevy::window::WindowMode, + #[lua(output(proxy))] + position: bevy::window::prelude::WindowPosition, + #[lua(output(proxy))] + resolution: bevy::window::WindowResolution, + title: std::string::String, + name: std::option::Option, + #[lua(output(proxy))] + composite_alpha_mode: bevy::window::CompositeAlphaMode, + #[lua(output(proxy))] + resize_constraints: bevy::window::prelude::WindowResizeConstraints, + resizable: bool, + #[lua(output(proxy))] + enabled_buttons: bevy::window::EnabledButtons, + decorations: bool, + transparent: bool, + focused: bool, + #[lua(output(proxy))] + window_level: bevy::window::WindowLevel, + canvas: std::option::Option, + fit_canvas_to_parent: bool, + prevent_default_event_handling: bool, + #[lua(output(proxy))] + internal: bevy::window::InternalWindowState, + ime_enabled: bool, + #[lua(output(proxy))] + ime_position: bevy::math::Vec2, + window_theme: ReflectedValue, + visible: bool, + skip_taskbar: bool, + desired_maximum_frame_latency: ReflectedValue, + recognize_pinch_gesture: bool, + recognize_rotation_gesture: bool, + recognize_doubletap_gesture: bool, + recognize_pan_gesture: ReflectedValue, + movable_by_window_background: bool, + fullsize_content_view: bool, + has_shadow: bool, + titlebar_shown: bool, + titlebar_transparent: bool, + titlebar_show_title: bool, + titlebar_show_buttons: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::prelude::WindowMoved", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::WindowMoved) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::prelude::WindowMoved; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowMoved { + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, + #[lua(output(proxy))] + position: bevy::math::IVec2, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::prelude::WindowPosition", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::prelude::WindowPosition; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &window::WindowPosition) -> bool; + +"#, + r#" +/// Creates a new [`WindowPosition`] at a position. + + #[lua(kind = "Function", output(proxy))] + fn new( + #[proxy] + position: bevy::math::IVec2, + ) -> bevy::window::prelude::WindowPosition; + +"#, + r#" +/// Set the position to a specific point. + + #[lua(kind = "MutatingMethod")] + fn set(&mut self, #[proxy] position: bevy::math::IVec2) -> (); + +"#, + r#" +/// Set the window to a specific monitor. + + #[lua(kind = "MutatingMethod")] + fn center( + &mut self, + #[proxy] + monitor: bevy::window::prelude::MonitorSelection, + ) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowPosition {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::prelude::WindowResizeConstraints", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::prelude::WindowResizeConstraints; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &window::WindowResizeConstraints) -> bool; + +"#, + r#" +/// Checks if the constraints are valid. +/// Will output warnings if it isn't. + + #[lua(kind = "Method", output(proxy))] + fn check_constraints(&self) -> bevy::window::prelude::WindowResizeConstraints; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowResizeConstraints { + min_width: f32, + min_height: f32, + max_width: f32, + max_height: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowEvent", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::WindowEvent) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowEvent; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowEvent {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowResized", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowResized; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::WindowResized) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowResized { + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, + width: f32, + height: f32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowCreated", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowCreated; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::WindowCreated) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowCreated { + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowClosing", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowClosing; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::WindowClosing) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowClosing { + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowClosed", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowClosed; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::WindowClosed) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowClosed { + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowCloseRequested", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowCloseRequested; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::WindowCloseRequested) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowCloseRequested { + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowDestroyed", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::WindowDestroyed) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowDestroyed; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowDestroyed { + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::RequestRedraw", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::RequestRedraw; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::RequestRedraw) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct RequestRedraw {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowFocused", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::WindowFocused) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowFocused; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowFocused { + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, + focused: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowOccluded", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::WindowOccluded) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowOccluded; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowOccluded { + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, + occluded: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowScaleFactorChanged", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::WindowScaleFactorChanged) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowScaleFactorChanged; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowScaleFactorChanged { + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, + scale_factor: f64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowBackendScaleFactorChanged", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowBackendScaleFactorChanged; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::WindowBackendScaleFactorChanged) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowBackendScaleFactorChanged { + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, + scale_factor: f64, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowThemeChanged", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::WindowThemeChanged) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowThemeChanged; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowThemeChanged { + #[lua(output(proxy))] + window: bevy::ecs::entity::Entity, + #[lua(output(proxy))] + theme: bevy::window::WindowTheme, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::AppLifecycle", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::AppLifecycle; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &event::AppLifecycle) -> bool; + +"#, + r#" +/// Return `true` if the app can be updated. + + #[lua(kind = "Method")] + fn is_active(&self) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct AppLifecycle {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::PrimaryWindow", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &window::PrimaryWindow) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::PrimaryWindow; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct PrimaryWindow {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowTheme", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &window::WindowTheme) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowTheme; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowTheme {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::Monitor", + functions[r#" +/// Returns the physical size of the monitor in pixels + + #[lua(kind = "Method", output(proxy))] + fn physical_size(&self) -> bevy::math::UVec2; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::Monitor; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct Monitor { + name: std::option::Option, + physical_height: u32, + physical_width: u32, + #[lua(output(proxy))] + physical_position: bevy::math::IVec2, + refresh_rate_millihertz: std::option::Option, + scale_factor: f64, + video_modes: ReflectedValue, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::VideoMode", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::VideoMode; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct VideoMode { + #[lua(output(proxy))] + physical_size: bevy::math::UVec2, + bit_depth: u16, + refresh_rate_millihertz: u32, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::PrimaryMonitor", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::PrimaryMonitor; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct PrimaryMonitor {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::SystemCursorIcon", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::SystemCursorIcon; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &system_cursor::SystemCursorIcon) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct SystemCursorIcon {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowRef", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowRef; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowRef {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::NormalizedWindowRef", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::NormalizedWindowRef; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +/// Fetch the entity of this window reference + + #[lua(kind = "Method", output(proxy))] + fn entity(&self) -> bevy::ecs::entity::Entity; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &window::NormalizedWindowRef) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct NormalizedWindowRef(); +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::CursorOptions", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::CursorOptions; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct CursorOptions { + visible: bool, + #[lua(output(proxy))] + grab_mode: bevy::window::CursorGrabMode, + hit_test: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::PresentMode", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::PresentMode; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &window::PresentMode) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct PresentMode {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowMode", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &window::WindowMode) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowMode; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowMode {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowResolution", + functions[r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowResolution; + +"#, + r#" +/// Creates a new [`WindowResolution`]. + + #[lua(kind = "Function", output(proxy))] + fn new(physical_width: f32, physical_height: f32) -> bevy::window::WindowResolution; + +"#, + r#" +/// Builder method for adding a scale factor override to the resolution. + + #[lua(kind = "Method", output(proxy))] + fn with_scale_factor_override( + self, + scale_factor_override: f32, + ) -> bevy::window::WindowResolution; + +"#, + r#" +/// The window's client area width in logical pixels. + + #[lua(kind = "Method")] + fn width(&self) -> f32; + +"#, + r#" +/// The window's client area height in logical pixels. + + #[lua(kind = "Method")] + fn height(&self) -> f32; + +"#, + r#" +/// The window's client size in logical pixels + + #[lua(kind = "Method", output(proxy))] + fn size(&self) -> bevy::math::Vec2; + +"#, + r#" +/// The window's client area width in physical pixels. + + #[lua(kind = "Method")] + fn physical_width(&self) -> u32; + +"#, + r#" +/// The window's client area height in physical pixels. + + #[lua(kind = "Method")] + fn physical_height(&self) -> u32; + +"#, + r#" +/// The window's client size in physical pixels + + #[lua(kind = "Method", output(proxy))] + fn physical_size(&self) -> bevy::math::UVec2; + +"#, + r#" +/// The ratio of physical pixels to logical pixels. +/// `physical_pixels = logical_pixels * scale_factor` + + #[lua(kind = "Method")] + fn scale_factor(&self) -> f32; + +"#, + r#" +/// The window scale factor as reported by the window backend. +/// This value is unaffected by [`WindowResolution::scale_factor_override`]. + + #[lua(kind = "Method")] + fn base_scale_factor(&self) -> f32; + +"#, + r#" +/// The scale factor set with [`WindowResolution::set_scale_factor_override`]. +/// This value may be different from the scale factor reported by the window backend. + + #[lua(kind = "Method")] + fn scale_factor_override(&self) -> std::option::Option; + +"#, + r#" +/// Set the window's logical resolution. + + #[lua(kind = "MutatingMethod")] + fn set(&mut self, width: f32, height: f32) -> (); + +"#, + r#" +/// Set the window's physical resolution. +/// This will ignore the scale factor setting, so most of the time you should +/// prefer to use [`WindowResolution::set`]. + + #[lua(kind = "MutatingMethod")] + fn set_physical_resolution(&mut self, width: u32, height: u32) -> (); + +"#, + r#" +/// Set the window's scale factor, this may get overridden by the backend. + + #[lua(kind = "MutatingMethod")] + fn set_scale_factor(&mut self, scale_factor: f32) -> (); + +"#, + r#" +/// Set the window's scale factor, and apply it to the currently known physical size. +/// This may get overridden by the backend. This is mostly useful on window creation, +/// so that the window is created with the expected size instead of waiting for a resize +/// event after its creation. + + #[lua(kind = "MutatingMethod")] + fn set_scale_factor_and_apply_to_physical_size(&mut self, scale_factor: f32) -> (); + +"#, + r#" +/// Set the window's scale factor, this will be used over what the backend decides. +/// This can change the logical and physical sizes if the resulting physical +/// size is not within the limits. + + #[lua(kind = "MutatingMethod")] + fn set_scale_factor_override( + &mut self, + scale_factor_override: std::option::Option, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &window::WindowResolution) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowResolution {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::CompositeAlphaMode", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &window::CompositeAlphaMode) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::CompositeAlphaMode; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct CompositeAlphaMode {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::EnabledButtons", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &window::EnabledButtons) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::EnabledButtons; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct EnabledButtons { + minimize: bool, + maximize: bool, + close: bool, +} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::WindowLevel", + functions[r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &window::WindowLevel) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::WindowLevel; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct WindowLevel {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::InternalWindowState", + functions[r#" +/// Consumes the current maximize request, if it exists. This should only be called by window backends. + + #[lua(kind = "MutatingMethod")] + fn take_maximize_request(&mut self) -> std::option::Option; + +"#, + r#" +/// Consumes the current minimize request, if it exists. This should only be called by window backends. + + #[lua(kind = "MutatingMethod")] + fn take_minimize_request(&mut self) -> std::option::Option; + +"#, + r#" +/// Consumes the current move request, if it exists. This should only be called by window backends. + + #[lua(kind = "MutatingMethod")] + fn take_move_request(&mut self) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::InternalWindowState; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &window::InternalWindowState) -> bool; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct InternalWindowState {} +#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[proxy( + derive(clone), + remote = "bevy::window::CursorGrabMode", + functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq", + kind = "MetaFunction", + composite = "eq", + metamethod = "Eq", + )] + fn eq(&self, #[proxy] other: &window::CursorGrabMode) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq", kind = "Method")] + fn assert_receiver_is_total_eq(&self) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] + fn clone(&self) -> bevy::window::CursorGrabMode; + +"#, + r#" +#[lua(kind="MetaMethod", metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +struct CursorGrabMode {} +#[derive(Default)] +pub(crate) struct Globals; +impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { + fn add_instances< + 'lua, + T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, + >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { + instances + .add_instance( + "WindowPosition", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaWindowPosition, + >::new, + )?; + instances + .add_instance( + "WindowResolution", + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< + LuaWindowResolution, + >::new, + )?; + Ok(()) + } +} +pub struct BevyWindowAPIProvider; +impl bevy_mod_scripting_core::hosts::APIProvider for BevyWindowAPIProvider { + type APITarget = std::sync::Mutex; + type ScriptContext = std::sync::Mutex; + type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; + fn attach_api( + &mut self, + ctx: &mut Self::APITarget, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); + bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) + .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( + e.to_string(), + )) + } + fn get_doc_fragment(&self) -> Option { + Some( + bevy_mod_scripting_lua::docs::LuaDocFragment::new( + "BevyWindowAPI", + |tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaWindowPosition, + >, + >() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::< + bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< + LuaWindowResolution, + >, + >() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + }, + ), + ) + } + fn setup_script( + &mut self, + script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn setup_script_runtime( + &mut self, + world_ptr: bevy_mod_scripting_core::world::WorldPointer, + _script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn register_with_app(&self, app: &mut bevy::app::App) { + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::< + bevy::window::prelude::WindowResizeConstraints, + >(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/mod.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/mod.rs new file mode 100644 index 0000000000..b0ca5e66d0 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/mod.rs @@ -0,0 +1,88 @@ +// @generated by cargo bevy-api-gen collect, modify the templates not this file +#![allow(clippy::all)] +#![allow(unused, deprecated, dead_code)] +#![cfg_attr(rustfmt, rustfmt_skip)] +pub mod bevy_a11y; +pub mod bevy_ecs; +pub mod bevy_transform; +pub mod bevy_math; +pub mod bevy_input; +pub mod bevy_core; +pub mod bevy_time; +pub mod bevy_hierarchy; +pub mod bevy_window; +pub mod bevy_reflect; +extern crate self as bevy_script_api; +use bevy_mod_scripting_core::docs::DocFragment; +pub struct LuaBevyAPIProvider; +impl bevy_mod_scripting_core::hosts::APIProvider for LuaBevyAPIProvider { + type APITarget = std::sync::Mutex; + type ScriptContext = std::sync::Mutex; + type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; + fn attach_api( + &mut self, + ctx: &mut Self::APITarget, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + bevy_a11y::BevyA11YAPIProvider.attach_api(ctx)?; + bevy_ecs::BevyEcsAPIProvider.attach_api(ctx)?; + bevy_transform::BevyTransformAPIProvider.attach_api(ctx)?; + bevy_math::BevyMathAPIProvider.attach_api(ctx)?; + bevy_input::BevyInputAPIProvider.attach_api(ctx)?; + bevy_core::BevyCoreAPIProvider.attach_api(ctx)?; + bevy_time::BevyTimeAPIProvider.attach_api(ctx)?; + bevy_hierarchy::BevyHierarchyAPIProvider.attach_api(ctx)?; + bevy_window::BevyWindowAPIProvider.attach_api(ctx)?; + bevy_reflect::BevyReflectAPIProvider.attach_api(ctx)?; + Ok(()) + } + fn get_doc_fragment(&self) -> Option { + [ + bevy_a11y::BevyA11YAPIProvider.get_doc_fragment(), + bevy_ecs::BevyEcsAPIProvider.get_doc_fragment(), + bevy_transform::BevyTransformAPIProvider.get_doc_fragment(), + bevy_math::BevyMathAPIProvider.get_doc_fragment(), + bevy_input::BevyInputAPIProvider.get_doc_fragment(), + bevy_core::BevyCoreAPIProvider.get_doc_fragment(), + bevy_time::BevyTimeAPIProvider.get_doc_fragment(), + bevy_hierarchy::BevyHierarchyAPIProvider.get_doc_fragment(), + bevy_window::BevyWindowAPIProvider.get_doc_fragment(), + bevy_reflect::BevyReflectAPIProvider.get_doc_fragment(), + ] + .into_iter() + .filter_map(|a: Option<_>| a) + .fold( + None, + |a, b| match a { + Some(a) => Some(a.merge(b)), + None => Some(b), + }, + ) + } + fn setup_script( + &mut self, + script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn setup_script_runtime( + &mut self, + world_ptr: bevy_mod_scripting_core::world::WorldPointer, + _script_data: &bevy_mod_scripting_core::hosts::ScriptData, + ctx: &mut Self::ScriptContext, + ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + Ok(()) + } + fn register_with_app(&self, app: &mut bevy::app::App) { + bevy_a11y::BevyA11YAPIProvider.register_with_app(app); + bevy_ecs::BevyEcsAPIProvider.register_with_app(app); + bevy_transform::BevyTransformAPIProvider.register_with_app(app); + bevy_math::BevyMathAPIProvider.register_with_app(app); + bevy_input::BevyInputAPIProvider.register_with_app(app); + bevy_core::BevyCoreAPIProvider.register_with_app(app); + bevy_time::BevyTimeAPIProvider.register_with_app(app); + bevy_hierarchy::BevyHierarchyAPIProvider.register_with_app(app); + bevy_window::BevyWindowAPIProvider.register_with_app(app); + bevy_reflect::BevyReflectAPIProvider.register_with_app(app); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/lib.rs b/crates/languages/bevy_mod_scripting_lua/src/lib.rs index d356fade06..7a5dc2990b 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/lib.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/lib.rs @@ -1,197 +1,255 @@ -use crate::{ - assets::{LuaFile, LuaLoader}, - docs::LuaDocFragment, -}; -use bevy::{ecs::schedule::ScheduleLabel, prelude::*}; -use bevy_mod_scripting_core::{prelude::*, systems::*, world::WorldPointerGuard}; - -use std::fmt; -use std::marker::PhantomData; -use std::sync::Mutex; -use tealr::mlu::mlua::{prelude::*, Function}; - pub mod assets; pub mod docs; pub mod util; +use bevy::{ + app::{App, Plugin}, + ecs::{entity::Entity, world::World}, + reflect::{FromType, GetTypeRegistration, Reflect, TypePath}, +}; +use bevy_mod_scripting_core::{ + bindings::{ReflectReference, WorldCallbackAccess}, + context::{ContextBuilder, ContextInitializer, ContextPreHandlingInitializer}, + error::ScriptError, + event::CallbackLabel, + handler::Args, + script::ScriptId, + ScriptingPlugin, +}; +use bindings::{proxy::LuaProxied, world::LuaWorld}; pub use tealr; +pub mod bindings; +use tealr::mlu::mlua::{FromLua, Function, IntoLua, IntoLuaMulti, Lua, Value}; + pub mod prelude { - pub use crate::{ - assets::{LuaFile, LuaLoader}, - docs::{LuaDocFragment, TypeWalkerBuilder}, - tealr::{ - self, - mlu::{ - mlua::{self, prelude::*, Value}, - TealData, - }, + pub use crate::tealr::{ + self, + mlu::{ + mlua::{self, prelude::*, Value}, + TealData, }, - LuaEvent, LuaScriptHost, }; } -pub trait LuaArg: for<'lua> IntoLuaMulti<'lua> + Clone + Sync + Send + 'static {} - -impl IntoLuaMulti<'lua> + Clone + Sync + Send + 'static> LuaArg for T {} +pub trait LuaEventArg: Args + for<'l> IntoLuaMulti<'l> {} +impl IntoLuaMulti<'l>> LuaEventArg for T {} -#[derive(Clone, Event)] -/// A Lua Hook. The result of creating this event will be -/// a call to the lua script with the hook_name and the given arguments -pub struct LuaEvent { - pub hook_name: String, - pub args: A, - pub recipients: Recipients, +pub struct LuaScriptingPlugin IntoLuaMulti<'l>> { + pub scripting_plugin: ScriptingPlugin, } -impl fmt::Debug for LuaEvent { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("LuaEvent") - .field("hook_name", &self.hook_name) - .field("recipients", &self.recipients) - .finish() +impl Default for LuaScriptingPlugin { + fn default() -> Self { + LuaScriptingPlugin { + scripting_plugin: ScriptingPlugin { + context_assigner: None, + runtime_builder: None, + callback_handler: Some(lua_handler::), + context_builder: Some(ContextBuilder:: { + load: lua_context_load, + reload: lua_context_reload, + }), + }, + } } } -impl ScriptEvent for LuaEvent { - fn recipients(&self) -> &crate::Recipients { - &self.recipients +impl Plugin for LuaScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + self.scripting_plugin.build(app); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); } } -#[derive(Resource)] -/// Lua script host, enables Lua scripting. -pub struct LuaScriptHost { - _ph: PhantomData, +pub fn lua_context_load( + script_id: &ScriptId, + content: &[u8], + initializers: &[ContextInitializer], + pre_handling_initializers: &[ContextPreHandlingInitializer], + world: &mut World, + _: &mut (), +) -> Result { + #[cfg(feature = "unsafe_lua_modules")] + let context = unsafe { Lua::unsafe_new() }; + #[cfg(not(feature = "unsafe_lua_modules"))] + let mut context = Lua::new(); + + with_world(world, &mut context, |context| { + initializers + .iter() + .try_for_each(|init| init(script_id, context))?; + + pre_handling_initializers + .iter() + .try_for_each(|init| init(script_id, Entity::from_raw(0), context))?; + + context.load(content).exec()?; + Ok(()) + })?; + + Ok(context) } -impl Default for LuaScriptHost { - fn default() -> Self { - Self { - _ph: Default::default(), - } - } +pub fn lua_context_reload( + script: &ScriptId, + content: &[u8], + old_ctxt: &mut Lua, + initializers: &[ContextInitializer], + pre_handling_initializers: &[ContextPreHandlingInitializer], + world: &mut World, + _: &mut (), +) -> Result<(), ScriptError> { + *old_ctxt = lua_context_load( + script, + content, + initializers, + pre_handling_initializers, + world, + &mut (), + )?; + Ok(()) } -impl ScriptHost for LuaScriptHost { - type ScriptContext = Mutex; - type APITarget = Mutex; - type ScriptEvent = LuaEvent; - type ScriptAsset = LuaFile; - type DocTarget = LuaDocFragment; - - fn register_with_app_in_set(app: &mut App, schedule: impl ScheduleLabel, set: impl SystemSet) { - app.add_priority_event::() - .init_asset::() - .init_asset_loader::() - .init_resource::>() - .init_resource::>() - .init_resource::>() - .register_type::>() - .register_type::>() - .register_type::>() - // handle script insertions removal first - // then update their contexts later on script asset changes - .add_systems( - schedule, - ( - script_add_synchronizer::, - script_remove_synchronizer::, - script_hot_reload_handler::, - ) - .chain() - .in_set(set), - ); - } +#[allow(clippy::too_many_arguments)] +pub fn lua_handler IntoLuaMulti<'l>>( + args: A, + entity: bevy::ecs::entity::Entity, + script_id: &ScriptId, + callback_label: &CallbackLabel, + context: &mut Lua, + pre_handling_initializers: &[ContextPreHandlingInitializer], + _: &mut (), + world: &mut bevy::ecs::world::World, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + with_world(world, context, |context| { + pre_handling_initializers + .iter() + .try_for_each(|init| init(script_id, entity, context))?; + + let handler: Function = match context.globals().raw_get(callback_label.as_ref()) { + Ok(handler) => handler, + // not subscribed to this event type + Err(_) => return Ok(()), + }; + + handler.call::<_, ()>(args)?; + Ok(()) + }) +} + +/// Safely scopes world access for a lua context to the given closure's scope +pub fn with_world Result<(), ScriptError>>( + world: &mut World, + context: &mut Lua, + f: F, +) -> Result<(), ScriptError> { + WorldCallbackAccess::with_callback_access(world, |guard| { + context.globals().set("world", LuaWorld(guard.clone()))?; + // TODO set entity + script id as well + f(context) + }) +} - fn load_script( +/// Registers a lua proxy object via the reflection system +pub trait RegisterLua { + fn register_lua_proxy( &mut self, - script: &[u8], - script_data: &ScriptData, - providers: &mut APIProviders, - ) -> Result { - #[cfg(feature = "unsafe_lua_modules")] - let lua = unsafe { Lua::unsafe_new() }; - #[cfg(not(feature = "unsafe_lua_modules"))] - let lua = Lua::new(); - - // init lua api before loading script - let mut lua = Mutex::new(lua); - providers.attach_all(&mut lua)?; - - lua.get_mut() - .map_err(|e| ScriptError::FailedToLoad { - script: script_data.name.to_owned(), - msg: e.to_string(), - })? - .load(script) - .set_name(script_data.name) - .exec() - .map_err(|e| ScriptError::FailedToLoad { - script: script_data.name.to_owned(), - msg: e.to_string(), - })?; - - Ok(lua) - } + ) -> &mut Self + where + T::Proxy: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, + T::Proxy: From + AsRef; - fn setup_script( + fn register_lua_value( &mut self, - script_data: &ScriptData, - ctx: &mut Self::ScriptContext, - providers: &mut APIProviders, - ) -> Result<(), ScriptError> { - providers.setup_all(script_data, ctx) + ) -> &mut Self + where + T: for<'l> IntoLua<'l> + for<'l> FromLua<'l>; +} + +impl RegisterLua for App { + fn register_lua_proxy( + &mut self, + ) -> &mut Self + where + T::Proxy: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, + T::Proxy: From + AsRef, + { + self.register_type::(); + self.register_type_data::() } - fn handle_events<'a>( + fn register_lua_value( &mut self, - world: &mut World, - events: &[Self::ScriptEvent], - ctxs: impl Iterator, &'a mut Self::ScriptContext)>, - providers: &mut APIProviders, - ) { - // safety: - // - we have &mut World access - // - we do not use the original reference again anywhere in this function - let world = unsafe { WorldPointerGuard::new(world) }; - - ctxs.for_each(|(script_data, ctx)| { - providers - .setup_runtime_all(world.clone(), &script_data, ctx) - .expect("Could not setup script runtime"); - - let ctx = ctx.get_mut().expect("Poison error in context"); - - // event order is preserved, but scripts can't rely on any temporal - // guarantees when it comes to other scripts callbacks, - // at least for now. - let globals = ctx.globals(); - for event in events { - // check if this script should handle this event - if !event.recipients().is_recipient(&script_data) { - continue; - } - - let f: Function = match globals.raw_get(event.hook_name.clone()) { - Ok(f) => f, - Err(_) => continue, // not subscribed to this event - }; - - if let Err(error) = f.call::<_, ()>(event.args.clone()) { - let mut world = world.write(); - let mut state: CachedScriptState = world.remove_resource().unwrap(); - - let (_, mut error_wrt, _) = state.event_state.get_mut(&mut world); - - let error = ScriptError::RuntimeError { - script: script_data.name.to_owned(), - msg: error.to_string(), - }; - - error!("{}", error); - error_wrt.send(ScriptErrorEvent { error }); - world.insert_resource(state); - } - } - }); + ) -> &mut Self + where + T: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, + { + self.register_type::(); + self.register_type_data::() + } +} + +/// Stores the procedure used to convert a lua value to a reflect value and vice versa, Used for types which are represented in lua via proxies which store +/// a reference to the actual value. +/// This is used for types which are represented in lua with pass by reference semantics +#[derive(Clone)] +pub struct ReflectLuaProxied { + pub into_proxy: + for<'l> fn(ReflectReference, &'l Lua) -> Result, tealr::mlu::mlua::Error>, + pub from_proxy: + for<'l> fn(Value<'l>, &'l Lua) -> Result, +} + +impl FromType for ReflectLuaProxied +where + T::Proxy: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, + T::Proxy: From + AsRef, +{ + fn from_type() -> Self { + Self { + into_proxy: |p, l| T::Proxy::from(p).into_lua(l), + from_proxy: |v, l| T::Proxy::from_lua(v, l).map(|p| p.as_ref().clone()), + } + } +} + +/// Stores the procedure used to convert a lua value to a reflect value and vice versa, Used for types which are represented directly in lua with +/// pass by value semantics, These need to implement [`Clone`] +#[derive(Clone)] +pub struct ReflectLuaValue { + pub into_value: for<'l> fn(&dyn Reflect, &'l Lua) -> Result, tealr::mlu::mlua::Error>, + pub set_value: + for<'l> fn(&mut dyn Reflect, Value<'l>, &'l Lua) -> Result<(), tealr::mlu::mlua::Error>, + pub from_value: + for<'l> fn(Value<'l>, &'l Lua) -> Result, tealr::mlu::mlua::Error>, +} + +impl IntoLua<'l> + for<'l> FromLua<'l>> FromType + for ReflectLuaValue +{ + fn from_type() -> Self { + Self { + into_value: |v, l| v.downcast_ref::().unwrap().clone().into_lua(l), + set_value: |t, v, l| { + let mut t = t.downcast_mut::().unwrap(); + *t = T::from_lua(v, l)?; + Ok(()) + }, + from_value: |v, l| T::from_lua(v, l).map(|v| Box::new(v) as Box), + } } } diff --git a/makefile b/makefile index fdd2efe86c..a381dd3221 100644 --- a/makefile +++ b/makefile @@ -28,7 +28,7 @@ CODEGEN_PATH=${PWD}/target/codegen BEVY_PATH=${CODEGEN_PATH}/bevy GLAM_PATH=${CODEGEN_PATH}/glam OUTPUT_PATH=${CODEGEN_PATH}/output -GENERATED_SRC_PATH=./crates/bevy_script_api/src/providers +GENERATED_SRC_PATH=./crates/languages/bevy_mod_scripting_lua/src/bindings/providers GEN_BEVY_FEATURES=bevy_asset,bevy_gltf,bevy_animation,bevy_core_pipeline,bevy_ui,bevy_pbr,bevy_render,bevy_text,bevy_sprite,file_watcher,multi_threaded build_test_in_package: @@ -61,10 +61,10 @@ clean_bevy: cd ${BEVY_PATH} && cargo clean generate_bevy: - cd ${BEVY_PATH} && cargo +${NIGHTLY_VERSION} bevy-api-gen generate --output ${OUTPUT_PATH} --template-args '{ "self_is_bevy_script_api": true}' --features ${GEN_BEVY_FEATURES} -vv + cd ${BEVY_PATH} && cargo +${NIGHTLY_VERSION} bevy-api-gen generate --output ${OUTPUT_PATH} --template-args '{ "self_is_bms_lua": true}' --features ${GEN_BEVY_FEATURES} -vv collect_bevy: - cd ${BEVY_PATH} && cargo +${NIGHTLY_VERSION} bevy-api-gen collect --output ${OUTPUT_PATH} --template-args '{ "self_is_bevy_script_api": true}' -vv + cd ${BEVY_PATH} && cargo +${NIGHTLY_VERSION} bevy-api-gen collect --output ${OUTPUT_PATH} --template-args '{ "self_is_bms_lua": true}' -vv deletion_confirmation: @echo -n "This action will delete ALL files in directories: '${GENERATED_SRC_PATH}' amd ${OUTPUT_PATH} (y/N) " From 44f66c3e39dc9aa4fe4b38c3bfb8015aa43ee33a Mon Sep 17 00:00:00 2001 From: makspll Date: Sun, 10 Nov 2024 19:02:27 +0000 Subject: [PATCH 03/22] don't check for all std traits being present --- .../bevy_api_gen/src/passes/cache_traits.rs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/bevy_api_gen/src/passes/cache_traits.rs b/crates/bevy_api_gen/src/passes/cache_traits.rs index bdbd956815..c0c36b058b 100644 --- a/crates/bevy_api_gen/src/passes/cache_traits.rs +++ b/crates/bevy_api_gen/src/passes/cache_traits.rs @@ -57,21 +57,21 @@ pub(crate) fn cache_traits(ctxt: &mut BevyCtxt<'_>, _args: &Args) -> bool { log::trace!("has_std: {}", has_std); - if has_std && !ctxt.cached_traits.has_all_std_source_traits() { - log::debug!( - "all traits: {}", - tcx.all_traits() - .map(|t| tcx.def_path_str(t).to_string()) - .collect::>() - .join(", ") - ); + // if has_std && !ctxt.cached_traits.has_all_std_source_traits() { + // log::debug!( + // "all traits: {}", + // tcx.all_traits() + // .map(|t| tcx.def_path_str(t).to_string()) + // .collect::>() + // .join(", ") + // ); - panic!( - "Could not find traits: [{}] in crate: {}, did bootstrapping go wrong?", - ctxt.cached_traits.missing_std_source_traits().join(", "), - tcx.crate_name(LOCAL_CRATE) - ) - } + // panic!( + // "Could not find traits: [{}] in crate: {}, did bootstrapping go wrong?", + // ctxt.cached_traits.missing_std_source_traits().join(", "), + // tcx.crate_name(LOCAL_CRATE) + // ) + // } true } From 1a783f30ec18c8db04100181761f0798f3777819 Mon Sep 17 00:00:00 2001 From: makspll Date: Sun, 10 Nov 2024 23:12:37 +0000 Subject: [PATCH 04/22] bring in bms_lua changes --- crates/bevy_api_gen/src/args.rs | 1 + crates/bevy_api_gen/src/context.rs | 3 +- crates/bevy_api_gen/templates/footer.tera | 2 +- crates/bevy_api_gen/templates/header.tera | 4 +- crates/bevy_api_gen/templates/item.tera | 2 +- crates/bevy_api_gen/templates/macros.tera | 10 +- crates/bevy_mod_scripting_derive/Cargo.toml | 31 + crates/bevy_mod_scripting_derive/readme.md | 3 + crates/bevy_mod_scripting_derive/src/input.rs | 115 + crates/bevy_mod_scripting_derive/src/lib.rs | 531 + crates/bevy_mod_scripting_derive/src/utils.rs | 59 + .../bevy_mod_scripting_lua/Cargo.toml | 4 + .../bevy_mod_scripting_lua/src/assets.rs | 284 +- .../src/bindings/mod.rs | 5 + .../src/bindings/providers/bevy_a11y.rs | 85 +- .../src/bindings/providers/bevy_core.rs | 98 +- .../src/bindings/providers/bevy_ecs.rs | 431 +- .../src/bindings/providers/bevy_hierarchy.rs | 156 +- .../src/bindings/providers/bevy_input.rs | 1573 +- .../src/bindings/providers/bevy_math.rs | 4439 ++-- .../src/bindings/providers/bevy_reflect.rs | 17909 ++++++++-------- .../src/bindings/providers/bevy_time.rs | 463 +- .../src/bindings/providers/bevy_transform.rs | 751 +- .../src/bindings/providers/bevy_window.rs | 1564 +- .../src/bindings/providers/mod.rs | 105 +- .../src/bindings/proxy.rs | 189 + .../src/bindings/reference.rs | 428 + .../src/bindings/std.rs | 39 + .../src/bindings/type_registration.rs | 27 + .../src/bindings/world.rs | 131 + .../bevy_mod_scripting_lua/src/docs.rs | 113 +- .../bevy_mod_scripting_lua/src/lib.rs | 32 +- .../bevy_mod_scripting_lua/src/util.rs | 45 + 33 files changed, 15203 insertions(+), 14429 deletions(-) create mode 100644 crates/bevy_mod_scripting_derive/Cargo.toml create mode 100644 crates/bevy_mod_scripting_derive/readme.md create mode 100644 crates/bevy_mod_scripting_derive/src/input.rs create mode 100644 crates/bevy_mod_scripting_derive/src/lib.rs create mode 100644 crates/bevy_mod_scripting_derive/src/utils.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/std.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/type_registration.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs diff --git a/crates/bevy_api_gen/src/args.rs b/crates/bevy_api_gen/src/args.rs index 63898dc098..69ff5294fe 100644 --- a/crates/bevy_api_gen/src/args.rs +++ b/crates/bevy_api_gen/src/args.rs @@ -112,6 +112,7 @@ fn default_ignored_types() -> String { "bevy_reflect::DynamicTuple", "bevy_reflect::DynamicTupleStruct", "bevy_reflect::DynamicEnum", + "bevy_reflect::DynamicSet", "bevy_reflect::OsString", // TODO: once macros allow Vecs for primitives as args remove this from ignored types ] .join(",") diff --git a/crates/bevy_api_gen/src/context.rs b/crates/bevy_api_gen/src/context.rs index 83ed871bbb..baa33448a1 100644 --- a/crates/bevy_api_gen/src/context.rs +++ b/crates/bevy_api_gen/src/context.rs @@ -83,7 +83,8 @@ impl ReflectType<'_> { pub(crate) const DEF_PATHS_FROM_LUA: [&str; 2] = ["value::FromLuaMulti", "mlua::FromLuaMulti"]; pub(crate) const DEF_PATHS_INTO_LUA: [&str; 2] = ["value::IntoLuaMulti", "mlua::IntoLuaMulti"]; -pub(crate) const DEF_PATHS_REFLECT: [&str; 2] = ["bevy_reflect::Reflect", "reflect::Reflect"]; +pub(crate) const DEF_PATHS_REFLECT: [&str; 2] = + ["bevy_reflect::PartialReflect", "reflect::PartialReflect"]; pub(crate) const DEF_PATHS_GET_TYPE_REGISTRATION: [&str; 2] = [ "bevy_reflect::GetTypeRegistration", "reflect::GetTypeRegistration", diff --git a/crates/bevy_api_gen/templates/footer.tera b/crates/bevy_api_gen/templates/footer.tera index 87a76308e2..0009ff8855 100644 --- a/crates/bevy_api_gen/templates/footer.tera +++ b/crates/bevy_api_gen/templates/footer.tera @@ -33,7 +33,7 @@ pub struct {{ "ScriptingPlugin" | prefix_cratename | convert_case(case="upper_ca impl bevy::app::Plugin for {{ "ScriptingPlugin" | prefix_cratename | convert_case(case="upper_camel")}} { fn build(&self, app: &mut bevy::prelude::App) { {% for item in items %} - app.register_proxy::<{{ item.import_path }}>(); + app.register_lua_proxy::<{{ item.import_path }}>(); {% endfor %} app.add_context_initializer::<()>({{ "ContextInitializer" | prefix_cratename | convert_case(case="snake") }}); app.add_documentation_fragment( diff --git a/crates/bevy_api_gen/templates/header.tera b/crates/bevy_api_gen/templates/header.tera index 2cdbb5745e..5404318ea2 100644 --- a/crates/bevy_api_gen/templates/header.tera +++ b/crates/bevy_api_gen/templates/header.tera @@ -12,7 +12,7 @@ use super::{{crate}}::*; use bevy_mod_scripting_core::{AddContextInitializer, StoreDocumentation, bindings::ReflectReference}; {% if args.self_is_bms_lua %} -use crate::{bindings::proxy::{LuaReflectRefProxy,LuaReflectRefMutProxy,LuaReflectValProxy,LuaValProxy,IdentityProxy},RegisterLuaProxy, tealr::mlu::mlua::IntoLua}; +use crate::{bindings::proxy::{LuaReflectRefProxy,LuaReflectRefMutProxy,LuaReflectValProxy,LuaValProxy,LuaIdentityProxy},RegisterLua, tealr::mlu::mlua::IntoLua}; {% else %} -use bevy_mod_scripting::{lua::bindings::proxy::{LuaReflectRefProxy,LuaReflectRefMutProxy,LuaReflectValProxy,LuaValProxy,IdentityProxy}, RegisterLuaProxy, tealr::mlu::mlua::IntoLua}; +use bevy_mod_scripting::{lua::bindings::proxy::{LuaReflectRefProxy,LuaReflectRefMutProxy,LuaReflectValProxy,LuaValProxy,LuaIdentityProxy}, RegisterLua, tealr::mlu::mlua::IntoLua}; {% endif %} \ No newline at end of file diff --git a/crates/bevy_api_gen/templates/item.tera b/crates/bevy_api_gen/templates/item.tera index 43bb345ec7..969b932438 100644 --- a/crates/bevy_api_gen/templates/item.tera +++ b/crates/bevy_api_gen/templates/item.tera @@ -11,7 +11,7 @@ {% set bms_lua_path="bevy_mod_scripting::lua" %} {% endif %} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( remote="{{ item.import_path }}", bms_core_path="{{bms_core_path}}", diff --git a/crates/bevy_api_gen/templates/macros.tera b/crates/bevy_api_gen/templates/macros.tera index ef5b578334..ec421a0605 100644 --- a/crates/bevy_api_gen/templates/macros.tera +++ b/crates/bevy_api_gen/templates/macros.tera @@ -1,6 +1,6 @@ {% macro vector_index(num_type) %} #[lua(metamethod="Index")] -fn index(self, idx: usize) -> IdentityProxy<{{ num_type }}> { +fn index(self, idx: usize) -> LuaIdentityProxy<{{ num_type }}> { _self[idx - 1] } {% endmacro vector_index %} @@ -14,15 +14,13 @@ fn index(&mut self, idx: usize, val: {{ num_type }}) -> () { {% macro matrix_index(col_type, mat_type, bms_core_path) %} #[lua(metamethod="Index")] -fn index(_self: IdentityProxy, idx: usize) -> IdentityProxy<{{ col_type | prefix_lua }}> { +fn index(_self: LuaIdentityProxy, idx: usize) -> LuaIdentityProxy<{{ col_type | prefix_lua }}> { let mut curr_ref = _self.0.clone(); let def_ref = {{bms_core_path}}::bindings::DeferredReflection{ get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(idx - 1)) + if let Some(ret) = ref_.try_as_reflect_mut().map(|ret| ret.downcast_mut::()).flatten(){ + Ok(ret.col_mut(idx - 1)) } else { Err(bevy::reflect::ReflectPathError::InvalidDowncast) } diff --git a/crates/bevy_mod_scripting_derive/Cargo.toml b/crates/bevy_mod_scripting_derive/Cargo.toml new file mode 100644 index 0000000000..4540176a35 --- /dev/null +++ b/crates/bevy_mod_scripting_derive/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "bevy_mod_scripting_derive" +version = "0.6.0" +authors = ["Maksymilian Mozolewski "] +edition = "2021" +license = "MIT OR Apache-2.0" +description = "Necessary functionality for Lua support with bevy_mod_scripting" +repository = "https://github.com/makspll/bevy_mod_scripting" +homepage = "https://github.com/makspll/bevy_mod_scripting" +keywords = ["bevy", "gamedev", "scripting", "rhai"] +categories = ["game-development"] +readme = "readme.md" + +[lib] +name = "bevy_mod_scripting_derive" +path = "src/lib.rs" +proc-macro = true + +[dependencies] +paste = "1.0.7" +darling = "0.20.3" +syn = { version = "2.0.38", features = ["full", "fold", "extra-traits"] } +quote = "1.0.8" +proc-macro2 = "1.0" +convert_case = "0.5.0" +rustdoc-types = "0.11.0" +serde = { version = "1.0", features = ["derive"] } +serde_derive = "1.0.137" +indexmap = { version = "1.9.1", features = ["serde"] } +strum = { version = "0.24.1", features = ["derive"] } +vec1 = "1.10.1" diff --git a/crates/bevy_mod_scripting_derive/readme.md b/crates/bevy_mod_scripting_derive/readme.md new file mode 100644 index 0000000000..e058ed4f00 --- /dev/null +++ b/crates/bevy_mod_scripting_derive/readme.md @@ -0,0 +1,3 @@ +# bevy_mod_scripting_lua_derive + +This crate is a part of the ["bevy_mod_scripting" workspace](https://github.com/makspll/bevy_mod_scripting). \ No newline at end of file diff --git a/crates/bevy_mod_scripting_derive/src/input.rs b/crates/bevy_mod_scripting_derive/src/input.rs new file mode 100644 index 0000000000..4fc68695f6 --- /dev/null +++ b/crates/bevy_mod_scripting_derive/src/input.rs @@ -0,0 +1,115 @@ +use darling::{util::Flag, FromDeriveInput, FromMeta}; +use proc_macro2::Ident; +use std::ops::{Deref, DerefMut}; +use syn::{spanned::Spanned, visit_mut::VisitMut, Attribute, Field, TraitItemFn, Variant}; + +#[derive(FromMeta)] +pub struct BMSCorePath(pub syn::Path); + +impl Default for BMSCorePath { + fn default() -> Self { + Self(syn::parse_quote!(bevy_mod_scripting::core)) + } +} + +#[derive(FromMeta)] +pub struct BMSLuaPath(pub syn::Path); + +impl Default for BMSLuaPath { + fn default() -> Self { + Self(syn::parse_quote!(bevy_mod_scripting::lua)) + } +} + +#[derive(FromDeriveInput)] +#[darling(attributes(proxy), forward_attrs(allow, doc, cfg))] +pub struct ProxyInput { + /// The name of the type for which we are generating a proxy (target type) + pub ident: syn::Ident, + /// The visibility of the target type + pub vis: syn::Visibility, + /// The generics on the target type + pub generics: syn::Generics, + /// The attributes on the target type + pub attrs: Vec, + + /// The path to the type for which we are generating a proxy if it's a foreign type + pub remote: Option, + + /// if provided will call the function at this path to get the world callback access. Normally this is retrieved using a global variable. + pub get_world_callback_access_fn: Option, + + /// If set will use the given path as the type for the proxy instead of generating a new one + /// Only used for the special world proxies, probably not useful for anything else, the macro assumes we have an inner ReflectReference in the wrapper + pub proxy_as_type: Option, + + /// The path to the bevy_mod_scripting_core crate + #[darling(default)] + pub bms_core_path: BMSCorePath, + /// The path to the bevy_mod_scripting_lua crate + #[darling(default)] + pub bms_lua_path: BMSLuaPath, + + /// The name to use for the proxy type, if not provided the language derive macro + /// will generate one using a standard prefix. + #[darling(rename = "name")] + pub proxy_name: Option, + + /// The body of the type for which we are generating a proxy + pub data: darling::ast::Data, + + /// A list of multi-lang function definitions to be generated on the proxy type + #[darling(default)] + pub functions: TraitItemFnsWrapper, +} + +#[derive(Default)] +pub struct TraitItemFnsWrapper(pub Vec); + +impl FromMeta for TraitItemFnsWrapper { + fn from_string(value: &str) -> darling::Result { + let token_stream: proc_macro2::TokenStream = value.parse().map_err(syn::Error::from)?; + let trait_items_vec = vec![syn::parse2(token_stream)?]; + Ok(TraitItemFnsWrapper(trait_items_vec)) + } + + fn from_list(items: &[darling::ast::NestedMeta]) -> darling::Result { + Ok(TraitItemFnsWrapper( + items + .iter() + .map(Self::from_nested_meta) + .collect::, _>>()? + .into_iter() + .flat_map(|v| v.0.into_iter()) + .collect::>(), + )) + } +} + +impl Deref for TraitItemFnsWrapper { + type Target = Vec; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} +impl DerefMut for TraitItemFnsWrapper { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +/// Replaces every occurence of an identifier with +/// the given string while preserving the original span +pub struct IdentifierRenamingVisitor<'a> { + pub target: &'a str, + pub replacement: &'a str, +} + +impl VisitMut for IdentifierRenamingVisitor<'_> { + fn visit_ident_mut(&mut self, i: &mut Ident) { + if *i == self.target { + *i = Ident::new(self.replacement, i.span()); + } + } +} diff --git a/crates/bevy_mod_scripting_derive/src/lib.rs b/crates/bevy_mod_scripting_derive/src/lib.rs new file mode 100644 index 0000000000..6c932ffc43 --- /dev/null +++ b/crates/bevy_mod_scripting_derive/src/lib.rs @@ -0,0 +1,531 @@ +mod input; +mod utils; + +use crate::{input::*, utils::doc_attribute_to_string_lit}; + +use std::collections::HashMap; +use darling::util::Flag; +use syn::{ + spanned::Spanned, Path, Token, TraitItemFn, parse_quote, + parse_macro_input, parse_quote_spanned, DeriveInput, ExprClosure, FnArg, + punctuated::Punctuated +}; + +use darling::{FromAttributes, FromDeriveInput}; +use proc_macro::TokenStream; +use proc_macro2::*; +use quote::*; + + +const SELF_ALIAS: &str = "_self"; +const CTXT_ALIAS: &str = "lua"; +const PROXY_PREFIX: &str = "Lua"; + +/// Convert receiver to a standardised form, for example: +/// - instead o a `&self` receiver we have a `_self: LuaRefProxy` +/// - instead of a `&mut self` receiver we have a `_self: LuaRefMutProxy` +/// - instead of a `self` receiver we have a `_self: ValLuaProxy` +/// Returns true if the receiver was changed +fn standardise_receiver(receiver: &mut FnArg, target_type: &Path, bms_lua_path: &Path, proxy_as_type: Option<&Path>) -> bool { + let replacement = if let FnArg::Receiver(receiver) = receiver { + let ref_ = &receiver.reference.as_ref().map(|(amp, lifetime)| { + quote_spanned! {receiver.span()=> + #amp #lifetime + } + }); + + let self_ident = syn::Ident::new(SELF_ALIAS, receiver.span()); + let self_ident_type = match proxy_as_type{ + Some(target_type) => { + quote_spanned! {receiver.span()=> + #target_type + } + }, + None => { + let unproxy_container_name = match (ref_.is_some(), receiver.mutability.is_some()) { + (true, true) => "LuaReflectRefMutProxy", + (true, false) => "LuaReflectRefProxy", + (false, _) => "LuaReflectValProxy", + }; + let unproxy_ident = syn::Ident::new(unproxy_container_name, receiver.span()); + + quote_spanned! {receiver.span()=> + #bms_lua_path::bindings::proxy::#unproxy_ident::<#target_type> + } + } + }; + + Some(syn::FnArg::Typed(parse_quote_spanned! {receiver.span()=> + #self_ident: #self_ident_type + })) + } else { + None + }; + if let Some(replacement) = replacement { + *receiver = replacement; + true + } else { + false + } +} + +/// Collect all arguments into a tuple, for example: +/// - `fn foo(a: i32, b: f32)` becomes `(name: (i32, f32))` +fn collect_args_in_tuple<'a, I: Iterator>( + args: I, + name: &Ident, + outer_mut: bool, +) -> FnArg { + let (_, arg_types) = args + .map(|arg| { + if let FnArg::Typed(arg) = arg { + (arg.pat.clone(), arg.ty.clone()) + } else { + panic!("Function arguments must be typed") + } + }) + .unzip::<_, _, Vec<_>, Vec<_>>(); + + let outer_mut = if outer_mut { + Some(Token![mut](name.span())) + } else { + None + }; + + parse_quote!( #outer_mut #name : (#(#arg_types),*) ) +} + +/// Convert a function definition to a closure, for example: +/// - `fn foo(a: i32, b: f32) -> f32 { a + b }` becomes `|a: i32, b: f32| { a + b} ` +fn convert_function_def_to_closure(f: &TraitItemFn) -> ExprClosure { + let span = f.span(); + let sig = &f.sig.inputs; + let body = f + .default + .as_ref() + .unwrap_or_else(|| panic!("Function {} must have a body", f.sig.ident)); + parse_quote_spanned! {span => + |#sig| #body + } +} + +/// Processes the function def to wrap it in the necessary proxying logic +/// Will convert the function signature to take in two arguments: +/// - a context argument +/// - a tuple of all arguments passed to the underlying function +fn proxy_wrap_function_def( + f: &mut TraitItemFn, + target_type: &Path, + bms_core: &Path, + bms_lua: &Path, + get_world_callback_access_fn: Option<&Path>, + proxy_as_type: Option<&Path>, + mlua: &Path, + attrs: &FunctionAttrs, +) { + + // collect all args into tuple and add lua context arg + let ctxt_alias = syn::Ident::new(CTXT_ALIAS, f.sig.inputs.span()); + + let ctxt_arg = if attrs.with_context.is_present() { + f.sig + .inputs + .pop() + .expect("Expected at least one argument for the context") + .into_value() + } else { + parse_quote_spanned! {f.span()=> + #ctxt_alias: &#mlua::Lua + } + }; + + let ctxt_arg_ident = match &ctxt_arg { + FnArg::Typed(arg) => arg.pat.clone(), + _ => panic!("Expected a typed argument, not a receiver for the context argument"), + }; + + let mut has_receiver = false; + if let Some(first_arg) = f.sig.inputs.first_mut() { + has_receiver = standardise_receiver(first_arg, target_type, bms_lua, proxy_as_type); + }; + + let func_name = &f.sig.ident; + let (mut original_arg_idents, _) = f + .sig + .inputs + .iter() + .map(|arg| { + if let FnArg::Typed(arg) = arg { + (arg.pat.clone(), arg.ty.clone()) + } else { + panic!("Function arguments must be typed") + } + }) + .unzip::<_, _, Vec<_>, Vec<_>>(); + + let span = f.span(); + let args_ident = format_ident!("args", span = f.sig.inputs.span()); + let args_tail_ident = format_ident!("args_tail", span = f.sig.inputs.span()); + let args_head_ident = format_ident!("args_head", span = f.sig.inputs.span()); + let args_split = if get_world_callback_access_fn.is_some() { + let tail = (1..original_arg_idents.len()).map(|i| { + let i = syn::Index::from(i); + quote_spanned!(span=> #args_ident.#i) + }); + quote_spanned!(span=> + let #args_head_ident = #args_ident.0; + let #args_tail_ident = (#(#tail),*); + ) + } else { + Default::default() + }; + + + + // change signature to take in a single args tuple instead of multiple arguments (on top of a context arg) + f.sig.inputs = Punctuated::from_iter(vec![ + ctxt_arg, + collect_args_in_tuple(f.sig.inputs.iter(), &args_ident, true), + ]); + + let args_var_to_use = if get_world_callback_access_fn.is_some() { + original_arg_idents.remove(0); + args_tail_ident + } else { + args_ident + }; + + let out_type = match &f.sig.output { + syn::ReturnType::Default => quote_spanned! {f.span()=> + () + }, + syn::ReturnType::Type(_, ty) => ty.to_token_stream(), + }; + + + // wrap function body in our unwrapping and wrapping logic, ignore pre-existing body + let mut fn_call = std::panic::catch_unwind(|| { + match (&f.default, &attrs.as_trait, get_world_callback_access_fn.is_some()) { + (_, _, true) => quote_spanned!(span=> + world.#func_name(#(#original_arg_idents),*) + ), + (Some(body), _, _) => quote_spanned!(span=> + (||{ #body })() + ), + (_, None, _) => quote_spanned!(span=> + #target_type::#func_name(#(#original_arg_idents),*) + ), + (_, Some(trait_path), _) => { + let trait_path = quote_spanned!(span=> #trait_path); + quote_spanned!(span=> + <#target_type as #trait_path>::#func_name(#(#original_arg_idents),*) + ) + } + } + }) + .unwrap(); // todo: handle the error nicer + + if f.sig.unsafety.is_some() { + fn_call = quote_spanned!(span=> + unsafe { #fn_call } + ); + } + + if attrs.no_proxy.is_present() { + f.default = Some(parse_quote_spanned! {span=> + { + #fn_call + } + }); + } else { + let world = if let Some(world_getter_fn_path) = get_world_callback_access_fn { + quote_spanned!(span=> + let mut world: #bms_core::bindings::WorldCallbackAccess = #world_getter_fn_path(#args_head_ident); + let mut world = world.read().ok_or_else(|| #mlua::Error::external("World no longer exists"))?; + ) + } else { + quote_spanned!(span=> + let mut world: #bms_lua::bindings::proxy::LuaValProxy<#bms_core::bindings::WorldCallbackAccess> = #ctxt_arg_ident.globals().get("world")?; + let mut world = <#bms_lua::bindings::proxy::LuaValProxy<#bms_core::bindings::WorldCallbackAccess> as #bms_core::bindings::Unproxy>::unproxy(&mut world).map_err(#mlua::Error::external)?; + let mut world = world.read().ok_or_else(|| #mlua::Error::external("World no longer exists"))?; + ) + }; + + + f.default = Some(parse_quote_spanned! {span=> + { + #args_split + #world + let out: #out_type = world.proxy_call(#args_var_to_use, |(#(#original_arg_idents),*)| { + #fn_call + }).map_err(|e| #mlua::Error::external(e))?; + Ok(out) + } + }); + } +} + +fn generate_methods_registration( + attrs: &FunctionAttrs, + span: Span, + name: proc_macro2::TokenStream, + closure: ExprClosure, +) -> proc_macro2::TokenStream { + let registration_method = if attrs.metamethod.is_some() { + quote_spanned!(span=>add_meta_function) + } else { + quote_spanned!(span=>add_function) + }; + let docs = attrs.doc.iter().map(|doc| { + quote_spanned! {span=> + methods.document(#doc); + } + }); + quote_spanned! {span=> + #(#docs)* + methods.#registration_method(#name, #closure); + } +} + +#[derive(FromAttributes, Clone)] +#[darling(attributes(lua))] +struct FunctionAttrs { + #[darling(multiple)] + pub doc: Vec, + + /// Marks the function as a composite with the given ID, at least one another function with the same composite + /// ID must exist resulting in a combined function being generated. The actual function to dispatch to will be decided based on + /// the types of arguments. If the signature is invalid (i.e. doesn't allow us to dispatch) an error will be thrown + #[darling(default)] + pub composite: Option, + + /// Marks this to be ignored, only used for fields as functions are opt-in + pub skip: Flag, + + /// If passed will generate statement before calling the method + /// on the type + pub as_trait: Option, + + /// If passed will generate a metamethod call instead of using the function name + pub metamethod: Option, + + /// If true will pass in the context as the last argument, + /// i.e. will remove that argument from the function signature and use it's name as the context alias + pub with_context: Flag, + + /// Skips the unproxying & proxying call, useful for functions that don't need to access the world + pub no_proxy: Flag, +} + +#[proc_macro_derive(LuaProxy, attributes(lua, proxy))] +pub fn impl_lua_proxy(input: TokenStream) -> TokenStream { + let derive_input = parse_macro_input!(input as DeriveInput); + + let mut meta: ProxyInput = match ProxyInput::from_derive_input(&derive_input) { + Ok(v) => v, + Err(e) => return darling::Error::write_errors(e).into(), + }; + if meta.proxy_name.is_some() { + // throw error + return syn::Error::new( + derive_input.span(), + "The `name` attribute is not supported for lua proxies", + ) + .to_compile_error() + .into(); + } + + let target_type = meta.remote.unwrap_or(meta.ident.clone().into()); + let target_type_str = target_type.segments.last().unwrap().ident.to_string(); + let proxy_type_ident = match meta.proxy_as_type.as_ref() { + Some(proxy_as_type) => proxy_as_type.clone(), + None => meta.proxy_name.unwrap_or_else(|| format_ident!("{PROXY_PREFIX}{}", &target_type_str, span = meta.ident.span())).into(), + }; + + + let bms_core = meta.bms_core_path.0; + let bms_lua = meta.bms_lua_path.0; + let tealr: Path = parse_quote_spanned!(bms_lua.span()=> + #bms_lua::tealr + ); + let mlua: Path = parse_quote_spanned!(bms_core.span()=> + #tealr::mlu::mlua + ); + + // generate type level tealr documentation calls + let type_level_document_calls = meta + .attrs + .iter() + .filter(|&a| a.meta.path().is_ident("doc")) + .map(doc_attribute_to_string_lit) + .map(|tkns| { + quote_spanned!(meta.ident.span()=> + methods.document_type(#tkns); + ) + }); + + // extract composites first + let mut composites: HashMap> = HashMap::new(); + meta.functions.0.retain(|f| { + let attrs = FunctionAttrs::from_attributes(&f.attrs).unwrap(); + if let Some(composite_id) = &attrs.composite { + composites + .entry(composite_id.to_owned()) + .or_default() + .push((f.clone(), attrs)); + false + } else { + true + } + }); + + let add_composite_function_stmts = composites.into_values().map(|functions| { + let (first_function, first_function_attrs) = functions + .first() + .cloned() + .expect("At least one function must be a composite for this code to be reached"); + + let name = match &first_function_attrs.metamethod { + Some(metamethod) => quote_spanned!(metamethod.span()=> + #mlua::MetaMethod::#metamethod + ), + None => first_function.sig.ident.to_string().to_token_stream(), + }; + + let value_arg_types = (0..first_function.sig.inputs.len()) + .map(|_| { + quote_spanned!(first_function.span()=> + #mlua::Value + ) + }) + .collect::>(); + + let value_arg_names = (0..first_function.sig.inputs.len()).map(|i| { + format_ident!("arg{}", i, span = first_function.span()) + }).collect::>(); + + let closures = functions + .into_iter() + .map(|(mut f, attrs)| { + proxy_wrap_function_def(&mut f, &target_type, &bms_core, &bms_lua, meta.get_world_callback_access_fn.as_ref() ,meta.proxy_as_type.as_ref(), &mlua, &attrs); + convert_function_def_to_closure(&f) + }) + .collect::>(); + + let closure_args_types = closures.iter().map(|closure| { + let last = closure.inputs.last().unwrap(); + if let syn::Pat::Type(pat_type) = last { + &pat_type.ty + } else { + panic!("Closure must have a single argument tuple as its last argument") + } + }); + + let closure = parse_quote_spanned! {first_function.span()=> + |ctxt, (#(#value_arg_names,)*): (#(#value_arg_types,)*)| { + let args = #mlua::MultiValue::from_vec(vec![#(#value_arg_names,)*]); + #( + if let Ok(args) = <#closure_args_types as #mlua::FromLuaMulti>::from_lua_multi(args.clone(), ctxt) { + let out : Result<_, #mlua::Error> = (#closures)(ctxt, args); + return out?.into_lua(ctxt) + } + )* + Err(#mlua::Error::external("Invalid arguments for composite function")) + } + }; + + generate_methods_registration(&first_function_attrs, first_function.span(), name, closure) + }); + + let add_function_stmts = meta.functions.0.into_iter().filter_map(|mut f| { + let attrs = FunctionAttrs::from_attributes(&f.attrs).unwrap(); + + if attrs.skip.is_present() { + return None; + } + + proxy_wrap_function_def(&mut f, &target_type, &bms_core, &bms_lua, meta.get_world_callback_access_fn.as_ref(), meta.proxy_as_type.as_ref(), &mlua, &attrs); + + let name = match &attrs.metamethod { + Some(metamethod) => quote_spanned!(metamethod.span()=> + #mlua::MetaMethod::#metamethod + ), + None => f.sig.ident.to_string().to_token_stream(), + }; + let span = f.span(); + + let closure = convert_function_def_to_closure(&f); + + Some(generate_methods_registration(&attrs, span, name, closure)) + }); + + let vis = &meta.vis; + + let definition = if let Some(proxy_as_type) = meta.proxy_as_type.as_ref() { + Default::default() + } else { + quote_spanned!(derive_input.span()=> + #[derive(Clone, Debug, #tealr::mlu::UserData, #tealr::ToTypename)] + #vis struct #proxy_type_ident (pub #bms_core::bindings::ReflectReference); + ) + }; + + let conversions = if let Some(proxy_as_type) = meta.proxy_as_type.as_ref() { + Default::default() + } else { + quote_spanned!(derive_input.span()=> + impl AsRef<#bms_core::bindings::ReflectReference> for #proxy_type_ident { + fn as_ref(&self) -> &#bms_core::bindings::ReflectReference { + &self.0 + } + } + + impl From<#bms_core::bindings::ReflectReference> for #proxy_type_ident { + fn from(r: #bms_core::bindings::ReflectReference) -> Self { + Self(r) + } + } + ) + }; + + + quote_spanned! {meta.ident.span()=> + + #definition + + impl #bms_lua::bindings::proxy::LuaProxied for #target_type { + type Proxy = #proxy_type_ident; + } + + impl #tealr::mlu::TealData for #proxy_type_ident { + fn add_methods<'lua, M: #tealr::mlu::TealDataMethods<'lua, Self>>(methods: &mut M) { + #(#type_level_document_calls)* + #(#add_composite_function_stmts)* + #(#add_function_stmts)* + } + } + + + impl<'lua> #tealr::mlu::mlua::FromLua<'lua> for #proxy_type_ident { + fn from_lua( + value: #tealr::mlu::mlua::Value<'lua>, + _lua: &#tealr::mlu::mlua::Lua, + ) -> Result { + match value { + tealr::mlu::mlua::Value::UserData(ud) => Ok(ud.borrow::()?.clone()), + _ => { + return Err(#tealr::mlu::mlua::Error::FromLuaConversionError { + from: value.type_name(), + to: stringify!(#proxy_type_ident), + message: None, + }) + } + } + } + } + + #conversions + } + .into() +} + diff --git a/crates/bevy_mod_scripting_derive/src/utils.rs b/crates/bevy_mod_scripting_derive/src/utils.rs new file mode 100644 index 0000000000..d8df6bb792 --- /dev/null +++ b/crates/bevy_mod_scripting_derive/src/utils.rs @@ -0,0 +1,59 @@ +use proc_macro2::{Ident, TokenStream}; +use quote::ToTokens; +use syn::{ + parse::{Parse, ParseStream}, + Attribute, Path, PathArguments, PathSegment, Type, TypePath, +}; + +pub fn doc_attribute_to_string_lit(attrs: &Attribute) -> Option { + attrs + .meta + .require_name_value() + .map(|v| v.value.to_token_stream()) + .ok() +} + +pub fn ident_to_type_path(ident: Ident) -> TypePath { + TypePath { + qself: None, + path: Path { + leading_colon: None, + segments: [PathSegment { + ident, + arguments: PathArguments::None, + }] + .into_iter() + .collect(), + }, + } +} +/// Converts the given ToTokens into token stream, stringifies it and removes whitespace +pub fn stringify_token_group(t: &T) -> String { + let mut k = t.into_token_stream().to_string(); + k.retain(|c| !c.is_whitespace()); + k +} + +/// Converts simple type to base string (i.e. one which has a single type identifier) +pub fn type_base_string(t: &Type) -> Option { + match t { + Type::Paren(v) => type_base_string(&v.elem), + Type::Path(p) => Some(p.path.segments.last()?.ident.to_string()), + Type::Ptr(p) => type_base_string(&p.elem), + Type::Reference(r) => type_base_string(&r.elem), + Type::Slice(v) => type_base_string(&v.elem), + _ => None, + } +} + +#[derive(Default, Debug, Clone)] +pub struct EmptyToken; + +impl Parse for EmptyToken { + fn parse(_: ParseStream) -> Result { + Ok(Self) + } +} +impl ToTokens for EmptyToken { + fn to_tokens(&self, _: &mut TokenStream) {} +} diff --git a/crates/languages/bevy_mod_scripting_lua/Cargo.toml b/crates/languages/bevy_mod_scripting_lua/Cargo.toml index f8288805d8..d483005013 100644 --- a/crates/languages/bevy_mod_scripting_lua/Cargo.toml +++ b/crates/languages/bevy_mod_scripting_lua/Cargo.toml @@ -41,6 +41,7 @@ path = "src/lib.rs" [dependencies] bevy = { workspace = true, default-features = false } bevy_mod_scripting_core = { workspace = true } +bevy_mod_scripting_derive = { path = "../../bevy_mod_scripting_derive" } tealr = { version = "0.9", features = [ "mlua_vendored", "mlua_send", @@ -49,3 +50,6 @@ tealr = { version = "0.9", features = [ parking_lot = "0.12.1" serde_json = "1.0.81" anyhow = "1.0.75" +uuid = "1.1" +smol_str = "0.2.2" +smallvec = "1.13" diff --git a/crates/languages/bevy_mod_scripting_lua/src/assets.rs b/crates/languages/bevy_mod_scripting_lua/src/assets.rs index 7e3e50d74b..b7d54e0c7a 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/assets.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/assets.rs @@ -1,157 +1,157 @@ -use bevy::{ - asset::{io::Reader, Asset, AssetLoader}, - reflect::TypePath, - utils::BoxedFuture, -}; -use bevy_mod_scripting_core::asset::CodeAsset; +// use bevy::{ +// asset::{io::Reader, Asset, AssetLoader}, +// reflect::TypePath, +// utils::BoxedFuture, +// }; +// use bevy_mod_scripting_core::asset::CodeAsset; -use anyhow::Error; +// use anyhow::Error; -#[derive(Asset, TypePath, Debug)] -/// A lua code file in bytes -pub struct LuaFile { - pub bytes: Vec, -} +// #[derive(Asset, TypePath, Debug)] +// /// A lua code file in bytes +// pub struct LuaFile { +// pub bytes: Vec, +// } -impl CodeAsset for LuaFile { - fn bytes(&self) -> &[u8] { - self.bytes.as_slice() - } -} +// impl CodeAsset for LuaFile { +// fn bytes(&self) -> &[u8] { +// self.bytes.as_slice() +// } +// } -#[derive(Default)] -/// Asset loader for lua scripts -pub struct LuaLoader; +// #[derive(Default)] +// /// Asset loader for lua scripts +// pub struct LuaLoader; -fn old_lua_load<'a>( - bytes: &'a [u8], - load_context: &'a mut bevy::asset::LoadContext, -) -> BoxedFuture<'a, Result, Error>> { - match load_context.path().extension().map(|s| s.to_str().unwrap()) { - #[cfg(all(feature = "teal", debug_assertions))] - Some("tl") => { - use bevy::asset::io::file::FileAssetReader; - use std::fs; - use std::path::PathBuf; - use std::process::Command; +// fn old_lua_load<'a>( +// bytes: &'a [u8], +// load_context: &'a mut bevy::asset::LoadContext, +// ) -> BoxedFuture<'a, Result, Error>> { +// match load_context.path().extension().map(|s| s.to_str().unwrap()) { +// #[cfg(all(feature = "teal", debug_assertions))] +// Some("tl") => { +// use bevy::asset::io::file::FileAssetReader; +// use std::fs; +// use std::path::PathBuf; +// use std::process::Command; - let scripts_dir = &FileAssetReader::get_base_path() - .join("assets") - .join("scripts"); +// let scripts_dir = &FileAssetReader::get_base_path() +// .join("assets") +// .join("scripts"); - let temp_file_path = &std::env::temp_dir().join("bevy_mod_scripting.temp.lua"); - bevy::prelude::info!("tl file path {}", scripts_dir.to_str().unwrap()); - // optionally put the output in the /build folder - let build_dir_path: Option = - if load_context.path().starts_with("scripts/build/") { - Some( - load_context - .path() - .strip_prefix("scripts/") - .unwrap() - .to_owned(), - ) - } else if load_context.path().starts_with("scripts/") { - Some( - PathBuf::from("build/") - .join(load_context.path().strip_prefix("scripts/").unwrap()), - ) - } else { - None - }; +// let temp_file_path = &std::env::temp_dir().join("bevy_mod_scripting.temp.lua"); +// bevy::prelude::info!("tl file path {}", scripts_dir.to_str().unwrap()); +// // optionally put the output in the /build folder +// let build_dir_path: Option = +// if load_context.path().starts_with("scripts/build/") { +// Some( +// load_context +// .path() +// .strip_prefix("scripts/") +// .unwrap() +// .to_owned(), +// ) +// } else if load_context.path().starts_with("scripts/") { +// Some( +// PathBuf::from("build/") +// .join(load_context.path().strip_prefix("scripts/").unwrap()), +// ) +// } else { +// None +// }; - let full_path = &FileAssetReader::get_base_path() - .join("assets") - .join(load_context.path()); - bevy::log::info!( - "tl check {} : {}", - full_path.to_str().unwrap(), - scripts_dir.to_str().unwrap() - ); - if let Ok(e) = Command::new("tl") - .args(["check", full_path.to_str().unwrap()]) - .current_dir(scripts_dir) - .status() - { - if !e.success() { - return Box::pin(async move { - Err(Error::msg(format!( - "Teal file `{}` has errors", - load_context.path().to_str().unwrap() - ))) - }); - } - } else { - fs::remove_file(temp_file_path).expect("Something went wrong running `tl check`"); - panic!("Something went wrong running `tl check`"); - } +// let full_path = &FileAssetReader::get_base_path() +// .join("assets") +// .join(load_context.path()); +// bevy::log::info!( +// "tl check {} : {}", +// full_path.to_str().unwrap(), +// scripts_dir.to_str().unwrap() +// ); +// if let Ok(e) = Command::new("tl") +// .args(["check", full_path.to_str().unwrap()]) +// .current_dir(scripts_dir) +// .status() +// { +// if !e.success() { +// return Box::pin(async move { +// Err(Error::msg(format!( +// "Teal file `{}` has errors", +// load_context.path().to_str().unwrap() +// ))) +// }); +// } +// } else { +// fs::remove_file(temp_file_path).expect("Something went wrong running `tl check`"); +// panic!("Something went wrong running `tl check`"); +// } - if let Ok(e) = Command::new("tl") - .args([ - "gen", - full_path.to_str().unwrap(), - "-o", - temp_file_path.to_str().unwrap(), - ]) - .current_dir(scripts_dir) - .status() - { - if !e.success() { - return Box::pin(async move { - Err(Error::msg(format!( - "Teal file `{}` could not be compiled!", - load_context.path().to_str().unwrap() - ))) - }); - } - } else { - fs::remove_file(temp_file_path).expect("Something went wrong running `tl gen`"); - panic!("Something went wrong running `tl gen`") - } +// if let Ok(e) = Command::new("tl") +// .args([ +// "gen", +// full_path.to_str().unwrap(), +// "-o", +// temp_file_path.to_str().unwrap(), +// ]) +// .current_dir(scripts_dir) +// .status() +// { +// if !e.success() { +// return Box::pin(async move { +// Err(Error::msg(format!( +// "Teal file `{}` could not be compiled!", +// load_context.path().to_str().unwrap() +// ))) +// }); +// } +// } else { +// fs::remove_file(temp_file_path).expect("Something went wrong running `tl gen`"); +// panic!("Something went wrong running `tl gen`") +// } - if let Some(mut build_dir_path) = build_dir_path { - build_dir_path = scripts_dir.join(build_dir_path); - let _ = fs::create_dir_all(build_dir_path.parent().unwrap()); - let _ = fs::copy(temp_file_path, build_dir_path.with_extension("lua")); - } +// if let Some(mut build_dir_path) = build_dir_path { +// build_dir_path = scripts_dir.join(build_dir_path); +// let _ = fs::create_dir_all(build_dir_path.parent().unwrap()); +// let _ = fs::copy(temp_file_path, build_dir_path.with_extension("lua")); +// } - let lua_code = - fs::read_to_string(temp_file_path).expect("Could not find output lua file"); - fs::remove_file(temp_file_path).unwrap(); +// let lua_code = +// fs::read_to_string(temp_file_path).expect("Could not find output lua file"); +// fs::remove_file(temp_file_path).unwrap(); - Box::pin(async move { Ok(lua_code.as_bytes().into()) }) - } +// Box::pin(async move { Ok(lua_code.as_bytes().into()) }) +// } - _ => Box::pin(async move { Ok(bytes.into()) }), - } -} -impl AssetLoader for LuaLoader { - type Asset = LuaFile; - type Settings = (); - type Error = Error; +// _ => Box::pin(async move { Ok(bytes.into()) }), +// } +// } +// impl AssetLoader for LuaLoader { +// type Asset = LuaFile; +// type Settings = (); +// type Error = Error; - async fn load( - &self, - reader: &mut dyn Reader, //bytes: &'a [u8], - _settings: &(), - load_context: &mut bevy::asset::LoadContext<'_>, - ) -> std::result::Result< - ::Asset, - ::Error, - > { - bevy::prelude::info!("lua loader invoked: {:#}", load_context.asset_path()); - let mut bytes = Vec::new(); - reader.read_to_end(&mut bytes).await?; - let bytes = old_lua_load(bytes.as_slice(), load_context).await?; - Ok(LuaFile { bytes }) - } +// async fn load( +// &self, +// reader: &mut dyn Reader, //bytes: &'a [u8], +// _settings: &(), +// load_context: &mut bevy::asset::LoadContext<'_>, +// ) -> std::result::Result< +// ::Asset, +// ::Error, +// > { +// bevy::prelude::info!("lua loader invoked: {:#}", load_context.asset_path()); +// let mut bytes = Vec::new(); +// reader.read_to_end(&mut bytes).await?; +// let bytes = old_lua_load(bytes.as_slice(), load_context).await?; +// Ok(LuaFile { bytes }) +// } - #[cfg(feature = "teal")] - fn extensions(&self) -> &[&str] { - &["lua", "tl"] - } - #[cfg(not(feature = "teal"))] - fn extensions(&self) -> &[&str] { - &["lua"] - } -} +// #[cfg(feature = "teal")] +// fn extensions(&self) -> &[&str] { +// &["lua", "tl"] +// } +// #[cfg(not(feature = "teal"))] +// fn extensions(&self) -> &[&str] { +// &["lua"] +// } +// } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/mod.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/mod.rs index 384af4032b..5a278b6306 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/mod.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/mod.rs @@ -1,3 +1,8 @@ use bevy_mod_scripting_core::bindings::WorldCallbackAccess; pub mod providers; +pub mod proxy; +pub mod reference; +pub mod std; +pub mod type_registration; +pub mod world; diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_a11y.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_a11y.rs index b6ef3788e4..991607f1cb 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_a11y.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_a11y.rs @@ -4,41 +4,48 @@ #![cfg_attr(rustfmt, rustfmt_skip)] use super::bevy_ecs::*; use super::bevy_reflect::*; -extern crate self as bevy_script_api; -use bevy_script_api::{ - lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, }; -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy(derive(), remote = "bevy::a11y::Focus", functions[])] -struct Focus(ReflectedValue); +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_derive::LuaProxy)] +#[proxy( + remote = "bevy::a11y::Focus", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[] +)] +pub struct Focus(ReflectReference); #[derive(Default)] pub(crate) struct Globals; -impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { - fn add_instances< - 'lua, - T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, - >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { Ok(()) } } -pub struct BevyA11YAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyA11YAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; - fn attach_api( - &mut self, - ctx: &mut Self::APITarget, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); - bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) - .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( - e.to_string(), - )) - } - fn get_doc_fragment(&self) -> Option { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( +fn bevy_a_11_y_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyA11YScriptingPlugin; +impl bevy::app::Plugin for BevyA11YScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_a_11_y_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( "BevyA11YAPI", |tw| { tw.document_global_instance::() @@ -46,24 +53,6 @@ impl bevy_mod_scripting_core::hosts::APIProvider for BevyA11YAPIProvider { .process_type::() }, ), - ) - } - fn setup_script( - &mut self, - script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn setup_script_runtime( - &mut self, - world_ptr: bevy_mod_scripting_core::world::WorldPointer, - _script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn register_with_app(&self, app: &mut bevy::app::App) { - app.register_foreign_lua_type::(); + ); } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_core.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_core.rs index f205ff73bd..050cbea514 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_core.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_core.rs @@ -4,67 +4,73 @@ #![cfg_attr(rustfmt, rustfmt_skip)] use super::bevy_ecs::*; use super::bevy_reflect::*; -extern crate self as bevy_script_api; -use bevy_script_api::{ - lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, }; -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::core::prelude::Name", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::core::prelude::Name; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &name::Name) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{}", _self) } "#] )] -struct Name {} +pub struct Name {} #[derive(Default)] pub(crate) struct Globals; -impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { - fn add_instances< - 'lua, - T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, - >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { Ok(()) } } -pub struct BevyCoreAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyCoreAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; - fn attach_api( - &mut self, - ctx: &mut Self::APITarget, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); - bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) - .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( - e.to_string(), - )) - } - fn get_doc_fragment(&self) -> Option { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( +fn bevy_core_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyCoreScriptingPlugin; +impl bevy::app::Plugin for BevyCoreScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_core_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( "BevyCoreAPI", |tw| { tw.document_global_instance::() @@ -72,24 +78,6 @@ impl bevy_mod_scripting_core::hosts::APIProvider for BevyCoreAPIProvider { .process_type::() }, ), - ) - } - fn setup_script( - &mut self, - script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn setup_script_runtime( - &mut self, - world_ptr: bevy_mod_scripting_core::world::WorldPointer, - _script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn register_with_app(&self, app: &mut bevy::app::App) { - app.register_foreign_lua_type::(); + ); } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs index 8f3b5d4e27..bbda61844f 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs @@ -3,18 +3,27 @@ #![allow(unused, deprecated, dead_code)] #![cfg_attr(rustfmt, rustfmt_skip)] use super::bevy_reflect::*; -extern crate self as bevy_script_api; -use bevy_script_api::{ - lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, }; -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::ecs::entity::Entity", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::ecs::entity::Entity; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -28,8 +37,8 @@ use bevy_script_api::{ /// `Entity` lines up between instances, but instead insert a secondary identifier as /// a component. - #[lua(kind = "Function", output(proxy))] - fn from_raw(index: u32) -> bevy::ecs::entity::Entity; + #[lua()] + fn from_raw(index: u32) -> LuaReflectValProxy; "#, r#" @@ -38,8 +47,8 @@ use bevy_script_api::{ /// for serialization between runs. /// No particular structure is guaranteed for the returned bits. - #[lua(kind = "Method")] - fn to_bits(self) -> u64; + #[lua()] + fn to_bits(_self: LuaReflectValProxy) -> u64; "#, r#" @@ -48,8 +57,8 @@ use bevy_script_api::{ /// # Panics /// This method will likely panic if given `u64` values that did not come from [`Entity::to_bits`]. - #[lua(kind = "Function", output(proxy))] - fn from_bits(bits: u64) -> bevy::ecs::entity::Entity; + #[lua()] + fn from_bits(bits: u64) -> LuaReflectValProxy; "#, r#" @@ -58,8 +67,8 @@ use bevy_script_api::{ /// with both live and dead entities. Useful for compactly representing entities within a /// specific snapshot of the world, such as when serializing. - #[lua(kind = "Method")] - fn index(self) -> u32; + #[lua()] + fn index(_self: LuaReflectValProxy) -> u32; "#, r#" @@ -67,90 +76,97 @@ use bevy_script_api::{ /// entity with a given index is despawned. This serves as a "count" of the number of times a /// given index has been reused (index, generation) pairs uniquely identify a given Entity. - #[lua(kind = "Method")] - fn generation(self) -> u32; + #[lua()] + fn generation(_self: LuaReflectValProxy) -> u32; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &entity::Entity) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Entity {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Entity {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "bevy::ecs::world::OnAdd", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct OnAdd {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct OnAdd {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "bevy::ecs::world::OnInsert", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct OnInsert {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct OnInsert {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "bevy::ecs::world::OnRemove", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct OnRemove {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct OnRemove {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "bevy::ecs::world::OnReplace", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct OnReplace {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct OnReplace {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::ecs::component::ComponentId", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &component::ComponentId) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -158,128 +174,137 @@ struct OnReplace {} /// The `index` is a unique value associated with each type of component in a given world. /// Usually, this value is taken from a counter incremented for each type of component registered with the world. - #[lua(kind = "Function", output(proxy))] - fn new(index: usize) -> bevy::ecs::component::ComponentId; + #[lua()] + fn new(index: usize) -> LuaReflectValProxy; "#, r#" /// Returns the index of the current component. - #[lua(kind = "Method")] - fn index(self) -> usize; + #[lua()] + fn index(_self: LuaReflectValProxy) -> usize; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::ecs::component::ComponentId; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct ComponentId(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct ComponentId(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::ecs::component::Tick", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &component::Tick) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::ecs::component::Tick; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new [`Tick`] wrapping the given value. - #[lua(kind = "Function", output(proxy))] - fn new(tick: u32) -> bevy::ecs::component::Tick; + #[lua()] + fn new(tick: u32) -> LuaReflectValProxy; "#, r#" /// Gets the value of this change tick. - #[lua(kind = "Method")] - fn get(self) -> u32; + #[lua()] + fn get(_self: LuaReflectValProxy) -> u32; "#, r#" /// Sets the value of this change tick. - #[lua(kind = "MutatingMethod")] - fn set(&mut self, tick: u32) -> (); + #[lua()] + fn set(_self: LuaReflectRefMutProxy, tick: u32) -> (); "#, r#" /// Returns `true` if this `Tick` occurred since the system's `last_run`. /// `this_run` is the current tick of the system, used as a reference to help deal with wraparound. - #[lua(kind = "Method")] + #[lua()] fn is_newer_than( - self, - #[proxy] - last_run: bevy::ecs::component::Tick, - #[proxy] - this_run: bevy::ecs::component::Tick, + _self: LuaReflectValProxy, + last_run: LuaReflectValProxy, + this_run: LuaReflectValProxy, ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Tick {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Tick {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::ecs::component::ComponentTicks", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::ecs::component::ComponentTicks; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if the component or resource was added after the system last ran /// (or the system is running for the first time). - #[lua(kind = "Method")] + #[lua()] fn is_added( - &self, - #[proxy] - last_run: bevy::ecs::component::Tick, - #[proxy] - this_run: bevy::ecs::component::Tick, + _self: LuaReflectRefProxy, + last_run: LuaReflectValProxy, + this_run: LuaReflectValProxy, ) -> bool; "#, @@ -287,28 +312,30 @@ struct Tick {} /// Returns `true` if the component or resource was added or mutably dereferenced after the system last ran /// (or the system is running for the first time). - #[lua(kind = "Method")] + #[lua()] fn is_changed( - &self, - #[proxy] - last_run: bevy::ecs::component::Tick, - #[proxy] - this_run: bevy::ecs::component::Tick, + _self: LuaReflectRefProxy, + last_run: LuaReflectValProxy, + this_run: LuaReflectValProxy, ) -> bool; "#, r#" /// Returns the tick recording the time this component or resource was most recently changed. - #[lua(kind = "Method", output(proxy))] - fn last_changed_tick(&self) -> bevy::ecs::component::Tick; + #[lua()] + fn last_changed_tick( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the tick recording the time this component or resource was added. - #[lua(kind = "Method", output(proxy))] - fn added_tick(&self) -> bevy::ecs::component::Tick; + #[lua()] + fn added_tick( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -324,59 +351,66 @@ struct Tick {} /// component_ticks.set_changed(world.read_change_tick()); /// ``` - #[lua(kind = "MutatingMethod")] - fn set_changed(&mut self, #[proxy] change_tick: bevy::ecs::component::Tick) -> (); + #[lua()] + fn set_changed( + _self: LuaReflectRefMutProxy, + change_tick: LuaReflectValProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct ComponentTicks {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct ComponentTicks {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::ecs::identifier::Identifier", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::ecs::identifier::Identifier; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &identifier::Identifier) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Returns the value of the low segment of the [`Identifier`]. - #[lua(kind = "Method")] - fn low(self) -> u32; + #[lua()] + fn low(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns the masked value of the high segment of the [`Identifier`]. /// Does not include the flag bits. - #[lua(kind = "Method")] - fn masked_high(self) -> u32; + #[lua()] + fn masked_high(_self: LuaReflectValProxy) -> u32; "#, r#" /// Convert the [`Identifier`] into a `u64`. - #[lua(kind = "Method")] - fn to_bits(self) -> u64; + #[lua()] + fn to_bits(_self: LuaReflectValProxy) -> u64; "#, r#" @@ -384,164 +418,137 @@ struct ComponentTicks {} /// # Panics /// This method will likely panic if given `u64` values that did not come from [`Identifier::to_bits`]. - #[lua(kind = "Function", output(proxy))] - fn from_bits(value: u64) -> bevy::ecs::identifier::Identifier; + #[lua()] + fn from_bits(value: u64) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Identifier {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Identifier {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::ecs::entity::EntityHash", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::ecs::entity::EntityHash; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#] )] -struct EntityHash {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct EntityHash {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::ecs::removal_detection::RemovedComponentEntity", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::ecs::removal_detection::RemovedComponentEntity; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct RemovedComponentEntity(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy(derive(), remote = "bevy::ecs::system::SystemIdMarker", functions[])] -struct SystemIdMarker {} +pub struct RemovedComponentEntity(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] +#[proxy( + remote = "bevy::ecs::system::SystemIdMarker", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[] +)] +pub struct SystemIdMarker {} #[derive(Default)] pub(crate) struct Globals; -impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { - fn add_instances< - 'lua, - T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, - >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { instances - .add_instance( - "Entity", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Entity", crate::tealr::mlu::UserDataProxy::::new)?; instances .add_instance( "ComponentId", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances - .add_instance( - "Tick", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Tick", crate::tealr::mlu::UserDataProxy::::new)?; instances .add_instance( "Identifier", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; Ok(()) } } -pub struct BevyEcsAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyEcsAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; - fn attach_api( - &mut self, - ctx: &mut Self::APITarget, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); - bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) - .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( - e.to_string(), - )) - } - fn get_doc_fragment(&self) -> Option { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( +fn bevy_ecs_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyEcsScriptingPlugin; +impl bevy::app::Plugin for BevyEcsScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_ecs_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( "BevyEcsAPI", |tw| { tw.document_global_instance::() .expect("Something went wrong documenting globals") .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() .process_type::() .process_type::() .process_type::() .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaComponentId, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaIdentifier, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() .process_type::() .process_type::() }, ), - ) - } - fn setup_script( - &mut self, - script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn setup_script_runtime( - &mut self, - world_ptr: bevy_mod_scripting_core::world::WorldPointer, - _script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn register_with_app(&self, app: &mut bevy::app::App) { - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::< - bevy::ecs::removal_detection::RemovedComponentEntity, - >(); - app.register_foreign_lua_type::(); + ); } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs index 2cb1efa99e..5db574d547 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs @@ -5,128 +5,140 @@ use super::bevy_ecs::*; use super::bevy_reflect::*; use super::bevy_core::*; -extern crate self as bevy_script_api; -use bevy_script_api::{ - lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, }; -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "bevy::hierarchy::prelude::Children", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Swaps the child at `a_index` with the child at `b_index`. - #[lua(kind = "MutatingMethod")] - fn swap(&mut self, a_index: usize, b_index: usize) -> (); + #[lua()] + fn swap( + _self: LuaReflectRefMutProxy, + a_index: usize, + b_index: usize, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Children(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Children(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "bevy::hierarchy::prelude::Parent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &components::parent::Parent) -> bool; - -"#, - r#" -/// Gets the [`Entity`] ID of the parent. - - #[lua(kind = "Method", output(proxy))] - fn get(&self) -> bevy::ecs::entity::Entity; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Parent(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Parent(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::hierarchy::HierarchyEvent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &events::HierarchyEvent) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::hierarchy::HierarchyEvent; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct HierarchyEvent {} +pub struct HierarchyEvent {} #[derive(Default)] pub(crate) struct Globals; -impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { - fn add_instances< - 'lua, - T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, - >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { Ok(()) } } -pub struct BevyHierarchyAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyHierarchyAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; - fn attach_api( - &mut self, - ctx: &mut Self::APITarget, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); - bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) - .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( - e.to_string(), - )) - } - fn get_doc_fragment(&self) -> Option { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( +fn bevy_hierarchy_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyHierarchyScriptingPlugin; +impl bevy::app::Plugin for BevyHierarchyScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_hierarchy_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( "BevyHierarchyAPI", |tw| { tw.document_global_instance::() @@ -136,26 +148,6 @@ impl bevy_mod_scripting_core::hosts::APIProvider for BevyHierarchyAPIProvider { .process_type::() }, ), - ) - } - fn setup_script( - &mut self, - script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn setup_script_runtime( - &mut self, - world_ptr: bevy_mod_scripting_core::world::WorldPointer, - _script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn register_with_app(&self, app: &mut bevy::app::App) { - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); + ); } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs index f13ae2f8ef..6fb241e53a 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs @@ -6,1157 +6,1171 @@ use super::bevy_ecs::*; use super::bevy_reflect::*; use super::bevy_core::*; use super::bevy_math::*; -extern crate self as bevy_script_api; -use bevy_script_api::{ - lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, }; -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "bevy::input::gamepad::Gamepad", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" -/// Returns the left stick as a [`Vec2`] - - #[lua(kind = "Method", output(proxy))] - fn left_stick(&self) -> bevy::math::Vec2; - -"#, - r#" -/// Returns the right stick as a [`Vec2`] - - #[lua(kind = "Method", output(proxy))] - fn right_stick(&self) -> bevy::math::Vec2; - -"#, - r#" -/// Returns the directional pad as a [`Vec2`] - - #[lua(kind = "Method", output(proxy))] - fn dpad(&self) -> bevy::math::Vec2; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Gamepad { +pub struct Gamepad { vendor_id: std::option::Option, product_id: std::option::Option, - digital: ReflectedValue, - analog: ReflectedValue, + digital: ReflectReference, + analog: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::GamepadAxis", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gamepad::GamepadAxis) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadAxis; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct GamepadAxis {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct GamepadAxis {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::GamepadButton", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadButton; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gamepad::GamepadButton) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct GamepadButton {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct GamepadButton {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::GamepadSettings", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadSettings; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct GamepadSettings { - #[lua(output(proxy))] +pub struct GamepadSettings { default_button_settings: bevy::input::gamepad::ButtonSettings, - #[lua(output(proxy))] default_axis_settings: bevy::input::gamepad::AxisSettings, - #[lua(output(proxy))] default_button_axis_settings: bevy::input::gamepad::ButtonAxisSettings, - button_settings: ReflectedValue, - axis_settings: ReflectedValue, - button_axis_settings: ReflectedValue, + button_settings: ReflectReference, + axis_settings: ReflectReference, + button_axis_settings: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::keyboard::KeyCode", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &keyboard::KeyCode) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::keyboard::KeyCode; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct KeyCode {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct KeyCode {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::mouse::MouseButton", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::mouse::MouseButton; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &mouse::MouseButton) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct MouseButton {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct MouseButton {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::touch::TouchInput", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::touch::TouchInput; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &touch::TouchInput) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct TouchInput { - #[lua(output(proxy))] +pub struct TouchInput { phase: bevy::input::touch::TouchPhase, - #[lua(output(proxy))] - position: bevy::math::Vec2, - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, - force: ReflectedValue, + position: ReflectReference, + window: ReflectReference, + force: ReflectReference, id: u64, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::keyboard::KeyboardFocusLost", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &keyboard::KeyboardFocusLost) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::keyboard::KeyboardFocusLost; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct KeyboardFocusLost {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct KeyboardFocusLost {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::keyboard::KeyboardInput", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &keyboard::KeyboardInput) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::keyboard::KeyboardInput; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct KeyboardInput { - #[lua(output(proxy))] +pub struct KeyboardInput { key_code: bevy::input::keyboard::KeyCode, - #[lua(output(proxy))] logical_key: bevy::input::keyboard::Key, - #[lua(output(proxy))] state: bevy::input::ButtonState, repeat: bool, - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, + window: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::mouse::AccumulatedMouseMotion", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &mouse::AccumulatedMouseMotion) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::mouse::AccumulatedMouseMotion; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AccumulatedMouseMotion { - #[lua(output(proxy))] - delta: bevy::math::Vec2, +pub struct AccumulatedMouseMotion { + delta: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::mouse::AccumulatedMouseScroll", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::mouse::AccumulatedMouseScroll; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &mouse::AccumulatedMouseScroll) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AccumulatedMouseScroll { - #[lua(output(proxy))] +pub struct AccumulatedMouseScroll { unit: bevy::input::mouse::MouseScrollUnit, - #[lua(output(proxy))] - delta: bevy::math::Vec2, + delta: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::mouse::MouseButtonInput", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &mouse::MouseButtonInput) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::mouse::MouseButtonInput; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct MouseButtonInput { - #[lua(output(proxy))] +pub struct MouseButtonInput { button: bevy::input::mouse::MouseButton, - #[lua(output(proxy))] state: bevy::input::ButtonState, - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, + window: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::mouse::MouseMotion", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &mouse::MouseMotion) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::mouse::MouseMotion; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct MouseMotion { - #[lua(output(proxy))] - delta: bevy::math::Vec2, +pub struct MouseMotion { + delta: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::mouse::MouseWheel", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::mouse::MouseWheel; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &mouse::MouseWheel) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct MouseWheel { - #[lua(output(proxy))] +pub struct MouseWheel { unit: bevy::input::mouse::MouseScrollUnit, x: f32, y: f32, - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, + window: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::GamepadAxisChangedEvent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gamepad::GamepadAxisChangedEvent) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadAxisChangedEvent; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -/// Creates a new [`GamepadAxisChangedEvent`] - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - entity: bevy::ecs::entity::Entity, - #[proxy] - axis: bevy::input::gamepad::GamepadAxis, - value: f32, - ) -> bevy::input::gamepad::GamepadAxisChangedEvent; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct GamepadAxisChangedEvent { - #[lua(output(proxy))] - entity: bevy::ecs::entity::Entity, - #[lua(output(proxy))] +pub struct GamepadAxisChangedEvent { + entity: ReflectReference, axis: bevy::input::gamepad::GamepadAxis, value: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::GamepadButtonChangedEvent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gamepad::GamepadButtonChangedEvent) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadButtonChangedEvent; - -"#, - r#" -/// Creates a new [`GamepadButtonChangedEvent`] - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - entity: bevy::ecs::entity::Entity, - #[proxy] - button: bevy::input::gamepad::GamepadButton, - #[proxy] - state: bevy::input::ButtonState, - value: f32, - ) -> bevy::input::gamepad::GamepadButtonChangedEvent; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct GamepadButtonChangedEvent { - #[lua(output(proxy))] - entity: bevy::ecs::entity::Entity, - #[lua(output(proxy))] +pub struct GamepadButtonChangedEvent { + entity: ReflectReference, button: bevy::input::gamepad::GamepadButton, - #[lua(output(proxy))] state: bevy::input::ButtonState, value: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::GamepadButtonStateChangedEvent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" -/// Creates a new [`GamepadButtonStateChangedEvent`] - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - entity: bevy::ecs::entity::Entity, - #[proxy] - button: bevy::input::gamepad::GamepadButton, - #[proxy] - state: bevy::input::ButtonState, - ) -> bevy::input::gamepad::GamepadButtonStateChangedEvent; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadButtonStateChangedEvent; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gamepad::GamepadButtonStateChangedEvent) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct GamepadButtonStateChangedEvent { - #[lua(output(proxy))] - entity: bevy::ecs::entity::Entity, - #[lua(output(proxy))] +pub struct GamepadButtonStateChangedEvent { + entity: ReflectReference, button: bevy::input::gamepad::GamepadButton, - #[lua(output(proxy))] state: bevy::input::ButtonState, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::GamepadConnection", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gamepad::GamepadConnection) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadConnection; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct GamepadConnection {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct GamepadConnection {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::GamepadConnectionEvent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadConnectionEvent; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gamepad::GamepadConnectionEvent) -> bool; - -"#, - r#" -/// Creates a [`GamepadConnectionEvent`]. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - gamepad: bevy::ecs::entity::Entity, - #[proxy] - connection: bevy::input::gamepad::GamepadConnection, - ) -> bevy::input::gamepad::GamepadConnectionEvent; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Is the gamepad connected? - #[lua(kind = "Method")] - fn connected(&self) -> bool; + #[lua()] + fn connected( + _self: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Is the gamepad disconnected? - #[lua(kind = "Method")] - fn disconnected(&self) -> bool; + #[lua()] + fn disconnected( + _self: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct GamepadConnectionEvent { - #[lua(output(proxy))] - gamepad: bevy::ecs::entity::Entity, - #[lua(output(proxy))] +pub struct GamepadConnectionEvent { + gamepad: ReflectReference, connection: bevy::input::gamepad::GamepadConnection, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::GamepadEvent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gamepad::GamepadEvent) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadEvent; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct GamepadEvent {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct GamepadEvent {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::GamepadInput", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gamepad::GamepadInput) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadInput; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct GamepadInput {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct GamepadInput {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::GamepadRumbleRequest", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" -/// Get the [`Entity`] associated with this request. - - #[lua(kind = "Method", output(proxy))] - fn gamepad(&self) -> bevy::ecs::entity::Entity; - -"#, - r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadRumbleRequest; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#] )] -struct GamepadRumbleRequest {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct GamepadRumbleRequest {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::RawGamepadAxisChangedEvent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gamepad::RawGamepadAxisChangedEvent) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::RawGamepadAxisChangedEvent; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Creates a [`RawGamepadAxisChangedEvent`]. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - gamepad: bevy::ecs::entity::Entity, - #[proxy] - axis_type: bevy::input::gamepad::GamepadAxis, - value: f32, - ) -> bevy::input::gamepad::RawGamepadAxisChangedEvent; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct RawGamepadAxisChangedEvent { - #[lua(output(proxy))] - gamepad: bevy::ecs::entity::Entity, - #[lua(output(proxy))] +pub struct RawGamepadAxisChangedEvent { + gamepad: ReflectReference, axis: bevy::input::gamepad::GamepadAxis, value: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::RawGamepadButtonChangedEvent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::RawGamepadButtonChangedEvent; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gamepad::RawGamepadButtonChangedEvent) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -/// Creates a [`RawGamepadButtonChangedEvent`]. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - gamepad: bevy::ecs::entity::Entity, - #[proxy] - button_type: bevy::input::gamepad::GamepadButton, - value: f32, - ) -> bevy::input::gamepad::RawGamepadButtonChangedEvent; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct RawGamepadButtonChangedEvent { - #[lua(output(proxy))] - gamepad: bevy::ecs::entity::Entity, - #[lua(output(proxy))] +pub struct RawGamepadButtonChangedEvent { + gamepad: ReflectReference, button: bevy::input::gamepad::GamepadButton, value: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::RawGamepadEvent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gamepad::RawGamepadEvent) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::RawGamepadEvent; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct RawGamepadEvent {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct RawGamepadEvent {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gestures::PinchGesture", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gestures::PinchGesture) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gestures::PinchGesture; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct PinchGesture(f32); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct PinchGesture(f32); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gestures::RotationGesture", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gestures::RotationGesture) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gestures::RotationGesture; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct RotationGesture(f32); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct RotationGesture(f32); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gestures::DoubleTapGesture", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gestures::DoubleTapGesture) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gestures::DoubleTapGesture; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct DoubleTapGesture {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct DoubleTapGesture {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gestures::PanGesture", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gestures::PanGesture; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gestures::PanGesture) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct PanGesture(#[lua(output(proxy))] bevy::math::Vec2); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct PanGesture(ReflectReference); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::ButtonState", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" /// Is this button pressed? - #[lua(kind = "Method")] - fn is_pressed(&self) -> bool; + #[lua()] + fn is_pressed(_self: LuaReflectRefProxy) -> bool; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &ButtonState) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::ButtonState; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct ButtonState {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct ButtonState {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::ButtonSettings", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gamepad::ButtonSettings) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Returns `true` if the button is pressed. /// A button is considered pressed if the `value` passed is greater than or equal to the press threshold. - #[lua(kind = "Method")] - fn is_pressed(&self, value: f32) -> bool; + #[lua()] + fn is_pressed( + _self: LuaReflectRefProxy, + value: f32, + ) -> bool; "#, r#" /// Returns `true` if the button is released. /// A button is considered released if the `value` passed is lower than or equal to the release threshold. - #[lua(kind = "Method")] - fn is_released(&self, value: f32) -> bool; + #[lua()] + fn is_released( + _self: LuaReflectRefProxy, + value: f32, + ) -> bool; "#, r#" /// Get the button input threshold above which the button is considered pressed. - #[lua(kind = "Method")] - fn press_threshold(&self) -> f32; + #[lua()] + fn press_threshold( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" @@ -1164,15 +1178,20 @@ struct ButtonState {} /// If the value passed is outside the range [release threshold..=1.0], the value will not be changed. /// Returns the new value of the press threshold. - #[lua(kind = "MutatingMethod")] - fn set_press_threshold(&mut self, value: f32) -> f32; + #[lua()] + fn set_press_threshold( + _self: LuaReflectRefMutProxy, + value: f32, + ) -> f32; "#, r#" /// Get the button input threshold below which the button is considered released. - #[lua(kind = "Method")] - fn release_threshold(&self) -> f32; + #[lua()] + fn release_threshold( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" @@ -1180,39 +1199,49 @@ struct ButtonState {} /// value passed is outside the range [0.0..=press threshold], the value will not be changed. /// Returns the new value of the release threshold. - #[lua(kind = "MutatingMethod")] - fn set_release_threshold(&mut self, value: f32) -> f32; + #[lua()] + fn set_release_threshold( + _self: LuaReflectRefMutProxy, + value: f32, + ) -> f32; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::ButtonSettings; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct ButtonSettings {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct ButtonSettings {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::AxisSettings", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::AxisSettings; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Get the value above which inputs will be rounded up to 1.0. - #[lua(kind = "Method")] - fn livezone_upperbound(&self) -> f32; + #[lua()] + fn livezone_upperbound( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" @@ -1221,15 +1250,20 @@ struct ButtonSettings {} /// the value will not be changed. /// Returns the new value of `livezone_upperbound`. - #[lua(kind = "MutatingMethod")] - fn set_livezone_upperbound(&mut self, value: f32) -> f32; + #[lua()] + fn set_livezone_upperbound( + _self: LuaReflectRefMutProxy, + value: f32, + ) -> f32; "#, r#" /// Get the value below which positive inputs will be rounded down to 0.0. - #[lua(kind = "Method")] - fn deadzone_upperbound(&self) -> f32; + #[lua()] + fn deadzone_upperbound( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" @@ -1238,15 +1272,20 @@ struct ButtonSettings {} /// the value will not be changed. /// Returns the new value of `deadzone_upperbound`. - #[lua(kind = "MutatingMethod")] - fn set_deadzone_upperbound(&mut self, value: f32) -> f32; + #[lua()] + fn set_deadzone_upperbound( + _self: LuaReflectRefMutProxy, + value: f32, + ) -> f32; "#, r#" /// Get the value below which negative inputs will be rounded down to -1.0. - #[lua(kind = "Method")] - fn livezone_lowerbound(&self) -> f32; + #[lua()] + fn livezone_lowerbound( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" @@ -1255,15 +1294,20 @@ struct ButtonSettings {} /// the value will not be changed. /// Returns the new value of `livezone_lowerbound`. - #[lua(kind = "MutatingMethod")] - fn set_livezone_lowerbound(&mut self, value: f32) -> f32; + #[lua()] + fn set_livezone_lowerbound( + _self: LuaReflectRefMutProxy, + value: f32, + ) -> f32; "#, r#" /// Get the value above which inputs will be rounded up to 0.0. - #[lua(kind = "Method")] - fn deadzone_lowerbound(&self) -> f32; + #[lua()] + fn deadzone_lowerbound( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" @@ -1272,15 +1316,18 @@ struct ButtonSettings {} /// the value will not be changed. /// Returns the new value of `deadzone_lowerbound`. - #[lua(kind = "MutatingMethod")] - fn set_deadzone_lowerbound(&mut self, value: f32) -> f32; + #[lua()] + fn set_deadzone_lowerbound( + _self: LuaReflectRefMutProxy, + value: f32, + ) -> f32; "#, r#" /// Get the minimum value by which input must change before the change is registered. - #[lua(kind = "Method")] - fn threshold(&self) -> f32; + #[lua()] + fn threshold(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -1288,15 +1335,21 @@ struct ButtonSettings {} /// If the value passed is not within [0.0..=2.0], the value will not be changed. /// Returns the new value of threshold. - #[lua(kind = "MutatingMethod")] - fn set_threshold(&mut self, value: f32) -> f32; + #[lua()] + fn set_threshold( + _self: LuaReflectRefMutProxy, + value: f32, + ) -> f32; "#, r#" /// Clamps the `raw_value` according to the `AxisSettings`. - #[lua(kind = "Method")] - fn clamp(&self, new_value: f32) -> f32; + #[lua()] + fn clamp( + _self: LuaReflectRefProxy, + new_value: f32, + ) -> f32; "#, r#" @@ -1304,9 +1357,9 @@ struct ButtonSettings {} /// Returns the clamped `new_value` if the change exceeds the settings threshold, /// and `None` otherwise. - #[lua(kind = "Method")] + #[lua()] fn filter( - &self, + _self: LuaReflectRefProxy, new_value: f32, old_value: std::option::Option, ) -> std::option::Option; @@ -1315,34 +1368,36 @@ struct ButtonSettings {} r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gamepad::AxisSettings) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AxisSettings {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct AxisSettings {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::ButtonAxisSettings", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Filters the `new_value` based on the `old_value`, according to the [`ButtonAxisSettings`]. /// Returns the clamped `new_value`, according to the [`ButtonAxisSettings`], if the change /// exceeds the settings threshold, and `None` otherwise. - #[lua(kind = "Method")] + #[lua()] fn filter( - &self, + _self: LuaReflectRefProxy, new_value: f32, old_value: std::option::Option, ) -> std::option::Option; @@ -1350,351 +1405,386 @@ struct AxisSettings {} "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::ButtonAxisSettings; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct ButtonAxisSettings { +pub struct ButtonAxisSettings { high: f32, low: f32, threshold: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::gamepad::GamepadRumbleIntensity", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::gamepad::GamepadRumbleIntensity; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &gamepad::GamepadRumbleIntensity) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Creates a new rumble intensity with weak motor intensity set to the given value. /// Clamped within the `0.0` to `1.0` range. - #[lua(kind = "Function", output(proxy))] - fn weak_motor(intensity: f32) -> bevy::input::gamepad::GamepadRumbleIntensity; + #[lua()] + fn weak_motor( + intensity: f32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new rumble intensity with strong motor intensity set to the given value. /// Clamped within the `0.0` to `1.0` range. - #[lua(kind = "Function", output(proxy))] - fn strong_motor(intensity: f32) -> bevy::input::gamepad::GamepadRumbleIntensity; + #[lua()] + fn strong_motor( + intensity: f32, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct GamepadRumbleIntensity { +pub struct GamepadRumbleIntensity { strong_motor: f32, weak_motor: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::keyboard::Key", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::keyboard::Key; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &keyboard::Key) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Key {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Key {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::keyboard::NativeKeyCode", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::keyboard::NativeKeyCode; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &keyboard::NativeKeyCode) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct NativeKeyCode {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct NativeKeyCode {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::keyboard::NativeKey", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &keyboard::NativeKey) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::keyboard::NativeKey; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct NativeKey {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct NativeKey {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::mouse::MouseScrollUnit", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::mouse::MouseScrollUnit; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &mouse::MouseScrollUnit) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct MouseScrollUnit {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct MouseScrollUnit {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::touch::TouchPhase", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &touch::TouchPhase) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::touch::TouchPhase; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct TouchPhase {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct TouchPhase {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::input::touch::ForceTouch", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::input::touch::ForceTouch; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &touch::ForceTouch) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct ForceTouch {} +pub struct ForceTouch {} #[derive(Default)] pub(crate) struct Globals; -impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { - fn add_instances< - 'lua, - T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, - >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { - instances - .add_instance( - "GamepadAxisChangedEvent", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaGamepadAxisChangedEvent, - >::new, - )?; - instances - .add_instance( - "GamepadButtonChangedEvent", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaGamepadButtonChangedEvent, - >::new, - )?; - instances - .add_instance( - "GamepadButtonStateChangedEvent", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaGamepadButtonStateChangedEvent, - >::new, - )?; - instances - .add_instance( - "GamepadConnectionEvent", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaGamepadConnectionEvent, - >::new, - )?; - instances - .add_instance( - "RawGamepadAxisChangedEvent", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaRawGamepadAxisChangedEvent, - >::new, - )?; - instances - .add_instance( - "RawGamepadButtonChangedEvent", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaRawGamepadButtonChangedEvent, - >::new, - )?; +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { instances .add_instance( "GamepadRumbleIntensity", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaGamepadRumbleIntensity, - >::new, + crate::tealr::mlu::UserDataProxy::::new, )?; Ok(()) } } -pub struct BevyInputAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyInputAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; - fn attach_api( - &mut self, - ctx: &mut Self::APITarget, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); - bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) - .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( - e.to_string(), - )) - } - fn get_doc_fragment(&self) -> Option { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( +fn bevy_input_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyInputScriptingPlugin; +impl bevy::app::Plugin for BevyInputScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_input_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( "BevyInputAPI", |tw| { tw.document_global_instance::() @@ -1714,45 +1804,15 @@ impl bevy_mod_scripting_core::hosts::APIProvider for BevyInputAPIProvider { .process_type::() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaGamepadAxisChangedEvent, - >, - >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaGamepadButtonChangedEvent, - >, - >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaGamepadButtonStateChangedEvent, - >, - >() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaGamepadConnectionEvent, - >, - >() .process_type::() .process_type::() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaRawGamepadAxisChangedEvent, - >, - >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaRawGamepadButtonChangedEvent, - >, - >() .process_type::() .process_type::() .process_type::() @@ -1764,9 +1824,7 @@ impl bevy_mod_scripting_core::hosts::APIProvider for BevyInputAPIProvider { .process_type::() .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaGamepadRumbleIntensity, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() .process_type::() @@ -1776,71 +1834,6 @@ impl bevy_mod_scripting_core::hosts::APIProvider for BevyInputAPIProvider { .process_type::() }, ), - ) - } - fn setup_script( - &mut self, - script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn setup_script_runtime( - &mut self, - world_ptr: bevy_mod_scripting_core::world::WorldPointer, - _script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn register_with_app(&self, app: &mut bevy::app::App) { - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::< - bevy::input::gamepad::GamepadButtonChangedEvent, - >(); - app.register_foreign_lua_type::< - bevy::input::gamepad::GamepadButtonStateChangedEvent, - >(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::< - bevy::input::gamepad::RawGamepadAxisChangedEvent, - >(); - app.register_foreign_lua_type::< - bevy::input::gamepad::RawGamepadButtonChangedEvent, - >(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); + ); } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs index 822cdb30a3..67c56c306b 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs @@ -3,207 +3,210 @@ #![allow(unused, deprecated, dead_code)] #![cfg_attr(rustfmt, rustfmt_skip)] use super::bevy_reflect::*; -extern crate self as bevy_script_api; -use bevy_script_api::{ - lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, }; -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::AspectRatio", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &aspect_ratio::AspectRatio) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Returns the aspect ratio as a f32 value. - #[lua(kind = "Method")] - fn ratio(&self) -> f32; + #[lua()] + fn ratio(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Returns the inverse of this aspect ratio (height/width). - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::AspectRatio; + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns true if the aspect ratio represents a landscape orientation. - #[lua(kind = "Method")] - fn is_landscape(&self) -> bool; + #[lua()] + fn is_landscape(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns true if the aspect ratio represents a portrait orientation. - #[lua(kind = "Method")] - fn is_portrait(&self) -> bool; + #[lua()] + fn is_portrait(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns true if the aspect ratio is exactly square. - #[lua(kind = "Method")] - fn is_square(&self) -> bool; + #[lua()] + fn is_square(_self: LuaReflectRefProxy) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::AspectRatio; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AspectRatio(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct AspectRatio(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::CompassOctant", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::CompassOctant; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &compass::CompassOctant) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct CompassOctant {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct CompassOctant {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::CompassQuadrant", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &compass::CompassQuadrant) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::CompassQuadrant; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct CompassQuadrant {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct CompassQuadrant {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Isometry2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Isometry2d) -> bevy::math::Isometry2d; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::Isometry2d; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Create a two-dimensional isometry from a rotation and a translation. - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - translation: bevy::math::prelude::Vec2, - #[proxy] - rotation: bevy::math::Rot2, - ) -> bevy::math::Isometry2d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Create a two-dimensional isometry from a rotation. - #[lua(kind = "Function", output(proxy))] - fn from_rotation(#[proxy] rotation: bevy::math::Rot2) -> bevy::math::Isometry2d; - -"#, - r#" -/// Create a two-dimensional isometry from a translation. - - #[lua(kind = "Function", output(proxy))] - fn from_translation( - #[proxy] - translation: bevy::math::prelude::Vec2, - ) -> bevy::math::Isometry2d; + #[lua()] + fn from_rotation( + rotation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Create a two-dimensional isometry from a translation with the given `x` and `y` components. - #[lua(kind = "Function", output(proxy))] - fn from_xy(x: f32, y: f32) -> bevy::math::Isometry2d; + #[lua()] + fn from_xy(x: f32, y: f32) -> LuaReflectValProxy; "#, r#" /// The inverse isometry that undoes this one. - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::Isometry2d; + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -211,113 +214,61 @@ struct CompassQuadrant {} /// If the same isometry is used multiple times, it is more efficient to instead compute /// the inverse once and use that for each transformation. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn inverse_mul( - &self, - #[proxy] - rhs: bevy::math::Isometry2d, - ) -> bevy::math::Isometry2d; + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Transform a point by rotating and translating it using this isometry. - #[lua(kind = "Method", output(proxy))] - fn transform_point( - &self, - #[proxy] - point: bevy::math::prelude::Vec2, - ) -> bevy::math::prelude::Vec2; - -"#, - r#" -/// Transform a point by rotating and translating it using the inverse of this isometry. -/// This is more efficient than `iso.inverse().transform_point(point)` for one-shot cases. -/// If the same isometry is used multiple times, it is more efficient to instead compute -/// the inverse once and use that for each transformation. - - #[lua(kind = "Method", output(proxy))] - fn inverse_transform_point( - &self, - #[proxy] - point: bevy::math::prelude::Vec2, - ) -> bevy::math::prelude::Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::prelude::Vec2) -> bevy::math::prelude::Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &isometry::Isometry2d) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::prelude::Dir2) -> bevy::math::prelude::Dir2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Isometry2d { - #[lua(output(proxy))] +pub struct Isometry2d { rotation: bevy::math::Rot2, - #[lua(output(proxy))] - translation: bevy::math::prelude::Vec2, + translation: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Isometry3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" -/// Create a three-dimensional isometry from a rotation. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation( - #[proxy] - rotation: bevy::math::prelude::Quat, - ) -> bevy::math::Isometry3d; - -"#, - r#" /// Create a three-dimensional isometry from a translation with the given `x`, `y`, and `z` components. - #[lua(kind = "Function", output(proxy))] - fn from_xyz(x: f32, y: f32, z: f32) -> bevy::math::Isometry3d; + #[lua()] + fn from_xyz(x: f32, y: f32, z: f32) -> LuaReflectValProxy; "#, r#" /// The inverse isometry that undoes this one. - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::Isometry3d; + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -325,274 +276,155 @@ struct Isometry2d { /// If the same isometry is used multiple times, it is more efficient to instead compute /// the inverse once and use that for each transformation. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn inverse_mul( - &self, - #[proxy] - rhs: bevy::math::Isometry3d, - ) -> bevy::math::Isometry3d; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::prelude::Vec3) -> bevy::math::prelude::Vec3; + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &isometry::Isometry3d) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::Isometry3d; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::prelude::Dir3) -> bevy::math::prelude::Dir3; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Isometry3d) -> bevy::math::Isometry3d; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Isometry3d { - #[lua(output(proxy))] - rotation: bevy::math::prelude::Quat, - #[lua(output(proxy))] - translation: bevy::math::Vec3A, +pub struct Isometry3d { + rotation: ReflectReference, + translation: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Ray2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::Ray2d; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &ray::Ray2d) -> bool; - -"#, - r#" -/// Create a new `Ray2d` from a given origin and direction - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - origin: bevy::math::prelude::Vec2, - #[proxy] - direction: bevy::math::prelude::Dir2, - ) -> bevy::math::Ray2d; - -"#, - r#" -/// Get a point at a given distance along the ray - - #[lua(kind = "Method", output(proxy))] - fn get_point(&self, distance: f32) -> bevy::math::prelude::Vec2; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Get the distance to a plane if the ray intersects it - #[lua(kind = "Method")] - fn intersect_plane( - &self, - #[proxy] - plane_origin: bevy::math::prelude::Vec2, - #[proxy] - plane: bevy::math::primitives::Plane2d, - ) -> std::option::Option; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Ray2d { - #[lua(output(proxy))] - origin: bevy::math::prelude::Vec2, - #[lua(output(proxy))] +pub struct Ray2d { + origin: ReflectReference, direction: bevy::math::prelude::Dir2, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Ray3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::Ray3d; - -"#, - r#" -/// Create a new `Ray3d` from a given origin and direction - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - origin: bevy::math::prelude::Vec3, - #[proxy] - direction: bevy::math::prelude::Dir3, - ) -> bevy::math::Ray3d; - -"#, - r#" -/// Get a point at a given distance along the ray - - #[lua(kind = "Method", output(proxy))] - fn get_point(&self, distance: f32) -> bevy::math::prelude::Vec3; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Get the distance to a plane if the ray intersects it - #[lua(kind = "Method")] - fn intersect_plane( - &self, - #[proxy] - plane_origin: bevy::math::prelude::Vec3, - #[proxy] - plane: bevy::math::primitives::InfinitePlane3d, - ) -> std::option::Option; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &ray::Ray3d) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Ray3d { - #[lua(output(proxy))] - origin: bevy::math::prelude::Vec3, - #[lua(output(proxy))] +pub struct Ray3d { + origin: ReflectReference, direction: bevy::math::prelude::Dir3, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Rot2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::Rot2; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Rotates a [`Vec2`] by a [`Rot2`]. - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::prelude::Vec2) -> bevy::math::prelude::Vec2; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Rot2) -> bevy::math::Rot2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Rotates the [`Dir2`] using a [`Rot2`]. - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( - self, - #[proxy] - direction: bevy::math::prelude::Dir2, - ) -> bevy::math::prelude::Dir2; + _self: LuaReflectValProxy, + direction: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -611,8 +443,8 @@ struct Ray3d { /// assert_relative_eq!(rot1 * rot1, rot3); /// ``` - #[lua(kind = "Function", output(proxy))] - fn radians(radians: f32) -> bevy::math::Rot2; + #[lua()] + fn radians(radians: f32) -> LuaReflectValProxy; "#, r#" @@ -630,8 +462,8 @@ struct Ray3d { /// assert_relative_eq!(rot1 * rot1, rot3); /// ``` - #[lua(kind = "Function", output(proxy))] - fn degrees(degrees: f32) -> bevy::math::Rot2; + #[lua()] + fn degrees(degrees: f32) -> LuaReflectValProxy; "#, r#" @@ -649,8 +481,8 @@ struct Ray3d { /// assert_relative_eq!(rot1 * rot1, rot3); /// ``` - #[lua(kind = "Function", output(proxy))] - fn turn_fraction(fraction: f32) -> bevy::math::Rot2; + #[lua()] + fn turn_fraction(fraction: f32) -> LuaReflectValProxy; "#, r#" @@ -659,36 +491,36 @@ struct Ray3d { /// # Panics /// Panics if `sin * sin + cos * cos != 1.0` when the `glam_assert` feature is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_sin_cos(sin: f32, cos: f32) -> bevy::math::Rot2; + #[lua()] + fn from_sin_cos(sin: f32, cos: f32) -> LuaReflectValProxy; "#, r#" /// Returns the rotation in radians in the `(-pi, pi]` range. - #[lua(kind = "Method")] - fn as_radians(self) -> f32; + #[lua()] + fn as_radians(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns the rotation in degrees in the `(-180, 180]` range. - #[lua(kind = "Method")] - fn as_degrees(self) -> f32; + #[lua()] + fn as_degrees(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns the rotation as a fraction of a full 360 degree turn. - #[lua(kind = "Method")] - fn as_turn_fraction(self) -> f32; + #[lua()] + fn as_turn_fraction(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns the sine and cosine of the rotation angle in radians. - #[lua(kind = "Method")] - fn sin_cos(self) -> (f32, f32); + #[lua()] + fn sin_cos(_self: LuaReflectValProxy) -> (f32, f32); "#, r#" @@ -697,8 +529,8 @@ struct Ray3d { /// can be a result of incorrect construction or floating point error caused by /// successive operations. - #[lua(kind = "Method")] - fn length(self) -> f32; + #[lua()] + fn length(_self: LuaReflectValProxy) -> f32; "#, r#" @@ -709,16 +541,16 @@ struct Ray3d { /// can be a result of incorrect construction or floating point error caused by /// successive operations. - #[lua(kind = "Method")] - fn length_squared(self) -> f32; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f32; "#, r#" /// Computes `1.0 / self.length()`. /// For valid results, `self` must _not_ have a length of zero. - #[lua(kind = "Method")] - fn length_recip(self) -> f32; + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f32; "#, r#" @@ -730,8 +562,10 @@ struct Ray3d { /// # Panics /// Panics if `self` has a length of zero, NaN, or infinity when debug assertions are enabled. - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::Rot2; + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -739,52 +573,59 @@ struct Ray3d { /// Useful for preventing numerical error accumulation. /// See [`Dir3::fast_renormalize`](crate::Dir3::fast_renormalize) for an example of when such error accumulation might occur. - #[lua(kind = "Method", output(proxy))] - fn fast_renormalize(self) -> bevy::math::Rot2; + #[lua()] + fn fast_renormalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if the rotation is neither infinite nor NaN. - #[lua(kind = "Method")] - fn is_finite(self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; "#, r#" /// Returns `true` if the rotation is NaN. - #[lua(kind = "Method")] - fn is_nan(self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; "#, r#" /// Returns whether `self` has a length of `1.0` or not. /// Uses a precision threshold of approximately `1e-4`. - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; "#, r#" /// Returns `true` if the rotation is near [`Rot2::IDENTITY`]. - #[lua(kind = "Method")] - fn is_near_identity(self) -> bool; + #[lua()] + fn is_near_identity(_self: LuaReflectValProxy) -> bool; "#, r#" /// Returns the angle in radians needed to make `self` and `other` coincide. - #[lua(kind = "Method")] - fn angle_between(self, #[proxy] other: bevy::math::Rot2) -> f32; + #[lua()] + fn angle_between( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> f32; "#, r#" /// Returns the inverse of the rotation. This is also the conjugate /// of the unit complex number representing the rotation. - #[lua(kind = "Method", output(proxy))] - fn inverse(self) -> bevy::math::Rot2; + #[lua()] + fn inverse( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -816,8 +657,12 @@ struct Ray3d { /// assert_eq!(result2.as_degrees(), 67.5); /// ``` - #[lua(kind = "Method", output(proxy))] - fn nlerp(self, #[proxy] end: bevy::math::Rot2, s: f32) -> bevy::math::Rot2; + #[lua()] + fn nlerp( + _self: LuaReflectValProxy, + end: LuaReflectValProxy, + s: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -840,62 +685,49 @@ struct Ray3d { /// assert_eq!(result2.as_degrees(), 67.5); /// ``` - #[lua(kind = "Method", output(proxy))] - fn slerp(self, #[proxy] end: bevy::math::Rot2, s: f32) -> bevy::math::Rot2; + #[lua()] + fn slerp( + _self: LuaReflectValProxy, + end: LuaReflectValProxy, + s: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &rotation2d::Rot2) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Rot2 { +pub struct Rot2 { cos: f32, sin: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::prelude::Dir2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" -/// Create a [`Dir2`] from a [`Vec2`] that is already normalized. -/// # Warning -/// `value` must be normalized, i.e its length must be `1.0`. - - #[lua(kind = "Function", output(proxy))] - fn new_unchecked( - #[proxy] - value: bevy::math::prelude::Vec2, - ) -> bevy::math::prelude::Dir2; - -"#, - r#" /// Create a direction from its `x` and `y` components, assuming the resulting vector is normalized. /// # Warning /// The vector produced from `x` and `y` must be normalized, i.e its length must be `1.0`. - #[lua(kind = "Function", output(proxy))] - fn from_xy_unchecked(x: f32, y: f32) -> bevy::math::prelude::Dir2; - -"#, - r#" -/// Returns the inner [`Vec2`] - - #[lua(kind = "Method", output(proxy))] - fn as_vec2(&self) -> bevy::math::prelude::Vec2; + #[lua()] + fn from_xy_unchecked( + x: f32, + y: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -917,59 +749,68 @@ struct Rot2 { /// assert_relative_eq!(result2, Dir2::from_xy(0.5_f32.sqrt(), 0.5_f32.sqrt()).unwrap()); /// ``` - #[lua(kind = "Method", output(proxy))] + #[lua()] fn slerp( - self, - #[proxy] - rhs: bevy::math::prelude::Dir2, + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, s: f32, - ) -> bevy::math::prelude::Dir2; + ) -> LuaReflectValProxy; "#, r#" /// Get the rotation that rotates this direction to `other`. - #[lua(kind = "Method", output(proxy))] - fn rotation_to(self, #[proxy] other: bevy::math::prelude::Dir2) -> bevy::math::Rot2; + #[lua()] + fn rotation_to( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Get the rotation that rotates `other` to this direction. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn rotation_from( - self, - #[proxy] - other: bevy::math::prelude::Dir2, - ) -> bevy::math::Rot2; + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Get the rotation that rotates the X-axis to this direction. - #[lua(kind = "Method", output(proxy))] - fn rotation_from_x(self) -> bevy::math::Rot2; + #[lua()] + fn rotation_from_x( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Get the rotation that rotates this direction to the X-axis. - #[lua(kind = "Method", output(proxy))] - fn rotation_to_x(self) -> bevy::math::Rot2; + #[lua()] + fn rotation_to_x( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Get the rotation that rotates the Y-axis to this direction. - #[lua(kind = "Method", output(proxy))] - fn rotation_from_y(self) -> bevy::math::Rot2; + #[lua()] + fn rotation_from_y( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Get the rotation that rotates this direction to the Y-axis. - #[lua(kind = "Method", output(proxy))] - fn rotation_to_y(self) -> bevy::math::Rot2; + #[lua()] + fn rotation_to_y( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -977,108 +818,71 @@ struct Rot2 { /// Useful for preventing numerical error accumulation. /// See [`Dir3::fast_renormalize`] for an example of when such error accumulation might occur. - #[lua(kind = "Method", output(proxy))] - fn fast_renormalize(self) -> bevy::math::prelude::Dir2; + #[lua()] + fn fast_renormalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &direction::Dir2) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::prelude::Dir2; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::prelude::Dir2; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::prelude::Vec2; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Dir2(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Dir2(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::prelude::Dir3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &direction::Dir3) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::prelude::Vec3; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::prelude::Dir3; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -/// Create a [`Dir3`] from a [`Vec3`] that is already normalized. -/// # Warning -/// `value` must be normalized, i.e its length must be `1.0`. - #[lua(kind = "Function", output(proxy))] - fn new_unchecked( - #[proxy] - value: bevy::math::prelude::Vec3, - ) -> bevy::math::prelude::Dir3; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1086,15 +890,12 @@ struct Dir2(); /// # Warning /// The vector produced from `x`, `y`, and `z` must be normalized, i.e its length must be `1.0`. - #[lua(kind = "Function", output(proxy))] - fn from_xyz_unchecked(x: f32, y: f32, z: f32) -> bevy::math::prelude::Dir3; - -"#, - r#" -/// Returns the inner [`Vec3`] - - #[lua(kind = "Method", output(proxy))] - fn as_vec3(&self) -> bevy::math::prelude::Vec3; + #[lua()] + fn from_xyz_unchecked( + x: f32, + y: f32, + z: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -1120,13 +921,12 @@ struct Dir2(); /// assert_relative_eq!(result2, Dir3::from_xyz(0.5_f32.sqrt(), 0.5_f32.sqrt(), 0.0).unwrap()); /// ``` - #[lua(kind = "Method", output(proxy))] + #[lua()] fn slerp( - self, - #[proxy] - rhs: bevy::math::prelude::Dir3, + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, s: f32, - ) -> bevy::math::prelude::Dir3; + ) -> LuaReflectValProxy; "#, r#" @@ -1156,51 +956,44 @@ struct Dir2(); /// } /// ``` - #[lua(kind = "Method", output(proxy))] - fn fast_renormalize(self) -> bevy::math::prelude::Dir3; + #[lua()] + fn fast_renormalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::prelude::Dir3; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Dir3(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Dir3(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::prelude::Dir3A", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" -/// Create a [`Dir3A`] from a [`Vec3A`] that is already normalized. -/// # Warning -/// `value` must be normalized, i.e its length must be `1.0`. - - #[lua(kind = "Function", output(proxy))] - fn new_unchecked(#[proxy] value: bevy::math::Vec3A) -> bevy::math::prelude::Dir3A; - -"#, - r#" /// Create a direction from its `x`, `y`, and `z` components, assuming the resulting vector is normalized. /// # Warning /// The vector produced from `x`, `y`, and `z` must be normalized, i.e its length must be `1.0`. - #[lua(kind = "Function", output(proxy))] - fn from_xyz_unchecked(x: f32, y: f32, z: f32) -> bevy::math::prelude::Dir3A; - -"#, - r#" -/// Returns the inner [`Vec3A`] - - #[lua(kind = "Method", output(proxy))] - fn as_vec3a(&self) -> bevy::math::Vec3A; + #[lua()] + fn from_xyz_unchecked( + x: f32, + y: f32, + z: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -1226,13 +1019,12 @@ struct Dir3(); /// assert_relative_eq!(result2, Dir3A::from_xyz(0.5_f32.sqrt(), 0.5_f32.sqrt(), 0.0).unwrap()); /// ``` - #[lua(kind = "Method", output(proxy))] + #[lua()] fn slerp( - self, - #[proxy] - rhs: bevy::math::prelude::Dir3A, + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, s: f32, - ) -> bevy::math::prelude::Dir3A; + ) -> LuaReflectValProxy; "#, r#" @@ -1240,63 +1032,53 @@ struct Dir3(); /// Useful for preventing numerical error accumulation. /// See [`Dir3::fast_renormalize`] for an example of when such error accumulation might occur. - #[lua(kind = "Method", output(proxy))] - fn fast_renormalize(self) -> bevy::math::prelude::Dir3A; + #[lua()] + fn fast_renormalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::prelude::Dir3A; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &direction::Dir3A) -> bool; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::prelude::Dir3A; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Dir3A(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Dir3A(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::prelude::IRect", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Create a new rectangle from two corner points. /// The two points do not need to be the minimum and/or maximum corners. @@ -1308,74 +1090,13 @@ struct Dir3A(); /// let r = IRect::new(2, 3, 5, -1); // w=3 h=4 /// ``` - #[lua(kind = "Function", output(proxy))] - fn new(x0: i32, y0: i32, x1: i32, y1: i32) -> bevy::math::prelude::IRect; - -"#, - r#" -/// Create a new rectangle from two corner points. -/// The two points do not need to be the minimum and/or maximum corners. -/// They only need to be two opposite corners. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// // Unit rect from [0,0] to [1,1] -/// let r = IRect::from_corners(IVec2::ZERO, IVec2::ONE); // w=1 h=1 -/// // Same; the points do not need to be ordered -/// let r = IRect::from_corners(IVec2::ONE, IVec2::ZERO); // w=1 h=1 -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_corners( - #[proxy] - p0: bevy::math::prelude::IVec2, - #[proxy] - p1: bevy::math::prelude::IVec2, - ) -> bevy::math::prelude::IRect; - -"#, - r#" -/// Create a new rectangle from its center and size. -/// # Rounding Behavior -/// If the size contains odd numbers they will be rounded down to the nearest whole number. -/// # Panics -/// This method panics if any of the components of the size is negative. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r = IRect::from_center_size(IVec2::ZERO, IVec2::new(3, 2)); // w=2 h=2 -/// assert_eq!(r.min, IVec2::splat(-1)); -/// assert_eq!(r.max, IVec2::splat(1)); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_center_size( - #[proxy] - origin: bevy::math::prelude::IVec2, - #[proxy] - size: bevy::math::prelude::IVec2, - ) -> bevy::math::prelude::IRect; - -"#, - r#" -/// Create a new rectangle from its center and half-size. -/// # Panics -/// This method panics if any of the components of the half-size is negative. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r = IRect::from_center_half_size(IVec2::ZERO, IVec2::ONE); // w=2 h=2 -/// assert_eq!(r.min, IVec2::splat(-1)); -/// assert_eq!(r.max, IVec2::splat(1)); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_center_half_size( - #[proxy] - origin: bevy::math::prelude::IVec2, - #[proxy] - half_size: bevy::math::prelude::IVec2, - ) -> bevy::math::prelude::IRect; + #[lua()] + fn new( + x0: i32, + y0: i32, + x1: i32, + y1: i32, + ) -> LuaReflectValProxy; "#, r#" @@ -1387,8 +1108,8 @@ struct Dir3A(); /// assert!(r.is_empty()); /// ``` - #[lua(kind = "Method")] - fn is_empty(&self) -> bool; + #[lua()] + fn is_empty(_self: LuaReflectRefProxy) -> bool; "#, r#" @@ -1400,8 +1121,8 @@ struct Dir3A(); /// assert_eq!(r.width(), 5); /// ``` - #[lua(kind = "Method")] - fn width(&self) -> i32; + #[lua()] + fn width(_self: LuaReflectRefProxy) -> i32; "#, r#" @@ -1413,66 +1134,8 @@ struct Dir3A(); /// assert_eq!(r.height(), 1); /// ``` - #[lua(kind = "Method")] - fn height(&self) -> i32; - -"#, - r#" -/// Rectangle size. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 -/// assert_eq!(r.size(), IVec2::new(5, 1)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn size(&self) -> bevy::math::prelude::IVec2; - -"#, - r#" -/// Rectangle half-size. -/// # Rounding Behavior -/// If the full size contains odd numbers they will be rounded down to the nearest whole number when calculating the half size. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r = IRect::new(0, 0, 4, 3); // w=4 h=3 -/// assert_eq!(r.half_size(), IVec2::new(2, 1)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn half_size(&self) -> bevy::math::prelude::IVec2; - -"#, - r#" -/// The center point of the rectangle. -/// # Rounding Behavior -/// If the (min + max) contains odd numbers they will be rounded down to the nearest whole number when calculating the center. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r = IRect::new(0, 0, 5, 2); // w=5 h=2 -/// assert_eq!(r.center(), IVec2::new(2, 1)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn center(&self) -> bevy::math::prelude::IVec2; - -"#, - r#" -/// Check if a point lies within this rectangle, inclusive of its edges. -/// # Examples -/// ``` -/// # use bevy_math::IRect; -/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 -/// assert!(r.contains(r.center())); -/// assert!(r.contains(r.min)); -/// assert!(r.contains(r.max)); -/// ``` - - #[lua(kind = "Method")] - fn contains(&self, #[proxy] point: bevy::math::prelude::IVec2) -> bool; + #[lua()] + fn height(_self: LuaReflectRefProxy) -> i32; "#, r#" @@ -1488,33 +1151,11 @@ struct Dir3A(); /// assert_eq!(r.max, IVec2::new(5, 3)); /// ``` - #[lua(kind = "Method", output(proxy))] + #[lua()] fn union( - &self, - #[proxy] - other: bevy::math::prelude::IRect, - ) -> bevy::math::prelude::IRect; - -"#, - r#" -/// Build a new rectangle formed of the union of this rectangle and a point. -/// The union is the smallest rectangle enclosing both the rectangle and the point. If the -/// point is already inside the rectangle, this method returns a copy of the rectangle. -/// # Examples -/// ``` -/// # use bevy_math::{IRect, IVec2}; -/// let r = IRect::new(0, 0, 5, 1); // w=5 h=1 -/// let u = r.union_point(IVec2::new(3, 6)); -/// assert_eq!(u.min, IVec2::ZERO); -/// assert_eq!(u.max, IVec2::new(5, 6)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn union_point( - &self, - #[proxy] - other: bevy::math::prelude::IVec2, - ) -> bevy::math::prelude::IRect; + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1532,12 +1173,11 @@ struct Dir3A(); /// assert_eq!(r.max, IVec2::new(3, 1)); /// ``` - #[lua(kind = "Method", output(proxy))] + #[lua()] fn intersect( - &self, - #[proxy] - other: bevy::math::prelude::IRect, - ) -> bevy::math::prelude::IRect; + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1558,234 +1198,132 @@ struct Dir3A(); /// assert_eq!(r2.max, IVec2::new(3, 2)); /// ``` - #[lua(kind = "Method", output(proxy))] - fn inflate(&self, expansion: i32) -> bevy::math::prelude::IRect; + #[lua()] + fn inflate( + _self: LuaReflectRefProxy, + expansion: i32, + ) -> LuaReflectValProxy; "#, r#" /// Returns self as [`Rect`] (f32) - #[lua(kind = "Method", output(proxy))] - fn as_rect(&self) -> bevy::math::prelude::Rect; + #[lua()] + fn as_rect( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns self as [`URect`] (u32) - #[lua(kind = "Method", output(proxy))] - fn as_urect(&self) -> bevy::math::prelude::URect; + #[lua()] + fn as_urect( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &rects::irect::IRect) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::prelude::IRect; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -struct IRect { - #[lua(output(proxy))] - min: bevy::math::prelude::IVec2, - #[lua(output(proxy))] - max: bevy::math::prelude::IVec2, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy( - derive(clone), - remote = "bevy::math::prelude::Rect", - functions[r#" -/// Create a new rectangle from two corner points. -/// The two points do not need to be the minimum and/or maximum corners. -/// They only need to be two opposite corners. -/// # Examples -/// ``` -/// # use bevy_math::Rect; -/// let r = Rect::new(0., 4., 10., 6.); // w=10 h=2 -/// let r = Rect::new(2., 3., 5., -1.); // w=3 h=4 -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn new(x0: f32, y0: f32, x1: f32, y1: f32) -> bevy::math::prelude::Rect; - -"#, - r#" -/// Create a new rectangle from two corner points. -/// The two points do not need to be the minimum and/or maximum corners. -/// They only need to be two opposite corners. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// // Unit rect from [0,0] to [1,1] -/// let r = Rect::from_corners(Vec2::ZERO, Vec2::ONE); // w=1 h=1 -/// // Same; the points do not need to be ordered -/// let r = Rect::from_corners(Vec2::ONE, Vec2::ZERO); // w=1 h=1 -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_corners( - #[proxy] - p0: bevy::math::prelude::Vec2, - #[proxy] - p1: bevy::math::prelude::Vec2, - ) -> bevy::math::prelude::Rect; - -"#, - r#" -/// Create a new rectangle from its center and size. -/// # Panics -/// This method panics if any of the components of the size is negative. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r = Rect::from_center_size(Vec2::ZERO, Vec2::ONE); // w=1 h=1 -/// assert!(r.min.abs_diff_eq(Vec2::splat(-0.5), 1e-5)); -/// assert!(r.max.abs_diff_eq(Vec2::splat(0.5), 1e-5)); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_center_size( - #[proxy] - origin: bevy::math::prelude::Vec2, - #[proxy] - size: bevy::math::prelude::Vec2, - ) -> bevy::math::prelude::Rect; - -"#, - r#" -/// Create a new rectangle from its center and half-size. -/// # Panics -/// This method panics if any of the components of the half-size is negative. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r = Rect::from_center_half_size(Vec2::ZERO, Vec2::ONE); // w=2 h=2 -/// assert!(r.min.abs_diff_eq(Vec2::splat(-1.), 1e-5)); -/// assert!(r.max.abs_diff_eq(Vec2::splat(1.), 1e-5)); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_center_half_size( - #[proxy] - origin: bevy::math::prelude::Vec2, - #[proxy] - half_size: bevy::math::prelude::Vec2, - ) -> bevy::math::prelude::Rect; - -"#, - r#" -/// Check if the rectangle is empty. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r = Rect::from_corners(Vec2::ZERO, Vec2::new(0., 1.)); // w=0 h=1 -/// assert!(r.is_empty()); -/// ``` - - #[lua(kind = "Method")] - fn is_empty(&self) -> bool; - -"#, - r#" -/// Rectangle width (max.x - min.x). -/// # Examples -/// ``` -/// # use bevy_math::Rect; -/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// assert!((r.width() - 5.).abs() <= 1e-5); -/// ``` +"#, + r#" - #[lua(kind = "Method")] - fn width(&self) -> f32; + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -/// Rectangle height (max.y - min.y). -/// # Examples -/// ``` -/// # use bevy_math::Rect; -/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// assert!((r.height() - 1.).abs() <= 1e-5); -/// ``` - #[lua(kind = "Method")] - fn height(&self) -> f32; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Rectangle size. +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct IRect { + min: ReflectReference, + max: ReflectReference, +} +#[derive(bevy_mod_scripting_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::prelude::Rect", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" +/// Create a new rectangle from two corner points. +/// The two points do not need to be the minimum and/or maximum corners. +/// They only need to be two opposite corners. /// # Examples /// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// assert!(r.size().abs_diff_eq(Vec2::new(5., 1.), 1e-5)); +/// # use bevy_math::Rect; +/// let r = Rect::new(0., 4., 10., 6.); // w=10 h=2 +/// let r = Rect::new(2., 3., 5., -1.); // w=3 h=4 /// ``` - #[lua(kind = "Method", output(proxy))] - fn size(&self) -> bevy::math::prelude::Vec2; + #[lua()] + fn new( + x0: f32, + y0: f32, + x1: f32, + y1: f32, + ) -> LuaReflectValProxy; "#, r#" -/// Rectangle half-size. +/// Check if the rectangle is empty. /// # Examples /// ``` /// # use bevy_math::{Rect, Vec2}; -/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// assert!(r.half_size().abs_diff_eq(Vec2::new(2.5, 0.5), 1e-5)); +/// let r = Rect::from_corners(Vec2::ZERO, Vec2::new(0., 1.)); // w=0 h=1 +/// assert!(r.is_empty()); /// ``` - #[lua(kind = "Method", output(proxy))] - fn half_size(&self) -> bevy::math::prelude::Vec2; + #[lua()] + fn is_empty(_self: LuaReflectRefProxy) -> bool; "#, r#" -/// The center point of the rectangle. +/// Rectangle width (max.x - min.x). /// # Examples /// ``` -/// # use bevy_math::{Rect, Vec2}; +/// # use bevy_math::Rect; /// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// assert!(r.center().abs_diff_eq(Vec2::new(2.5, 0.5), 1e-5)); +/// assert!((r.width() - 5.).abs() <= 1e-5); /// ``` - #[lua(kind = "Method", output(proxy))] - fn center(&self) -> bevy::math::prelude::Vec2; + #[lua()] + fn width(_self: LuaReflectRefProxy) -> f32; "#, r#" -/// Check if a point lies within this rectangle, inclusive of its edges. +/// Rectangle height (max.y - min.y). /// # Examples /// ``` /// # use bevy_math::Rect; /// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// assert!(r.contains(r.center())); -/// assert!(r.contains(r.min)); -/// assert!(r.contains(r.max)); +/// assert!((r.height() - 1.).abs() <= 1e-5); /// ``` - #[lua(kind = "Method")] - fn contains(&self, #[proxy] point: bevy::math::prelude::Vec2) -> bool; + #[lua()] + fn height(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -1801,33 +1339,11 @@ struct IRect { /// assert!(r.max.abs_diff_eq(Vec2::new(5., 3.), 1e-5)); /// ``` - #[lua(kind = "Method", output(proxy))] + #[lua()] fn union( - &self, - #[proxy] - other: bevy::math::prelude::Rect, - ) -> bevy::math::prelude::Rect; - -"#, - r#" -/// Build a new rectangle formed of the union of this rectangle and a point. -/// The union is the smallest rectangle enclosing both the rectangle and the point. If the -/// point is already inside the rectangle, this method returns a copy of the rectangle. -/// # Examples -/// ``` -/// # use bevy_math::{Rect, Vec2}; -/// let r = Rect::new(0., 0., 5., 1.); // w=5 h=1 -/// let u = r.union_point(Vec2::new(3., 6.)); -/// assert!(u.min.abs_diff_eq(Vec2::ZERO, 1e-5)); -/// assert!(u.max.abs_diff_eq(Vec2::new(5., 6.), 1e-5)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn union_point( - &self, - #[proxy] - other: bevy::math::prelude::Vec2, - ) -> bevy::math::prelude::Rect; + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1845,12 +1361,11 @@ struct IRect { /// assert!(r.max.abs_diff_eq(Vec2::new(3., 1.), 1e-5)); /// ``` - #[lua(kind = "Method", output(proxy))] + #[lua()] fn intersect( - &self, - #[proxy] - other: bevy::math::prelude::Rect, - ) -> bevy::math::prelude::Rect; + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1871,8 +1386,11 @@ struct IRect { /// assert!(r2.max.abs_diff_eq(Vec2::new(4., 5.), 1e-5)); /// ``` - #[lua(kind = "Method", output(proxy))] - fn inflate(&self, expansion: f32) -> bevy::math::prelude::Rect; + #[lua()] + fn inflate( + _self: LuaReflectRefProxy, + expansion: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -1890,83 +1408,93 @@ struct IRect { /// assert_eq!(n.max.y, 0.6); /// ``` - #[lua(kind = "Method", output(proxy))] + #[lua()] fn normalize( - &self, - #[proxy] - other: bevy::math::prelude::Rect, - ) -> bevy::math::prelude::Rect; + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns self as [`IRect`] (i32) - #[lua(kind = "Method", output(proxy))] - fn as_irect(&self) -> bevy::math::prelude::IRect; + #[lua()] + fn as_irect( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns self as [`URect`] (u32) - #[lua(kind = "Method", output(proxy))] - fn as_urect(&self) -> bevy::math::prelude::URect; + #[lua()] + fn as_urect( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &rects::rect::Rect) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::prelude::Rect; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Rect { - #[lua(output(proxy))] - min: bevy::math::prelude::Vec2, - #[lua(output(proxy))] - max: bevy::math::prelude::Vec2, +pub struct Rect { + min: ReflectReference, + max: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::prelude::URect", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::prelude::URect; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &rects::urect::URect) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" @@ -1980,74 +1508,13 @@ struct Rect { /// let r = URect::new(2, 4, 5, 0); // w=3 h=4 /// ``` - #[lua(kind = "Function", output(proxy))] - fn new(x0: u32, y0: u32, x1: u32, y1: u32) -> bevy::math::prelude::URect; - -"#, - r#" -/// Create a new rectangle from two corner points. -/// The two points do not need to be the minimum and/or maximum corners. -/// They only need to be two opposite corners. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// // Unit rect from [0,0] to [1,1] -/// let r = URect::from_corners(UVec2::ZERO, UVec2::ONE); // w=1 h=1 -/// // Same; the points do not need to be ordered -/// let r = URect::from_corners(UVec2::ONE, UVec2::ZERO); // w=1 h=1 -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_corners( - #[proxy] - p0: bevy::math::prelude::UVec2, - #[proxy] - p1: bevy::math::prelude::UVec2, - ) -> bevy::math::prelude::URect; - -"#, - r#" -/// Create a new rectangle from its center and size. -/// # Rounding Behavior -/// If the size contains odd numbers they will be rounded down to the nearest whole number. -/// # Panics -/// This method panics if any of the components of the size is negative or if `origin - (size / 2)` results in any negatives. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r = URect::from_center_size(UVec2::ONE, UVec2::splat(2)); // w=2 h=2 -/// assert_eq!(r.min, UVec2::splat(0)); -/// assert_eq!(r.max, UVec2::splat(2)); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_center_size( - #[proxy] - origin: bevy::math::prelude::UVec2, - #[proxy] - size: bevy::math::prelude::UVec2, - ) -> bevy::math::prelude::URect; - -"#, - r#" -/// Create a new rectangle from its center and half-size. -/// # Panics -/// This method panics if any of the components of the half-size is negative or if `origin - half_size` results in any negatives. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r = URect::from_center_half_size(UVec2::ONE, UVec2::ONE); // w=2 h=2 -/// assert_eq!(r.min, UVec2::splat(0)); -/// assert_eq!(r.max, UVec2::splat(2)); -/// ``` - - #[lua(kind = "Function", output(proxy))] - fn from_center_half_size( - #[proxy] - origin: bevy::math::prelude::UVec2, - #[proxy] - half_size: bevy::math::prelude::UVec2, - ) -> bevy::math::prelude::URect; + #[lua()] + fn new( + x0: u32, + y0: u32, + x1: u32, + y1: u32, + ) -> LuaReflectValProxy; "#, r#" @@ -2059,8 +1526,8 @@ struct Rect { /// assert!(r.is_empty()); /// ``` - #[lua(kind = "Method")] - fn is_empty(&self) -> bool; + #[lua()] + fn is_empty(_self: LuaReflectRefProxy) -> bool; "#, r#" @@ -2072,8 +1539,8 @@ struct Rect { /// assert_eq!(r.width(), 5); /// ``` - #[lua(kind = "Method")] - fn width(&self) -> u32; + #[lua()] + fn width(_self: LuaReflectRefProxy) -> u32; "#, r#" @@ -2085,66 +1552,8 @@ struct Rect { /// assert_eq!(r.height(), 1); /// ``` - #[lua(kind = "Method")] - fn height(&self) -> u32; - -"#, - r#" -/// Rectangle size. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 -/// assert_eq!(r.size(), UVec2::new(5, 1)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn size(&self) -> bevy::math::prelude::UVec2; - -"#, - r#" -/// Rectangle half-size. -/// # Rounding Behavior -/// If the full size contains odd numbers they will be rounded down to the nearest whole number when calculating the half size. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r = URect::new(0, 0, 4, 2); // w=4 h=2 -/// assert_eq!(r.half_size(), UVec2::new(2, 1)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn half_size(&self) -> bevy::math::prelude::UVec2; - -"#, - r#" -/// The center point of the rectangle. -/// # Rounding Behavior -/// If the (min + max) contains odd numbers they will be rounded down to the nearest whole number when calculating the center. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r = URect::new(0, 0, 4, 2); // w=4 h=2 -/// assert_eq!(r.center(), UVec2::new(2, 1)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn center(&self) -> bevy::math::prelude::UVec2; - -"#, - r#" -/// Check if a point lies within this rectangle, inclusive of its edges. -/// # Examples -/// ``` -/// # use bevy_math::URect; -/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 -/// assert!(r.contains(r.center())); -/// assert!(r.contains(r.min)); -/// assert!(r.contains(r.max)); -/// ``` - - #[lua(kind = "Method")] - fn contains(&self, #[proxy] point: bevy::math::prelude::UVec2) -> bool; + #[lua()] + fn height(_self: LuaReflectRefProxy) -> u32; "#, r#" @@ -2160,33 +1569,11 @@ struct Rect { /// assert_eq!(r.max, UVec2::new(5, 8)); /// ``` - #[lua(kind = "Method", output(proxy))] + #[lua()] fn union( - &self, - #[proxy] - other: bevy::math::prelude::URect, - ) -> bevy::math::prelude::URect; - -"#, - r#" -/// Build a new rectangle formed of the union of this rectangle and a point. -/// The union is the smallest rectangle enclosing both the rectangle and the point. If the -/// point is already inside the rectangle, this method returns a copy of the rectangle. -/// # Examples -/// ``` -/// # use bevy_math::{URect, UVec2}; -/// let r = URect::new(0, 0, 5, 1); // w=5 h=1 -/// let u = r.union_point(UVec2::new(3, 6)); -/// assert_eq!(u.min, UVec2::ZERO); -/// assert_eq!(u.max, UVec2::new(5, 6)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn union_point( - &self, - #[proxy] - other: bevy::math::prelude::UVec2, - ) -> bevy::math::prelude::URect; + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2204,12 +1591,11 @@ struct Rect { /// assert_eq!(r.max, UVec2::new(2, 2)); /// ``` - #[lua(kind = "Method", output(proxy))] + #[lua()] fn intersect( - &self, - #[proxy] - other: bevy::math::prelude::URect, - ) -> bevy::math::prelude::URect; + _self: LuaReflectRefProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2230,375 +1616,309 @@ struct Rect { /// assert_eq!(r2.max, UVec2::splat(7)); /// ``` - #[lua(kind = "Method", output(proxy))] - fn inflate(&self, expansion: i32) -> bevy::math::prelude::URect; + #[lua()] + fn inflate( + _self: LuaReflectRefProxy, + expansion: i32, + ) -> LuaReflectValProxy; "#, r#" /// Returns self as [`Rect`] (f32) - #[lua(kind = "Method", output(proxy))] - fn as_rect(&self) -> bevy::math::prelude::Rect; + #[lua()] + fn as_rect( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns self as [`IRect`] (i32) - #[lua(kind = "Method", output(proxy))] - fn as_irect(&self) -> bevy::math::prelude::IRect; + #[lua()] + fn as_irect( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct URect { - #[lua(output(proxy))] - min: bevy::math::prelude::UVec2, - #[lua(output(proxy))] - max: bevy::math::prelude::UVec2, +pub struct URect { + min: ReflectReference, + max: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] -#[proxy(derive(), remote = "bevy::math::Affine3", functions[])] -struct Affine3 { - #[lua(output(proxy))] - matrix3: bevy::math::prelude::Mat3, - #[lua(output(proxy))] - translation: bevy::math::prelude::Vec3, +#[derive(bevy_mod_scripting_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::Affine3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[] +)] +pub struct Affine3 { + matrix3: ReflectReference, + translation: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::bounding::Aabb2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::bounding::Aabb2d; - -"#, - r#" -/// Constructs an AABB from its center and half-size. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - center: bevy::math::prelude::Vec2, - #[proxy] - half_size: bevy::math::prelude::Vec2, - ) -> bevy::math::bounding::Aabb2d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the smallest [`BoundingCircle`] containing this [`Aabb2d`]. - #[lua(kind = "Method", output(proxy))] - fn bounding_circle(&self) -> bevy::math::bounding::BoundingCircle; + #[lua()] + fn bounding_circle( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Finds the point on the AABB that is closest to the given `point`. -/// If the point is outside the AABB, the returned point will be on the perimeter of the AABB. -/// Otherwise, it will be inside the AABB and returned as is. - - #[lua(kind = "Method", output(proxy))] - fn closest_point( - &self, - #[proxy] - point: bevy::math::prelude::Vec2, - ) -> bevy::math::prelude::Vec2; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Aabb2d { - #[lua(output(proxy))] - min: bevy::math::prelude::Vec2, - #[lua(output(proxy))] - max: bevy::math::prelude::Vec2, +pub struct Aabb2d { + min: ReflectReference, + max: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::bounding::BoundingCircle", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" -/// Constructs a bounding circle from its center and radius. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - center: bevy::math::prelude::Vec2, - radius: f32, - ) -> bevy::math::bounding::BoundingCircle; - -"#, - r#" /// Get the radius of the bounding circle - #[lua(kind = "Method")] - fn radius(&self) -> f32; + #[lua()] + fn radius(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Computes the smallest [`Aabb2d`] containing this [`BoundingCircle`]. - #[lua(kind = "Method", output(proxy))] - fn aabb_2d(&self) -> bevy::math::bounding::Aabb2d; - -"#, - r#" -/// Finds the point on the bounding circle that is closest to the given `point`. -/// If the point is outside the circle, the returned point will be on the perimeter of the circle. -/// Otherwise, it will be inside the circle and returned as is. - - #[lua(kind = "Method", output(proxy))] - fn closest_point( - &self, - #[proxy] - point: bevy::math::prelude::Vec2, - ) -> bevy::math::prelude::Vec2; + #[lua()] + fn aabb_2d( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::bounding::BoundingCircle; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct BoundingCircle { - #[lua(output(proxy))] - center: bevy::math::prelude::Vec2, - #[lua(output(proxy))] +pub struct BoundingCircle { + center: ReflectReference, circle: bevy::math::primitives::Circle, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Circle", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Create a new [`Circle`] from a `radius` - #[lua(kind = "Function", output(proxy))] - fn new(radius: f32) -> bevy::math::primitives::Circle; + #[lua()] + fn new(radius: f32) -> LuaReflectValProxy; "#, r#" /// Get the diameter of the circle - #[lua(kind = "Method")] - fn diameter(&self) -> f32; - -"#, - r#" -/// Finds the point on the circle that is closest to the given `point`. -/// If the point is outside the circle, the returned point will be on the perimeter of the circle. -/// Otherwise, it will be inside the circle and returned as is. - - #[lua(kind = "Method", output(proxy))] - fn closest_point( - &self, - #[proxy] - point: bevy::math::prelude::Vec2, - ) -> bevy::math::prelude::Vec2; + #[lua()] + fn diameter(_self: LuaReflectRefProxy) -> f32; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Circle; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim2::Circle) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Circle { +pub struct Circle { radius: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Annulus", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Annulus; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim2::Annulus) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Create a new [`Annulus`] from the radii of the inner and outer circle - #[lua(kind = "Function", output(proxy))] - fn new(inner_radius: f32, outer_radius: f32) -> bevy::math::primitives::Annulus; + #[lua()] + fn new( + inner_radius: f32, + outer_radius: f32, + ) -> LuaReflectValProxy; "#, r#" /// Get the diameter of the annulus - #[lua(kind = "Method")] - fn diameter(&self) -> f32; + #[lua()] + fn diameter(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Get the thickness of the annulus - #[lua(kind = "Method")] - fn thickness(&self) -> f32; - -"#, - r#" -/// Finds the point on the annulus that is closest to the given `point`: -/// - If the point is outside of the annulus completely, the returned point will be on the outer perimeter. -/// - If the point is inside of the inner circle (hole) of the annulus, the returned point will be on the inner perimeter. -/// - Otherwise, the returned point is overlapping the annulus and returned as is. - - #[lua(kind = "Method", output(proxy))] - fn closest_point( - &self, - #[proxy] - point: bevy::math::prelude::Vec2, - ) -> bevy::math::prelude::Vec2; + #[lua()] + fn thickness(_self: LuaReflectRefProxy) -> f32; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Annulus { - #[lua(output(proxy))] +pub struct Annulus { inner_circle: bevy::math::primitives::Circle, - #[lua(output(proxy))] outer_circle: bevy::math::primitives::Circle, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Arc2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Create a new [`Arc2d`] from a `radius` and a `half_angle` - #[lua(kind = "Function", output(proxy))] - fn new(radius: f32, half_angle: f32) -> bevy::math::primitives::Arc2d; + #[lua()] + fn new( + radius: f32, + half_angle: f32, + ) -> LuaReflectValProxy; "#, r#" /// Create a new [`Arc2d`] from a `radius` and an `angle` in radians - #[lua(kind = "Function", output(proxy))] - fn from_radians(radius: f32, angle: f32) -> bevy::math::primitives::Arc2d; + #[lua()] + fn from_radians( + radius: f32, + angle: f32, + ) -> LuaReflectValProxy; "#, r#" /// Create a new [`Arc2d`] from a `radius` and an `angle` in degrees. - #[lua(kind = "Function", output(proxy))] - fn from_degrees(radius: f32, angle: f32) -> bevy::math::primitives::Arc2d; + #[lua()] + fn from_degrees( + radius: f32, + angle: f32, + ) -> LuaReflectValProxy; "#, r#" /// Create a new [`Arc2d`] from a `radius` and a `fraction` of a single turn. /// For instance, `0.5` turns is a semicircle. - #[lua(kind = "Function", output(proxy))] - fn from_turns(radius: f32, fraction: f32) -> bevy::math::primitives::Arc2d; + #[lua()] + fn from_turns( + radius: f32, + fraction: f32, + ) -> LuaReflectValProxy; "#, r#" /// Get the angle of the arc - #[lua(kind = "Method")] - fn angle(&self) -> f32; + #[lua()] + fn angle(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Get the length of the arc - #[lua(kind = "Method")] - fn length(&self) -> f32; - -"#, - r#" -/// Get the right-hand end point of the arc - - #[lua(kind = "Method", output(proxy))] - fn right_endpoint(&self) -> bevy::math::prelude::Vec2; - -"#, - r#" -/// Get the left-hand end point of the arc - - #[lua(kind = "Method", output(proxy))] - fn left_endpoint(&self) -> bevy::math::prelude::Vec2; - -"#, - r#" -/// Get the midpoint of the arc - - #[lua(kind = "Method", output(proxy))] - fn midpoint(&self) -> bevy::math::prelude::Vec2; + #[lua()] + fn length(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Get half the distance between the endpoints (half the length of the chord) - #[lua(kind = "Method")] - fn half_chord_length(&self) -> f32; + #[lua()] + fn half_chord_length( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" /// Get the distance between the endpoints (the length of the chord) - #[lua(kind = "Method")] - fn chord_length(&self) -> f32; - -"#, - r#" -/// Get the midpoint of the two endpoints (the midpoint of the chord) - - #[lua(kind = "Method", output(proxy))] - fn chord_midpoint(&self) -> bevy::math::prelude::Vec2; + #[lua()] + fn chord_length(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -2607,8 +1927,8 @@ struct Annulus { /// Equivalently, the [`radius`](Self::radius) minus the [`sagitta`](Self::sagitta). /// Note that for a [`major`](Self::is_major) arc, the apothem will be negative. - #[lua(kind = "Method")] - fn apothem(&self) -> f32; + #[lua()] + fn apothem(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -2617,326 +1937,370 @@ struct Annulus { /// Equivalently, the height of the triangle whose base is the chord and whose apex is the midpoint of the arc. /// The sagitta is also the sum of the [`radius`](Self::radius) and the [`apothem`](Self::apothem). - #[lua(kind = "Method")] - fn sagitta(&self) -> f32; + #[lua()] + fn sagitta(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Produces true if the arc is at most half a circle. /// **Note:** This is not the negation of [`is_major`](Self::is_major): an exact semicircle is both major and minor. - #[lua(kind = "Method")] - fn is_minor(&self) -> bool; + #[lua()] + fn is_minor(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Produces true if the arc is at least half a circle. /// **Note:** This is not the negation of [`is_minor`](Self::is_minor): an exact semicircle is both major and minor. - #[lua(kind = "Method")] - fn is_major(&self) -> bool; + #[lua()] + fn is_major(_self: LuaReflectRefProxy) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Arc2d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim2::Arc2d) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Arc2d { +pub struct Arc2d { radius: f32, half_angle: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Capsule2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim2::Capsule2d) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Create a new `Capsule2d` from a radius and length - #[lua(kind = "Function", output(proxy))] - fn new(radius: f32, length: f32) -> bevy::math::primitives::Capsule2d; + #[lua()] + fn new( + radius: f32, + length: f32, + ) -> LuaReflectValProxy; "#, r#" /// Get the part connecting the semicircular ends of the capsule as a [`Rectangle`] - #[lua(kind = "Method", output(proxy))] - fn to_inner_rectangle(&self) -> bevy::math::primitives::Rectangle; + #[lua()] + fn to_inner_rectangle( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Capsule2d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Capsule2d { +pub struct Capsule2d { radius: f32, half_length: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::CircularSector", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Create a new [`CircularSector`] from a `radius` and an `angle` - #[lua(kind = "Function", output(proxy))] - fn new(radius: f32, angle: f32) -> bevy::math::primitives::CircularSector; + #[lua()] + fn new( + radius: f32, + angle: f32, + ) -> LuaReflectValProxy; "#, r#" /// Create a new [`CircularSector`] from a `radius` and an `angle` in radians. - #[lua(kind = "Function", output(proxy))] - fn from_radians(radius: f32, angle: f32) -> bevy::math::primitives::CircularSector; + #[lua()] + fn from_radians( + radius: f32, + angle: f32, + ) -> LuaReflectValProxy; "#, r#" /// Create a new [`CircularSector`] from a `radius` and an `angle` in degrees. - #[lua(kind = "Function", output(proxy))] - fn from_degrees(radius: f32, angle: f32) -> bevy::math::primitives::CircularSector; + #[lua()] + fn from_degrees( + radius: f32, + angle: f32, + ) -> LuaReflectValProxy; "#, r#" /// Create a new [`CircularSector`] from a `radius` and a number of `turns` of a circle. /// For instance, `0.5` turns is a semicircle. - #[lua(kind = "Function", output(proxy))] - fn from_turns(radius: f32, fraction: f32) -> bevy::math::primitives::CircularSector; + #[lua()] + fn from_turns( + radius: f32, + fraction: f32, + ) -> LuaReflectValProxy; "#, r#" /// Get half the angle of the sector - #[lua(kind = "Method")] - fn half_angle(&self) -> f32; + #[lua()] + fn half_angle( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" /// Get the angle of the sector - #[lua(kind = "Method")] - fn angle(&self) -> f32; + #[lua()] + fn angle(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Get the radius of the sector - #[lua(kind = "Method")] - fn radius(&self) -> f32; + #[lua()] + fn radius(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Get the length of the arc defining the sector - #[lua(kind = "Method")] - fn arc_length(&self) -> f32; + #[lua()] + fn arc_length( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" /// Get half the length of the chord defined by the sector /// See [`Arc2d::half_chord_length`] - #[lua(kind = "Method")] - fn half_chord_length(&self) -> f32; + #[lua()] + fn half_chord_length( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" /// Get the length of the chord defined by the sector /// See [`Arc2d::chord_length`] - #[lua(kind = "Method")] - fn chord_length(&self) -> f32; - -"#, - r#" -/// Get the midpoint of the chord defined by the sector -/// See [`Arc2d::chord_midpoint`] - - #[lua(kind = "Method", output(proxy))] - fn chord_midpoint(&self) -> bevy::math::prelude::Vec2; + #[lua()] + fn chord_length( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" /// Get the length of the apothem of this sector /// See [`Arc2d::apothem`] - #[lua(kind = "Method")] - fn apothem(&self) -> f32; + #[lua()] + fn apothem(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Get the length of the sagitta of this sector /// See [`Arc2d::sagitta`] - #[lua(kind = "Method")] - fn sagitta(&self) -> f32; + #[lua()] + fn sagitta(_self: LuaReflectRefProxy) -> f32; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::CircularSector; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim2::CircularSector) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct CircularSector { - #[lua(output(proxy))] +pub struct CircularSector { arc: bevy::math::primitives::Arc2d, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::CircularSegment", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::CircularSegment; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim2::CircularSegment) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Create a new [`CircularSegment`] from a `radius`, and an `angle` - #[lua(kind = "Function", output(proxy))] - fn new(radius: f32, angle: f32) -> bevy::math::primitives::CircularSegment; + #[lua()] + fn new( + radius: f32, + angle: f32, + ) -> LuaReflectValProxy; "#, r#" /// Create a new [`CircularSegment`] from a `radius` and an `angle` in radians. - #[lua(kind = "Function", output(proxy))] - fn from_radians(radius: f32, angle: f32) -> bevy::math::primitives::CircularSegment; + #[lua()] + fn from_radians( + radius: f32, + angle: f32, + ) -> LuaReflectValProxy; "#, r#" /// Create a new [`CircularSegment`] from a `radius` and an `angle` in degrees. - #[lua(kind = "Function", output(proxy))] - fn from_degrees(radius: f32, angle: f32) -> bevy::math::primitives::CircularSegment; + #[lua()] + fn from_degrees( + radius: f32, + angle: f32, + ) -> LuaReflectValProxy; "#, r#" /// Create a new [`CircularSegment`] from a `radius` and a number of `turns` of a circle. /// For instance, `0.5` turns is a semicircle. - #[lua(kind = "Function", output(proxy))] - fn from_turns(radius: f32, fraction: f32) -> bevy::math::primitives::CircularSegment; + #[lua()] + fn from_turns( + radius: f32, + fraction: f32, + ) -> LuaReflectValProxy; "#, r#" /// Get the half-angle of the segment - #[lua(kind = "Method")] - fn half_angle(&self) -> f32; + #[lua()] + fn half_angle( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" /// Get the angle of the segment - #[lua(kind = "Method")] - fn angle(&self) -> f32; + #[lua()] + fn angle(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Get the radius of the segment - #[lua(kind = "Method")] - fn radius(&self) -> f32; + #[lua()] + fn radius(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Get the length of the arc defining the segment - #[lua(kind = "Method")] - fn arc_length(&self) -> f32; + #[lua()] + fn arc_length( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" /// Get half the length of the segment's base, also known as its chord - #[lua(kind = "Method")] - fn half_chord_length(&self) -> f32; + #[lua()] + fn half_chord_length( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" /// Get the length of the segment's base, also known as its chord - #[lua(kind = "Method")] - fn chord_length(&self) -> f32; - -"#, - r#" -/// Get the midpoint of the segment's base, also known as its chord - - #[lua(kind = "Method", output(proxy))] - fn chord_midpoint(&self) -> bevy::math::prelude::Vec2; + #[lua()] + fn chord_length( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" @@ -2944,67 +2308,66 @@ struct CircularSector { /// which is the signed distance between the segment and the center of its circle /// See [`Arc2d::apothem`] - #[lua(kind = "Method")] - fn apothem(&self) -> f32; + #[lua()] + fn apothem( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" /// Get the length of the sagitta of this segment, also known as its height /// See [`Arc2d::sagitta`] - #[lua(kind = "Method")] - fn sagitta(&self) -> f32; + #[lua()] + fn sagitta( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct CircularSegment { - #[lua(output(proxy))] +pub struct CircularSegment { arc: bevy::math::primitives::Arc2d, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Ellipse", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim2::Ellipse) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Ellipse; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Create a new `Ellipse` from half of its width and height. /// This corresponds to the two perpendicular radii defining the ellipse. - #[lua(kind = "Function", output(proxy))] - fn new(half_width: f32, half_height: f32) -> bevy::math::primitives::Ellipse; - -"#, - r#" -/// Create a new `Ellipse` from a given full size. -/// `size.x` is the diameter along the X axis, and `size.y` is the diameter along the Y axis. - - #[lua(kind = "Function", output(proxy))] - fn from_size( - #[proxy] - size: bevy::math::prelude::Vec2, - ) -> bevy::math::primitives::Ellipse; + #[lua()] + fn new( + half_width: f32, + half_height: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -3012,216 +2375,176 @@ struct CircularSegment { /// It can be thought of as a measure of how "stretched" or elongated the ellipse is. /// The value should be in the range [0, 1), where 0 represents a circle, and 1 represents a parabola. - #[lua(kind = "Method")] - fn eccentricity(&self) -> f32; + #[lua()] + fn eccentricity(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Get the focal length of the ellipse. This corresponds to the distance between one of the foci and the center of the ellipse. /// The focal length of an ellipse is related to its eccentricity by `eccentricity = focal_length / semi_major` - #[lua(kind = "Method")] - fn focal_length(&self) -> f32; + #[lua()] + fn focal_length(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Returns the length of the semi-major axis. This corresponds to the longest radius of the ellipse. - #[lua(kind = "Method")] - fn semi_major(&self) -> f32; + #[lua()] + fn semi_major(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Returns the length of the semi-minor axis. This corresponds to the shortest radius of the ellipse. - #[lua(kind = "Method")] - fn semi_minor(&self) -> f32; + #[lua()] + fn semi_minor(_self: LuaReflectRefProxy) -> f32; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Ellipse { - #[lua(output(proxy))] - half_size: bevy::math::prelude::Vec2, +pub struct Ellipse { + half_size: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Line2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Line2d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim2::Line2d) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Line2d { - #[lua(output(proxy))] +pub struct Line2d { direction: bevy::math::prelude::Dir2, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Plane2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Plane2d; - -"#, - r#" -/// Create a new `Plane2d` from a normal -/// # Panics -/// Panics if the given `normal` is zero (or very close to zero), or non-finite. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - normal: bevy::math::prelude::Vec2, - ) -> bevy::math::primitives::Plane2d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim2::Plane2d) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Plane2d { - #[lua(output(proxy))] +pub struct Plane2d { normal: bevy::math::prelude::Dir2, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Rectangle", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Rectangle; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim2::Rectangle) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Create a new `Rectangle` from a full width and height - #[lua(kind = "Function", output(proxy))] - fn new(width: f32, height: f32) -> bevy::math::primitives::Rectangle; - -"#, - r#" -/// Create a new `Rectangle` from a given full size - - #[lua(kind = "Function", output(proxy))] - fn from_size( - #[proxy] - size: bevy::math::prelude::Vec2, - ) -> bevy::math::primitives::Rectangle; - -"#, - r#" -/// Create a new `Rectangle` from two corner points - - #[lua(kind = "Function", output(proxy))] - fn from_corners( - #[proxy] - point1: bevy::math::prelude::Vec2, - #[proxy] - point2: bevy::math::prelude::Vec2, - ) -> bevy::math::primitives::Rectangle; + #[lua()] + fn new( + width: f32, + height: f32, + ) -> LuaReflectValProxy; "#, r#" /// Create a `Rectangle` from a single length. /// The resulting `Rectangle` will be the same size in every direction. - #[lua(kind = "Function", output(proxy))] - fn from_length(length: f32) -> bevy::math::primitives::Rectangle; - -"#, - r#" -/// Get the size of the rectangle - - #[lua(kind = "Method", output(proxy))] - fn size(&self) -> bevy::math::prelude::Vec2; - -"#, - r#" -/// Finds the point on the rectangle that is closest to the given `point`. -/// If the point is outside the rectangle, the returned point will be on the perimeter of the rectangle. -/// Otherwise, it will be inside the rectangle and returned as is. - - #[lua(kind = "Method", output(proxy))] - fn closest_point( - &self, - #[proxy] - point: bevy::math::prelude::Vec2, - ) -> bevy::math::prelude::Vec2; + #[lua()] + fn from_length(length: f32) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Rectangle { - #[lua(output(proxy))] - half_size: bevy::math::prelude::Vec2, +pub struct Rectangle { + half_size: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::RegularPolygon", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::RegularPolygon; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -3230,16 +2553,21 @@ struct Rectangle { /// # Panics /// Panics if `circumradius` is negative - #[lua(kind = "Function", output(proxy))] - fn new(circumradius: f32, sides: u32) -> bevy::math::primitives::RegularPolygon; + #[lua()] + fn new( + circumradius: f32, + sides: u32, + ) -> LuaReflectValProxy; "#, r#" /// Get the radius of the circumcircle on which all vertices /// of the regular polygon lie - #[lua(kind = "Method")] - fn circumradius(&self) -> f32; + #[lua()] + fn circumradius( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" @@ -3247,15 +2575,19 @@ struct Rectangle { /// This is the radius of the largest circle that can /// be drawn within the polygon - #[lua(kind = "Method")] - fn inradius(&self) -> f32; + #[lua()] + fn inradius( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" /// Get the length of one side of the regular polygon - #[lua(kind = "Method")] - fn side_length(&self) -> f32; + #[lua()] + fn side_length( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" @@ -3263,8 +2595,10 @@ struct Rectangle { /// This is the angle formed by two adjacent sides with points /// within the angle being in the interior of the polygon - #[lua(kind = "Method")] - fn internal_angle_degrees(&self) -> f32; + #[lua()] + fn internal_angle_degrees( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" @@ -3272,8 +2606,10 @@ struct Rectangle { /// This is the angle formed by two adjacent sides with points /// within the angle being in the interior of the polygon - #[lua(kind = "Method")] - fn internal_angle_radians(&self) -> f32; + #[lua()] + fn internal_angle_radians( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" @@ -3281,8 +2617,10 @@ struct Rectangle { /// This is the angle formed by two adjacent sides with points /// within the angle being in the exterior of the polygon - #[lua(kind = "Method")] - fn external_angle_degrees(&self) -> f32; + #[lua()] + fn external_angle_degrees( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" @@ -3290,210 +2628,180 @@ struct Rectangle { /// This is the angle formed by two adjacent sides with points /// within the angle being in the exterior of the polygon - #[lua(kind = "Method")] - fn external_angle_radians(&self) -> f32; + #[lua()] + fn external_angle_radians( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim2::RegularPolygon) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct RegularPolygon { - #[lua(output(proxy))] +pub struct RegularPolygon { circumcircle: bevy::math::primitives::Circle, sides: u32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Rhombus", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Rhombus; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim2::Rhombus) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Create a new `Rhombus` from a vertical and horizontal diagonal sizes. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn new( horizontal_diagonal: f32, vertical_diagonal: f32, - ) -> bevy::math::primitives::Rhombus; + ) -> LuaReflectValProxy; "#, r#" /// Create a new `Rhombus` from a side length with all inner angles equal. - #[lua(kind = "Function", output(proxy))] - fn from_side(side: f32) -> bevy::math::primitives::Rhombus; + #[lua()] + fn from_side(side: f32) -> LuaReflectValProxy; "#, r#" /// Create a new `Rhombus` from a given inradius with all inner angles equal. - #[lua(kind = "Function", output(proxy))] - fn from_inradius(inradius: f32) -> bevy::math::primitives::Rhombus; + #[lua()] + fn from_inradius( + inradius: f32, + ) -> LuaReflectValProxy; "#, r#" /// Get the length of each side of the rhombus - #[lua(kind = "Method")] - fn side(&self) -> f32; + #[lua()] + fn side(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Get the radius of the circumcircle on which all vertices /// of the rhombus lie - #[lua(kind = "Method")] - fn circumradius(&self) -> f32; + #[lua()] + fn circumradius(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Get the radius of the largest circle that can /// be drawn within the rhombus - #[lua(kind = "Method")] - fn inradius(&self) -> f32; - -"#, - r#" -/// Finds the point on the rhombus that is closest to the given `point`. -/// If the point is outside the rhombus, the returned point will be on the perimeter of the rhombus. -/// Otherwise, it will be inside the rhombus and returned as is. - - #[lua(kind = "Method", output(proxy))] - fn closest_point( - &self, - #[proxy] - point: bevy::math::prelude::Vec2, - ) -> bevy::math::prelude::Vec2; + #[lua()] + fn inradius(_self: LuaReflectRefProxy) -> f32; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Rhombus { - #[lua(output(proxy))] - half_diagonals: bevy::math::prelude::Vec2, +pub struct Rhombus { + half_diagonals: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Segment2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Create a new `Segment2d` from a direction and full length of the segment - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - direction: bevy::math::prelude::Dir2, - length: f32, - ) -> bevy::math::primitives::Segment2d; - -"#, - r#" -/// Get the position of the first point on the line segment - - #[lua(kind = "Method", output(proxy))] - fn point1(&self) -> bevy::math::prelude::Vec2; - -"#, - r#" -/// Get the position of the second point on the line segment - - #[lua(kind = "Method", output(proxy))] - fn point2(&self) -> bevy::math::prelude::Vec2; + #[lua()] + fn new( + direction: LuaReflectValProxy, + length: f32, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim2::Segment2d) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Segment2d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Segment2d { - #[lua(output(proxy))] +pub struct Segment2d { direction: bevy::math::prelude::Dir2, half_length: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Triangle2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim2::Triangle2d) -> bool; - -"#, - r#" -/// Create a new `Triangle2d` from points `a`, `b`, and `c` - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - a: bevy::math::prelude::Vec2, - #[proxy] - b: bevy::math::prelude::Vec2, - #[proxy] - c: bevy::math::prelude::Vec2, - ) -> bevy::math::primitives::Triangle2d; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -3501,680 +2809,614 @@ struct Segment2d { /// A triangle is degenerate if the cross product of the vectors `ab` and `ac` has a length less than `10e-7`. /// This indicates that the three vertices are collinear or nearly collinear. - #[lua(kind = "Method")] - fn is_degenerate(&self) -> bool; + #[lua()] + fn is_degenerate( + _self: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Checks if the triangle is acute, meaning all angles are less than 90 degrees - #[lua(kind = "Method")] - fn is_acute(&self) -> bool; + #[lua()] + fn is_acute(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Checks if the triangle is obtuse, meaning one angle is greater than 90 degrees - #[lua(kind = "Method")] - fn is_obtuse(&self) -> bool; + #[lua()] + fn is_obtuse(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Reverse the [`WindingOrder`] of the triangle /// by swapping the first and last vertices. - #[lua(kind = "MutatingMethod")] - fn reverse(&mut self) -> (); + #[lua()] + fn reverse(_self: LuaReflectRefMutProxy) -> (); "#, r#" /// This triangle but reversed. - #[lua(kind = "Method", output(proxy))] - fn reversed(self) -> bevy::math::primitives::Triangle2d; + #[lua()] + fn reversed( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Triangle2d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Triangle2d { - vertices: ReflectedValue, +pub struct Triangle2d { + vertices: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::bounding::Aabb3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Computes the smallest [`BoundingSphere`] containing this [`Aabb3d`]. - #[lua(kind = "Method", output(proxy))] - fn bounding_sphere(&self) -> bevy::math::bounding::BoundingSphere; + #[lua()] + fn bounding_sphere( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::bounding::Aabb3d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Aabb3d { - #[lua(output(proxy))] - min: bevy::math::Vec3A, - #[lua(output(proxy))] - max: bevy::math::Vec3A, +pub struct Aabb3d { + min: ReflectReference, + max: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::bounding::BoundingSphere", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::bounding::BoundingSphere; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Get the radius of the bounding sphere - #[lua(kind = "Method")] - fn radius(&self) -> f32; + #[lua()] + fn radius(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Computes the smallest [`Aabb3d`] containing this [`BoundingSphere`]. - #[lua(kind = "Method", output(proxy))] - fn aabb_3d(&self) -> bevy::math::bounding::Aabb3d; + #[lua()] + fn aabb_3d( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct BoundingSphere { - #[lua(output(proxy))] - center: bevy::math::Vec3A, - #[lua(output(proxy))] +pub struct BoundingSphere { + center: ReflectReference, sphere: bevy::math::primitives::Sphere, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Sphere", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Sphere; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim3::Sphere) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Create a new [`Sphere`] from a `radius` - #[lua(kind = "Function", output(proxy))] - fn new(radius: f32) -> bevy::math::primitives::Sphere; + #[lua()] + fn new(radius: f32) -> LuaReflectValProxy; "#, r#" /// Get the diameter of the sphere - #[lua(kind = "Method")] - fn diameter(&self) -> f32; - -"#, - r#" -/// Finds the point on the sphere that is closest to the given `point`. -/// If the point is outside the sphere, the returned point will be on the surface of the sphere. -/// Otherwise, it will be inside the sphere and returned as is. - - #[lua(kind = "Method", output(proxy))] - fn closest_point( - &self, - #[proxy] - point: bevy::math::prelude::Vec3, - ) -> bevy::math::prelude::Vec3; + #[lua()] + fn diameter(_self: LuaReflectRefProxy) -> f32; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Sphere { +pub struct Sphere { radius: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Cuboid", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Create a new `Cuboid` from a full x, y, and z length - #[lua(kind = "Function", output(proxy))] + #[lua()] fn new( x_length: f32, y_length: f32, z_length: f32, - ) -> bevy::math::primitives::Cuboid; - -"#, - r#" -/// Create a new `Cuboid` from a given full size - - #[lua(kind = "Function", output(proxy))] - fn from_size( - #[proxy] - size: bevy::math::prelude::Vec3, - ) -> bevy::math::primitives::Cuboid; - -"#, - r#" -/// Create a new `Cuboid` from two corner points - - #[lua(kind = "Function", output(proxy))] - fn from_corners( - #[proxy] - point1: bevy::math::prelude::Vec3, - #[proxy] - point2: bevy::math::prelude::Vec3, - ) -> bevy::math::primitives::Cuboid; + ) -> LuaReflectValProxy; "#, r#" /// Create a `Cuboid` from a single length. /// The resulting `Cuboid` will be the same size in every direction. - #[lua(kind = "Function", output(proxy))] - fn from_length(length: f32) -> bevy::math::primitives::Cuboid; - -"#, - r#" -/// Get the size of the cuboid - - #[lua(kind = "Method", output(proxy))] - fn size(&self) -> bevy::math::prelude::Vec3; - -"#, - r#" -/// Finds the point on the cuboid that is closest to the given `point`. -/// If the point is outside the cuboid, the returned point will be on the surface of the cuboid. -/// Otherwise, it will be inside the cuboid and returned as is. - - #[lua(kind = "Method", output(proxy))] - fn closest_point( - &self, - #[proxy] - point: bevy::math::prelude::Vec3, - ) -> bevy::math::prelude::Vec3; + #[lua()] + fn from_length(length: f32) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim3::Cuboid) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Cuboid; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Cuboid { - #[lua(output(proxy))] - half_size: bevy::math::prelude::Vec3, +pub struct Cuboid { + half_size: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Cylinder", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Cylinder; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Create a new `Cylinder` from a radius and full height - #[lua(kind = "Function", output(proxy))] - fn new(radius: f32, height: f32) -> bevy::math::primitives::Cylinder; + #[lua()] + fn new( + radius: f32, + height: f32, + ) -> LuaReflectValProxy; "#, r#" /// Get the base of the cylinder as a [`Circle`] - #[lua(kind = "Method", output(proxy))] - fn base(&self) -> bevy::math::primitives::Circle; + #[lua()] + fn base( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Get the surface area of the side of the cylinder, /// also known as the lateral area - #[lua(kind = "Method")] - fn lateral_area(&self) -> f32; + #[lua()] + fn lateral_area(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Get the surface area of one base of the cylinder - #[lua(kind = "Method")] - fn base_area(&self) -> f32; + #[lua()] + fn base_area(_self: LuaReflectRefProxy) -> f32; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim3::Cylinder) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Cylinder { +pub struct Cylinder { radius: f32, half_height: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Capsule3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim3::Capsule3d) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Create a new `Capsule3d` from a radius and length - #[lua(kind = "Function", output(proxy))] - fn new(radius: f32, length: f32) -> bevy::math::primitives::Capsule3d; + #[lua()] + fn new( + radius: f32, + length: f32, + ) -> LuaReflectValProxy; "#, r#" /// Get the part connecting the hemispherical ends /// of the capsule as a [`Cylinder`] - #[lua(kind = "Method", output(proxy))] - fn to_cylinder(&self) -> bevy::math::primitives::Cylinder; + #[lua()] + fn to_cylinder( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Capsule3d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Capsule3d { +pub struct Capsule3d { radius: f32, half_length: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Cone", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim3::Cone) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Cone; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Create a new [`Cone`] from a radius and height. - #[lua(kind = "Function", output(proxy))] - fn new(radius: f32, height: f32) -> bevy::math::primitives::Cone; + #[lua()] + fn new(radius: f32, height: f32) -> LuaReflectValProxy; "#, r#" /// Get the base of the cone as a [`Circle`] - #[lua(kind = "Method", output(proxy))] - fn base(&self) -> bevy::math::primitives::Circle; + #[lua()] + fn base( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Get the slant height of the cone, the length of the line segment /// connecting a point on the base to the apex - #[lua(kind = "Method")] - fn slant_height(&self) -> f32; + #[lua()] + fn slant_height(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Get the surface area of the side of the cone, /// also known as the lateral area - #[lua(kind = "Method")] - fn lateral_area(&self) -> f32; + #[lua()] + fn lateral_area(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Get the surface area of the base of the cone - #[lua(kind = "Method")] - fn base_area(&self) -> f32; + #[lua()] + fn base_area(_self: LuaReflectRefProxy) -> f32; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Cone { +pub struct Cone { radius: f32, height: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::ConicalFrustum", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::ConicalFrustum; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim3::ConicalFrustum) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct ConicalFrustum { +pub struct ConicalFrustum { radius_top: f32, radius_bottom: f32, height: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::InfinitePlane3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::InfinitePlane3d; - -"#, - r#" -/// Computes an [`Isometry3d`] which transforms points from the plane in 3D space with the given -/// `origin` to the XY-plane. -/// ## Guarantees -/// * the transformation is a [congruence] meaning it will preserve all distances and angles of -/// the transformed geometry -/// * uses the least rotation possible to transform the geometry -/// * if two geometries are transformed with the same isometry, then the relations between -/// them, like distances, are also preserved -/// * compared to projections, the transformation is lossless (up to floating point errors) -/// reversible -/// ## Non-Guarantees -/// * the rotation used is generally not unique -/// * the orientation of the transformed geometry in the XY plane might be arbitrary, to -/// enforce some kind of alignment the user has to use an extra transformation ontop of this -/// one -/// See [`isometries_xy`] for example usescases. -/// [congruence]: https://en.wikipedia.org/wiki/Congruence_(geometry) -/// [`isometries_xy`]: `InfinitePlane3d::isometries_xy` - - #[lua(kind = "Method", output(proxy))] - fn isometry_into_xy( - &self, - #[proxy] - origin: bevy::math::prelude::Vec3, - ) -> bevy::math::Isometry3d; - -"#, - r#" -/// Computes an [`Isometry3d`] which transforms points from the XY-plane to this plane with the -/// given `origin`. -/// ## Guarantees -/// * the transformation is a [congruence] meaning it will preserve all distances and angles of -/// the transformed geometry -/// * uses the least rotation possible to transform the geometry -/// * if two geometries are transformed with the same isometry, then the relations between -/// them, like distances, are also preserved -/// * compared to projections, the transformation is lossless (up to floating point errors) -/// reversible -/// ## Non-Guarantees -/// * the rotation used is generally not unique -/// * the orientation of the transformed geometry in the XY plane might be arbitrary, to -/// enforce some kind of alignment the user has to use an extra transformation ontop of this -/// one -/// See [`isometries_xy`] for example usescases. -/// [congruence]: https://en.wikipedia.org/wiki/Congruence_(geometry) -/// [`isometries_xy`]: `InfinitePlane3d::isometries_xy` - - #[lua(kind = "Method", output(proxy))] - fn isometry_from_xy( - &self, - #[proxy] - origin: bevy::math::prelude::Vec3, - ) -> bevy::math::Isometry3d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim3::InfinitePlane3d) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct InfinitePlane3d { - #[lua(output(proxy))] +pub struct InfinitePlane3d { normal: bevy::math::prelude::Dir3, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Line3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim3::Line3d) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Line3d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Line3d { - #[lua(output(proxy))] +pub struct Line3d { direction: bevy::math::prelude::Dir3, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Segment3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim3::Segment3d) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Segment3d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Create a new `Segment3d` from a direction and full length of the segment - #[lua(kind = "Function", output(proxy))] + #[lua()] fn new( - #[proxy] - direction: bevy::math::prelude::Dir3, + direction: LuaReflectValProxy, length: f32, - ) -> bevy::math::primitives::Segment3d; - -"#, - r#" -/// Get the position of the first point on the line segment - - #[lua(kind = "Method", output(proxy))] - fn point1(&self) -> bevy::math::prelude::Vec3; + ) -> LuaReflectValProxy; "#, r#" -/// Get the position of the second point on the line segment - - #[lua(kind = "Method", output(proxy))] - fn point2(&self) -> bevy::math::prelude::Vec3; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Segment3d { - #[lua(output(proxy))] +pub struct Segment3d { direction: bevy::math::prelude::Dir3, half_length: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Torus", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim3::Torus) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Torus; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4182,8 +3424,11 @@ struct Segment3d { /// The inner radius is the radius of the hole, and the outer radius /// is the radius of the entire object - #[lua(kind = "Function", output(proxy))] - fn new(inner_radius: f32, outer_radius: f32) -> bevy::math::primitives::Torus; + #[lua()] + fn new( + inner_radius: f32, + outer_radius: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -4191,8 +3436,8 @@ struct Segment3d { /// For a ring torus, this corresponds to the radius of the hole, /// or `major_radius - minor_radius` - #[lua(kind = "Method")] - fn inner_radius(&self) -> f32; + #[lua()] + fn inner_radius(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -4200,722 +3445,632 @@ struct Segment3d { /// This corresponds to the overall radius of the entire object, /// or `major_radius + minor_radius` - #[lua(kind = "Method")] - fn outer_radius(&self) -> f32; + #[lua()] + fn outer_radius(_self: LuaReflectRefProxy) -> f32; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Torus { +pub struct Torus { minor_radius: f32, major_radius: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Triangle3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" -/// Create a new [`Triangle3d`] from points `a`, `b`, and `c`. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - a: bevy::math::prelude::Vec3, - #[proxy] - b: bevy::math::prelude::Vec3, - #[proxy] - c: bevy::math::prelude::Vec3, - ) -> bevy::math::primitives::Triangle3d; - -"#, - r#" /// Checks if the triangle is degenerate, meaning it has zero area. /// A triangle is degenerate if the cross product of the vectors `ab` and `ac` has a length less than `10e-7`. /// This indicates that the three vertices are collinear or nearly collinear. - #[lua(kind = "Method")] - fn is_degenerate(&self) -> bool; + #[lua()] + fn is_degenerate( + _self: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Checks if the triangle is acute, meaning all angles are less than 90 degrees - #[lua(kind = "Method")] - fn is_acute(&self) -> bool; + #[lua()] + fn is_acute(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Checks if the triangle is obtuse, meaning one angle is greater than 90 degrees - #[lua(kind = "Method")] - fn is_obtuse(&self) -> bool; + #[lua()] + fn is_obtuse(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Reverse the triangle by swapping the first and last vertices. - #[lua(kind = "MutatingMethod")] - fn reverse(&mut self) -> (); + #[lua()] + fn reverse(_self: LuaReflectRefMutProxy) -> (); "#, r#" /// This triangle but reversed. - #[lua(kind = "Method", output(proxy))] - fn reversed(self) -> bevy::math::primitives::Triangle3d; - -"#, - r#" -/// Get the centroid of the triangle. -/// This function finds the geometric center of the triangle by averaging the vertices: -/// `centroid = (a + b + c) / 3`. - - #[lua(kind = "Method", output(proxy))] - fn centroid(&self) -> bevy::math::prelude::Vec3; - -"#, - r#" -/// Get the circumcenter of the triangle. - - #[lua(kind = "Method", output(proxy))] - fn circumcenter(&self) -> bevy::math::prelude::Vec3; + #[lua()] + fn reversed( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim3::Triangle3d) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Triangle3d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Triangle3d { - vertices: ReflectedValue, +pub struct Triangle3d { + vertices: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::bounding::RayCast2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" -/// Construct a [`RayCast2d`] from an origin, [`Dir2`], and max distance. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - origin: bevy::math::prelude::Vec2, - #[proxy] - direction: bevy::math::prelude::Dir2, - max: f32, - ) -> bevy::math::bounding::RayCast2d; - -"#, - r#" /// Construct a [`RayCast2d`] from a [`Ray2d`] and max distance. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_ray( - #[proxy] - ray: bevy::math::Ray2d, + ray: LuaReflectValProxy, max: f32, - ) -> bevy::math::bounding::RayCast2d; - -"#, - r#" -/// Get the cached multiplicative inverse of the direction of the ray. - - #[lua(kind = "Method", output(proxy))] - fn direction_recip(&self) -> bevy::math::prelude::Vec2; + ) -> LuaReflectValProxy; "#, r#" /// Get the distance of an intersection with an [`Aabb2d`], if any. - #[lua(kind = "Method")] + #[lua()] fn aabb_intersection_at( - &self, - #[proxy] - aabb: &bounding::bounded2d::Aabb2d, + _self: LuaReflectRefProxy, + aabb: LuaReflectRefProxy, ) -> std::option::Option; "#, r#" /// Get the distance of an intersection with a [`BoundingCircle`], if any. - #[lua(kind = "Method")] + #[lua()] fn circle_intersection_at( - &self, - #[proxy] - circle: &bounding::bounded2d::BoundingCircle, + _self: LuaReflectRefProxy, + circle: LuaReflectRefProxy, ) -> std::option::Option; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::bounding::RayCast2d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct RayCast2d { - #[lua(output(proxy))] +pub struct RayCast2d { ray: bevy::math::Ray2d, max: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::bounding::AabbCast2d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" -/// Construct an [`AabbCast2d`] from an [`Aabb2d`], origin, [`Dir2`], and max distance. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - aabb: bevy::math::bounding::Aabb2d, - #[proxy] - origin: bevy::math::prelude::Vec2, - #[proxy] - direction: bevy::math::prelude::Dir2, - max: f32, - ) -> bevy::math::bounding::AabbCast2d; - -"#, - r#" /// Construct an [`AabbCast2d`] from an [`Aabb2d`], [`Ray2d`], and max distance. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_ray( - #[proxy] - aabb: bevy::math::bounding::Aabb2d, - #[proxy] - ray: bevy::math::Ray2d, + aabb: LuaReflectValProxy, + ray: LuaReflectValProxy, max: f32, - ) -> bevy::math::bounding::AabbCast2d; + ) -> LuaReflectValProxy; "#, r#" /// Get the distance at which the [`Aabb2d`]s collide, if at all. - #[lua(kind = "Method")] + #[lua()] fn aabb_collision_at( - &self, - #[proxy] - aabb: bevy::math::bounding::Aabb2d, + _self: LuaReflectRefProxy, + aabb: LuaReflectValProxy, ) -> std::option::Option; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::bounding::AabbCast2d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AabbCast2d { - #[lua(output(proxy))] +pub struct AabbCast2d { ray: bevy::math::bounding::RayCast2d, - #[lua(output(proxy))] aabb: bevy::math::bounding::Aabb2d, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::bounding::BoundingCircleCast", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::bounding::BoundingCircleCast; - -"#, - r#" -/// Construct a [`BoundingCircleCast`] from a [`BoundingCircle`], origin, [`Dir2`], and max distance. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - circle: bevy::math::bounding::BoundingCircle, - #[proxy] - origin: bevy::math::prelude::Vec2, - #[proxy] - direction: bevy::math::prelude::Dir2, - max: f32, - ) -> bevy::math::bounding::BoundingCircleCast; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Construct a [`BoundingCircleCast`] from a [`BoundingCircle`], [`Ray2d`], and max distance. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_ray( - #[proxy] - circle: bevy::math::bounding::BoundingCircle, - #[proxy] - ray: bevy::math::Ray2d, + circle: LuaReflectValProxy, + ray: LuaReflectValProxy, max: f32, - ) -> bevy::math::bounding::BoundingCircleCast; + ) -> LuaReflectValProxy; "#, r#" /// Get the distance at which the [`BoundingCircle`]s collide, if at all. - #[lua(kind = "Method")] + #[lua()] fn circle_collision_at( - &self, - #[proxy] - circle: bevy::math::bounding::BoundingCircle, + _self: LuaReflectRefProxy, + circle: LuaReflectValProxy, ) -> std::option::Option; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct BoundingCircleCast { - #[lua(output(proxy))] +pub struct BoundingCircleCast { ray: bevy::math::bounding::RayCast2d, - #[lua(output(proxy))] circle: bevy::math::bounding::BoundingCircle, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::bounding::RayCast3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::bounding::RayCast3d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Construct a [`RayCast3d`] from a [`Ray3d`] and max distance. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_ray( - #[proxy] - ray: bevy::math::Ray3d, + ray: LuaReflectValProxy, max: f32, - ) -> bevy::math::bounding::RayCast3d; - -"#, - r#" -/// Get the cached multiplicative inverse of the direction of the ray. - - #[lua(kind = "Method", output(proxy))] - fn direction_recip(&self) -> bevy::math::Vec3A; + ) -> LuaReflectValProxy; "#, r#" /// Get the distance of an intersection with an [`Aabb3d`], if any. - #[lua(kind = "Method")] + #[lua()] fn aabb_intersection_at( - &self, - #[proxy] - aabb: &bounding::bounded3d::Aabb3d, + _self: LuaReflectRefProxy, + aabb: LuaReflectRefProxy, ) -> std::option::Option; "#, r#" /// Get the distance of an intersection with a [`BoundingSphere`], if any. - #[lua(kind = "Method")] + #[lua()] fn sphere_intersection_at( - &self, - #[proxy] - sphere: &bounding::bounded3d::BoundingSphere, + _self: LuaReflectRefProxy, + sphere: LuaReflectRefProxy, ) -> std::option::Option; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct RayCast3d { - #[lua(output(proxy))] - origin: bevy::math::Vec3A, - #[lua(output(proxy))] +pub struct RayCast3d { + origin: ReflectReference, direction: bevy::math::prelude::Dir3A, max: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::bounding::AabbCast3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::bounding::AabbCast3d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Construct an [`AabbCast3d`] from an [`Aabb3d`], [`Ray3d`], and max distance. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_ray( - #[proxy] - aabb: bevy::math::bounding::Aabb3d, - #[proxy] - ray: bevy::math::Ray3d, + aabb: LuaReflectValProxy, + ray: LuaReflectValProxy, max: f32, - ) -> bevy::math::bounding::AabbCast3d; + ) -> LuaReflectValProxy; "#, r#" /// Get the distance at which the [`Aabb3d`]s collide, if at all. - #[lua(kind = "Method")] + #[lua()] fn aabb_collision_at( - &self, - #[proxy] - aabb: bevy::math::bounding::Aabb3d, + _self: LuaReflectRefProxy, + aabb: LuaReflectValProxy, ) -> std::option::Option; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AabbCast3d { - #[lua(output(proxy))] +pub struct AabbCast3d { ray: bevy::math::bounding::RayCast3d, - #[lua(output(proxy))] aabb: bevy::math::bounding::Aabb3d, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::bounding::BoundingSphereCast", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::bounding::BoundingSphereCast; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Construct a [`BoundingSphereCast`] from a [`BoundingSphere`], [`Ray3d`], and max distance. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_ray( - #[proxy] - sphere: bevy::math::bounding::BoundingSphere, - #[proxy] - ray: bevy::math::Ray3d, + sphere: LuaReflectValProxy, + ray: LuaReflectValProxy, max: f32, - ) -> bevy::math::bounding::BoundingSphereCast; + ) -> LuaReflectValProxy; "#, r#" /// Get the distance at which the [`BoundingSphere`]s collide, if at all. - #[lua(kind = "Method")] + #[lua()] fn sphere_collision_at( - &self, - #[proxy] - sphere: bevy::math::bounding::BoundingSphere, + _self: LuaReflectRefProxy, + sphere: LuaReflectValProxy, ) -> std::option::Option; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct BoundingSphereCast { - #[lua(output(proxy))] +pub struct BoundingSphereCast { ray: bevy::math::bounding::RayCast3d, - #[lua(output(proxy))] sphere: bevy::math::bounding::BoundingSphere, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::curve::interval::Interval", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &curve::interval::Interval) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Get the start of this interval. - #[lua(kind = "Method")] - fn start(self) -> f32; + #[lua()] + fn start(_self: LuaReflectValProxy) -> f32; "#, r#" /// Get the end of this interval. - #[lua(kind = "Method")] - fn end(self) -> f32; + #[lua()] + fn end(_self: LuaReflectValProxy) -> f32; "#, r#" /// Get the length of this interval. Note that the result may be infinite (`f32::INFINITY`). - #[lua(kind = "Method")] - fn length(self) -> f32; + #[lua()] + fn length(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns `true` if this interval is bounded — that is, if both its start and end are finite. /// Equivalently, an interval is bounded if its length is finite. - #[lua(kind = "Method")] - fn is_bounded(self) -> bool; + #[lua()] + fn is_bounded( + _self: LuaReflectValProxy, + ) -> bool; "#, r#" /// Returns `true` if this interval has a finite start. - #[lua(kind = "Method")] - fn has_finite_start(self) -> bool; + #[lua()] + fn has_finite_start( + _self: LuaReflectValProxy, + ) -> bool; "#, r#" /// Returns `true` if this interval has a finite end. - #[lua(kind = "Method")] - fn has_finite_end(self) -> bool; + #[lua()] + fn has_finite_end( + _self: LuaReflectValProxy, + ) -> bool; "#, r#" /// Returns `true` if `item` is contained in this interval. - #[lua(kind = "Method")] - fn contains(self, item: f32) -> bool; + #[lua()] + fn contains( + _self: LuaReflectValProxy, + item: f32, + ) -> bool; "#, r#" /// Returns `true` if the other interval is contained in this interval. /// This is non-strict: each interval will contain itself. - #[lua(kind = "Method")] + #[lua()] fn contains_interval( - self, - #[proxy] - other: bevy::math::curve::interval::Interval, + _self: LuaReflectValProxy, + other: LuaReflectValProxy, ) -> bool; "#, r#" /// Clamp the given `value` to lie within this interval. - #[lua(kind = "Method")] - fn clamp(self, value: f32) -> f32; + #[lua()] + fn clamp( + _self: LuaReflectValProxy, + value: f32, + ) -> f32; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::curve::interval::Interval; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Interval {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Interval {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::FloatOrd", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &float_ord::FloatOrd) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::FloatOrd; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::FloatOrd; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::PartialOrd", kind = "Method")] - fn lt(&self, #[proxy] other: &float_ord::FloatOrd) -> bool; + #[lua(as_trait = "std::cmp::PartialOrd::")] + fn lt( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::PartialOrd", kind = "Method")] - fn le(&self, #[proxy] other: &float_ord::FloatOrd) -> bool; + #[lua(as_trait = "std::cmp::PartialOrd::")] + fn le( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::PartialOrd", kind = "Method")] - fn gt(&self, #[proxy] other: &float_ord::FloatOrd) -> bool; + #[lua(as_trait = "std::cmp::PartialOrd::")] + fn gt( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::PartialOrd", kind = "Method")] - fn ge(&self, #[proxy] other: &float_ord::FloatOrd) -> bool; + #[lua(as_trait = "std::cmp::PartialOrd::")] + fn ge( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct FloatOrd(f32); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct FloatOrd(f32); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Plane3d", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim3::Plane3d) -> bool; - -"#, - r#" -/// Create a new `Plane3d` from a normal and a half size -/// # Panics -/// Panics if the given `normal` is zero (or very close to zero), or non-finite. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - normal: bevy::math::prelude::Vec3, - #[proxy] - half_size: bevy::math::prelude::Vec2, - ) -> bevy::math::primitives::Plane3d; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Plane3d; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Plane3d { - #[lua(output(proxy))] +pub struct Plane3d { normal: bevy::math::prelude::Dir3, - #[lua(output(proxy))] - half_size: bevy::math::prelude::Vec2, + half_size: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::primitives::Tetrahedron", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &primitives::dim3::Tetrahedron) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::primitives::Tetrahedron; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -/// Create a new [`Tetrahedron`] from points `a`, `b`, `c` and `d`. - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - a: bevy::math::prelude::Vec3, - #[proxy] - b: bevy::math::prelude::Vec3, - #[proxy] - c: bevy::math::prelude::Vec3, - #[proxy] - d: bevy::math::prelude::Vec3, - ) -> bevy::math::primitives::Tetrahedron; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4924,308 +4079,259 @@ struct Plane3d { /// the first three points using the right-hand rule points /// away from the fourth vertex. - #[lua(kind = "Method")] - fn signed_volume(&self) -> f32; - -"#, - r#" -/// Get the centroid of the tetrahedron. -/// This function finds the geometric center of the tetrahedron -/// by averaging the vertices: `centroid = (a + b + c + d) / 4`. - - #[lua(kind = "Method", output(proxy))] - fn centroid(&self) -> bevy::math::prelude::Vec3; + #[lua()] + fn signed_volume( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Tetrahedron { - vertices: ReflectedValue, +pub struct Tetrahedron { + vertices: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::curve::easing::EaseFunction", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &curve::easing::EaseFunction) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::math::curve::easing::EaseFunction; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct EaseFunction {} +pub struct EaseFunction {} #[derive(Default)] pub(crate) struct Globals; -impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { - fn add_instances< - 'lua, - T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, - >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { instances .add_instance( "Isometry2d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "Isometry3d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Ray2d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Ray3d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances - .add_instance( - "Rot2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Dir2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Dir3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Rot2", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "Dir3A", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Dir2", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "IRect", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Dir3", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "Rect", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Dir3A", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "URect", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("IRect", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "Aabb2d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Rect", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "BoundingCircle", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaBoundingCircle, - >::new, - )?; + .add_instance("URect", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "Circle", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Circle", crate::tealr::mlu::UserDataProxy::::new)?; instances .add_instance( "Annulus", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances - .add_instance( - "Arc2d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Arc2d", crate::tealr::mlu::UserDataProxy::::new)?; instances .add_instance( "Capsule2d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "CircularSector", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaCircularSector, - >::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "CircularSegment", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaCircularSegment, - >::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "Ellipse", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Plane2d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "Rectangle", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "RegularPolygon", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaRegularPolygon, - >::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "Rhombus", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "Segment2d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Triangle2d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances - .add_instance( - "Sphere", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Sphere", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "Cuboid", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Cuboid", crate::tealr::mlu::UserDataProxy::::new)?; instances .add_instance( "Cylinder", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "Capsule3d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances - .add_instance( - "Cone", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Cone", crate::tealr::mlu::UserDataProxy::::new)?; instances .add_instance( "Segment3d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances - .add_instance( - "Torus", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Triangle3d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Torus", crate::tealr::mlu::UserDataProxy::::new)?; instances .add_instance( "RayCast2d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "AabbCast2d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "BoundingCircleCast", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaBoundingCircleCast, - >::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "RayCast3d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "AabbCast3d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "BoundingSphereCast", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaBoundingSphereCast, - >::new, - )?; - instances - .add_instance( - "Plane3d", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; - instances - .add_instance( - "Tetrahedron", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; Ok(()) } } -pub struct BevyMathAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyMathAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; - fn attach_api( - &mut self, - ctx: &mut Self::APITarget, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); - bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) - .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( - e.to_string(), - )) - } - fn get_doc_fragment(&self) -> Option { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( +fn bevy_math_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyMathScriptingPlugin; +impl bevy::app::Plugin for BevyMathScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_math_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( "BevyMathAPI", |tw| { tw.document_global_instance::() @@ -5235,298 +4341,109 @@ impl bevy_mod_scripting_core::hosts::APIProvider for BevyMathAPIProvider { .process_type::() .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaIsometry2d, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaIsometry3d, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaBoundingCircle, - >, - >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaCapsule2d, - >, - >() + .process_type::>() .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaCircularSector, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaCircularSegment, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaRectangle, - >, - >() + .process_type::>() .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaRegularPolygon, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaSegment2d, - >, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaTriangle2d, - >, - >() .process_type::() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaCylinder, - >, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaCapsule3d, - >, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() .process_type::() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaSegment3d, - >, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaTriangle3d, - >, - >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaRayCast2d, - >, - >() + .process_type::>() .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaAabbCast2d, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaBoundingCircleCast, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaRayCast3d, - >, - >() + .process_type::>() .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaAabbCast3d, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaBoundingSphereCast, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaTetrahedron, - >, - >() .process_type::() }, ), - ) - } - fn setup_script( - &mut self, - script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn setup_script_runtime( - &mut self, - world_ptr: bevy_mod_scripting_core::world::WorldPointer, - _script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn register_with_app(&self, app: &mut bevy::app::App) { - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); + ); } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs index 9c6497b6a5..1659fd0a00 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs @@ -2,14 +2,21 @@ #![allow(clippy::all)] #![allow(unused, deprecated, dead_code)] #![cfg_attr(rustfmt, rustfmt_skip)] -extern crate self as bevy_script_api; -use bevy_script_api::{ - lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, }; -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "std::sync::atomic::AtomicBool", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a new `AtomicBool`. /// # Examples @@ -19,8 +26,8 @@ use bevy_script_api::{ /// let atomic_false = AtomicBool::new(false); /// ``` - #[lua(kind = "Function", output(proxy))] - fn new(v: bool) -> std::sync::atomic::AtomicBool; + #[lua()] + fn new(v: bool) -> LuaReflectValProxy; "#, r#" @@ -34,22 +41,23 @@ use bevy_script_api::{ /// assert_eq!(some_bool.into_inner(), true); /// ``` - #[lua(kind = "Method")] - fn into_inner(self) -> bool; + #[lua()] + fn into_inner(_self: LuaReflectValProxy) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AtomicBool {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct AtomicBool {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "std::sync::atomic::AtomicI16", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a new atomic integer. /// # Examples @@ -58,8 +66,8 @@ struct AtomicBool {} ///let atomic_forty_two = AtomicI16::new(42); /// ``` - #[lua(kind = "Function", output(proxy))] - fn new(v: i16) -> std::sync::atomic::AtomicI16; + #[lua()] + fn new(v: i16) -> LuaReflectValProxy; "#, r#" @@ -73,22 +81,23 @@ struct AtomicBool {} /// assert_eq!(some_var.into_inner(), 5); /// ``` - #[lua(kind = "Method")] - fn into_inner(self) -> i16; + #[lua()] + fn into_inner(_self: LuaReflectValProxy) -> i16; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AtomicI16 {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct AtomicI16 {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "std::sync::atomic::AtomicI32", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a new atomic integer. /// # Examples @@ -97,8 +106,8 @@ struct AtomicI16 {} ///let atomic_forty_two = AtomicI32::new(42); /// ``` - #[lua(kind = "Function", output(proxy))] - fn new(v: i32) -> std::sync::atomic::AtomicI32; + #[lua()] + fn new(v: i32) -> LuaReflectValProxy; "#, r#" @@ -112,22 +121,23 @@ struct AtomicI16 {} /// assert_eq!(some_var.into_inner(), 5); /// ``` - #[lua(kind = "Method")] - fn into_inner(self) -> i32; + #[lua()] + fn into_inner(_self: LuaReflectValProxy) -> i32; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AtomicI32 {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct AtomicI32 {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "std::sync::atomic::AtomicI64", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a new atomic integer. /// # Examples @@ -136,8 +146,8 @@ struct AtomicI32 {} ///let atomic_forty_two = AtomicI64::new(42); /// ``` - #[lua(kind = "Function", output(proxy))] - fn new(v: i64) -> std::sync::atomic::AtomicI64; + #[lua()] + fn new(v: i64) -> LuaReflectValProxy; "#, r#" @@ -151,22 +161,23 @@ struct AtomicI32 {} /// assert_eq!(some_var.into_inner(), 5); /// ``` - #[lua(kind = "Method")] - fn into_inner(self) -> i64; + #[lua()] + fn into_inner(_self: LuaReflectValProxy) -> i64; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AtomicI64 {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct AtomicI64 {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "std::sync::atomic::AtomicI8", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a new atomic integer. /// # Examples @@ -175,8 +186,8 @@ struct AtomicI64 {} ///let atomic_forty_two = AtomicI8::new(42); /// ``` - #[lua(kind = "Function", output(proxy))] - fn new(v: i8) -> std::sync::atomic::AtomicI8; + #[lua()] + fn new(v: i8) -> LuaReflectValProxy; "#, r#" @@ -190,22 +201,23 @@ struct AtomicI64 {} /// assert_eq!(some_var.into_inner(), 5); /// ``` - #[lua(kind = "Method")] - fn into_inner(self) -> i8; + #[lua()] + fn into_inner(_self: LuaReflectValProxy) -> i8; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AtomicI8 {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct AtomicI8 {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "std::sync::atomic::AtomicIsize", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a new atomic integer. /// # Examples @@ -214,8 +226,8 @@ struct AtomicI8 {} ///let atomic_forty_two = AtomicIsize::new(42); /// ``` - #[lua(kind = "Function", output(proxy))] - fn new(v: isize) -> std::sync::atomic::AtomicIsize; + #[lua()] + fn new(v: isize) -> LuaReflectValProxy; "#, r#" @@ -229,22 +241,23 @@ struct AtomicI8 {} /// assert_eq!(some_var.into_inner(), 5); /// ``` - #[lua(kind = "Method")] - fn into_inner(self) -> isize; + #[lua()] + fn into_inner(_self: LuaReflectValProxy) -> isize; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AtomicIsize {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct AtomicIsize {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "std::sync::atomic::AtomicU16", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a new atomic integer. /// # Examples @@ -253,8 +266,8 @@ struct AtomicIsize {} ///let atomic_forty_two = AtomicU16::new(42); /// ``` - #[lua(kind = "Function", output(proxy))] - fn new(v: u16) -> std::sync::atomic::AtomicU16; + #[lua()] + fn new(v: u16) -> LuaReflectValProxy; "#, r#" @@ -268,22 +281,23 @@ struct AtomicIsize {} /// assert_eq!(some_var.into_inner(), 5); /// ``` - #[lua(kind = "Method")] - fn into_inner(self) -> u16; + #[lua()] + fn into_inner(_self: LuaReflectValProxy) -> u16; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AtomicU16 {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct AtomicU16 {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "std::sync::atomic::AtomicU32", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a new atomic integer. /// # Examples @@ -292,8 +306,8 @@ struct AtomicU16 {} ///let atomic_forty_two = AtomicU32::new(42); /// ``` - #[lua(kind = "Function", output(proxy))] - fn new(v: u32) -> std::sync::atomic::AtomicU32; + #[lua()] + fn new(v: u32) -> LuaReflectValProxy; "#, r#" @@ -307,22 +321,23 @@ struct AtomicU16 {} /// assert_eq!(some_var.into_inner(), 5); /// ``` - #[lua(kind = "Method")] - fn into_inner(self) -> u32; + #[lua()] + fn into_inner(_self: LuaReflectValProxy) -> u32; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AtomicU32 {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct AtomicU32 {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "std::sync::atomic::AtomicU64", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a new atomic integer. /// # Examples @@ -331,8 +346,8 @@ struct AtomicU32 {} ///let atomic_forty_two = AtomicU64::new(42); /// ``` - #[lua(kind = "Function", output(proxy))] - fn new(v: u64) -> std::sync::atomic::AtomicU64; + #[lua()] + fn new(v: u64) -> LuaReflectValProxy; "#, r#" @@ -346,22 +361,23 @@ struct AtomicU32 {} /// assert_eq!(some_var.into_inner(), 5); /// ``` - #[lua(kind = "Method")] - fn into_inner(self) -> u64; + #[lua()] + fn into_inner(_self: LuaReflectValProxy) -> u64; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AtomicU64 {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct AtomicU64 {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "std::sync::atomic::AtomicU8", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a new atomic integer. /// # Examples @@ -370,8 +386,8 @@ struct AtomicU64 {} ///let atomic_forty_two = AtomicU8::new(42); /// ``` - #[lua(kind = "Function", output(proxy))] - fn new(v: u8) -> std::sync::atomic::AtomicU8; + #[lua()] + fn new(v: u8) -> LuaReflectValProxy; "#, r#" @@ -385,22 +401,23 @@ struct AtomicU64 {} /// assert_eq!(some_var.into_inner(), 5); /// ``` - #[lua(kind = "Method")] - fn into_inner(self) -> u8; + #[lua()] + fn into_inner(_self: LuaReflectValProxy) -> u8; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AtomicU8 {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct AtomicU8 {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(), remote = "std::sync::atomic::AtomicUsize", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a new atomic integer. /// # Examples @@ -409,8 +426,8 @@ struct AtomicU8 {} ///let atomic_forty_two = AtomicUsize::new(42); /// ``` - #[lua(kind = "Function", output(proxy))] - fn new(v: usize) -> std::sync::atomic::AtomicUsize; + #[lua()] + fn new(v: usize) -> LuaReflectValProxy; "#, r#" @@ -424,71 +441,64 @@ struct AtomicU8 {} /// assert_eq!(some_var.into_inner(), 5); /// ``` - #[lua(kind = "Method")] - fn into_inner(self) -> usize; + #[lua()] + fn into_inner(_self: LuaReflectValProxy) -> usize; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AtomicUsize {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct AtomicUsize {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::utils::Duration", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: u32) -> bevy::utils::Duration; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::utils::Duration; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::utils::Duration) -> bevy::utils::Duration; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_utils::Duration) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -505,8 +515,8 @@ struct AtomicUsize {} /// let five_seconds = Duration::new(5, 0); /// ``` - #[lua(kind = "Function", output(proxy))] - fn new(secs: u64, nanos: u32) -> bevy::utils::Duration; + #[lua()] + fn new(secs: u64, nanos: u32) -> LuaReflectValProxy; "#, r#" @@ -519,8 +529,8 @@ struct AtomicUsize {} /// assert_eq!(0, duration.subsec_nanos()); /// ``` - #[lua(kind = "Function", output(proxy))] - fn from_secs(secs: u64) -> bevy::utils::Duration; + #[lua()] + fn from_secs(secs: u64) -> LuaReflectValProxy; "#, r#" @@ -533,8 +543,8 @@ struct AtomicUsize {} /// assert_eq!(569_000_000, duration.subsec_nanos()); /// ``` - #[lua(kind = "Function", output(proxy))] - fn from_millis(millis: u64) -> bevy::utils::Duration; + #[lua()] + fn from_millis(millis: u64) -> LuaReflectValProxy; "#, r#" @@ -547,8 +557,8 @@ struct AtomicUsize {} /// assert_eq!(2_000, duration.subsec_nanos()); /// ``` - #[lua(kind = "Function", output(proxy))] - fn from_micros(micros: u64) -> bevy::utils::Duration; + #[lua()] + fn from_micros(micros: u64) -> LuaReflectValProxy; "#, r#" @@ -565,8 +575,8 @@ struct AtomicUsize {} /// assert_eq!(123, duration.subsec_nanos()); /// ``` - #[lua(kind = "Function", output(proxy))] - fn from_nanos(nanos: u64) -> bevy::utils::Duration; + #[lua()] + fn from_nanos(nanos: u64) -> LuaReflectValProxy; "#, r#" @@ -583,8 +593,8 @@ struct AtomicUsize {} /// assert!(!Duration::from_secs(1).is_zero()); /// ``` - #[lua(kind = "Method")] - fn is_zero(&self) -> bool; + #[lua()] + fn is_zero(_self: LuaReflectRefProxy) -> bool; "#, r#" @@ -603,8 +613,8 @@ struct AtomicUsize {} /// [`as_secs_f32`]: Duration::as_secs_f32 /// [`subsec_nanos`]: Duration::subsec_nanos - #[lua(kind = "Method")] - fn as_secs(&self) -> u64; + #[lua()] + fn as_secs(_self: LuaReflectRefProxy) -> u64; "#, r#" @@ -620,8 +630,8 @@ struct AtomicUsize {} /// assert_eq!(duration.subsec_millis(), 432); /// ``` - #[lua(kind = "Method")] - fn subsec_millis(&self) -> u32; + #[lua()] + fn subsec_millis(_self: LuaReflectRefProxy) -> u32; "#, r#" @@ -637,8 +647,8 @@ struct AtomicUsize {} /// assert_eq!(duration.subsec_micros(), 234_567); /// ``` - #[lua(kind = "Method")] - fn subsec_micros(&self) -> u32; + #[lua()] + fn subsec_micros(_self: LuaReflectRefProxy) -> u32; "#, r#" @@ -654,8 +664,8 @@ struct AtomicUsize {} /// assert_eq!(duration.subsec_nanos(), 10_000_000); /// ``` - #[lua(kind = "Method")] - fn subsec_nanos(&self) -> u32; + #[lua()] + fn subsec_nanos(_self: LuaReflectRefProxy) -> u32; "#, r#" @@ -667,8 +677,8 @@ struct AtomicUsize {} /// assert_eq!(duration.as_millis(), 5_730); /// ``` - #[lua(kind = "Method")] - fn as_millis(&self) -> u128; + #[lua()] + fn as_millis(_self: LuaReflectRefProxy) -> u128; "#, r#" @@ -680,8 +690,8 @@ struct AtomicUsize {} /// assert_eq!(duration.as_micros(), 5_730_023); /// ``` - #[lua(kind = "Method")] - fn as_micros(&self) -> u128; + #[lua()] + fn as_micros(_self: LuaReflectRefProxy) -> u128; "#, r#" @@ -693,8 +703,8 @@ struct AtomicUsize {} /// assert_eq!(duration.as_nanos(), 5_730_023_852); /// ``` - #[lua(kind = "Method")] - fn as_nanos(&self) -> u128; + #[lua()] + fn as_nanos(_self: LuaReflectRefProxy) -> u128; "#, r#" @@ -706,8 +716,11 @@ struct AtomicUsize {} /// assert_eq!(Duration::new(100, 400_000_000).abs_diff(Duration::new(110, 0)), Duration::new(9, 600_000_000)); /// ``` - #[lua(kind = "Method", output(proxy))] - fn abs_diff(self, #[proxy] other: bevy::utils::Duration) -> bevy::utils::Duration; + #[lua()] + fn abs_diff( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -721,12 +734,11 @@ struct AtomicUsize {} /// assert_eq!(Duration::new(1, 0).saturating_add(Duration::new(u64::MAX, 0)), Duration::MAX); /// ``` - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_add( - self, - #[proxy] - rhs: bevy::utils::Duration, - ) -> bevy::utils::Duration; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -739,12 +751,11 @@ struct AtomicUsize {} /// assert_eq!(Duration::new(0, 0).saturating_sub(Duration::new(0, 1)), Duration::ZERO); /// ``` - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_sub( - self, - #[proxy] - rhs: bevy::utils::Duration, - ) -> bevy::utils::Duration; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -758,8 +769,11 @@ struct AtomicUsize {} /// assert_eq!(Duration::new(u64::MAX - 1, 0).saturating_mul(2), Duration::MAX); /// ``` - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, rhs: u32) -> bevy::utils::Duration; + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" @@ -772,8 +786,8 @@ struct AtomicUsize {} /// assert_eq!(dur.as_secs_f64(), 2.7); /// ``` - #[lua(kind = "Method")] - fn as_secs_f64(&self) -> f64; + #[lua()] + fn as_secs_f64(_self: LuaReflectRefProxy) -> f64; "#, r#" @@ -786,8 +800,8 @@ struct AtomicUsize {} /// assert_eq!(dur.as_secs_f32(), 2.7); /// ``` - #[lua(kind = "Method")] - fn as_secs_f32(&self) -> f32; + #[lua()] + fn as_secs_f32(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -816,8 +830,8 @@ struct AtomicUsize {} /// assert_eq!(res, Duration::new(0, 1)); /// ``` - #[lua(kind = "Function", output(proxy))] - fn from_secs_f64(secs: f64) -> bevy::utils::Duration; + #[lua()] + fn from_secs_f64(secs: f64) -> LuaReflectValProxy; "#, r#" @@ -846,8 +860,8 @@ struct AtomicUsize {} /// assert_eq!(res, Duration::new(0, 1)); /// ``` - #[lua(kind = "Function", output(proxy))] - fn from_secs_f32(secs: f32) -> bevy::utils::Duration; + #[lua()] + fn from_secs_f32(secs: f32) -> LuaReflectValProxy; "#, r#" @@ -862,8 +876,11 @@ struct AtomicUsize {} /// assert_eq!(dur.mul_f64(3.14e5), Duration::new(847_800, 0)); /// ``` - #[lua(kind = "Method", output(proxy))] - fn mul_f64(self, rhs: f64) -> bevy::utils::Duration; + #[lua()] + fn mul_f64( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -878,8 +895,11 @@ struct AtomicUsize {} /// assert_eq!(dur.mul_f32(3.14e5), Duration::new(847_800, 0)); /// ``` - #[lua(kind = "Method", output(proxy))] - fn mul_f32(self, rhs: f32) -> bevy::utils::Duration; + #[lua()] + fn mul_f32( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -894,8 +914,11 @@ struct AtomicUsize {} /// assert_eq!(dur.div_f64(3.14e5), Duration::new(0, 8_599)); /// ``` - #[lua(kind = "Method", output(proxy))] - fn div_f64(self, rhs: f64) -> bevy::utils::Duration; + #[lua()] + fn div_f64( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -912,8 +935,11 @@ struct AtomicUsize {} /// assert_eq!(dur.div_f32(3.14e5), Duration::new(0, 8_599)); /// ``` - #[lua(kind = "Method", output(proxy))] - fn div_f32(self, rhs: f32) -> bevy::utils::Duration; + #[lua()] + fn div_f32( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -926,8 +952,11 @@ struct AtomicUsize {} /// assert_eq!(dur1.div_duration_f64(dur2), 0.5); /// ``` - #[lua(kind = "Method")] - fn div_duration_f64(self, #[proxy] rhs: bevy::utils::Duration) -> f64; + #[lua()] + fn div_duration_f64( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" @@ -940,83 +969,76 @@ struct AtomicUsize {} /// assert_eq!(dur1.div_duration_f32(dur2), 0.5); /// ``` - #[lua(kind = "Method")] - fn div_duration_f32(self, #[proxy] rhs: bevy::utils::Duration) -> f32; + #[lua()] + fn div_duration_f32( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::utils::Duration) -> bevy::utils::Duration; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: u32) -> bevy::utils::Duration; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Duration {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Duration {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::utils::Instant", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &bevy_utils::Instant) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::utils::Instant; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] other: bevy::utils::Duration) -> bevy::utils::Instant; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1028,14 +1050,11 @@ struct Duration {} /// See [Monotonicity]. /// [Monotonicity]: Instant#monotonicity - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] other: bevy::utils::Instant) -> bevy::utils::Duration; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1046,8 +1065,8 @@ struct Duration {} /// let now = Instant::now(); /// ``` - #[lua(kind = "Function", output(proxy))] - fn now() -> bevy::utils::Instant; + #[lua()] + fn now() -> LuaReflectValProxy; "#, r#" @@ -1069,12 +1088,11 @@ struct Duration {} /// println!("{:?}", now.duration_since(new_now)); // 0ns /// ``` - #[lua(kind = "Method", output(proxy))] + #[lua()] fn duration_since( - &self, - #[proxy] - earlier: bevy::utils::Instant, - ) -> bevy::utils::Duration; + _self: LuaReflectRefProxy, + earlier: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1091,12 +1109,11 @@ struct Duration {} /// println!("{:?}", now.saturating_duration_since(new_now)); // 0ns /// ``` - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_duration_since( - &self, - #[proxy] - earlier: bevy::utils::Instant, - ) -> bevy::utils::Duration; + _self: LuaReflectRefProxy, + earlier: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1116,8 +1133,10 @@ struct Duration {} /// assert!(instant.elapsed() >= three_secs); /// ``` - #[lua(kind = "Method", output(proxy))] - fn elapsed(&self) -> bevy::utils::Duration; + #[lua()] + fn elapsed( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1125,37 +1144,33 @@ struct Duration {} /// This function may panic if the resulting point in time cannot be represented by the /// underlying data structure. See [`Instant::checked_add`] for a version without panic. - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] other: bevy::utils::Duration) -> bevy::utils::Instant; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + other: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Instant(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Instant(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "std::path::PathBuf", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::path::PathBuf) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -1166,8 +1181,8 @@ struct Instant(); /// let path = PathBuf::new(); /// ``` - #[lua(kind = "Function", output(proxy))] - fn new() -> std::path::PathBuf; + #[lua()] + fn new() -> LuaReflectValProxy; "#, r#" @@ -1184,8 +1199,8 @@ struct Instant(); /// ``` /// [`with_capacity`]: OsString::with_capacity - #[lua(kind = "Function", output(proxy))] - fn with_capacity(capacity: usize) -> std::path::PathBuf; + #[lua()] + fn with_capacity(capacity: usize) -> LuaReflectValProxy; "#, r#" @@ -1203,66 +1218,73 @@ struct Instant(); /// assert_eq!(Path::new("/"), p); /// ``` - #[lua(kind = "MutatingMethod")] - fn pop(&mut self) -> bool; + #[lua()] + fn pop(_self: LuaReflectRefMutProxy) -> bool; "#, r#" /// Invokes [`capacity`] on the underlying instance of [`OsString`]. /// [`capacity`]: OsString::capacity - #[lua(kind = "Method")] - fn capacity(&self) -> usize; + #[lua()] + fn capacity(_self: LuaReflectRefProxy) -> usize; "#, r#" /// Invokes [`clear`] on the underlying instance of [`OsString`]. /// [`clear`]: OsString::clear - #[lua(kind = "MutatingMethod")] - fn clear(&mut self) -> (); + #[lua()] + fn clear(_self: LuaReflectRefMutProxy) -> (); "#, r#" /// Invokes [`reserve`] on the underlying instance of [`OsString`]. /// [`reserve`]: OsString::reserve - #[lua(kind = "MutatingMethod")] - fn reserve(&mut self, additional: usize) -> (); + #[lua()] + fn reserve( + _self: LuaReflectRefMutProxy, + additional: usize, + ) -> (); "#, r#" /// Invokes [`reserve_exact`] on the underlying instance of [`OsString`]. /// [`reserve_exact`]: OsString::reserve_exact - #[lua(kind = "MutatingMethod")] - fn reserve_exact(&mut self, additional: usize) -> (); + #[lua()] + fn reserve_exact( + _self: LuaReflectRefMutProxy, + additional: usize, + ) -> (); "#, r#" /// Invokes [`shrink_to_fit`] on the underlying instance of [`OsString`]. /// [`shrink_to_fit`]: OsString::shrink_to_fit - #[lua(kind = "MutatingMethod")] - fn shrink_to_fit(&mut self) -> (); + #[lua()] + fn shrink_to_fit(_self: LuaReflectRefMutProxy) -> (); "#, r#" /// Invokes [`shrink_to`] on the underlying instance of [`OsString`]. /// [`shrink_to`]: OsString::shrink_to - #[lua(kind = "MutatingMethod")] - fn shrink_to(&mut self, min_capacity: usize) -> (); + #[lua()] + fn shrink_to( + _self: LuaReflectRefMutProxy, + min_capacity: usize, + ) -> (); "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::path::PathBuf; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1270,123 +1292,107 @@ struct Instant(); /// This method is preferred over simply assigning `source.clone()` to `self`, /// as it avoids reallocation if possible. - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "MutatingMethod", - )] - fn clone_from(&mut self, #[proxy] source: &std::path::PathBuf) -> (); + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone_from( + _self: LuaReflectRefMutProxy, + source: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct PathBuf {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct PathBuf {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "std::ops::RangeFull", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> std::ops::RangeFull; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &std::ops::RangeFull) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct RangeFull {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct RangeFull {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Quat", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Quat; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Divides a quaternion by a scalar value. /// The quotient is not guaranteed to be normalized. - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f32) -> bevy::math::Quat; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Quat) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Multiplies a quaternion by a scalar value. /// The product is not guaranteed to be normalized. - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Quat; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Quat; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1397,28 +1403,22 @@ struct RangeFull {} /// # Panics /// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Quat) -> bevy::math::Quat; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Subtracts the `rhs` quaternion from `self`. /// The difference is not guaranteed to be normalized. - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Quat) -> bevy::math::Quat; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1427,14 +1427,11 @@ struct RangeFull {} /// Note that addition is not the same as combining the rotations represented by the /// two quaternions! That corresponds to multiplication. - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Quat) -> bevy::math::Quat; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1446,8 +1443,8 @@ struct RangeFull {} /// This function does not check if the input is normalized, it is up to the user to /// provide normalized input or to normalized the resulting quaternion. - #[lua(kind = "Function", output(proxy))] - fn from_xyzw(x: f32, y: f32, z: f32, w: f32) -> bevy::math::Quat; + #[lua()] + fn from_xyzw(x: f32, y: f32, z: f32, w: f32) -> LuaReflectValProxy; "#, r#" @@ -1456,8 +1453,8 @@ struct RangeFull {} /// This function does not check if the input is normalized, it is up to the user to /// provide normalized input or to normalized the resulting quaternion. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f32; 4]) -> bevy::math::Quat; + #[lua()] + fn from_array(a: [f32; 4]) -> LuaReflectValProxy; "#, r#" @@ -1466,8 +1463,10 @@ struct RangeFull {} /// This function does not check if the input is normalized, it is up to the user to /// provide normalized input or to normalized the resulting quaternion. - #[lua(kind = "Function", output(proxy))] - fn from_vec4(#[proxy] v: bevy::math::Vec4) -> bevy::math::Quat; + #[lua()] + fn from_vec4( + v: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1476,50 +1475,54 @@ struct RangeFull {} /// # Panics /// Will panic if `axis` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_axis_angle(#[proxy] axis: bevy::math::Vec3, angle: f32) -> bevy::math::Quat; + #[lua()] + fn from_axis_angle( + axis: LuaReflectValProxy, + angle: f32, + ) -> LuaReflectValProxy; "#, r#" /// Create a quaternion that rotates `v.length()` radians around `v.normalize()`. /// `from_scaled_axis(Vec3::ZERO)` results in the identity quaternion. - #[lua(kind = "Function", output(proxy))] - fn from_scaled_axis(#[proxy] v: bevy::math::Vec3) -> bevy::math::Quat; + #[lua()] + fn from_scaled_axis( + v: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a quaternion from the `angle` (in radians) around the x axis. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f32) -> bevy::math::Quat; + #[lua()] + fn from_rotation_x(angle: f32) -> LuaReflectValProxy; "#, r#" /// Creates a quaternion from the `angle` (in radians) around the y axis. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f32) -> bevy::math::Quat; + #[lua()] + fn from_rotation_y(angle: f32) -> LuaReflectValProxy; "#, r#" /// Creates a quaternion from the `angle` (in radians) around the z axis. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f32) -> bevy::math::Quat; + #[lua()] + fn from_rotation_z(angle: f32) -> LuaReflectValProxy; "#, r#" /// Creates a quaternion from the given Euler rotation sequence and the angles (in radians). - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_euler( - #[proxy] - euler: bevy::math::EulerRot, + euler: LuaReflectValProxy, a: f32, b: f32, c: f32, - ) -> bevy::math::Quat; + ) -> LuaReflectValProxy; "#, r#" @@ -1529,8 +1532,10 @@ struct RangeFull {} /// # Panics /// Will panic if any input matrix column is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] mat: &glam::Mat3) -> bevy::math::Quat; + #[lua()] + fn from_mat3( + mat: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1540,8 +1545,10 @@ struct RangeFull {} /// # Panics /// Will panic if any input matrix column is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_mat3a(#[proxy] mat: &glam::Mat3A) -> bevy::math::Quat; + #[lua()] + fn from_mat3a( + mat: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1552,8 +1559,10 @@ struct RangeFull {} /// Will panic if any column of the upper 3x3 rotation matrix is not normalized when /// `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_mat4(#[proxy] mat: &glam::Mat4) -> bevy::math::Quat; + #[lua()] + fn from_mat4( + mat: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1566,13 +1575,11 @@ struct RangeFull {} /// # Panics /// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_rotation_arc( - #[proxy] - from: bevy::math::Vec3, - #[proxy] - to: bevy::math::Vec3, - ) -> bevy::math::Quat; + from: LuaReflectValProxy, + to: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1585,13 +1592,11 @@ struct RangeFull {} /// # Panics /// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_rotation_arc_colinear( - #[proxy] - from: bevy::math::Vec3, - #[proxy] - to: bevy::math::Vec3, - ) -> bevy::math::Quat; + from: LuaReflectValProxy, + to: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1604,49 +1609,56 @@ struct RangeFull {} /// # Panics /// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_rotation_arc_2d( - #[proxy] - from: bevy::math::Vec2, - #[proxy] - to: bevy::math::Vec2, - ) -> bevy::math::Quat; + from: LuaReflectValProxy, + to: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the rotation axis scaled by the rotation in radians. - #[lua(kind = "Method", output(proxy))] - fn to_scaled_axis(self) -> bevy::math::Vec3; + #[lua()] + fn to_scaled_axis( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the rotation angles for the given euler rotation sequence. - #[lua(kind = "Method")] - fn to_euler(self, #[proxy] order: bevy::math::EulerRot) -> (f32, f32, f32); + #[lua()] + fn to_euler( + _self: LuaReflectValProxy, + order: LuaReflectValProxy, + ) -> (f32, f32, f32); "#, r#" /// `[x, y, z, w]` - #[lua(kind = "Method")] - fn to_array(&self) -> [f32; 4]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f32; 4]; "#, r#" /// Returns the vector part of the quaternion. - #[lua(kind = "Method", output(proxy))] - fn xyz(self) -> bevy::math::Vec3; + #[lua()] + fn xyz( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the quaternion conjugate of `self`. For a unit quaternion the /// conjugate is also the inverse. - #[lua(kind = "Method", output(proxy))] - fn conjugate(self) -> bevy::math::Quat; + #[lua()] + fn conjugate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1657,23 +1669,28 @@ struct RangeFull {} /// # Panics /// Will panic if `self` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn inverse(self) -> bevy::math::Quat; + #[lua()] + fn inverse( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. The dot product is /// equal to the cosine of the angle between two quaternion rotations. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::Quat) -> f32; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" /// Computes the length of `self`. - #[lua(kind = "Method")] - fn length(self) -> f32; + #[lua()] + fn length(_self: LuaReflectValProxy) -> f32; "#, r#" @@ -1681,16 +1698,16 @@ struct RangeFull {} /// This is generally faster than `length()` as it avoids a square /// root operation. - #[lua(kind = "Method")] - fn length_squared(self) -> f32; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f32; "#, r#" /// Computes `1.0 / length()`. /// For valid results, `self` must _not_ be of length zero. - #[lua(kind = "Method")] - fn length_recip(self) -> f32; + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f32; "#, r#" @@ -1699,37 +1716,39 @@ struct RangeFull {} /// Panics /// Will panic if `self` is zero length when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::Quat; + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if, and only if, all elements are finite. /// If any element is either `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; "#, r#" /// Returns `true` if any elements are `NAN`. - #[lua(kind = "Method")] - fn is_nan(self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; "#, r#" /// Returns whether `self` of length `1.0` or not. /// Uses a precision threshold of `1e-6`. - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; "#, r#" - #[lua(kind = "Method")] - fn is_near_identity(self) -> bool; + #[lua()] + fn is_near_identity(_self: LuaReflectValProxy) -> bool; "#, r#" @@ -1739,8 +1758,11 @@ struct RangeFull {} /// # Panics /// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Method")] - fn angle_between(self, #[proxy] rhs: bevy::math::Quat) -> f32; + #[lua()] + fn angle_between( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" @@ -1752,13 +1774,12 @@ struct RangeFull {} /// # Panics /// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn rotate_towards( - &self, - #[proxy] - rhs: bevy::math::Quat, + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, max_angle: f32, - ) -> bevy::math::Quat; + ) -> LuaReflectValProxy; "#, r#" @@ -1770,8 +1791,12 @@ struct RangeFull {} /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::Quat, max_abs_diff: f32) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; "#, r#" @@ -1782,8 +1807,12 @@ struct RangeFull {} /// # Panics /// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] end: bevy::math::Quat, s: f32) -> bevy::math::Quat; + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + end: LuaReflectValProxy, + s: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -1794,8 +1823,12 @@ struct RangeFull {} /// # Panics /// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn slerp(self, #[proxy] end: bevy::math::Quat, s: f32) -> bevy::math::Quat; + #[lua()] + fn slerp( + _self: LuaReflectValProxy, + end: LuaReflectValProxy, + s: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -1803,8 +1836,11 @@ struct RangeFull {} /// # Panics /// Will panic if `self` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn mul_vec3(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn mul_vec3( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1814,8 +1850,11 @@ struct RangeFull {} /// # Panics /// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn mul_quat(self, #[proxy] rhs: bevy::math::Quat) -> bevy::math::Quat; + #[lua()] + fn mul_quat( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1826,21 +1865,28 @@ struct RangeFull {} /// Will panic if any input affine matrix column is not normalized when `glam_assert` is /// enabled. - #[lua(kind = "Function", output(proxy))] - fn from_affine3(#[proxy] a: &glam::Affine3A) -> bevy::math::Quat; + #[lua()] + fn from_affine3( + a: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies a quaternion and a 3D vector, returning the rotated vector. - #[lua(kind = "Method", output(proxy))] - fn mul_vec3a(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn mul_vec3a( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(kind = "Method", output(proxy))] - fn as_dquat(self) -> bevy::math::DQuat; + #[lua()] + fn as_dquat( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -1848,124 +1894,101 @@ struct RangeFull {} /// # Panics /// Will panic if `self` is not normalized when `glam_assert` is enabled. - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Quat(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Quat(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Vec3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::Vec3) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::Vec3>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::Vec3) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::Vec3>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::Vec3) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Add::<&bevy::math::Vec3>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: f32, y: f32, z: f32) -> bevy::math::Vec3; + #[lua()] + fn new(x: f32, y: f32, z: f32) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: f32) -> bevy::math::Vec3; + #[lua()] + fn splat(v: f32) -> LuaReflectValProxy; "#, r#" @@ -1974,102 +1997,128 @@ struct Quat(); /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec3, - #[proxy] - if_true: bevy::math::Vec3, - #[proxy] - if_false: bevy::math::Vec3, - ) -> bevy::math::Vec3; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f32; 3]) -> bevy::math::Vec3; + #[lua()] + fn from_array(a: [f32; 3]) -> LuaReflectValProxy; "#, r#" /// `[x, y, z]` - #[lua(kind = "Method")] - fn to_array(&self) -> [f32; 3]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f32; 3]; "#, r#" /// Creates a 4D vector from `self` and the given `w` value. - #[lua(kind = "Method", output(proxy))] - fn extend(self, w: f32) -> bevy::math::Vec4; + #[lua()] + fn extend( + _self: LuaReflectValProxy, + w: f32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. /// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::Vec2; + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: f32) -> bevy::math::Vec3; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: f32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: f32) -> bevy::math::Vec3; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: f32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `z`. - #[lua(kind = "Method", output(proxy))] - fn with_z(self, z: f32) -> bevy::math::Vec3; + #[lua()] + fn with_z( + _self: LuaReflectValProxy, + z: f32, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::Vec3) -> f32; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the cross product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn cross(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn cross( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2078,46 +2127,44 @@ struct Quat(); /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::Vec3, - #[proxy] - max: bevy::math::Vec3, - ) -> bevy::math::Vec3; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> f32; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> f32; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> f32; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> f32; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> f32; "#, r#" @@ -2126,8 +2173,11 @@ struct Quat(); /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2136,8 +2186,11 @@ struct Quat(); /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2146,8 +2199,11 @@ struct Quat(); /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2156,8 +2212,11 @@ struct Quat(); /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2166,8 +2225,11 @@ struct Quat(); /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2176,15 +2238,20 @@ struct Quat(); /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the absolute value of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::Vec3; + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2193,15 +2260,20 @@ struct Quat(); /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` /// - `NAN` if the number is `NAN` - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::Vec3; + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector with signs of `rhs` and the magnitudes of `self`. - #[lua(kind = "Method", output(proxy))] - fn copysign(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn copysign( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2209,91 +2281,107 @@ struct Quat(); /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns `true` if, and only if, all elements are finite. If any element is either /// `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; "#, r#" /// Performs `is_finite` on each element of self, returning a vector mask of the results. /// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`. - #[lua(kind = "Method", output(proxy))] - fn is_finite_mask(self) -> bevy::math::BVec3; + #[lua()] + fn is_finite_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; "#, r#" /// Performs `is_nan` on each element of self, returning a vector mask of the results. /// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`. - #[lua(kind = "Method", output(proxy))] - fn is_nan_mask(self) -> bevy::math::BVec3; + #[lua()] + fn is_nan_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the length of `self`. - #[lua(kind = "Method")] - fn length(self) -> f32; + #[lua()] + fn length(_self: LuaReflectValProxy) -> f32; "#, r#" /// Computes the squared length of `self`. /// This is faster than `length()` as it avoids a square root operation. - #[lua(kind = "Method")] - fn length_squared(self) -> f32; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f32; "#, r#" /// Computes `1.0 / length()`. /// For valid results, `self` must _not_ be of length zero. - #[lua(kind = "Method")] - fn length_recip(self) -> f32; + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f32; "#, r#" /// Computes the Euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance(self, #[proxy] rhs: bevy::math::Vec3) -> f32; + #[lua()] + fn distance( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" /// Compute the squared euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::Vec3) -> f32; + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. /// [Euclidean division]: f32::rem_euclid - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2303,8 +2391,10 @@ struct Quat(); /// Panics /// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::Vec3; + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2314,8 +2404,11 @@ struct Quat(); /// the result of this operation will be the fallback value. /// See also [`Self::try_normalize()`]. - #[lua(kind = "Method", output(proxy))] - fn normalize_or(self, #[proxy] fallback: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn normalize_or( + _self: LuaReflectValProxy, + fallback: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2324,16 +2417,18 @@ struct Quat(); /// the result of this operation will be zero. /// See also [`Self::try_normalize()`]. - #[lua(kind = "Method", output(proxy))] - fn normalize_or_zero(self) -> bevy::math::Vec3; + #[lua()] + fn normalize_or_zero( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns whether `self` is length `1.0` or not. /// Uses a precision threshold of approximately `1e-4`. - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; "#, r#" @@ -2342,8 +2437,11 @@ struct Quat(); /// # Panics /// Will panic if `rhs` is zero length when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn project_onto(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn project_onto( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2354,8 +2452,11 @@ struct Quat(); /// # Panics /// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reject_from(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn reject_from( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2364,8 +2465,11 @@ struct Quat(); /// # Panics /// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn project_onto_normalized(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn project_onto_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2376,40 +2480,51 @@ struct Quat(); /// # Panics /// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reject_from_normalized(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn reject_from_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the nearest integer to a number for each element of `self`. /// Round half-way cases away from 0.0. - #[lua(kind = "Method", output(proxy))] - fn round(self) -> bevy::math::Vec3; + #[lua()] + fn round( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the largest integer less than or equal to a number for each /// element of `self`. - #[lua(kind = "Method", output(proxy))] - fn floor(self) -> bevy::math::Vec3; + #[lua()] + fn floor( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the smallest integer greater than or equal to a number for /// each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn ceil(self) -> bevy::math::Vec3; + #[lua()] + fn ceil( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the integer part each element of `self`. This means numbers are /// always truncated towards zero. - #[lua(kind = "Method", output(proxy))] - fn trunc(self) -> bevy::math::Vec3; + #[lua()] + fn trunc( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2418,8 +2533,10 @@ struct Quat(); /// `self - self.floor()`. /// Note that this is fast but not precise for large numbers. - #[lua(kind = "Method", output(proxy))] - fn fract(self) -> bevy::math::Vec3; + #[lua()] + fn fract( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2428,30 +2545,39 @@ struct Quat(); /// `self - self.trunc()`. /// Note that this is fast but not precise for large numbers. - #[lua(kind = "Method", output(proxy))] - fn fract_gl(self) -> bevy::math::Vec3; + #[lua()] + fn fract_gl( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing `e^self` (the exponential function) for each element of /// `self`. - #[lua(kind = "Method", output(proxy))] - fn exp(self) -> bevy::math::Vec3; + #[lua()] + fn exp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing each element of `self` raised to the power of `n`. - #[lua(kind = "Method", output(proxy))] - fn powf(self, n: f32) -> bevy::math::Vec3; + #[lua()] + fn powf( + _self: LuaReflectValProxy, + n: f32, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn recip(self) -> bevy::math::Vec3; + #[lua()] + fn recip( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2460,8 +2586,12 @@ struct Quat(); /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly /// extrapolated. - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] rhs: bevy::math::Vec3, s: f32) -> bevy::math::Vec3; + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + s: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -2469,8 +2599,12 @@ struct Quat(); /// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to /// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`. - #[lua(kind = "Method", output(proxy))] - fn move_towards(&self, #[proxy] rhs: bevy::math::Vec3, d: f32) -> bevy::math::Vec3; + #[lua()] + fn move_towards( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + d: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -2479,8 +2613,11 @@ struct Quat(); /// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)` /// while being slightly cheaper to compute. - #[lua(kind = "Method", output(proxy))] - fn midpoint(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn midpoint( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2492,8 +2629,12 @@ struct Quat(); /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::Vec3, max_abs_diff: f32) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; "#, r#" @@ -2501,8 +2642,12 @@ struct Quat(); /// # Panics /// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length(self, min: f32, max: f32) -> bevy::math::Vec3; + #[lua()] + fn clamp_length( + _self: LuaReflectValProxy, + min: f32, + max: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -2510,8 +2655,11 @@ struct Quat(); /// # Panics /// Will panic if `max` is negative when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length_max(self, max: f32) -> bevy::math::Vec3; + #[lua()] + fn clamp_length_max( + _self: LuaReflectValProxy, + max: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -2519,8 +2667,11 @@ struct Quat(); /// # Panics /// Will panic if `min` is negative when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length_min(self, min: f32) -> bevy::math::Vec3; + #[lua()] + fn clamp_length_min( + _self: LuaReflectValProxy, + min: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -2531,14 +2682,12 @@ struct Quat(); /// and will be heavily dependant on designing algorithms with specific target hardware in /// mind. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn mul_add( - self, - #[proxy] - a: bevy::math::Vec3, - #[proxy] - b: bevy::math::Vec3, - ) -> bevy::math::Vec3; + _self: LuaReflectValProxy, + a: LuaReflectValProxy, + b: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2548,8 +2697,11 @@ struct Quat(); /// # Panics /// Will panic if `normal` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reflect(self, #[proxy] normal: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn reflect( + _self: LuaReflectValProxy, + normal: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2560,16 +2712,23 @@ struct Quat(); /// # Panics /// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn refract(self, #[proxy] normal: bevy::math::Vec3, eta: f32) -> bevy::math::Vec3; + #[lua()] + fn refract( + _self: LuaReflectValProxy, + normal: LuaReflectValProxy, + eta: f32, + ) -> LuaReflectValProxy; "#, r#" /// Returns the angle (in radians) between two vectors in the range `[0, +π]`. /// The inputs do not need to be unit vectors however they must be non-zero. - #[lua(kind = "Method")] - fn angle_between(self, #[proxy] rhs: bevy::math::Vec3) -> f32; + #[lua()] + fn angle_between( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" @@ -2578,8 +2737,10 @@ struct Quat(); /// The output vector is not necessarily unit length. For that use /// [`Self::any_orthonormal_vector()`] instead. - #[lua(kind = "Method", output(proxy))] - fn any_orthogonal_vector(&self) -> bevy::math::Vec3; + #[lua()] + fn any_orthogonal_vector( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2588,238 +2749,213 @@ struct Quat(); /// # Panics /// Will panic if `self` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn any_orthonormal_vector(&self) -> bevy::math::Vec3; + #[lua()] + fn any_orthonormal_vector( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec3(&self) -> bevy::math::DVec3; + #[lua()] + fn as_dvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec3(&self) -> bevy::math::IVec3; + #[lua()] + fn as_ivec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec3(&self) -> bevy::math::UVec3; + #[lua()] + fn as_uvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec3(&self) -> bevy::math::I64Vec3; + #[lua()] + fn as_i64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec3(&self) -> bevy::math::U64Vec3; + #[lua()] + fn as_u64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: f32) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::Vec3) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::Vec3>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f32) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::Vec3) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Vec3; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: f32) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: f32) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::Vec3) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Div::<&bevy::math::Vec3>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> LuaIdentityProxy { + _self[idx - 1] } "#, r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: f32) -> () { + _self[idx - 1] = val } "#] )] -struct Vec3 { +pub struct Vec3 { x: f32, y: f32, z: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::IVec2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: i32) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: i32, y: i32) -> bevy::math::IVec2; + #[lua()] + fn new(x: i32, y: i32) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: i32) -> bevy::math::IVec2; + #[lua()] + fn splat(v: i32) -> LuaReflectValProxy; "#, r#" @@ -2828,80 +2964,98 @@ struct Vec3 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec2, - #[proxy] - if_true: bevy::math::IVec2, - #[proxy] - if_false: bevy::math::IVec2, - ) -> bevy::math::IVec2; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [i32; 2]) -> bevy::math::IVec2; + #[lua()] + fn from_array(a: [i32; 2]) -> LuaReflectValProxy; "#, r#" /// `[x, y]` - #[lua(kind = "Method")] - fn to_array(&self) -> [i32; 2]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i32; 2]; "#, r#" /// Creates a 3D vector from `self` and the given `z` value. - #[lua(kind = "Method", output(proxy))] - fn extend(self, z: i32) -> bevy::math::IVec3; + #[lua()] + fn extend( + _self: LuaReflectValProxy, + z: i32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: i32) -> bevy::math::IVec2; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: i32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: i32) -> bevy::math::IVec2; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: i32, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::IVec2) -> i32; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i32; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2910,46 +3064,44 @@ struct Vec3 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::IVec2, - #[proxy] - max: bevy::math::IVec2, - ) -> bevy::math::IVec2; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> i32; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> i32; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> i32; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> i32; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> i32; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> i32; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> i32; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> i32; "#, r#" @@ -2958,8 +3110,11 @@ struct Vec3 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2968,8 +3123,11 @@ struct Vec3 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2978,8 +3136,11 @@ struct Vec3 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2988,8 +3149,11 @@ struct Vec3 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -2998,8 +3162,11 @@ struct Vec3 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -3008,15 +3175,20 @@ struct Vec3 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::BVec2; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the absolute value of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::IVec2; + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -3025,8 +3197,10 @@ struct Vec3 { /// - `1` if the number is positive /// - `-1` if the number is negative - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::IVec2; + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -3034,22 +3208,25 @@ struct Vec3 { /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Computes the squared length of `self`. - #[lua(kind = "Method")] - fn length_squared(self) -> i32; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> i32; "#, r#" /// Compute the squared euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::IVec2) -> i32; + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i32; "#, r#" @@ -3057,8 +3234,11 @@ struct Vec3 { /// # Panics /// This function will panic if any `rhs` element is 0 or the division results in overflow. - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -3067,23 +3247,31 @@ struct Vec3 { /// This function will panic if any `rhs` element is 0 or the division results in overflow. /// [Euclidean division]: i32::rem_euclid - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector that is equal to `self` rotated by 90 degrees. - #[lua(kind = "Method", output(proxy))] - fn perp(self) -> bevy::math::IVec2; + #[lua()] + fn perp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// The perpendicular dot product of `self` and `rhs`. /// Also known as the wedge product, 2D cross product, and determinant. - #[lua(kind = "Method")] - fn perp_dot(self, #[proxy] rhs: bevy::math::IVec2) -> i32; + #[lua()] + fn perp_dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i32; "#, r#" @@ -3091,613 +3279,552 @@ struct Vec3 { /// then this just rotation. This is what you usually want. Otherwise, /// it will be like a rotation with a multiplication by `self`'s length. - #[lua(kind = "Method", output(proxy))] - fn rotate(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua()] + fn rotate( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec2(&self) -> bevy::math::Vec2; + #[lua()] + fn as_vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec2(&self) -> bevy::math::DVec2; + #[lua()] + fn as_dvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec2(&self) -> bevy::math::UVec2; + #[lua()] + fn as_uvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec2(&self) -> bevy::math::I64Vec2; + #[lua()] + fn as_i64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec2(&self) -> bevy::math::U64Vec2; + #[lua()] + fn as_u64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping multiplication of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping division of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and `rhs`. /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and `rhs`. /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating multiplication of `self` and `rhs`. /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating division of `self` and `rhs`. /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.wrapping_add_unsigned(rhs.x), self.y.wrapping_add_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add_unsigned(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::IVec2; + #[lua()] + fn wrapping_add_unsigned( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.wrapping_sub_unsigned(rhs.x), self.y.wrapping_sub_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub_unsigned(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::IVec2; + #[lua()] + fn wrapping_sub_unsigned( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// In other words this computes `[self.x.saturating_add_unsigned(rhs.x), self.y.saturating_add_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_add_unsigned( - self, - #[proxy] - rhs: bevy::math::UVec2, - ) -> bevy::math::IVec2; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.saturating_sub_unsigned(rhs.x), self.y.saturating_sub_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_sub_unsigned( - self, - #[proxy] - rhs: bevy::math::UVec2, - ) -> bevy::math::IVec2; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::IVec2) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::IVec2>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: i32) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::IVec2) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Add::<&bevy::math::IVec2>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::IVec2; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::IVec2) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: i32) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::IVec2) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::IVec2>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::IVec2) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Div::<&bevy::math::IVec2>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: i32) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::IVec2) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::IVec2>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: i32) -> bevy::math::IVec2; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> LuaIdentityProxy { + _self[idx - 1] } "#, r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: i32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: i32) -> () { + _self[idx - 1] = val } "#] )] -struct IVec2 { +pub struct IVec2 { x: i32, y: i32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::IVec3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: i32) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::IVec3; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: i32) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::IVec3) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::IVec3>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::IVec3) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: i32) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: i32) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::IVec3) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::IVec3>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::IVec3) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Add::<&bevy::math::IVec3>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::IVec3) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Div::<&bevy::math::IVec3>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::IVec3) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::IVec3>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: i32) -> bevy::math::IVec3; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: i32, y: i32, z: i32) -> bevy::math::IVec3; + #[lua()] + fn new(x: i32, y: i32, z: i32) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: i32) -> bevy::math::IVec3; + #[lua()] + fn splat(v: i32) -> LuaReflectValProxy; "#, r#" @@ -3706,102 +3833,128 @@ struct IVec2 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec3, - #[proxy] - if_true: bevy::math::IVec3, - #[proxy] - if_false: bevy::math::IVec3, - ) -> bevy::math::IVec3; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [i32; 3]) -> bevy::math::IVec3; + #[lua()] + fn from_array(a: [i32; 3]) -> LuaReflectValProxy; "#, r#" /// `[x, y, z]` - #[lua(kind = "Method")] - fn to_array(&self) -> [i32; 3]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i32; 3]; "#, r#" /// Creates a 4D vector from `self` and the given `w` value. - #[lua(kind = "Method", output(proxy))] - fn extend(self, w: i32) -> bevy::math::IVec4; + #[lua()] + fn extend( + _self: LuaReflectValProxy, + w: i32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. /// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::IVec2; + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: i32) -> bevy::math::IVec3; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: i32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: i32) -> bevy::math::IVec3; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: i32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `z`. - #[lua(kind = "Method", output(proxy))] - fn with_z(self, z: i32) -> bevy::math::IVec3; + #[lua()] + fn with_z( + _self: LuaReflectValProxy, + z: i32, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::IVec3) -> i32; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i32; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the cross product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn cross(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua()] + fn cross( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -3810,46 +3963,44 @@ struct IVec2 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::IVec3, - #[proxy] - max: bevy::math::IVec3, - ) -> bevy::math::IVec3; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> i32; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> i32; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> i32; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> i32; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> i32; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> i32; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> i32; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> i32; "#, r#" @@ -3858,8 +4009,11 @@ struct IVec2 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -3868,8 +4022,11 @@ struct IVec2 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -3878,8 +4035,11 @@ struct IVec2 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -3888,8 +4048,11 @@ struct IVec2 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -3898,8 +4061,11 @@ struct IVec2 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -3908,15 +4074,20 @@ struct IVec2 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::BVec3; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the absolute value of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::IVec3; + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -3925,8 +4096,10 @@ struct IVec2 { /// - `1` if the number is positive /// - `-1` if the number is negative - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::IVec3; + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -3934,22 +4107,25 @@ struct IVec2 { /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Computes the squared length of `self`. - #[lua(kind = "Method")] - fn length_squared(self) -> i32; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> i32; "#, r#" /// Compute the squared euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::IVec3) -> i32; + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i32; "#, r#" @@ -3957,8 +4133,11 @@ struct IVec2 { /// # Panics /// This function will panic if any `rhs` element is 0 or the division results in overflow. - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -3967,342 +4146,351 @@ struct IVec2 { /// This function will panic if any `rhs` element is 0 or the division results in overflow. /// [Euclidean division]: i32::rem_euclid - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec3(&self) -> bevy::math::Vec3; + #[lua()] + fn as_vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec3a(&self) -> bevy::math::Vec3A; + #[lua()] + fn as_vec3a( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec3(&self) -> bevy::math::DVec3; + #[lua()] + fn as_dvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec3(&self) -> bevy::math::UVec3; + #[lua()] + fn as_uvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec3(&self) -> bevy::math::I64Vec3; + #[lua()] + fn as_i64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec3(&self) -> bevy::math::U64Vec3; + #[lua()] + fn as_u64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping multiplication of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping division of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and `rhs`. /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and `rhs`. /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating multiplication of `self` and `rhs`. /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating division of `self` and `rhs`. /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::IVec3; + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.wrapping_add_unsigned(rhs.x), self.y.wrapping_add_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add_unsigned(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::IVec3; + #[lua()] + fn wrapping_add_unsigned( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.wrapping_sub_unsigned(rhs.x), self.y.wrapping_sub_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub_unsigned(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::IVec3; + #[lua()] + fn wrapping_sub_unsigned( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// In other words this computes `[self.x.saturating_add_unsigned(rhs.x), self.y.saturating_add_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_add_unsigned( - self, - #[proxy] - rhs: bevy::math::UVec3, - ) -> bevy::math::IVec3; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.saturating_sub_unsigned(rhs.x), self.y.saturating_sub_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_sub_unsigned( - self, - #[proxy] - rhs: bevy::math::UVec3, - ) -> bevy::math::IVec3; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> LuaIdentityProxy { + _self[idx - 1] } "#, r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: i32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: i32) -> () { + _self[idx - 1] = val } "#] )] -struct IVec3 { +pub struct IVec3 { x: i32, y: i32, z: i32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::IVec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: i32) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: i32) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::IVec4) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: i32) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: i32) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: i32) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::IVec4) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::IVec4>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::IVec4; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: i32, y: i32, z: i32, w: i32) -> bevy::math::IVec4; + #[lua()] + fn new(x: i32, y: i32, z: i32, w: i32) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: i32) -> bevy::math::IVec4; + #[lua()] + fn splat(v: i32) -> LuaReflectValProxy; "#, r#" @@ -4311,95 +4499,118 @@ struct IVec3 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec4, - #[proxy] - if_true: bevy::math::IVec4, - #[proxy] - if_false: bevy::math::IVec4, - ) -> bevy::math::IVec4; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [i32; 4]) -> bevy::math::IVec4; + #[lua()] + fn from_array(a: [i32; 4]) -> LuaReflectValProxy; "#, r#" /// `[x, y, z, w]` - #[lua(kind = "Method")] - fn to_array(&self) -> [i32; 4]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i32; 4]; "#, r#" /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. /// Truncation to [`IVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::IVec3; + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: i32) -> bevy::math::IVec4; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: i32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: i32) -> bevy::math::IVec4; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: i32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `z`. - #[lua(kind = "Method", output(proxy))] - fn with_z(self, z: i32) -> bevy::math::IVec4; + #[lua()] + fn with_z( + _self: LuaReflectValProxy, + z: i32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `w`. - #[lua(kind = "Method", output(proxy))] - fn with_w(self, w: i32) -> bevy::math::IVec4; + #[lua()] + fn with_w( + _self: LuaReflectValProxy, + w: i32, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::IVec4) -> i32; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i32; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4408,46 +4619,44 @@ struct IVec3 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::IVec4, - #[proxy] - max: bevy::math::IVec4, - ) -> bevy::math::IVec4; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> i32; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> i32; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> i32; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> i32; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> i32; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> i32; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> i32; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> i32; "#, r#" @@ -4456,8 +4665,11 @@ struct IVec3 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4466,8 +4678,11 @@ struct IVec3 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4476,8 +4691,11 @@ struct IVec3 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4486,8 +4704,11 @@ struct IVec3 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4496,8 +4717,11 @@ struct IVec3 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4506,15 +4730,20 @@ struct IVec3 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::BVec4; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the absolute value of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::IVec4; + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4523,8 +4752,10 @@ struct IVec3 { /// - `1` if the number is positive /// - `-1` if the number is negative - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::IVec4; + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4532,22 +4763,25 @@ struct IVec3 { /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Computes the squared length of `self`. - #[lua(kind = "Method")] - fn length_squared(self) -> i32; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> i32; "#, r#" /// Compute the squared euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::IVec4) -> i32; + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i32; "#, r#" @@ -4555,8 +4789,11 @@ struct IVec3 { /// # Panics /// This function will panic if any `rhs` element is 0 or the division results in overflow. - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4565,261 +4802,285 @@ struct IVec3 { /// This function will panic if any `rhs` element is 0 or the division results in overflow. /// [Euclidean division]: i32::rem_euclid - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec4(&self) -> bevy::math::Vec4; + #[lua()] + fn as_vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec4(&self) -> bevy::math::DVec4; + #[lua()] + fn as_dvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec4(&self) -> bevy::math::UVec4; + #[lua()] + fn as_uvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec4(&self) -> bevy::math::I64Vec4; + #[lua()] + fn as_i64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec4(&self) -> bevy::math::U64Vec4; + #[lua()] + fn as_u64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping multiplication of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping division of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and `rhs`. /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and `rhs`. /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating multiplication of `self` and `rhs`. /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating division of `self` and `rhs`. /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.wrapping_add_unsigned(rhs.x), self.y.wrapping_add_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add_unsigned(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::IVec4; + #[lua()] + fn wrapping_add_unsigned( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.wrapping_sub_unsigned(rhs.x), self.y.wrapping_sub_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub_unsigned(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::IVec4; + #[lua()] + fn wrapping_sub_unsigned( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// In other words this computes `[self.x.saturating_add_unsigned(rhs.x), self.y.saturating_add_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_add_unsigned( - self, - #[proxy] - rhs: bevy::math::UVec4, - ) -> bevy::math::IVec4; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.saturating_sub_unsigned(rhs.x), self.y.saturating_sub_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_sub_unsigned( - self, - #[proxy] - rhs: bevy::math::UVec4, - ) -> bevy::math::IVec4; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::IVec4) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Add::<&bevy::math::IVec4>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::IVec4) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Div::<&bevy::math::IVec4>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::IVec4) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::IVec4>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::IVec4) -> bevy::math::IVec4; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::IVec4>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> LuaIdentityProxy { + _self[idx - 1] } "#, r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: i32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: i32) -> () { + _self[idx - 1] = val } "#] )] -struct IVec4 { +pub struct IVec4 { x: i32, y: i32, z: i32, w: i32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::I64Vec2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: i64, y: i64) -> bevy::math::I64Vec2; + #[lua()] + fn new(x: i64, y: i64) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: i64) -> bevy::math::I64Vec2; + #[lua()] + fn splat(v: i64) -> LuaReflectValProxy; "#, r#" @@ -4828,80 +5089,98 @@ struct IVec4 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec2, - #[proxy] - if_true: bevy::math::I64Vec2, - #[proxy] - if_false: bevy::math::I64Vec2, - ) -> bevy::math::I64Vec2; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [i64; 2]) -> bevy::math::I64Vec2; + #[lua()] + fn from_array(a: [i64; 2]) -> LuaReflectValProxy; "#, r#" /// `[x, y]` - #[lua(kind = "Method")] - fn to_array(&self) -> [i64; 2]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i64; 2]; "#, r#" /// Creates a 3D vector from `self` and the given `z` value. - #[lua(kind = "Method", output(proxy))] - fn extend(self, z: i64) -> bevy::math::I64Vec3; + #[lua()] + fn extend( + _self: LuaReflectValProxy, + z: i64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: i64) -> bevy::math::I64Vec2; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: i64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: i64) -> bevy::math::I64Vec2; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: i64, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::I64Vec2) -> i64; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i64; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4910,46 +5189,44 @@ struct IVec4 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::I64Vec2, - #[proxy] - max: bevy::math::I64Vec2, - ) -> bevy::math::I64Vec2; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> i64; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> i64; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> i64; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> i64; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> i64; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> i64; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> i64; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> i64; "#, r#" @@ -4958,8 +5235,11 @@ struct IVec4 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4968,8 +5248,11 @@ struct IVec4 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4978,8 +5261,11 @@ struct IVec4 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4988,8 +5274,11 @@ struct IVec4 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -4998,8 +5287,11 @@ struct IVec4 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -5008,15 +5300,20 @@ struct IVec4 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the absolute value of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::I64Vec2; + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -5025,8 +5322,10 @@ struct IVec4 { /// - `1` if the number is positive /// - `-1` if the number is negative - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::I64Vec2; + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -5034,22 +5333,25 @@ struct IVec4 { /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Computes the squared length of `self`. - #[lua(kind = "Method")] - fn length_squared(self) -> i64; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> i64; "#, r#" /// Compute the squared euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::I64Vec2) -> i64; + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i64; "#, r#" @@ -5057,8 +5359,11 @@ struct IVec4 { /// # Panics /// This function will panic if any `rhs` element is 0 or the division results in overflow. - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -5067,23 +5372,31 @@ struct IVec4 { /// This function will panic if any `rhs` element is 0 or the division results in overflow. /// [Euclidean division]: i64::rem_euclid - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector that is equal to `self` rotated by 90 degrees. - #[lua(kind = "Method", output(proxy))] - fn perp(self) -> bevy::math::I64Vec2; + #[lua()] + fn perp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// The perpendicular dot product of `self` and `rhs`. /// Also known as the wedge product, 2D cross product, and determinant. - #[lua(kind = "Method")] - fn perp_dot(self, #[proxy] rhs: bevy::math::I64Vec2) -> i64; + #[lua()] + fn perp_dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i64; "#, r#" @@ -5091,402 +5404,383 @@ struct IVec4 { /// then this just rotation. This is what you usually want. Otherwise, /// it will be like a rotation with a multiplication by `self`'s length. - #[lua(kind = "Method", output(proxy))] - fn rotate(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua()] + fn rotate( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec2(&self) -> bevy::math::Vec2; + #[lua()] + fn as_vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec2(&self) -> bevy::math::DVec2; + #[lua()] + fn as_dvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec2(&self) -> bevy::math::IVec2; + #[lua()] + fn as_ivec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec2(&self) -> bevy::math::UVec2; + #[lua()] + fn as_uvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec2(&self) -> bevy::math::U64Vec2; + #[lua()] + fn as_u64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping multiplication of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping division of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and `rhs`. /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and `rhs`. /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating multiplication of `self` and `rhs`. /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating division of `self` and `rhs`. /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.wrapping_add_unsigned(rhs.x), self.y.wrapping_add_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn wrapping_add_unsigned( - self, - #[proxy] - rhs: bevy::math::U64Vec2, - ) -> bevy::math::I64Vec2; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.wrapping_sub_unsigned(rhs.x), self.y.wrapping_sub_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn wrapping_sub_unsigned( - self, - #[proxy] - rhs: bevy::math::U64Vec2, - ) -> bevy::math::I64Vec2; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// In other words this computes `[self.x.saturating_add_unsigned(rhs.x), self.y.saturating_add_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_add_unsigned( - self, - #[proxy] - rhs: bevy::math::U64Vec2, - ) -> bevy::math::I64Vec2; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.saturating_sub_unsigned(rhs.x), self.y.saturating_sub_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_sub_unsigned( - self, - #[proxy] - rhs: bevy::math::U64Vec2, - ) -> bevy::math::I64Vec2; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: i64) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::I64Vec2; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: i64) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: i64) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::I64Vec2) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::I64Vec2>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::I64Vec2) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Div::<&bevy::math::I64Vec2>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: i64) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::I64Vec2) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::I64Vec2) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Add::<&bevy::math::I64Vec2>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::I64Vec2) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::I64Vec2>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: i64) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::I64Vec2) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::I64Vec2>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::I64Vec2) -> bevy::math::I64Vec2; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct I64Vec2 { +pub struct I64Vec2 { x: i64, y: i64, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::I64Vec3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: i64, y: i64, z: i64) -> bevy::math::I64Vec3; + #[lua()] + fn new(x: i64, y: i64, z: i64) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: i64) -> bevy::math::I64Vec3; + #[lua()] + fn splat(v: i64) -> LuaReflectValProxy; "#, r#" @@ -5495,102 +5789,128 @@ struct I64Vec2 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec3, - #[proxy] - if_true: bevy::math::I64Vec3, - #[proxy] - if_false: bevy::math::I64Vec3, - ) -> bevy::math::I64Vec3; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [i64; 3]) -> bevy::math::I64Vec3; + #[lua()] + fn from_array(a: [i64; 3]) -> LuaReflectValProxy; "#, r#" /// `[x, y, z]` - #[lua(kind = "Method")] - fn to_array(&self) -> [i64; 3]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i64; 3]; "#, r#" /// Creates a 4D vector from `self` and the given `w` value. - #[lua(kind = "Method", output(proxy))] - fn extend(self, w: i64) -> bevy::math::I64Vec4; + #[lua()] + fn extend( + _self: LuaReflectValProxy, + w: i64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. /// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::I64Vec2; + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: i64) -> bevy::math::I64Vec3; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: i64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: i64) -> bevy::math::I64Vec3; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: i64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `z`. - #[lua(kind = "Method", output(proxy))] - fn with_z(self, z: i64) -> bevy::math::I64Vec3; + #[lua()] + fn with_z( + _self: LuaReflectValProxy, + z: i64, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::I64Vec3) -> i64; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i64; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the cross product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn cross(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua()] + fn cross( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -5599,46 +5919,44 @@ struct I64Vec2 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::I64Vec3, - #[proxy] - max: bevy::math::I64Vec3, - ) -> bevy::math::I64Vec3; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> i64; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> i64; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> i64; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> i64; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> i64; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> i64; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> i64; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> i64; "#, r#" @@ -5647,8 +5965,11 @@ struct I64Vec2 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -5657,8 +5978,11 @@ struct I64Vec2 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -5667,8 +5991,11 @@ struct I64Vec2 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -5677,8 +6004,11 @@ struct I64Vec2 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -5687,8 +6017,11 @@ struct I64Vec2 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -5697,15 +6030,20 @@ struct I64Vec2 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the absolute value of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::I64Vec3; + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -5714,8 +6052,10 @@ struct I64Vec2 { /// - `1` if the number is positive /// - `-1` if the number is negative - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::I64Vec3; + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -5723,22 +6063,25 @@ struct I64Vec2 { /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Computes the squared length of `self`. - #[lua(kind = "Method")] - fn length_squared(self) -> i64; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> i64; "#, r#" /// Compute the squared euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::I64Vec3) -> i64; + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i64; "#, r#" @@ -5746,8 +6089,11 @@ struct I64Vec2 { /// # Panics /// This function will panic if any `rhs` element is 0 or the division results in overflow. - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -5756,479 +6102,446 @@ struct I64Vec2 { /// This function will panic if any `rhs` element is 0 or the division results in overflow. /// [Euclidean division]: i64::rem_euclid - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec3(&self) -> bevy::math::Vec3; + #[lua()] + fn as_vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec3a(&self) -> bevy::math::Vec3A; + #[lua()] + fn as_vec3a( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec3(&self) -> bevy::math::DVec3; + #[lua()] + fn as_dvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec3(&self) -> bevy::math::IVec3; + #[lua()] + fn as_ivec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec3(&self) -> bevy::math::UVec3; + #[lua()] + fn as_uvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec3(&self) -> bevy::math::U64Vec3; + #[lua()] + fn as_u64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping multiplication of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping division of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and `rhs`. /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and `rhs`. /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating multiplication of `self` and `rhs`. /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating division of `self` and `rhs`. /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.wrapping_add_unsigned(rhs.x), self.y.wrapping_add_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn wrapping_add_unsigned( - self, - #[proxy] - rhs: bevy::math::U64Vec3, - ) -> bevy::math::I64Vec3; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.wrapping_sub_unsigned(rhs.x), self.y.wrapping_sub_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn wrapping_sub_unsigned( - self, - #[proxy] - rhs: bevy::math::U64Vec3, - ) -> bevy::math::I64Vec3; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// In other words this computes `[self.x.saturating_add_unsigned(rhs.x), self.y.saturating_add_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_add_unsigned( - self, - #[proxy] - rhs: bevy::math::U64Vec3, - ) -> bevy::math::I64Vec3; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.saturating_sub_unsigned(rhs.x), self.y.saturating_sub_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_sub_unsigned( - self, - #[proxy] - rhs: bevy::math::U64Vec3, - ) -> bevy::math::I64Vec3; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: i64) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: i64) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::I64Vec3) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::I64Vec3>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::I64Vec3; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::I64Vec3) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: i64) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::I64Vec3) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::I64Vec3>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: i64) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::I64Vec3) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Add::<&bevy::math::I64Vec3>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: i64) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::I64Vec3) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::I64Vec3>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::I64Vec3) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::I64Vec3) -> bevy::math::I64Vec3; + #[lua(as_trait = "std::ops::Div::<&bevy::math::I64Vec3>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct I64Vec3 { +pub struct I64Vec3 { x: i64, y: i64, z: i64, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::I64Vec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: i64) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::I64Vec4; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::I64Vec4) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::I64Vec4>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::I64Vec4) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Div::<&bevy::math::I64Vec4>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::I64Vec4) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: i64, y: i64, z: i64, w: i64) -> bevy::math::I64Vec4; + #[lua()] + fn new(x: i64, y: i64, z: i64, w: i64) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: i64) -> bevy::math::I64Vec4; + #[lua()] + fn splat(v: i64) -> LuaReflectValProxy; "#, r#" @@ -6237,95 +6550,118 @@ struct I64Vec3 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec4, - #[proxy] - if_true: bevy::math::I64Vec4, - #[proxy] - if_false: bevy::math::I64Vec4, - ) -> bevy::math::I64Vec4; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [i64; 4]) -> bevy::math::I64Vec4; + #[lua()] + fn from_array(a: [i64; 4]) -> LuaReflectValProxy; "#, r#" /// `[x, y, z, w]` - #[lua(kind = "Method")] - fn to_array(&self) -> [i64; 4]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i64; 4]; "#, r#" /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. /// Truncation to [`I64Vec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::I64Vec3; + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: i64) -> bevy::math::I64Vec4; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: i64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: i64) -> bevy::math::I64Vec4; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: i64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `z`. - #[lua(kind = "Method", output(proxy))] - fn with_z(self, z: i64) -> bevy::math::I64Vec4; + #[lua()] + fn with_z( + _self: LuaReflectValProxy, + z: i64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `w`. - #[lua(kind = "Method", output(proxy))] - fn with_w(self, w: i64) -> bevy::math::I64Vec4; + #[lua()] + fn with_w( + _self: LuaReflectValProxy, + w: i64, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::I64Vec4) -> i64; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i64; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -6334,46 +6670,44 @@ struct I64Vec3 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::I64Vec4, - #[proxy] - max: bevy::math::I64Vec4, - ) -> bevy::math::I64Vec4; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> i64; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> i64; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> i64; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> i64; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> i64; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> i64; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> i64; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> i64; "#, r#" @@ -6382,8 +6716,11 @@ struct I64Vec3 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -6392,8 +6729,11 @@ struct I64Vec3 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -6402,8 +6742,11 @@ struct I64Vec3 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -6412,8 +6755,11 @@ struct I64Vec3 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -6422,8 +6768,11 @@ struct I64Vec3 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -6432,15 +6781,20 @@ struct I64Vec3 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::BVec4; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the absolute value of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::I64Vec4; + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -6449,8 +6803,10 @@ struct I64Vec3 { /// - `1` if the number is positive /// - `-1` if the number is negative - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::I64Vec4; + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -6458,22 +6814,25 @@ struct I64Vec3 { /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Computes the squared length of `self`. - #[lua(kind = "Method")] - fn length_squared(self) -> i64; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> i64; "#, r#" /// Compute the squared euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::I64Vec4) -> i64; + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> i64; "#, r#" @@ -6481,8 +6840,11 @@ struct I64Vec3 { /// # Panics /// This function will panic if any `rhs` element is 0 or the division results in overflow. - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -6491,459 +6853,427 @@ struct I64Vec3 { /// This function will panic if any `rhs` element is 0 or the division results in overflow. /// [Euclidean division]: i64::rem_euclid - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec4(&self) -> bevy::math::Vec4; + #[lua()] + fn as_vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec4(&self) -> bevy::math::DVec4; + #[lua()] + fn as_dvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec4(&self) -> bevy::math::IVec4; + #[lua()] + fn as_ivec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec4(&self) -> bevy::math::UVec4; + #[lua()] + fn as_uvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec4(&self) -> bevy::math::U64Vec4; + #[lua()] + fn as_u64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping multiplication of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping division of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and `rhs`. /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and `rhs`. /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating multiplication of `self` and `rhs`. /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating division of `self` and `rhs`. /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.wrapping_add_unsigned(rhs.x), self.y.wrapping_add_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn wrapping_add_unsigned( - self, - #[proxy] - rhs: bevy::math::U64Vec4, - ) -> bevy::math::I64Vec4; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.wrapping_sub_unsigned(rhs.x), self.y.wrapping_sub_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn wrapping_sub_unsigned( - self, - #[proxy] - rhs: bevy::math::U64Vec4, - ) -> bevy::math::I64Vec4; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// In other words this computes `[self.x.saturating_add_unsigned(rhs.x), self.y.saturating_add_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_add_unsigned( - self, - #[proxy] - rhs: bevy::math::U64Vec4, - ) -> bevy::math::I64Vec4; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and unsigned vector `rhs`. /// In other words this computes `[self.x.saturating_sub_unsigned(rhs.x), self.y.saturating_sub_unsigned(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_sub_unsigned( - self, - #[proxy] - rhs: bevy::math::U64Vec4, - ) -> bevy::math::I64Vec4; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::I64Vec4) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::I64Vec4>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: i64) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::I64Vec4) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::I64Vec4>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: i64) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: i64) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::I64Vec4) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Add::<&bevy::math::I64Vec4>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: i64) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::I64Vec4) -> bevy::math::I64Vec4; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct I64Vec4 { +pub struct I64Vec4 { x: i64, y: i64, z: i64, w: i64, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::UVec2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::UVec2) -> bevy::math::UVec2; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::UVec2>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::UVec2) -> bevy::math::UVec2; + #[lua(as_trait = "std::ops::Div::<&bevy::math::UVec2>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::UVec2; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: u32) -> bevy::math::UVec2; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: u32) -> bevy::math::UVec2; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::UVec2) -> bevy::math::UVec2; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::UVec2>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: u32, y: u32) -> bevy::math::UVec2; + #[lua()] + fn new(x: u32, y: u32) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: u32) -> bevy::math::UVec2; + #[lua()] + fn splat(v: u32) -> LuaReflectValProxy; "#, r#" @@ -6952,80 +7282,98 @@ struct I64Vec4 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec2, - #[proxy] - if_true: bevy::math::UVec2, - #[proxy] - if_false: bevy::math::UVec2, - ) -> bevy::math::UVec2; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [u32; 2]) -> bevy::math::UVec2; + #[lua()] + fn from_array(a: [u32; 2]) -> LuaReflectValProxy; "#, r#" /// `[x, y]` - #[lua(kind = "Method")] - fn to_array(&self) -> [u32; 2]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [u32; 2]; "#, r#" /// Creates a 3D vector from `self` and the given `z` value. - #[lua(kind = "Method", output(proxy))] - fn extend(self, z: u32) -> bevy::math::UVec3; + #[lua()] + fn extend( + _self: LuaReflectValProxy, + z: u32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: u32) -> bevy::math::UVec2; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: u32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: u32) -> bevy::math::UVec2; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: u32, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::UVec2) -> u32; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> u32; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -7034,46 +7382,44 @@ struct I64Vec4 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::UVec2, - #[proxy] - max: bevy::math::UVec2, - ) -> bevy::math::UVec2; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> u32; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> u32; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> u32; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> u32; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> u32; "#, r#" @@ -7082,8 +7428,11 @@ struct I64Vec4 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -7092,8 +7441,11 @@ struct I64Vec4 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -7102,8 +7454,11 @@ struct I64Vec4 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -7112,8 +7467,11 @@ struct I64Vec4 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -7122,8 +7480,11 @@ struct I64Vec4 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -7132,383 +7493,376 @@ struct I64Vec4 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::BVec2; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the squared length of `self`. - #[lua(kind = "Method")] - fn length_squared(self) -> u32; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> u32; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec2(&self) -> bevy::math::Vec2; + #[lua()] + fn as_vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec2(&self) -> bevy::math::DVec2; + #[lua()] + fn as_dvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec2(&self) -> bevy::math::IVec2; + #[lua()] + fn as_ivec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec2(&self) -> bevy::math::I64Vec2; + #[lua()] + fn as_i64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec2(&self) -> bevy::math::U64Vec2; + #[lua()] + fn as_u64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping multiplication of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping division of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and `rhs`. /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and `rhs`. /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating multiplication of `self` and `rhs`. /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating division of `self` and `rhs`. /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`. /// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add_signed(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::UVec2; + #[lua()] + fn wrapping_add_signed( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and signed vector `rhs`. /// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_add_signed(self, #[proxy] rhs: bevy::math::IVec2) -> bevy::math::UVec2; + #[lua()] + fn saturating_add_signed( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::UVec2) -> bevy::math::UVec2; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: u32) -> bevy::math::UVec2; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: u32) -> bevy::math::UVec2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::UVec2) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: u32) -> bevy::math::UVec2; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::UVec2) -> bevy::math::UVec2; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::UVec2>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::UVec2) -> bevy::math::UVec2; + #[lua(as_trait = "std::ops::Add::<&bevy::math::UVec2>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> LuaIdentityProxy { + _self[idx - 1] } "#, r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: u32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: u32) -> () { + _self[idx - 1] = val } "#] )] -struct UVec2 { +pub struct UVec2 { x: u32, y: u32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::UVec3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::UVec3) -> bevy::math::UVec3; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::UVec3>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::UVec3) -> bevy::math::UVec3; + #[lua(as_trait = "std::ops::Div::<&bevy::math::UVec3>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::UVec3) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::UVec3) -> bevy::math::UVec3; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::UVec3>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::UVec3; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: u32) -> bevy::math::UVec3; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: u32) -> bevy::math::UVec3; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: u32) -> bevy::math::UVec3; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: u32, y: u32, z: u32) -> bevy::math::UVec3; + #[lua()] + fn new(x: u32, y: u32, z: u32) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: u32) -> bevy::math::UVec3; + #[lua()] + fn splat(v: u32) -> LuaReflectValProxy; "#, r#" @@ -7517,102 +7871,128 @@ struct UVec2 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec3, - #[proxy] - if_true: bevy::math::UVec3, - #[proxy] - if_false: bevy::math::UVec3, - ) -> bevy::math::UVec3; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [u32; 3]) -> bevy::math::UVec3; + #[lua()] + fn from_array(a: [u32; 3]) -> LuaReflectValProxy; "#, r#" /// `[x, y, z]` - #[lua(kind = "Method")] - fn to_array(&self) -> [u32; 3]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [u32; 3]; "#, r#" /// Creates a 4D vector from `self` and the given `w` value. - #[lua(kind = "Method", output(proxy))] - fn extend(self, w: u32) -> bevy::math::UVec4; + #[lua()] + fn extend( + _self: LuaReflectValProxy, + w: u32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. /// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::UVec2; + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: u32) -> bevy::math::UVec3; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: u32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: u32) -> bevy::math::UVec3; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: u32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `z`. - #[lua(kind = "Method", output(proxy))] - fn with_z(self, z: u32) -> bevy::math::UVec3; + #[lua()] + fn with_z( + _self: LuaReflectValProxy, + z: u32, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::UVec3) -> u32; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> u32; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the cross product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn cross(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua()] + fn cross( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -7621,46 +8001,44 @@ struct UVec2 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::UVec3, - #[proxy] - max: bevy::math::UVec3, - ) -> bevy::math::UVec3; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> u32; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> u32; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> u32; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> u32; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> u32; "#, r#" @@ -7669,8 +8047,11 @@ struct UVec2 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -7679,8 +8060,11 @@ struct UVec2 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -7689,8 +8073,11 @@ struct UVec2 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -7699,8 +8086,11 @@ struct UVec2 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -7709,8 +8099,11 @@ struct UVec2 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -7719,335 +8112,345 @@ struct UVec2 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::BVec3; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the squared length of `self`. - #[lua(kind = "Method")] - fn length_squared(self) -> u32; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> u32; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec3(&self) -> bevy::math::Vec3; + #[lua()] + fn as_vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec3a(&self) -> bevy::math::Vec3A; + #[lua()] + fn as_vec3a( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec3(&self) -> bevy::math::DVec3; + #[lua()] + fn as_dvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec3(&self) -> bevy::math::IVec3; + #[lua()] + fn as_ivec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec3(&self) -> bevy::math::I64Vec3; + #[lua()] + fn as_i64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec3(&self) -> bevy::math::U64Vec3; + #[lua()] + fn as_u64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping multiplication of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping division of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and `rhs`. /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and `rhs`. /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating multiplication of `self` and `rhs`. /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating division of `self` and `rhs`. /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`. /// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add_signed(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::UVec3; + #[lua()] + fn wrapping_add_signed( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and signed vector `rhs`. /// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_add_signed(self, #[proxy] rhs: bevy::math::IVec3) -> bevy::math::UVec3; + #[lua()] + fn saturating_add_signed( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::UVec3) -> bevy::math::UVec3; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::UVec3>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: u32) -> bevy::math::UVec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::UVec3) -> bevy::math::UVec3; + #[lua(as_trait = "std::ops::Add::<&bevy::math::UVec3>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: u32) -> bevy::math::UVec3; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::UVec3) -> bevy::math::UVec3; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> LuaIdentityProxy { + _self[idx - 1] } "#, r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: u32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: u32) -> () { + _self[idx - 1] = val } "#] )] -struct UVec3 { +pub struct UVec3 { x: u32, y: u32, z: u32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::UVec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::UVec4) -> bevy::math::UVec4; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::UVec4>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::UVec4) -> bevy::math::UVec4; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::UVec4>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: u32) -> bevy::math::UVec4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: u32, y: u32, z: u32, w: u32) -> bevy::math::UVec4; + #[lua()] + fn new(x: u32, y: u32, z: u32, w: u32) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: u32) -> bevy::math::UVec4; + #[lua()] + fn splat(v: u32) -> LuaReflectValProxy; "#, r#" @@ -8056,95 +8459,118 @@ struct UVec3 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec4, - #[proxy] - if_true: bevy::math::UVec4, - #[proxy] - if_false: bevy::math::UVec4, - ) -> bevy::math::UVec4; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [u32; 4]) -> bevy::math::UVec4; + #[lua()] + fn from_array(a: [u32; 4]) -> LuaReflectValProxy; "#, r#" /// `[x, y, z, w]` - #[lua(kind = "Method")] - fn to_array(&self) -> [u32; 4]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [u32; 4]; "#, r#" /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. /// Truncation to [`UVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::UVec3; + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: u32) -> bevy::math::UVec4; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: u32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: u32) -> bevy::math::UVec4; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: u32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `z`. - #[lua(kind = "Method", output(proxy))] - fn with_z(self, z: u32) -> bevy::math::UVec4; + #[lua()] + fn with_z( + _self: LuaReflectValProxy, + z: u32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `w`. - #[lua(kind = "Method", output(proxy))] - fn with_w(self, w: u32) -> bevy::math::UVec4; + #[lua()] + fn with_w( + _self: LuaReflectValProxy, + w: u32, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::UVec4) -> u32; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> u32; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -8153,46 +8579,44 @@ struct UVec3 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::UVec4, - #[proxy] - max: bevy::math::UVec4, - ) -> bevy::math::UVec4; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> u32; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> u32; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> u32; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> u32; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> u32; "#, r#" @@ -8201,8 +8625,11 @@ struct UVec3 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -8211,8 +8638,11 @@ struct UVec3 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -8221,8 +8651,11 @@ struct UVec3 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -8231,8 +8664,11 @@ struct UVec3 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -8241,8 +8677,11 @@ struct UVec3 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -8251,320 +8690,330 @@ struct UVec3 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::BVec4; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the squared length of `self`. - #[lua(kind = "Method")] - fn length_squared(self) -> u32; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> u32; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec4(&self) -> bevy::math::Vec4; + #[lua()] + fn as_vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec4(&self) -> bevy::math::DVec4; + #[lua()] + fn as_dvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec4(&self) -> bevy::math::IVec4; + #[lua()] + fn as_ivec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec4(&self) -> bevy::math::I64Vec4; + #[lua()] + fn as_i64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec4(&self) -> bevy::math::U64Vec4; + #[lua()] + fn as_u64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping multiplication of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping division of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and `rhs`. /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and `rhs`. /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating multiplication of `self` and `rhs`. /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating division of `self` and `rhs`. /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`. /// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add_signed(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::UVec4; + #[lua()] + fn wrapping_add_signed( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and signed vector `rhs`. /// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_add_signed(self, #[proxy] rhs: bevy::math::IVec4) -> bevy::math::UVec4; + #[lua()] + fn saturating_add_signed( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::UVec4; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::UVec4) -> bevy::math::UVec4; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::UVec4>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: u32) -> bevy::math::UVec4; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::UVec4) -> bevy::math::UVec4; + #[lua(as_trait = "std::ops::Div::<&bevy::math::UVec4>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: u32) -> bevy::math::UVec4; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::UVec4) -> bevy::math::UVec4; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: u32) -> bevy::math::UVec4; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::UVec4) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: u32) -> bevy::math::UVec4; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::UVec4) -> bevy::math::UVec4; + #[lua(as_trait = "std::ops::Add::<&bevy::math::UVec4>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> LuaIdentityProxy { + _self[idx - 1] } "#, r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: u32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: u32) -> () { + _self[idx - 1] = val } "#] )] -struct UVec4 { +pub struct UVec4 { x: u32, y: u32, z: u32, w: u32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::U64Vec2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: u64, y: u64) -> bevy::math::U64Vec2; + #[lua()] + fn new(x: u64, y: u64) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: u64) -> bevy::math::U64Vec2; + #[lua()] + fn splat(v: u64) -> LuaReflectValProxy; "#, r#" @@ -8573,80 +9022,98 @@ struct UVec4 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec2, - #[proxy] - if_true: bevy::math::U64Vec2, - #[proxy] - if_false: bevy::math::U64Vec2, - ) -> bevy::math::U64Vec2; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [u64; 2]) -> bevy::math::U64Vec2; + #[lua()] + fn from_array(a: [u64; 2]) -> LuaReflectValProxy; "#, r#" /// `[x, y]` - #[lua(kind = "Method")] - fn to_array(&self) -> [u64; 2]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [u64; 2]; "#, r#" /// Creates a 3D vector from `self` and the given `z` value. - #[lua(kind = "Method", output(proxy))] - fn extend(self, z: u64) -> bevy::math::U64Vec3; + #[lua()] + fn extend( + _self: LuaReflectValProxy, + z: u64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: u64) -> bevy::math::U64Vec2; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: u64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: u64) -> bevy::math::U64Vec2; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: u64, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::U64Vec2) -> u64; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> u64; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -8655,46 +9122,44 @@ struct UVec4 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::U64Vec2, - #[proxy] - max: bevy::math::U64Vec2, - ) -> bevy::math::U64Vec2; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> u64; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> u64; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> u64; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> u64; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> u64; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> u64; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> u64; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> u64; "#, r#" @@ -8703,8 +9168,11 @@ struct UVec4 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -8713,8 +9181,11 @@ struct UVec4 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -8723,8 +9194,11 @@ struct UVec4 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -8733,8 +9207,11 @@ struct UVec4 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -8743,8 +9220,11 @@ struct UVec4 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -8753,440 +9233,409 @@ struct UVec4 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the squared length of `self`. - #[lua(kind = "Method")] - fn length_squared(self) -> u64; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> u64; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec2(&self) -> bevy::math::Vec2; + #[lua()] + fn as_vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec2(&self) -> bevy::math::DVec2; + #[lua()] + fn as_dvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec2(&self) -> bevy::math::IVec2; + #[lua()] + fn as_ivec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec2(&self) -> bevy::math::UVec2; + #[lua()] + fn as_uvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec2(&self) -> bevy::math::I64Vec2; + #[lua()] + fn as_i64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping multiplication of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping division of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and `rhs`. /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and `rhs`. /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating multiplication of `self` and `rhs`. /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating division of `self` and `rhs`. /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`. /// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn wrapping_add_signed( - self, - #[proxy] - rhs: bevy::math::I64Vec2, - ) -> bevy::math::U64Vec2; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and signed vector `rhs`. /// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_add_signed( - self, - #[proxy] - rhs: bevy::math::I64Vec2, - ) -> bevy::math::U64Vec2; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: u64) -> bevy::math::U64Vec2; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::U64Vec2) -> bevy::math::U64Vec2; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::U64Vec2>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: u64) -> bevy::math::U64Vec2; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: u64) -> bevy::math::U64Vec2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::U64Vec2) -> bevy::math::U64Vec2; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::U64Vec2>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::U64Vec2) -> bevy::math::U64Vec2; + #[lua(as_trait = "std::ops::Add::<&bevy::math::U64Vec2>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: u64) -> bevy::math::U64Vec2; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::U64Vec2) -> bevy::math::U64Vec2; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::U64Vec2) -> bevy::math::U64Vec2; + #[lua(as_trait = "std::ops::Div::<&bevy::math::U64Vec2>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::U64Vec2) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::U64Vec2) -> bevy::math::U64Vec2; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::U64Vec2>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::U64Vec2; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: u64) -> bevy::math::U64Vec2; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct U64Vec2 { +pub struct U64Vec2 { x: u64, y: u64, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::U64Vec3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: u64) -> bevy::math::U64Vec3; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::U64Vec3) -> bevy::math::U64Vec3; + #[lua(as_trait = "std::ops::Add::<&bevy::math::U64Vec3>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: u64) -> bevy::math::U64Vec3; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: u64) -> bevy::math::U64Vec3; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: u64, y: u64, z: u64) -> bevy::math::U64Vec3; + #[lua()] + fn new(x: u64, y: u64, z: u64) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: u64) -> bevy::math::U64Vec3; + #[lua()] + fn splat(v: u64) -> LuaReflectValProxy; "#, r#" @@ -9195,102 +9644,128 @@ struct U64Vec2 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec3, - #[proxy] - if_true: bevy::math::U64Vec3, - #[proxy] - if_false: bevy::math::U64Vec3, - ) -> bevy::math::U64Vec3; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [u64; 3]) -> bevy::math::U64Vec3; + #[lua()] + fn from_array(a: [u64; 3]) -> LuaReflectValProxy; "#, r#" /// `[x, y, z]` - #[lua(kind = "Method")] - fn to_array(&self) -> [u64; 3]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [u64; 3]; "#, r#" /// Creates a 4D vector from `self` and the given `w` value. - #[lua(kind = "Method", output(proxy))] - fn extend(self, w: u64) -> bevy::math::U64Vec4; + #[lua()] + fn extend( + _self: LuaReflectValProxy, + w: u64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. /// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::U64Vec2; + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: u64) -> bevy::math::U64Vec3; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: u64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: u64) -> bevy::math::U64Vec3; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: u64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `z`. - #[lua(kind = "Method", output(proxy))] - fn with_z(self, z: u64) -> bevy::math::U64Vec3; + #[lua()] + fn with_z( + _self: LuaReflectValProxy, + z: u64, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::U64Vec3) -> u64; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> u64; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the cross product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn cross(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua()] + fn cross( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -9299,46 +9774,44 @@ struct U64Vec2 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::U64Vec3, - #[proxy] - max: bevy::math::U64Vec3, - ) -> bevy::math::U64Vec3; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> u64; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> u64; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> u64; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> u64; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> u64; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> u64; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> u64; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> u64; "#, r#" @@ -9347,8 +9820,11 @@ struct U64Vec2 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -9357,8 +9833,11 @@ struct U64Vec2 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -9367,8 +9846,11 @@ struct U64Vec2 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -9377,8 +9859,11 @@ struct U64Vec2 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -9387,8 +9872,11 @@ struct U64Vec2 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -9397,469 +9885,439 @@ struct U64Vec2 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::BVec3; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the squared length of `self`. - #[lua(kind = "Method")] - fn length_squared(self) -> u64; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> u64; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec3(&self) -> bevy::math::Vec3; + #[lua()] + fn as_vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec3a(&self) -> bevy::math::Vec3A; + #[lua()] + fn as_vec3a( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec3(&self) -> bevy::math::DVec3; + #[lua()] + fn as_dvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec3(&self) -> bevy::math::IVec3; + #[lua()] + fn as_ivec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec3(&self) -> bevy::math::UVec3; + #[lua()] + fn as_uvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec3(&self) -> bevy::math::I64Vec3; + #[lua()] + fn as_i64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping multiplication of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping division of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and `rhs`. /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and `rhs`. /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating multiplication of `self` and `rhs`. /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating division of `self` and `rhs`. /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`. /// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn wrapping_add_signed( - self, - #[proxy] - rhs: bevy::math::I64Vec3, - ) -> bevy::math::U64Vec3; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and signed vector `rhs`. /// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_add_signed( - self, - #[proxy] - rhs: bevy::math::I64Vec3, - ) -> bevy::math::U64Vec3; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::U64Vec3) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: u64) -> bevy::math::U64Vec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::U64Vec3) -> bevy::math::U64Vec3; + #[lua(as_trait = "std::ops::Div::<&bevy::math::U64Vec3>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::U64Vec3) -> bevy::math::U64Vec3; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::U64Vec3>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: u64) -> bevy::math::U64Vec3; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::U64Vec3) -> bevy::math::U64Vec3; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::U64Vec3>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::U64Vec3) -> bevy::math::U64Vec3; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::U64Vec3>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::U64Vec3; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::U64Vec3) -> bevy::math::U64Vec3; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct U64Vec3 { +pub struct U64Vec3 { x: u64, y: u64, z: u64, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::U64Vec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: u64) -> bevy::math::U64Vec4; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: u64) -> bevy::math::U64Vec4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::U64Vec4) -> bevy::math::U64Vec4; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::U64Vec4>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::U64Vec4) -> bevy::math::U64Vec4; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::U64Vec4>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::U64Vec4) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: u64) -> bevy::math::U64Vec4; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::U64Vec4; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::U64Vec4) -> bevy::math::U64Vec4; + #[lua(as_trait = "std::ops::Div::<&bevy::math::U64Vec4>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::U64Vec4) -> bevy::math::U64Vec4; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::U64Vec4>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: u64, y: u64, z: u64, w: u64) -> bevy::math::U64Vec4; + #[lua()] + fn new(x: u64, y: u64, z: u64, w: u64) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: u64) -> bevy::math::U64Vec4; + #[lua()] + fn splat(v: u64) -> LuaReflectValProxy; "#, r#" @@ -9868,95 +10326,118 @@ struct U64Vec3 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec4, - #[proxy] - if_true: bevy::math::U64Vec4, - #[proxy] - if_false: bevy::math::U64Vec4, - ) -> bevy::math::U64Vec4; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [u64; 4]) -> bevy::math::U64Vec4; + #[lua()] + fn from_array(a: [u64; 4]) -> LuaReflectValProxy; "#, r#" /// `[x, y, z, w]` - #[lua(kind = "Method")] - fn to_array(&self) -> [u64; 4]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [u64; 4]; "#, r#" /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. /// Truncation to [`U64Vec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::U64Vec3; + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: u64) -> bevy::math::U64Vec4; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: u64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: u64) -> bevy::math::U64Vec4; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: u64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `z`. - #[lua(kind = "Method", output(proxy))] - fn with_z(self, z: u64) -> bevy::math::U64Vec4; + #[lua()] + fn with_z( + _self: LuaReflectValProxy, + z: u64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `w`. - #[lua(kind = "Method", output(proxy))] - fn with_w(self, w: u64) -> bevy::math::U64Vec4; + #[lua()] + fn with_w( + _self: LuaReflectValProxy, + w: u64, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::U64Vec4) -> u64; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> u64; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -9965,46 +10446,44 @@ struct U64Vec3 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::U64Vec4, - #[proxy] - max: bevy::math::U64Vec4, - ) -> bevy::math::U64Vec4; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> u64; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> u64; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> u64; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> u64; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> u64; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> u64; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> u64; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> u64; "#, r#" @@ -10013,8 +10492,11 @@ struct U64Vec3 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10023,8 +10505,11 @@ struct U64Vec3 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10033,8 +10518,11 @@ struct U64Vec3 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10043,8 +10531,11 @@ struct U64Vec3 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10053,8 +10544,11 @@ struct U64Vec3 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10063,336 +10557,331 @@ struct U64Vec3 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::BVec4; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the squared length of `self`. - #[lua(kind = "Method")] - fn length_squared(self) -> u64; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> u64; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec4(&self) -> bevy::math::Vec4; + #[lua()] + fn as_vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec4(&self) -> bevy::math::DVec4; + #[lua()] + fn as_dvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec4(&self) -> bevy::math::IVec4; + #[lua()] + fn as_ivec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec4(&self) -> bevy::math::UVec4; + #[lua()] + fn as_uvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec4(&self) -> bevy::math::I64Vec4; + #[lua()] + fn as_i64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_add(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua()] + fn wrapping_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping subtraction of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_sub(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua()] + fn wrapping_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping multiplication of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_mul(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua()] + fn wrapping_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping division of `self` and `rhs`. /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn wrapping_div(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua()] + fn wrapping_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and `rhs`. /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_add(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua()] + fn saturating_add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating subtraction of `self` and `rhs`. /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_sub(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua()] + fn saturating_sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating multiplication of `self` and `rhs`. /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_mul(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua()] + fn saturating_mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating division of `self` and `rhs`. /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn saturating_div(self, #[proxy] rhs: bevy::math::U64Vec4) -> bevy::math::U64Vec4; + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`. /// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn wrapping_add_signed( - self, - #[proxy] - rhs: bevy::math::I64Vec4, - ) -> bevy::math::U64Vec4; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the saturating addition of `self` and signed vector `rhs`. /// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn saturating_add_signed( - self, - #[proxy] - rhs: bevy::math::I64Vec4, - ) -> bevy::math::U64Vec4; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: u64) -> bevy::math::U64Vec4; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::U64Vec4) -> bevy::math::U64Vec4; + #[lua(as_trait = "std::ops::Add::<&bevy::math::U64Vec4>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: u64) -> bevy::math::U64Vec4; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct U64Vec4 { +pub struct U64Vec4 { x: u64, y: u64, z: u64, w: u64, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Vec2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: f32) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: f32) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::Vec2) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::Vec2) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::Vec2>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::Vec2) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Add::<&bevy::math::Vec2>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: f32) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: f32, y: f32) -> bevy::math::Vec2; + #[lua()] + fn new(x: f32, y: f32) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: f32) -> bevy::math::Vec2; + #[lua()] + fn splat(v: f32) -> LuaReflectValProxy; "#, r#" @@ -10401,80 +10890,98 @@ struct U64Vec4 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec2, - #[proxy] - if_true: bevy::math::Vec2, - #[proxy] - if_false: bevy::math::Vec2, - ) -> bevy::math::Vec2; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f32; 2]) -> bevy::math::Vec2; + #[lua()] + fn from_array(a: [f32; 2]) -> LuaReflectValProxy; "#, r#" /// `[x, y]` - #[lua(kind = "Method")] - fn to_array(&self) -> [f32; 2]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f32; 2]; "#, r#" /// Creates a 3D vector from `self` and the given `z` value. - #[lua(kind = "Method", output(proxy))] - fn extend(self, z: f32) -> bevy::math::Vec3; + #[lua()] + fn extend( + _self: LuaReflectValProxy, + z: f32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: f32) -> bevy::math::Vec2; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: f32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: f32) -> bevy::math::Vec2; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: f32, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::Vec2) -> f32; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10483,46 +10990,44 @@ struct U64Vec4 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::Vec2, - #[proxy] - max: bevy::math::Vec2, - ) -> bevy::math::Vec2; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> f32; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> f32; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> f32; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> f32; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> f32; "#, r#" @@ -10531,8 +11036,11 @@ struct U64Vec4 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10541,8 +11049,11 @@ struct U64Vec4 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10551,8 +11062,11 @@ struct U64Vec4 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10561,8 +11075,11 @@ struct U64Vec4 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10571,8 +11088,11 @@ struct U64Vec4 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10581,15 +11101,20 @@ struct U64Vec4 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::BVec2; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the absolute value of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::Vec2; + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10598,15 +11123,20 @@ struct U64Vec4 { /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` /// - `NAN` if the number is `NAN` - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::Vec2; + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector with signs of `rhs` and the magnitudes of `self`. - #[lua(kind = "Method", output(proxy))] - fn copysign(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn copysign( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10614,91 +11144,107 @@ struct U64Vec4 { /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns `true` if, and only if, all elements are finite. If any element is either /// `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; "#, r#" /// Performs `is_finite` on each element of self, returning a vector mask of the results. /// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`. - #[lua(kind = "Method", output(proxy))] - fn is_finite_mask(self) -> bevy::math::BVec2; + #[lua()] + fn is_finite_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; "#, r#" /// Performs `is_nan` on each element of self, returning a vector mask of the results. /// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`. - #[lua(kind = "Method", output(proxy))] - fn is_nan_mask(self) -> bevy::math::BVec2; + #[lua()] + fn is_nan_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the length of `self`. - #[lua(kind = "Method")] - fn length(self) -> f32; + #[lua()] + fn length(_self: LuaReflectValProxy) -> f32; "#, r#" /// Computes the squared length of `self`. /// This is faster than `length()` as it avoids a square root operation. - #[lua(kind = "Method")] - fn length_squared(self) -> f32; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f32; "#, r#" /// Computes `1.0 / length()`. /// For valid results, `self` must _not_ be of length zero. - #[lua(kind = "Method")] - fn length_recip(self) -> f32; + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f32; "#, r#" /// Computes the Euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance(self, #[proxy] rhs: bevy::math::Vec2) -> f32; + #[lua()] + fn distance( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" /// Compute the squared euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::Vec2) -> f32; + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. /// [Euclidean division]: f32::rem_euclid - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10708,8 +11254,10 @@ struct U64Vec4 { /// Panics /// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::Vec2; + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10719,8 +11267,11 @@ struct U64Vec4 { /// the result of this operation will be the fallback value. /// See also [`Self::try_normalize()`]. - #[lua(kind = "Method", output(proxy))] - fn normalize_or(self, #[proxy] fallback: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn normalize_or( + _self: LuaReflectValProxy, + fallback: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10729,16 +11280,18 @@ struct U64Vec4 { /// the result of this operation will be zero. /// See also [`Self::try_normalize()`]. - #[lua(kind = "Method", output(proxy))] - fn normalize_or_zero(self) -> bevy::math::Vec2; + #[lua()] + fn normalize_or_zero( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns whether `self` is length `1.0` or not. /// Uses a precision threshold of approximately `1e-4`. - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; "#, r#" @@ -10747,8 +11300,11 @@ struct U64Vec4 { /// # Panics /// Will panic if `rhs` is zero length when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn project_onto(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn project_onto( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10759,8 +11315,11 @@ struct U64Vec4 { /// # Panics /// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reject_from(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn reject_from( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10769,8 +11328,11 @@ struct U64Vec4 { /// # Panics /// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn project_onto_normalized(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn project_onto_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10781,40 +11343,51 @@ struct U64Vec4 { /// # Panics /// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reject_from_normalized(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn reject_from_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the nearest integer to a number for each element of `self`. /// Round half-way cases away from 0.0. - #[lua(kind = "Method", output(proxy))] - fn round(self) -> bevy::math::Vec2; + #[lua()] + fn round( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the largest integer less than or equal to a number for each /// element of `self`. - #[lua(kind = "Method", output(proxy))] - fn floor(self) -> bevy::math::Vec2; + #[lua()] + fn floor( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the smallest integer greater than or equal to a number for /// each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn ceil(self) -> bevy::math::Vec2; + #[lua()] + fn ceil( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the integer part each element of `self`. This means numbers are /// always truncated towards zero. - #[lua(kind = "Method", output(proxy))] - fn trunc(self) -> bevy::math::Vec2; + #[lua()] + fn trunc( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10823,8 +11396,10 @@ struct U64Vec4 { /// `self - self.floor()`. /// Note that this is fast but not precise for large numbers. - #[lua(kind = "Method", output(proxy))] - fn fract(self) -> bevy::math::Vec2; + #[lua()] + fn fract( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10833,30 +11408,39 @@ struct U64Vec4 { /// `self - self.trunc()`. /// Note that this is fast but not precise for large numbers. - #[lua(kind = "Method", output(proxy))] - fn fract_gl(self) -> bevy::math::Vec2; + #[lua()] + fn fract_gl( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing `e^self` (the exponential function) for each element of /// `self`. - #[lua(kind = "Method", output(proxy))] - fn exp(self) -> bevy::math::Vec2; + #[lua()] + fn exp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing each element of `self` raised to the power of `n`. - #[lua(kind = "Method", output(proxy))] - fn powf(self, n: f32) -> bevy::math::Vec2; + #[lua()] + fn powf( + _self: LuaReflectValProxy, + n: f32, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn recip(self) -> bevy::math::Vec2; + #[lua()] + fn recip( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10865,8 +11449,12 @@ struct U64Vec4 { /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly /// extrapolated. - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] rhs: bevy::math::Vec2, s: f32) -> bevy::math::Vec2; + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + s: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -10874,8 +11462,12 @@ struct U64Vec4 { /// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to /// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`. - #[lua(kind = "Method", output(proxy))] - fn move_towards(&self, #[proxy] rhs: bevy::math::Vec2, d: f32) -> bevy::math::Vec2; + #[lua()] + fn move_towards( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + d: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -10884,8 +11476,11 @@ struct U64Vec4 { /// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)` /// while being slightly cheaper to compute. - #[lua(kind = "Method", output(proxy))] - fn midpoint(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn midpoint( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10897,8 +11492,12 @@ struct U64Vec4 { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::Vec2, max_abs_diff: f32) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; "#, r#" @@ -10906,8 +11505,12 @@ struct U64Vec4 { /// # Panics /// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length(self, min: f32, max: f32) -> bevy::math::Vec2; + #[lua()] + fn clamp_length( + _self: LuaReflectValProxy, + min: f32, + max: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -10915,8 +11518,11 @@ struct U64Vec4 { /// # Panics /// Will panic if `max` is negative when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length_max(self, max: f32) -> bevy::math::Vec2; + #[lua()] + fn clamp_length_max( + _self: LuaReflectValProxy, + max: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -10924,8 +11530,11 @@ struct U64Vec4 { /// # Panics /// Will panic if `min` is negative when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length_min(self, min: f32) -> bevy::math::Vec2; + #[lua()] + fn clamp_length_min( + _self: LuaReflectValProxy, + min: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -10936,14 +11545,12 @@ struct U64Vec4 { /// and will be heavily dependant on designing algorithms with specific target hardware in /// mind. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn mul_add( - self, - #[proxy] - a: bevy::math::Vec2, - #[proxy] - b: bevy::math::Vec2, - ) -> bevy::math::Vec2; + _self: LuaReflectValProxy, + a: LuaReflectValProxy, + b: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10953,8 +11560,11 @@ struct U64Vec4 { /// # Panics /// Will panic if `normal` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reflect(self, #[proxy] normal: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn reflect( + _self: LuaReflectValProxy, + normal: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -10965,8 +11575,12 @@ struct U64Vec4 { /// # Panics /// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn refract(self, #[proxy] normal: bevy::math::Vec2, eta: f32) -> bevy::math::Vec2; + #[lua()] + fn refract( + _self: LuaReflectValProxy, + normal: LuaReflectValProxy, + eta: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -10975,45 +11589,56 @@ struct U64Vec4 { /// `Vec2::from_angle(PI).rotate(Vec2::Y)` will create the vector `[-1, 0]` /// and rotate [`Vec2::Y`] around it returning `-Vec2::Y`. - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f32) -> bevy::math::Vec2; + #[lua()] + fn from_angle(angle: f32) -> LuaReflectValProxy; "#, r#" /// Returns the angle (in radians) of this vector in the range `[-π, +π]`. /// The input does not need to be a unit vector however it must be non-zero. - #[lua(kind = "Method")] - fn to_angle(self) -> f32; + #[lua()] + fn to_angle(_self: LuaReflectValProxy) -> f32; "#, r#" - #[lua(kind = "Method")] - fn angle_between(self, #[proxy] rhs: bevy::math::Vec2) -> f32; + #[lua()] + fn angle_between( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" /// Returns the angle of rotation (in radians) from `self` to `rhs` in the range `[-π, +π]`. /// The inputs do not need to be unit vectors however they must be non-zero. - #[lua(kind = "Method")] - fn angle_to(self, #[proxy] rhs: bevy::math::Vec2) -> f32; + #[lua()] + fn angle_to( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" /// Returns a vector that is equal to `self` rotated by 90 degrees. - #[lua(kind = "Method", output(proxy))] - fn perp(self) -> bevy::math::Vec2; + #[lua()] + fn perp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// The perpendicular dot product of `self` and `rhs`. /// Also known as the wedge product, 2D cross product, and determinant. - #[lua(kind = "Method")] - fn perp_dot(self, #[proxy] rhs: bevy::math::Vec2) -> f32; + #[lua()] + fn perp_dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" @@ -11021,8 +11646,11 @@ struct U64Vec4 { /// then this just rotation. This is what you usually want. Otherwise, /// it will be like a rotation with a multiplication by `self`'s length. - #[lua(kind = "Method", output(proxy))] - fn rotate(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn rotate( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11031,384 +11659,320 @@ struct U64Vec4 { /// `self.angle_between(rhs)`, the result will be equal to `rhs`. If `max_angle` is negative, /// rotates towards the exact opposite of `rhs`. Will not go past the target. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn rotate_towards( - &self, - #[proxy] - rhs: bevy::math::Vec2, + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, max_angle: f32, - ) -> bevy::math::Vec2; + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec2(&self) -> bevy::math::DVec2; + #[lua()] + fn as_dvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec2(&self) -> bevy::math::IVec2; + #[lua()] + fn as_ivec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec2(&self) -> bevy::math::UVec2; + #[lua()] + fn as_uvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec2(&self) -> bevy::math::I64Vec2; + #[lua()] + fn as_i64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec2(&self) -> bevy::math::U64Vec2; + #[lua()] + fn as_u64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::Vec2) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::Vec2>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::Vec2) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::Vec2>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::Vec2) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Div::<&bevy::math::Vec2>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f32) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Vec2; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> LuaIdentityProxy { + _self[idx - 1] } "#, r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: f32) -> () { + _self[idx - 1] = val } "#] )] -struct Vec2 { +pub struct Vec2 { x: f32, y: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Vec3A", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: f32) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Vec3A; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f32) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::Vec3A) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Add::<&bevy::math::Vec3A>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: f32) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: f32) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::Vec3A) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::Vec3A>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::Vec3A) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::Vec3A>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::Vec3A) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Div::<&bevy::math::Vec3A>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Vec3A) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::Vec3A) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::Vec3A>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: f32, y: f32, z: f32) -> bevy::math::Vec3A; + #[lua()] + fn new(x: f32, y: f32, z: f32) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: f32) -> bevy::math::Vec3A; + #[lua()] + fn splat(v: f32) -> LuaReflectValProxy; "#, r#" @@ -11417,110 +11981,138 @@ struct Vec2 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec3A, - #[proxy] - if_true: bevy::math::Vec3A, - #[proxy] - if_false: bevy::math::Vec3A, - ) -> bevy::math::Vec3A; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f32; 3]) -> bevy::math::Vec3A; + #[lua()] + fn from_array(a: [f32; 3]) -> LuaReflectValProxy; "#, r#" /// `[x, y, z]` - #[lua(kind = "Method")] - fn to_array(&self) -> [f32; 3]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f32; 3]; "#, r#" /// Creates a [`Vec3A`] from the `x`, `y` and `z` elements of `self` discarding `w`. /// On architectures where SIMD is supported such as SSE2 on `x86_64` this conversion is a noop. - #[lua(kind = "Function", output(proxy))] - fn from_vec4(#[proxy] v: bevy::math::Vec4) -> bevy::math::Vec3A; + #[lua()] + fn from_vec4( + v: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` and the given `w` value. - #[lua(kind = "Method", output(proxy))] - fn extend(self, w: f32) -> bevy::math::Vec4; + #[lua()] + fn extend( + _self: LuaReflectValProxy, + w: f32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. /// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::Vec2; + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: f32) -> bevy::math::Vec3A; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: f32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: f32) -> bevy::math::Vec3A; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: f32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `z`. - #[lua(kind = "Method", output(proxy))] - fn with_z(self, z: f32) -> bevy::math::Vec3A; + #[lua()] + fn with_z( + _self: LuaReflectValProxy, + z: f32, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::Vec3A) -> f32; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the cross product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn cross(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn cross( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11529,46 +12121,44 @@ struct Vec2 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::Vec3A, - #[proxy] - max: bevy::math::Vec3A, - ) -> bevy::math::Vec3A; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> f32; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> f32; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> f32; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> f32; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> f32; "#, r#" @@ -11577,8 +12167,11 @@ struct Vec2 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11587,8 +12180,11 @@ struct Vec2 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11597,8 +12193,11 @@ struct Vec2 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11607,8 +12206,11 @@ struct Vec2 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11617,8 +12219,11 @@ struct Vec2 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11627,15 +12232,20 @@ struct Vec2 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::BVec3A; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the absolute value of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::Vec3A; + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11644,15 +12254,20 @@ struct Vec2 { /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` /// - `NAN` if the number is `NAN` - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::Vec3A; + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector with signs of `rhs` and the magnitudes of `self`. - #[lua(kind = "Method", output(proxy))] - fn copysign(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn copysign( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11660,91 +12275,107 @@ struct Vec2 { /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns `true` if, and only if, all elements are finite. If any element is either /// `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; "#, r#" /// Performs `is_finite` on each element of self, returning a vector mask of the results. /// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`. - #[lua(kind = "Method", output(proxy))] - fn is_finite_mask(self) -> bevy::math::BVec3A; + #[lua()] + fn is_finite_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; "#, r#" /// Performs `is_nan` on each element of self, returning a vector mask of the results. /// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`. - #[lua(kind = "Method", output(proxy))] - fn is_nan_mask(self) -> bevy::math::BVec3A; + #[lua()] + fn is_nan_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the length of `self`. - #[lua(kind = "Method")] - fn length(self) -> f32; + #[lua()] + fn length(_self: LuaReflectValProxy) -> f32; "#, r#" /// Computes the squared length of `self`. /// This is faster than `length()` as it avoids a square root operation. - #[lua(kind = "Method")] - fn length_squared(self) -> f32; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f32; "#, r#" /// Computes `1.0 / length()`. /// For valid results, `self` must _not_ be of length zero. - #[lua(kind = "Method")] - fn length_recip(self) -> f32; + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f32; "#, r#" /// Computes the Euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance(self, #[proxy] rhs: bevy::math::Vec3A) -> f32; + #[lua()] + fn distance( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" /// Compute the squared euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::Vec3A) -> f32; + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. /// [Euclidean division]: f32::rem_euclid - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11754,8 +12385,10 @@ struct Vec2 { /// Panics /// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::Vec3A; + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11765,8 +12398,11 @@ struct Vec2 { /// the result of this operation will be the fallback value. /// See also [`Self::try_normalize()`]. - #[lua(kind = "Method", output(proxy))] - fn normalize_or(self, #[proxy] fallback: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn normalize_or( + _self: LuaReflectValProxy, + fallback: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11775,16 +12411,18 @@ struct Vec2 { /// the result of this operation will be zero. /// See also [`Self::try_normalize()`]. - #[lua(kind = "Method", output(proxy))] - fn normalize_or_zero(self) -> bevy::math::Vec3A; + #[lua()] + fn normalize_or_zero( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns whether `self` is length `1.0` or not. /// Uses a precision threshold of approximately `1e-4`. - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; "#, r#" @@ -11793,8 +12431,11 @@ struct Vec2 { /// # Panics /// Will panic if `rhs` is zero length when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn project_onto(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn project_onto( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11805,8 +12446,11 @@ struct Vec2 { /// # Panics /// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reject_from(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn reject_from( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11815,12 +12459,11 @@ struct Vec2 { /// # Panics /// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn project_onto_normalized( - self, - #[proxy] - rhs: bevy::math::Vec3A, - ) -> bevy::math::Vec3A; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11831,44 +12474,51 @@ struct Vec2 { /// # Panics /// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn reject_from_normalized( - self, - #[proxy] - rhs: bevy::math::Vec3A, - ) -> bevy::math::Vec3A; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the nearest integer to a number for each element of `self`. /// Round half-way cases away from 0.0. - #[lua(kind = "Method", output(proxy))] - fn round(self) -> bevy::math::Vec3A; + #[lua()] + fn round( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the largest integer less than or equal to a number for each /// element of `self`. - #[lua(kind = "Method", output(proxy))] - fn floor(self) -> bevy::math::Vec3A; + #[lua()] + fn floor( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the smallest integer greater than or equal to a number for /// each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn ceil(self) -> bevy::math::Vec3A; + #[lua()] + fn ceil( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the integer part each element of `self`. This means numbers are /// always truncated towards zero. - #[lua(kind = "Method", output(proxy))] - fn trunc(self) -> bevy::math::Vec3A; + #[lua()] + fn trunc( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11877,8 +12527,10 @@ struct Vec2 { /// `self - self.floor()`. /// Note that this is fast but not precise for large numbers. - #[lua(kind = "Method", output(proxy))] - fn fract(self) -> bevy::math::Vec3A; + #[lua()] + fn fract( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11887,30 +12539,39 @@ struct Vec2 { /// `self - self.trunc()`. /// Note that this is fast but not precise for large numbers. - #[lua(kind = "Method", output(proxy))] - fn fract_gl(self) -> bevy::math::Vec3A; + #[lua()] + fn fract_gl( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing `e^self` (the exponential function) for each element of /// `self`. - #[lua(kind = "Method", output(proxy))] - fn exp(self) -> bevy::math::Vec3A; + #[lua()] + fn exp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing each element of `self` raised to the power of `n`. - #[lua(kind = "Method", output(proxy))] - fn powf(self, n: f32) -> bevy::math::Vec3A; + #[lua()] + fn powf( + _self: LuaReflectValProxy, + n: f32, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn recip(self) -> bevy::math::Vec3A; + #[lua()] + fn recip( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11919,8 +12580,12 @@ struct Vec2 { /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly /// extrapolated. - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] rhs: bevy::math::Vec3A, s: f32) -> bevy::math::Vec3A; + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + s: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -11928,8 +12593,12 @@ struct Vec2 { /// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to /// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`. - #[lua(kind = "Method", output(proxy))] - fn move_towards(&self, #[proxy] rhs: bevy::math::Vec3A, d: f32) -> bevy::math::Vec3A; + #[lua()] + fn move_towards( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + d: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -11938,8 +12607,11 @@ struct Vec2 { /// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)` /// while being slightly cheaper to compute. - #[lua(kind = "Method", output(proxy))] - fn midpoint(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn midpoint( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -11951,8 +12623,12 @@ struct Vec2 { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::Vec3A, max_abs_diff: f32) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; "#, r#" @@ -11960,8 +12636,12 @@ struct Vec2 { /// # Panics /// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length(self, min: f32, max: f32) -> bevy::math::Vec3A; + #[lua()] + fn clamp_length( + _self: LuaReflectValProxy, + min: f32, + max: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -11969,8 +12649,11 @@ struct Vec2 { /// # Panics /// Will panic if `max` is negative when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length_max(self, max: f32) -> bevy::math::Vec3A; + #[lua()] + fn clamp_length_max( + _self: LuaReflectValProxy, + max: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -11978,8 +12661,11 @@ struct Vec2 { /// # Panics /// Will panic if `min` is negative when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length_min(self, min: f32) -> bevy::math::Vec3A; + #[lua()] + fn clamp_length_min( + _self: LuaReflectValProxy, + min: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -11990,14 +12676,12 @@ struct Vec2 { /// and will be heavily dependant on designing algorithms with specific target hardware in /// mind. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn mul_add( - self, - #[proxy] - a: bevy::math::Vec3A, - #[proxy] - b: bevy::math::Vec3A, - ) -> bevy::math::Vec3A; + _self: LuaReflectValProxy, + a: LuaReflectValProxy, + b: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12007,8 +12691,11 @@ struct Vec2 { /// # Panics /// Will panic if `normal` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reflect(self, #[proxy] normal: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn reflect( + _self: LuaReflectValProxy, + normal: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12019,16 +12706,23 @@ struct Vec2 { /// # Panics /// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn refract(self, #[proxy] normal: bevy::math::Vec3A, eta: f32) -> bevy::math::Vec3A; + #[lua()] + fn refract( + _self: LuaReflectValProxy, + normal: LuaReflectValProxy, + eta: f32, + ) -> LuaReflectValProxy; "#, r#" /// Returns the angle (in radians) between two vectors in the range `[0, +π]`. /// The inputs do not need to be unit vectors however they must be non-zero. - #[lua(kind = "Method")] - fn angle_between(self, #[proxy] rhs: bevy::math::Vec3A) -> f32; + #[lua()] + fn angle_between( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" @@ -12037,8 +12731,10 @@ struct Vec2 { /// The output vector is not necessarily unit length. For that use /// [`Self::any_orthonormal_vector()`] instead. - #[lua(kind = "Method", output(proxy))] - fn any_orthogonal_vector(&self) -> bevy::math::Vec3A; + #[lua()] + fn any_orthogonal_vector( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12047,246 +12743,218 @@ struct Vec2 { /// # Panics /// Will panic if `self` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn any_orthonormal_vector(&self) -> bevy::math::Vec3A; + #[lua()] + fn any_orthonormal_vector( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec3(&self) -> bevy::math::DVec3; + #[lua()] + fn as_dvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec3(&self) -> bevy::math::IVec3; + #[lua()] + fn as_ivec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec3(&self) -> bevy::math::UVec3; + #[lua()] + fn as_uvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec3(&self) -> bevy::math::I64Vec3; + #[lua()] + fn as_i64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec3(&self) -> bevy::math::U64Vec3; + #[lua()] + fn as_u64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> LuaIdentityProxy { + _self[idx - 1] } "#, r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: f32) -> () { + _self[idx - 1] = val } "#] )] -struct Vec3A(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Vec3A(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Vec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f32) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Vec4; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::Vec4) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::Vec4>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: f32) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::Vec4) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::Vec4>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Vec4) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::Vec4) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Add::<&bevy::math::Vec4>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: f32) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::Vec4) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Div::<&bevy::math::Vec4>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::Vec4) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::Vec4>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: f32, y: f32, z: f32, w: f32) -> bevy::math::Vec4; + #[lua()] + fn new(x: f32, y: f32, z: f32, w: f32) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: f32) -> bevy::math::Vec4; + #[lua()] + fn splat(v: f32) -> LuaReflectValProxy; "#, r#" @@ -12295,29 +12963,26 @@ struct Vec3A(); /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec4A, - #[proxy] - if_true: bevy::math::Vec4, - #[proxy] - if_false: bevy::math::Vec4, - ) -> bevy::math::Vec4; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f32; 4]) -> bevy::math::Vec4; + #[lua()] + fn from_array(a: [f32; 4]) -> LuaReflectValProxy; "#, r#" /// `[x, y, z, w]` - #[lua(kind = "Method")] - fn to_array(&self) -> [f32; 4]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f32; 4]; "#, r#" @@ -12325,66 +12990,92 @@ struct Vec3A(); /// Truncation to [`Vec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. /// To truncate to [`Vec3A`] use [`Vec3A::from()`]. - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::Vec3; + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: f32) -> bevy::math::Vec4; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: f32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: f32) -> bevy::math::Vec4; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: f32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `z`. - #[lua(kind = "Method", output(proxy))] - fn with_z(self, z: f32) -> bevy::math::Vec4; + #[lua()] + fn with_z( + _self: LuaReflectValProxy, + z: f32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `w`. - #[lua(kind = "Method", output(proxy))] - fn with_w(self, w: f32) -> bevy::math::Vec4; + #[lua()] + fn with_w( + _self: LuaReflectValProxy, + w: f32, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::Vec4) -> f32; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12393,46 +13084,44 @@ struct Vec3A(); /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::Vec4, - #[proxy] - max: bevy::math::Vec4, - ) -> bevy::math::Vec4; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> f32; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> f32; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> f32; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> f32; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> f32; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> f32; "#, r#" @@ -12441,8 +13130,11 @@ struct Vec3A(); /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12451,8 +13143,11 @@ struct Vec3A(); /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12461,8 +13156,11 @@ struct Vec3A(); /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12471,8 +13169,11 @@ struct Vec3A(); /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12481,8 +13182,11 @@ struct Vec3A(); /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12491,15 +13195,20 @@ struct Vec3A(); /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::BVec4A; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the absolute value of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::Vec4; + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12508,15 +13217,20 @@ struct Vec3A(); /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` /// - `NAN` if the number is `NAN` - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::Vec4; + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector with signs of `rhs` and the magnitudes of `self`. - #[lua(kind = "Method", output(proxy))] - fn copysign(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua()] + fn copysign( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12524,91 +13238,107 @@ struct Vec3A(); /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns `true` if, and only if, all elements are finite. If any element is either /// `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; "#, r#" /// Performs `is_finite` on each element of self, returning a vector mask of the results. /// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`. - #[lua(kind = "Method", output(proxy))] - fn is_finite_mask(self) -> bevy::math::BVec4A; + #[lua()] + fn is_finite_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; "#, r#" /// Performs `is_nan` on each element of self, returning a vector mask of the results. /// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`. - #[lua(kind = "Method", output(proxy))] - fn is_nan_mask(self) -> bevy::math::BVec4A; + #[lua()] + fn is_nan_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the length of `self`. - #[lua(kind = "Method")] - fn length(self) -> f32; + #[lua()] + fn length(_self: LuaReflectValProxy) -> f32; "#, r#" /// Computes the squared length of `self`. /// This is faster than `length()` as it avoids a square root operation. - #[lua(kind = "Method")] - fn length_squared(self) -> f32; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f32; "#, r#" /// Computes `1.0 / length()`. /// For valid results, `self` must _not_ be of length zero. - #[lua(kind = "Method")] - fn length_recip(self) -> f32; + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f32; "#, r#" /// Computes the Euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance(self, #[proxy] rhs: bevy::math::Vec4) -> f32; + #[lua()] + fn distance( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" /// Compute the squared euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::Vec4) -> f32; + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f32; "#, r#" /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. /// [Euclidean division]: f32::rem_euclid - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12618,8 +13348,10 @@ struct Vec3A(); /// Panics /// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::Vec4; + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12629,8 +13361,11 @@ struct Vec3A(); /// the result of this operation will be the fallback value. /// See also [`Self::try_normalize()`]. - #[lua(kind = "Method", output(proxy))] - fn normalize_or(self, #[proxy] fallback: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua()] + fn normalize_or( + _self: LuaReflectValProxy, + fallback: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12639,16 +13374,18 @@ struct Vec3A(); /// the result of this operation will be zero. /// See also [`Self::try_normalize()`]. - #[lua(kind = "Method", output(proxy))] - fn normalize_or_zero(self) -> bevy::math::Vec4; + #[lua()] + fn normalize_or_zero( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns whether `self` is length `1.0` or not. /// Uses a precision threshold of approximately `1e-4`. - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; "#, r#" @@ -12657,8 +13394,11 @@ struct Vec3A(); /// # Panics /// Will panic if `rhs` is zero length when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn project_onto(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua()] + fn project_onto( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12669,8 +13409,11 @@ struct Vec3A(); /// # Panics /// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reject_from(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua()] + fn reject_from( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12679,8 +13422,11 @@ struct Vec3A(); /// # Panics /// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn project_onto_normalized(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua()] + fn project_onto_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12691,40 +13437,51 @@ struct Vec3A(); /// # Panics /// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reject_from_normalized(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua()] + fn reject_from_normalized( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the nearest integer to a number for each element of `self`. /// Round half-way cases away from 0.0. - #[lua(kind = "Method", output(proxy))] - fn round(self) -> bevy::math::Vec4; + #[lua()] + fn round( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the largest integer less than or equal to a number for each /// element of `self`. - #[lua(kind = "Method", output(proxy))] - fn floor(self) -> bevy::math::Vec4; + #[lua()] + fn floor( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the smallest integer greater than or equal to a number for /// each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn ceil(self) -> bevy::math::Vec4; + #[lua()] + fn ceil( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the integer part each element of `self`. This means numbers are /// always truncated towards zero. - #[lua(kind = "Method", output(proxy))] - fn trunc(self) -> bevy::math::Vec4; + #[lua()] + fn trunc( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12733,8 +13490,10 @@ struct Vec3A(); /// `self - self.floor()`. /// Note that this is fast but not precise for large numbers. - #[lua(kind = "Method", output(proxy))] - fn fract(self) -> bevy::math::Vec4; + #[lua()] + fn fract( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12743,30 +13502,39 @@ struct Vec3A(); /// `self - self.trunc()`. /// Note that this is fast but not precise for large numbers. - #[lua(kind = "Method", output(proxy))] - fn fract_gl(self) -> bevy::math::Vec4; + #[lua()] + fn fract_gl( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing `e^self` (the exponential function) for each element of /// `self`. - #[lua(kind = "Method", output(proxy))] - fn exp(self) -> bevy::math::Vec4; + #[lua()] + fn exp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing each element of `self` raised to the power of `n`. - #[lua(kind = "Method", output(proxy))] - fn powf(self, n: f32) -> bevy::math::Vec4; + #[lua()] + fn powf( + _self: LuaReflectValProxy, + n: f32, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn recip(self) -> bevy::math::Vec4; + #[lua()] + fn recip( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12775,8 +13543,12 @@ struct Vec3A(); /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly /// extrapolated. - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] rhs: bevy::math::Vec4, s: f32) -> bevy::math::Vec4; + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + s: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -12784,8 +13556,12 @@ struct Vec3A(); /// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to /// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`. - #[lua(kind = "Method", output(proxy))] - fn move_towards(&self, #[proxy] rhs: bevy::math::Vec4, d: f32) -> bevy::math::Vec4; + #[lua()] + fn move_towards( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + d: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -12794,8 +13570,11 @@ struct Vec3A(); /// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)` /// while being slightly cheaper to compute. - #[lua(kind = "Method", output(proxy))] - fn midpoint(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua()] + fn midpoint( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12807,8 +13586,12 @@ struct Vec3A(); /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::Vec4, max_abs_diff: f32) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; "#, r#" @@ -12816,8 +13599,12 @@ struct Vec3A(); /// # Panics /// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length(self, min: f32, max: f32) -> bevy::math::Vec4; + #[lua()] + fn clamp_length( + _self: LuaReflectValProxy, + min: f32, + max: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -12825,8 +13612,11 @@ struct Vec3A(); /// # Panics /// Will panic if `max` is negative when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length_max(self, max: f32) -> bevy::math::Vec4; + #[lua()] + fn clamp_length_max( + _self: LuaReflectValProxy, + max: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -12834,8 +13624,11 @@ struct Vec3A(); /// # Panics /// Will panic if `min` is negative when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length_min(self, min: f32) -> bevy::math::Vec4; + #[lua()] + fn clamp_length_min( + _self: LuaReflectValProxy, + min: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -12846,14 +13639,12 @@ struct Vec3A(); /// and will be heavily dependant on designing algorithms with specific target hardware in /// mind. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn mul_add( - self, - #[proxy] - a: bevy::math::Vec4, - #[proxy] - b: bevy::math::Vec4, - ) -> bevy::math::Vec4; + _self: LuaReflectValProxy, + a: LuaReflectValProxy, + b: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12863,8 +13654,11 @@ struct Vec3A(); /// # Panics /// Will panic if `normal` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reflect(self, #[proxy] normal: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua()] + fn reflect( + _self: LuaReflectValProxy, + normal: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -12875,152 +13669,153 @@ struct Vec3A(); /// # Panics /// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn refract(self, #[proxy] normal: bevy::math::Vec4, eta: f32) -> bevy::math::Vec4; + #[lua()] + fn refract( + _self: LuaReflectValProxy, + normal: LuaReflectValProxy, + eta: f32, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f64`. - #[lua(kind = "Method", output(proxy))] - fn as_dvec4(&self) -> bevy::math::DVec4; + #[lua()] + fn as_dvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec4(&self) -> bevy::math::IVec4; + #[lua()] + fn as_ivec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec4(&self) -> bevy::math::UVec4; + #[lua()] + fn as_uvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec4(&self) -> bevy::math::I64Vec4; + #[lua()] + fn as_i64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec4(&self) -> bevy::math::U64Vec4; + #[lua()] + fn as_u64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: f32) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> LuaIdentityProxy { + _self[idx - 1] } "#, r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f32) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: f32) -> () { + _self[idx - 1] = val } "#] )] -struct Vec4(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Vec4(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::BVec2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::BVec2; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" /// Creates a new vector mask. - #[lua(kind = "Function", output(proxy))] - fn new(x: bool, y: bool) -> bevy::math::BVec2; + #[lua()] + fn new(x: bool, y: bool) -> LuaReflectValProxy; "#, r#" /// Creates a vector mask with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: bool) -> bevy::math::BVec2; + #[lua()] + fn splat(v: bool) -> LuaReflectValProxy; "#, r#" /// Creates a new vector mask from a bool array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [bool; 2]) -> bevy::math::BVec2; + #[lua()] + fn from_array(a: [bool; 2]) -> LuaReflectValProxy; "#, r#" @@ -13028,85 +13823,88 @@ struct Vec4(); /// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn bitmask(self) -> u32; + #[lua()] + fn bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns true if any of the elements are true, false otherwise. - #[lua(kind = "Method")] - fn any(self) -> bool; + #[lua()] + fn any(_self: LuaReflectValProxy) -> bool; "#, r#" /// Returns true if all the elements are true, false otherwise. - #[lua(kind = "Method")] - fn all(self) -> bool; + #[lua()] + fn all(_self: LuaReflectValProxy) -> bool; "#, r#" /// Tests the value at `index`. /// Panics if `index` is greater than 1. - #[lua(kind = "Method")] - fn test(&self, index: usize) -> bool; + #[lua()] + fn test(_self: LuaReflectRefProxy, index: usize) -> bool; "#, r#" /// Sets the element at `index`. /// Panics if `index` is greater than 1. - #[lua(kind = "MutatingMethod")] - fn set(&mut self, index: usize, value: bool) -> (); + #[lua()] + fn set( + _self: LuaReflectRefMutProxy, + index: usize, + value: bool, + ) -> (); "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::BVec2) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct BVec2 { +pub struct BVec2 { x: bool, y: bool, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::BVec3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a new vector mask. - #[lua(kind = "Function", output(proxy))] - fn new(x: bool, y: bool, z: bool) -> bevy::math::BVec3; + #[lua()] + fn new(x: bool, y: bool, z: bool) -> LuaReflectValProxy; "#, r#" /// Creates a vector mask with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: bool) -> bevy::math::BVec3; + #[lua()] + fn splat(v: bool) -> LuaReflectValProxy; "#, r#" /// Creates a new vector mask from a bool array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [bool; 3]) -> bevy::math::BVec3; + #[lua()] + fn from_array(a: [bool; 3]) -> LuaReflectValProxy; "#, r#" @@ -13114,119 +13912,118 @@ struct BVec2 { /// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn bitmask(self) -> u32; + #[lua()] + fn bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns true if any of the elements are true, false otherwise. - #[lua(kind = "Method")] - fn any(self) -> bool; + #[lua()] + fn any(_self: LuaReflectValProxy) -> bool; "#, r#" /// Returns true if all the elements are true, false otherwise. - #[lua(kind = "Method")] - fn all(self) -> bool; + #[lua()] + fn all(_self: LuaReflectValProxy) -> bool; "#, r#" /// Tests the value at `index`. /// Panics if `index` is greater than 2. - #[lua(kind = "Method")] - fn test(&self, index: usize) -> bool; + #[lua()] + fn test(_self: LuaReflectRefProxy, index: usize) -> bool; "#, r#" /// Sets the element at `index`. /// Panics if `index` is greater than 2. - #[lua(kind = "MutatingMethod")] - fn set(&mut self, index: usize, value: bool) -> (); + #[lua()] + fn set( + _self: LuaReflectRefMutProxy, + index: usize, + value: bool, + ) -> (); "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::BVec3) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::BVec3; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct BVec3 { +pub struct BVec3 { x: bool, y: bool, z: bool, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::BVec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::BVec4) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Creates a new vector mask. - #[lua(kind = "Function", output(proxy))] - fn new(x: bool, y: bool, z: bool, w: bool) -> bevy::math::BVec4; + #[lua()] + fn new(x: bool, y: bool, z: bool, w: bool) -> LuaReflectValProxy; "#, r#" /// Creates a vector mask with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: bool) -> bevy::math::BVec4; + #[lua()] + fn splat(v: bool) -> LuaReflectValProxy; "#, r#" /// Creates a new vector mask from a bool array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [bool; 4]) -> bevy::math::BVec4; + #[lua()] + fn from_array(a: [bool; 4]) -> LuaReflectValProxy; "#, r#" @@ -13234,187 +14031,162 @@ struct BVec3 { /// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn bitmask(self) -> u32; + #[lua()] + fn bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns true if any of the elements are true, false otherwise. - #[lua(kind = "Method")] - fn any(self) -> bool; + #[lua()] + fn any(_self: LuaReflectValProxy) -> bool; "#, r#" /// Returns true if all the elements are true, false otherwise. - #[lua(kind = "Method")] - fn all(self) -> bool; + #[lua()] + fn all(_self: LuaReflectValProxy) -> bool; "#, r#" /// Tests the value at `index`. /// Panics if `index` is greater than 3. - #[lua(kind = "Method")] - fn test(&self, index: usize) -> bool; + #[lua()] + fn test(_self: LuaReflectRefProxy, index: usize) -> bool; "#, r#" /// Sets the element at `index`. /// Panics if `index` is greater than 3. - #[lua(kind = "MutatingMethod")] - fn set(&mut self, index: usize, value: bool) -> (); + #[lua()] + fn set( + _self: LuaReflectRefMutProxy, + index: usize, + value: bool, + ) -> (); "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::BVec4; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct BVec4 { +pub struct BVec4 { x: bool, y: bool, z: bool, w: bool, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::DVec2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::DVec2) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::DVec2>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::DVec2) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::DVec2>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f64) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::DVec2) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::DVec2>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::DVec2) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Div::<&bevy::math::DVec2>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: f64) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: f64, y: f64) -> bevy::math::DVec2; + #[lua()] + fn new(x: f64, y: f64) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: f64) -> bevy::math::DVec2; + #[lua()] + fn splat(v: f64) -> LuaReflectValProxy; "#, r#" @@ -13423,80 +14195,98 @@ struct BVec4 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec2, - #[proxy] - if_true: bevy::math::DVec2, - #[proxy] - if_false: bevy::math::DVec2, - ) -> bevy::math::DVec2; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f64; 2]) -> bevy::math::DVec2; + #[lua()] + fn from_array(a: [f64; 2]) -> LuaReflectValProxy; "#, r#" /// `[x, y]` - #[lua(kind = "Method")] - fn to_array(&self) -> [f64; 2]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f64; 2]; "#, r#" /// Creates a 3D vector from `self` and the given `z` value. - #[lua(kind = "Method", output(proxy))] - fn extend(self, z: f64) -> bevy::math::DVec3; + #[lua()] + fn extend( + _self: LuaReflectValProxy, + z: f64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: f64) -> bevy::math::DVec2; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: f64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: f64) -> bevy::math::DVec2; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: f64, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::DVec2) -> f64; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13505,46 +14295,44 @@ struct BVec4 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::DVec2, - #[proxy] - max: bevy::math::DVec2, - ) -> bevy::math::DVec2; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> f64; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> f64; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> f64; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> f64; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> f64; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> f64; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> f64; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> f64; "#, r#" @@ -13553,8 +14341,11 @@ struct BVec4 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13563,8 +14354,11 @@ struct BVec4 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13573,8 +14367,11 @@ struct BVec4 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13583,8 +14380,11 @@ struct BVec4 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13593,8 +14393,11 @@ struct BVec4 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13603,15 +14406,20 @@ struct BVec4 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::BVec2; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the absolute value of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::DVec2; + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13620,15 +14428,20 @@ struct BVec4 { /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` /// - `NAN` if the number is `NAN` - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::DVec2; + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector with signs of `rhs` and the magnitudes of `self`. - #[lua(kind = "Method", output(proxy))] - fn copysign(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn copysign( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13636,91 +14449,107 @@ struct BVec4 { /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns `true` if, and only if, all elements are finite. If any element is either /// `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; "#, r#" /// Performs `is_finite` on each element of self, returning a vector mask of the results. /// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`. - #[lua(kind = "Method", output(proxy))] - fn is_finite_mask(self) -> bevy::math::BVec2; + #[lua()] + fn is_finite_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; "#, r#" /// Performs `is_nan` on each element of self, returning a vector mask of the results. /// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`. - #[lua(kind = "Method", output(proxy))] - fn is_nan_mask(self) -> bevy::math::BVec2; + #[lua()] + fn is_nan_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the length of `self`. - #[lua(kind = "Method")] - fn length(self) -> f64; + #[lua()] + fn length(_self: LuaReflectValProxy) -> f64; "#, r#" /// Computes the squared length of `self`. /// This is faster than `length()` as it avoids a square root operation. - #[lua(kind = "Method")] - fn length_squared(self) -> f64; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f64; "#, r#" /// Computes `1.0 / length()`. /// For valid results, `self` must _not_ be of length zero. - #[lua(kind = "Method")] - fn length_recip(self) -> f64; + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f64; "#, r#" /// Computes the Euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance(self, #[proxy] rhs: bevy::math::DVec2) -> f64; + #[lua()] + fn distance( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" /// Compute the squared euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::DVec2) -> f64; + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. /// [Euclidean division]: f64::rem_euclid - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13730,8 +14559,10 @@ struct BVec4 { /// Panics /// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::DVec2; + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13741,8 +14572,11 @@ struct BVec4 { /// the result of this operation will be the fallback value. /// See also [`Self::try_normalize()`]. - #[lua(kind = "Method", output(proxy))] - fn normalize_or(self, #[proxy] fallback: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn normalize_or( + _self: LuaReflectValProxy, + fallback: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13751,16 +14585,18 @@ struct BVec4 { /// the result of this operation will be zero. /// See also [`Self::try_normalize()`]. - #[lua(kind = "Method", output(proxy))] - fn normalize_or_zero(self) -> bevy::math::DVec2; + #[lua()] + fn normalize_or_zero( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns whether `self` is length `1.0` or not. /// Uses a precision threshold of approximately `1e-4`. - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; "#, r#" @@ -13769,8 +14605,11 @@ struct BVec4 { /// # Panics /// Will panic if `rhs` is zero length when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn project_onto(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn project_onto( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13781,8 +14620,11 @@ struct BVec4 { /// # Panics /// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reject_from(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn reject_from( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13791,12 +14633,11 @@ struct BVec4 { /// # Panics /// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn project_onto_normalized( - self, - #[proxy] - rhs: bevy::math::DVec2, - ) -> bevy::math::DVec2; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13807,44 +14648,51 @@ struct BVec4 { /// # Panics /// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn reject_from_normalized( - self, - #[proxy] - rhs: bevy::math::DVec2, - ) -> bevy::math::DVec2; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the nearest integer to a number for each element of `self`. /// Round half-way cases away from 0.0. - #[lua(kind = "Method", output(proxy))] - fn round(self) -> bevy::math::DVec2; + #[lua()] + fn round( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the largest integer less than or equal to a number for each /// element of `self`. - #[lua(kind = "Method", output(proxy))] - fn floor(self) -> bevy::math::DVec2; + #[lua()] + fn floor( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the smallest integer greater than or equal to a number for /// each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn ceil(self) -> bevy::math::DVec2; + #[lua()] + fn ceil( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the integer part each element of `self`. This means numbers are /// always truncated towards zero. - #[lua(kind = "Method", output(proxy))] - fn trunc(self) -> bevy::math::DVec2; + #[lua()] + fn trunc( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13853,8 +14701,10 @@ struct BVec4 { /// `self - self.floor()`. /// Note that this is fast but not precise for large numbers. - #[lua(kind = "Method", output(proxy))] - fn fract(self) -> bevy::math::DVec2; + #[lua()] + fn fract( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13863,30 +14713,39 @@ struct BVec4 { /// `self - self.trunc()`. /// Note that this is fast but not precise for large numbers. - #[lua(kind = "Method", output(proxy))] - fn fract_gl(self) -> bevy::math::DVec2; + #[lua()] + fn fract_gl( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing `e^self` (the exponential function) for each element of /// `self`. - #[lua(kind = "Method", output(proxy))] - fn exp(self) -> bevy::math::DVec2; + #[lua()] + fn exp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing each element of `self` raised to the power of `n`. - #[lua(kind = "Method", output(proxy))] - fn powf(self, n: f64) -> bevy::math::DVec2; + #[lua()] + fn powf( + _self: LuaReflectValProxy, + n: f64, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn recip(self) -> bevy::math::DVec2; + #[lua()] + fn recip( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13895,8 +14754,12 @@ struct BVec4 { /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly /// extrapolated. - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] rhs: bevy::math::DVec2, s: f64) -> bevy::math::DVec2; + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + s: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -13904,8 +14767,12 @@ struct BVec4 { /// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to /// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`. - #[lua(kind = "Method", output(proxy))] - fn move_towards(&self, #[proxy] rhs: bevy::math::DVec2, d: f64) -> bevy::math::DVec2; + #[lua()] + fn move_towards( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + d: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -13914,8 +14781,11 @@ struct BVec4 { /// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)` /// while being slightly cheaper to compute. - #[lua(kind = "Method", output(proxy))] - fn midpoint(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn midpoint( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13927,8 +14797,12 @@ struct BVec4 { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::DVec2, max_abs_diff: f64) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; "#, r#" @@ -13936,8 +14810,12 @@ struct BVec4 { /// # Panics /// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length(self, min: f64, max: f64) -> bevy::math::DVec2; + #[lua()] + fn clamp_length( + _self: LuaReflectValProxy, + min: f64, + max: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -13945,8 +14823,11 @@ struct BVec4 { /// # Panics /// Will panic if `max` is negative when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length_max(self, max: f64) -> bevy::math::DVec2; + #[lua()] + fn clamp_length_max( + _self: LuaReflectValProxy, + max: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -13954,8 +14835,11 @@ struct BVec4 { /// # Panics /// Will panic if `min` is negative when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length_min(self, min: f64) -> bevy::math::DVec2; + #[lua()] + fn clamp_length_min( + _self: LuaReflectValProxy, + min: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -13966,14 +14850,12 @@ struct BVec4 { /// and will be heavily dependant on designing algorithms with specific target hardware in /// mind. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn mul_add( - self, - #[proxy] - a: bevy::math::DVec2, - #[proxy] - b: bevy::math::DVec2, - ) -> bevy::math::DVec2; + _self: LuaReflectValProxy, + a: LuaReflectValProxy, + b: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13983,8 +14865,11 @@ struct BVec4 { /// # Panics /// Will panic if `normal` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reflect(self, #[proxy] normal: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn reflect( + _self: LuaReflectValProxy, + normal: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -13995,8 +14880,12 @@ struct BVec4 { /// # Panics /// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn refract(self, #[proxy] normal: bevy::math::DVec2, eta: f64) -> bevy::math::DVec2; + #[lua()] + fn refract( + _self: LuaReflectValProxy, + normal: LuaReflectValProxy, + eta: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -14005,45 +14894,56 @@ struct BVec4 { /// `DVec2::from_angle(PI).rotate(DVec2::Y)` will create the vector `[-1, 0]` /// and rotate [`DVec2::Y`] around it returning `-DVec2::Y`. - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f64) -> bevy::math::DVec2; + #[lua()] + fn from_angle(angle: f64) -> LuaReflectValProxy; "#, r#" /// Returns the angle (in radians) of this vector in the range `[-π, +π]`. /// The input does not need to be a unit vector however it must be non-zero. - #[lua(kind = "Method")] - fn to_angle(self) -> f64; + #[lua()] + fn to_angle(_self: LuaReflectValProxy) -> f64; "#, r#" - #[lua(kind = "Method")] - fn angle_between(self, #[proxy] rhs: bevy::math::DVec2) -> f64; + #[lua()] + fn angle_between( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" /// Returns the angle of rotation (in radians) from `self` to `rhs` in the range `[-π, +π]`. /// The inputs do not need to be unit vectors however they must be non-zero. - #[lua(kind = "Method")] - fn angle_to(self, #[proxy] rhs: bevy::math::DVec2) -> f64; + #[lua()] + fn angle_to( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" /// Returns a vector that is equal to `self` rotated by 90 degrees. - #[lua(kind = "Method", output(proxy))] - fn perp(self) -> bevy::math::DVec2; + #[lua()] + fn perp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// The perpendicular dot product of `self` and `rhs`. /// Also known as the wedge product, 2D cross product, and determinant. - #[lua(kind = "Method")] - fn perp_dot(self, #[proxy] rhs: bevy::math::DVec2) -> f64; + #[lua()] + fn perp_dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" @@ -14051,8 +14951,11 @@ struct BVec4 { /// then this just rotation. This is what you usually want. Otherwise, /// it will be like a rotation with a multiplication by `self`'s length. - #[lua(kind = "Method", output(proxy))] - fn rotate(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn rotate( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14061,347 +14964,294 @@ struct BVec4 { /// `self.angle_between(rhs)`, the result will be equal to `rhs`. If `max_angle` is negative, /// rotates towards the exact opposite of `rhs`. Will not go past the target. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn rotate_towards( - &self, - #[proxy] - rhs: bevy::math::DVec2, + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, max_angle: f64, - ) -> bevy::math::DVec2; + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec2(&self) -> bevy::math::Vec2; + #[lua()] + fn as_vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec2(&self) -> bevy::math::IVec2; + #[lua()] + fn as_ivec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec2(&self) -> bevy::math::UVec2; + #[lua()] + fn as_uvec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec2(&self) -> bevy::math::I64Vec2; + #[lua()] + fn as_i64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec2(&self) -> bevy::math::U64Vec2; + #[lua()] + fn as_u64vec2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f64) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: f64) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DVec2; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::DVec2) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Add::<&bevy::math::DVec2>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: f64) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::DVec2) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> LuaIdentityProxy { + _self[idx - 1] } "#, r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f64) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: f64) -> () { + _self[idx - 1] = val } "#] )] -struct DVec2 { +pub struct DVec2 { x: f64, y: f64, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::DVec3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::DVec3) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::DVec3>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::DVec3) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::DVec3>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f64) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DVec3; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::DVec3) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: f64) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: f64) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: f64) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: f64, y: f64, z: f64) -> bevy::math::DVec3; + #[lua()] + fn new(x: f64, y: f64, z: f64) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: f64) -> bevy::math::DVec3; + #[lua()] + fn splat(v: f64) -> LuaReflectValProxy; "#, r#" @@ -14410,102 +15260,128 @@ struct DVec2 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec3, - #[proxy] - if_true: bevy::math::DVec3, - #[proxy] - if_false: bevy::math::DVec3, - ) -> bevy::math::DVec3; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f64; 3]) -> bevy::math::DVec3; + #[lua()] + fn from_array(a: [f64; 3]) -> LuaReflectValProxy; "#, r#" /// `[x, y, z]` - #[lua(kind = "Method")] - fn to_array(&self) -> [f64; 3]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f64; 3]; "#, r#" /// Creates a 4D vector from `self` and the given `w` value. - #[lua(kind = "Method", output(proxy))] - fn extend(self, w: f64) -> bevy::math::DVec4; + #[lua()] + fn extend( + _self: LuaReflectValProxy, + w: f64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. /// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::DVec2; + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: f64) -> bevy::math::DVec3; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: f64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: f64) -> bevy::math::DVec3; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: f64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D vector from `self` with the given value of `z`. - #[lua(kind = "Method", output(proxy))] - fn with_z(self, z: f64) -> bevy::math::DVec3; + #[lua()] + fn with_z( + _self: LuaReflectValProxy, + z: f64, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::DVec3) -> f64; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the cross product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn cross(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn cross( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14514,46 +15390,44 @@ struct DVec2 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::DVec3, - #[proxy] - max: bevy::math::DVec3, - ) -> bevy::math::DVec3; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> f64; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> f64; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> f64; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> f64; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> f64; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> f64; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> f64; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> f64; "#, r#" @@ -14562,8 +15436,11 @@ struct DVec2 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14572,8 +15449,11 @@ struct DVec2 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14582,8 +15462,11 @@ struct DVec2 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14592,8 +15475,11 @@ struct DVec2 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14602,8 +15488,11 @@ struct DVec2 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14612,15 +15501,20 @@ struct DVec2 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::BVec3; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the absolute value of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::DVec3; + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14629,15 +15523,20 @@ struct DVec2 { /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` /// - `NAN` if the number is `NAN` - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::DVec3; + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector with signs of `rhs` and the magnitudes of `self`. - #[lua(kind = "Method", output(proxy))] - fn copysign(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn copysign( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14645,91 +15544,107 @@ struct DVec2 { /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns `true` if, and only if, all elements are finite. If any element is either /// `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; "#, r#" /// Performs `is_finite` on each element of self, returning a vector mask of the results. /// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`. - #[lua(kind = "Method", output(proxy))] - fn is_finite_mask(self) -> bevy::math::BVec3; + #[lua()] + fn is_finite_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; "#, r#" /// Performs `is_nan` on each element of self, returning a vector mask of the results. /// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`. - #[lua(kind = "Method", output(proxy))] - fn is_nan_mask(self) -> bevy::math::BVec3; + #[lua()] + fn is_nan_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the length of `self`. - #[lua(kind = "Method")] - fn length(self) -> f64; + #[lua()] + fn length(_self: LuaReflectValProxy) -> f64; "#, r#" /// Computes the squared length of `self`. /// This is faster than `length()` as it avoids a square root operation. - #[lua(kind = "Method")] - fn length_squared(self) -> f64; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f64; "#, r#" /// Computes `1.0 / length()`. /// For valid results, `self` must _not_ be of length zero. - #[lua(kind = "Method")] - fn length_recip(self) -> f64; + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f64; "#, r#" /// Computes the Euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance(self, #[proxy] rhs: bevy::math::DVec3) -> f64; + #[lua()] + fn distance( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" /// Compute the squared euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::DVec3) -> f64; + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. /// [Euclidean division]: f64::rem_euclid - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14739,8 +15654,10 @@ struct DVec2 { /// Panics /// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::DVec3; + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14750,8 +15667,11 @@ struct DVec2 { /// the result of this operation will be the fallback value. /// See also [`Self::try_normalize()`]. - #[lua(kind = "Method", output(proxy))] - fn normalize_or(self, #[proxy] fallback: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn normalize_or( + _self: LuaReflectValProxy, + fallback: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14760,16 +15680,18 @@ struct DVec2 { /// the result of this operation will be zero. /// See also [`Self::try_normalize()`]. - #[lua(kind = "Method", output(proxy))] - fn normalize_or_zero(self) -> bevy::math::DVec3; + #[lua()] + fn normalize_or_zero( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns whether `self` is length `1.0` or not. /// Uses a precision threshold of approximately `1e-4`. - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; "#, r#" @@ -14778,8 +15700,11 @@ struct DVec2 { /// # Panics /// Will panic if `rhs` is zero length when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn project_onto(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn project_onto( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14790,8 +15715,11 @@ struct DVec2 { /// # Panics /// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reject_from(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn reject_from( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14800,12 +15728,11 @@ struct DVec2 { /// # Panics /// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn project_onto_normalized( - self, - #[proxy] - rhs: bevy::math::DVec3, - ) -> bevy::math::DVec3; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14816,44 +15743,51 @@ struct DVec2 { /// # Panics /// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn reject_from_normalized( - self, - #[proxy] - rhs: bevy::math::DVec3, - ) -> bevy::math::DVec3; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the nearest integer to a number for each element of `self`. /// Round half-way cases away from 0.0. - #[lua(kind = "Method", output(proxy))] - fn round(self) -> bevy::math::DVec3; + #[lua()] + fn round( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the largest integer less than or equal to a number for each /// element of `self`. - #[lua(kind = "Method", output(proxy))] - fn floor(self) -> bevy::math::DVec3; + #[lua()] + fn floor( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the smallest integer greater than or equal to a number for /// each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn ceil(self) -> bevy::math::DVec3; + #[lua()] + fn ceil( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the integer part each element of `self`. This means numbers are /// always truncated towards zero. - #[lua(kind = "Method", output(proxy))] - fn trunc(self) -> bevy::math::DVec3; + #[lua()] + fn trunc( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14862,8 +15796,10 @@ struct DVec2 { /// `self - self.floor()`. /// Note that this is fast but not precise for large numbers. - #[lua(kind = "Method", output(proxy))] - fn fract(self) -> bevy::math::DVec3; + #[lua()] + fn fract( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14872,30 +15808,39 @@ struct DVec2 { /// `self - self.trunc()`. /// Note that this is fast but not precise for large numbers. - #[lua(kind = "Method", output(proxy))] - fn fract_gl(self) -> bevy::math::DVec3; + #[lua()] + fn fract_gl( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing `e^self` (the exponential function) for each element of /// `self`. - #[lua(kind = "Method", output(proxy))] - fn exp(self) -> bevy::math::DVec3; + #[lua()] + fn exp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing each element of `self` raised to the power of `n`. - #[lua(kind = "Method", output(proxy))] - fn powf(self, n: f64) -> bevy::math::DVec3; + #[lua()] + fn powf( + _self: LuaReflectValProxy, + n: f64, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn recip(self) -> bevy::math::DVec3; + #[lua()] + fn recip( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14904,8 +15849,12 @@ struct DVec2 { /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly /// extrapolated. - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] rhs: bevy::math::DVec3, s: f64) -> bevy::math::DVec3; + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + s: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -14913,8 +15862,12 @@ struct DVec2 { /// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to /// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`. - #[lua(kind = "Method", output(proxy))] - fn move_towards(&self, #[proxy] rhs: bevy::math::DVec3, d: f64) -> bevy::math::DVec3; + #[lua()] + fn move_towards( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + d: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -14923,8 +15876,11 @@ struct DVec2 { /// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)` /// while being slightly cheaper to compute. - #[lua(kind = "Method", output(proxy))] - fn midpoint(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn midpoint( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14936,8 +15892,12 @@ struct DVec2 { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::DVec3, max_abs_diff: f64) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; "#, r#" @@ -14945,8 +15905,12 @@ struct DVec2 { /// # Panics /// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length(self, min: f64, max: f64) -> bevy::math::DVec3; + #[lua()] + fn clamp_length( + _self: LuaReflectValProxy, + min: f64, + max: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -14954,8 +15918,11 @@ struct DVec2 { /// # Panics /// Will panic if `max` is negative when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length_max(self, max: f64) -> bevy::math::DVec3; + #[lua()] + fn clamp_length_max( + _self: LuaReflectValProxy, + max: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -14963,8 +15930,11 @@ struct DVec2 { /// # Panics /// Will panic if `min` is negative when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length_min(self, min: f64) -> bevy::math::DVec3; + #[lua()] + fn clamp_length_min( + _self: LuaReflectValProxy, + min: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -14975,14 +15945,12 @@ struct DVec2 { /// and will be heavily dependant on designing algorithms with specific target hardware in /// mind. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn mul_add( - self, - #[proxy] - a: bevy::math::DVec3, - #[proxy] - b: bevy::math::DVec3, - ) -> bevy::math::DVec3; + _self: LuaReflectValProxy, + a: LuaReflectValProxy, + b: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -14992,8 +15960,11 @@ struct DVec2 { /// # Panics /// Will panic if `normal` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reflect(self, #[proxy] normal: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn reflect( + _self: LuaReflectValProxy, + normal: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15004,16 +15975,23 @@ struct DVec2 { /// # Panics /// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn refract(self, #[proxy] normal: bevy::math::DVec3, eta: f64) -> bevy::math::DVec3; + #[lua()] + fn refract( + _self: LuaReflectValProxy, + normal: LuaReflectValProxy, + eta: f64, + ) -> LuaReflectValProxy; "#, r#" /// Returns the angle (in radians) between two vectors in the range `[0, +π]`. /// The inputs do not need to be unit vectors however they must be non-zero. - #[lua(kind = "Method")] - fn angle_between(self, #[proxy] rhs: bevy::math::DVec3) -> f64; + #[lua()] + fn angle_between( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" @@ -15022,8 +16000,10 @@ struct DVec2 { /// The output vector is not necessarily unit length. For that use /// [`Self::any_orthonormal_vector()`] instead. - #[lua(kind = "Method", output(proxy))] - fn any_orthogonal_vector(&self) -> bevy::math::DVec3; + #[lua()] + fn any_orthogonal_vector( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15032,329 +16012,285 @@ struct DVec2 { /// # Panics /// Will panic if `self` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn any_orthonormal_vector(&self) -> bevy::math::DVec3; + #[lua()] + fn any_orthonormal_vector( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec3(&self) -> bevy::math::Vec3; + #[lua()] + fn as_vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec3a(&self) -> bevy::math::Vec3A; + #[lua()] + fn as_vec3a( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec3(&self) -> bevy::math::IVec3; + #[lua()] + fn as_ivec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec3(&self) -> bevy::math::UVec3; + #[lua()] + fn as_uvec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec3(&self) -> bevy::math::I64Vec3; + #[lua()] + fn as_i64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec3(&self) -> bevy::math::U64Vec3; + #[lua()] + fn as_u64vec3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::DVec3) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Div::<&bevy::math::DVec3>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::DVec3) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::DVec3>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::DVec3) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Add::<&bevy::math::DVec3>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f64) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> LuaIdentityProxy { + _self[idx - 1] } "#, r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f64) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: f64) -> () { + _self[idx - 1] = val } "#] )] -struct DVec3 { +pub struct DVec3 { x: f64, y: f64, z: f64, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::DVec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DVec4; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: &glam::DVec4) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::DVec4>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, rhs: f64) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: &glam::DVec4) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::DVec4>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, rhs: f64) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f64) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: &glam::DVec4) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::DVec4>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: &glam::DVec4) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Div::<&bevy::math::DVec4>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: &glam::DVec4) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Add::<&bevy::math::DVec4>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f64) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::DVec4) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Rem", - kind = "MetaFunction", - output(proxy), - composite = "rem", - metamethod = "Mod", - )] - fn rem(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector. - #[lua(kind = "Function", output(proxy))] - fn new(x: f64, y: f64, z: f64, w: f64) -> bevy::math::DVec4; + #[lua()] + fn new(x: f64, y: f64, z: f64, w: f64) -> LuaReflectValProxy; "#, r#" /// Creates a vector with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: f64) -> bevy::math::DVec4; + #[lua()] + fn splat(v: f64) -> LuaReflectValProxy; "#, r#" @@ -15363,95 +16299,118 @@ struct DVec3 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn select( - #[proxy] - mask: bevy::math::BVec4, - #[proxy] - if_true: bevy::math::DVec4, - #[proxy] - if_false: bevy::math::DVec4, - ) -> bevy::math::DVec4; + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector from an array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f64; 4]) -> bevy::math::DVec4; + #[lua()] + fn from_array(a: [f64; 4]) -> LuaReflectValProxy; "#, r#" /// `[x, y, z, w]` - #[lua(kind = "Method")] - fn to_array(&self) -> [f64; 4]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f64; 4]; "#, r#" /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. /// Truncation to [`DVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. - #[lua(kind = "Method", output(proxy))] - fn truncate(self) -> bevy::math::DVec3; + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `x`. - #[lua(kind = "Method", output(proxy))] - fn with_x(self, x: f64) -> bevy::math::DVec4; + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: f64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `y`. - #[lua(kind = "Method", output(proxy))] - fn with_y(self, y: f64) -> bevy::math::DVec4; + #[lua()] + fn with_y( + _self: LuaReflectValProxy, + y: f64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `z`. - #[lua(kind = "Method", output(proxy))] - fn with_z(self, z: f64) -> bevy::math::DVec4; + #[lua()] + fn with_z( + _self: LuaReflectValProxy, + z: f64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4D vector from `self` with the given value of `w`. - #[lua(kind = "Method", output(proxy))] - fn with_w(self, w: f64) -> bevy::math::DVec4; + #[lua()] + fn with_w( + _self: LuaReflectValProxy, + w: f64, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::DVec4) -> f64; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" /// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(kind = "Method", output(proxy))] - fn dot_into_vec(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua()] + fn dot_into_vec( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the minimum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn min(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua()] + fn min( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the maximum values for each element of `self` and `rhs`. /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. - #[lua(kind = "Method", output(proxy))] - fn max(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua()] + fn max( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15460,46 +16419,44 @@ struct DVec3 { /// # Panics /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn clamp( - self, - #[proxy] - min: bevy::math::DVec4, - #[proxy] - max: bevy::math::DVec4, - ) -> bevy::math::DVec4; + _self: LuaReflectValProxy, + min: LuaReflectValProxy, + max: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the horizontal minimum of `self`. /// In other words this computes `min(x, y, ..)`. - #[lua(kind = "Method")] - fn min_element(self) -> f64; + #[lua()] + fn min_element(_self: LuaReflectValProxy) -> f64; "#, r#" /// Returns the horizontal maximum of `self`. /// In other words this computes `max(x, y, ..)`. - #[lua(kind = "Method")] - fn max_element(self) -> f64; + #[lua()] + fn max_element(_self: LuaReflectValProxy) -> f64; "#, r#" /// Returns the sum of all elements of `self`. /// In other words, this computes `self.x + self.y + ..`. - #[lua(kind = "Method")] - fn element_sum(self) -> f64; + #[lua()] + fn element_sum(_self: LuaReflectValProxy) -> f64; "#, r#" /// Returns the product of all elements of `self`. /// In other words, this computes `self.x * self.y * ..`. - #[lua(kind = "Method")] - fn element_product(self) -> f64; + #[lua()] + fn element_product(_self: LuaReflectValProxy) -> f64; "#, r#" @@ -15508,8 +16465,11 @@ struct DVec3 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpeq(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; + #[lua()] + fn cmpeq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15518,8 +16478,11 @@ struct DVec3 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpne(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; + #[lua()] + fn cmpne( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15528,8 +16491,11 @@ struct DVec3 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpge(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; + #[lua()] + fn cmpge( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15538,8 +16504,11 @@ struct DVec3 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmpgt(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; + #[lua()] + fn cmpgt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15548,8 +16517,11 @@ struct DVec3 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmple(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; + #[lua()] + fn cmple( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15558,15 +16530,20 @@ struct DVec3 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. - #[lua(kind = "Method", output(proxy))] - fn cmplt(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::BVec4; + #[lua()] + fn cmplt( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the absolute value of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn abs(self) -> bevy::math::DVec4; + #[lua()] + fn abs( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15575,15 +16552,20 @@ struct DVec3 { /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` /// - `NAN` if the number is `NAN` - #[lua(kind = "Method", output(proxy))] - fn signum(self) -> bevy::math::DVec4; + #[lua()] + fn signum( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector with signs of `rhs` and the magnitudes of `self`. - #[lua(kind = "Method", output(proxy))] - fn copysign(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua()] + fn copysign( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15591,91 +16573,107 @@ struct DVec3 { /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn is_negative_bitmask(self) -> u32; + #[lua()] + fn is_negative_bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns `true` if, and only if, all elements are finite. If any element is either /// `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; "#, r#" /// Performs `is_finite` on each element of self, returning a vector mask of the results. /// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`. - #[lua(kind = "Method", output(proxy))] - fn is_finite_mask(self) -> bevy::math::BVec4; + #[lua()] + fn is_finite_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; "#, r#" /// Performs `is_nan` on each element of self, returning a vector mask of the results. /// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`. - #[lua(kind = "Method", output(proxy))] - fn is_nan_mask(self) -> bevy::math::BVec4; + #[lua()] + fn is_nan_mask( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the length of `self`. - #[lua(kind = "Method")] - fn length(self) -> f64; + #[lua()] + fn length(_self: LuaReflectValProxy) -> f64; "#, r#" /// Computes the squared length of `self`. /// This is faster than `length()` as it avoids a square root operation. - #[lua(kind = "Method")] - fn length_squared(self) -> f64; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f64; "#, r#" /// Computes `1.0 / length()`. /// For valid results, `self` must _not_ be of length zero. - #[lua(kind = "Method")] - fn length_recip(self) -> f64; + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f64; "#, r#" /// Computes the Euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance(self, #[proxy] rhs: bevy::math::DVec4) -> f64; + #[lua()] + fn distance( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" /// Compute the squared euclidean distance between two points in space. - #[lua(kind = "Method")] - fn distance_squared(self, #[proxy] rhs: bevy::math::DVec4) -> f64; + #[lua()] + fn distance_squared( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. - #[lua(kind = "Method", output(proxy))] - fn div_euclid(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua()] + fn div_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. /// [Euclidean division]: f64::rem_euclid - #[lua(kind = "Method", output(proxy))] - fn rem_euclid(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua()] + fn rem_euclid( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15685,8 +16683,10 @@ struct DVec3 { /// Panics /// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::DVec4; + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15696,8 +16696,11 @@ struct DVec3 { /// the result of this operation will be the fallback value. /// See also [`Self::try_normalize()`]. - #[lua(kind = "Method", output(proxy))] - fn normalize_or(self, #[proxy] fallback: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua()] + fn normalize_or( + _self: LuaReflectValProxy, + fallback: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15706,16 +16709,18 @@ struct DVec3 { /// the result of this operation will be zero. /// See also [`Self::try_normalize()`]. - #[lua(kind = "Method", output(proxy))] - fn normalize_or_zero(self) -> bevy::math::DVec4; + #[lua()] + fn normalize_or_zero( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns whether `self` is length `1.0` or not. /// Uses a precision threshold of approximately `1e-4`. - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; "#, r#" @@ -15724,8 +16729,11 @@ struct DVec3 { /// # Panics /// Will panic if `rhs` is zero length when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn project_onto(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua()] + fn project_onto( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15736,8 +16744,11 @@ struct DVec3 { /// # Panics /// Will panic if `rhs` has a length of zero when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reject_from(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua()] + fn reject_from( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15746,12 +16757,11 @@ struct DVec3 { /// # Panics /// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn project_onto_normalized( - self, - #[proxy] - rhs: bevy::math::DVec4, - ) -> bevy::math::DVec4; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15762,44 +16772,51 @@ struct DVec3 { /// # Panics /// Will panic if `rhs` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn reject_from_normalized( - self, - #[proxy] - rhs: bevy::math::DVec4, - ) -> bevy::math::DVec4; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the nearest integer to a number for each element of `self`. /// Round half-way cases away from 0.0. - #[lua(kind = "Method", output(proxy))] - fn round(self) -> bevy::math::DVec4; + #[lua()] + fn round( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the largest integer less than or equal to a number for each /// element of `self`. - #[lua(kind = "Method", output(proxy))] - fn floor(self) -> bevy::math::DVec4; + #[lua()] + fn floor( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the smallest integer greater than or equal to a number for /// each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn ceil(self) -> bevy::math::DVec4; + #[lua()] + fn ceil( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the integer part each element of `self`. This means numbers are /// always truncated towards zero. - #[lua(kind = "Method", output(proxy))] - fn trunc(self) -> bevy::math::DVec4; + #[lua()] + fn trunc( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15808,8 +16825,10 @@ struct DVec3 { /// `self - self.floor()`. /// Note that this is fast but not precise for large numbers. - #[lua(kind = "Method", output(proxy))] - fn fract(self) -> bevy::math::DVec4; + #[lua()] + fn fract( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15818,30 +16837,39 @@ struct DVec3 { /// `self - self.trunc()`. /// Note that this is fast but not precise for large numbers. - #[lua(kind = "Method", output(proxy))] - fn fract_gl(self) -> bevy::math::DVec4; + #[lua()] + fn fract_gl( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing `e^self` (the exponential function) for each element of /// `self`. - #[lua(kind = "Method", output(proxy))] - fn exp(self) -> bevy::math::DVec4; + #[lua()] + fn exp( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing each element of `self` raised to the power of `n`. - #[lua(kind = "Method", output(proxy))] - fn powf(self, n: f64) -> bevy::math::DVec4; + #[lua()] + fn powf( + _self: LuaReflectValProxy, + n: f64, + ) -> LuaReflectValProxy; "#, r#" /// Returns a vector containing the reciprocal `1.0/n` of each element of `self`. - #[lua(kind = "Method", output(proxy))] - fn recip(self) -> bevy::math::DVec4; + #[lua()] + fn recip( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15850,8 +16878,12 @@ struct DVec3 { /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly /// extrapolated. - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] rhs: bevy::math::DVec4, s: f64) -> bevy::math::DVec4; + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + s: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -15859,8 +16891,12 @@ struct DVec3 { /// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to /// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`. - #[lua(kind = "Method", output(proxy))] - fn move_towards(&self, #[proxy] rhs: bevy::math::DVec4, d: f64) -> bevy::math::DVec4; + #[lua()] + fn move_towards( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + d: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -15869,8 +16905,11 @@ struct DVec3 { /// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)` /// while being slightly cheaper to compute. - #[lua(kind = "Method", output(proxy))] - fn midpoint(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua()] + fn midpoint( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15882,8 +16921,12 @@ struct DVec3 { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::DVec4, max_abs_diff: f64) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; "#, r#" @@ -15891,8 +16934,12 @@ struct DVec3 { /// # Panics /// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length(self, min: f64, max: f64) -> bevy::math::DVec4; + #[lua()] + fn clamp_length( + _self: LuaReflectValProxy, + min: f64, + max: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -15900,8 +16947,11 @@ struct DVec3 { /// # Panics /// Will panic if `max` is negative when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length_max(self, max: f64) -> bevy::math::DVec4; + #[lua()] + fn clamp_length_max( + _self: LuaReflectValProxy, + max: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -15909,8 +16959,11 @@ struct DVec3 { /// # Panics /// Will panic if `min` is negative when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn clamp_length_min(self, min: f64) -> bevy::math::DVec4; + #[lua()] + fn clamp_length_min( + _self: LuaReflectValProxy, + min: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -15921,14 +16974,12 @@ struct DVec3 { /// and will be heavily dependant on designing algorithms with specific target hardware in /// mind. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn mul_add( - self, - #[proxy] - a: bevy::math::DVec4, - #[proxy] - b: bevy::math::DVec4, - ) -> bevy::math::DVec4; + _self: LuaReflectValProxy, + a: LuaReflectValProxy, + b: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15938,8 +16989,11 @@ struct DVec3 { /// # Panics /// Will panic if `normal` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn reflect(self, #[proxy] normal: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua()] + fn reflect( + _self: LuaReflectValProxy, + normal: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15950,181 +17004,184 @@ struct DVec3 { /// # Panics /// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn refract(self, #[proxy] normal: bevy::math::DVec4, eta: f64) -> bevy::math::DVec4; + #[lua()] + fn refract( + _self: LuaReflectValProxy, + normal: LuaReflectValProxy, + eta: f64, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `f32`. - #[lua(kind = "Method", output(proxy))] - fn as_vec4(&self) -> bevy::math::Vec4; + #[lua()] + fn as_vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i32`. - #[lua(kind = "Method", output(proxy))] - fn as_ivec4(&self) -> bevy::math::IVec4; + #[lua()] + fn as_ivec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u32`. - #[lua(kind = "Method", output(proxy))] - fn as_uvec4(&self) -> bevy::math::UVec4; + #[lua()] + fn as_uvec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `i64`. - #[lua(kind = "Method", output(proxy))] - fn as_i64vec4(&self) -> bevy::math::I64Vec4; + #[lua()] + fn as_i64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Casts all elements of `self` to `u64`. - #[lua(kind = "Method", output(proxy))] - fn as_u64vec4(&self) -> bevy::math::U64Vec4; + #[lua()] + fn as_u64vec4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, rhs: f64) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind="MetaMethod", raw , metamethod="Index")] -fn index(&self, lua: &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(self.inner()?[*idx]) +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> LuaIdentityProxy { + _self[idx - 1] } "#, r#" -#[lua(kind="MutatingMetaMethod", raw, metamethod="NewIndex")] -fn index(&mut self, lua: &Lua, idx: crate::lua::util::LuaIndex, val: f64) -> Result<(),_> { - self.val_mut(|s| Ok(s[*idx] = val))? +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: f64) -> () { + _self[idx - 1] = val } "#] )] -struct DVec4 { +pub struct DVec4 { x: f64, y: f64, z: f64, w: f64, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Mat2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Mat2; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2x2 matrix from two column vectors. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_cols( - #[proxy] - x_axis: bevy::math::Vec2, - #[proxy] - y_axis: bevy::math::Vec2, - ) -> bevy::math::Mat2; + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a `[f32; 4]` array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f32; 4]; + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f32; 4]; "#, r#" /// Creates a `[[f32; 2]; 2]` 2D array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f32; 2]; 2]; + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f32; 2]; 2]; "#, r#" /// Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0. - #[lua(kind = "Function", output(proxy))] - fn from_diagonal(#[proxy] diagonal: bevy::math::Vec2) -> bevy::math::Mat2; + #[lua()] + fn from_diagonal( + diagonal: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of /// `angle` (in radians). - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_scale_angle( - #[proxy] - scale: bevy::math::Vec2, + scale: LuaReflectValProxy, angle: f32, - ) -> bevy::math::Mat2; + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2x2 matrix containing a rotation of `angle` (in radians). - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f32) -> bevy::math::Mat2; + #[lua()] + fn from_angle(angle: f32) -> LuaReflectValProxy; "#, r#" /// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] m: bevy::math::Mat3) -> bevy::math::Mat2; + #[lua()] + fn from_mat3( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -16133,20 +17190,21 @@ struct DVec4 { /// # Panics /// Panics if `i` or `j` is greater than 2. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_mat3_minor( - #[proxy] - m: bevy::math::Mat3, + m: LuaReflectValProxy, i: usize, j: usize, - ) -> bevy::math::Mat2; + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. - #[lua(kind = "Function", output(proxy))] - fn from_mat3a(#[proxy] m: bevy::math::Mat3A) -> bevy::math::Mat2; + #[lua()] + fn from_mat3a( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -16155,13 +17213,12 @@ struct DVec4 { /// # Panics /// Panics if `i` or `j` is greater than 2. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_mat3a_minor( - #[proxy] - m: bevy::math::Mat3A, + m: LuaReflectValProxy, i: usize, j: usize, - ) -> bevy::math::Mat2; + ) -> LuaReflectValProxy; "#, r#" @@ -16169,8 +17226,11 @@ struct DVec4 { /// # Panics /// Panics if `index` is greater than 1. - #[lua(kind = "Method", output(proxy))] - fn col(&self, index: usize) -> bevy::math::Vec2; + #[lua()] + fn col( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; "#, r#" @@ -16178,37 +17238,42 @@ struct DVec4 { /// # Panics /// Panics if `index` is greater than 1. - #[lua(kind = "Method", output(proxy))] - fn row(&self, index: usize) -> bevy::math::Vec2; + #[lua()] + fn row( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if, and only if, all elements are finite. /// If any element is either `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns the transpose of `self`. - #[lua(kind = "Method", output(proxy))] - fn transpose(&self) -> bevy::math::Mat2; + #[lua()] + fn transpose( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the determinant of `self`. - #[lua(kind = "Method")] - fn determinant(&self) -> f32; + #[lua()] + fn determinant(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -16217,50 +17282,70 @@ struct DVec4 { /// # Panics /// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::Mat2; + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms a 2D vector. - #[lua(kind = "Method", output(proxy))] - fn mul_vec2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn mul_vec2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies two 2x2 matrices. - #[lua(kind = "Method", output(proxy))] - fn mul_mat2(&self, #[proxy] rhs: &glam::Mat2) -> bevy::math::Mat2; + #[lua()] + fn mul_mat2( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Adds two 2x2 matrices. - #[lua(kind = "Method", output(proxy))] - fn add_mat2(&self, #[proxy] rhs: &glam::Mat2) -> bevy::math::Mat2; + #[lua()] + fn add_mat2( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Subtracts two 2x2 matrices. - #[lua(kind = "Method", output(proxy))] - fn sub_mat2(&self, #[proxy] rhs: &glam::Mat2) -> bevy::math::Mat2; + #[lua()] + fn sub_mat2( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies a 2x2 matrix by a scalar. - #[lua(kind = "Method", output(proxy))] - fn mul_scalar(&self, rhs: f32) -> bevy::math::Mat2; + #[lua()] + fn mul_scalar( + _self: LuaReflectRefProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" /// Divides a 2x2 matrix by a scalar. - #[lua(kind = "Method", output(proxy))] - fn div_scalar(&self, rhs: f32) -> bevy::math::Mat2; + #[lua()] + fn div_scalar( + _self: LuaReflectRefProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -16272,242 +17357,211 @@ struct DVec4 { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Mat2, max_abs_diff: f32) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; "#, r#" /// Takes the absolute value of each element in `self` - #[lua(kind = "Method", output(proxy))] - fn abs(&self) -> bevy::math::Mat2; + #[lua()] + fn abs( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(kind = "Method", output(proxy))] - fn as_dmat2(&self) -> bevy::math::DMat2; + #[lua()] + fn as_dmat2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Mat2) -> bevy::math::Mat2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Mat2; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f32) -> bevy::math::Mat2; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Mat2) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Mat2) -> bevy::math::Mat2; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Mat2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Mat2) -> bevy::math::Mat2; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(LuaVec2::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) +#[lua(metamethod="Index")] +fn index(_self: LuaIdentityProxy, idx: usize) -> LuaIdentityProxy { + let mut curr_ref = _self.0.clone(); + let def_ref = bevy_mod_scripting_core::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if let Some(ret) = ref_.try_as_reflect_mut().map(|ret| ret.downcast_mut::()).flatten(){ + Ok(ret.col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push(bevy_mod_scripting_core::bindings::ReflectionPathElem::new_deferred(def_ref)); + LuaVec2(curr_ref) } "#] )] -struct Mat2(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Mat2(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Mat3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Mat3) -> bevy::math::Mat3; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f32) -> bevy::math::Mat3; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Mat3) -> bevy::math::Mat3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Mat3; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3x3 matrix from three column vectors. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_cols( - #[proxy] - x_axis: bevy::math::Vec3, - #[proxy] - y_axis: bevy::math::Vec3, - #[proxy] - z_axis: bevy::math::Vec3, - ) -> bevy::math::Mat3; + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a `[f32; 9]` array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f32; 9]; + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f32; 9]; "#, r#" /// Creates a `[[f32; 3]; 3]` 3D array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f32; 3]; 3]; + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f32; 3]; 3]; "#, r#" /// Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. - #[lua(kind = "Function", output(proxy))] - fn from_diagonal(#[proxy] diagonal: bevy::math::Vec3) -> bevy::math::Mat3; + #[lua()] + fn from_diagonal( + diagonal: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column. - #[lua(kind = "Function", output(proxy))] - fn from_mat4(#[proxy] m: bevy::math::Mat4) -> bevy::math::Mat3; + #[lua()] + fn from_mat4( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -16516,13 +17570,12 @@ struct Mat2(); /// # Panics /// Panics if `i` or `j` is greater than 3. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_mat4_minor( - #[proxy] - m: bevy::math::Mat4, + m: LuaReflectValProxy, i: usize, j: usize, - ) -> bevy::math::Mat3; + ) -> LuaReflectValProxy; "#, r#" @@ -16530,8 +17583,10 @@ struct Mat2(); /// # Panics /// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_quat(#[proxy] rotation: bevy::math::Quat) -> bevy::math::Mat3; + #[lua()] + fn from_quat( + rotation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -16540,22 +17595,24 @@ struct Mat2(); /// # Panics /// Will panic if `axis` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_axis_angle(#[proxy] axis: bevy::math::Vec3, angle: f32) -> bevy::math::Mat3; + #[lua()] + fn from_axis_angle( + axis: LuaReflectValProxy, + angle: f32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in /// radians). - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_euler( - #[proxy] - order: bevy::math::EulerRot, + order: LuaReflectValProxy, a: f32, b: f32, c: f32, - ) -> bevy::math::Mat3; + ) -> LuaReflectValProxy; "#, r#" @@ -16565,29 +17622,32 @@ struct Mat2(); /// # Panics /// Will panic if any input matrix column is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method")] - fn to_euler(&self, #[proxy] order: bevy::math::EulerRot) -> (f32, f32, f32); + #[lua()] + fn to_euler( + _self: LuaReflectRefProxy, + order: LuaReflectValProxy, + ) -> (f32, f32, f32); "#, r#" /// Creates a 3D rotation matrix from `angle` (in radians) around the x axis. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f32) -> bevy::math::Mat3; + #[lua()] + fn from_rotation_x(angle: f32) -> LuaReflectValProxy; "#, r#" /// Creates a 3D rotation matrix from `angle` (in radians) around the y axis. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f32) -> bevy::math::Mat3; + #[lua()] + fn from_rotation_y(angle: f32) -> LuaReflectValProxy; "#, r#" /// Creates a 3D rotation matrix from `angle` (in radians) around the z axis. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f32) -> bevy::math::Mat3; + #[lua()] + fn from_rotation_z(angle: f32) -> LuaReflectValProxy; "#, r#" @@ -16595,8 +17655,10 @@ struct Mat2(); /// The resulting matrix can be used to transform 2D points and vectors. See /// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::Vec2) -> bevy::math::Mat3; + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -16605,8 +17667,8 @@ struct Mat2(); /// The resulting matrix can be used to transform 2D points and vectors. See /// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f32) -> bevy::math::Mat3; + #[lua()] + fn from_angle(angle: f32) -> LuaReflectValProxy; "#, r#" @@ -16615,14 +17677,12 @@ struct Mat2(); /// The resulting matrix can be used to transform 2D points and vectors. See /// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_scale_angle_translation( - #[proxy] - scale: bevy::math::Vec2, + scale: LuaReflectValProxy, angle: f32, - #[proxy] - translation: bevy::math::Vec2, - ) -> bevy::math::Mat3; + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -16632,8 +17692,10 @@ struct Mat2(); /// # Panics /// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::Vec2) -> bevy::math::Mat3; + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -16641,8 +17703,10 @@ struct Mat2(); /// The resulting matrix can be used to transform 2D points and vectors. See /// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - #[lua(kind = "Function", output(proxy))] - fn from_mat2(#[proxy] m: bevy::math::Mat2) -> bevy::math::Mat3; + #[lua()] + fn from_mat2( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -16650,8 +17714,11 @@ struct Mat2(); /// # Panics /// Panics if `index` is greater than 2. - #[lua(kind = "Method", output(proxy))] - fn col(&self, index: usize) -> bevy::math::Vec3; + #[lua()] + fn col( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; "#, r#" @@ -16659,37 +17726,42 @@ struct Mat2(); /// # Panics /// Panics if `index` is greater than 2. - #[lua(kind = "Method", output(proxy))] - fn row(&self, index: usize) -> bevy::math::Vec3; + #[lua()] + fn row( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if, and only if, all elements are finite. /// If any element is either `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns the transpose of `self`. - #[lua(kind = "Method", output(proxy))] - fn transpose(&self) -> bevy::math::Mat3; + #[lua()] + fn transpose( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the determinant of `self`. - #[lua(kind = "Method")] - fn determinant(&self) -> f32; + #[lua()] + fn determinant(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -16698,8 +17770,10 @@ struct Mat2(); /// # Panics /// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::Mat3; + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -16709,8 +17783,11 @@ struct Mat2(); /// # Panics /// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn transform_point2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn transform_point2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -16720,57 +17797,81 @@ struct Mat2(); /// # Panics /// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn transform_vector2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn transform_vector2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms a 3D vector. - #[lua(kind = "Method", output(proxy))] - fn mul_vec3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn mul_vec3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms a [`Vec3A`]. - #[lua(kind = "Method", output(proxy))] - fn mul_vec3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn mul_vec3a( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies two 3x3 matrices. - #[lua(kind = "Method", output(proxy))] - fn mul_mat3(&self, #[proxy] rhs: &glam::Mat3) -> bevy::math::Mat3; + #[lua()] + fn mul_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Adds two 3x3 matrices. - #[lua(kind = "Method", output(proxy))] - fn add_mat3(&self, #[proxy] rhs: &glam::Mat3) -> bevy::math::Mat3; + #[lua()] + fn add_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Subtracts two 3x3 matrices. - #[lua(kind = "Method", output(proxy))] - fn sub_mat3(&self, #[proxy] rhs: &glam::Mat3) -> bevy::math::Mat3; + #[lua()] + fn sub_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies a 3x3 matrix by a scalar. - #[lua(kind = "Method", output(proxy))] - fn mul_scalar(&self, rhs: f32) -> bevy::math::Mat3; + #[lua()] + fn mul_scalar( + _self: LuaReflectRefProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" /// Divides a 3x3 matrix by a scalar. - #[lua(kind = "Method", output(proxy))] - fn div_scalar(&self, rhs: f32) -> bevy::math::Mat3; + #[lua()] + fn div_scalar( + _self: LuaReflectRefProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -16782,189 +17883,171 @@ struct Mat2(); /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Mat3, max_abs_diff: f32) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; "#, r#" /// Takes the absolute value of each element in `self` - #[lua(kind = "Method", output(proxy))] - fn abs(&self) -> bevy::math::Mat3; + #[lua()] + fn abs( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(kind = "Method", output(proxy))] - fn as_dmat3(&self) -> bevy::math::DMat3; + #[lua()] + fn as_dmat3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Mat3; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Mat3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Mat3) -> bevy::math::Mat3; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Mat3) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Affine2) -> bevy::math::Mat3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(LuaVec3::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) +#[lua(metamethod="Index")] +fn index(_self: LuaIdentityProxy, idx: usize) -> LuaIdentityProxy { + let mut curr_ref = _self.0.clone(); + let def_ref = bevy_mod_scripting_core::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if let Some(ret) = ref_.try_as_reflect_mut().map(|ret| ret.downcast_mut::()).flatten(){ + Ok(ret.col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push(bevy_mod_scripting_core::bindings::ReflectionPathElem::new_deferred(def_ref)); + LuaVec3(curr_ref) } "#] )] -struct Mat3 { - #[lua(output(proxy))] +pub struct Mat3 { x_axis: bevy::math::Vec3, - #[lua(output(proxy))] y_axis: bevy::math::Vec3, - #[lua(output(proxy))] z_axis: bevy::math::Vec3, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Mat3A", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a 3x3 matrix from three column vectors. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_cols( - #[proxy] - x_axis: bevy::math::Vec3A, - #[proxy] - y_axis: bevy::math::Vec3A, - #[proxy] - z_axis: bevy::math::Vec3A, - ) -> bevy::math::Mat3A; + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a `[f32; 9]` array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f32; 9]; + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f32; 9]; "#, r#" /// Creates a `[[f32; 3]; 3]` 3D array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f32; 3]; 3]; + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f32; 3]; 3]; "#, r#" /// Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. - #[lua(kind = "Function", output(proxy))] - fn from_diagonal(#[proxy] diagonal: bevy::math::Vec3) -> bevy::math::Mat3A; + #[lua()] + fn from_diagonal( + diagonal: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column. - #[lua(kind = "Function", output(proxy))] - fn from_mat4(#[proxy] m: bevy::math::Mat4) -> bevy::math::Mat3A; + #[lua()] + fn from_mat4( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -16973,13 +18056,12 @@ struct Mat3 { /// # Panics /// Panics if `i` or `j` is greater than 3. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_mat4_minor( - #[proxy] - m: bevy::math::Mat4, + m: LuaReflectValProxy, i: usize, j: usize, - ) -> bevy::math::Mat3A; + ) -> LuaReflectValProxy; "#, r#" @@ -16987,8 +18069,10 @@ struct Mat3 { /// # Panics /// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_quat(#[proxy] rotation: bevy::math::Quat) -> bevy::math::Mat3A; + #[lua()] + fn from_quat( + rotation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -16997,22 +18081,24 @@ struct Mat3 { /// # Panics /// Will panic if `axis` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_axis_angle(#[proxy] axis: bevy::math::Vec3, angle: f32) -> bevy::math::Mat3A; + #[lua()] + fn from_axis_angle( + axis: LuaReflectValProxy, + angle: f32, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in /// radians). - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_euler( - #[proxy] - order: bevy::math::EulerRot, + order: LuaReflectValProxy, a: f32, b: f32, c: f32, - ) -> bevy::math::Mat3A; + ) -> LuaReflectValProxy; "#, r#" @@ -17022,29 +18108,32 @@ struct Mat3 { /// # Panics /// Will panic if any input matrix column is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method")] - fn to_euler(&self, #[proxy] order: bevy::math::EulerRot) -> (f32, f32, f32); + #[lua()] + fn to_euler( + _self: LuaReflectRefProxy, + order: LuaReflectValProxy, + ) -> (f32, f32, f32); "#, r#" /// Creates a 3D rotation matrix from `angle` (in radians) around the x axis. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f32) -> bevy::math::Mat3A; + #[lua()] + fn from_rotation_x(angle: f32) -> LuaReflectValProxy; "#, r#" /// Creates a 3D rotation matrix from `angle` (in radians) around the y axis. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f32) -> bevy::math::Mat3A; + #[lua()] + fn from_rotation_y(angle: f32) -> LuaReflectValProxy; "#, r#" /// Creates a 3D rotation matrix from `angle` (in radians) around the z axis. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f32) -> bevy::math::Mat3A; + #[lua()] + fn from_rotation_z(angle: f32) -> LuaReflectValProxy; "#, r#" @@ -17052,8 +18141,10 @@ struct Mat3 { /// The resulting matrix can be used to transform 2D points and vectors. See /// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::Vec2) -> bevy::math::Mat3A; + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17062,8 +18153,8 @@ struct Mat3 { /// The resulting matrix can be used to transform 2D points and vectors. See /// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f32) -> bevy::math::Mat3A; + #[lua()] + fn from_angle(angle: f32) -> LuaReflectValProxy; "#, r#" @@ -17072,14 +18163,12 @@ struct Mat3 { /// The resulting matrix can be used to transform 2D points and vectors. See /// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_scale_angle_translation( - #[proxy] - scale: bevy::math::Vec2, + scale: LuaReflectValProxy, angle: f32, - #[proxy] - translation: bevy::math::Vec2, - ) -> bevy::math::Mat3A; + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17089,8 +18178,10 @@ struct Mat3 { /// # Panics /// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::Vec2) -> bevy::math::Mat3A; + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17098,8 +18189,10 @@ struct Mat3 { /// The resulting matrix can be used to transform 2D points and vectors. See /// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - #[lua(kind = "Function", output(proxy))] - fn from_mat2(#[proxy] m: bevy::math::Mat2) -> bevy::math::Mat3A; + #[lua()] + fn from_mat2( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17107,8 +18200,11 @@ struct Mat3 { /// # Panics /// Panics if `index` is greater than 2. - #[lua(kind = "Method", output(proxy))] - fn col(&self, index: usize) -> bevy::math::Vec3A; + #[lua()] + fn col( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; "#, r#" @@ -17116,37 +18212,42 @@ struct Mat3 { /// # Panics /// Panics if `index` is greater than 2. - #[lua(kind = "Method", output(proxy))] - fn row(&self, index: usize) -> bevy::math::Vec3A; + #[lua()] + fn row( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if, and only if, all elements are finite. /// If any element is either `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns the transpose of `self`. - #[lua(kind = "Method", output(proxy))] - fn transpose(&self) -> bevy::math::Mat3A; + #[lua()] + fn transpose( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the determinant of `self`. - #[lua(kind = "Method")] - fn determinant(&self) -> f32; + #[lua()] + fn determinant(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -17155,8 +18256,10 @@ struct Mat3 { /// # Panics /// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::Mat3A; + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17166,8 +18269,11 @@ struct Mat3 { /// # Panics /// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn transform_point2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn transform_point2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17177,57 +18283,81 @@ struct Mat3 { /// # Panics /// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn transform_vector2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn transform_vector2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms a 3D vector. - #[lua(kind = "Method", output(proxy))] - fn mul_vec3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn mul_vec3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms a [`Vec3A`]. - #[lua(kind = "Method", output(proxy))] - fn mul_vec3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn mul_vec3a( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies two 3x3 matrices. - #[lua(kind = "Method", output(proxy))] - fn mul_mat3(&self, #[proxy] rhs: &glam::Mat3A) -> bevy::math::Mat3A; + #[lua()] + fn mul_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Adds two 3x3 matrices. - #[lua(kind = "Method", output(proxy))] - fn add_mat3(&self, #[proxy] rhs: &glam::Mat3A) -> bevy::math::Mat3A; + #[lua()] + fn add_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Subtracts two 3x3 matrices. - #[lua(kind = "Method", output(proxy))] - fn sub_mat3(&self, #[proxy] rhs: &glam::Mat3A) -> bevy::math::Mat3A; + #[lua()] + fn sub_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies a 3x3 matrix by a scalar. - #[lua(kind = "Method", output(proxy))] - fn mul_scalar(&self, rhs: f32) -> bevy::math::Mat3A; + #[lua()] + fn mul_scalar( + _self: LuaReflectRefProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" /// Divides a 3x3 matrix by a scalar. - #[lua(kind = "Method", output(proxy))] - fn div_scalar(&self, rhs: f32) -> bevy::math::Mat3A; + #[lua()] + fn div_scalar( + _self: LuaReflectRefProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -17239,256 +18369,216 @@ struct Mat3 { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Mat3A, max_abs_diff: f32) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; "#, r#" /// Takes the absolute value of each element in `self` - #[lua(kind = "Method", output(proxy))] - fn abs(&self) -> bevy::math::Mat3A; + #[lua()] + fn abs( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(kind = "Method", output(proxy))] - fn as_dmat3(&self) -> bevy::math::DMat3; + #[lua()] + fn as_dmat3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Mat3A; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Mat3A) -> bevy::math::Mat3A; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Mat3A) -> bevy::math::Mat3A; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Mat3A) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Mat3A; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Mat3A) -> bevy::math::Mat3A; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Mat3A; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Affine2) -> bevy::math::Mat3A; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f32) -> bevy::math::Mat3A; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(LuaVec3A::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) +#[lua(metamethod="Index")] +fn index(_self: LuaIdentityProxy, idx: usize) -> LuaIdentityProxy { + let mut curr_ref = _self.0.clone(); + let def_ref = bevy_mod_scripting_core::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if let Some(ret) = ref_.try_as_reflect_mut().map(|ret| ret.downcast_mut::()).flatten(){ + Ok(ret.col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push(bevy_mod_scripting_core::bindings::ReflectionPathElem::new_deferred(def_ref)); + LuaVec3A(curr_ref) } "#] )] -struct Mat3A { - #[lua(output(proxy))] +pub struct Mat3A { x_axis: bevy::math::Vec3A, - #[lua(output(proxy))] y_axis: bevy::math::Vec3A, - #[lua(output(proxy))] z_axis: bevy::math::Vec3A, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Mat4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f32) -> bevy::math::Mat4; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Mat4) -> bevy::math::Mat4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4x4 matrix from four column vectors. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_cols( - #[proxy] - x_axis: bevy::math::Vec4, - #[proxy] - y_axis: bevy::math::Vec4, - #[proxy] - z_axis: bevy::math::Vec4, - #[proxy] - w_axis: bevy::math::Vec4, - ) -> bevy::math::Mat4; + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + w_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a `[f32; 16]` array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f32; 16]; + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f32; 16]; "#, r#" /// Creates a `[[f32; 4]; 4]` 4D array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f32; 4]; 4]; + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f32; 4]; 4]; "#, r#" /// Creates a 4x4 matrix with its diagonal set to `diagonal` and all other entries set to 0. - #[lua(kind = "Function", output(proxy))] - fn from_diagonal(#[proxy] diagonal: bevy::math::Vec4) -> bevy::math::Mat4; + #[lua()] + fn from_diagonal( + diagonal: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17499,15 +18589,12 @@ struct Mat3A { /// # Panics /// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_scale_rotation_translation( - #[proxy] - scale: bevy::math::Vec3, - #[proxy] - rotation: bevy::math::Quat, - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::math::Mat4; + scale: LuaReflectValProxy, + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17517,13 +18604,11 @@ struct Mat3A { /// # Panics /// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_rotation_translation( - #[proxy] - rotation: bevy::math::Quat, - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::math::Mat4; + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17533,8 +18618,10 @@ struct Mat3A { /// # Panics /// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_quat(#[proxy] rotation: bevy::math::Quat) -> bevy::math::Mat4; + #[lua()] + fn from_quat( + rotation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17543,8 +18630,10 @@ struct Mat3A { /// The resulting matrix can be used to transform 3D points and vectors. See /// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] m: bevy::math::Mat3) -> bevy::math::Mat4; + #[lua()] + fn from_mat3( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17553,8 +18642,10 @@ struct Mat3A { /// The resulting matrix can be used to transform 3D points and vectors. See /// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - #[lua(kind = "Function", output(proxy))] - fn from_mat3a(#[proxy] m: bevy::math::Mat3A) -> bevy::math::Mat4; + #[lua()] + fn from_mat3a( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17562,8 +18653,10 @@ struct Mat3A { /// The resulting matrix can be used to transform 3D points and vectors. See /// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::Vec3) -> bevy::math::Mat4; + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17574,8 +18667,11 @@ struct Mat3A { /// # Panics /// Will panic if `axis` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_axis_angle(#[proxy] axis: bevy::math::Vec3, angle: f32) -> bevy::math::Mat4; + #[lua()] + fn from_axis_angle( + axis: LuaReflectValProxy, + angle: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -17584,14 +18680,13 @@ struct Mat3A { /// The resulting matrix can be used to transform 3D points and vectors. See /// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_euler( - #[proxy] - order: bevy::math::EulerRot, + order: LuaReflectValProxy, a: f32, b: f32, c: f32, - ) -> bevy::math::Mat4; + ) -> LuaReflectValProxy; "#, r#" @@ -17602,8 +18697,11 @@ struct Mat3A { /// Will panic if any column of the upper 3x3 rotation matrix is not normalized when /// `glam_assert` is enabled. - #[lua(kind = "Method")] - fn to_euler(&self, #[proxy] order: bevy::math::EulerRot) -> (f32, f32, f32); + #[lua()] + fn to_euler( + _self: LuaReflectRefProxy, + order: LuaReflectValProxy, + ) -> (f32, f32, f32); "#, r#" @@ -17612,8 +18710,8 @@ struct Mat3A { /// The resulting matrix can be used to transform 3D points and vectors. See /// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f32) -> bevy::math::Mat4; + #[lua()] + fn from_rotation_x(angle: f32) -> LuaReflectValProxy; "#, r#" @@ -17622,8 +18720,8 @@ struct Mat3A { /// The resulting matrix can be used to transform 3D points and vectors. See /// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f32) -> bevy::math::Mat4; + #[lua()] + fn from_rotation_y(angle: f32) -> LuaReflectValProxy; "#, r#" @@ -17632,8 +18730,8 @@ struct Mat3A { /// The resulting matrix can be used to transform 3D points and vectors. See /// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f32) -> bevy::math::Mat4; + #[lua()] + fn from_rotation_z(angle: f32) -> LuaReflectValProxy; "#, r#" @@ -17643,8 +18741,10 @@ struct Mat3A { /// # Panics /// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::Vec3) -> bevy::math::Mat4; + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17652,8 +18752,11 @@ struct Mat3A { /// # Panics /// Panics if `index` is greater than 3. - #[lua(kind = "Method", output(proxy))] - fn col(&self, index: usize) -> bevy::math::Vec4; + #[lua()] + fn col( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; "#, r#" @@ -17661,37 +18764,42 @@ struct Mat3A { /// # Panics /// Panics if `index` is greater than 3. - #[lua(kind = "Method", output(proxy))] - fn row(&self, index: usize) -> bevy::math::Vec4; + #[lua()] + fn row( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if, and only if, all elements are finite. /// If any element is either `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns the transpose of `self`. - #[lua(kind = "Method", output(proxy))] - fn transpose(&self) -> bevy::math::Mat4; + #[lua()] + fn transpose( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the determinant of `self`. - #[lua(kind = "Method")] - fn determinant(&self) -> f32; + #[lua()] + fn determinant(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -17700,8 +18808,10 @@ struct Mat3A { /// # Panics /// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::Mat4; + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17709,15 +18819,12 @@ struct Mat3A { /// direction. /// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_to_lh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - dir: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Mat4; + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17725,15 +18832,12 @@ struct Mat3A { /// direction. /// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_to_rh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - dir: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Mat4; + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17743,15 +18847,12 @@ struct Mat3A { /// # Panics /// Will panic if `up` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_at_lh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - center: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Mat4; + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17761,15 +18862,12 @@ struct Mat3A { /// # Panics /// Will panic if `up` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_at_rh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - center: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Mat4; + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17778,13 +18876,13 @@ struct Mat3A { /// This is the same as the OpenGL `gluPerspective` function. /// See - #[lua(kind = "Function", output(proxy))] + #[lua()] fn perspective_rh_gl( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, z_far: f32, - ) -> bevy::math::Mat4; + ) -> LuaReflectValProxy; "#, r#" @@ -17794,13 +18892,13 @@ struct Mat3A { /// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is /// enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn perspective_lh( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, z_far: f32, - ) -> bevy::math::Mat4; + ) -> LuaReflectValProxy; "#, r#" @@ -17810,13 +18908,13 @@ struct Mat3A { /// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is /// enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn perspective_rh( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, z_far: f32, - ) -> bevy::math::Mat4; + ) -> LuaReflectValProxy; "#, r#" @@ -17827,12 +18925,12 @@ struct Mat3A { /// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is /// enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn perspective_infinite_lh( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, - ) -> bevy::math::Mat4; + ) -> LuaReflectValProxy; "#, r#" @@ -17841,12 +18939,12 @@ struct Mat3A { /// # Panics /// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn perspective_infinite_reverse_lh( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, - ) -> bevy::math::Mat4; + ) -> LuaReflectValProxy; "#, r#" @@ -17857,12 +18955,12 @@ struct Mat3A { /// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is /// enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn perspective_infinite_rh( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, - ) -> bevy::math::Mat4; + ) -> LuaReflectValProxy; "#, r#" @@ -17871,12 +18969,12 @@ struct Mat3A { /// # Panics /// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn perspective_infinite_reverse_rh( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, - ) -> bevy::math::Mat4; + ) -> LuaReflectValProxy; "#, r#" @@ -17886,7 +18984,7 @@ struct Mat3A { /// /// Useful to map a right-handed coordinate system to the normalized device coordinates that OpenGL expects. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn orthographic_rh_gl( left: f32, right: f32, @@ -17894,14 +18992,14 @@ struct Mat3A { top: f32, near: f32, far: f32, - ) -> bevy::math::Mat4; + ) -> LuaReflectValProxy; "#, r#" /// Creates a left-handed orthographic projection matrix with `[0,1]` depth range. /// Useful to map a left-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn orthographic_lh( left: f32, right: f32, @@ -17909,14 +19007,14 @@ struct Mat3A { top: f32, near: f32, far: f32, - ) -> bevy::math::Mat4; + ) -> LuaReflectValProxy; "#, r#" /// Creates a right-handed orthographic projection matrix with `[0,1]` depth range. /// Useful to map a right-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn orthographic_rh( left: f32, right: f32, @@ -17924,7 +19022,7 @@ struct Mat3A { top: f32, near: f32, far: f32, - ) -> bevy::math::Mat4; + ) -> LuaReflectValProxy; "#, r#" @@ -17933,8 +19031,11 @@ struct Mat3A { /// The perspective divide is performed meaning the resulting 3D vector is divided by `w`. /// This method assumes that `self` contains a projective transform. - #[lua(kind = "Method", output(proxy))] - fn project_point3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn project_point3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17947,8 +19048,11 @@ struct Mat3A { /// # Panics /// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn transform_point3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn transform_point3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17959,8 +19063,11 @@ struct Mat3A { /// # Panics /// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn transform_vector3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn transform_vector3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -17969,66 +19076,93 @@ struct Mat3A { /// The perspective divide is performed meaning the resulting 3D vector is divided by `w`. /// This method assumes that `self` contains a projective transform. - #[lua(kind = "Method", output(proxy))] - fn project_point3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn project_point3a( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms the given [`Vec3A`] as 3D point. /// This is the equivalent of multiplying the [`Vec3A`] as a 4D vector where `w` is `1.0`. - #[lua(kind = "Method", output(proxy))] - fn transform_point3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn transform_point3a( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms the give [`Vec3A`] as 3D vector. /// This is the equivalent of multiplying the [`Vec3A`] as a 4D vector where `w` is `0.0`. - #[lua(kind = "Method", output(proxy))] - fn transform_vector3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn transform_vector3a( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms a 4D vector. - #[lua(kind = "Method", output(proxy))] - fn mul_vec4(&self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua()] + fn mul_vec4( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies two 4x4 matrices. - #[lua(kind = "Method", output(proxy))] - fn mul_mat4(&self, #[proxy] rhs: &glam::Mat4) -> bevy::math::Mat4; + #[lua()] + fn mul_mat4( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Adds two 4x4 matrices. - #[lua(kind = "Method", output(proxy))] - fn add_mat4(&self, #[proxy] rhs: &glam::Mat4) -> bevy::math::Mat4; + #[lua()] + fn add_mat4( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Subtracts two 4x4 matrices. - #[lua(kind = "Method", output(proxy))] - fn sub_mat4(&self, #[proxy] rhs: &glam::Mat4) -> bevy::math::Mat4; + #[lua()] + fn sub_mat4( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies a 4x4 matrix by a scalar. - #[lua(kind = "Method", output(proxy))] - fn mul_scalar(&self, rhs: f32) -> bevy::math::Mat4; + #[lua()] + fn mul_scalar( + _self: LuaReflectRefProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" /// Divides a 4x4 matrix by a scalar. - #[lua(kind = "Method", output(proxy))] - fn div_scalar(&self, rhs: f32) -> bevy::math::Mat4; + #[lua()] + fn div_scalar( + _self: LuaReflectRefProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -18040,289 +19174,249 @@ struct Mat3A { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Mat4, max_abs_diff: f32) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; "#, r#" /// Takes the absolute value of each element in `self` - #[lua(kind = "Method", output(proxy))] - fn abs(&self) -> bevy::math::Mat4; + #[lua()] + fn abs( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(kind = "Method", output(proxy))] - fn as_dmat4(&self) -> bevy::math::DMat4; + #[lua()] + fn as_dmat4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::Mat4) -> bevy::math::Mat4; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Vec4) -> bevy::math::Vec4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f32) -> bevy::math::Mat4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::Mat4; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Affine3A) -> bevy::math::Mat4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::Mat4) -> bevy::math::Mat4; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Mat4) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Mat4; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(LuaVec4::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) +#[lua(metamethod="Index")] +fn index(_self: LuaIdentityProxy, idx: usize) -> LuaIdentityProxy { + let mut curr_ref = _self.0.clone(); + let def_ref = bevy_mod_scripting_core::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if let Some(ret) = ref_.try_as_reflect_mut().map(|ret| ret.downcast_mut::()).flatten(){ + Ok(ret.col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push(bevy_mod_scripting_core::bindings::ReflectionPathElem::new_deferred(def_ref)); + LuaVec4(curr_ref) } "#] )] -struct Mat4 { - #[lua(output(proxy))] +pub struct Mat4 { x_axis: bevy::math::Vec4, - #[lua(output(proxy))] y_axis: bevy::math::Vec4, - #[lua(output(proxy))] z_axis: bevy::math::Vec4, - #[lua(output(proxy))] w_axis: bevy::math::Vec4, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::DMat2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f64) -> bevy::math::DMat2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::DMat2; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::DMat2) -> bevy::math::DMat2; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DMat2; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::DMat2) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Creates a 2x2 matrix from two column vectors. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_cols( - #[proxy] - x_axis: bevy::math::DVec2, - #[proxy] - y_axis: bevy::math::DVec2, - ) -> bevy::math::DMat2; + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a `[f64; 4]` array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f64; 4]; + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f64; 4]; "#, r#" /// Creates a `[[f64; 2]; 2]` 2D array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f64; 2]; 2]; + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f64; 2]; 2]; "#, r#" /// Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0. - #[lua(kind = "Function", output(proxy))] - fn from_diagonal(#[proxy] diagonal: bevy::math::DVec2) -> bevy::math::DMat2; + #[lua()] + fn from_diagonal( + diagonal: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of /// `angle` (in radians). - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_scale_angle( - #[proxy] - scale: bevy::math::DVec2, + scale: LuaReflectValProxy, angle: f64, - ) -> bevy::math::DMat2; + ) -> LuaReflectValProxy; "#, r#" /// Creates a 2x2 matrix containing a rotation of `angle` (in radians). - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f64) -> bevy::math::DMat2; + #[lua()] + fn from_angle(angle: f64) -> LuaReflectValProxy; "#, r#" /// Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] m: bevy::math::DMat3) -> bevy::math::DMat2; + #[lua()] + fn from_mat3( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -18331,13 +19425,12 @@ struct Mat4 { /// # Panics /// Panics if `i` or `j` is greater than 2. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_mat3_minor( - #[proxy] - m: bevy::math::DMat3, + m: LuaReflectValProxy, i: usize, j: usize, - ) -> bevy::math::DMat2; + ) -> LuaReflectValProxy; "#, r#" @@ -18345,8 +19438,11 @@ struct Mat4 { /// # Panics /// Panics if `index` is greater than 1. - #[lua(kind = "Method", output(proxy))] - fn col(&self, index: usize) -> bevy::math::DVec2; + #[lua()] + fn col( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; "#, r#" @@ -18354,37 +19450,42 @@ struct Mat4 { /// # Panics /// Panics if `index` is greater than 1. - #[lua(kind = "Method", output(proxy))] - fn row(&self, index: usize) -> bevy::math::DVec2; + #[lua()] + fn row( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if, and only if, all elements are finite. /// If any element is either `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns the transpose of `self`. - #[lua(kind = "Method", output(proxy))] - fn transpose(&self) -> bevy::math::DMat2; + #[lua()] + fn transpose( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the determinant of `self`. - #[lua(kind = "Method")] - fn determinant(&self) -> f64; + #[lua()] + fn determinant(_self: LuaReflectRefProxy) -> f64; "#, r#" @@ -18393,50 +19494,70 @@ struct Mat4 { /// # Panics /// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::DMat2; + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms a 2D vector. - #[lua(kind = "Method", output(proxy))] - fn mul_vec2(&self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn mul_vec2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies two 2x2 matrices. - #[lua(kind = "Method", output(proxy))] - fn mul_mat2(&self, #[proxy] rhs: &glam::DMat2) -> bevy::math::DMat2; + #[lua()] + fn mul_mat2( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Adds two 2x2 matrices. - #[lua(kind = "Method", output(proxy))] - fn add_mat2(&self, #[proxy] rhs: &glam::DMat2) -> bevy::math::DMat2; + #[lua()] + fn add_mat2( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Subtracts two 2x2 matrices. - #[lua(kind = "Method", output(proxy))] - fn sub_mat2(&self, #[proxy] rhs: &glam::DMat2) -> bevy::math::DMat2; + #[lua()] + fn sub_mat2( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies a 2x2 matrix by a scalar. - #[lua(kind = "Method", output(proxy))] - fn mul_scalar(&self, rhs: f64) -> bevy::math::DMat2; + #[lua()] + fn mul_scalar( + _self: LuaReflectRefProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" /// Divides a 2x2 matrix by a scalar. - #[lua(kind = "Method", output(proxy))] - fn div_scalar(&self, rhs: f64) -> bevy::math::DMat2; + #[lua()] + fn div_scalar( + _self: LuaReflectRefProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -18448,235 +19569,205 @@ struct Mat4 { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::DMat2, max_abs_diff: f64) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; "#, r#" /// Takes the absolute value of each element in `self` - #[lua(kind = "Method", output(proxy))] - fn abs(&self) -> bevy::math::DMat2; + #[lua()] + fn abs( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(kind = "Method", output(proxy))] - fn as_mat2(&self) -> bevy::math::Mat2; + #[lua()] + fn as_mat2( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::DMat2) -> bevy::math::DMat2; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DMat2) -> bevy::math::DMat2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f64) -> bevy::math::DMat2; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(LuaDVec2::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) +#[lua(metamethod="Index")] +fn index(_self: LuaIdentityProxy, idx: usize) -> LuaIdentityProxy { + let mut curr_ref = _self.0.clone(); + let def_ref = bevy_mod_scripting_core::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if let Some(ret) = ref_.try_as_reflect_mut().map(|ret| ret.downcast_mut::()).flatten(){ + Ok(ret.col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push(bevy_mod_scripting_core::bindings::ReflectionPathElem::new_deferred(def_ref)); + LuaDVec2(curr_ref) } "#] )] -struct DMat2 { - #[lua(output(proxy))] +pub struct DMat2 { x_axis: bevy::math::DVec2, - #[lua(output(proxy))] y_axis: bevy::math::DVec2, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::DMat3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DAffine2) -> bevy::math::DMat3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::DMat3) -> bevy::math::DMat3; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::DMat3) -> bevy::math::DMat3; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DMat3; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::DMat3) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::DMat3; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f64) -> bevy::math::DMat3; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3x3 matrix from three column vectors. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_cols( - #[proxy] - x_axis: bevy::math::DVec3, - #[proxy] - y_axis: bevy::math::DVec3, - #[proxy] - z_axis: bevy::math::DVec3, - ) -> bevy::math::DMat3; + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a `[f64; 9]` array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f64; 9]; + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f64; 9]; "#, r#" /// Creates a `[[f64; 3]; 3]` 3D array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f64; 3]; 3]; + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f64; 3]; 3]; "#, r#" /// Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. - #[lua(kind = "Function", output(proxy))] - fn from_diagonal(#[proxy] diagonal: bevy::math::DVec3) -> bevy::math::DMat3; + #[lua()] + fn from_diagonal( + diagonal: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column. - #[lua(kind = "Function", output(proxy))] - fn from_mat4(#[proxy] m: bevy::math::DMat4) -> bevy::math::DMat3; + #[lua()] + fn from_mat4( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -18685,13 +19776,12 @@ struct DMat2 { /// # Panics /// Panics if `i` or `j` is greater than 3. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_mat4_minor( - #[proxy] - m: bevy::math::DMat4, + m: LuaReflectValProxy, i: usize, j: usize, - ) -> bevy::math::DMat3; + ) -> LuaReflectValProxy; "#, r#" @@ -18699,8 +19789,10 @@ struct DMat2 { /// # Panics /// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_quat(#[proxy] rotation: bevy::math::DQuat) -> bevy::math::DMat3; + #[lua()] + fn from_quat( + rotation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -18709,26 +19801,24 @@ struct DMat2 { /// # Panics /// Will panic if `axis` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_axis_angle( - #[proxy] - axis: bevy::math::DVec3, + axis: LuaReflectValProxy, angle: f64, - ) -> bevy::math::DMat3; + ) -> LuaReflectValProxy; "#, r#" /// Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in /// radians). - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_euler( - #[proxy] - order: bevy::math::EulerRot, + order: LuaReflectValProxy, a: f64, b: f64, c: f64, - ) -> bevy::math::DMat3; + ) -> LuaReflectValProxy; "#, r#" @@ -18738,29 +19828,32 @@ struct DMat2 { /// # Panics /// Will panic if any input matrix column is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method")] - fn to_euler(&self, #[proxy] order: bevy::math::EulerRot) -> (f64, f64, f64); + #[lua()] + fn to_euler( + _self: LuaReflectRefProxy, + order: LuaReflectValProxy, + ) -> (f64, f64, f64); "#, r#" /// Creates a 3D rotation matrix from `angle` (in radians) around the x axis. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f64) -> bevy::math::DMat3; + #[lua()] + fn from_rotation_x(angle: f64) -> LuaReflectValProxy; "#, r#" /// Creates a 3D rotation matrix from `angle` (in radians) around the y axis. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f64) -> bevy::math::DMat3; + #[lua()] + fn from_rotation_y(angle: f64) -> LuaReflectValProxy; "#, r#" /// Creates a 3D rotation matrix from `angle` (in radians) around the z axis. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f64) -> bevy::math::DMat3; + #[lua()] + fn from_rotation_z(angle: f64) -> LuaReflectValProxy; "#, r#" @@ -18768,8 +19861,10 @@ struct DMat2 { /// The resulting matrix can be used to transform 2D points and vectors. See /// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::DVec2) -> bevy::math::DMat3; + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -18778,8 +19873,8 @@ struct DMat2 { /// The resulting matrix can be used to transform 2D points and vectors. See /// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f64) -> bevy::math::DMat3; + #[lua()] + fn from_angle(angle: f64) -> LuaReflectValProxy; "#, r#" @@ -18788,14 +19883,12 @@ struct DMat2 { /// The resulting matrix can be used to transform 2D points and vectors. See /// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_scale_angle_translation( - #[proxy] - scale: bevy::math::DVec2, + scale: LuaReflectValProxy, angle: f64, - #[proxy] - translation: bevy::math::DVec2, - ) -> bevy::math::DMat3; + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -18805,8 +19898,10 @@ struct DMat2 { /// # Panics /// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::DVec2) -> bevy::math::DMat3; + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -18814,8 +19909,10 @@ struct DMat2 { /// The resulting matrix can be used to transform 2D points and vectors. See /// [`Self::transform_point2()`] and [`Self::transform_vector2()`]. - #[lua(kind = "Function", output(proxy))] - fn from_mat2(#[proxy] m: bevy::math::DMat2) -> bevy::math::DMat3; + #[lua()] + fn from_mat2( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -18823,8 +19920,11 @@ struct DMat2 { /// # Panics /// Panics if `index` is greater than 2. - #[lua(kind = "Method", output(proxy))] - fn col(&self, index: usize) -> bevy::math::DVec3; + #[lua()] + fn col( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; "#, r#" @@ -18832,37 +19932,42 @@ struct DMat2 { /// # Panics /// Panics if `index` is greater than 2. - #[lua(kind = "Method", output(proxy))] - fn row(&self, index: usize) -> bevy::math::DVec3; + #[lua()] + fn row( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if, and only if, all elements are finite. /// If any element is either `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns the transpose of `self`. - #[lua(kind = "Method", output(proxy))] - fn transpose(&self) -> bevy::math::DMat3; + #[lua()] + fn transpose( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the determinant of `self`. - #[lua(kind = "Method")] - fn determinant(&self) -> f64; + #[lua()] + fn determinant(_self: LuaReflectRefProxy) -> f64; "#, r#" @@ -18871,8 +19976,10 @@ struct DMat2 { /// # Panics /// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::DMat3; + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -18882,8 +19989,11 @@ struct DMat2 { /// # Panics /// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn transform_point2(&self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn transform_point2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -18893,50 +20003,71 @@ struct DMat2 { /// # Panics /// Will panic if the 2nd row of `self` is not `(0, 0, 1)` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn transform_vector2(&self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn transform_vector2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms a 3D vector. - #[lua(kind = "Method", output(proxy))] - fn mul_vec3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn mul_vec3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies two 3x3 matrices. - #[lua(kind = "Method", output(proxy))] - fn mul_mat3(&self, #[proxy] rhs: &glam::DMat3) -> bevy::math::DMat3; + #[lua()] + fn mul_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Adds two 3x3 matrices. - #[lua(kind = "Method", output(proxy))] - fn add_mat3(&self, #[proxy] rhs: &glam::DMat3) -> bevy::math::DMat3; + #[lua()] + fn add_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Subtracts two 3x3 matrices. - #[lua(kind = "Method", output(proxy))] - fn sub_mat3(&self, #[proxy] rhs: &glam::DMat3) -> bevy::math::DMat3; + #[lua()] + fn sub_mat3( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies a 3x3 matrix by a scalar. - #[lua(kind = "Method", output(proxy))] - fn mul_scalar(&self, rhs: f64) -> bevy::math::DMat3; + #[lua()] + fn mul_scalar( + _self: LuaReflectRefProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" /// Divides a 3x3 matrix by a scalar. - #[lua(kind = "Method", output(proxy))] - fn div_scalar(&self, rhs: f64) -> bevy::math::DMat3; + #[lua()] + fn div_scalar( + _self: LuaReflectRefProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -18948,139 +20079,128 @@ struct DMat2 { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::DMat3, max_abs_diff: f64) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; "#, r#" /// Takes the absolute value of each element in `self` - #[lua(kind = "Method", output(proxy))] - fn abs(&self) -> bevy::math::DMat3; + #[lua()] + fn abs( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(kind = "Method", output(proxy))] - fn as_mat3(&self) -> bevy::math::Mat3; + #[lua()] + fn as_mat3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DMat3) -> bevy::math::DMat3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f64) -> bevy::math::DMat3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(LuaDVec3::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) +#[lua(metamethod="Index")] +fn index(_self: LuaIdentityProxy, idx: usize) -> LuaIdentityProxy { + let mut curr_ref = _self.0.clone(); + let def_ref = bevy_mod_scripting_core::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if let Some(ret) = ref_.try_as_reflect_mut().map(|ret| ret.downcast_mut::()).flatten(){ + Ok(ret.col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push(bevy_mod_scripting_core::bindings::ReflectionPathElem::new_deferred(def_ref)); + LuaDVec3(curr_ref) } "#] )] -struct DMat3 { - #[lua(output(proxy))] +pub struct DMat3 { x_axis: bevy::math::DVec3, - #[lua(output(proxy))] y_axis: bevy::math::DVec3, - #[lua(output(proxy))] z_axis: bevy::math::DVec3, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::DMat4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::DMat4) -> bevy::math::DMat4; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a 4x4 matrix from four column vectors. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_cols( - #[proxy] - x_axis: bevy::math::DVec4, - #[proxy] - y_axis: bevy::math::DVec4, - #[proxy] - z_axis: bevy::math::DVec4, - #[proxy] - w_axis: bevy::math::DVec4, - ) -> bevy::math::DMat4; + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + w_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a `[f64; 16]` array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f64; 16]; + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f64; 16]; "#, r#" /// Creates a `[[f64; 4]; 4]` 4D array storing data in column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f64; 4]; 4]; + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f64; 4]; 4]; "#, r#" /// Creates a 4x4 matrix with its diagonal set to `diagonal` and all other entries set to 0. - #[lua(kind = "Function", output(proxy))] - fn from_diagonal(#[proxy] diagonal: bevy::math::DVec4) -> bevy::math::DMat4; + #[lua()] + fn from_diagonal( + diagonal: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19091,15 +20211,12 @@ struct DMat3 { /// # Panics /// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_scale_rotation_translation( - #[proxy] - scale: bevy::math::DVec3, - #[proxy] - rotation: bevy::math::DQuat, - #[proxy] - translation: bevy::math::DVec3, - ) -> bevy::math::DMat4; + scale: LuaReflectValProxy, + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19109,13 +20226,11 @@ struct DMat3 { /// # Panics /// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_rotation_translation( - #[proxy] - rotation: bevy::math::DQuat, - #[proxy] - translation: bevy::math::DVec3, - ) -> bevy::math::DMat4; + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19125,8 +20240,10 @@ struct DMat3 { /// # Panics /// Will panic if `rotation` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_quat(#[proxy] rotation: bevy::math::DQuat) -> bevy::math::DMat4; + #[lua()] + fn from_quat( + rotation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19135,8 +20252,10 @@ struct DMat3 { /// The resulting matrix can be used to transform 3D points and vectors. See /// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] m: bevy::math::DMat3) -> bevy::math::DMat4; + #[lua()] + fn from_mat3( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19144,8 +20263,10 @@ struct DMat3 { /// The resulting matrix can be used to transform 3D points and vectors. See /// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::DVec3) -> bevy::math::DMat4; + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19156,12 +20277,11 @@ struct DMat3 { /// # Panics /// Will panic if `axis` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_axis_angle( - #[proxy] - axis: bevy::math::DVec3, + axis: LuaReflectValProxy, angle: f64, - ) -> bevy::math::DMat4; + ) -> LuaReflectValProxy; "#, r#" @@ -19170,14 +20290,13 @@ struct DMat3 { /// The resulting matrix can be used to transform 3D points and vectors. See /// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_euler( - #[proxy] - order: bevy::math::EulerRot, + order: LuaReflectValProxy, a: f64, b: f64, c: f64, - ) -> bevy::math::DMat4; + ) -> LuaReflectValProxy; "#, r#" @@ -19188,8 +20307,11 @@ struct DMat3 { /// Will panic if any column of the upper 3x3 rotation matrix is not normalized when /// `glam_assert` is enabled. - #[lua(kind = "Method")] - fn to_euler(&self, #[proxy] order: bevy::math::EulerRot) -> (f64, f64, f64); + #[lua()] + fn to_euler( + _self: LuaReflectRefProxy, + order: LuaReflectValProxy, + ) -> (f64, f64, f64); "#, r#" @@ -19198,8 +20320,8 @@ struct DMat3 { /// The resulting matrix can be used to transform 3D points and vectors. See /// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f64) -> bevy::math::DMat4; + #[lua()] + fn from_rotation_x(angle: f64) -> LuaReflectValProxy; "#, r#" @@ -19208,8 +20330,8 @@ struct DMat3 { /// The resulting matrix can be used to transform 3D points and vectors. See /// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f64) -> bevy::math::DMat4; + #[lua()] + fn from_rotation_y(angle: f64) -> LuaReflectValProxy; "#, r#" @@ -19218,8 +20340,8 @@ struct DMat3 { /// The resulting matrix can be used to transform 3D points and vectors. See /// [`Self::transform_point3()`] and [`Self::transform_vector3()`]. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f64) -> bevy::math::DMat4; + #[lua()] + fn from_rotation_z(angle: f64) -> LuaReflectValProxy; "#, r#" @@ -19229,8 +20351,10 @@ struct DMat3 { /// # Panics /// Will panic if all elements of `scale` are zero when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::DVec3) -> bevy::math::DMat4; + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19238,8 +20362,11 @@ struct DMat3 { /// # Panics /// Panics if `index` is greater than 3. - #[lua(kind = "Method", output(proxy))] - fn col(&self, index: usize) -> bevy::math::DVec4; + #[lua()] + fn col( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; "#, r#" @@ -19247,37 +20374,42 @@ struct DMat3 { /// # Panics /// Panics if `index` is greater than 3. - #[lua(kind = "Method", output(proxy))] - fn row(&self, index: usize) -> bevy::math::DVec4; + #[lua()] + fn row( + _self: LuaReflectRefProxy, + index: usize, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if, and only if, all elements are finite. /// If any element is either `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns the transpose of `self`. - #[lua(kind = "Method", output(proxy))] - fn transpose(&self) -> bevy::math::DMat4; + #[lua()] + fn transpose( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the determinant of `self`. - #[lua(kind = "Method")] - fn determinant(&self) -> f64; + #[lua()] + fn determinant(_self: LuaReflectRefProxy) -> f64; "#, r#" @@ -19286,8 +20418,10 @@ struct DMat3 { /// # Panics /// Will panic if the determinant of `self` is zero when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::DMat4; + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19295,15 +20429,12 @@ struct DMat3 { /// direction. /// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_to_lh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - dir: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DMat4; + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19311,15 +20442,12 @@ struct DMat3 { /// direction. /// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_to_rh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - dir: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DMat4; + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19329,15 +20457,12 @@ struct DMat3 { /// # Panics /// Will panic if `up` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_at_lh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - center: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DMat4; + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19347,15 +20472,12 @@ struct DMat3 { /// # Panics /// Will panic if `up` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_at_rh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - center: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DMat4; + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19364,13 +20486,13 @@ struct DMat3 { /// This is the same as the OpenGL `gluPerspective` function. /// See - #[lua(kind = "Function", output(proxy))] + #[lua()] fn perspective_rh_gl( fov_y_radians: f64, aspect_ratio: f64, z_near: f64, z_far: f64, - ) -> bevy::math::DMat4; + ) -> LuaReflectValProxy; "#, r#" @@ -19380,13 +20502,13 @@ struct DMat3 { /// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is /// enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn perspective_lh( fov_y_radians: f64, aspect_ratio: f64, z_near: f64, z_far: f64, - ) -> bevy::math::DMat4; + ) -> LuaReflectValProxy; "#, r#" @@ -19396,13 +20518,13 @@ struct DMat3 { /// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is /// enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn perspective_rh( fov_y_radians: f64, aspect_ratio: f64, z_near: f64, z_far: f64, - ) -> bevy::math::DMat4; + ) -> LuaReflectValProxy; "#, r#" @@ -19413,12 +20535,12 @@ struct DMat3 { /// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is /// enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn perspective_infinite_lh( fov_y_radians: f64, aspect_ratio: f64, z_near: f64, - ) -> bevy::math::DMat4; + ) -> LuaReflectValProxy; "#, r#" @@ -19427,12 +20549,12 @@ struct DMat3 { /// # Panics /// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn perspective_infinite_reverse_lh( fov_y_radians: f64, aspect_ratio: f64, z_near: f64, - ) -> bevy::math::DMat4; + ) -> LuaReflectValProxy; "#, r#" @@ -19443,12 +20565,12 @@ struct DMat3 { /// Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is /// enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn perspective_infinite_rh( fov_y_radians: f64, aspect_ratio: f64, z_near: f64, - ) -> bevy::math::DMat4; + ) -> LuaReflectValProxy; "#, r#" @@ -19457,12 +20579,12 @@ struct DMat3 { /// # Panics /// Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn perspective_infinite_reverse_rh( fov_y_radians: f64, aspect_ratio: f64, z_near: f64, - ) -> bevy::math::DMat4; + ) -> LuaReflectValProxy; "#, r#" @@ -19472,7 +20594,7 @@ struct DMat3 { /// /// Useful to map a right-handed coordinate system to the normalized device coordinates that OpenGL expects. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn orthographic_rh_gl( left: f64, right: f64, @@ -19480,14 +20602,14 @@ struct DMat3 { top: f64, near: f64, far: f64, - ) -> bevy::math::DMat4; + ) -> LuaReflectValProxy; "#, r#" /// Creates a left-handed orthographic projection matrix with `[0,1]` depth range. /// Useful to map a left-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn orthographic_lh( left: f64, right: f64, @@ -19495,14 +20617,14 @@ struct DMat3 { top: f64, near: f64, far: f64, - ) -> bevy::math::DMat4; + ) -> LuaReflectValProxy; "#, r#" /// Creates a right-handed orthographic projection matrix with `[0,1]` depth range. /// Useful to map a right-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn orthographic_rh( left: f64, right: f64, @@ -19510,7 +20632,7 @@ struct DMat3 { top: f64, near: f64, far: f64, - ) -> bevy::math::DMat4; + ) -> LuaReflectValProxy; "#, r#" @@ -19519,8 +20641,11 @@ struct DMat3 { /// The perspective divide is performed meaning the resulting 3D vector is divided by `w`. /// This method assumes that `self` contains a projective transform. - #[lua(kind = "Method", output(proxy))] - fn project_point3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn project_point3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19533,8 +20658,11 @@ struct DMat3 { /// # Panics /// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn transform_point3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn transform_point3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19545,50 +20673,71 @@ struct DMat3 { /// # Panics /// Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn transform_vector3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn transform_vector3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms a 4D vector. - #[lua(kind = "Method", output(proxy))] - fn mul_vec4(&self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua()] + fn mul_vec4( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies two 4x4 matrices. - #[lua(kind = "Method", output(proxy))] - fn mul_mat4(&self, #[proxy] rhs: &glam::DMat4) -> bevy::math::DMat4; + #[lua()] + fn mul_mat4( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Adds two 4x4 matrices. - #[lua(kind = "Method", output(proxy))] - fn add_mat4(&self, #[proxy] rhs: &glam::DMat4) -> bevy::math::DMat4; + #[lua()] + fn add_mat4( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Subtracts two 4x4 matrices. - #[lua(kind = "Method", output(proxy))] - fn sub_mat4(&self, #[proxy] rhs: &glam::DMat4) -> bevy::math::DMat4; + #[lua()] + fn sub_mat4( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies a 4x4 matrix by a scalar. - #[lua(kind = "Method", output(proxy))] - fn mul_scalar(&self, rhs: f64) -> bevy::math::DMat4; + #[lua()] + fn mul_scalar( + _self: LuaReflectRefProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" /// Divides a 4x4 matrix by a scalar. - #[lua(kind = "Method", output(proxy))] - fn div_scalar(&self, rhs: f64) -> bevy::math::DMat4; + #[lua()] + fn div_scalar( + _self: LuaReflectRefProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -19600,192 +20749,162 @@ struct DMat3 { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::DMat4, max_abs_diff: f64) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; "#, r#" /// Takes the absolute value of each element in `self` - #[lua(kind = "Method", output(proxy))] - fn abs(&self) -> bevy::math::DMat4; + #[lua()] + fn abs( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(kind = "Method", output(proxy))] - fn as_mat4(&self) -> bevy::math::Mat4; + #[lua()] + fn as_mat4( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DMat4; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::DMat4; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::DMat4) -> bevy::math::DMat4; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DAffine3) -> bevy::math::DMat4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DMat4) -> bevy::math::DMat4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f64) -> bevy::math::DMat4; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::DMat4) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f64) -> bevy::math::DMat4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DVec4) -> bevy::math::DVec4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#, r#" -#[lua(kind = "MetaMethod", raw, metamethod="Index")] -fn index(&self, ctx : &Lua, idx: crate::lua::util::LuaIndex) -> Result { - Ok(LuaDVec4::new_ref( - self.reflect_ref(ctx.get_world()?).sub_ref(bevy_script_api::ReflectionPathElement::SubReflection{ - label:"col", - get: std::sync::Arc::new(|ref_| Err(bevy_script_api::error::ReflectionError::InsufficientProvenance{ - path: "".to_owned(), - msg: "Cannot get column of matrix with immutable reference".to_owned() - })), - get_mut: std::sync::Arc::new(move |ref_| { - if ref_.is::(){ - Ok(ref_.downcast_mut::() - .unwrap() - .col_mut(*idx)) - } else { - Err(bevy_script_api::error::ReflectionError::CannotDowncast{from: ref_.get_represented_type_info().unwrap().type_path().into(), to:"Mat3".into()}) - } - }) - }) - ) - ) +#[lua(metamethod="Index")] +fn index(_self: LuaIdentityProxy, idx: usize) -> LuaIdentityProxy { + let mut curr_ref = _self.0.clone(); + let def_ref = bevy_mod_scripting_core::bindings::DeferredReflection{ + get: std::sync::Arc::new(|ref_| Err(bevy::reflect::ReflectPathError::InvalidDowncast)), + get_mut: std::sync::Arc::new(move |ref_| { + if let Some(ret) = ref_.try_as_reflect_mut().map(|ret| ret.downcast_mut::()).flatten(){ + Ok(ret.col_mut(idx - 1)) + } else { + Err(bevy::reflect::ReflectPathError::InvalidDowncast) + } + }) + }; + curr_ref.reflect_path.push(bevy_mod_scripting_core::bindings::ReflectionPathElem::new_deferred(def_ref)); + LuaDVec4(curr_ref) } "#] )] -struct DMat4 { - #[lua(output(proxy))] +pub struct DMat4 { x_axis: bevy::math::DVec4, - #[lua(output(proxy))] y_axis: bevy::math::DVec4, - #[lua(output(proxy))] z_axis: bevy::math::DVec4, - #[lua(output(proxy))] w_axis: bevy::math::DVec4, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Affine2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates an affine transform from three column vectors. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_cols( - #[proxy] - x_axis: bevy::math::Vec2, - #[proxy] - y_axis: bevy::math::Vec2, - #[proxy] - z_axis: bevy::math::Vec2, - ) -> bevy::math::Affine2; + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a `[f32; 6]` array storing data in column major order. - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f32; 6]; + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f32; 6]; "#, r#" @@ -19793,37 +20912,43 @@ struct DMat4 { /// column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f32; 2]; 3]; + #[lua()] + fn to_cols_array_2d(_self: LuaReflectRefProxy) -> [[f32; 2]; 3]; "#, r#" /// Creates an affine transform that changes scale. /// Note that if any scale is zero the transform will be non-invertible. - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::Vec2) -> bevy::math::Affine2; + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform from the given rotation `angle`. - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f32) -> bevy::math::Affine2; + #[lua()] + fn from_angle(angle: f32) -> LuaReflectValProxy; "#, r#" /// Creates an affine transformation from the given 2D `translation`. - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::Vec2) -> bevy::math::Affine2; + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) - #[lua(kind = "Function", output(proxy))] - fn from_mat2(#[proxy] matrix2: bevy::math::Mat2) -> bevy::math::Affine2; + #[lua()] + fn from_mat2( + matrix2: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19832,13 +20957,11 @@ struct DMat4 { /// Equivalent to /// `Affine2::from_translation(translation) * Affine2::from_mat2(mat2)` - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_mat2_translation( - #[proxy] - matrix2: bevy::math::Mat2, - #[proxy] - translation: bevy::math::Vec2, - ) -> bevy::math::Affine2; + matrix2: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19847,14 +20970,12 @@ struct DMat4 { /// Equivalent to `Affine2::from_translation(translation) * /// Affine2::from_angle(angle) * Affine2::from_scale(scale)` - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_scale_angle_translation( - #[proxy] - scale: bevy::math::Vec2, + scale: LuaReflectValProxy, angle: f32, - #[proxy] - translation: bevy::math::Vec2, - ) -> bevy::math::Affine2; + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19862,33 +20983,39 @@ struct DMat4 { /// `translation`. /// Equivalent to `Affine2::from_translation(translation) * Affine2::from_angle(angle)` - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_angle_translation( angle: f32, - #[proxy] - translation: bevy::math::Vec2, - ) -> bevy::math::Affine2; + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// The given `Mat3` must be an affine transform, - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] m: bevy::math::Mat3) -> bevy::math::Affine2; + #[lua()] + fn from_mat3( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// The given [`Mat3A`] must be an affine transform, - #[lua(kind = "Function", output(proxy))] - fn from_mat3a(#[proxy] m: bevy::math::Mat3A) -> bevy::math::Affine2; + #[lua()] + fn from_mat3a( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms the given 2D point, applying shear, scale, rotation and translation. - #[lua(kind = "Method", output(proxy))] - fn transform_point2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn transform_point2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19896,8 +21023,11 @@ struct DMat4 { /// translation). /// To also apply translation, use [`Self::transform_point2()`] instead. - #[lua(kind = "Method", output(proxy))] - fn transform_vector2(&self, #[proxy] rhs: bevy::math::Vec2) -> bevy::math::Vec2; + #[lua()] + fn transform_vector2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19905,15 +21035,15 @@ struct DMat4 { /// If any element is either `NaN`, positive or negative infinity, this will return /// `false`. - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; "#, r#" @@ -19925,147 +21055,127 @@ struct DMat4 { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Affine2, max_abs_diff: f32) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; "#, r#" /// Return the inverse of this transform. /// Note that if the transform is not invertible the result will be invalid. - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::Affine2; + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Affine2) -> bevy::math::Affine2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Affine2) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Mat3) -> bevy::math::Mat3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Mat3A) -> bevy::math::Mat3A; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Affine2; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Affine2 { - #[lua(output(proxy))] +pub struct Affine2 { matrix2: bevy::math::Mat2, - #[lua(output(proxy))] translation: bevy::math::Vec2, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::Affine3A", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Affine3A) -> bevy::math::Affine3A; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::Affine3A; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::Mat4) -> bevy::math::Mat4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform from three column vectors. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_cols( - #[proxy] - x_axis: bevy::math::Vec3A, - #[proxy] - y_axis: bevy::math::Vec3A, - #[proxy] - z_axis: bevy::math::Vec3A, - #[proxy] - w_axis: bevy::math::Vec3A, - ) -> bevy::math::Affine3A; + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + w_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a `[f32; 12]` array storing data in column major order. - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f32; 12]; + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f32; 12]; "#, r#" @@ -20073,74 +21183,83 @@ struct Affine2 { /// column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f32; 3]; 4]; + #[lua()] + fn to_cols_array_2d( + _self: LuaReflectRefProxy, + ) -> [[f32; 3]; 4]; "#, r#" /// Creates an affine transform that changes scale. /// Note that if any scale is zero the transform will be non-invertible. - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::Vec3) -> bevy::math::Affine3A; + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform from the given `rotation` quaternion. - #[lua(kind = "Function", output(proxy))] - fn from_quat(#[proxy] rotation: bevy::math::Quat) -> bevy::math::Affine3A; + #[lua()] + fn from_quat( + rotation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform containing a 3D rotation around a normalized /// rotation `axis` of `angle` (in radians). - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_axis_angle( - #[proxy] - axis: bevy::math::Vec3, + axis: LuaReflectValProxy, angle: f32, - ) -> bevy::math::Affine3A; + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform containing a 3D rotation around the x axis of /// `angle` (in radians). - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f32) -> bevy::math::Affine3A; + #[lua()] + fn from_rotation_x(angle: f32) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform containing a 3D rotation around the y axis of /// `angle` (in radians). - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f32) -> bevy::math::Affine3A; + #[lua()] + fn from_rotation_y(angle: f32) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform containing a 3D rotation around the z axis of /// `angle` (in radians). - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f32) -> bevy::math::Affine3A; + #[lua()] + fn from_rotation_z(angle: f32) -> LuaReflectValProxy; "#, r#" /// Creates an affine transformation from the given 3D `translation`. - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::Vec3) -> bevy::math::Affine3A; + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform from a 3x3 matrix (expressing scale, shear and /// rotation) - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] mat3: bevy::math::Mat3) -> bevy::math::Affine3A; + #[lua()] + fn from_mat3( + mat3: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20148,13 +21267,11 @@ struct Affine2 { /// and a translation vector. /// Equivalent to `Affine3A::from_translation(translation) * Affine3A::from_mat3(mat3)` - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_mat3_translation( - #[proxy] - mat3: bevy::math::Mat3, - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::math::Affine3A; + mat3: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20163,36 +21280,33 @@ struct Affine2 { /// Equivalent to `Affine3A::from_translation(translation) * /// Affine3A::from_quat(rotation) * Affine3A::from_scale(scale)` - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_scale_rotation_translation( - #[proxy] - scale: bevy::math::Vec3, - #[proxy] - rotation: bevy::math::Quat, - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::math::Affine3A; + scale: LuaReflectValProxy, + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform from the given 3D `rotation` and `translation`. /// Equivalent to `Affine3A::from_translation(translation) * Affine3A::from_quat(rotation)` - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_rotation_translation( - #[proxy] - rotation: bevy::math::Quat, - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::math::Affine3A; + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// The given `Mat4` must be an affine transform, /// i.e. contain no perspective transform. - #[lua(kind = "Function", output(proxy))] - fn from_mat4(#[proxy] m: bevy::math::Mat4) -> bevy::math::Affine3A; + #[lua()] + fn from_mat4( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20200,15 +21314,12 @@ struct Affine2 { /// direction. /// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_to_lh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - dir: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Affine3A; + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20216,15 +21327,12 @@ struct Affine2 { /// direction. /// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_to_rh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - dir: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Affine3A; + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20234,15 +21342,12 @@ struct Affine2 { /// # Panics /// Will panic if `up` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_at_lh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - center: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Affine3A; + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20252,22 +21357,22 @@ struct Affine2 { /// # Panics /// Will panic if `up` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_at_rh( - #[proxy] - eye: bevy::math::Vec3, - #[proxy] - center: bevy::math::Vec3, - #[proxy] - up: bevy::math::Vec3, - ) -> bevy::math::Affine3A; + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms the given 3D points, applying shear, scale, rotation and translation. - #[lua(kind = "Method", output(proxy))] - fn transform_point3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn transform_point3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20275,15 +21380,21 @@ struct Affine2 { /// translation). /// To also apply translation, use [`Self::transform_point3()`] instead. - #[lua(kind = "Method", output(proxy))] - fn transform_vector3(&self, #[proxy] rhs: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua()] + fn transform_vector3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms the given [`Vec3A`], applying shear, scale, rotation and translation. - #[lua(kind = "Method", output(proxy))] - fn transform_point3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn transform_point3a( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20291,8 +21402,11 @@ struct Affine2 { /// translation). /// To also apply translation, use [`Self::transform_point3a()`] instead. - #[lua(kind = "Method", output(proxy))] - fn transform_vector3a(&self, #[proxy] rhs: bevy::math::Vec3A) -> bevy::math::Vec3A; + #[lua()] + fn transform_vector3a( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20300,15 +21414,15 @@ struct Affine2 { /// If any element is either `NaN`, positive or negative infinity, this will return /// `false`. - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; "#, r#" @@ -20320,110 +21434,100 @@ struct Affine2 { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::Affine3A, max_abs_diff: f32) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f32, + ) -> bool; "#, r#" /// Return the inverse of this transform. /// Note that if the transform is not invertible the result will be invalid. - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::Affine3A; + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::Affine3A) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Affine3A { - #[lua(output(proxy))] +pub struct Affine3A { matrix3: bevy::math::Mat3A, - #[lua(output(proxy))] translation: bevy::math::Vec3A, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::DAffine2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DMat3) -> bevy::math::DMat3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DAffine2) -> bevy::math::DAffine2; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::DAffine2) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DAffine2; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform from three column vectors. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_cols( - #[proxy] - x_axis: bevy::math::DVec2, - #[proxy] - y_axis: bevy::math::DVec2, - #[proxy] - z_axis: bevy::math::DVec2, - ) -> bevy::math::DAffine2; + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a `[f64; 6]` array storing data in column major order. - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f64; 6]; + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f64; 6]; "#, r#" @@ -20431,37 +21535,45 @@ struct Affine3A { /// column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f64; 2]; 3]; + #[lua()] + fn to_cols_array_2d( + _self: LuaReflectRefProxy, + ) -> [[f64; 2]; 3]; "#, r#" /// Creates an affine transform that changes scale. /// Note that if any scale is zero the transform will be non-invertible. - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::DVec2) -> bevy::math::DAffine2; + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform from the given rotation `angle`. - #[lua(kind = "Function", output(proxy))] - fn from_angle(angle: f64) -> bevy::math::DAffine2; + #[lua()] + fn from_angle(angle: f64) -> LuaReflectValProxy; "#, r#" /// Creates an affine transformation from the given 2D `translation`. - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::DVec2) -> bevy::math::DAffine2; + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) - #[lua(kind = "Function", output(proxy))] - fn from_mat2(#[proxy] matrix2: bevy::math::DMat2) -> bevy::math::DAffine2; + #[lua()] + fn from_mat2( + matrix2: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20470,13 +21582,11 @@ struct Affine3A { /// Equivalent to /// `DAffine2::from_translation(translation) * DAffine2::from_mat2(mat2)` - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_mat2_translation( - #[proxy] - matrix2: bevy::math::DMat2, - #[proxy] - translation: bevy::math::DVec2, - ) -> bevy::math::DAffine2; + matrix2: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20485,14 +21595,12 @@ struct Affine3A { /// Equivalent to `DAffine2::from_translation(translation) * /// DAffine2::from_angle(angle) * DAffine2::from_scale(scale)` - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_scale_angle_translation( - #[proxy] - scale: bevy::math::DVec2, + scale: LuaReflectValProxy, angle: f64, - #[proxy] - translation: bevy::math::DVec2, - ) -> bevy::math::DAffine2; + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20500,26 +21608,30 @@ struct Affine3A { /// `translation`. /// Equivalent to `DAffine2::from_translation(translation) * DAffine2::from_angle(angle)` - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_angle_translation( angle: f64, - #[proxy] - translation: bevy::math::DVec2, - ) -> bevy::math::DAffine2; + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// The given `DMat3` must be an affine transform, - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] m: bevy::math::DMat3) -> bevy::math::DAffine2; + #[lua()] + fn from_mat3( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms the given 2D point, applying shear, scale, rotation and translation. - #[lua(kind = "Method", output(proxy))] - fn transform_point2(&self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn transform_point2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20527,8 +21639,11 @@ struct Affine3A { /// translation). /// To also apply translation, use [`Self::transform_point2()`] instead. - #[lua(kind = "Method", output(proxy))] - fn transform_vector2(&self, #[proxy] rhs: bevy::math::DVec2) -> bevy::math::DVec2; + #[lua()] + fn transform_vector2( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20536,15 +21651,15 @@ struct Affine3A { /// If any element is either `NaN`, positive or negative infinity, this will return /// `false`. - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; "#, r#" @@ -20556,56 +21671,57 @@ struct Affine3A { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::DAffine2, max_abs_diff: f64) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; "#, r#" /// Return the inverse of this transform. /// Note that if the transform is not invertible the result will be invalid. - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::DAffine2; + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct DAffine2 { - #[lua(output(proxy))] +pub struct DAffine2 { matrix2: bevy::math::DMat2, - #[lua(output(proxy))] translation: bevy::math::DVec2, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::DAffine3", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates an affine transform from three column vectors. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_cols( - #[proxy] - x_axis: bevy::math::DVec3, - #[proxy] - y_axis: bevy::math::DVec3, - #[proxy] - z_axis: bevy::math::DVec3, - #[proxy] - w_axis: bevy::math::DVec3, - ) -> bevy::math::DAffine3; + x_axis: LuaReflectValProxy, + y_axis: LuaReflectValProxy, + z_axis: LuaReflectValProxy, + w_axis: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a `[f64; 12]` array storing data in column major order. - #[lua(kind = "Method")] - fn to_cols_array(&self) -> [f64; 12]; + #[lua()] + fn to_cols_array(_self: LuaReflectRefProxy) -> [f64; 12]; "#, r#" @@ -20613,74 +21729,83 @@ struct DAffine2 { /// column major order. /// If you require data in row major order `transpose` the matrix first. - #[lua(kind = "Method")] - fn to_cols_array_2d(&self) -> [[f64; 3]; 4]; + #[lua()] + fn to_cols_array_2d( + _self: LuaReflectRefProxy, + ) -> [[f64; 3]; 4]; "#, r#" /// Creates an affine transform that changes scale. /// Note that if any scale is zero the transform will be non-invertible. - #[lua(kind = "Function", output(proxy))] - fn from_scale(#[proxy] scale: bevy::math::DVec3) -> bevy::math::DAffine3; + #[lua()] + fn from_scale( + scale: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform from the given `rotation` quaternion. - #[lua(kind = "Function", output(proxy))] - fn from_quat(#[proxy] rotation: bevy::math::DQuat) -> bevy::math::DAffine3; + #[lua()] + fn from_quat( + rotation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform containing a 3D rotation around a normalized /// rotation `axis` of `angle` (in radians). - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_axis_angle( - #[proxy] - axis: bevy::math::DVec3, + axis: LuaReflectValProxy, angle: f64, - ) -> bevy::math::DAffine3; + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform containing a 3D rotation around the x axis of /// `angle` (in radians). - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f64) -> bevy::math::DAffine3; + #[lua()] + fn from_rotation_x(angle: f64) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform containing a 3D rotation around the y axis of /// `angle` (in radians). - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f64) -> bevy::math::DAffine3; + #[lua()] + fn from_rotation_y(angle: f64) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform containing a 3D rotation around the z axis of /// `angle` (in radians). - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f64) -> bevy::math::DAffine3; + #[lua()] + fn from_rotation_z(angle: f64) -> LuaReflectValProxy; "#, r#" /// Creates an affine transformation from the given 3D `translation`. - #[lua(kind = "Function", output(proxy))] - fn from_translation(#[proxy] translation: bevy::math::DVec3) -> bevy::math::DAffine3; + #[lua()] + fn from_translation( + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform from a 3x3 matrix (expressing scale, shear and /// rotation) - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] mat3: bevy::math::DMat3) -> bevy::math::DAffine3; + #[lua()] + fn from_mat3( + mat3: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20688,13 +21813,11 @@ struct DAffine2 { /// and a translation vector. /// Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_mat3(mat3)` - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_mat3_translation( - #[proxy] - mat3: bevy::math::DMat3, - #[proxy] - translation: bevy::math::DVec3, - ) -> bevy::math::DAffine3; + mat3: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20703,36 +21826,33 @@ struct DAffine2 { /// Equivalent to `DAffine3::from_translation(translation) * /// DAffine3::from_quat(rotation) * DAffine3::from_scale(scale)` - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_scale_rotation_translation( - #[proxy] - scale: bevy::math::DVec3, - #[proxy] - rotation: bevy::math::DQuat, - #[proxy] - translation: bevy::math::DVec3, - ) -> bevy::math::DAffine3; + scale: LuaReflectValProxy, + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates an affine transform from the given 3D `rotation` and `translation`. /// Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_quat(rotation)` - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_rotation_translation( - #[proxy] - rotation: bevy::math::DQuat, - #[proxy] - translation: bevy::math::DVec3, - ) -> bevy::math::DAffine3; + rotation: LuaReflectValProxy, + translation: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// The given `DMat4` must be an affine transform, /// i.e. contain no perspective transform. - #[lua(kind = "Function", output(proxy))] - fn from_mat4(#[proxy] m: bevy::math::DMat4) -> bevy::math::DAffine3; + #[lua()] + fn from_mat4( + m: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20740,15 +21860,12 @@ struct DAffine2 { /// direction. /// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_to_lh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - dir: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DAffine3; + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20756,15 +21873,12 @@ struct DAffine2 { /// direction. /// For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_to_rh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - dir: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DAffine3; + eye: LuaReflectValProxy, + dir: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20774,15 +21888,12 @@ struct DAffine2 { /// # Panics /// Will panic if `up` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_at_lh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - center: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DAffine3; + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20792,22 +21903,22 @@ struct DAffine2 { /// # Panics /// Will panic if `up` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn look_at_rh( - #[proxy] - eye: bevy::math::DVec3, - #[proxy] - center: bevy::math::DVec3, - #[proxy] - up: bevy::math::DVec3, - ) -> bevy::math::DAffine3; + eye: LuaReflectValProxy, + center: LuaReflectValProxy, + up: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Transforms the given 3D points, applying shear, scale, rotation and translation. - #[lua(kind = "Method", output(proxy))] - fn transform_point3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn transform_point3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20815,8 +21926,11 @@ struct DAffine2 { /// translation). /// To also apply translation, use [`Self::transform_point3()`] instead. - #[lua(kind = "Method", output(proxy))] - fn transform_vector3(&self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn transform_vector3( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20824,15 +21938,15 @@ struct DAffine2 { /// If any element is either `NaN`, positive or negative infinity, this will return /// `false`. - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns `true` if any elements are `NaN`. - #[lua(kind = "Method")] - fn is_nan(&self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectRefProxy) -> bool; "#, r#" @@ -20844,118 +21958,103 @@ struct DAffine2 { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(&self, #[proxy] rhs: bevy::math::DAffine3, max_abs_diff: f64) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; "#, r#" /// Return the inverse of this transform. /// Note that if the transform is not invertible the result will be invalid. - #[lua(kind = "Method", output(proxy))] - fn inverse(&self) -> bevy::math::DAffine3; + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::DAffine3) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DAffine3) -> bevy::math::DAffine3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DMat4) -> bevy::math::DMat4; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DAffine3; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct DAffine3 { - #[lua(output(proxy))] +pub struct DAffine3 { matrix3: bevy::math::DMat3, - #[lua(output(proxy))] translation: bevy::math::DVec3, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::DQuat", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Subtracts the `rhs` quaternion from `self`. /// The difference is not guaranteed to be normalized. - #[lua( - as_trait = "std::ops::Sub", - kind = "MetaFunction", - output(proxy), - composite = "sub", - metamethod = "Sub", - )] - fn sub(self, #[proxy] rhs: bevy::math::DQuat) -> bevy::math::DQuat; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Neg", - kind = "MetaFunction", - output(proxy), - composite = "neg", - metamethod = "Unm", - )] - fn neg(self) -> bevy::math::DQuat; + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies a quaternion by a scalar value. /// The product is not guaranteed to be normalized. - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, rhs: f64) -> bevy::math::DQuat; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -20964,14 +22063,11 @@ struct DAffine3 { /// Note that addition is not the same as combining the rotations represented by the /// two quaternions! That corresponds to multiplication. - #[lua( - as_trait = "std::ops::Add", - kind = "MetaFunction", - output(proxy), - composite = "add", - metamethod = "Add", - )] - fn add(self, #[proxy] rhs: bevy::math::DQuat) -> bevy::math::DQuat; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -20979,38 +22075,30 @@ struct DAffine3 { /// # Panics /// Will panic if `self` is not normalized when `glam_assert` is enabled. - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::DQuat; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Divides a quaternion by a scalar value. /// The quotient is not guaranteed to be normalized. - #[lua( - as_trait = "std::ops::Div", - kind = "MetaFunction", - output(proxy), - composite = "div", - metamethod = "Div", - )] - fn div(self, rhs: f64) -> bevy::math::DQuat; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -21021,25 +22109,20 @@ struct DAffine3 { /// # Panics /// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] rhs: bevy::math::DQuat) -> bevy::math::DQuat; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::DQuat) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -21051,8 +22134,13 @@ struct DAffine3 { /// This function does not check if the input is normalized, it is up to the user to /// provide normalized input or to normalized the resulting quaternion. - #[lua(kind = "Function", output(proxy))] - fn from_xyzw(x: f64, y: f64, z: f64, w: f64) -> bevy::math::DQuat; + #[lua()] + fn from_xyzw( + x: f64, + y: f64, + z: f64, + w: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -21061,8 +22149,8 @@ struct DAffine3 { /// This function does not check if the input is normalized, it is up to the user to /// provide normalized input or to normalized the resulting quaternion. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [f64; 4]) -> bevy::math::DQuat; + #[lua()] + fn from_array(a: [f64; 4]) -> LuaReflectValProxy; "#, r#" @@ -21071,8 +22159,10 @@ struct DAffine3 { /// This function does not check if the input is normalized, it is up to the user to /// provide normalized input or to normalized the resulting quaternion. - #[lua(kind = "Function", output(proxy))] - fn from_vec4(#[proxy] v: bevy::math::DVec4) -> bevy::math::DQuat; + #[lua()] + fn from_vec4( + v: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -21081,54 +22171,54 @@ struct DAffine3 { /// # Panics /// Will panic if `axis` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_axis_angle( - #[proxy] - axis: bevy::math::DVec3, + axis: LuaReflectValProxy, angle: f64, - ) -> bevy::math::DQuat; + ) -> LuaReflectValProxy; "#, r#" /// Create a quaternion that rotates `v.length()` radians around `v.normalize()`. /// `from_scaled_axis(Vec3::ZERO)` results in the identity quaternion. - #[lua(kind = "Function", output(proxy))] - fn from_scaled_axis(#[proxy] v: bevy::math::DVec3) -> bevy::math::DQuat; + #[lua()] + fn from_scaled_axis( + v: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a quaternion from the `angle` (in radians) around the x axis. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_x(angle: f64) -> bevy::math::DQuat; + #[lua()] + fn from_rotation_x(angle: f64) -> LuaReflectValProxy; "#, r#" /// Creates a quaternion from the `angle` (in radians) around the y axis. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_y(angle: f64) -> bevy::math::DQuat; + #[lua()] + fn from_rotation_y(angle: f64) -> LuaReflectValProxy; "#, r#" /// Creates a quaternion from the `angle` (in radians) around the z axis. - #[lua(kind = "Function", output(proxy))] - fn from_rotation_z(angle: f64) -> bevy::math::DQuat; + #[lua()] + fn from_rotation_z(angle: f64) -> LuaReflectValProxy; "#, r#" /// Creates a quaternion from the given Euler rotation sequence and the angles (in radians). - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_euler( - #[proxy] - euler: bevy::math::EulerRot, + euler: LuaReflectValProxy, a: f64, b: f64, c: f64, - ) -> bevy::math::DQuat; + ) -> LuaReflectValProxy; "#, r#" @@ -21138,8 +22228,10 @@ struct DAffine3 { /// # Panics /// Will panic if any input matrix column is not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_mat3(#[proxy] mat: &glam::DMat3) -> bevy::math::DQuat; + #[lua()] + fn from_mat3( + mat: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -21150,8 +22242,10 @@ struct DAffine3 { /// Will panic if any column of the upper 3x3 rotation matrix is not normalized when /// `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] - fn from_mat4(#[proxy] mat: &glam::DMat4) -> bevy::math::DQuat; + #[lua()] + fn from_mat4( + mat: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -21164,13 +22258,11 @@ struct DAffine3 { /// # Panics /// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_rotation_arc( - #[proxy] - from: bevy::math::DVec3, - #[proxy] - to: bevy::math::DVec3, - ) -> bevy::math::DQuat; + from: LuaReflectValProxy, + to: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -21183,13 +22275,11 @@ struct DAffine3 { /// # Panics /// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_rotation_arc_colinear( - #[proxy] - from: bevy::math::DVec3, - #[proxy] - to: bevy::math::DVec3, - ) -> bevy::math::DQuat; + from: LuaReflectValProxy, + to: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -21202,49 +22292,56 @@ struct DAffine3 { /// # Panics /// Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_rotation_arc_2d( - #[proxy] - from: bevy::math::DVec2, - #[proxy] - to: bevy::math::DVec2, - ) -> bevy::math::DQuat; + from: LuaReflectValProxy, + to: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the rotation axis scaled by the rotation in radians. - #[lua(kind = "Method", output(proxy))] - fn to_scaled_axis(self) -> bevy::math::DVec3; + #[lua()] + fn to_scaled_axis( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the rotation angles for the given euler rotation sequence. - #[lua(kind = "Method")] - fn to_euler(self, #[proxy] order: bevy::math::EulerRot) -> (f64, f64, f64); + #[lua()] + fn to_euler( + _self: LuaReflectValProxy, + order: LuaReflectValProxy, + ) -> (f64, f64, f64); "#, r#" /// `[x, y, z, w]` - #[lua(kind = "Method")] - fn to_array(&self) -> [f64; 4]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [f64; 4]; "#, r#" /// Returns the vector part of the quaternion. - #[lua(kind = "Method", output(proxy))] - fn xyz(self) -> bevy::math::DVec3; + #[lua()] + fn xyz( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns the quaternion conjugate of `self`. For a unit quaternion the /// conjugate is also the inverse. - #[lua(kind = "Method", output(proxy))] - fn conjugate(self) -> bevy::math::DQuat; + #[lua()] + fn conjugate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -21255,23 +22352,28 @@ struct DAffine3 { /// # Panics /// Will panic if `self` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn inverse(self) -> bevy::math::DQuat; + #[lua()] + fn inverse( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Computes the dot product of `self` and `rhs`. The dot product is /// equal to the cosine of the angle between two quaternion rotations. - #[lua(kind = "Method")] - fn dot(self, #[proxy] rhs: bevy::math::DQuat) -> f64; + #[lua()] + fn dot( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" /// Computes the length of `self`. - #[lua(kind = "Method")] - fn length(self) -> f64; + #[lua()] + fn length(_self: LuaReflectValProxy) -> f64; "#, r#" @@ -21279,16 +22381,16 @@ struct DAffine3 { /// This is generally faster than `length()` as it avoids a square /// root operation. - #[lua(kind = "Method")] - fn length_squared(self) -> f64; + #[lua()] + fn length_squared(_self: LuaReflectValProxy) -> f64; "#, r#" /// Computes `1.0 / length()`. /// For valid results, `self` must _not_ be of length zero. - #[lua(kind = "Method")] - fn length_recip(self) -> f64; + #[lua()] + fn length_recip(_self: LuaReflectValProxy) -> f64; "#, r#" @@ -21297,37 +22399,39 @@ struct DAffine3 { /// Panics /// Will panic if `self` is zero length when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn normalize(self) -> bevy::math::DQuat; + #[lua()] + fn normalize( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" /// Returns `true` if, and only if, all elements are finite. /// If any element is either `NaN`, positive or negative infinity, this will return `false`. - #[lua(kind = "Method")] - fn is_finite(self) -> bool; + #[lua()] + fn is_finite(_self: LuaReflectValProxy) -> bool; "#, r#" /// Returns `true` if any elements are `NAN`. - #[lua(kind = "Method")] - fn is_nan(self) -> bool; + #[lua()] + fn is_nan(_self: LuaReflectValProxy) -> bool; "#, r#" /// Returns whether `self` of length `1.0` or not. /// Uses a precision threshold of `1e-6`. - #[lua(kind = "Method")] - fn is_normalized(self) -> bool; + #[lua()] + fn is_normalized(_self: LuaReflectValProxy) -> bool; "#, r#" - #[lua(kind = "Method")] - fn is_near_identity(self) -> bool; + #[lua()] + fn is_near_identity(_self: LuaReflectValProxy) -> bool; "#, r#" @@ -21337,8 +22441,11 @@ struct DAffine3 { /// # Panics /// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Method")] - fn angle_between(self, #[proxy] rhs: bevy::math::DQuat) -> f64; + #[lua()] + fn angle_between( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> f64; "#, r#" @@ -21350,13 +22457,12 @@ struct DAffine3 { /// # Panics /// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn rotate_towards( - &self, - #[proxy] - rhs: bevy::math::DQuat, + _self: LuaReflectRefProxy, + rhs: LuaReflectValProxy, max_angle: f64, - ) -> bevy::math::DQuat; + ) -> LuaReflectValProxy; "#, r#" @@ -21368,8 +22474,12 @@ struct DAffine3 { /// For more see /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). - #[lua(kind = "Method")] - fn abs_diff_eq(self, #[proxy] rhs: bevy::math::DQuat, max_abs_diff: f64) -> bool; + #[lua()] + fn abs_diff_eq( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + max_abs_diff: f64, + ) -> bool; "#, r#" @@ -21380,8 +22490,12 @@ struct DAffine3 { /// # Panics /// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn lerp(self, #[proxy] end: bevy::math::DQuat, s: f64) -> bevy::math::DQuat; + #[lua()] + fn lerp( + _self: LuaReflectValProxy, + end: LuaReflectValProxy, + s: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -21392,8 +22506,12 @@ struct DAffine3 { /// # Panics /// Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn slerp(self, #[proxy] end: bevy::math::DQuat, s: f64) -> bevy::math::DQuat; + #[lua()] + fn slerp( + _self: LuaReflectValProxy, + end: LuaReflectValProxy, + s: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -21401,8 +22519,11 @@ struct DAffine3 { /// # Panics /// Will panic if `self` is not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn mul_vec3(self, #[proxy] rhs: bevy::math::DVec3) -> bevy::math::DVec3; + #[lua()] + fn mul_vec3( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -21412,8 +22533,11 @@ struct DAffine3 { /// # Panics /// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - #[lua(kind = "Method", output(proxy))] - fn mul_quat(self, #[proxy] rhs: bevy::math::DQuat) -> bevy::math::DQuat; + #[lua()] + fn mul_quat( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -21424,91 +22548,95 @@ struct DAffine3 { /// Will panic if any input affine matrix column is not normalized when `glam_assert` is /// enabled. - #[lua(kind = "Function", output(proxy))] - fn from_affine3(#[proxy] a: &glam::DAffine3) -> bevy::math::DQuat; + #[lua()] + fn from_affine3( + a: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(kind = "Method", output(proxy))] - fn as_quat(self) -> bevy::math::Quat; + #[lua()] + fn as_quat( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct DQuat { +pub struct DQuat { x: f64, y: f64, z: f64, w: f64, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::EulerRot", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::EulerRot; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &glam::EulerRot) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct EulerRot {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct EulerRot {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::BVec3A", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Creates a new vector mask. - #[lua(kind = "Function", output(proxy))] - fn new(x: bool, y: bool, z: bool) -> bevy::math::BVec3A; + #[lua()] + fn new(x: bool, y: bool, z: bool) -> LuaReflectValProxy; "#, r#" /// Creates a vector mask with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: bool) -> bevy::math::BVec3A; + #[lua()] + fn splat(v: bool) -> LuaReflectValProxy; "#, r#" /// Creates a new vector mask from a bool array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [bool; 3]) -> bevy::math::BVec3A; + #[lua()] + fn from_array(a: [bool; 3]) -> LuaReflectValProxy; "#, r#" @@ -21516,102 +22644,101 @@ struct EulerRot {} /// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn bitmask(self) -> u32; + #[lua()] + fn bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns true if any of the elements are true, false otherwise. - #[lua(kind = "Method")] - fn any(self) -> bool; + #[lua()] + fn any(_self: LuaReflectValProxy) -> bool; "#, r#" /// Returns true if all the elements are true, false otherwise. - #[lua(kind = "Method")] - fn all(self) -> bool; + #[lua()] + fn all(_self: LuaReflectValProxy) -> bool; "#, r#" /// Tests the value at `index`. /// Panics if `index` is greater than 2. - #[lua(kind = "Method")] - fn test(&self, index: usize) -> bool; + #[lua()] + fn test(_self: LuaReflectRefProxy, index: usize) -> bool; "#, r#" /// Sets the element at `index`. /// Panics if `index` is greater than 2. - #[lua(kind = "MutatingMethod")] - fn set(&mut self, index: usize, value: bool) -> (); + #[lua()] + fn set( + _self: LuaReflectRefMutProxy, + index: usize, + value: bool, + ) -> (); "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::BVec3A) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::BVec3A; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct BVec3A(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct BVec3A(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::math::BVec4A", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> bevy::math::BVec4A; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new vector mask. - #[lua(kind = "Function", output(proxy))] - fn new(x: bool, y: bool, z: bool, w: bool) -> bevy::math::BVec4A; + #[lua()] + fn new(x: bool, y: bool, z: bool, w: bool) -> LuaReflectValProxy; "#, r#" /// Creates a vector mask with all elements set to `v`. - #[lua(kind = "Function", output(proxy))] - fn splat(v: bool) -> bevy::math::BVec4A; + #[lua()] + fn splat(v: bool) -> LuaReflectValProxy; "#, r#" /// Creates a new vector mask from a bool array. - #[lua(kind = "Function", output(proxy))] - fn from_array(a: [bool; 4]) -> bevy::math::BVec4A; + #[lua()] + fn from_array(a: [bool; 4]) -> LuaReflectValProxy; "#, r#" @@ -21619,124 +22746,124 @@ struct BVec3A(); /// A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. - #[lua(kind = "Method")] - fn bitmask(self) -> u32; + #[lua()] + fn bitmask(_self: LuaReflectValProxy) -> u32; "#, r#" /// Returns true if any of the elements are true, false otherwise. - #[lua(kind = "Method")] - fn any(self) -> bool; + #[lua()] + fn any(_self: LuaReflectValProxy) -> bool; "#, r#" /// Returns true if all the elements are true, false otherwise. - #[lua(kind = "Method")] - fn all(self) -> bool; + #[lua()] + fn all(_self: LuaReflectValProxy) -> bool; "#, r#" /// Tests the value at `index`. /// Panics if `index` is greater than 3. - #[lua(kind = "Method")] - fn test(&self, index: usize) -> bool; + #[lua()] + fn test(_self: LuaReflectRefProxy, index: usize) -> bool; "#, r#" /// Sets the element at `index`. /// Panics if `index` is greater than 3. - #[lua(kind = "MutatingMethod")] - fn set(&mut self, index: usize, value: bool) -> (); + #[lua()] + fn set( + _self: LuaReflectRefMutProxy, + index: usize, + value: bool, + ) -> (); "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] rhs: &glam::BVec4A) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct BVec4A(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct BVec4A(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "smol_str::SmolStr", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &smol_str::SmolStr) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> smol_str::SmolStr; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(kind = "Method")] - fn to_string(&self) -> std::string::String; + #[lua()] + fn to_string(_self: LuaReflectRefProxy) -> std::string::String; "#, r#" - #[lua(kind = "Method")] - fn len(&self) -> usize; + #[lua()] + fn len(_self: LuaReflectRefProxy) -> usize; "#, r#" - #[lua(kind = "Method")] - fn is_empty(&self) -> bool; + #[lua()] + fn is_empty(_self: LuaReflectRefProxy) -> bool; "#, r#" - #[lua(kind = "Method")] - fn is_heap_allocated(&self) -> bool; + #[lua()] + fn is_heap_allocated(_self: LuaReflectRefProxy) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct SmolStr(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct SmolStr(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "uuid::Uuid", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" @@ -21761,8 +22888,8 @@ struct SmolStr(); /// [`getrandom`]: https://crates.io/crates/getrandom /// [from_random_bytes]: struct.Builder.html#method.from_random_bytes - #[lua(kind = "Function", output(proxy))] - fn new_v4() -> uuid::Uuid; + #[lua()] + fn new_v4() -> LuaReflectValProxy; "#, r#" @@ -21782,8 +22909,8 @@ struct SmolStr(); /// # References /// * [Version Field in RFC 9562](https://www.ietf.org/rfc/rfc9562.html#section-4.2) - #[lua(kind = "Method")] - fn get_version_num(&self) -> usize; + #[lua()] + fn get_version_num(_self: LuaReflectRefProxy) -> usize; "#, r#" @@ -21802,8 +22929,8 @@ struct SmolStr(); /// # } /// ``` - #[lua(kind = "Method")] - fn as_u128(&self) -> u128; + #[lua()] + fn as_u128(_self: LuaReflectRefProxy) -> u128; "#, r#" @@ -21828,8 +22955,8 @@ struct SmolStr(); /// # } /// ``` - #[lua(kind = "Method")] - fn to_u128_le(&self) -> u128; + #[lua()] + fn to_u128_le(_self: LuaReflectRefProxy) -> u128; "#, r#" @@ -21850,8 +22977,8 @@ struct SmolStr(); /// # } /// ``` - #[lua(kind = "Method")] - fn as_u64_pair(&self) -> (u64, u64); + #[lua()] + fn as_u64_pair(_self: LuaReflectRefProxy) -> (u64, u64); "#, r#" @@ -21869,8 +22996,8 @@ struct SmolStr(); /// assert_eq!(bytes, uuid.into_bytes()); /// ``` - #[lua(kind = "Method")] - fn into_bytes(self) -> [u8; 16]; + #[lua()] + fn into_bytes(_self: LuaReflectValProxy) -> [u8; 16]; "#, r#" @@ -21894,22 +23021,22 @@ struct SmolStr(); /// # } /// ``` - #[lua(kind = "Method")] - fn to_bytes_le(&self) -> [u8; 16]; + #[lua()] + fn to_bytes_le(_self: LuaReflectRefProxy) -> [u8; 16]; "#, r#" /// Tests if the UUID is nil (all zeros). - #[lua(kind = "Method")] - fn is_nil(&self) -> bool; + #[lua()] + fn is_nil(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Tests if the UUID is max (all ones). - #[lua(kind = "Method")] - fn is_max(&self) -> bool; + #[lua()] + fn is_max(_self: LuaReflectRefProxy) -> bool; "#, r#" @@ -21934,7 +23061,7 @@ struct SmolStr(); /// ); /// ``` - #[lua(kind = "Function")] + #[lua()] fn encode_buffer() -> [u8; 45]; "#, @@ -21942,9 +23069,9 @@ struct SmolStr(); /// If the UUID is the correct version (v1, or v6) this will return the /// node value as a 6-byte array. For other versions this will return `None`. - #[lua(kind = "Method")] + #[lua()] fn get_node_id( - &self, + _self: LuaReflectRefProxy, ) -> bevy::reflect::erased_serde::__private::serde::__private::Option<[u8; 6]>; "#, @@ -21965,8 +23092,8 @@ struct SmolStr(); /// ); /// ``` - #[lua(kind = "Function", output(proxy))] - fn nil() -> uuid::Uuid; + #[lua()] + fn nil() -> LuaReflectValProxy; "#, r#" @@ -21986,8 +23113,8 @@ struct SmolStr(); /// ); /// ``` - #[lua(kind = "Function", output(proxy))] - fn max() -> uuid::Uuid; + #[lua()] + fn max() -> LuaReflectValProxy; "#, r#" @@ -22004,8 +23131,8 @@ struct SmolStr(); /// ); /// ``` - #[lua(kind = "Function", output(proxy))] - fn from_u128(v: u128) -> uuid::Uuid; + #[lua()] + fn from_u128(v: u128) -> LuaReflectValProxy; "#, r#" @@ -22026,8 +23153,8 @@ struct SmolStr(); /// ); /// ``` - #[lua(kind = "Function", output(proxy))] - fn from_u128_le(v: u128) -> uuid::Uuid; + #[lua()] + fn from_u128_le(v: u128) -> LuaReflectValProxy; "#, r#" @@ -22045,8 +23172,8 @@ struct SmolStr(); /// ); /// ``` - #[lua(kind = "Function", output(proxy))] - fn from_u64_pair(high_bits: u64, low_bits: u64) -> uuid::Uuid; + #[lua()] + fn from_u64_pair(high_bits: u64, low_bits: u64) -> LuaReflectValProxy; "#, r#" @@ -22071,8 +23198,8 @@ struct SmolStr(); /// # } /// ``` - #[lua(kind = "Function", output(proxy))] - fn from_bytes(bytes: [u8; 16]) -> uuid::Uuid; + #[lua()] + fn from_bytes(bytes: [u8; 16]) -> LuaReflectValProxy; "#, r#" @@ -22098,646 +23225,406 @@ struct SmolStr(); /// # } /// ``` - #[lua(kind = "Function", output(proxy))] - fn from_bytes_le(b: [u8; 16]) -> uuid::Uuid; + #[lua()] + fn from_bytes_le(b: [u8; 16]) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &uuid::Uuid) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua( - as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone", - kind = "Method", - output(proxy), - )] - fn clone(&self) -> uuid::Uuid; + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone(_self: LuaReflectRefProxy) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Uuid(); +pub struct Uuid(); #[derive(Default)] pub(crate) struct Globals; -impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { - fn add_instances< - 'lua, - T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, - >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { instances .add_instance( "AtomicBool", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "AtomicI16", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "AtomicI32", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "AtomicI64", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "AtomicI8", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "AtomicIsize", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "AtomicU16", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "AtomicU32", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "AtomicU64", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "AtomicU8", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "AtomicUsize", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "Duration", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "Instant", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "PathBuf", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances - .add_instance( - "Quat", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Quat", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "Vec3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Vec3", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "IVec2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("IVec2", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "IVec3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("IVec3", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "IVec4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("IVec4", crate::tealr::mlu::UserDataProxy::::new)?; instances .add_instance( "I64Vec2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "I64Vec3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "I64Vec4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances - .add_instance( - "UVec2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("UVec2", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "UVec3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("UVec3", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "UVec4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("UVec4", crate::tealr::mlu::UserDataProxy::::new)?; instances .add_instance( "U64Vec2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "U64Vec3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "U64Vec4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances - .add_instance( - "Vec2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Vec2", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "Vec3A", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Vec3A", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "Vec4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Vec4", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "BVec2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("BVec2", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "BVec3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("BVec3", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "BVec4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("BVec4", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "DVec2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("DVec2", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "DVec3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("DVec3", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "DVec4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("DVec4", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "Mat2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Mat2", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "Mat3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Mat3", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "Mat3A", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Mat3A", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "Mat4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Mat4", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "DMat2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("DMat2", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "DMat3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("DMat3", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "DMat4", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("DMat4", crate::tealr::mlu::UserDataProxy::::new)?; instances .add_instance( "Affine2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "Affine3A", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "DAffine2", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "DAffine3", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances - .add_instance( - "DQuat", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("DQuat", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "BVec3A", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("BVec3A", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "BVec4A", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("BVec4A", crate::tealr::mlu::UserDataProxy::::new)?; instances - .add_instance( - "Uuid", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Uuid", crate::tealr::mlu::UserDataProxy::::new)?; Ok(()) } } -pub struct BevyReflectAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyReflectAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; - fn attach_api( - &mut self, - ctx: &mut Self::APITarget, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); - bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) - .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( - e.to_string(), - )) - } - fn get_doc_fragment(&self) -> Option { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( +fn bevy_reflect_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyReflectScriptingPlugin; +impl bevy::app::Plugin for BevyReflectScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_reflect_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( "BevyReflectAPI", |tw| { tw.document_global_instance::() .expect("Something went wrong documenting globals") .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaAtomicBool, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaAtomicI16, - >, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaAtomicI32, - >, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaAtomicI64, - >, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaAtomicI8, - >, - >() + .process_type::>() .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaAtomicIsize, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaAtomicU16, - >, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaAtomicU32, - >, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaAtomicU64, - >, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaAtomicU8, - >, - >() + .process_type::>() .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaAtomicUsize, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaDuration, - >, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaAffine3A, - >, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaDAffine2, - >, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaDAffine3, - >, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() }, ), - ) - } - fn setup_script( - &mut self, - script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn setup_script_runtime( - &mut self, - world_ptr: bevy_mod_scripting_core::world::WorldPointer, - _script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn register_with_app(&self, app: &mut bevy::app::App) { - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); + ); } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs index 8910927aea..a066640a81 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs @@ -4,67 +4,69 @@ #![cfg_attr(rustfmt, rustfmt_skip)] use super::bevy_ecs::*; use super::bevy_reflect::*; -extern crate self as bevy_script_api; -use bevy_script_api::{ - lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, }; -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::time::prelude::Fixed", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::time::prelude::Fixed; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Fixed {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Fixed {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::time::prelude::Real", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::time::prelude::Real; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Real {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Real {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::time::prelude::Timer", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); - -"#, - r#" -/// Creates a new timer with a given duration. -/// See also [`Timer::from_seconds`](Timer::from_seconds). - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - duration: bevy::utils::Duration, - #[proxy] - mode: bevy::time::prelude::TimerMode, - ) -> bevy::time::prelude::Timer; + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" @@ -75,12 +77,11 @@ struct Real {} /// let mut timer = Timer::from_seconds(1.0, TimerMode::Once); /// ``` - #[lua(kind = "Function", output(proxy))] + #[lua()] fn from_seconds( duration: f32, - #[proxy] - mode: bevy::time::prelude::TimerMode, - ) -> bevy::time::prelude::Timer; + mode: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -104,8 +105,8 @@ struct Real {} /// assert!(timer_repeating.finished()); /// ``` - #[lua(kind = "Method")] - fn finished(&self) -> bool; + #[lua()] + fn finished(_self: LuaReflectRefProxy) -> bool; "#, r#" @@ -121,88 +122,24 @@ struct Real {} /// assert!(!timer.just_finished()); /// ``` - #[lua(kind = "Method")] - fn just_finished(&self) -> bool; - -"#, - r#" -/// Returns the time elapsed on the timer. Guaranteed to be between 0.0 and `duration`. -/// Will only equal `duration` when the timer is finished and non repeating. -/// See also [`Stopwatch::elapsed`](Stopwatch::elapsed). -/// # Examples -/// ``` -/// # use bevy_time::*; -/// use std::time::Duration; -/// let mut timer = Timer::from_seconds(1.0, TimerMode::Once); -/// timer.tick(Duration::from_secs_f32(0.5)); -/// assert_eq!(timer.elapsed(), Duration::from_secs_f32(0.5)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn elapsed(&self) -> bevy::utils::Duration; + #[lua()] + fn just_finished(_self: LuaReflectRefProxy) -> bool; "#, r#" /// Returns the time elapsed on the timer as an `f32`. /// See also [`Timer::elapsed`](Timer::elapsed). - #[lua(kind = "Method")] - fn elapsed_secs(&self) -> f32; + #[lua()] + fn elapsed_secs(_self: LuaReflectRefProxy) -> f32; "#, r#" /// Returns the time elapsed on the timer as an `f64`. /// See also [`Timer::elapsed`](Timer::elapsed). - #[lua(kind = "Method")] - fn elapsed_secs_f64(&self) -> f64; - -"#, - r#" -/// Sets the elapsed time of the timer without any other considerations. -/// See also [`Stopwatch::set`](Stopwatch::set). -/// # -/// ``` -/// # use bevy_time::*; -/// use std::time::Duration; -/// let mut timer = Timer::from_seconds(1.0, TimerMode::Once); -/// timer.set_elapsed(Duration::from_secs(2)); -/// assert_eq!(timer.elapsed(), Duration::from_secs(2)); -/// // the timer is not finished even if the elapsed time is greater than the duration. -/// assert!(!timer.finished()); -/// ``` - - #[lua(kind = "MutatingMethod")] - fn set_elapsed(&mut self, #[proxy] time: bevy::utils::Duration) -> (); - -"#, - r#" -/// Returns the duration of the timer. -/// # Examples -/// ``` -/// # use bevy_time::*; -/// use std::time::Duration; -/// let timer = Timer::new(Duration::from_secs(1), TimerMode::Once); -/// assert_eq!(timer.duration(), Duration::from_secs(1)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn duration(&self) -> bevy::utils::Duration; - -"#, - r#" -/// Sets the duration of the timer. -/// # Examples -/// ``` -/// # use bevy_time::*; -/// use std::time::Duration; -/// let mut timer = Timer::from_seconds(1.5, TimerMode::Once); -/// timer.set_duration(Duration::from_secs(1)); -/// assert_eq!(timer.duration(), Duration::from_secs(1)); -/// ``` - - #[lua(kind = "MutatingMethod")] - fn set_duration(&mut self, #[proxy] duration: bevy::utils::Duration) -> (); + #[lua()] + fn elapsed_secs_f64(_self: LuaReflectRefProxy) -> f64; "#, r#" @@ -214,8 +151,10 @@ struct Real {} /// assert_eq!(timer.mode(), TimerMode::Repeating); /// ``` - #[lua(kind = "Method", output(proxy))] - fn mode(&self) -> bevy::time::prelude::TimerMode; + #[lua()] + fn mode( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -228,8 +167,11 @@ struct Real {} /// assert_eq!(timer.mode(), TimerMode::Once); /// ``` - #[lua(kind = "MutatingMethod")] - fn set_mode(&mut self, #[proxy] mode: bevy::time::prelude::TimerMode) -> (); + #[lua()] + fn set_mode( + _self: LuaReflectRefMutProxy, + mode: LuaReflectValProxy, + ) -> (); "#, r#" @@ -245,8 +187,8 @@ struct Real {} /// assert_eq!(timer.elapsed_secs(), 0.0); /// ``` - #[lua(kind = "MutatingMethod")] - fn pause(&mut self) -> (); + #[lua()] + fn pause(_self: LuaReflectRefMutProxy) -> (); "#, r#" @@ -264,8 +206,8 @@ struct Real {} /// assert_eq!(timer.elapsed_secs(), 0.5); /// ``` - #[lua(kind = "MutatingMethod")] - fn unpause(&mut self) -> (); + #[lua()] + fn unpause(_self: LuaReflectRefMutProxy) -> (); "#, r#" @@ -282,8 +224,8 @@ struct Real {} /// assert!(!timer.paused()); /// ``` - #[lua(kind = "Method")] - fn paused(&self) -> bool; + #[lua()] + fn paused(_self: LuaReflectRefProxy) -> bool; "#, r#" @@ -301,8 +243,8 @@ struct Real {} /// assert_eq!(timer.elapsed_secs(), 0.0); /// ``` - #[lua(kind = "MutatingMethod")] - fn reset(&mut self) -> (); + #[lua()] + fn reset(_self: LuaReflectRefMutProxy) -> (); "#, r#" @@ -316,8 +258,8 @@ struct Real {} /// assert_eq!(timer.fraction(), 0.25); /// ``` - #[lua(kind = "Method")] - fn fraction(&self) -> f32; + #[lua()] + fn fraction(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -331,8 +273,8 @@ struct Real {} /// assert_eq!(timer.fraction_remaining(), 0.75); /// ``` - #[lua(kind = "Method")] - fn fraction_remaining(&self) -> f32; + #[lua()] + fn fraction_remaining(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -348,23 +290,8 @@ struct Real {} /// assert_eq!(Ordering::Equal, result); /// ``` - #[lua(kind = "Method")] - fn remaining_secs(&self) -> f32; - -"#, - r#" -/// Returns the remaining time using Duration -/// # Examples -/// ``` -/// # use bevy_time::*; -/// use std::time::Duration; -/// let mut timer = Timer::from_seconds(2.0, TimerMode::Once); -/// timer.tick(Duration::from_secs_f32(0.5)); -/// assert_eq!(timer.remaining(), Duration::from_secs_f32(1.5)); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn remaining(&self) -> bevy::utils::Duration; + #[lua()] + fn remaining_secs(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -385,113 +312,130 @@ struct Real {} /// assert_eq!(timer.times_finished_this_tick(), 0); /// ``` - #[lua(kind = "Method")] - fn times_finished_this_tick(&self) -> u32; + #[lua()] + fn times_finished_this_tick( + _self: LuaReflectRefProxy, + ) -> u32; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::time::prelude::Timer; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &timer::Timer) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Timer {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Timer {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::time::prelude::TimerMode", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &timer::TimerMode) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::time::prelude::TimerMode; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct TimerMode {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct TimerMode {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::time::prelude::Virtual", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::time::prelude::Virtual; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Virtual {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Virtual {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::time::Stopwatch", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::time::Stopwatch; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", - composite = "eq", - metamethod = "Eq", - )] - fn eq(&self, #[proxy] other: &stopwatch::Stopwatch) -> bool; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -504,27 +448,8 @@ struct Virtual {} /// assert_eq!(stopwatch.is_paused(), false); /// ``` - #[lua(kind = "Function", output(proxy))] - fn new() -> bevy::time::Stopwatch; - -"#, - r#" -/// Returns the elapsed time since the last [`reset`](Stopwatch::reset) -/// of the stopwatch. -/// # Examples -/// ``` -/// # use bevy_time::*; -/// use std::time::Duration; -/// let mut stopwatch = Stopwatch::new(); -/// stopwatch.tick(Duration::from_secs(1)); -/// assert_eq!(stopwatch.elapsed(), Duration::from_secs(1)); -/// ``` -/// # See Also -/// [`elapsed_secs`](Stopwatch::elapsed_secs) - if an `f32` value is desirable instead. -/// [`elapsed_secs_f64`](Stopwatch::elapsed_secs_f64) - if an `f64` is desirable instead. - - #[lua(kind = "Method", output(proxy))] - fn elapsed(&self) -> bevy::utils::Duration; + #[lua()] + fn new() -> LuaReflectValProxy; "#, r#" @@ -542,8 +467,8 @@ struct Virtual {} /// [`elapsed`](Stopwatch::elapsed) - if a `Duration` is desirable instead. /// [`elapsed_secs_f64`](Stopwatch::elapsed_secs_f64) - if an `f64` is desirable instead. - #[lua(kind = "Method")] - fn elapsed_secs(&self) -> f32; + #[lua()] + fn elapsed_secs(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -553,23 +478,8 @@ struct Virtual {} /// [`elapsed`](Stopwatch::elapsed) - if a `Duration` is desirable instead. /// [`elapsed_secs`](Stopwatch::elapsed_secs) - if an `f32` is desirable instead. - #[lua(kind = "Method")] - fn elapsed_secs_f64(&self) -> f64; - -"#, - r#" -/// Sets the elapsed time of the stopwatch. -/// # Examples -/// ``` -/// # use bevy_time::*; -/// use std::time::Duration; -/// let mut stopwatch = Stopwatch::new(); -/// stopwatch.set_elapsed(Duration::from_secs_f32(1.0)); -/// assert_eq!(stopwatch.elapsed_secs(), 1.0); -/// ``` - - #[lua(kind = "MutatingMethod")] - fn set_elapsed(&mut self, #[proxy] time: bevy::utils::Duration) -> (); + #[lua()] + fn elapsed_secs_f64(_self: LuaReflectRefProxy) -> f64; "#, r#" @@ -586,8 +496,8 @@ struct Virtual {} /// assert_eq!(stopwatch.elapsed_secs(), 0.0); /// ``` - #[lua(kind = "MutatingMethod")] - fn pause(&mut self) -> (); + #[lua()] + fn pause(_self: LuaReflectRefMutProxy) -> (); "#, r#" @@ -605,8 +515,8 @@ struct Virtual {} /// assert_eq!(stopwatch.elapsed_secs(), 1.0); /// ``` - #[lua(kind = "MutatingMethod")] - fn unpause(&mut self) -> (); + #[lua()] + fn unpause(_self: LuaReflectRefMutProxy) -> (); "#, r#" @@ -622,8 +532,8 @@ struct Virtual {} /// assert!(!stopwatch.is_paused()); /// ``` - #[lua(kind = "Method")] - fn is_paused(&self) -> bool; + #[lua()] + fn is_paused(_self: LuaReflectRefProxy) -> bool; "#, r#" @@ -638,56 +548,54 @@ struct Virtual {} /// assert_eq!(stopwatch.elapsed_secs(), 0.0); /// ``` - #[lua(kind = "MutatingMethod")] - fn reset(&mut self) -> (); + #[lua()] + fn reset(_self: LuaReflectRefMutProxy) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Stopwatch {} +pub struct Stopwatch {} #[derive(Default)] pub(crate) struct Globals; -impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { - fn add_instances< - 'lua, - T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, - >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { instances - .add_instance( - "Timer", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, - )?; + .add_instance("Timer", crate::tealr::mlu::UserDataProxy::::new)?; instances .add_instance( "Stopwatch", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; Ok(()) } } -pub struct BevyTimeAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyTimeAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; - fn attach_api( - &mut self, - ctx: &mut Self::APITarget, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); - bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) - .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( - e.to_string(), - )) - } - fn get_doc_fragment(&self) -> Option { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( +fn bevy_time_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyTimeScriptingPlugin; +impl bevy::app::Plugin for BevyTimeScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_time_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( "BevyTimeAPI", |tw| { tw.document_global_instance::() @@ -695,42 +603,13 @@ impl bevy_mod_scripting_core::hosts::APIProvider for BevyTimeAPIProvider { .process_type::() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy, - >() + .process_type::>() .process_type::() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaStopwatch, - >, - >() + .process_type::>() }, ), - ) - } - fn setup_script( - &mut self, - script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn setup_script_runtime( - &mut self, - world_ptr: bevy_mod_scripting_core::world::WorldPointer, - _script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn register_with_app(&self, app: &mut bevy::app::App) { - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); + ); } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs index d6e093de4a..f1c2607d4c 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs @@ -7,113 +7,61 @@ use super::bevy_reflect::*; use super::bevy_core::*; use super::bevy_math::*; use super::bevy_hierarchy::*; -extern crate self as bevy_script_api; -use bevy_script_api::{ - lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, }; -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::transform::components::GlobalTransform", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &components::global_transform::GlobalTransform) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), + as_trait = "std::ops::Mul::", composite = "mul", - metamethod = "Mul", )] fn mul( - self, - #[proxy] - transform: bevy::transform::components::Transform, - ) -> bevy::transform::components::GlobalTransform; - -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] value: bevy::math::Vec3) -> bevy::math::Vec3; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::transform::components::GlobalTransform; - -"#, - r#" - - #[lua(kind = "Function", output(proxy))] - fn from_xyz(x: f32, y: f32, z: f32) -> bevy::transform::components::GlobalTransform; - -"#, - r#" - - #[lua(kind = "Function", output(proxy))] - fn from_translation( - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::transform::components::GlobalTransform; - -"#, - r#" - - #[lua(kind = "Function", output(proxy))] - fn from_rotation( - #[proxy] - rotation: bevy::math::Quat, - ) -> bevy::transform::components::GlobalTransform; - -"#, - r#" - - #[lua(kind = "Function", output(proxy))] - fn from_scale( - #[proxy] - scale: bevy::math::Vec3, - ) -> bevy::transform::components::GlobalTransform; + _self: LuaReflectValProxy, + transform: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(kind = "Function", output(proxy))] - fn from_isometry( - #[proxy] - iso: bevy::math::Isometry3d, - ) -> bevy::transform::components::GlobalTransform; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Returns the 3d affine transformation matrix as a [`Mat4`]. - #[lua(kind = "Method", output(proxy))] - fn compute_matrix(&self) -> bevy::math::Mat4; - -"#, - r#" -/// Returns the 3d affine transformation matrix as an [`Affine3A`]. - - #[lua(kind = "Method", output(proxy))] - fn affine(&self) -> bevy::math::Affine3A; + #[lua()] + fn from_xyz( + x: f32, + y: f32, + z: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -121,19 +69,10 @@ use bevy_script_api::{ /// The transform is expected to be non-degenerate and without shearing, or the output /// will be invalid. - #[lua(kind = "Method", output(proxy))] - fn compute_transform(&self) -> bevy::transform::components::Transform; - -"#, - r#" -/// Returns the isometric part of the transformation as an [isometry]. Any scaling done by the -/// transformation will be ignored. -/// The transform is expected to be non-degenerate and without shearing, or the output -/// will be invalid. -/// [isometry]: Isometry3d - - #[lua(kind = "Method", output(proxy))] - fn to_isometry(&self) -> bevy::math::Isometry3d; + #[lua()] + fn compute_transform( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -168,182 +107,61 @@ use bevy_script_api::{ /// The transform is expected to be non-degenerate and without shearing, or the output /// will be invalid. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn reparented_to( - &self, - #[proxy] - parent: &components::global_transform::GlobalTransform, - ) -> bevy::transform::components::Transform; - -"#, - r#" -///Return the local right vector (X). - - #[lua(kind = "Method", output(proxy))] - fn right(&self) -> bevy::math::Dir3; - -"#, - r#" -///Return the local left vector (-X). - - #[lua(kind = "Method", output(proxy))] - fn left(&self) -> bevy::math::Dir3; - -"#, - r#" -///Return the local up vector (Y). - - #[lua(kind = "Method", output(proxy))] - fn up(&self) -> bevy::math::Dir3; - -"#, - r#" -///Return the local down vector (-Y). - - #[lua(kind = "Method", output(proxy))] - fn down(&self) -> bevy::math::Dir3; - -"#, - r#" -///Return the local back vector (Z). - - #[lua(kind = "Method", output(proxy))] - fn back(&self) -> bevy::math::Dir3; - -"#, - r#" -///Return the local forward vector (-Z). - - #[lua(kind = "Method", output(proxy))] - fn forward(&self) -> bevy::math::Dir3; - -"#, - r#" -/// Get the translation as a [`Vec3`]. - - #[lua(kind = "Method", output(proxy))] - fn translation(&self) -> bevy::math::Vec3; - -"#, - r#" -/// Get the translation as a [`Vec3A`]. - - #[lua(kind = "Method", output(proxy))] - fn translation_vec3a(&self) -> bevy::math::Vec3A; - -"#, - r#" -/// Get the rotation as a [`Quat`]. -/// The transform is expected to be non-degenerate and without shearing, or the output will be invalid. -/// # Warning -/// This is calculated using `to_scale_rotation_translation`, meaning that you -/// should probably use it directly if you also need translation or scale. - - #[lua(kind = "Method", output(proxy))] - fn rotation(&self) -> bevy::math::Quat; - -"#, - r#" -/// Get the scale as a [`Vec3`]. -/// The transform is expected to be non-degenerate and without shearing, or the output will be invalid. -/// Some of the computations overlap with `to_scale_rotation_translation`, which means you should use -/// it instead if you also need rotation. - - #[lua(kind = "Method", output(proxy))] - fn scale(&self) -> bevy::math::Vec3; - -"#, - r#" -/// Get an upper bound of the radius from the given `extents`. - - #[lua(kind = "Method")] - fn radius_vec3a(&self, #[proxy] extents: bevy::math::Vec3A) -> f32; - -"#, - r#" -/// Transforms the given point from local space to global space, applying shear, scale, rotation and translation. -/// It can be used like this: -/// ``` -/// # use bevy_transform::prelude::{GlobalTransform}; -/// # use bevy_math::prelude::Vec3; -/// let global_transform = GlobalTransform::from_xyz(1., 2., 3.); -/// let local_point = Vec3::new(1., 2., 3.); -/// let global_point = global_transform.transform_point(local_point); -/// assert_eq!(global_point, Vec3::new(2., 4., 6.)); -/// ``` -/// ``` -/// # use bevy_transform::prelude::{GlobalTransform}; -/// # use bevy_math::Vec3; -/// let global_point = Vec3::new(2., 4., 6.); -/// let global_transform = GlobalTransform::from_xyz(1., 2., 3.); -/// let local_point = global_transform.affine().inverse().transform_point3(global_point); -/// assert_eq!(local_point, Vec3::new(1., 2., 3.)) -/// ``` -/// To apply shear, scale, and rotation *without* applying translation, different functions are available: -/// ``` -/// # use bevy_transform::prelude::{GlobalTransform}; -/// # use bevy_math::prelude::Vec3; -/// let global_transform = GlobalTransform::from_xyz(1., 2., 3.); -/// let local_direction = Vec3::new(1., 2., 3.); -/// let global_direction = global_transform.affine().transform_vector3(local_direction); -/// assert_eq!(global_direction, Vec3::new(1., 2., 3.)); -/// let roundtripped_local_direction = global_transform.affine().inverse().transform_vector3(global_direction); -/// assert_eq!(roundtripped_local_direction, local_direction); -/// ``` - - #[lua(kind = "Method", output(proxy))] - fn transform_point(&self, #[proxy] point: bevy::math::Vec3) -> bevy::math::Vec3; + _self: LuaReflectRefProxy, + parent: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Multiplies `self` with `transform` component by component, returning the /// resulting [`GlobalTransform`] - #[lua(kind = "Method", output(proxy))] + #[lua()] fn mul_transform( - &self, - #[proxy] - transform: bevy::transform::components::Transform, - ) -> bevy::transform::components::GlobalTransform; + _self: LuaReflectRefProxy, + transform: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), + as_trait = "std::ops::Mul::", composite = "mul", - metamethod = "Mul", )] fn mul( - self, - #[proxy] - global_transform: bevy::transform::components::GlobalTransform, - ) -> bevy::transform::components::GlobalTransform; + _self: LuaReflectValProxy, + global_transform: LuaReflectValProxy< + bevy::transform::components::GlobalTransform, + >, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct GlobalTransform(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct GlobalTransform(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::transform::components::Transform", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &components::transform::Transform) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -351,281 +169,74 @@ struct GlobalTransform(); /// is used for z-ordering elements: higher `z`-value will be in front of lower /// `z`-value. - #[lua(kind = "Function", output(proxy))] - fn from_xyz(x: f32, y: f32, z: f32) -> bevy::transform::components::Transform; - -"#, - r#" -/// Extracts the translation, rotation, and scale from `matrix`. It must be a 3d affine -/// transformation matrix. - - #[lua(kind = "Function", output(proxy))] - fn from_matrix( - #[proxy] - world_from_local: bevy::math::Mat4, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Creates a new [`Transform`], with `translation`. Rotation will be 0 and scale 1 on -/// all axes. - - #[lua(kind = "Function", output(proxy))] - fn from_translation( - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Creates a new [`Transform`], with `rotation`. Translation will be 0 and scale 1 on -/// all axes. - - #[lua(kind = "Function", output(proxy))] - fn from_rotation( - #[proxy] - rotation: bevy::math::Quat, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Creates a new [`Transform`], with `scale`. Translation will be 0 and rotation 0 on -/// all axes. - - #[lua(kind = "Function", output(proxy))] - fn from_scale( - #[proxy] - scale: bevy::math::Vec3, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Creates a new [`Transform`] that is equivalent to the given [isometry]. -/// [isometry]: Isometry3d - - #[lua(kind = "Function", output(proxy))] - fn from_isometry( - #[proxy] - iso: bevy::math::Isometry3d, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Returns this [`Transform`] with a new translation. - - #[lua(kind = "Method", output(proxy))] - fn with_translation( - self, - #[proxy] - translation: bevy::math::Vec3, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Returns this [`Transform`] with a new rotation. - - #[lua(kind = "Method", output(proxy))] - fn with_rotation( - self, - #[proxy] - rotation: bevy::math::Quat, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Returns this [`Transform`] with a new scale. - - #[lua(kind = "Method", output(proxy))] - fn with_scale( - self, - #[proxy] - scale: bevy::math::Vec3, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Returns the 3d affine transformation matrix from this transforms translation, -/// rotation, and scale. - - #[lua(kind = "Method", output(proxy))] - fn compute_matrix(&self) -> bevy::math::Mat4; - -"#, - r#" -/// Returns the 3d affine transformation matrix from this transforms translation, -/// rotation, and scale. - - #[lua(kind = "Method", output(proxy))] - fn compute_affine(&self) -> bevy::math::Affine3A; - -"#, - r#" -/// Get the unit vector in the local `X` direction. - - #[lua(kind = "Method", output(proxy))] - fn local_x(&self) -> bevy::math::Dir3; - -"#, - r#" -/// Equivalent to [`-local_x()`][Transform::local_x()] - - #[lua(kind = "Method", output(proxy))] - fn left(&self) -> bevy::math::Dir3; - -"#, - r#" -/// Equivalent to [`local_x()`][Transform::local_x()] - - #[lua(kind = "Method", output(proxy))] - fn right(&self) -> bevy::math::Dir3; - -"#, - r#" -/// Get the unit vector in the local `Y` direction. - - #[lua(kind = "Method", output(proxy))] - fn local_y(&self) -> bevy::math::Dir3; - -"#, - r#" -/// Equivalent to [`local_y()`][Transform::local_y] - - #[lua(kind = "Method", output(proxy))] - fn up(&self) -> bevy::math::Dir3; - -"#, - r#" -/// Equivalent to [`-local_y()`][Transform::local_y] - - #[lua(kind = "Method", output(proxy))] - fn down(&self) -> bevy::math::Dir3; - -"#, - r#" -/// Get the unit vector in the local `Z` direction. - - #[lua(kind = "Method", output(proxy))] - fn local_z(&self) -> bevy::math::Dir3; - -"#, - r#" -/// Equivalent to [`-local_z()`][Transform::local_z] - - #[lua(kind = "Method", output(proxy))] - fn forward(&self) -> bevy::math::Dir3; - -"#, - r#" -/// Equivalent to [`local_z()`][Transform::local_z] - - #[lua(kind = "Method", output(proxy))] - fn back(&self) -> bevy::math::Dir3; - -"#, - r#" -/// Rotates this [`Transform`] by the given rotation. -/// If this [`Transform`] has a parent, the `rotation` is relative to the rotation of the parent. -/// # Examples -/// - [`3d_rotation`] -/// [`3d_rotation`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/3d_rotation.rs - - #[lua(kind = "MutatingMethod")] - fn rotate(&mut self, #[proxy] rotation: bevy::math::Quat) -> (); - -"#, - r#" -/// Rotates this [`Transform`] around the given `axis` by `angle` (in radians). -/// If this [`Transform`] has a parent, the `axis` is relative to the rotation of the parent. - - #[lua(kind = "MutatingMethod")] - fn rotate_axis(&mut self, #[proxy] axis: bevy::math::Dir3, angle: f32) -> (); + #[lua()] + fn from_xyz( + x: f32, + y: f32, + z: f32, + ) -> LuaReflectValProxy; "#, r#" /// Rotates this [`Transform`] around the `X` axis by `angle` (in radians). /// If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. - #[lua(kind = "MutatingMethod")] - fn rotate_x(&mut self, angle: f32) -> (); + #[lua()] + fn rotate_x( + _self: LuaReflectRefMutProxy, + angle: f32, + ) -> (); "#, r#" /// Rotates this [`Transform`] around the `Y` axis by `angle` (in radians). /// If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. - #[lua(kind = "MutatingMethod")] - fn rotate_y(&mut self, angle: f32) -> (); + #[lua()] + fn rotate_y( + _self: LuaReflectRefMutProxy, + angle: f32, + ) -> (); "#, r#" /// Rotates this [`Transform`] around the `Z` axis by `angle` (in radians). /// If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. - #[lua(kind = "MutatingMethod")] - fn rotate_z(&mut self, angle: f32) -> (); - -"#, - r#" -/// Rotates this [`Transform`] by the given `rotation`. -/// The `rotation` is relative to this [`Transform`]'s current rotation. - - #[lua(kind = "MutatingMethod")] - fn rotate_local(&mut self, #[proxy] rotation: bevy::math::Quat) -> (); - -"#, - r#" -/// Rotates this [`Transform`] around its local `axis` by `angle` (in radians). - - #[lua(kind = "MutatingMethod")] - fn rotate_local_axis(&mut self, #[proxy] axis: bevy::math::Dir3, angle: f32) -> (); + #[lua()] + fn rotate_z( + _self: LuaReflectRefMutProxy, + angle: f32, + ) -> (); "#, r#" /// Rotates this [`Transform`] around its local `X` axis by `angle` (in radians). - #[lua(kind = "MutatingMethod")] - fn rotate_local_x(&mut self, angle: f32) -> (); + #[lua()] + fn rotate_local_x( + _self: LuaReflectRefMutProxy, + angle: f32, + ) -> (); "#, r#" /// Rotates this [`Transform`] around its local `Y` axis by `angle` (in radians). - #[lua(kind = "MutatingMethod")] - fn rotate_local_y(&mut self, angle: f32) -> (); + #[lua()] + fn rotate_local_y( + _self: LuaReflectRefMutProxy, + angle: f32, + ) -> (); "#, r#" /// Rotates this [`Transform`] around its local `Z` axis by `angle` (in radians). - #[lua(kind = "MutatingMethod")] - fn rotate_local_z(&mut self, angle: f32) -> (); - -"#, - r#" -/// Translates this [`Transform`] around a `point` in space. -/// If this [`Transform`] has a parent, the `point` is relative to the [`Transform`] of the parent. - - #[lua(kind = "MutatingMethod")] - fn translate_around( - &mut self, - #[proxy] - point: bevy::math::Vec3, - #[proxy] - rotation: bevy::math::Quat, - ) -> (); - -"#, - r#" -/// Rotates this [`Transform`] around a `point` in space. -/// If this [`Transform`] has a parent, the `point` is relative to the [`Transform`] of the parent. - - #[lua(kind = "MutatingMethod")] - fn rotate_around( - &mut self, - #[proxy] - point: bevy::math::Vec3, - #[proxy] - rotation: bevy::math::Quat, + #[lua()] + fn rotate_local_z( + _self: LuaReflectRefMutProxy, + angle: f32, ) -> (); "#, @@ -633,26 +244,11 @@ struct GlobalTransform(); /// Multiplies `self` with `transform` component by component, returning the /// resulting [`Transform`] - #[lua(kind = "Method", output(proxy))] + #[lua()] fn mul_transform( - &self, - #[proxy] - transform: bevy::transform::components::Transform, - ) -> bevy::transform::components::Transform; - -"#, - r#" -/// Transforms the given `point`, applying scale, rotation and translation. -/// If this [`Transform`] has an ancestor entity with a [`Transform`] component, -/// [`Transform::transform_point`] will transform a point in local space into its -/// parent transform's space. -/// If this [`Transform`] does not have a parent, [`Transform::transform_point`] will -/// transform a point in local space into worldspace coordinates. -/// If you always want to transform a point in local space to worldspace, or if you need -/// the inverse transformations, see [`GlobalTransform::transform_point()`]. - - #[lua(kind = "Method", output(proxy))] - fn transform_point(&self, #[proxy] point: bevy::math::Vec3) -> bevy::math::Vec3; + _self: LuaReflectRefProxy, + transform: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -660,160 +256,105 @@ struct GlobalTransform(); /// finite. If any of them contains a `NaN`, positive or negative infinity, /// this will return `false`. - #[lua(kind = "Method")] - fn is_finite(&self) -> bool; - -"#, - r#" -/// Get the [isometry] defined by this transform's rotation and translation, ignoring scale. -/// [isometry]: Isometry3d - - #[lua(kind = "Method", output(proxy))] - fn to_isometry(&self) -> bevy::math::Isometry3d; + #[lua()] + fn is_finite( + _self: LuaReflectRefProxy, + ) -> bool; "#, r#" #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), + as_trait = "std::ops::Mul::", composite = "mul", - metamethod = "Mul", )] fn mul( - self, - #[proxy] - global_transform: bevy::transform::components::GlobalTransform, - ) -> bevy::transform::components::GlobalTransform; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::transform::components::Transform; + _self: LuaReflectValProxy, + global_transform: LuaReflectValProxy< + bevy::transform::components::GlobalTransform, + >, + ) -> LuaReflectValProxy; "#, r#" - #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), - composite = "mul", - metamethod = "Mul", - )] - fn mul(self, #[proxy] value: bevy::math::Vec3) -> bevy::math::Vec3; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::ops::Mul", - kind = "MetaFunction", - output(proxy), + as_trait = "std::ops::Mul::", composite = "mul", - metamethod = "Mul", )] fn mul( - self, - #[proxy] - transform: bevy::transform::components::Transform, - ) -> bevy::transform::components::Transform; + _self: LuaReflectValProxy, + transform: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Transform { - #[lua(output(proxy))] - translation: bevy::math::Vec3, - #[lua(output(proxy))] - rotation: bevy::math::Quat, - #[lua(output(proxy))] - scale: bevy::math::Vec3, +pub struct Transform { + translation: ReflectReference, + rotation: ReflectReference, + scale: ReflectReference, } #[derive(Default)] pub(crate) struct Globals; -impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { - fn add_instances< - 'lua, - T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, - >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { instances .add_instance( "GlobalTransform", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaGlobalTransform, - >::new, + crate::tealr::mlu::UserDataProxy::::new, )?; instances .add_instance( "Transform", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::::new, + crate::tealr::mlu::UserDataProxy::::new, )?; Ok(()) } } -pub struct BevyTransformAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyTransformAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; - fn attach_api( - &mut self, - ctx: &mut Self::APITarget, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); - bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) - .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( - e.to_string(), - )) - } - fn get_doc_fragment(&self) -> Option { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( +fn bevy_transform_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyTransformScriptingPlugin; +impl bevy::app::Plugin for BevyTransformScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_transform_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( "BevyTransformAPI", |tw| { tw.document_global_instance::() .expect("Something went wrong documenting globals") .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaGlobalTransform, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaTransform, - >, - >() + .process_type::>() }, ), - ) - } - fn setup_script( - &mut self, - script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn setup_script_runtime( - &mut self, - world_ptr: bevy_mod_scripting_core::world::WorldPointer, - _script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn register_with_app(&self, app: &mut bevy::app::App) { - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); + ); } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs index 75ee99eaa8..95df5fe7a7 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs @@ -8,244 +8,287 @@ use super::bevy_reflect::*; use super::bevy_core::*; use super::bevy_input::*; use super::bevy_math::*; -extern crate self as bevy_script_api; -use bevy_script_api::{ - lua::RegisterForeignLuaType, ReflectedValue, common::bevy::GetWorld, +use bevy_mod_scripting_core::{ + AddContextInitializer, StoreDocumentation, bindings::ReflectReference, }; -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +use crate::{ + bindings::proxy::{ + LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, + LuaIdentityProxy, + }, + RegisterLua, tealr::mlu::mlua::IntoLua, +}; +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::prelude::CursorEntered", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::CursorEntered) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::CursorEntered; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct CursorEntered { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, +pub struct CursorEntered { + window: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::prelude::CursorLeft", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::CursorLeft; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::CursorLeft) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct CursorLeft { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, +pub struct CursorLeft { + window: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::prelude::CursorMoved", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::CursorMoved) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::CursorMoved; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct CursorMoved { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, - #[lua(output(proxy))] - position: bevy::math::Vec2, - delta: ReflectedValue, -} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct CursorMoved { + window: ReflectReference, + position: ReflectReference, + delta: ReflectReference, +} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::prelude::FileDragAndDrop", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::FileDragAndDrop) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::FileDragAndDrop; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct FileDragAndDrop {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct FileDragAndDrop {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::prelude::Ime", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::Ime; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::Ime) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Ime {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct Ime {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::prelude::MonitorSelection", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::MonitorSelection; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &window::MonitorSelection) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct MonitorSelection {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct MonitorSelection {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::prelude::Window", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Setting to true will attempt to maximize the window. /// Setting to false will attempt to un-maximize the window. - #[lua(kind = "MutatingMethod")] - fn set_maximized(&mut self, maximized: bool) -> (); + #[lua()] + fn set_maximized( + _self: LuaReflectRefMutProxy, + maximized: bool, + ) -> (); "#, r#" /// Setting to true will attempt to minimize the window. /// Setting to false will attempt to un-minimize the window. - #[lua(kind = "MutatingMethod")] - fn set_minimized(&mut self, minimized: bool) -> (); + #[lua()] + fn set_minimized( + _self: LuaReflectRefMutProxy, + minimized: bool, + ) -> (); "#, r#" @@ -253,129 +296,97 @@ struct MonitorSelection {} /// There is no guarantee that this will work unless the left mouse button was /// pressed immediately before this function was called. - #[lua(kind = "MutatingMethod")] - fn start_drag_move(&mut self) -> (); - -"#, - r#" -/// Calling this will attempt to start a drag-resize of the window. -/// There is no guarantee that this will work unless the left mouse button was -/// pressed immediately before this function was called. - - #[lua(kind = "MutatingMethod")] - fn start_drag_resize(&mut self, #[proxy] direction: bevy::math::CompassOctant) -> (); + #[lua()] + fn start_drag_move( + _self: LuaReflectRefMutProxy, + ) -> (); "#, r#" /// The window's client area width in logical pixels. /// See [`WindowResolution`] for an explanation about logical/physical sizes. - #[lua(kind = "Method")] - fn width(&self) -> f32; + #[lua()] + fn width(_self: LuaReflectRefProxy) -> f32; "#, r#" /// The window's client area height in logical pixels. /// See [`WindowResolution`] for an explanation about logical/physical sizes. - #[lua(kind = "Method")] - fn height(&self) -> f32; - -"#, - r#" -/// The window's client size in logical pixels -/// See [`WindowResolution`] for an explanation about logical/physical sizes. - - #[lua(kind = "Method", output(proxy))] - fn size(&self) -> bevy::math::Vec2; + #[lua()] + fn height(_self: LuaReflectRefProxy) -> f32; "#, r#" /// The window's client area width in physical pixels. /// See [`WindowResolution`] for an explanation about logical/physical sizes. - #[lua(kind = "Method")] - fn physical_width(&self) -> u32; + #[lua()] + fn physical_width(_self: LuaReflectRefProxy) -> u32; "#, r#" /// The window's client area height in physical pixels. /// See [`WindowResolution`] for an explanation about logical/physical sizes. - #[lua(kind = "Method")] - fn physical_height(&self) -> u32; - -"#, - r#" -/// The window's client size in physical pixels -/// See [`WindowResolution`] for an explanation about logical/physical sizes. - - #[lua(kind = "Method", output(proxy))] - fn physical_size(&self) -> bevy::math::UVec2; + #[lua()] + fn physical_height(_self: LuaReflectRefProxy) -> u32; "#, r#" /// The window's scale factor. /// Ratio of physical size to logical size, see [`WindowResolution`]. - #[lua(kind = "Method")] - fn scale_factor(&self) -> f32; + #[lua()] + fn scale_factor(_self: LuaReflectRefProxy) -> f32; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::Window; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Window { - #[lua(output(proxy))] +pub struct Window { cursor_options: bevy::window::CursorOptions, - #[lua(output(proxy))] present_mode: bevy::window::PresentMode, - #[lua(output(proxy))] mode: bevy::window::WindowMode, - #[lua(output(proxy))] position: bevy::window::prelude::WindowPosition, - #[lua(output(proxy))] resolution: bevy::window::WindowResolution, title: std::string::String, name: std::option::Option, - #[lua(output(proxy))] composite_alpha_mode: bevy::window::CompositeAlphaMode, - #[lua(output(proxy))] resize_constraints: bevy::window::prelude::WindowResizeConstraints, resizable: bool, - #[lua(output(proxy))] enabled_buttons: bevy::window::EnabledButtons, decorations: bool, transparent: bool, focused: bool, - #[lua(output(proxy))] window_level: bevy::window::WindowLevel, canvas: std::option::Option, fit_canvas_to_parent: bool, prevent_default_event_handling: bool, - #[lua(output(proxy))] internal: bevy::window::InternalWindowState, ime_enabled: bool, - #[lua(output(proxy))] - ime_position: bevy::math::Vec2, - window_theme: ReflectedValue, + ime_position: ReflectReference, + window_theme: ReflectReference, visible: bool, skip_taskbar: bool, - desired_maximum_frame_latency: ReflectedValue, + desired_maximum_frame_latency: ReflectReference, recognize_pinch_gesture: bool, recognize_rotation_gesture: bool, recognize_doubletap_gesture: bool, - recognize_pan_gesture: ReflectedValue, + recognize_pan_gesture: ReflectReference, movable_by_window_background: bool, fullsize_content_view: bool, has_shadow: bool, @@ -384,1090 +395,1184 @@ struct Window { titlebar_show_title: bool, titlebar_show_buttons: bool, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::prelude::WindowMoved", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::WindowMoved) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::WindowMoved; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowMoved { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, - #[lua(output(proxy))] - position: bevy::math::IVec2, +pub struct WindowMoved { + window: ReflectReference, + position: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::prelude::WindowPosition", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::WindowPosition; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &window::WindowPosition) -> bool; - -"#, - r#" -/// Creates a new [`WindowPosition`] at a position. - - #[lua(kind = "Function", output(proxy))] - fn new( - #[proxy] - position: bevy::math::IVec2, - ) -> bevy::window::prelude::WindowPosition; - -"#, - r#" -/// Set the position to a specific point. - - #[lua(kind = "MutatingMethod")] - fn set(&mut self, #[proxy] position: bevy::math::IVec2) -> (); + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Set the window to a specific monitor. - #[lua(kind = "MutatingMethod")] + #[lua()] fn center( - &mut self, - #[proxy] - monitor: bevy::window::prelude::MonitorSelection, + _self: LuaReflectRefMutProxy, + monitor: LuaReflectValProxy, ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowPosition {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct WindowPosition {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::prelude::WindowResizeConstraints", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::prelude::WindowResizeConstraints; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &window::WindowResizeConstraints) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Checks if the constraints are valid. /// Will output warnings if it isn't. - #[lua(kind = "Method", output(proxy))] - fn check_constraints(&self) -> bevy::window::prelude::WindowResizeConstraints; + #[lua()] + fn check_constraints( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowResizeConstraints { +pub struct WindowResizeConstraints { min_width: f32, min_height: f32, max_width: f32, max_height: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowEvent", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::WindowEvent) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowEvent; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowEvent {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct WindowEvent {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowResized", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowResized; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::WindowResized) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowResized { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, +pub struct WindowResized { + window: ReflectReference, width: f32, height: f32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowCreated", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowCreated; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::WindowCreated) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowCreated { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, +pub struct WindowCreated { + window: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowClosing", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowClosing; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::WindowClosing) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowClosing { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, +pub struct WindowClosing { + window: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowClosed", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowClosed; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::WindowClosed) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowClosed { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, +pub struct WindowClosed { + window: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowCloseRequested", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowCloseRequested; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::WindowCloseRequested) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowCloseRequested { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, +pub struct WindowCloseRequested { + window: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowDestroyed", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::WindowDestroyed) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowDestroyed; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowDestroyed { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, +pub struct WindowDestroyed { + window: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::RequestRedraw", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::RequestRedraw; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::RequestRedraw) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct RequestRedraw {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct RequestRedraw {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowFocused", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::WindowFocused) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowFocused; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowFocused { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, +pub struct WindowFocused { + window: ReflectReference, focused: bool, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowOccluded", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::WindowOccluded) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowOccluded; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowOccluded { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, +pub struct WindowOccluded { + window: ReflectReference, occluded: bool, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowScaleFactorChanged", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::WindowScaleFactorChanged) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowScaleFactorChanged; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowScaleFactorChanged { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, +pub struct WindowScaleFactorChanged { + window: ReflectReference, scale_factor: f64, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowBackendScaleFactorChanged", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowBackendScaleFactorChanged; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::WindowBackendScaleFactorChanged) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowBackendScaleFactorChanged { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, +pub struct WindowBackendScaleFactorChanged { + window: ReflectReference, scale_factor: f64, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowThemeChanged", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::WindowThemeChanged) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowThemeChanged; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowThemeChanged { - #[lua(output(proxy))] - window: bevy::ecs::entity::Entity, - #[lua(output(proxy))] +pub struct WindowThemeChanged { + window: ReflectReference, theme: bevy::window::WindowTheme, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::AppLifecycle", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::AppLifecycle; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &event::AppLifecycle) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" /// Return `true` if the app can be updated. - #[lua(kind = "Method")] - fn is_active(&self) -> bool; + #[lua()] + fn is_active(_self: LuaReflectRefProxy) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct AppLifecycle {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct AppLifecycle {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::PrimaryWindow", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &window::PrimaryWindow) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::PrimaryWindow; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct PrimaryWindow {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct PrimaryWindow {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowTheme", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &window::WindowTheme) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowTheme; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowTheme {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct WindowTheme {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::Monitor", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" -/// Returns the physical size of the monitor in pixels - #[lua(kind = "Method", output(proxy))] - fn physical_size(&self) -> bevy::math::UVec2; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::Monitor; - -"#, - r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct Monitor { +pub struct Monitor { name: std::option::Option, physical_height: u32, physical_width: u32, - #[lua(output(proxy))] - physical_position: bevy::math::IVec2, + physical_position: ReflectReference, refresh_rate_millihertz: std::option::Option, scale_factor: f64, - video_modes: ReflectedValue, + video_modes: ReflectReference, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::VideoMode", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::VideoMode; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct VideoMode { - #[lua(output(proxy))] - physical_size: bevy::math::UVec2, +pub struct VideoMode { + physical_size: ReflectReference, bit_depth: u16, refresh_rate_millihertz: u32, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::PrimaryMonitor", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::PrimaryMonitor; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct PrimaryMonitor {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct PrimaryMonitor {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::SystemCursorIcon", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::SystemCursorIcon; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &system_cursor::SystemCursorIcon) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct SystemCursorIcon {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct SystemCursorIcon {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowRef", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowRef; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowRef {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct WindowRef {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::NormalizedWindowRef", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::NormalizedWindowRef; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Fetch the entity of this window reference - #[lua(kind = "Method", output(proxy))] - fn entity(&self) -> bevy::ecs::entity::Entity; + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &window::NormalizedWindowRef) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct NormalizedWindowRef(); -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct NormalizedWindowRef(); +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::CursorOptions", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::CursorOptions; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct CursorOptions { +pub struct CursorOptions { visible: bool, - #[lua(output(proxy))] grab_mode: bevy::window::CursorGrabMode, hit_test: bool, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::PresentMode", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::PresentMode; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &window::PresentMode) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct PresentMode {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct PresentMode {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowMode", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &window::WindowMode) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowMode; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowMode {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct WindowMode {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowResolution", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowResolution; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" /// Creates a new [`WindowResolution`]. - #[lua(kind = "Function", output(proxy))] - fn new(physical_width: f32, physical_height: f32) -> bevy::window::WindowResolution; + #[lua()] + fn new( + physical_width: f32, + physical_height: f32, + ) -> LuaReflectValProxy; "#, r#" /// Builder method for adding a scale factor override to the resolution. - #[lua(kind = "Method", output(proxy))] + #[lua()] fn with_scale_factor_override( - self, + _self: LuaReflectValProxy, scale_factor_override: f32, - ) -> bevy::window::WindowResolution; + ) -> LuaReflectValProxy; "#, r#" /// The window's client area width in logical pixels. - #[lua(kind = "Method")] - fn width(&self) -> f32; + #[lua()] + fn width(_self: LuaReflectRefProxy) -> f32; "#, r#" /// The window's client area height in logical pixels. - #[lua(kind = "Method")] - fn height(&self) -> f32; - -"#, - r#" -/// The window's client size in logical pixels - - #[lua(kind = "Method", output(proxy))] - fn size(&self) -> bevy::math::Vec2; + #[lua()] + fn height(_self: LuaReflectRefProxy) -> f32; "#, r#" /// The window's client area width in physical pixels. - #[lua(kind = "Method")] - fn physical_width(&self) -> u32; + #[lua()] + fn physical_width(_self: LuaReflectRefProxy) -> u32; "#, r#" /// The window's client area height in physical pixels. - #[lua(kind = "Method")] - fn physical_height(&self) -> u32; - -"#, - r#" -/// The window's client size in physical pixels - - #[lua(kind = "Method", output(proxy))] - fn physical_size(&self) -> bevy::math::UVec2; + #[lua()] + fn physical_height(_self: LuaReflectRefProxy) -> u32; "#, r#" /// The ratio of physical pixels to logical pixels. /// `physical_pixels = logical_pixels * scale_factor` - #[lua(kind = "Method")] - fn scale_factor(&self) -> f32; + #[lua()] + fn scale_factor(_self: LuaReflectRefProxy) -> f32; "#, r#" /// The window scale factor as reported by the window backend. /// This value is unaffected by [`WindowResolution::scale_factor_override`]. - #[lua(kind = "Method")] - fn base_scale_factor(&self) -> f32; + #[lua()] + fn base_scale_factor( + _self: LuaReflectRefProxy, + ) -> f32; "#, r#" /// The scale factor set with [`WindowResolution::set_scale_factor_override`]. /// This value may be different from the scale factor reported by the window backend. - #[lua(kind = "Method")] - fn scale_factor_override(&self) -> std::option::Option; + #[lua()] + fn scale_factor_override( + _self: LuaReflectRefProxy, + ) -> std::option::Option; "#, r#" /// Set the window's logical resolution. - #[lua(kind = "MutatingMethod")] - fn set(&mut self, width: f32, height: f32) -> (); + #[lua()] + fn set( + _self: LuaReflectRefMutProxy, + width: f32, + height: f32, + ) -> (); "#, r#" @@ -1475,15 +1580,22 @@ struct WindowMode {} /// This will ignore the scale factor setting, so most of the time you should /// prefer to use [`WindowResolution::set`]. - #[lua(kind = "MutatingMethod")] - fn set_physical_resolution(&mut self, width: u32, height: u32) -> (); + #[lua()] + fn set_physical_resolution( + _self: LuaReflectRefMutProxy, + width: u32, + height: u32, + ) -> (); "#, r#" /// Set the window's scale factor, this may get overridden by the backend. - #[lua(kind = "MutatingMethod")] - fn set_scale_factor(&mut self, scale_factor: f32) -> (); + #[lua()] + fn set_scale_factor( + _self: LuaReflectRefMutProxy, + scale_factor: f32, + ) -> (); "#, r#" @@ -1492,8 +1604,11 @@ struct WindowMode {} /// so that the window is created with the expected size instead of waiting for a resize /// event after its creation. - #[lua(kind = "MutatingMethod")] - fn set_scale_factor_and_apply_to_physical_size(&mut self, scale_factor: f32) -> (); + #[lua()] + fn set_scale_factor_and_apply_to_physical_size( + _self: LuaReflectRefMutProxy, + scale_factor: f32, + ) -> (); "#, r#" @@ -1501,9 +1616,9 @@ struct WindowMode {} /// This can change the logical and physical sizes if the resulting physical /// size is not within the limits. - #[lua(kind = "MutatingMethod")] + #[lua()] fn set_scale_factor_override( - &mut self, + _self: LuaReflectRefMutProxy, scale_factor_override: std::option::Option, ) -> (); @@ -1511,252 +1626,312 @@ struct WindowMode {} r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &window::WindowResolution) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowResolution {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct WindowResolution {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::CompositeAlphaMode", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &window::CompositeAlphaMode) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::CompositeAlphaMode; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct CompositeAlphaMode {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct CompositeAlphaMode {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::EnabledButtons", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &window::EnabledButtons) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::EnabledButtons; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct EnabledButtons { +pub struct EnabledButtons { minimize: bool, maximize: bool, close: bool, } -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::WindowLevel", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &window::WindowLevel) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::WindowLevel; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct WindowLevel {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct WindowLevel {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::InternalWindowState", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" /// Consumes the current maximize request, if it exists. This should only be called by window backends. - #[lua(kind = "MutatingMethod")] - fn take_maximize_request(&mut self) -> std::option::Option; + #[lua()] + fn take_maximize_request( + _self: LuaReflectRefMutProxy, + ) -> std::option::Option; "#, r#" /// Consumes the current minimize request, if it exists. This should only be called by window backends. - #[lua(kind = "MutatingMethod")] - fn take_minimize_request(&mut self) -> std::option::Option; + #[lua()] + fn take_minimize_request( + _self: LuaReflectRefMutProxy, + ) -> std::option::Option; "#, r#" /// Consumes the current move request, if it exists. This should only be called by window backends. - #[lua(kind = "MutatingMethod")] - fn take_move_request(&mut self) -> bool; + #[lua()] + fn take_move_request( + _self: LuaReflectRefMutProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::InternalWindowState; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &window::InternalWindowState) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct InternalWindowState {} -#[derive(bevy_mod_scripting_lua_derive::LuaProxy)] +pub struct InternalWindowState {} +#[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( - derive(clone), remote = "bevy::window::CursorGrabMode", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", functions[r#" #[lua( - as_trait = "std::cmp::PartialEq", - kind = "MetaFunction", + as_trait = "std::cmp::PartialEq::", composite = "eq", - metamethod = "Eq", )] - fn eq(&self, #[proxy] other: &window::CursorGrabMode) -> bool; + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::cmp::Eq", kind = "Method")] - fn assert_receiver_is_total_eq(&self) -> (); + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); "#, r#" - #[lua(as_trait = "std::clone::Clone", kind = "Method", output(proxy))] - fn clone(&self) -> bevy::window::CursorGrabMode; + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -#[lua(kind="MetaMethod", metamethod="ToString")] +#[lua(metamethod="ToString")] fn index(&self) -> String { format!("{:?}", _self) } "#] )] -struct CursorGrabMode {} +pub struct CursorGrabMode {} #[derive(Default)] pub(crate) struct Globals; -impl bevy_mod_scripting_lua::tealr::mlu::ExportInstances for Globals { - fn add_instances< - 'lua, - T: bevy_mod_scripting_lua::tealr::mlu::InstanceCollector<'lua>, - >(self, instances: &mut T) -> bevy_mod_scripting_lua::tealr::mlu::mlua::Result<()> { - instances - .add_instance( - "WindowPosition", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaWindowPosition, - >::new, - )?; +impl crate::tealr::mlu::ExportInstances for Globals { + fn add_instances<'lua, T: crate::tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> crate::tealr::mlu::mlua::Result<()> { instances .add_instance( "WindowResolution", - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy::< - LuaWindowResolution, - >::new, + crate::tealr::mlu::UserDataProxy::::new, )?; Ok(()) } } -pub struct BevyWindowAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for BevyWindowAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; - fn attach_api( - &mut self, - ctx: &mut Self::APITarget, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - let ctx = ctx.get_mut().expect("Unable to acquire lock on Lua context"); - bevy_mod_scripting_lua::tealr::mlu::set_global_env(Globals, ctx) - .map_err(|e| bevy_mod_scripting_core::error::ScriptError::Other( - e.to_string(), - )) - } - fn get_doc_fragment(&self) -> Option { - Some( - bevy_mod_scripting_lua::docs::LuaDocFragment::new( +fn bevy_window_context_initializer( + _: &bevy_mod_scripting_core::script::ScriptId, + ctx: &mut crate::prelude::Lua, +) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { + crate::tealr::mlu::set_global_env(Globals, ctx)?; + Ok(()) +} +pub struct BevyWindowScriptingPlugin; +impl bevy::app::Plugin for BevyWindowScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.register_lua_proxy::(); + app.add_context_initializer::<()>(bevy_window_context_initializer); + app.add_documentation_fragment( + crate::docs::LuaDocumentationFragment::new( "BevyWindowAPI", |tw| { tw.document_global_instance::() @@ -1770,11 +1945,6 @@ impl bevy_mod_scripting_core::hosts::APIProvider for BevyWindowAPIProvider { .process_type::() .process_type::() .process_type::() - .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaWindowPosition, - >, - >() .process_type::() .process_type::() .process_type::() @@ -1803,9 +1973,7 @@ impl bevy_mod_scripting_core::hosts::APIProvider for BevyWindowAPIProvider { .process_type::() .process_type::() .process_type::< - bevy_mod_scripting_lua::tealr::mlu::UserDataProxy< - LuaWindowResolution, - >, + crate::tealr::mlu::UserDataProxy, >() .process_type::() .process_type::() @@ -1814,66 +1982,6 @@ impl bevy_mod_scripting_core::hosts::APIProvider for BevyWindowAPIProvider { .process_type::() }, ), - ) - } - fn setup_script( - &mut self, - script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn setup_script_runtime( - &mut self, - world_ptr: bevy_mod_scripting_core::world::WorldPointer, - _script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn register_with_app(&self, app: &mut bevy::app::App) { - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::< - bevy::window::prelude::WindowResizeConstraints, - >(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); - app.register_foreign_lua_type::(); + ); } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/mod.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/mod.rs index b0ca5e66d0..094ba75fd2 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/mod.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/mod.rs @@ -2,87 +2,28 @@ #![allow(clippy::all)] #![allow(unused, deprecated, dead_code)] #![cfg_attr(rustfmt, rustfmt_skip)] -pub mod bevy_a11y; -pub mod bevy_ecs; -pub mod bevy_transform; -pub mod bevy_math; -pub mod bevy_input; -pub mod bevy_core; -pub mod bevy_time; -pub mod bevy_hierarchy; -pub mod bevy_window; -pub mod bevy_reflect; -extern crate self as bevy_script_api; -use bevy_mod_scripting_core::docs::DocFragment; -pub struct LuaBevyAPIProvider; -impl bevy_mod_scripting_core::hosts::APIProvider for LuaBevyAPIProvider { - type APITarget = std::sync::Mutex; - type ScriptContext = std::sync::Mutex; - type DocTarget = bevy_mod_scripting_lua::docs::LuaDocFragment; - fn attach_api( - &mut self, - ctx: &mut Self::APITarget, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - bevy_a11y::BevyA11YAPIProvider.attach_api(ctx)?; - bevy_ecs::BevyEcsAPIProvider.attach_api(ctx)?; - bevy_transform::BevyTransformAPIProvider.attach_api(ctx)?; - bevy_math::BevyMathAPIProvider.attach_api(ctx)?; - bevy_input::BevyInputAPIProvider.attach_api(ctx)?; - bevy_core::BevyCoreAPIProvider.attach_api(ctx)?; - bevy_time::BevyTimeAPIProvider.attach_api(ctx)?; - bevy_hierarchy::BevyHierarchyAPIProvider.attach_api(ctx)?; - bevy_window::BevyWindowAPIProvider.attach_api(ctx)?; - bevy_reflect::BevyReflectAPIProvider.attach_api(ctx)?; - Ok(()) - } - fn get_doc_fragment(&self) -> Option { - [ - bevy_a11y::BevyA11YAPIProvider.get_doc_fragment(), - bevy_ecs::BevyEcsAPIProvider.get_doc_fragment(), - bevy_transform::BevyTransformAPIProvider.get_doc_fragment(), - bevy_math::BevyMathAPIProvider.get_doc_fragment(), - bevy_input::BevyInputAPIProvider.get_doc_fragment(), - bevy_core::BevyCoreAPIProvider.get_doc_fragment(), - bevy_time::BevyTimeAPIProvider.get_doc_fragment(), - bevy_hierarchy::BevyHierarchyAPIProvider.get_doc_fragment(), - bevy_window::BevyWindowAPIProvider.get_doc_fragment(), - bevy_reflect::BevyReflectAPIProvider.get_doc_fragment(), - ] - .into_iter() - .filter_map(|a: Option<_>| a) - .fold( - None, - |a, b| match a { - Some(a) => Some(a.merge(b)), - None => Some(b), - }, - ) - } - fn setup_script( - &mut self, - script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn setup_script_runtime( - &mut self, - world_ptr: bevy_mod_scripting_core::world::WorldPointer, - _script_data: &bevy_mod_scripting_core::hosts::ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), bevy_mod_scripting_core::error::ScriptError> { - Ok(()) - } - fn register_with_app(&self, app: &mut bevy::app::App) { - bevy_a11y::BevyA11YAPIProvider.register_with_app(app); - bevy_ecs::BevyEcsAPIProvider.register_with_app(app); - bevy_transform::BevyTransformAPIProvider.register_with_app(app); - bevy_math::BevyMathAPIProvider.register_with_app(app); - bevy_input::BevyInputAPIProvider.register_with_app(app); - bevy_core::BevyCoreAPIProvider.register_with_app(app); - bevy_time::BevyTimeAPIProvider.register_with_app(app); - bevy_hierarchy::BevyHierarchyAPIProvider.register_with_app(app); - bevy_window::BevyWindowAPIProvider.register_with_app(app); - bevy_reflect::BevyReflectAPIProvider.register_with_app(app); +pub(crate) mod bevy_a11y; +pub(crate) mod bevy_ecs; +pub(crate) mod bevy_transform; +pub(crate) mod bevy_math; +pub(crate) mod bevy_input; +pub(crate) mod bevy_core; +pub(crate) mod bevy_time; +pub(crate) mod bevy_hierarchy; +pub(crate) mod bevy_window; +pub(crate) mod bevy_reflect; +pub struct LuaBevyScriptingPlugin; +impl bevy::app::Plugin for LuaBevyScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + bevy_a11y::BevyA11YScriptingPlugin.build(app); + bevy_ecs::BevyEcsScriptingPlugin.build(app); + bevy_transform::BevyTransformScriptingPlugin.build(app); + bevy_math::BevyMathScriptingPlugin.build(app); + bevy_input::BevyInputScriptingPlugin.build(app); + bevy_core::BevyCoreScriptingPlugin.build(app); + bevy_time::BevyTimeScriptingPlugin.build(app); + bevy_hierarchy::BevyHierarchyScriptingPlugin.build(app); + bevy_window::BevyWindowScriptingPlugin.build(app); + bevy_reflect::BevyReflectScriptingPlugin.build(app); } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs new file mode 100644 index 0000000000..8fc5fad8cb --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs @@ -0,0 +1,189 @@ +//! Set of traits used to define how types are turned into and from proxies in Lua. +//! Proxies can either be logical "copies" or owned "direct representations" of the instance, or references to one via the [`bevy_mod_scripting_core::bindings::ReflectReference`] construct. + +use bevy::reflect::{FromReflect, Reflect, TypeRegistry}; +use bevy_mod_scripting_core::{ + bindings::{ + Proxy, ReflectAllocator, ReflectRefMutProxy, ReflectRefProxy, ReflectReference, + ReflectValProxy, Unproxy, ValProxy, WorldAccessGuard, WorldAccessUnit, WorldAccessWrite, + }, + error::{ScriptError, ScriptResult}, +}; +use tealr::{ + mlu::mlua::{Error, FromLua, IntoLua, Lua, Value}, + ToTypename, +}; + +/// Local trait alias for the [`Proxied`] trait. +pub trait LuaProxied { + type Proxy; +} + +/// Convenience for proxying a type into lua via itself without implementing [`Proxy`] on it. +/// Converts to Lua via T's implementation of IntoLua directly +pub struct LuaIdentityProxy(pub Option); + +impl Proxy for LuaIdentityProxy { + type Input<'i> = T; + fn proxy<'i>(value: Self::Input<'i>) -> ScriptResult { + Ok(Self(Some(value))) + } +} + +impl Unproxy for LuaIdentityProxy { + type Output<'o> = T where + Self: 'o; + + fn unproxy<'o>(&'o mut self) -> ScriptResult> { + Ok(self + .0 + .take() + .expect("IdentityProxy was already unproxied before")) + } +} + +impl ToTypename for LuaIdentityProxy { + fn to_typename() -> tealr::Type { + T::to_typename() + } +} + +impl<'a, T: IntoLua<'a>> IntoLua<'a> for LuaIdentityProxy { + fn into_lua(self, lua: &'a Lua) -> tealr::mlu::mlua::prelude::LuaResult> { + self.0.into_lua(lua) + } +} + +impl<'a, T: FromLua<'a>> FromLua<'a> for LuaIdentityProxy { + fn from_lua(value: Value<'a>, lua: &'a Lua) -> Result { + Ok(Self(Some(T::from_lua(value, lua)?))) + } +} + +/// Proxy which uses [`ValProxy`] to represent the type in Lua. Requires that the type implements [`LuaProxied`] and that the proxy implements [`From`] for the type. +/// +/// Used for types which are copied into lua rather than references to originals in the world. +/// Use when your type does not implement Reflect or if it's a simple type that can be copied into lua. +pub struct LuaValProxy(pub ValProxy); + +/// Proxy which uses [`ReflectValProxy`] to represent the type in Lua. Requires that the type implements [`LuaProxied`] and [`FromReflect`] and that the proxy implements [`AsRef`]. +/// Think of the proxy as just a container for a [`ReflectReference`]. +/// +/// Semantically equivalent to `T`, use it where you would use the `T` type. +pub struct LuaReflectValProxy(pub ReflectValProxy); + +/// Proxy which uses [`ReflectRefProxy`] to represent the type in Lua. Requires that the type implements [`LuaProxied`] and [`Reflect`] and that the proxy implements [`AsRef`]. +/// Think of the proxy as just a container for a [`ReflectReference`]. +/// +/// Semantically equivalent to `&T`, use it where you would use the `&T` type. +pub struct LuaReflectRefProxy(pub ReflectRefProxy); + +/// Proxy which uses [`ReflectRefMutProxy`] to represent the type in Lua. Requires that the type implements [`LuaProxied`] and [`Reflect`] and that the proxy implements [`AsRef`]. +/// Think of the proxy as just a container for a [`ReflectReference`]. +/// +/// Semantically equivalent to `&mut T`, use it where you would use the `&mut T` type. +pub struct LuaReflectRefMutProxy(pub ReflectRefMutProxy); + +macro_rules! impl_lua_unproxy { + ($ty:ident as $as:ident ($generic:tt) $($bound_var:path : ($($bounds:tt)+),)*) => { + impl <$generic> Unproxy for $ty<$generic> + where + $($bound_var : $($bounds)+),* + { + type Output<'b> = <$as<$generic,$generic::Proxy> as Unproxy>::Output<'b> where Self: 'b; + + fn collect_accesses<'w>( + &self, + guard: &WorldAccessGuard<'w>, + accesses: &mut smallvec::SmallVec<[WorldAccessWrite<'w>; 1]>, + ) -> ScriptResult<()> { + self.0.collect_accesses(guard, accesses) + } + + fn unproxy(&mut self) -> ScriptResult> { + self.0.unproxy() + } + + unsafe fn unproxy_with_world<'w,'o>( + &'o mut self, + guard: &WorldAccessGuard<'w>, + accesses: &'o [WorldAccessUnit<'w>], + type_registry: &TypeRegistry, + allocator: &'o ReflectAllocator, + ) -> ScriptResult> { + self.0 + .unproxy_with_world(guard, accesses, type_registry, allocator) + } + + fn accesses_len(&self) -> usize { + self.0.accesses_len() + } + } + + impl<'lua, $generic: LuaProxied> FromLua<'lua> for $ty<$generic> + where + $generic::Proxy: FromLua<'lua>, + { + fn from_lua(value: Value<'lua>, lua: &'lua Lua) -> Result { + let inner: $generic::Proxy = $generic::Proxy::from_lua(value, lua)?; + let inner = $as::<$generic,$generic::Proxy>::new(inner); + Ok(Self(inner)) + } + } + + impl<'lua, $generic: LuaProxied> IntoLua<'lua> for $ty<$generic> + where + $generic::Proxy: IntoLua<'lua>, + { + fn into_lua(self, lua: &'lua Lua) -> tealr::mlu::mlua::prelude::LuaResult> { + self.0.0.into_lua(lua) + } + } + + impl ToTypename for $ty where T::Proxy: ToTypename { + fn to_typename() -> tealr::Type { + T::Proxy::to_typename() + } + } + }; +} + +macro_rules! impl_lua_proxy { + ($ty:ident as $as:ident => $generic:tt : $($bounds:path),* $(| T::Proxy: $($proxy_bounds:tt)*)?) => { + impl<$generic> bevy_mod_scripting_core::bindings::Proxy for $ty<$generic> + where + T::Proxy: $($($proxy_bounds)*)?, + T: $($bounds+)*, + { + type Input<'i>=<$as<$generic, $generic::Proxy> as bevy_mod_scripting_core::bindings::Proxy>::Input<'i>; + fn proxy<'i>(value: Self::Input<'i>) -> ScriptResult { + Ok(Self($as::<$generic,$generic::Proxy>::proxy(value)?)) + } + } + + + }; +} + +impl_lua_proxy!(LuaValProxy as ValProxy => T : LuaProxied | T::Proxy: From); +impl_lua_proxy!(LuaReflectValProxy as ReflectValProxy => T : LuaProxied,Reflect | T::Proxy: From ); + +impl_lua_unproxy!(LuaValProxy as ValProxy (T) + T: (LuaProxied), + T: (for <'l> From<&'l T::Proxy>), +); +impl_lua_unproxy!(LuaReflectValProxy as ReflectValProxy (T) + T: (FromReflect), + T: (LuaProxied), + T::Proxy: (AsRef), +); +impl_lua_unproxy!(LuaReflectRefProxy as ReflectRefProxy (T) + T: (LuaProxied), + T: (Reflect), + T::Proxy: (AsRef), +); +impl_lua_unproxy!(LuaReflectRefMutProxy as ReflectRefMutProxy (T) + T: (LuaProxied), + T: (Reflect), + T::Proxy: (AsRef), +); diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs new file mode 100644 index 0000000000..607ecd239d --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs @@ -0,0 +1,428 @@ +use std::{any::Any, error::Error}; + +use bevy::{ + ecs::{reflect::AppTypeRegistry, world::Mut}, + reflect::{OffsetAccess, ParsedPath, ReflectFromReflect}, +}; +use bevy_mod_scripting_core::{ + bindings::{ReflectAllocator, ReflectReference, Unproxy, WorldCallbackAccess}, + error::ScriptError, +}; +use tealr::mlu::{ + mlua::{self, FromLua, IntoLua, Lua, MetaMethod, UserData, Value}, + TealData, +}; + +use crate::{impl_userdata_from_lua, ReflectLuaProxied, ReflectLuaValue}; + +use super::{ + proxy::{LuaProxied, LuaValProxy}, + world::GetWorld, +}; + +/// Lua UserData wrapper for [`bevy_mod_scripting_core::bindings::ReflectReference`]. +/// Acts as a lua reflection interface. Any value which is registered in the type registry can be interacted with using this type. +#[derive(Debug, Clone, tealr::mlu::UserData, tealr::ToTypename)] +pub struct LuaReflectReference(pub ReflectReference); + +impl LuaReflectReference { + /// Queries the reflection system for a proxy registration for the underlying type. + /// If found will convert to lua using this proxy + /// If not found will use ::into_lua to convert to lua + pub fn to_lua_proxy(self, lua: &Lua) -> Result, mlua::Error> { + // note we do not need to refer to LuaWorld here, it does not matter what the proxy is, that's pretty neat, + let world = lua.get_world()?; + // TODO: i don't like the pingponging between errors here, need something more ergonomic + let result: Result = + world.with_resource(|world, type_registry: Mut| { + world.with_resource(|world, allocator: Mut| { + let type_registry = type_registry.read(); + // first we need the type id of the pointed to object to figure out how to work with it + let type_id = + self.0 + .with_reflect(world, &type_registry, Some(&allocator), |r| r.type_id()); + if let Some(type_data) = type_registry.get_type_data::(type_id) + { + self.0 + .with_reflect(world, &type_registry, Some(&allocator), |r| { + Ok((type_data.into_value)(r, lua)?) + }) + } else if let Some(type_data) = + type_registry.get_type_data::(type_id) + { + Ok((type_data.into_proxy)(self.0.clone(), lua)?) + } else { + Ok(self.clone().into_lua(lua)?) + } + }) + }); + result.map_err(mlua::Error::external) + } + + pub fn set_with_lua_proxy(&self, lua: &Lua, value: Value) -> Result<(), mlua::Error> { + let world = lua.get_world()?; + let result: Result<(), ScriptError> = + world.with_resource(|world, type_registry: Mut| { + world.with_resource(|world, allocator: Mut| { + let type_registry = type_registry.read(); + let type_id = + self.0 + .with_reflect(world, &type_registry, Some(&allocator), |r| r.type_id()); + + if let Some(type_data) = type_registry.get_type_data::(type_id) + { + self.0 + .with_reflect_mut(world, &type_registry, Some(&allocator), |r| { + Ok((type_data.set_value)(r, value, lua)?) + }) + } else if let Some(type_data) = + type_registry.get_type_data::(type_id) + { + let other = (type_data.from_proxy)(value, lua)?; + + // first we need to get a copy of the other value + let other = other + .with_reflect(world, &type_registry, Some(&allocator), |r| { + type_registry + .get_type_data::(r.type_id()) + .and_then(|from_reflect_td| from_reflect_td.from_reflect(r)) + }) + .ok_or_else(|| { + ScriptError::new_reflection_error(format!( + "Failed to call ReflectFromReflect for type id: {:?}", + type_registry.get_type_info(type_id).map(|t| t.type_path()) + )) + })?; + + // now we can set it + self.0 + .with_reflect_mut(world, &type_registry, Some(&allocator), |r| { + r.try_apply(other.as_partial_reflect()).map_err(|e| { + ScriptError::new_runtime_error(format!( + "Invalid assignment `{:?}` = `{:?}`. Wrong type.", + self.0.clone(), + e, + )) + }) + // r.set(other).map_err(|e| { + // ScriptError::new_runtime_error(format!( + // "Invalid assignment `{:?}` = `{:?}`. Wrong type.", + // self.0.clone(), + // e, + // )) + // }) + })?; + Ok(()) + } else { + Err(ScriptError::new_runtime_error(format!( + "Invalid assignment `{:?}` = `{:?}`. Wrong type.", + self.0.clone(), + value, + ))) + } + }) + }); + + result.map_err(mlua::Error::external) + } + + /// Adjusts all the numeric accesses in the path from 1-indexed to 0-indexed + pub fn to_host_index(path: &mut ParsedPath) { + path.0.iter_mut().for_each(|a| match a.access { + bevy::reflect::Access::FieldIndex(ref mut i) => *i -= 1, + bevy::reflect::Access::TupleIndex(ref mut i) => *i -= 1, + bevy::reflect::Access::ListIndex(ref mut i) => *i -= 1, + _ => {} + }); + } + + /// Adjusts all the numeric accesses in the path from 0-indexed to 1-indexed + pub fn from_host_index(path: &mut ParsedPath) { + path.0.iter_mut().for_each(|a| match a.access { + bevy::reflect::Access::FieldIndex(ref mut i) => *i += 1, + bevy::reflect::Access::TupleIndex(ref mut i) => *i += 1, + bevy::reflect::Access::ListIndex(ref mut i) => *i += 1, + _ => {} + }); + } + + pub fn parse_value_index(value: Value) -> Result { + if let Some(num) = value.as_usize() { + Ok(vec![OffsetAccess { + access: bevy::reflect::Access::ListIndex(num), + offset: Some(1), + }] + .into()) + } else if let Some(key) = value.as_str() { + if let Some(tuple_struct_index) = key.strip_prefix("_") { + if let Ok(index) = tuple_struct_index.parse::() { + return Ok(vec![OffsetAccess { + access: bevy::reflect::Access::TupleIndex(index), + offset: Some(1), + }] + .into()); + } + } + + ParsedPath::parse(key).map_err(|e| mlua::Error::external(e.to_string())) + } else { + Err(mlua::Error::external("Invalid index")) + } + } +} + +impl_userdata_from_lua!(LuaReflectReference); + +impl LuaProxied for ReflectReference { + type Proxy = LuaReflectReference; +} + +impl TealData for LuaReflectReference { + fn add_methods<'lua, T: tealr::mlu::TealDataMethods<'lua, Self>>(m: &mut T) { + m.add_meta_function( + MetaMethod::Index, + |l, (mut self_, key): (LuaReflectReference, Value)| { + // catchall, parse the path + let mut elem = Self::parse_value_index(key)?; + Self::to_host_index(&mut elem); + self_.0.index_path(elem); + self_.to_lua_proxy(l) + }, + ); + m.add_meta_function( + MetaMethod::NewIndex, + |l, (mut self_, key, value): (LuaReflectReference, Value, Value)| { + let mut elem = Self::parse_value_index(key)?; + Self::to_host_index(&mut elem); + self_.0.index_path(elem); + self_.set_with_lua_proxy(l, value) + }, + ); + } +} + +#[cfg(test)] +mod test { + + use bevy::{ + app::App, + ecs::{reflect::AppTypeRegistry, world::World}, + reflect::{FromReflect, OffsetAccess, Reflect}, + }; + use bevy_mod_scripting_core::{ + bindings::ReflectAllocator, + bindings::{ReflectBase, ReflectBaseType, WorldAccessGuard, WorldCallbackAccess}, + }; + use bevy_mod_scripting_derive::LuaProxy; + + use crate::{bindings::world::LuaWorld, RegisterLua}; + + use super::*; + + #[derive(Reflect)] + struct TestStruct { + value: usize, + proxy: TestProxied, + proxies: Vec, + } + + #[derive(Reflect)] + struct TestTupleStruct(usize, TestProxied, Vec); + + #[derive(Reflect)] + enum TestTupleEnum { + Value(usize), + Proxy(TestProxied), + Proxies(Vec), + } + + #[derive(Reflect, LuaProxy)] + #[proxy(bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate")] + #[reflect(LuaProxied)] + pub struct TestProxied; + + impl PartialEq for LuaTestProxied { + fn eq(&self, other: &Self) -> bool { + self.0 == other.0 + } + } + + /// asserts that setting then indexing into a LuaReflectReference of type T with the given expression returns the expected value. + /// Provides `t and `world` globals, with t being the LuaReflectReference to the provided value. + fn assert_lua_set_get_returns< + T: Reflect, + F: Fn(ReflectReference) -> O, + O: for<'l> FromLua<'l> + for<'l> IntoLua<'l> + PartialEq + std::fmt::Debug, + >( + mut world: &mut World, + val: T, + expr: &'static str, + expected: F, + ) { + let lua = Lua::new(); + let mut allocator = ReflectAllocator::default(); + let reflect_ref = LuaReflectReference(ReflectReference::new_allocated(val, &mut allocator)); + world.insert_resource(allocator); + + WorldCallbackAccess::with_callback_access(&mut world, |access| { + let globals = lua.globals(); + globals.set("test", reflect_ref.clone()).unwrap(); + globals.set("world", LuaWorld(access.clone())).unwrap(); + globals + .set("expected", expected(reflect_ref.0.clone())) + .unwrap(); + + let lua_code = format!( + r#" + {expr} = expected + return {expr} + "# + ); + let result = lua + .load(&lua_code) + .into_function() + .unwrap_or_else(|e| panic!("Could not load lua code into function: `{e}`")) + .call(()) + .unwrap_or_else(|e| { + panic!("Could not convert expression value to expected type: `{e}`") + }); + let result: O = result; + assert_eq!(result, expected(reflect_ref.0)); + }); + } + + #[test] + fn test_index_lua_value() { + // so we have the registry and can just do this + let mut app = App::new(); + app.register_lua_value::(); + + assert_lua_set_get_returns( + app.world_mut(), + TestStruct { + value: 123, + proxy: TestProxied, + proxies: vec![], + }, + "test.value", + |_| 123usize, + ); + + let mut app = App::new(); + app.register_lua_value::(); + + assert_lua_set_get_returns( + app.world_mut(), + TestTupleStruct(123, TestProxied, vec![]), + "test._1", + |_| 123usize, + ); + + let mut app = App::new(); + app.register_lua_value::(); + + assert_lua_set_get_returns( + app.world_mut(), + TestTupleEnum::Value(123usize), + "test._1", + |_| 123usize, + ); + } + + #[test] + fn test_index_lua_proxy() { + // so we have the registry and can just do this + let mut app = App::new(); + app.register_lua_proxy::(); + + assert_lua_set_get_returns( + app.world_mut(), + TestStruct { + value: 123, + proxy: TestProxied, + proxies: vec![], + }, + "test.proxy", + |mut r| { + r.index_path(ParsedPath::parse_static("proxy").unwrap()); + LuaTestProxied(r) + }, + ); + + let mut app = App::new(); + app.register_lua_proxy::(); + + assert_lua_set_get_returns( + app.world_mut(), + TestTupleStruct(123, TestProxied, vec![]), + "test._2", + |mut r| { + r.index_path(ParsedPath::parse_static(".1").unwrap()); + LuaTestProxied(r) + }, + ); + + let mut app = App::new(); + app.register_lua_proxy::(); + + assert_lua_set_get_returns( + app.world_mut(), + TestTupleEnum::Proxy(TestProxied), + "test._1", + |mut r| { + r.index_path(ParsedPath::parse_static(".0").unwrap()); + LuaTestProxied(r) + }, + ); + } + + #[test] + fn test_index_lua_proxy_vec() { + // so we have the registry and can just do this + let mut app = App::new(); + app.register_lua_proxy::(); + + assert_lua_set_get_returns( + app.world_mut(), + TestStruct { + value: 123, + proxy: TestProxied, + proxies: vec![TestProxied], + }, + "test.proxies[1]", + |mut r| { + r.index_path(ParsedPath::parse_static("proxies").unwrap()); + r.index_path(ParsedPath::parse_static("[0]").unwrap()); + LuaTestProxied(r) + }, + ); + + let mut app = App::new(); + app.register_lua_proxy::(); + + assert_lua_set_get_returns( + app.world_mut(), + TestTupleStruct(123, TestProxied, vec![TestProxied]), + "test._3[1]", + |mut r| { + r.index_path(ParsedPath::parse_static(".2").unwrap()); + r.index_path(ParsedPath::parse_static("[0]").unwrap()); + LuaTestProxied(r) + }, + ); + + let mut app = App::new(); + app.register_lua_proxy::(); + + assert_lua_set_get_returns( + app.world_mut(), + TestTupleEnum::Proxies(vec![TestProxied]), + "test._1[1]", + |mut r| { + r.index_path(ParsedPath::parse_static(".0").unwrap()); + r.index_path(ParsedPath::parse_static("[0]").unwrap()); + LuaTestProxied(r) + }, + ); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/std.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/std.rs new file mode 100644 index 0000000000..9d6e876378 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/std.rs @@ -0,0 +1,39 @@ +use tealr::{ + mlu::{mlua::IntoLua, TealData}, + ToTypename, +}; + +pub struct LuaResult(Result); + +impl TealData for LuaResult +where + T: ToTypename + for<'l> IntoLua<'l>, + E: ToTypename + for<'l> IntoLua<'l>, +{ + fn add_methods<'lua, M: tealr::mlu::TealDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_method("is_ok", |_, this, _: ()| Ok(this.0.is_ok())); + methods.add_method("is_err", |_, this, _: ()| Ok(this.0.is_err())); + methods.add_function("unwrap", |_, this: LuaResult| match this.0 { + Ok(value) => Ok(value), + Err(_) => Err(tealr::mlu::mlua::Error::RuntimeError( + "called `LuaResult::unwrap()` on an `Err` value".to_string(), + )), + }); + methods.add_method("unwrap_err", |_, this, _: ()| match &this.0 { + Ok(_) => Err(tealr::mlu::mlua::Error::RuntimeError( + "called `LuaResult::unwrap_err()` on an `Ok` value".to_string(), + )), + Err(value) => Ok(value), + }); + } + + fn add_fields<'lua, F: tealr::mlu::TealDataFields<'lua, Self>>(_fields: &mut F) {} +} + +impl ToTypename for LuaResult { + fn to_typename() -> tealr::Type { + let t = std::any::type_name::(); + let e = std::any::type_name::(); + tealr::Type::new_single(format!("LuaResult<{t},{e}>"), tealr::KindOfType::External) + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/type_registration.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/type_registration.rs new file mode 100644 index 0000000000..357ebe7567 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/type_registration.rs @@ -0,0 +1,27 @@ +use std::sync::Arc; + +use bevy::reflect::TypeRegistration; +use bevy_mod_scripting_core::bindings::ScriptTypeRegistration; +use tealr::mlu::TealData; + +use crate::impl_userdata_from_lua; + +use super::proxy::LuaProxied; + +/// Caches information about type data +#[derive(Clone, tealr::mlu::UserData, tealr::ToTypename)] +pub struct LuaTypeRegistration(pub ScriptTypeRegistration); + +impl_userdata_from_lua!(LuaTypeRegistration); + +impl TealData for LuaTypeRegistration {} + +impl From for LuaTypeRegistration { + fn from(value: ScriptTypeRegistration) -> Self { + Self(value) + } +} + +impl LuaProxied for ScriptTypeRegistration { + type Proxy = LuaTypeRegistration; +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs new file mode 100644 index 0000000000..9c3c3c1d4a --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs @@ -0,0 +1,131 @@ +use std::sync::Arc; + +use bevy::ecs::{reflect::AppTypeRegistry, world::Mut}; +use bevy::prelude::Entity; +use bevy_mod_scripting_core::{ + bindings::{ScriptTypeRegistration, Unproxy, WorldAccessGuard, WorldCallbackAccess}, + error::ScriptError, +}; +use bevy_mod_scripting_derive::LuaProxy; +use tealr::mlu::mlua::IntoLua; +use tealr::{ + mlu::{ + mlua::{self, FromLua}, + FromToLua, TealData, + }, + ToTypename, Type, +}; + +use super::{ + providers::bevy_ecs::LuaEntity, + proxy::{LuaIdentityProxy, LuaProxied, LuaReflectValProxy, LuaValProxy}, + type_registration::LuaTypeRegistration, +}; +use crate::{impl_userdata_from_lua, impl_userdata_with_tealdata}; + +/// Lua UserData wrapper for [`bevy::ecs::world::World`] +#[derive(LuaProxy, Clone)] +#[proxy( + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + get_world_callback_access_fn = "self::LuaWorld::world_callback_access", + proxy_as_type = "self::LuaWorld", + remote = "bevy_mod_scripting_core::bindings::WorldAccessGuard<'_>", + functions [ + r#" + #[lua()] + fn add_default_component(&self, entity: LuaReflectValProxy, registration: LuaValProxy) -> Result, ScriptError>; + "#, + // r#" + // #[lua()] + // fn get_type_by_name(&self, type_name: String) -> Result; + // "#, + ] +)] +pub struct LuaWorld(pub WorldCallbackAccess); + +impl LuaWorld { + pub fn world_callback_access(self) -> WorldCallbackAccess { + self.0.clone() + } +} + +impl ToTypename for LuaWorld { + fn to_typename() -> Type { + Type::new_single("LuaWorld", tealr::KindOfType::External) + } +} + +impl LuaProxied for WorldCallbackAccess { + type Proxy = LuaWorld; +} + +impl_userdata_with_tealdata!(LuaWorld); + +// impl LuaProxied for WorldCallbackAccess { +// type Proxy = LuaWorld; +// } + +impl From<&LuaWorld> for WorldCallbackAccess { + fn from(value: &LuaWorld) -> Self { + value.0.clone() + } +} + +pub trait GetWorld { + fn get_world(&self) -> Result>, mlua::Error>; +} + +impl GetWorld for mlua::Lua { + fn get_world(&self) -> Result>, mlua::Error> { + self.globals() + .get::<_, LuaValProxy>("world")? + .unproxy() + .and_then(|guard| { + guard + .read() + .ok_or_else(|| ScriptError::new_reflection_error("Stale world access")) + }) + .map_err(mlua::Error::external) + } +} + +#[cfg(test)] +mod test { + use std::sync::Arc; + + use bevy::ecs::world::World; + use bevy_mod_scripting_core::{ + bindings::WorldAccessGuard, + bindings::{Unproxy, ValProxy}, + }; + use tealr::mlu::mlua::Lua; + + use super::*; + use crate::bindings::proxy::LuaValProxy; + use tealr::mlu::mlua::IntoLua; + + #[test] + fn test_world_from_to_lua() { + let mut world = World::new(); + let world_access_guard = Arc::new(WorldAccessGuard::new(&mut world)); + let callback_access = unsafe { + bevy_mod_scripting_core::bindings::WorldCallbackAccess::new(Arc::downgrade( + &world_access_guard, + )) + }; + let proxy = LuaValProxy::( + ValProxy::new(LuaWorld(callback_access)), + ); + + let lua = Lua::new(); + let lua_val = proxy.into_lua(&lua).unwrap(); + let mut val = + LuaValProxy::::from_lua( + lua_val, &lua, + ) + .unwrap(); + + let _val = val.unproxy().unwrap(); + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/docs.rs b/crates/languages/bevy_mod_scripting_lua/src/docs.rs index 9fbb42b0d5..7850478082 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/docs.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/docs.rs @@ -1,17 +1,14 @@ -use core::str; use std::{ - borrow::Cow, env, fs::{self, File}, io::Write, - ops::Deref, process::Command, }; //use bevy::asset::FileAssetIo; use bevy::asset::io::file::FileAssetReader; use bevy_mod_scripting_core::prelude::*; -use tealr::{NameContainer, TypeGenerator, TypeWalker}; +use tealr::{TypeGenerator, TypeWalker}; pub type TypeWalkerBuilder = fn(TypeWalker) -> TypeWalker; @@ -51,14 +48,14 @@ struct Fragment { builder: TypeWalkerBuilder, } -pub struct LuaDocFragment { +pub struct LuaDocumentationFragment { name: &'static str, walker: Vec, } /// A piece of lua documentation, /// Each piece is combined into one large documentation page, and also a single teal declaration file if the `teal` feature is enabled -impl LuaDocFragment { +impl LuaDocumentationFragment { pub fn new(name: &'static str, f: TypeWalkerBuilder) -> Self { Self { name, @@ -67,7 +64,7 @@ impl LuaDocFragment { } } -impl DocFragment for LuaDocFragment { +impl DocumentationFragment for LuaDocumentationFragment { fn name(&self) -> &'static str { self.name } @@ -77,7 +74,7 @@ impl DocFragment for LuaDocFragment { self } - fn gen_docs(self) -> Result<(), ScriptError> { + fn gen_docs(self) -> Result<(), Box> { let script_asset_path = &FileAssetReader::get_base_path() .join("assets") .join("scripts"); @@ -100,128 +97,54 @@ impl DocFragment for LuaDocFragment { // fixes bug in tealr which causes syntax errors in teal due to duplicate fields (from having both getters and setters) tw.given_types.iter_mut().for_each(|tg| { if let TypeGenerator::Record(rg) = tg { - rg.fields - .sort_by(|f1, f2| f1.name.deref().cmp(f2.name.deref())); rg.fields.dedup_by(|a, b| a.name == b.name); - rg.static_fields - .sort_by(|f1, f2| f1.name.deref().cmp(f2.name.deref())); - rg.static_fields.dedup_by(|a, b| a.name == b.name); - for field in rg.fields.iter_mut().chain(rg.static_fields.iter_mut()) { - escape_name(&mut field.name); - } - for func in rg - .functions - .iter_mut() - .chain(rg.mut_functions.iter_mut()) - .chain(rg.methods.iter_mut()) - .chain(rg.mut_methods.iter_mut()) - { - escape_name(&mut func.name); - } } }); // generate json file - let json = serde_json::to_string_pretty(&tw) - .map_err(|e| ScriptError::DocGenError(e.to_string()))?; - - // temporary fix for incompatibility in json formats - // json.remove(json.len() - 1); - // json.push_str(",\n\"tealr_version_used\": \"0.9.0-alpha3\",\n\"extra_page\": []\n}"); + let json = serde_json::to_string_pretty(&tw)?; let json_path = script_doc_dir.join(format!("{}.json", docs_name)); - File::create(json_path) - .and_then(|mut file| { - file.write_all(json.as_bytes())?; - file.flush() - }) - .map_err(|e| ScriptError::DocGenError(e.to_string()))?; - + (File::create(json_path).and_then(|mut file| { + file.write_all(json.as_bytes())?; + file.flush() + }))?; // generate doc config files if they don't exist if !script_doc_dir.join("tealr_doc_gen_config.json").exists() { let config_path = script_doc_dir.join("tealr_doc_gen_config.json"); - File::create(config_path) - .and_then(|mut file| file.write_all(DEFAULT_DOC_CONFIG(&docs_name).as_bytes())) - .map_err(|e| ScriptError::DocGenError(e.to_string()))?; + (File::create(config_path) + .and_then(|mut file| file.write_all(DEFAULT_DOC_CONFIG(&docs_name).as_bytes())))? } // generate docs - Command::new("tealr_doc_gen") + (Command::new("tealr_doc_gen") .current_dir(script_doc_dir) .args(["run"]) - .status() - .map_err(|e| ScriptError::DocGenError(e.to_string()))?; + .status())?; #[cfg(feature = "teal")] { // now manage the definition (d.tl) file let definition_directory = script_asset_path.join("types"); - fs::create_dir_all(&definition_directory).map_err(|e| { - ScriptError::DocGenError(format!( - "Could not create `{}` directories: {e}", - &definition_directory.display() - )) - })?; + (fs::create_dir_all(&definition_directory))?; let definition_file_path = script_doc_dir .join(&docs_name) .join("definitions") .join(docs_name + ".d.tl"); let output_definition_file_path = script_asset_path.join("types").join("types.d.tl"); - fs::copy(&definition_file_path, &output_definition_file_path).map_err(|e| { - ScriptError::DocGenError(format!( - "Could not copy definition file from `{}` to `{}`: {e}", - definition_file_path.display(), - output_definition_file_path.display() - )) - })?; + (fs::copy(&definition_file_path, &output_definition_file_path))?; // finally create a tlconfig.lua file if doesn't exist // we do this to avoid problems with varying teal configurations // keep em settings consistent everywhere let tl_config_path = script_asset_path.join("tlconfig.lua"); if !tl_config_path.exists() { - let mut tl_file = File::create(tl_config_path) - .map_err(|e| ScriptError::DocGenError(e.to_string()))?; - tl_file - .write_all(DEFAULT_TEAL_CONFIG.as_bytes()) - .map_err(|e| ScriptError::DocGenError(e.to_string()))?; + let mut tl_file = (File::create(tl_config_path))?; + (tl_file.write_all(DEFAULT_TEAL_CONFIG.as_bytes()))?; } } Ok(()) } } - -/// Escapes a name of a table field, if that table field is a reserved keyword. -/// -/// ## Background -/// -/// String keys in a Lua table are allowed to be anything, even reserved -/// keywords. By default when tealr generates the type definition for a table -/// field, the string it generates is `{name} : {type}`. This causes a syntax -/// error when writing a bare keyword, since `nil : {type}` is considered trying -/// to add a type to the *value* nil (which is invalid). -/// -/// To get around this tealr allows us to escape table fields using the -/// `["{name}"] : {value}` syntax. This function detects if a name is one of the -/// Lua reserved words and fixes it if so. -fn escape_name(raw: &mut NameContainer) { - // List of Lua reserved keywords - const KEYWORD_FIELDS: &[&str] = &[ - "false", "true", "nil", // Values - "and", "not", "or", // Operators - "if", "then", "else", "elseif", "end", // If-Else - "for", "in", "break", "do", "repeat", "until", "while", // Loops - "function", "return", // Funcs - "local", // Declarations - "record", // Teal extra - ]; - let Ok(name) = str::from_utf8(raw) else { - return; - }; - if KEYWORD_FIELDS.contains(&name) { - let mapped = format!("[\"{name}\"]"); - *raw = NameContainer::from(Cow::Owned(mapped)); - } -} diff --git a/crates/languages/bevy_mod_scripting_lua/src/lib.rs b/crates/languages/bevy_mod_scripting_lua/src/lib.rs index 7a5dc2990b..b0e4ba6ced 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/lib.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/lib.rs @@ -4,7 +4,7 @@ pub mod util; use bevy::{ app::{App, Plugin}, ecs::{entity::Entity, world::World}, - reflect::{FromType, GetTypeRegistration, Reflect, TypePath}, + reflect::{FromType, GetTypeRegistration, PartialReflect, Reflect, TypePath}, }; use bevy_mod_scripting_core::{ bindings::{ReflectReference, WorldCallbackAccess}, @@ -173,11 +173,10 @@ pub trait RegisterLua { T::Proxy: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, T::Proxy: From + AsRef; - fn register_lua_value( - &mut self, - ) -> &mut Self + fn register_lua_value(&mut self) -> &mut Self where - T: for<'l> IntoLua<'l> + for<'l> FromLua<'l>; + T: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, + T: Reflect + Clone + TypePath + GetTypeRegistration; } impl RegisterLua for App { @@ -192,11 +191,10 @@ impl RegisterLua for App { self.register_type_data::() } - fn register_lua_value( - &mut self, - ) -> &mut Self + fn register_lua_value(&mut self) -> &mut Self where T: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, + T: Reflect + Clone + TypePath + GetTypeRegistration, { self.register_type::(); self.register_type_data::() @@ -231,11 +229,15 @@ where /// pass by value semantics, These need to implement [`Clone`] #[derive(Clone)] pub struct ReflectLuaValue { - pub into_value: for<'l> fn(&dyn Reflect, &'l Lua) -> Result, tealr::mlu::mlua::Error>, - pub set_value: - for<'l> fn(&mut dyn Reflect, Value<'l>, &'l Lua) -> Result<(), tealr::mlu::mlua::Error>, + pub into_value: + for<'l> fn(&dyn PartialReflect, &'l Lua) -> Result, tealr::mlu::mlua::Error>, + pub set_value: for<'l> fn( + &mut dyn PartialReflect, + Value<'l>, + &'l Lua, + ) -> Result<(), tealr::mlu::mlua::Error>, pub from_value: - for<'l> fn(Value<'l>, &'l Lua) -> Result, tealr::mlu::mlua::Error>, + for<'l> fn(Value<'l>, &'l Lua) -> Result, tealr::mlu::mlua::Error>, } impl IntoLua<'l> + for<'l> FromLua<'l>> FromType @@ -243,13 +245,13 @@ impl IntoLua<'l> + for<'l> FromLua<'l>> FromType { fn from_type() -> Self { Self { - into_value: |v, l| v.downcast_ref::().unwrap().clone().into_lua(l), + into_value: |v, l| v.try_downcast_ref::().unwrap().clone().into_lua(l), set_value: |t, v, l| { - let mut t = t.downcast_mut::().unwrap(); + let t = t.try_downcast_mut::().unwrap(); *t = T::from_lua(v, l)?; Ok(()) }, - from_value: |v, l| T::from_lua(v, l).map(|v| Box::new(v) as Box), + from_value: |v, l| T::from_lua(v, l).map(|v| Box::new(v) as Box), } } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/util.rs b/crates/languages/bevy_mod_scripting_lua/src/util.rs index 9b84ba5584..2652ee2f0a 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/util.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/util.rs @@ -153,3 +153,48 @@ macro_rules! __cfg_feature_any_lua52_lua53_lua54_luajit52 { macro_rules! __cfg_feature_any_lua52_lua53_lua54_luajit52 { ( $( $tok:tt )* ) => {}; } + +#[macro_export] +macro_rules! impl_userdata_from_lua { + ($ty:ident) => { + impl<'lua> ::tealr::mlu::mlua::FromLua<'lua> for $ty { + fn from_lua( + value: ::tealr::mlu::mlua::Value<'lua>, + _lua: &::tealr::mlu::mlua::Lua, + ) -> Result { + match value { + tealr::mlu::mlua::Value::UserData(ud) => Ok(ud.borrow::()?.clone()), + _ => { + return Err(::tealr::mlu::mlua::Error::FromLuaConversionError { + from: value.type_name(), + to: stringify!($ty), + message: None, + }) + } + } + } + } + }; +} + +#[macro_export] +macro_rules! impl_userdata_with_tealdata { + ($ty:ident) => { + impl ::tealr::mlu::mlua::UserData for $ty + where + Self: ::tealr::mlu::TealData, + { + fn add_methods<'lua, T: ::tealr::mlu::mlua::UserDataMethods<'lua, Self>>( + methods: &mut T, + ) { + let mut wrapper = tealr::mlu::UserDataWrapper::from_user_data_methods(methods); + ::add_methods(&mut wrapper); + } + + fn add_fields<'lua, T: ::tealr::mlu::mlua::UserDataFields<'lua, Self>>(fields: &mut T) { + let mut wrapper = tealr::mlu::UserDataWrapper::from_user_data_fields(fields); + ::add_fields(&mut wrapper); + } + } + }; +} From 2959959e8dc6984b29f95754acf424138ac56e48 Mon Sep 17 00:00:00 2001 From: makspll Date: Wed, 13 Nov 2024 08:41:28 +0000 Subject: [PATCH 05/22] Finally get a world proxy going for lua :sparkles: --- .vscode/tasks.json | 9 +- Cargo.toml | 1 + crates/bevy_mod_scripting_derive/Cargo.toml | 7 +- .../src/bindings/proxy.rs | 56 ++- .../src/bindings/reference.rs | 12 + .../src/bindings/std.rs | 70 ++-- .../src/bindings/type_registration.rs | 16 +- .../src/bindings/world.rs | 378 ++++++++++++++++-- makefile | 2 +- 9 files changed, 479 insertions(+), 72 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 14262c18e9..ddfbb877a8 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -12,6 +12,12 @@ "type": "promptString", "description": "The crate location of this unit test", "default": "bevy_mod_scripting" + }, + { + "id": "features", + "type": "promptString", + "description": "The features to enable for this unit test", + "default": "" } ], "tasks": [ @@ -22,7 +28,8 @@ "args": [ "build_test_in_package", "PACKAGE=${input:package}", - "TEST_NAME=${input:test_name}" + "TEST_NAME=${input:test_name}", + "TEST_FEATURES=${input:features}" ] } ] diff --git a/Cargo.toml b/Cargo.toml index f515af7b42..833ae934bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -92,6 +92,7 @@ members = [ "crates/languages/bevy_mod_scripting_rhai_derive", "crates/languages/bevy_mod_scripting_rune", "crates/bevy_mod_scripting_common", + "crates/bevy_mod_scripting_derive", ] resolver = "2" exclude = ["crates/bevy_api_gen", "crates/macro_tests"] diff --git a/crates/bevy_mod_scripting_derive/Cargo.toml b/crates/bevy_mod_scripting_derive/Cargo.toml index 4540176a35..56257fb9ee 100644 --- a/crates/bevy_mod_scripting_derive/Cargo.toml +++ b/crates/bevy_mod_scripting_derive/Cargo.toml @@ -19,7 +19,12 @@ proc-macro = true [dependencies] paste = "1.0.7" darling = "0.20.3" -syn = { version = "2.0.38", features = ["full", "fold", "extra-traits"] } +syn = { version = "2.0.38", features = [ + "full", + "fold", + "extra-traits", + "visit-mut", +] } quote = "1.0.8" proc-macro2 = "1.0" convert_case = "0.5.0" diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs index 8fc5fad8cb..edee3cc14b 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs @@ -10,15 +10,67 @@ use bevy_mod_scripting_core::{ error::{ScriptError, ScriptResult}, }; use tealr::{ - mlu::mlua::{Error, FromLua, IntoLua, Lua, Value}, + mlu::mlua::{Error, FromLua, IntoLua, IntoLuaMulti, Lua, Value}, ToTypename, }; -/// Local trait alias for the [`Proxied`] trait. +use super::world::Nil; + +/// Think of this as a Local trait alias for the [`Proxy`] trait. Specifies the proxy type for a given type. pub trait LuaProxied { type Proxy; } +/// Proxy which acts exactly like `T` when converting to Lua, but provides a `ToTypename` implementation based on another type `N`. +/// Used internally basically only to support Result types in Lua directly. +/// Will be unnecessary once I get rid of tealr. +pub(crate) struct TypenameProxy(T, std::marker::PhantomData); + +impl TypenameProxy { + pub fn new(value: T) -> Self { + Self(value, std::marker::PhantomData) + } +} + +impl ToTypename for TypenameProxy { + fn to_typename() -> tealr::Type { + N::to_typename() + } +} + +impl<'a, T: IntoLuaMulti<'a>, N: ToTypename> IntoLua<'a> for TypenameProxy { + fn into_lua(self, lua: &'a Lua) -> tealr::mlu::mlua::Result> { + self.0 + .into_lua_multi(lua) + .map(|mut v| v.pop_front().unwrap()) + } +} + +/// Proxy which converts to lua by throwing the error. Can be used inside a [`Result`] to proxy into a result which will throw the error if it's an [`Err`] when converting to Lua. +pub struct ErrorProxy(E); + +impl<'a, E: Into>> IntoLua<'a> + for ErrorProxy +{ + fn into_lua(self, _: &'a Lua) -> tealr::mlu::mlua::prelude::LuaResult> { + Err(Error::external(self.0)) + } +} + +/// This should never really need to be used, but it's here so we can use the type in Lua. +impl ToTypename for ErrorProxy { + fn to_typename() -> tealr::Type { + tealr::Type::new_single("Error", tealr::KindOfType::External) + } +} + +impl>> Proxy for ErrorProxy { + type Input<'i> = E; + fn proxy<'i>(value: Self::Input<'i>) -> ScriptResult { + Ok(Self(value)) + } +} + /// Convenience for proxying a type into lua via itself without implementing [`Proxy`] on it. /// Converts to Lua via T's implementation of IntoLua directly pub struct LuaIdentityProxy(pub Option); diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs index 607ecd239d..2f5ce99331 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs @@ -177,6 +177,18 @@ impl LuaProxied for ReflectReference { type Proxy = LuaReflectReference; } +impl From for ReflectReference { + fn from(value: LuaReflectReference) -> Self { + value.0 + } +} + +impl From for LuaReflectReference { + fn from(value: ReflectReference) -> Self { + Self(value) + } +} + impl TealData for LuaReflectReference { fn add_methods<'lua, T: tealr::mlu::TealDataMethods<'lua, Self>>(m: &mut T) { m.add_meta_function( diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/std.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/std.rs index 9d6e876378..41a3e35c00 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/std.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/std.rs @@ -1,39 +1,39 @@ -use tealr::{ - mlu::{mlua::IntoLua, TealData}, - ToTypename, -}; +// use tealr::{ +// mlu::{mlua::IntoLua, TealData}, +// ToTypename, +// }; -pub struct LuaResult(Result); +// pub struct LuaResult(Result); -impl TealData for LuaResult -where - T: ToTypename + for<'l> IntoLua<'l>, - E: ToTypename + for<'l> IntoLua<'l>, -{ - fn add_methods<'lua, M: tealr::mlu::TealDataMethods<'lua, Self>>(methods: &mut M) { - methods.add_method("is_ok", |_, this, _: ()| Ok(this.0.is_ok())); - methods.add_method("is_err", |_, this, _: ()| Ok(this.0.is_err())); - methods.add_function("unwrap", |_, this: LuaResult| match this.0 { - Ok(value) => Ok(value), - Err(_) => Err(tealr::mlu::mlua::Error::RuntimeError( - "called `LuaResult::unwrap()` on an `Err` value".to_string(), - )), - }); - methods.add_method("unwrap_err", |_, this, _: ()| match &this.0 { - Ok(_) => Err(tealr::mlu::mlua::Error::RuntimeError( - "called `LuaResult::unwrap_err()` on an `Ok` value".to_string(), - )), - Err(value) => Ok(value), - }); - } +// impl TealData for LuaResult +// where +// T: ToTypename + for<'l> IntoLua<'l>, +// E: ToTypename + for<'l> IntoLua<'l>, +// { +// fn add_methods<'lua, M: tealr::mlu::TealDataMethods<'lua, Self>>(methods: &mut M) { +// methods.add_method("is_ok", |_, this, _: ()| Ok(this.0.is_ok())); +// methods.add_method("is_err", |_, this, _: ()| Ok(this.0.is_err())); +// methods.add_function("unwrap", |_, this: LuaResult| match this.0 { +// Ok(value) => Ok(value), +// Err(_) => Err(tealr::mlu::mlua::Error::RuntimeError( +// "called `LuaResult::unwrap()` on an `Err` value".to_string(), +// )), +// }); +// methods.add_method("unwrap_err", |_, this, _: ()| match &this.0 { +// Ok(_) => Err(tealr::mlu::mlua::Error::RuntimeError( +// "called `LuaResult::unwrap_err()` on an `Ok` value".to_string(), +// )), +// Err(value) => Ok(value), +// }); +// } - fn add_fields<'lua, F: tealr::mlu::TealDataFields<'lua, Self>>(_fields: &mut F) {} -} +// fn add_fields<'lua, F: tealr::mlu::TealDataFields<'lua, Self>>(_fields: &mut F) {} +// } -impl ToTypename for LuaResult { - fn to_typename() -> tealr::Type { - let t = std::any::type_name::(); - let e = std::any::type_name::(); - tealr::Type::new_single(format!("LuaResult<{t},{e}>"), tealr::KindOfType::External) - } -} +// impl ToTypename for LuaResult { +// fn to_typename() -> tealr::Type { +// let t = std::any::type_name::(); +// let e = std::any::type_name::(); +// tealr::Type::new_single(format!("LuaResult<{t},{e}>"), tealr::KindOfType::External) +// } +// } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/type_registration.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/type_registration.rs index 357ebe7567..16955f6a38 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/type_registration.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/type_registration.rs @@ -14,7 +14,15 @@ pub struct LuaTypeRegistration(pub ScriptTypeRegistration); impl_userdata_from_lua!(LuaTypeRegistration); -impl TealData for LuaTypeRegistration {} +impl TealData for LuaTypeRegistration { + fn add_fields<'lua, F: tealr::mlu::TealDataFields<'lua, Self>>(fields: &mut F) { + fields.document("The [short name](https://docs.rs/bevy/latest/bevy/reflect/struct.TypeRegistration.html#method.get_short_name) of a type"); + fields.add_field_method_get("short_name", |_, s| Ok(s.0.short_name().to_owned())); + + fields.document("The full name of the type"); + fields.add_field_method_get("type_name", |_, s| Ok(s.0.type_name())); + } +} impl From for LuaTypeRegistration { fn from(value: ScriptTypeRegistration) -> Self { @@ -22,6 +30,12 @@ impl From for LuaTypeRegistration { } } +impl From<&LuaTypeRegistration> for ScriptTypeRegistration { + fn from(value: &LuaTypeRegistration) -> Self { + todo!() + } +} + impl LuaProxied for ScriptTypeRegistration { type Proxy = LuaTypeRegistration; } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs index 9c3c3c1d4a..846f412974 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs @@ -1,9 +1,12 @@ use std::sync::Arc; -use bevy::ecs::{reflect::AppTypeRegistry, world::Mut}; +use bevy::ecs::{component::ComponentId, reflect::AppTypeRegistry, world::Mut}; use bevy::prelude::Entity; + use bevy_mod_scripting_core::{ - bindings::{ScriptTypeRegistration, Unproxy, WorldAccessGuard, WorldCallbackAccess}, + bindings::{ + ReflectReference, ScriptTypeRegistration, Unproxy, WorldAccessGuard, WorldCallbackAccess, + }, error::ScriptError, }; use bevy_mod_scripting_derive::LuaProxy; @@ -16,32 +19,25 @@ use tealr::{ ToTypename, Type, }; +use super::proxy::LuaReflectRefProxy; use super::{ providers::bevy_ecs::LuaEntity, - proxy::{LuaIdentityProxy, LuaProxied, LuaReflectValProxy, LuaValProxy}, + proxy::{ + ErrorProxy, LuaIdentityProxy, LuaProxied, LuaReflectValProxy, LuaValProxy, TypenameProxy, + }, type_registration::LuaTypeRegistration, }; use crate::{impl_userdata_from_lua, impl_userdata_with_tealdata}; -/// Lua UserData wrapper for [`bevy::ecs::world::World`] -#[derive(LuaProxy, Clone)] -#[proxy( - bms_core_path = "bevy_mod_scripting_core", - bms_lua_path = "crate", - get_world_callback_access_fn = "self::LuaWorld::world_callback_access", - proxy_as_type = "self::LuaWorld", - remote = "bevy_mod_scripting_core::bindings::WorldAccessGuard<'_>", - functions [ - r#" - #[lua()] - fn add_default_component(&self, entity: LuaReflectValProxy, registration: LuaValProxy) -> Result, ScriptError>; - "#, - // r#" - // #[lua()] - // fn get_type_by_name(&self, type_name: String) -> Result; - // "#, - ] -)] +pub struct Nil; + +impl ToTypename for Nil { + fn to_typename() -> Type { + Type::new_single("nil", tealr::KindOfType::Builtin) + } +} + +#[derive(Clone, Debug)] pub struct LuaWorld(pub WorldCallbackAccess); impl LuaWorld { @@ -56,15 +52,277 @@ impl ToTypename for LuaWorld { } } -impl LuaProxied for WorldCallbackAccess { - type Proxy = LuaWorld; +impl TealData for LuaWorld { + fn add_methods<'lua, T: tealr::mlu::TealDataMethods<'lua, Self>>(methods: &mut T) { + methods.add_method("get_type_by_name", |_, this, type_name: String| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: Option> = world + .proxy_call(type_name, |type_name| world.get_type_by_name(type_name)) + .map_err(mlua::Error::external)?; + + Ok(out) + }); + + methods.add_method( + "add_default_component", + |_, + this, + args: ( + LuaReflectValProxy, + LuaValProxy, + )| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: Result<(), ErrorProxy> = world + .proxy_call(args, |(entity, registration)| { + world.add_default_component(entity, registration) + }) + .map_err(mlua::Error::external)?; + + Ok(TypenameProxy::<_, Nil>::new(out)) + }, + ); + + methods.add_method( + "get_component", + |_, this, args: (LuaReflectValProxy, LuaReflectValProxy)| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: Result>, ErrorProxy> = + world + .proxy_call(args, |(entity, component_id)| { + world.get_component(entity, component_id) + }) + .map_err(mlua::Error::external)?; + + Ok(TypenameProxy::< + _, + Option>, + >::new(out)) + }, + ); + + methods.add_method( + "has_component", + |_, this, args: (LuaReflectValProxy, LuaReflectValProxy)| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: Result> = world + .proxy_call(args, |(entity, component_id)| { + world.has_component(entity, component_id) + }) + .map_err(mlua::Error::external)?; + + Ok(TypenameProxy::<_, bool>::new(out)) + }, + ); + + methods.add_method( + "remove_component", + |_, + this, + args: ( + LuaReflectValProxy, + LuaValProxy, + )| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: Result<(), ErrorProxy> = world + .proxy_call(args, |(entity, registration)| { + world.remove_component(entity, registration) + }) + .map_err(mlua::Error::external)?; + + Ok(TypenameProxy::<_, Nil>::new(out)) + }, + ); + + methods.add_method( + "get_resource", + |_, this, resource_id: LuaReflectValProxy| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: Result, ErrorProxy> = world + .proxy_call(resource_id, |resource_id| world.get_resource(resource_id)) + .map_err(mlua::Error::external)?; + + Ok(TypenameProxy::<_, LuaReflectRefProxy>::new(out)) + }, + ); + + methods.add_method( + "remove_resource", + |_, this, registration: LuaValProxy| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: Result<(), ErrorProxy> = world + .proxy_call(registration, |registration| { + world.remove_resource(registration) + }) + .map_err(mlua::Error::external)?; + + Ok(TypenameProxy::<_, Nil>::new(out)) + }, + ); + + methods.add_method( + "has_resource", + |_, this, resource_id: LuaReflectValProxy| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: bool = world + .proxy_call(resource_id, |resource_id| world.has_resource(resource_id)) + .map_err(mlua::Error::external)?; + + Ok(out) + }, + ); + + methods.add_method( + "get_children", + |_, this, entity: LuaReflectValProxy| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: Result>, ErrorProxy> = world + .proxy_call(entity, |entity| world.get_children(entity)) + .map_err(mlua::Error::external)?; + + Ok(TypenameProxy::<_, Vec>>::new( + out, + )) + }, + ); + + methods.add_method( + "get_parent", + |_, this, entity: LuaReflectValProxy| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: Result>, ErrorProxy> = + world + .proxy_call(entity, |entity| world.get_parent(entity)) + .map_err(mlua::Error::external)?; + + Ok(TypenameProxy::<_, Option>>::new( + out, + )) + }, + ); + + methods.add_method( + "push_children", + |_, this, args: (LuaReflectValProxy, Vec>)| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: Result<(), ErrorProxy> = world + .proxy_call(args, |(parent, children)| { + world.push_children(parent, &children) + }) + .map_err(mlua::Error::external)?; + + Ok(TypenameProxy::<_, Nil>::new(out)) + }, + ); + + methods.add_method( + "remove_children", + |_, this, args: (LuaReflectValProxy, Vec>)| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: Result<(), ErrorProxy> = world + .proxy_call(args, |(parent, children)| { + world.remove_children(parent, &children) + }) + .map_err(mlua::Error::external)?; + + Ok(TypenameProxy::<_, Nil>::new(out)) + }, + ); + + methods.add_method( + "insert_children", + |_, + this, + args: ( + LuaReflectValProxy, + usize, + Vec>, + )| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: Result<(), ErrorProxy> = world + .proxy_call(args, |(parent, index, children)| { + world.insert_children(parent, index, &children) + }) + .map_err(mlua::Error::external)?; + + Ok(TypenameProxy::<_, Nil>::new(out)) + }, + ); + + methods.add_method( + "despawn_recursive", + |_, this, entity: LuaReflectValProxy| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: Result<(), ErrorProxy> = world + .proxy_call(entity, |entity| world.despawn_recursive(entity)) + .map_err(mlua::Error::external)?; + + Ok(TypenameProxy::<_, Nil>::new(out)) + }, + ); + + methods.add_method("despawn", |_, this, entity: LuaReflectValProxy| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: Result<(), ErrorProxy> = world + .proxy_call(entity, |entity| world.despawn(entity)) + .map_err(mlua::Error::external)?; + + Ok(TypenameProxy::<_, Nil>::new(out)) + }); + + methods.add_method( + "despawn_descendants", + |_, this, entity: LuaReflectValProxy| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: Result<(), ErrorProxy> = world + .proxy_call(entity, |entity| world.despawn_descendants(entity)) + .map_err(mlua::Error::external)?; + + Ok(TypenameProxy::<_, Nil>::new(out)) + }, + ); + } + + fn add_fields<'lua, F: tealr::mlu::TealDataFields<'lua, Self>>(_fields: &mut F) {} } +impl_userdata_from_lua!(LuaWorld); impl_userdata_with_tealdata!(LuaWorld); -// impl LuaProxied for WorldCallbackAccess { -// type Proxy = LuaWorld; -// } +impl LuaProxied for WorldCallbackAccess { + type Proxy = LuaWorld; +} impl From<&LuaWorld> for WorldCallbackAccess { fn from(value: &LuaWorld) -> Self { @@ -94,10 +352,14 @@ impl GetWorld for mlua::Lua { mod test { use std::sync::Arc; - use bevy::ecs::world::World; - use bevy_mod_scripting_core::{ - bindings::WorldAccessGuard, - bindings::{Unproxy, ValProxy}, + use bevy::{ + app::App, + ecs::world::World, + prelude::{Component, Resource}, + reflect::Reflect, + }; + use bevy_mod_scripting_core::bindings::{ + ReflectAllocator, Unproxy, ValProxy, WorldAccessGuard, }; use tealr::mlu::mlua::Lua; @@ -128,4 +390,58 @@ mod test { let _val = val.unproxy().unwrap(); } + + fn lua_tests() -> Vec<(&'static str, &'static str)> { + vec![ + ( + "get_type_by_name with unregistered type returns nothing", + " + assert(world:get_type_by_name('UnregisteredType') == nil) + ", + ), + ( + "get_type_by_name with registered type returns type", + " + local type = world:get_type_by_name('TestComponent') + assert(type ~= nil) + assert(type.type_name == 'TestComponent') + assert(type.short_name == 'TestComponent') + ", + ), + ] + } + + #[derive(Component, Debug, Clone, Reflect)] + pub struct TestComponent(String); + + #[derive(Resource, Debug, Clone, Reflect)] + pub struct TestResource(String); + + /// Initializes test world for scripts + fn init_world() -> World { + let mut world = World::default(); + world.init_resource::(); + world.init_resource::(); + // add some entities + world.spawn(TestComponent("Hello".to_string())); + world.insert_resource(TestResource("World".to_string())); + world + } + + #[test] + fn world_lua_api_tests() { + // use lua assertions to test the api + + for (test_name, code) in lua_tests() { + let lua = Lua::new(); + let mut world = init_world(); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + lua.globals().set("world", LuaWorld(world.clone())).unwrap(); + + let code = lua.load(code); + code.exec() + .map_err(|e| panic!("Failed lua test: {test_name}. Error: {e}")); + }); + } + } } diff --git a/makefile b/makefile index a381dd3221..527d16560d 100644 --- a/makefile +++ b/makefile @@ -32,7 +32,7 @@ GENERATED_SRC_PATH=./crates/languages/bevy_mod_scripting_lua/src/bindings/provid GEN_BEVY_FEATURES=bevy_asset,bevy_gltf,bevy_animation,bevy_core_pipeline,bevy_ui,bevy_pbr,bevy_render,bevy_text,bevy_sprite,file_watcher,multi_threaded build_test_in_package: - @cargo test --no-run --lib --workspace $(TEST_NAME) + @cargo test --no-run --lib --package ${PACKAGE} $(TEST_NAME) --features ${TEST_FEATURES} @export OUTPUT=$$(find ./target/debug/deps/ -regex ".*${PACKAGE}[^.]*" -printf "%T@\t%Tc %6k KiB %p\n" | sort -n -r | awk '{print $$NF}' | head -1); \ mv $${OUTPUT} ./target/debug/test_binary && echo "Using: $${OUTPUT}" && ls -v ./target/debug/ | grep "test_binary" From 37eb2318d451497fac0557b700f02b3c2e3e9dfe Mon Sep 17 00:00:00 2001 From: makspll Date: Wed, 13 Nov 2024 09:24:47 +0000 Subject: [PATCH 06/22] FIRST PASSING LUA WORLD API TESTS --- .../src/bindings/proxy.rs | 22 +- .../src/bindings/reference.rs | 8 +- .../src/bindings/world.rs | 533 +++++++++--------- crates/bevy_mod_scripting_core/src/error.rs | 2 +- .../src/bindings/proxy.rs | 2 +- .../src/bindings/world.rs | 38 +- 6 files changed, 318 insertions(+), 287 deletions(-) diff --git a/crates/bevy_mod_scripting_core/src/bindings/proxy.rs b/crates/bevy_mod_scripting_core/src/bindings/proxy.rs index 04c65f8180..9bc77465a5 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/proxy.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/proxy.rs @@ -82,7 +82,7 @@ pub trait Unproxy { _guard: &WorldAccessGuard<'w>, _accesses: &'o [WorldAccessUnit<'w>], _type_registry: &TypeRegistry, - _allocator: &'o ReflectAllocator, + _allocator: &ReflectAllocator, ) -> ScriptResult> { self.unproxy() } @@ -265,7 +265,7 @@ where guard: &WorldAccessGuard<'w>, accesses: &'o [WorldAccessUnit<'w>], type_registry: &TypeRegistry, - allocator: &'o ReflectAllocator, + allocator: &ReflectAllocator, ) -> ScriptResult> { let reflect_ref: &ReflectReference = self.0.as_ref(); let access = accesses.last().ok_or_else(|| { @@ -326,7 +326,7 @@ where guard: &WorldAccessGuard<'w>, accesses: &'o [WorldAccessUnit<'w>], type_registry: &TypeRegistry, - allocator: &'o ReflectAllocator, + allocator: &ReflectAllocator, ) -> ScriptResult> { let reflect_ref: &ReflectReference = self.0.as_ref(); accesses @@ -404,7 +404,7 @@ macro_rules! impl_unproxy_via_vec { guard: &WorldAccessGuard<'w>, accesses: &'o [WorldAccessUnit<'w>], type_registry: &TypeRegistry, - allocator: &'o ReflectAllocator, + allocator: &ReflectAllocator, ) -> ScriptResult> { let mut out = Vec::with_capacity(self.len()); let mut offset = 0; @@ -523,7 +523,7 @@ impl Unproxy for Option { guard: &WorldAccessGuard<'w>, accesses: &'o [WorldAccessUnit<'w>], type_registry: &TypeRegistry, - allocator: &'o ReflectAllocator, + allocator: &ReflectAllocator, ) -> ScriptResult> { if let Some(s) = self { let inner = s.unproxy_with_world(guard, accesses, type_registry, allocator)?; @@ -565,13 +565,13 @@ impl Proxy for Option { } } -impl Proxy for Result { - type Input<'a> = Result, E>; +impl Proxy for Result { + type Input<'a> = Result, E::Input<'a>>; fn proxy(input: Self::Input<'_>) -> ScriptResult { match input { Ok(i) => Ok(Ok(T::proxy(i)?)), - Err(e) => Ok(Err(e)), + Err(e) => Ok(Err(E::proxy(e)?)), } } @@ -581,7 +581,7 @@ impl Proxy for Result { ) -> ScriptResult { match input { Ok(i) => Ok(Ok(T::proxy_with_allocator(i, _allocator)?)), - Err(e) => Ok(Err(e)), + Err(e) => Ok(Err(E::proxy_with_allocator(e, _allocator)?)), } } } @@ -601,7 +601,7 @@ impl Unproxy for Result { guard: &WorldAccessGuard<'w>, accesses: &'o [WorldAccessUnit<'w>], type_registry: &TypeRegistry, - allocator: &'o ReflectAllocator, + allocator: &ReflectAllocator, ) -> ScriptResult> { match self { Ok(s) => Ok(Ok(s.unproxy_with_world( @@ -808,7 +808,7 @@ macro_rules! impl_tuple_unproxy_proxy { _guard: &WorldAccessGuard<'w>, _accesses: &'o [WorldAccessUnit<'w>], _type_registry: &TypeRegistry, - _allocator: &'o ReflectAllocator, + _allocator: &ReflectAllocator, ) -> ScriptResult> { let mut _offset = 0; diff --git a/crates/bevy_mod_scripting_core/src/bindings/reference.rs b/crates/bevy_mod_scripting_core/src/bindings/reference.rs index b89d146d06..952b50afeb 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/reference.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/reference.rs @@ -185,7 +185,7 @@ impl ReflectReference { world: UnsafeWorldCell<'w>, access: &'c WorldAccessWrite<'w>, type_registry: &TypeRegistry, - allocator: Option<&'c ReflectAllocator>, + allocator: Option<&ReflectAllocator>, ) -> ScriptResult<&'c dyn PartialReflect> { self.expect_read_access(access, type_registry, allocator, world)?; // Safety: since we have read access to the underlying componentId we can safely access the component @@ -202,7 +202,7 @@ impl ReflectReference { world: UnsafeWorldCell<'w>, access: &'c mut WorldAccessWrite<'w>, type_registry: &TypeRegistry, - allocator: Option<&'c ReflectAllocator>, + allocator: Option<&ReflectAllocator>, ) -> ScriptResult<&'c mut dyn PartialReflect> { self.expect_write_access(access, type_registry, allocator, world)?; // Safety: since we have write access to the underlying reflect access id we can safely access the component @@ -218,7 +218,7 @@ impl ReflectReference { &self, world: UnsafeWorldCell<'w>, type_registry: &TypeRegistry, - allocator: Option<&'w ReflectAllocator>, + allocator: Option<&ReflectAllocator>, ) -> ScriptResult<&'w dyn PartialReflect> { if let ReflectBase::Owned(id) = &self.base.base_id { let allocator = @@ -266,7 +266,7 @@ impl ReflectReference { &self, world: UnsafeWorldCell<'w>, type_registry: &TypeRegistry, - allocator: Option<&'w ReflectAllocator>, + allocator: Option<&ReflectAllocator>, ) -> ScriptResult<&'w mut dyn PartialReflect> { if let ReflectBase::Owned(id) = &self.base.base_id { let allocator = allocator.ok_or_else(|| ScriptError::new_reflection_error("Allocator missing"))?; diff --git a/crates/bevy_mod_scripting_core/src/bindings/world.rs b/crates/bevy_mod_scripting_core/src/bindings/world.rs index 0e60d2478a..6b590bbab9 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/world.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/world.rs @@ -135,16 +135,10 @@ pub(crate) const CONCURRENT_ACCESS_MSG: &str = /// common world methods, see: /// - [`crate::bindings::query`] for query related functionality impl WorldCallbackAccess { - pub fn get_type_by_name(&self, type_name: &str) -> Option { + // TODO: uses `String` for type_name to avoid lifetime issues with types proxying this via macros + pub fn get_type_by_name(&self, type_name: String) -> Option { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - world.with_resource(|_, registry: Mut| { - let registry = registry.read(); - registry - .get_with_short_type_path(type_name) - .or_else(|| registry.get_with_type_path(type_name)) - .map(|registration| ScriptTypeRegistration::new(Arc::new(registration.clone()))) - }) + world.get_type_by_name(type_name) } pub fn add_default_component( @@ -153,50 +147,7 @@ impl WorldCallbackAccess { registration: ScriptTypeRegistration, ) -> ScriptResult<()> { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( - "Cannot add default component since type: `{}`, Does not have ReflectComponent data registered.", - registration.type_info().type_path() - )))?; - - // we look for ReflectDefault or ReflectFromWorld data then a ReflectComponent data - let instance = if let Some(default_td) = registration.data::() { - default_td.default() - } else if let Some(from_world_td) = registration.data::() { - if let Some(world) = world.get_whole_world_access() { - from_world_td.from_world(world) - } else { - panic!("{CONCURRENT_WORLD_ACCESS_MSG}") - } - } else { - return Err(ScriptError::new_runtime_error(format!( - "Cannot add default component since type: `{}`, Does not have ReflectDefault or ReflectFromWorld data registered.", - registration.type_info().type_path() - ))); - }; - - // TODO: this shouldn't need entire world access it feels - if let Some(world) = world.get_whole_world_access() { - let app_registry = world - .remove_resource::() - .unwrap_or_else(|| panic!("Missing type registry")); - - let mut entity = world.get_entity_mut(entity).map_err(|e| { - ScriptError::new_runtime_error(format!( - "Could not access entity: {:?}. {e}", - entity - )) - })?; - { - let registry = app_registry.read(); - component_data.insert(&mut entity, instance.as_partial_reflect(), ®istry); - } - world.insert_resource(app_registry); - } else { - panic!("{CONCURRENT_WORLD_ACCESS_MSG}") - } - - Ok(()) + world.add_default_component(entity, registration) } pub fn get_component( @@ -205,45 +156,12 @@ impl WorldCallbackAccess { component_id: ComponentId, ) -> ScriptResult> { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - let entity = world.cell.get_entity(entity).ok_or_else(|| { - ScriptError::new_runtime_error(format!("Entity does not exist: {:?}", entity)) - })?; - - let component_info = world - .cell - .components() - .get_info(component_id) - .ok_or_else(|| { - ScriptError::new_runtime_error(format!( - "Component does not exist: {:?}", - component_id - )) - })?; - - if entity.contains_id(component_id) { - Ok(Some(ReflectReference { - base: ReflectBaseType { - type_id: component_info - .type_id() - .expect("Component does not have type id"), - base_id: ReflectBase::Component(entity.id(), component_id), - }, - reflect_path: Default::default(), - })) - } else { - Ok(None) - } + world.get_component(entity, component_id) } pub fn has_component(&self, entity: Entity, component_id: ComponentId) -> ScriptResult { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - let entity = world.cell.get_entity(entity).ok_or_else(|| { - ScriptError::new_runtime_error(format!("Entity does not exist: {:?}", entity)) - })?; - - Ok(entity.contains_id(component_id)) + world.has_component(entity, component_id) } pub fn remove_component( @@ -252,129 +170,42 @@ impl WorldCallbackAccess { registration: ScriptTypeRegistration, ) -> ScriptResult<()> { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( - "Cannot remove component since type: `{}`, Does not have ReflectComponent data registered.", - registration.type_info().type_path() - )))?; - - // TODO: this shouldn't need entire world access it feels - if let Some(world) = world.get_whole_world_access() { - let mut entity = world.get_entity_mut(entity).map_err(|e| { - ScriptError::new_runtime_error(format!( - "Could not retrieve entity: {:?}. {e}", - entity - )) - })?; - - component_data.remove(&mut entity); - } else { - panic!("{CONCURRENT_WORLD_ACCESS_MSG}") - } - Ok(()) + world.remove_component(entity, registration) } pub fn get_resource(&self, resource_id: ComponentId) -> ScriptResult { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - let component_info = world - .cell - .components() - .get_info(resource_id) - .ok_or_else(|| { - ScriptError::new_runtime_error(format!( - "Resource does not exist: {:?}", - resource_id - )) - })?; - - Ok(ReflectReference { - base: ReflectBaseType { - type_id: component_info - .type_id() - .expect("Resource does not have type id"), - base_id: ReflectBase::Resource(resource_id), - }, - reflect_path: Default::default(), - }) + world.get_resource(resource_id) } pub fn remove_resource(&self, registration: ScriptTypeRegistration) -> ScriptResult<()> { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( - "Cannot remove resource since type: `{}`, Does not have ReflectResource data registered.", - registration.type_info().type_path() - )))?; - - // TODO: this shouldn't need entire world access it feels - if let Some(world) = world.get_whole_world_access() { - component_data.remove(world); - } else { - panic!("{CONCURRENT_WORLD_ACCESS_MSG}") - } - Ok(()) + world.remove_resource(registration) } pub fn has_resource(&self, resource_id: ComponentId) -> bool { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - world.cell.components().get_info(resource_id).is_some() + world.has_resource(resource_id) } pub fn get_children(&self, entity: Entity) -> ScriptResult> { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - let access = world - .get_component_access_typed::() - .unwrap_or_else(|| panic!("{CONCURRENT_ACCESS_MSG}")); - - Ok(world - .get_component::(&access, entity)? - .map(|c| c.to_vec()) - .unwrap_or_default()) + world.get_children(entity) } pub fn get_parent(&self, entity: Entity) -> ScriptResult> { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - let access = world - .get_component_access_typed::() - .unwrap_or_else(|| panic!("{CONCURRENT_ACCESS_MSG}")); - - Ok(world - .get_component::(&access, entity)? - .map(|c| c.get())) + world.get_parent(entity) } pub fn push_children(&self, parent: Entity, children: &[Entity]) -> ScriptResult<()> { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - if let Some(world) = world.get_whole_world_access() { - let mut queue = CommandQueue::default(); - let mut commands = Commands::new(&mut queue, world); - commands.entity(parent).add_children(children); - queue.apply(world); - } else { - panic!("{CONCURRENT_WORLD_ACCESS_MSG}") - } - - Ok(()) + world.push_children(parent, children) } pub fn remove_children(&self, parent: Entity, children: &[Entity]) -> ScriptResult<()> { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - if let Some(world) = world.get_whole_world_access() { - let mut queue = CommandQueue::default(); - let mut commands = Commands::new(&mut queue, world); - commands.entity(parent).remove_children(children); - queue.apply(world); - } else { - panic!("{CONCURRENT_WORLD_ACCESS_MSG}") - } - - Ok(()) + world.remove_children(parent, children) } pub fn insert_children( @@ -384,62 +215,22 @@ impl WorldCallbackAccess { children: &[Entity], ) -> ScriptResult<()> { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - if let Some(world) = world.get_whole_world_access() { - let mut queue = CommandQueue::default(); - let mut commands = Commands::new(&mut queue, world); - commands.entity(parent).insert_children(index, children); - queue.apply(world); - } else { - panic!("{CONCURRENT_WORLD_ACCESS_MSG}") - } - - Ok(()) + world.insert_children(parent, index, children) } pub fn despawn_recursive(&self, entity: Entity) -> ScriptResult<()> { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - if let Some(world) = world.get_whole_world_access() { - let mut queue = CommandQueue::default(); - let mut commands = Commands::new(&mut queue, world); - commands.entity(entity).despawn_recursive(); - queue.apply(world); - } else { - panic!("{CONCURRENT_WORLD_ACCESS_MSG}") - } - - Ok(()) + world.despawn_recursive(entity) } pub fn despawn(&self, entity: Entity) -> ScriptResult<()> { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - if let Some(world) = world.get_whole_world_access() { - let mut queue = CommandQueue::default(); - let mut commands = Commands::new(&mut queue, world); - commands.entity(entity).despawn(); - queue.apply(world); - } else { - panic!("{CONCURRENT_WORLD_ACCESS_MSG}") - } - - Ok(()) + world.despawn(entity) } pub fn despawn_descendants(&self, entity: Entity) -> ScriptResult<()> { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); - - if let Some(world) = world.get_whole_world_access() { - let mut queue = CommandQueue::default(); - let mut commands = Commands::new(&mut queue, world); - commands.entity(entity).despawn_descendants(); - queue.apply(world); - } else { - panic!("{CONCURRENT_WORLD_ACCESS_MSG}") - } - - Ok(()) + world.despawn_descendants(entity) } } @@ -638,7 +429,7 @@ impl<'w> WorldAccessGuard<'w> { }); let resource = self - .get_resource_mut::(&mut access) + .get_resource_with_access_mut::(&mut access) .expect("invariant") .expect("invariant"); let out = f(self, resource); @@ -653,29 +444,30 @@ impl<'w> WorldAccessGuard<'w> { mut proxied_input: T, f: F, ) -> ScriptResult { - self.with_resource(|world, type_registry: Mut| { - world.with_resource(|_, mut allocator: Mut| { - let type_registry = type_registry.read(); - let mut world_acceses = SmallVec::default(); - - proxied_input.collect_accesses(self, &mut world_acceses)?; - let input = unsafe { - proxied_input.unproxy_with_world( - self, - &world_acceses, - &type_registry, - &allocator, - )? - }; - let out = f(input); - - O::proxy_with_allocator(out, &mut allocator) - }) - }) + let type_registry = + self.with_resource(|_, type_registry: Mut| type_registry.clone()); + + let type_registry = type_registry.read(); + let mut world_acceses = SmallVec::default(); + + let unproxied_input = self.with_resource(|_, allocator: Mut| { + proxied_input.collect_accesses(self, &mut world_acceses)?; + unsafe { + proxied_input.unproxy_with_world(self, &world_acceses, &type_registry, &allocator) + } + })?; + + let out = f(unproxied_input); + + let proxied_output = self.with_resource(|_, mut allocator: Mut| { + O::proxy_with_allocator(out, &mut allocator) + })?; + + Ok(proxied_output) } /// Get access to the given component, this is the only way to access a component/resource safely (in the context of the world access guard) - pub fn get_component( + pub fn get_component_with_access( &self, access: &WorldAccessWrite, entity: Entity, @@ -699,7 +491,7 @@ impl<'w> WorldAccessGuard<'w> { } /// Get access to the given component, this is the only way to access a component/resource safely (in the context of the world access guard) - pub fn get_component_mut( + pub fn get_component_with_access_mut( &self, access: &mut WorldAccessWrite, entity: Entity, @@ -723,7 +515,10 @@ impl<'w> WorldAccessGuard<'w> { } /// Get access to the given resource - pub fn get_resource(&self, access: &WorldAccessWrite) -> ScriptResult> { + pub fn get_resource_with_access( + &self, + access: &WorldAccessWrite, + ) -> ScriptResult> { let resource_id = match self.cell.components().resource_id::() { Some(id) => id, None => return Ok(None), @@ -743,7 +538,7 @@ impl<'w> WorldAccessGuard<'w> { } /// Get access to the given resource, this is the only way to access a component/resource safely (in the context of the world access guard) - pub fn get_resource_mut( + pub fn get_resource_with_access_mut( &self, access: &mut WorldAccessWrite, ) -> ScriptResult>> { @@ -768,12 +563,12 @@ impl<'w> WorldAccessGuard<'w> { /// Impl block for higher level world methods impl<'w> WorldAccessGuard<'w> { - pub fn get_type_by_name(&self, type_name: &str) -> Option { + pub fn get_type_by_name(&self, type_name: String) -> Option { self.with_resource(|_, registry: Mut| { let registry = registry.read(); registry - .get_with_short_type_path(type_name) - .or_else(|| registry.get_with_type_path(type_name)) + .get_with_short_type_path(&type_name) + .or_else(|| registry.get_with_type_path(&type_name)) .map(|registration| ScriptTypeRegistration::new(Arc::new(registration.clone()))) }) } @@ -825,6 +620,220 @@ impl<'w> WorldAccessGuard<'w> { panic!("{CONCURRENT_WORLD_ACCESS_MSG}") } + Ok(()) + } + pub fn get_component( + &self, + entity: Entity, + component_id: ComponentId, + ) -> ScriptResult> { + let entity = self.cell.get_entity(entity).ok_or_else(|| { + ScriptError::new_runtime_error(format!("Entity does not exist: {:?}", entity)) + })?; + + let component_info = self + .cell + .components() + .get_info(component_id) + .ok_or_else(|| { + ScriptError::new_runtime_error(format!( + "Component does not exist: {:?}", + component_id + )) + })?; + + if entity.contains_id(component_id) { + Ok(Some(ReflectReference { + base: ReflectBaseType { + type_id: component_info + .type_id() + .expect("Component does not have type id"), + base_id: ReflectBase::Component(entity.id(), component_id), + }, + reflect_path: Default::default(), + })) + } else { + Ok(None) + } + } + + pub fn has_component(&self, entity: Entity, component_id: ComponentId) -> ScriptResult { + let entity = self.cell.get_entity(entity).ok_or_else(|| { + ScriptError::new_runtime_error(format!("Entity does not exist: {:?}", entity)) + })?; + + Ok(entity.contains_id(component_id)) + } + + pub fn remove_component( + &self, + entity: Entity, + registration: ScriptTypeRegistration, + ) -> ScriptResult<()> { + let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( + "Cannot remove component since type: `{}`, Does not have ReflectComponent data registered.", + registration.type_info().type_path() + )))?; + + // TODO: this shouldn't need entire world access it feels + if let Some(world) = self.get_whole_world_access() { + let mut entity = world.get_entity_mut(entity).map_err(|e| { + ScriptError::new_runtime_error(format!( + "Could not retrieve entity: {:?}. {e}", + entity + )) + })?; + + component_data.remove(&mut entity); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + Ok(()) + } + + pub fn get_resource(&self, resource_id: ComponentId) -> ScriptResult { + let component_info = self + .cell + .components() + .get_info(resource_id) + .ok_or_else(|| { + ScriptError::new_runtime_error(format!( + "Resource does not exist: {:?}", + resource_id + )) + })?; + + Ok(ReflectReference { + base: ReflectBaseType { + type_id: component_info + .type_id() + .expect("Resource does not have type id"), + base_id: ReflectBase::Resource(resource_id), + }, + reflect_path: Default::default(), + }) + } + + pub fn remove_resource(&self, registration: ScriptTypeRegistration) -> ScriptResult<()> { + let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( + "Cannot remove resource since type: `{}`, Does not have ReflectResource data registered.", + registration.type_info().type_path() + )))?; + + // TODO: this shouldn't need entire world access it feels + if let Some(world) = self.get_whole_world_access() { + component_data.remove(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + Ok(()) + } + + pub fn has_resource(&self, resource_id: ComponentId) -> bool { + self.cell.components().get_info(resource_id).is_some() + } + + pub fn get_children(&self, entity: Entity) -> ScriptResult> { + let access = self + .get_component_access_typed::() + .unwrap_or_else(|| panic!("{CONCURRENT_ACCESS_MSG}")); + + Ok(self + .get_component_with_access::(&access, entity)? + .map(|c| c.to_vec()) + .unwrap_or_default()) + } + + pub fn get_parent(&self, entity: Entity) -> ScriptResult> { + let access = self + .get_component_access_typed::() + .unwrap_or_else(|| panic!("{CONCURRENT_ACCESS_MSG}")); + + Ok(self + .get_component_with_access::(&access, entity)? + .map(|c| c.get())) + } + + pub fn push_children(&self, parent: Entity, children: &[Entity]) -> ScriptResult<()> { + if let Some(world) = self.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(parent).add_children(children); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn remove_children(&self, parent: Entity, children: &[Entity]) -> ScriptResult<()> { + if let Some(world) = self.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(parent).remove_children(children); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn insert_children( + &self, + parent: Entity, + index: usize, + children: &[Entity], + ) -> ScriptResult<()> { + if let Some(world) = self.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(parent).insert_children(index, children); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn despawn_recursive(&self, entity: Entity) -> ScriptResult<()> { + if let Some(world) = self.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(entity).despawn_recursive(); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn despawn(&self, entity: Entity) -> ScriptResult<()> { + if let Some(world) = self.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(entity).despawn(); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + + Ok(()) + } + + pub fn despawn_descendants(&self, entity: Entity) -> ScriptResult<()> { + if let Some(world) = self.get_whole_world_access() { + let mut queue = CommandQueue::default(); + let mut commands = Commands::new(&mut queue, world); + commands.entity(entity).despawn_descendants(); + queue.apply(world); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + Ok(()) } } @@ -1204,18 +1213,20 @@ mod test_api { use super::*; fn get_reg(world: &WorldCallbackAccess, name: &str) -> ScriptTypeRegistration { - world.get_type_by_name(name).expect("Type not found") + world + .get_type_by_name(name.to_owned()) + .expect("Type not found") } fn test_comp_reg(world: &WorldCallbackAccess) -> ScriptTypeRegistration { world - .get_type_by_name("TestComponent") + .get_type_by_name("TestComponent".to_owned()) .expect("Component not found") } fn test_resource_reg(world: &WorldCallbackAccess) -> ScriptTypeRegistration { world - .get_type_by_name("TestResource") + .get_type_by_name("TestResource".to_owned()) .expect("Resource not found") } @@ -1223,8 +1234,8 @@ mod test_api { fn test_get_type_by_name() { let (mut world, _, _) = setup_world(|_, _| {}); WorldCallbackAccess::with_callback_access(&mut world, |world| { - let comp_reg = world.get_type_by_name("TestComponent").unwrap(); - let resource_reg = world.get_type_by_name("TestResource").unwrap(); + let comp_reg = world.get_type_by_name("TestComponent".to_owned()).unwrap(); + let resource_reg = world.get_type_by_name("TestResource".to_owned()).unwrap(); assert_eq!( comp_reg.type_info().type_id(), @@ -1241,8 +1252,8 @@ mod test_api { fn test_get_type_by_name_invalid() { let (mut world, _, _) = setup_world(|_, _| {}); WorldCallbackAccess::with_callback_access(&mut world, |world| { - let comp_reg = world.get_type_by_name("x"); - let resource_reg = world.get_type_by_name("z"); + let comp_reg = world.get_type_by_name("x".to_owned()); + let resource_reg = world.get_type_by_name("z".to_owned()); assert!(comp_reg.is_none()); assert!(resource_reg.is_none()); diff --git a/crates/bevy_mod_scripting_core/src/error.rs b/crates/bevy_mod_scripting_core/src/error.rs index ad1113489a..9bcdc9127c 100644 --- a/crates/bevy_mod_scripting_core/src/error.rs +++ b/crates/bevy_mod_scripting_core/src/error.rs @@ -113,7 +113,7 @@ impl ScriptError { pub fn with_context(self, context: S) -> Self { Self(Arc::new(ScriptErrorInner { script: self.0.script.clone(), - kind: self.0.kind.clone(), + kind: self.0.kind, context: context.to_string(), reason: self.0.reason.clone(), })) diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs index edee3cc14b..f811639338 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs @@ -161,7 +161,7 @@ macro_rules! impl_lua_unproxy { guard: &WorldAccessGuard<'w>, accesses: &'o [WorldAccessUnit<'w>], type_registry: &TypeRegistry, - allocator: &'o ReflectAllocator, + allocator: &ReflectAllocator, ) -> ScriptResult> { self.0 .unproxy_with_world(guard, accesses, type_registry, allocator) diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs index 846f412974..1c52f6145a 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs @@ -391,22 +391,30 @@ mod test { let _val = val.unproxy().unwrap(); } - fn lua_tests() -> Vec<(&'static str, &'static str)> { + fn lua_tests() -> Vec<(&'static str, &'static str, u32)> { vec![ ( "get_type_by_name with unregistered type returns nothing", " assert(world:get_type_by_name('UnregisteredType') == nil) ", + line!(), ), ( - "get_type_by_name with registered type returns type", + "get_type_by_name with registered type returns correct type", " local type = world:get_type_by_name('TestComponent') - assert(type ~= nil) - assert(type.type_name == 'TestComponent') - assert(type.short_name == 'TestComponent') + + local expected = { + type_name = 'bevy_mod_scripting_lua::bindings::world::test::TestComponent', + short_name = 'TestComponent', + } + + assert(type ~= nil, 'Type not found') + assert(type.type_name == expected.type_name, 'type_name mismatch, expected: ' .. expected.type_name .. ', got: ' .. type.type_name) + assert(type.short_name == expected.short_name, 'short_name mismatch, expected: ' .. expected.short_name .. ', got: ' .. type.short_name) ", + line!(), ), ] } @@ -417,10 +425,16 @@ mod test { #[derive(Resource, Debug, Clone, Reflect)] pub struct TestResource(String); - /// Initializes test world for scripts + /// Initializes test world for tests fn init_world() -> World { let mut world = World::default(); - world.init_resource::(); + let type_registry = AppTypeRegistry::default(); + { + let mut type_registry = type_registry.write(); + type_registry.register::(); + type_registry.register::(); + } + world.insert_resource(type_registry); world.init_resource::(); // add some entities world.spawn(TestComponent("Hello".to_string())); @@ -432,15 +446,21 @@ mod test { fn world_lua_api_tests() { // use lua assertions to test the api - for (test_name, code) in lua_tests() { + for (test_name, code, line) in lua_tests() { let lua = Lua::new(); let mut world = init_world(); WorldCallbackAccess::with_callback_access(&mut world, |world| { lua.globals().set("world", LuaWorld(world.clone())).unwrap(); let code = lua.load(code); + // ide friendly link to test, i.e. crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs:139 + let filename = file!(); + let test_hyperlink = format!("{filename}:{line}"); code.exec() - .map_err(|e| panic!("Failed lua test: {test_name}. Error: {e}")); + .inspect_err(|e| { + panic!("Failed lua test: `{test_name}` at: {test_hyperlink}. Error: {e}") + }) + .unwrap(); }); } } From 8a36f8fe3071b85f35b76313651936ed0dab2545 Mon Sep 17 00:00:00 2001 From: makspll Date: Thu, 14 Nov 2024 13:09:19 +0000 Subject: [PATCH 07/22] Lua integration tests with some of the API's working! --- .rustfmt.toml | 5 + Cargo.toml | 2 + crates/bevy_mod_scripting_core/Cargo.toml | 3 + .../src/bindings/query.rs | 46 ++- .../src/bindings/reference.rs | 31 +- .../src/bindings/world.rs | 368 +++++++++--------- crates/bevy_mod_scripting_derive/src/lib.rs | 67 ++-- .../bevy_mod_scripting_lua/Cargo.toml | 8 + .../src/bindings/proxy.rs | 9 +- .../src/bindings/reference.rs | 21 +- .../src/bindings/type_registration.rs | 2 +- .../src/bindings/world.rs | 166 ++------ .../bevy_mod_scripting_lua/src/lib.rs | 36 +- ...t_no_default_or_from_world_data_errors.lua | 9 + ...efault_and_component_data_adds_default.lua | 9 + ..._with_default_no_component_data_errors.lua | 10 + ..._world_and_component_data_adds_default.lua | 9 + ...th_from_world_no_component_data_errors.lua | 10 + .../component_with_component_data.lua | 3 + .../registered_type_returns_correct_type.lua | 10 + .../unregistered_type_returns_nothing.lua | 1 + .../bevy_mod_scripting_lua/tests/lua_tests.rs | 151 +++++++ makefile | 8 +- 23 files changed, 587 insertions(+), 397 deletions(-) create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_no_default_or_from_world_data_errors.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_default_and_component_data_adds_default.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_default_no_component_data_errors.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_from_world_and_component_data_adds_default.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_from_world_no_component_data_errors.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/get_component/component_with_component_data.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/get_type_by_name/registered_type_returns_correct_type.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/get_type_by_name/unregistered_type_returns_nothing.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs diff --git a/.rustfmt.toml b/.rustfmt.toml index 6e65172c8d..9a5f6e52a8 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,3 +1,8 @@ # max_width = 60 # use_small_heuristics = "Max" # format_generated_files = false + +reorder_imports = true +# currently unsupported but want them in when stable +imports_granularity = "Crate" +group_imports = "StdExternalCrate" diff --git a/Cargo.toml b/Cargo.toml index 833ae934bf..c924731e43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,6 +73,7 @@ bevy_script_api = { path = "crates/bevy_script_api", version = "0.8.0-alpha.1", bevy = { version = "0.15.0-rc.3", default-features = false } bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.8.0-alpha.1" } bevy_mod_scripting_common = { path = "crates/bevy_mod_scripting_common", version = "0.8.0-alpha.1" } +test_utils = { path = "crates/test_utils" } [dev-dependencies] bevy = { workspace = true, default-features = true } @@ -93,6 +94,7 @@ members = [ "crates/languages/bevy_mod_scripting_rune", "crates/bevy_mod_scripting_common", "crates/bevy_mod_scripting_derive", + "crates/test_utils", ] resolver = "2" exclude = ["crates/bevy_api_gen", "crates/macro_tests"] diff --git a/crates/bevy_mod_scripting_core/Cargo.toml b/crates/bevy_mod_scripting_core/Cargo.toml index ece7a115a2..c2bb18dcb8 100644 --- a/crates/bevy_mod_scripting_core/Cargo.toml +++ b/crates/bevy_mod_scripting_core/Cargo.toml @@ -27,3 +27,6 @@ paste = "1.0.7" parking_lot = "0.12.1" lockable = "0.0.8" smallvec = "1.11" + +[dev-dependencies] +test_utils = { workspace = true } diff --git a/crates/bevy_mod_scripting_core/src/bindings/query.rs b/crates/bevy_mod_scripting_core/src/bindings/query.rs index 5a7db18a45..05f728a300 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/query.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/query.rs @@ -1,56 +1,60 @@ +use super::{ReflectReference, WorldCallbackAccess}; +use crate::prelude::ScriptResult; +use bevy::{ + ecs::{component::ComponentId, entity::Entity}, + reflect::TypeRegistration, +}; use std::{any::TypeId, ops::Deref, sync::Arc}; -use bevy::{ecs::entity::Entity, reflect::TypeRegistration}; - -use super::{ReflectReference, WorldCallbackAccess, STALE_WORLD_MSG}; -use crate::prelude::{ScriptError, ScriptResult}; - /// A wrapper around a `TypeRegistration` that provides additional information about the type. /// /// This is used as a hook to a rust type from a scripting language. We should be able to easily convert between a type name and a [`ScriptTypeRegistration`]. #[derive(Clone)] -pub struct ScriptTypeRegistration(pub(crate) Arc); +pub struct ScriptTypeRegistration { + pub(crate) registration: Arc, + pub component_id: Option, +} impl ScriptTypeRegistration { - pub fn new(arc: Arc) -> Self { - Self(arc) + pub fn new(registration: Arc, component_id: Option) -> Self { + Self { + registration, + component_id, + } } #[inline(always)] pub fn short_name(&self) -> &str { - self.0.type_info().type_path_table().short_path() + self.registration.type_info().type_path_table().short_path() } #[inline(always)] pub fn type_name(&self) -> &'static str { - self.0.type_info().type_path_table().path() + self.registration.type_info().type_path_table().path() } #[inline(always)] pub fn type_id(&self) -> TypeId { - self.0.type_info().type_id() + self.registration.type_info().type_id() + } + + #[inline(always)] + pub fn component_id(&self) -> Option { + self.component_id } } impl std::fmt::Debug for ScriptTypeRegistration { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_tuple("ScriptTypeRegistration") - .field(&self.0.type_info().type_path()) + .field(&self.registration.type_info().type_path()) .finish() } } impl std::fmt::Display for ScriptTypeRegistration { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(self.0.type_info().type_path()) - } -} - -impl Deref for ScriptTypeRegistration { - type Target = Arc; - - fn deref(&self) -> &Self::Target { - &self.0 + f.write_str(self.registration.type_info().type_path()) } } diff --git a/crates/bevy_mod_scripting_core/src/bindings/reference.rs b/crates/bevy_mod_scripting_core/src/bindings/reference.rs index 952b50afeb..df7356e356 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/reference.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/reference.rs @@ -28,7 +28,8 @@ use bevy::{ }, ptr::Ptr, reflect::{ - Access, ParsedPath, PartialReflect, Reflect, ReflectFromPtr, ReflectPath, ReflectPathError, TypeInfo, TypeRegistry + Access, ParsedPath, PartialReflect, Reflect, ReflectFromPtr, ReflectPath, ReflectPathError, + TypeInfo, TypeRegistry, }, }; use smallvec::SmallVec; @@ -59,7 +60,6 @@ pub struct ReflectReference { struct UnregisteredType; impl ReflectReference { - pub fn new_allocated( value: T, allocator: &mut ReflectAllocator, @@ -269,7 +269,8 @@ impl ReflectReference { allocator: Option<&ReflectAllocator>, ) -> ScriptResult<&'w mut dyn PartialReflect> { if let ReflectBase::Owned(id) = &self.base.base_id { - let allocator = allocator.ok_or_else(|| ScriptError::new_reflection_error("Allocator missing"))?; + let allocator = + allocator.ok_or_else(|| ScriptError::new_reflection_error("Allocator missing"))?; let arc = allocator .get_mut(*id) @@ -318,7 +319,10 @@ impl ReflectReference { Ok(current) } - fn walk_path_mut<'a>(&self, root: &'a mut dyn PartialReflect) -> ScriptResult<&'a mut dyn PartialReflect> { + fn walk_path_mut<'a>( + &self, + root: &'a mut dyn PartialReflect, + ) -> ScriptResult<&'a mut dyn PartialReflect> { let mut current = root; for elem in self.reflect_path.iter() { current = elem @@ -428,8 +432,12 @@ impl ReflectionPathElem { impl From<(A, B)> for DeferredReflection where - A: Fn(&dyn PartialReflect) -> Result<&dyn PartialReflect, ReflectPathError<'static>> + Send + Sync, - B: Fn(&mut dyn PartialReflect) -> Result<&mut dyn PartialReflect, ReflectPathError<'static>> + Send + Sync, + A: Fn(&dyn PartialReflect) -> Result<&dyn PartialReflect, ReflectPathError<'static>> + + Send + + Sync, + B: Fn(&mut dyn PartialReflect) -> Result<&mut dyn PartialReflect, ReflectPathError<'static>> + + Send + + Sync, { fn from((get, get_mut): (A, B)) -> Self { Self { @@ -476,10 +484,15 @@ impl<'a> ReflectPath<'a> for &'a ReflectionPathElem { /// A ReflectPath which can perform arbitrary operations on the root object to produce a sub-reference #[derive(Clone)] pub struct DeferredReflection { - pub get: - Arc Result<&dyn PartialReflect, ReflectPathError<'static>> + Send + Sync>, + pub get: Arc< + dyn Fn(&dyn PartialReflect) -> Result<&dyn PartialReflect, ReflectPathError<'static>> + + Send + + Sync, + >, pub get_mut: Arc< - dyn Fn(&mut dyn PartialReflect) -> Result<&mut dyn PartialReflect, ReflectPathError<'static>> + dyn Fn( + &mut dyn PartialReflect, + ) -> Result<&mut dyn PartialReflect, ReflectPathError<'static>> + Send + Sync, >, diff --git a/crates/bevy_mod_scripting_core/src/bindings/world.rs b/crates/bevy_mod_scripting_core/src/bindings/world.rs index 6b590bbab9..773619b9a7 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/world.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/world.rs @@ -4,17 +4,14 @@ //! reflection gives us access to `dyn PartialReflect` objects via their type name, //! Scripting languages only really support `Clone` objects so if we want to support references, //! we need wrapper types which have owned and ref variants. -use lockable::LockableHashMap; +use lockable::{LockableHashMap, SyncLimit}; use std::{ any::TypeId, - cell::UnsafeCell, - error::Error, fmt::Debug, marker::PhantomData, - ops::Index, sync::{ - atomic::{AtomicBool, AtomicUsize, Ordering}, + atomic::{AtomicUsize, Ordering}, Arc, Weak, }, time::Duration, @@ -22,7 +19,6 @@ use std::{ use bevy::{ ecs::{ - change_detection::MutUntyped, component::{Component, ComponentId}, entity::Entity, reflect::{AppTypeRegistry, ReflectComponent, ReflectFromWorld, ReflectResource}, @@ -30,17 +26,13 @@ use bevy::{ world::{unsafe_world_cell::UnsafeWorldCell, CommandQueue, Mut, World}, }, hierarchy::{BuildChildren, Children, DespawnRecursiveExt, Parent}, - ptr::Ptr, - reflect::{ - std_traits::ReflectDefault, Access, ParsedPath, Reflect, ReflectFromPtr, ReflectPath, - ReflectPathError, TypeInfo, TypePath, TypeRegistration, TypeRegistry, - }, + reflect::{std_traits::ReflectDefault, TypeRegistry}, }; use smallvec::SmallVec; use crate::{ - bindings::{ReflectAllocation, ReflectAllocationId}, + bindings::ReflectAllocationId, prelude::{ReflectAllocator, ScriptError, ScriptResult}, }; @@ -135,6 +127,11 @@ pub(crate) const CONCURRENT_ACCESS_MSG: &str = /// common world methods, see: /// - [`crate::bindings::query`] for query related functionality impl WorldCallbackAccess { + pub fn spawn(&self) -> Entity { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + world.spawn() + } + // TODO: uses `String` for type_name to avoid lifetime issues with types proxying this via macros pub fn get_type_by_name(&self, type_name: String) -> Option { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); @@ -261,6 +258,24 @@ impl<'w> WorldAccessGuard<'w> { } } + /// Purely debugging utility to list all accesses currently held. + pub fn list_accesses(&self) -> Vec { + let keys = self.accesses.keys_with_entries_or_locked(); + + // return only those which have no value + keys.into_iter() + .filter(|k| { + let val = self + .accesses + .blocking_lock(*k, SyncLimit::no_limit()) + .unwrap(); + let val = val.value().unwrap(); + + val.is_none() + }) + .collect() + } + /// Retrieves the underlying unsafe world cell, with no additional guarantees of safety /// proceed with caution and only use this if you understand what you're doing pub fn as_unsafe_world_cell(&self) -> UnsafeWorldCell<'w> { @@ -273,6 +288,14 @@ impl<'w> WorldAccessGuard<'w> { self.cell } + /// Gets the component id of the given component or resource + pub fn get_component_id(&self, id: TypeId) -> Option { + let components = self.cell.components(); + components + .get_id(id) + .or_else(|| components.get_resource_id(id)) + } + /// Checks nobody else is currently accessing the world, and if so locks access to it until /// [`release_whole_world_access`] is called. pub fn get_whole_world_access(&self) -> Option<&mut World> { @@ -463,6 +486,11 @@ impl<'w> WorldAccessGuard<'w> { O::proxy_with_allocator(out, &mut allocator) })?; + // make sure to release all accesses + world_acceses.drain(..).for_each(|a| { + self.release_access(a); + }); + Ok(proxied_output) } @@ -563,13 +591,26 @@ impl<'w> WorldAccessGuard<'w> { /// Impl block for higher level world methods impl<'w> WorldAccessGuard<'w> { + pub fn spawn(&self) -> Entity { + if let Some(world) = self.get_whole_world_access() { + world.spawn_empty().id() + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + } + pub fn get_type_by_name(&self, type_name: String) -> Option { - self.with_resource(|_, registry: Mut| { + self.with_resource(|world, registry: Mut| { let registry = registry.read(); registry .get_with_short_type_path(&type_name) .or_else(|| registry.get_with_type_path(&type_name)) - .map(|registration| ScriptTypeRegistration::new(Arc::new(registration.clone()))) + .map(|registration| { + ScriptTypeRegistration::new( + Arc::new(registration.clone()), + world.get_component_id(registration.type_id()), + ) + }) }) } @@ -578,15 +619,16 @@ impl<'w> WorldAccessGuard<'w> { entity: Entity, registration: ScriptTypeRegistration, ) -> ScriptResult<()> { - let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( + let component_data = registration.registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( "Cannot add default component since type: `{}`, Does not have ReflectComponent data registered.", - registration.type_info().type_path() + registration.registration.type_info().type_path() )))?; // we look for ReflectDefault or ReflectFromWorld data then a ReflectComponent data - let instance = if let Some(default_td) = registration.data::() { + let instance = if let Some(default_td) = registration.registration.data::() + { default_td.default() - } else if let Some(from_world_td) = registration.data::() { + } else if let Some(from_world_td) = registration.registration.data::() { if let Some(world) = self.get_whole_world_access() { from_world_td.from_world(world) } else { @@ -595,7 +637,7 @@ impl<'w> WorldAccessGuard<'w> { } else { return Err(ScriptError::new_runtime_error(format!( "Cannot add default component since type: `{}`, Does not have ReflectDefault or ReflectFromWorld data registered.", - registration.type_info().type_path() + registration.registration.type_info().type_path() ))); }; @@ -670,9 +712,9 @@ impl<'w> WorldAccessGuard<'w> { entity: Entity, registration: ScriptTypeRegistration, ) -> ScriptResult<()> { - let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( + let component_data = registration.registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( "Cannot remove component since type: `{}`, Does not have ReflectComponent data registered.", - registration.type_info().type_path() + registration.registration.type_info().type_path() )))?; // TODO: this shouldn't need entire world access it feels @@ -715,9 +757,9 @@ impl<'w> WorldAccessGuard<'w> { } pub fn remove_resource(&self, registration: ScriptTypeRegistration) -> ScriptResult<()> { - let component_data = registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( + let component_data = registration.registration.data::().ok_or_else(|| ScriptError::new_runtime_error(format!( "Cannot remove resource since type: `{}`, Does not have ReflectResource data registered.", - registration.type_info().type_path() + registration.registration.type_info().type_path() )))?; // TODO: this shouldn't need entire world access it feels @@ -894,70 +936,45 @@ impl<'w> WorldAccessWrite<'w> { #[cfg(test)] mod test { + use crate::bindings::ScriptTypeRegistration; + use crate::prelude::ScriptErrorKind; + use bevy::ecs::system::Commands; + use bevy::hierarchy::BuildChildren; + use bevy::reflect::{ParsedPath, Reflect}; - use std::{any::Any, cell::UnsafeCell, convert::identity, sync::RwLock}; + use super::*; + use std::any::TypeId; use crate::{ + bindings::ReflectAllocator, bindings::{ DeferredReflection, ReflectBase, ReflectBaseType, ReflectReference, ReflectionPathElem, }, - bindings::{ReflectAllocation, ReflectAllocator}, }; - use super::*; - use bevy::{ - ecs::{component::Component, reflect::ReflectResource, system::Resource, world::World}, - reflect::TypeRegistryArc, + use bevy::ecs::world::World; + use test_utils::test_data::{ + setup_world, CompWithFromWorld, GetTestComponentId, TestComponent, TestResource, }; - #[derive(Component, Reflect, PartialEq, Eq, Debug)] - #[reflect(Component)] - pub(crate) struct TestComponent { - pub strings: Vec, - } - - #[derive(Resource, Reflect, Default, PartialEq, Eq, Debug)] - #[reflect(Resource)] - pub(crate) struct TestResource { - pub bytes: Vec, - } - - pub(crate) fn setup_world( - init: F, - ) -> (World, ComponentId, ComponentId) { - let mut world = World::default(); - let allocator = ReflectAllocator::default(); - - let component_id = world.register_component::(); - let resource_id = world.init_resource::(); - - let mut type_registry = TypeRegistry::new(); - type_registry.register::(); - type_registry.register::(); - - init(&mut world, &mut type_registry); - - world.insert_resource(allocator); - - world.insert_resource(AppTypeRegistry(TypeRegistryArc { - internal: Arc::new(RwLock::new(type_registry)), - })); - - (world, component_id, resource_id) + fn init_world() -> World { + setup_world(|w, _| { + w.init_resource::(); + }) } /// Tests that the given ref_ can be accessed and the value is as expected and access is released correctly (not for allocated values) fn assert_access_yields< O: Reflect + PartialEq + Debug, - F: FnOnce(&mut World, ComponentId, ComponentId) -> ReflectReference, - G: FnOnce(&WorldAccessGuard, ComponentId, ComponentId), + F: FnOnce(&mut World) -> ReflectReference, + G: FnOnce(&WorldAccessGuard), >( init: F, post_check: G, expected: O, ) { - let (mut world, component_id, resource_id) = setup_world(|_, _| {}); - let ref_ = init(&mut world, component_id, resource_id); + let mut world = init_world(); + let ref_ = init(&mut world); WorldCallbackAccess::with_callback_access(&mut world, |world| { let world = world.read().unwrap(); @@ -985,31 +1002,35 @@ mod test { }); assert!( - world.get_component_access(component_id).is_some(), + world + .get_component_access(TestComponent::test_component_id()) + .is_some(), "access to component was not release correctly" ); assert!( - world.get_resource_access(resource_id).is_some(), + world + .get_resource_access(TestResource::test_component_id()) + .is_some(), "access to component was not release correctly" ); - post_check(&world, component_id, resource_id); + post_check(&world); }); } /// Tests that setting to the expected value works as well as follow up reads give the expected value fn assert_set_then_get_yields< O: Reflect + PartialEq + Debug + Clone, - F: FnOnce(&mut World, ComponentId, ComponentId) -> ReflectReference, - G: FnOnce(&WorldAccessGuard, ComponentId, ComponentId), + F: FnOnce(&mut World) -> ReflectReference, + G: FnOnce(&WorldAccessGuard), >( init: F, post_check: G, expected: O, ) { - let (mut world, component_id, resource_id) = setup_world(|_, _| {}); - let ref_ = init(&mut world, component_id, resource_id); + let mut world = init_world(); + let ref_ = init(&mut world); WorldCallbackAccess::with_callback_access(&mut world, |world| { let world = world.read().unwrap(); // test set @@ -1055,13 +1076,13 @@ mod test { }) }) }); - post_check(&world, component_id, resource_id); + post_check(&world); }); } #[test] fn test_component_access() { - let init = |world: &mut World, component_id, _| { + let init = |world: &mut World| { let entity = world .spawn(TestComponent { strings: vec![String::from("initial")], @@ -1070,7 +1091,7 @@ mod test { ReflectReference { base: ReflectBaseType { - base_id: ReflectBase::Component(entity, component_id), + base_id: ReflectBase::Component(entity, TestComponent::test_component_id()), type_id: TypeId::of::(), }, reflect_path: vec![ @@ -1089,18 +1110,18 @@ mod test { } }; - assert_access_yields(init, |_, _, _| {}, String::from("initial")); - assert_set_then_get_yields(init, |_, _, _| {}, String::from("set")); + assert_access_yields(init, |_| {}, String::from("initial")); + assert_set_then_get_yields(init, |_| {}, String::from("set")); } #[test] fn test_resource_access() { - let init = |world: &mut World, _, resource_id| { + let init = |world: &mut World| { world.insert_resource(TestResource { bytes: vec![42u8] }); ReflectReference { base: ReflectBaseType { - base_id: ReflectBase::Resource(resource_id), + base_id: ReflectBase::Resource(TestResource::test_component_id()), type_id: TypeId::of::(), }, reflect_path: vec![ @@ -1118,13 +1139,13 @@ mod test { ], } }; - assert_access_yields(init, |_, _, _| {}, 42u8); - assert_set_then_get_yields(init, |_, _, _| {}, 69u8); + assert_access_yields(init, |_| {}, 42u8); + assert_set_then_get_yields(init, |_| {}, 69u8); } #[test] fn test_script_alloc_access() { - let init = |world: &mut World, _, _| { + let init = |world: &mut World| { let mut script_allocator = ReflectAllocator::default(); let mut ref_ = ReflectReference::new_allocated( TestComponent { @@ -1146,7 +1167,7 @@ mod test { world.insert_resource(script_allocator); ref_ }; - let post_check = |world: &WorldAccessGuard, _, _| { + let post_check = |world: &WorldAccessGuard| { assert!( world .get_allocation_access(ReflectAllocationId(0)) @@ -1197,20 +1218,6 @@ mod test { guard.release_access(access); assert_eq!(0, guard.accesses_count.load(Ordering::Relaxed)); } -} - -#[cfg(test)] -mod test_api { - use bevy::ecs::system::Commands; - use bevy::ecs::world::FromWorld; - use bevy::hierarchy::BuildChildren; - - use crate::bindings::ScriptTypeRegistration; - use crate::prelude::{ScriptErrorInner, ScriptErrorKind}; - - use super::test::{setup_world, TestComponent, TestResource}; - - use super::*; fn get_reg(world: &WorldCallbackAccess, name: &str) -> ScriptTypeRegistration { world @@ -1232,17 +1239,17 @@ mod test_api { #[test] fn test_get_type_by_name() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); WorldCallbackAccess::with_callback_access(&mut world, |world| { let comp_reg = world.get_type_by_name("TestComponent".to_owned()).unwrap(); let resource_reg = world.get_type_by_name("TestResource".to_owned()).unwrap(); assert_eq!( - comp_reg.type_info().type_id(), + comp_reg.registration.type_info().type_id(), std::any::TypeId::of::() ); assert_eq!( - resource_reg.type_info().type_id(), + resource_reg.registration.type_info().type_id(), std::any::TypeId::of::() ); }); @@ -1250,7 +1257,8 @@ mod test_api { #[test] fn test_get_type_by_name_invalid() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); + WorldCallbackAccess::with_callback_access(&mut world, |world| { let comp_reg = world.get_type_by_name("x".to_owned()); let resource_reg = world.get_type_by_name("z".to_owned()); @@ -1262,19 +1270,7 @@ mod test_api { #[test] fn test_add_default_component_from_world() { - #[derive(Reflect, Component, PartialEq, Debug)] - #[reflect(FromWorld, Component)] - struct CompWithFromWorld(pub String); - impl FromWorld for CompWithFromWorld { - fn from_world(_: &mut World) -> Self { - Self(String::from("FromWorld")) - } - } - - let (mut world, _, _) = setup_world(|w, r| { - w.register_component::(); - r.register::(); - }); + let mut world = init_world(); let entity = world.spawn_empty().id(); @@ -1291,20 +1287,7 @@ mod test_api { #[test] fn test_add_default_component_default() { - #[derive(Reflect, Component, PartialEq, Debug)] - #[reflect(Default, Component)] - struct CompWithFromWorld(pub String); - - impl Default for CompWithFromWorld { - fn default() -> Self { - Self(String::from("Default")) - } - } - - let (mut world, _, _) = setup_world(|w, r| { - w.register_component::(); - r.register::(); - }); + let mut world = init_world(); let entity = world.spawn_empty().id(); @@ -1321,14 +1304,7 @@ mod test_api { #[test] fn test_add_default_component_missing_from_world_and_default() { - #[derive(Reflect, Component, PartialEq, Debug)] - #[reflect(Component)] - struct CompWithFromWorld(pub String); - - let (mut world, _, _) = setup_world(|w, r| { - w.register_component::(); - r.register::(); - }); + let mut world = init_world(); let entity = world.spawn_empty().id(); @@ -1340,7 +1316,7 @@ mod test_api { } Err(ScriptError(inner)) => { assert_eq!(inner.kind, ScriptErrorKind::RuntimeError); - assert_eq!(inner.reason.to_string(), format!("Cannot add default component since type: `{}`, Does not have ReflectDefault or ReflectFromWorld data registered.", comp_reg.type_info().type_path())); + assert_eq!(inner.reason.to_string(), format!("Cannot add default component since type: `{}`, Does not have ReflectDefault or ReflectFromWorld data registered.", comp_reg.registration.type_info().type_path())); } } }); @@ -1348,20 +1324,7 @@ mod test_api { #[test] fn test_add_default_component_missing_component_data() { - #[derive(Reflect, Component, PartialEq, Debug)] - #[reflect(Default)] - struct CompWithFromWorld(pub String); - - impl Default for CompWithFromWorld { - fn default() -> Self { - Self(String::from("Default")) - } - } - - let (mut world, _, _) = setup_world(|w, r| { - w.register_component::(); - r.register::(); - }); + let mut world = init_world(); let entity = world.spawn_empty().id(); @@ -1373,7 +1336,7 @@ mod test_api { } Err(ScriptError(inner)) => { assert_eq!(inner.kind, ScriptErrorKind::RuntimeError); - assert_eq!(inner.reason.to_string(), format!("Cannot add default component since type: `{}`, Does not have ReflectComponent data registered.", comp_reg.type_info().type_path())); + assert_eq!(inner.reason.to_string(), format!("Cannot add default component since type: `{}`, Does not have ReflectComponent data registered.", comp_reg.registration.type_info().type_path())); } } }); @@ -1381,17 +1344,21 @@ mod test_api { #[test] fn test_get_component_existing() { - let (mut world, comp_id, _) = setup_world(|_, _| {}); + let mut world = init_world(); + let entity = world.spawn(TestComponent { strings: vec![] }).id(); WorldCallbackAccess::with_callback_access(&mut world, |world| { - let comp_ref = world.get_component(entity, comp_id).unwrap().unwrap(); + let comp_ref = world + .get_component(entity, TestComponent::test_component_id()) + .unwrap() + .unwrap(); assert_eq!( comp_ref, ReflectReference { base: ReflectBaseType { type_id: std::any::TypeId::of::(), - base_id: ReflectBase::Component(entity, comp_id), + base_id: ReflectBase::Component(entity, TestComponent::test_component_id()), }, reflect_path: Default::default(), } @@ -1401,21 +1368,25 @@ mod test_api { #[test] fn test_get_component_missing() { - let (mut world, comp_id, _) = setup_world(|_, _| {}); + let mut world = init_world(); + let entity = world.spawn_empty().id(); WorldCallbackAccess::with_callback_access(&mut world, |world| { - let comp_ref = world.get_component(entity, comp_id).unwrap(); + let comp_ref = world + .get_component(entity, TestComponent::test_component_id()) + .unwrap(); assert_eq!(comp_ref, None); }); } #[test] fn test_get_component_missing_entity() { - let (mut world, comp_id, _) = setup_world(|_, _| {}); + let mut world = init_world(); WorldCallbackAccess::with_callback_access(&mut world, |world| { - let comp_ref = world.get_component(Entity::from_raw(0), comp_id); + let comp_ref = + world.get_component(Entity::from_raw(0), TestComponent::test_component_id()); match comp_ref { Ok(_) => { panic!("Expected error") @@ -1430,7 +1401,7 @@ mod test_api { #[test] fn test_get_component_unregistered_component() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let entity = world.spawn_empty().id(); let fake_id = ComponentId::new(999); @@ -1454,7 +1425,7 @@ mod test_api { #[test] fn test_remove_component() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let entity = world .spawn(TestComponent { @@ -1476,7 +1447,7 @@ mod test_api { #[test] fn test_remove_component_empty_idempotent() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let entity = world.spawn_empty().id(); @@ -1494,7 +1465,7 @@ mod test_api { #[test] fn test_remove_component_missing_comp_registration() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let entity = world.spawn_empty().id(); @@ -1506,7 +1477,10 @@ mod test_api { } Err(e) => { assert_eq!(e.kind, ScriptErrorKind::RuntimeError); - assert_eq!(e.reason.to_string(), format!("Cannot remove component since type: `{}`, Does not have ReflectComponent data registered.", test_resource_reg(world).type_info().type_path())); + assert_eq!( + e.reason.to_string(), + format!("Cannot remove component since type: `{}`, Does not have ReflectComponent data registered.", test_resource_reg(world).registration.type_info().type_path()) + ); } } }); @@ -1519,7 +1493,8 @@ mod test_api { #[test] fn test_remove_component_missing_entity() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); + let fake_entity = Entity::from_raw(0); WorldCallbackAccess::with_callback_access(&mut world, |world| { @@ -1538,17 +1513,20 @@ mod test_api { #[test] fn test_get_resource_existing() { - let (mut world, _, resource_id) = setup_world(|_, _| {}); + let mut world = init_world(); + world.insert_resource(TestResource { bytes: vec![1] }); WorldCallbackAccess::with_callback_access(&mut world, |world| { - let comp_ref = world.get_resource(resource_id).unwrap(); + let comp_ref = world + .get_resource(TestResource::test_component_id()) + .unwrap(); assert_eq!( comp_ref, ReflectReference { base: ReflectBaseType { type_id: std::any::TypeId::of::(), - base_id: ReflectBase::Resource(resource_id), + base_id: ReflectBase::Resource(TestResource::test_component_id()), }, reflect_path: Default::default(), } @@ -1558,7 +1536,8 @@ mod test_api { #[test] fn test_get_resource_non_existing() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); + let fake_comp = ComponentId::new(999); WorldCallbackAccess::with_callback_access(&mut world, |world| { let comp_ref = world.get_resource(fake_comp); @@ -1577,7 +1556,7 @@ mod test_api { #[test] fn test_remove_resource() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); world.insert_resource(TestResource { bytes: vec![1] }); @@ -1590,7 +1569,7 @@ mod test_api { #[test] fn test_remove_resource_missing_idempotent() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); world.remove_resource::(); @@ -1603,14 +1582,14 @@ mod test_api { #[test] fn test_remove_resource_missing_resource_registration() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); WorldCallbackAccess::with_callback_access(&mut world, |world| { match world.remove_resource(test_comp_reg(world)) { Ok(_) => panic!("Expected error"), Err(e) => { assert_eq!(e.kind, ScriptErrorKind::RuntimeError); - assert_eq!(e.reason.to_string(), format!("Cannot remove resource since type: `{}`, Does not have ReflectResource data registered.", test_comp_reg(world).type_info().type_path())); + assert_eq!(e.reason.to_string(), format!("Cannot remove resource since type: `{}`, Does not have ReflectResource data registered.", test_comp_reg(world).registration.type_info().type_path())); } } }); @@ -1618,26 +1597,26 @@ mod test_api { #[test] fn test_has_resource_existing() { - let (mut world, _, res_reg) = setup_world(|_, _| {}); + let mut world = init_world(); WorldCallbackAccess::with_callback_access(&mut world, |world| { - assert!(world.has_resource(res_reg)); + assert!(world.has_resource(TestResource::test_component_id())); }); } #[test] fn test_has_resource_missing() { - let (mut world, _, res_reg) = setup_world(|_, _| {}); + let mut world = init_world(); world.remove_resource::(); WorldCallbackAccess::with_callback_access(&mut world, |world| { - assert!(world.has_resource(res_reg)); + assert!(world.has_resource(TestResource::test_component_id())); }); } #[test] fn test_get_children_1_child() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let parent = world.spawn_empty().id(); let child = world.spawn_empty().id(); @@ -1658,7 +1637,7 @@ mod test_api { expected = "Component not registered: `bevy_hierarchy::components::children::Children`" )] fn test_get_children_children_component_unregistered() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let parent = world.spawn_empty().id(); @@ -1669,7 +1648,7 @@ mod test_api { #[test] fn test_get_children_no_children() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); world.register_component::(); let parent = world.spawn_empty().id(); @@ -1682,7 +1661,7 @@ mod test_api { #[test] fn test_get_parent_1_parent() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let parent = world.spawn_empty().id(); let child = world.spawn_empty().id(); @@ -1699,7 +1678,8 @@ mod test_api { #[test] fn test_get_parent_no_parent() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); + world.register_component::(); let child = world.spawn_empty().id(); @@ -1715,7 +1695,7 @@ mod test_api { expected = "Component not registered: `bevy_hierarchy::components::parent::Parent`" )] fn test_get_parent_parent_component_unregistered() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let child = world.spawn_empty().id(); @@ -1726,7 +1706,7 @@ mod test_api { #[test] fn test_push_children_empty_entity() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let parent = world.spawn_empty().id(); let child = world.spawn_empty().id(); @@ -1742,7 +1722,7 @@ mod test_api { #[test] fn test_push_children_entity_with_1_child() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let parent = world.spawn_empty().id(); let child = world.spawn_empty().id(); @@ -1765,7 +1745,7 @@ mod test_api { #[test] fn test_remove_children_entity_with_1_child() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let parent = world.spawn_empty().id(); let child = world.spawn_empty().id(); @@ -1784,7 +1764,7 @@ mod test_api { #[test] fn test_remove_children_remove_half_children() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let parent = world.spawn_empty().id(); let child = world.spawn_empty().id(); @@ -1805,7 +1785,7 @@ mod test_api { #[test] fn test_insert_children_empty() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let parent = world.spawn_empty().id(); let child = world.spawn_empty().id(); @@ -1821,7 +1801,7 @@ mod test_api { #[test] fn test_insert_children_middle() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let parent = world.spawn_empty().id(); let child = world.spawn_empty().id(); @@ -1848,7 +1828,7 @@ mod test_api { #[test] fn test_despawn_entity() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let entity = world.spawn_empty().id(); @@ -1861,7 +1841,7 @@ mod test_api { #[test] fn test_despawn_recursive() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let parent = world.spawn_empty().id(); let child = world.spawn_empty().id(); @@ -1880,7 +1860,7 @@ mod test_api { #[test] fn test_despawn_descendants() { - let (mut world, _, _) = setup_world(|_, _| {}); + let mut world = init_world(); let parent = world.spawn_empty().id(); let child = world.spawn_empty().id(); diff --git a/crates/bevy_mod_scripting_derive/src/lib.rs b/crates/bevy_mod_scripting_derive/src/lib.rs index 6c932ffc43..62ef0e9e12 100644 --- a/crates/bevy_mod_scripting_derive/src/lib.rs +++ b/crates/bevy_mod_scripting_derive/src/lib.rs @@ -1,14 +1,13 @@ -mod input; +mod input; mod utils; use crate::{input::*, utils::doc_attribute_to_string_lit}; -use std::collections::HashMap; use darling::util::Flag; +use std::collections::HashMap; use syn::{ - spanned::Spanned, Path, Token, TraitItemFn, parse_quote, - parse_macro_input, parse_quote_spanned, DeriveInput, ExprClosure, FnArg, - punctuated::Punctuated + parse_macro_input, parse_quote, parse_quote_spanned, punctuated::Punctuated, spanned::Spanned, + DeriveInput, ExprClosure, FnArg, Path, Token, TraitItemFn, }; use darling::{FromAttributes, FromDeriveInput}; @@ -16,7 +15,6 @@ use proc_macro::TokenStream; use proc_macro2::*; use quote::*; - const SELF_ALIAS: &str = "_self"; const CTXT_ALIAS: &str = "lua"; const PROXY_PREFIX: &str = "Lua"; @@ -26,7 +24,12 @@ const PROXY_PREFIX: &str = "Lua"; /// - instead of a `&mut self` receiver we have a `_self: LuaRefMutProxy` /// - instead of a `self` receiver we have a `_self: ValLuaProxy` /// Returns true if the receiver was changed -fn standardise_receiver(receiver: &mut FnArg, target_type: &Path, bms_lua_path: &Path, proxy_as_type: Option<&Path>) -> bool { +fn standardise_receiver( + receiver: &mut FnArg, + target_type: &Path, + bms_lua_path: &Path, + proxy_as_type: Option<&Path>, +) -> bool { let replacement = if let FnArg::Receiver(receiver) = receiver { let ref_ = &receiver.reference.as_ref().map(|(amp, lifetime)| { quote_spanned! {receiver.span()=> @@ -35,12 +38,12 @@ fn standardise_receiver(receiver: &mut FnArg, target_type: &Path, bms_lua_path: }); let self_ident = syn::Ident::new(SELF_ALIAS, receiver.span()); - let self_ident_type = match proxy_as_type{ + let self_ident_type = match proxy_as_type { Some(target_type) => { quote_spanned! {receiver.span()=> #target_type } - }, + } None => { let unproxy_container_name = match (ref_.is_some(), receiver.mutability.is_some()) { (true, true) => "LuaReflectRefMutProxy", @@ -48,7 +51,7 @@ fn standardise_receiver(receiver: &mut FnArg, target_type: &Path, bms_lua_path: (false, _) => "LuaReflectValProxy", }; let unproxy_ident = syn::Ident::new(unproxy_container_name, receiver.span()); - + quote_spanned! {receiver.span()=> #bms_lua_path::bindings::proxy::#unproxy_ident::<#target_type> } @@ -123,7 +126,6 @@ fn proxy_wrap_function_def( mlua: &Path, attrs: &FunctionAttrs, ) { - // collect all args into tuple and add lua context arg let ctxt_alias = syn::Ident::new(CTXT_ALIAS, f.sig.inputs.span()); @@ -179,8 +181,6 @@ fn proxy_wrap_function_def( } else { Default::default() }; - - // change signature to take in a single args tuple instead of multiple arguments (on top of a context arg) f.sig.inputs = Punctuated::from_iter(vec![ @@ -202,13 +202,16 @@ fn proxy_wrap_function_def( syn::ReturnType::Type(_, ty) => ty.to_token_stream(), }; - // wrap function body in our unwrapping and wrapping logic, ignore pre-existing body let mut fn_call = std::panic::catch_unwind(|| { - match (&f.default, &attrs.as_trait, get_world_callback_access_fn.is_some()) { + match ( + &f.default, + &attrs.as_trait, + get_world_callback_access_fn.is_some(), + ) { (_, _, true) => quote_spanned!(span=> world.#func_name(#(#original_arg_idents),*) - ), + ), (Some(body), _, _) => quote_spanned!(span=> (||{ #body })() ), @@ -249,8 +252,7 @@ fn proxy_wrap_function_def( let mut world = <#bms_lua::bindings::proxy::LuaValProxy<#bms_core::bindings::WorldCallbackAccess> as #bms_core::bindings::Unproxy>::unproxy(&mut world).map_err(#mlua::Error::external)?; let mut world = world.read().ok_or_else(|| #mlua::Error::external("World no longer exists"))?; ) - }; - + }; f.default = Some(parse_quote_spanned! {span=> { @@ -339,10 +341,18 @@ pub fn impl_lua_proxy(input: TokenStream) -> TokenStream { let target_type_str = target_type.segments.last().unwrap().ident.to_string(); let proxy_type_ident = match meta.proxy_as_type.as_ref() { Some(proxy_as_type) => proxy_as_type.clone(), - None => meta.proxy_name.unwrap_or_else(|| format_ident!("{PROXY_PREFIX}{}", &target_type_str, span = meta.ident.span())).into(), + None => meta + .proxy_name + .unwrap_or_else(|| { + format_ident!( + "{PROXY_PREFIX}{}", + &target_type_str, + span = meta.ident.span() + ) + }) + .into(), }; - let bms_core = meta.bms_core_path.0; let bms_lua = meta.bms_lua_path.0; let tealr: Path = parse_quote_spanned!(bms_lua.span()=> @@ -444,7 +454,16 @@ pub fn impl_lua_proxy(input: TokenStream) -> TokenStream { return None; } - proxy_wrap_function_def(&mut f, &target_type, &bms_core, &bms_lua, meta.get_world_callback_access_fn.as_ref(), meta.proxy_as_type.as_ref(), &mlua, &attrs); + proxy_wrap_function_def( + &mut f, + &target_type, + &bms_core, + &bms_lua, + meta.get_world_callback_access_fn.as_ref(), + meta.proxy_as_type.as_ref(), + &mlua, + &attrs, + ); let name = match &attrs.metamethod { Some(metamethod) => quote_spanned!(metamethod.span()=> @@ -468,9 +487,9 @@ pub fn impl_lua_proxy(input: TokenStream) -> TokenStream { #[derive(Clone, Debug, #tealr::mlu::UserData, #tealr::ToTypename)] #vis struct #proxy_type_ident (pub #bms_core::bindings::ReflectReference); ) - }; + }; - let conversions = if let Some(proxy_as_type) = meta.proxy_as_type.as_ref() { + let conversions = if let Some(proxy_as_type) = meta.proxy_as_type.as_ref() { Default::default() } else { quote_spanned!(derive_input.span()=> @@ -488,7 +507,6 @@ pub fn impl_lua_proxy(input: TokenStream) -> TokenStream { ) }; - quote_spanned! {meta.ident.span()=> #definition @@ -528,4 +546,3 @@ pub fn impl_lua_proxy(input: TokenStream) -> TokenStream { } .into() } - diff --git a/crates/languages/bevy_mod_scripting_lua/Cargo.toml b/crates/languages/bevy_mod_scripting_lua/Cargo.toml index d483005013..5c7bfa10a7 100644 --- a/crates/languages/bevy_mod_scripting_lua/Cargo.toml +++ b/crates/languages/bevy_mod_scripting_lua/Cargo.toml @@ -53,3 +53,11 @@ anyhow = "1.0.75" uuid = "1.1" smol_str = "0.2.2" smallvec = "1.13" + +[dev-dependencies] +test_utils = { workspace = true } +libtest-mimic = "0.8" + +[[test]] +name = "lua_tests" +harness = false diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs index f811639338..83689e639a 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/proxy.rs @@ -42,7 +42,7 @@ impl<'a, T: IntoLuaMulti<'a>, N: ToTypename> IntoLua<'a> for TypenameProxy fn into_lua(self, lua: &'a Lua) -> tealr::mlu::mlua::Result> { self.0 .into_lua_multi(lua) - .map(|mut v| v.pop_front().unwrap()) + .map(|mut v| v.pop_front().unwrap_or_else(|| Value::Nil)) } } @@ -211,6 +211,13 @@ macro_rules! impl_lua_proxy { fn proxy<'i>(value: Self::Input<'i>) -> ScriptResult { Ok(Self($as::<$generic,$generic::Proxy>::proxy(value)?)) } + + fn proxy_with_allocator<'i>( + value: Self::Input<'i>, + allocator: &mut bevy_mod_scripting_core::bindings::ReflectAllocator, + ) -> ScriptResult { + Ok(Self($as::<$generic,$generic::Proxy>::proxy_with_allocator(value, allocator)?)) + } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs index 2f5ce99331..79903d04d2 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs @@ -1,4 +1,7 @@ -use std::{any::Any, error::Error}; +use std::{ + any::{Any, TypeId}, + error::Error, +}; use bevy::{ ecs::{reflect::AppTypeRegistry, world::Mut}, @@ -37,18 +40,28 @@ impl LuaReflectReference { world.with_resource(|world, type_registry: Mut| { world.with_resource(|world, allocator: Mut| { let type_registry = type_registry.read(); + // first we need the type id of the pointed to object to figure out how to work with it let type_id = self.0 - .with_reflect(world, &type_registry, Some(&allocator), |r| r.type_id()); - if let Some(type_data) = type_registry.get_type_data::(type_id) + .with_reflect(world, &type_registry, Some(&allocator), |r| { + r.get_represented_type_info().map(|t| t.type_id()) + }); + + // convenience, ideally we probably should just avoid lookups when no type id is here, but for now we just use a dummy type nothing will ever + // be registered for. If the type we're reflecting doesn't represent anything or a registered type, we use a generic reflect reference. + struct Dummy; + let type_id_or_dummy = type_id.unwrap_or(TypeId::of::()); + + if let Some(type_data) = + type_registry.get_type_data::(type_id_or_dummy) { self.0 .with_reflect(world, &type_registry, Some(&allocator), |r| { Ok((type_data.into_value)(r, lua)?) }) } else if let Some(type_data) = - type_registry.get_type_data::(type_id) + type_registry.get_type_data::(type_id_or_dummy) { Ok((type_data.into_proxy)(self.0.clone(), lua)?) } else { diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/type_registration.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/type_registration.rs index 16955f6a38..eba4c05d81 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/type_registration.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/type_registration.rs @@ -32,7 +32,7 @@ impl From for LuaTypeRegistration { impl From<&LuaTypeRegistration> for ScriptTypeRegistration { fn from(value: &LuaTypeRegistration) -> Self { - todo!() + value.0.clone() } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs index 1c52f6145a..9e5a0ccb6b 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs @@ -54,6 +54,28 @@ impl ToTypename for LuaWorld { impl TealData for LuaWorld { fn add_methods<'lua, T: tealr::mlu::TealDataMethods<'lua, Self>>(methods: &mut T) { + methods.add_method("_list_accesses", |_, this, ()| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let accesses = world + .list_accesses() + .into_iter() + .map(|v| format!("Access to: {v:?}")) + .collect::>(); + Ok(accesses) + }); + + methods.add_method("spawn", |_, this, ()| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let entity: LuaReflectValProxy = world + .proxy_call((), |()| world.spawn()) + .map_err(mlua::Error::external)?; + Ok(entity) + }); + methods.add_method("get_type_by_name", |_, this, type_name: String| { let world = this.0.read().ok_or_else(|| { mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) @@ -88,14 +110,22 @@ impl TealData for LuaWorld { methods.add_method( "get_component", - |_, this, args: (LuaReflectValProxy, LuaReflectValProxy)| { + |_, + this, + args: ( + LuaReflectValProxy, + LuaValProxy, + )| { let world = this.0.read().ok_or_else(|| { mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) })?; let out: Result>, ErrorProxy> = world .proxy_call(args, |(entity, component_id)| { - world.get_component(entity, component_id) + match component_id.component_id() { + Some(component_id) => world.get_component(entity, component_id), + None => Ok(None), + } }) .map_err(mlua::Error::external)?; @@ -108,13 +138,21 @@ impl TealData for LuaWorld { methods.add_method( "has_component", - |_, this, args: (LuaReflectValProxy, LuaReflectValProxy)| { + |_, + this, + args: ( + LuaReflectValProxy, + LuaValProxy, + )| { let world = this.0.read().ok_or_else(|| { mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) })?; let out: Result> = world - .proxy_call(args, |(entity, component_id)| { - world.has_component(entity, component_id) + .proxy_call(args, |(entity, registration)| { + match registration.component_id() { + Some(component_id) => world.has_component(entity, component_id), + None => Ok(false), + } }) .map_err(mlua::Error::external)?; @@ -347,121 +385,3 @@ impl GetWorld for mlua::Lua { .map_err(mlua::Error::external) } } - -#[cfg(test)] -mod test { - use std::sync::Arc; - - use bevy::{ - app::App, - ecs::world::World, - prelude::{Component, Resource}, - reflect::Reflect, - }; - use bevy_mod_scripting_core::bindings::{ - ReflectAllocator, Unproxy, ValProxy, WorldAccessGuard, - }; - use tealr::mlu::mlua::Lua; - - use super::*; - use crate::bindings::proxy::LuaValProxy; - use tealr::mlu::mlua::IntoLua; - - #[test] - fn test_world_from_to_lua() { - let mut world = World::new(); - let world_access_guard = Arc::new(WorldAccessGuard::new(&mut world)); - let callback_access = unsafe { - bevy_mod_scripting_core::bindings::WorldCallbackAccess::new(Arc::downgrade( - &world_access_guard, - )) - }; - let proxy = LuaValProxy::( - ValProxy::new(LuaWorld(callback_access)), - ); - - let lua = Lua::new(); - let lua_val = proxy.into_lua(&lua).unwrap(); - let mut val = - LuaValProxy::::from_lua( - lua_val, &lua, - ) - .unwrap(); - - let _val = val.unproxy().unwrap(); - } - - fn lua_tests() -> Vec<(&'static str, &'static str, u32)> { - vec![ - ( - "get_type_by_name with unregistered type returns nothing", - " - assert(world:get_type_by_name('UnregisteredType') == nil) - ", - line!(), - ), - ( - "get_type_by_name with registered type returns correct type", - " - local type = world:get_type_by_name('TestComponent') - - local expected = { - type_name = 'bevy_mod_scripting_lua::bindings::world::test::TestComponent', - short_name = 'TestComponent', - } - - assert(type ~= nil, 'Type not found') - assert(type.type_name == expected.type_name, 'type_name mismatch, expected: ' .. expected.type_name .. ', got: ' .. type.type_name) - assert(type.short_name == expected.short_name, 'short_name mismatch, expected: ' .. expected.short_name .. ', got: ' .. type.short_name) - ", - line!(), - ), - ] - } - - #[derive(Component, Debug, Clone, Reflect)] - pub struct TestComponent(String); - - #[derive(Resource, Debug, Clone, Reflect)] - pub struct TestResource(String); - - /// Initializes test world for tests - fn init_world() -> World { - let mut world = World::default(); - let type_registry = AppTypeRegistry::default(); - { - let mut type_registry = type_registry.write(); - type_registry.register::(); - type_registry.register::(); - } - world.insert_resource(type_registry); - world.init_resource::(); - // add some entities - world.spawn(TestComponent("Hello".to_string())); - world.insert_resource(TestResource("World".to_string())); - world - } - - #[test] - fn world_lua_api_tests() { - // use lua assertions to test the api - - for (test_name, code, line) in lua_tests() { - let lua = Lua::new(); - let mut world = init_world(); - WorldCallbackAccess::with_callback_access(&mut world, |world| { - lua.globals().set("world", LuaWorld(world.clone())).unwrap(); - - let code = lua.load(code); - // ide friendly link to test, i.e. crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs:139 - let filename = file!(); - let test_hyperlink = format!("{filename}:{line}"); - code.exec() - .inspect_err(|e| { - panic!("Failed lua test: `{test_name}` at: {test_hyperlink}. Error: {e}") - }) - .unwrap(); - }); - } - } -} diff --git a/crates/languages/bevy_mod_scripting_lua/src/lib.rs b/crates/languages/bevy_mod_scripting_lua/src/lib.rs index b0e4ba6ced..3fac3c6553 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/lib.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/lib.rs @@ -53,25 +53,29 @@ impl Default for LuaScriptingPlugin { } } +pub fn register_lua_values(app: &mut bevy::prelude::App) { + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); +} + impl Plugin for LuaScriptingPlugin { fn build(&self, app: &mut bevy::prelude::App) { self.scripting_plugin.build(app); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); + register_lua_values(app); } } diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_no_default_or_from_world_data_errors.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_no_default_or_from_world_data_errors.lua new file mode 100644 index 0000000000..aa185b18f4 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_no_default_or_from_world_data_errors.lua @@ -0,0 +1,9 @@ +function Test() + local entity = world:spawn() + local type = world:get_type_by_name('TestComponent') + world:add_default_component(entity, type) +end + +local success,err = pcall(Test) +assert(not success, 'No error thrown') +assert(string.find(tostring(err), 'Does not have ReflectDefault or ReflectFromWorld'), 'Error contains wrong message: ' .. tostring(err)) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_default_and_component_data_adds_default.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_default_and_component_data_adds_default.lua new file mode 100644 index 0000000000..cb7026bdff --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_default_and_component_data_adds_default.lua @@ -0,0 +1,9 @@ +local entity = world:spawn() +local _type = world:get_type_by_name('CompWithDefaultAndComponentData') +world:add_default_component(entity, _type) + +local added = world:has_component(entity, _type) +assert(added ~= nil, 'Component not added') + +local component = world:get_component(entity, _type) +assert(component._1 == "Default", 'Component did not have default value, got: ' .. component._1) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_default_no_component_data_errors.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_default_no_component_data_errors.lua new file mode 100644 index 0000000000..709b6fe706 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_default_no_component_data_errors.lua @@ -0,0 +1,10 @@ +function Test() + local entity = world:spawn() + local _type = world:get_type_by_name('CompWithDefault') + + world:add_default_component(entity, _type) +end + +local success,err = pcall(Test) +assert(not success, 'No error thrown') +assert(string.find(tostring(err), 'Does not have ReflectComponent'), 'Error contains wrong message: ' .. tostring(err)) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_from_world_and_component_data_adds_default.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_from_world_and_component_data_adds_default.lua new file mode 100644 index 0000000000..797e8ce998 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_from_world_and_component_data_adds_default.lua @@ -0,0 +1,9 @@ +local entity = world:spawn() +local _type = world:get_type_by_name('CompWithFromWorldAndComponentData') +world:add_default_component(entity, _type) + +local added = world:has_component(entity, _type) +assert(added ~= nil, 'Component not added') + +local component = world:get_component(entity, _type) +assert(component._1 == "Default", 'Component did not have default value, got: ' .. component._1) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_from_world_no_component_data_errors.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_from_world_no_component_data_errors.lua new file mode 100644 index 0000000000..777651855a --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_from_world_no_component_data_errors.lua @@ -0,0 +1,10 @@ +function Test() + local entity = world:spawn() + local _type = world:get_type_by_name('CompWithFromWorld') + + world:add_default_component(entity, _type) +end + +local success,err = pcall(Test) +assert(not success, 'No error thrown') +assert(string.find(tostring(err), 'Does not have ReflectComponent'), 'Error contains wrong message: ' .. tostring(err)) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_component/component_with_component_data.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_component/component_with_component_data.lua new file mode 100644 index 0000000000..a519c47e98 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/get_component/component_with_component_data.lua @@ -0,0 +1,3 @@ +let component = world:get_type_by_name("TestComponent") +world:get_component(entity, component) +// TODO \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_type_by_name/registered_type_returns_correct_type.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_type_by_name/registered_type_returns_correct_type.lua new file mode 100644 index 0000000000..d46f9ad774 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/get_type_by_name/registered_type_returns_correct_type.lua @@ -0,0 +1,10 @@ +local type = world:get_type_by_name('TestComponent') + +local expected = { + type_name = 'test_utils::test_data::TestComponent', + short_name = 'TestComponent', +} + +assert(type ~= nil, 'Type not found') +assert(type.type_name == expected.type_name, 'type_name mismatch, expected: ' .. expected.type_name .. ', got: ' .. type.type_name) +assert(type.short_name == expected.short_name, 'short_name mismatch, expected: ' .. expected.short_name .. ', got: ' .. type.short_name) diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_type_by_name/unregistered_type_returns_nothing.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_type_by_name/unregistered_type_returns_nothing.lua new file mode 100644 index 0000000000..bbd1c6f119 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/get_type_by_name/unregistered_type_returns_nothing.lua @@ -0,0 +1 @@ +assert(world:get_type_by_name('UnregisteredType') == nil, 'Unregistered type was found') diff --git a/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs b/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs new file mode 100644 index 0000000000..c4e6eb8b54 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs @@ -0,0 +1,151 @@ +use bevy::{ + app::App, + asset::{AssetPlugin, AssetServer}, + prelude::{AppTypeRegistry, Entity, World}, + MinimalPlugins, +}; +use bevy_mod_scripting_core::{ + bindings::{Proxy, ReflectAllocator, ReflectValProxy, WorldCallbackAccess}, + context::ContextLoadingSettings, + event::CallbackLabel, + script::ScriptId, +}; +use bevy_mod_scripting_lua::{ + bindings::{ + proxy::{LuaProxied, LuaReflectValProxy}, + world::LuaWorld, + }, + lua_context_load, lua_handler, + prelude::{Lua, LuaHookTriggers}, + register_lua_values, LuaScriptingPlugin, ReflectLuaValue, +}; +use libtest_mimic::{Arguments, Failed, Trial}; +use std::{ + any::TypeId, + fs::{self, DirEntry}, + io, + path::{Path, PathBuf}, +}; +use test_utils::test_data::setup_world; + +/// Initializes world for tests +fn init_app() -> App { + let mut app = App::new(); + + let world = setup_world(|_, _| {}); + + *app.world_mut() = world; + + // we probably should cut down some fat in here, but it's fast enough so meh + app.add_plugins(AssetPlugin::default()) + .add_plugins(LuaScriptingPlugin::<()>::default()) + .add_plugins(bevy_mod_scripting_lua::bindings::providers::LuaBevyScriptingPlugin); + + app +} + +struct Test { + code: String, + path: PathBuf, +} + +impl Test { + fn execute(self) -> Result<(), Failed> { + // let lua = Lua::new(); + // set file information + let mut app = init_app(); + let context_settings: ContextLoadingSettings = + app.world_mut() + .remove_resource() + .ok_or("could not find context loading settings")?; + + let mut lua = lua_context_load( + &(self.name()).into(), + self.code.as_bytes(), + &context_settings.context_initializers, + &context_settings.context_pre_handling_initializers, + app.world_mut(), + &mut (), + )?; + + lua_handler( + (), + Entity::from_raw(1), + &(self.name()).into(), + &CallbackLabel::new("test").ok_or("invalid callback label")?, + &mut lua, + &context_settings.context_pre_handling_initializers, + &mut (), + app.world_mut(), + )?; + + // WorldCallbackAccess::with_callback_access(app.world_mut(), |world| { + // lua.globals().set("world", LuaWorld(world.clone())).unwrap(); + + // let code = lua.load(self.code).set_name(self.path.to_string_lossy()); + // code.exec().map_err(|e| e.to_string()) + // })?; + Ok(()) + } + + fn name(&self) -> String { + // use the path from teh "data" directory as the test name separated by hyphens + let test = self + .path + .to_string_lossy() + .split("data") + .skip(1) + .collect::>() + .join("data") + .trim_start_matches("/") + .replace("/", " - ") + .replace(".lua", ""); + format!("lua_test - {test}") + } +} + +fn visit_dirs(dir: &Path, cb: &mut dyn FnMut(&DirEntry)) -> io::Result<()> { + if dir.is_dir() { + for entry in fs::read_dir(dir)? { + let entry = entry?; + let path = entry.path(); + if path.is_dir() { + visit_dirs(&path, cb)?; + } else { + cb(&entry); + } + } + } else { + panic!("Not a directory: {:?}", dir); + } + Ok(()) +} + +fn discover_all_tests() -> Vec { + let workspace_root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let test_root = workspace_root.join("tests").join("data"); + let mut test_files = Vec::new(); + visit_dirs(&test_root, &mut |entry| { + let path = entry.path(); + let code = fs::read_to_string(&path).unwrap(); + test_files.push(Test { code, path }); + }) + .unwrap(); + + test_files +} + +// run this with `cargo test --features lua54 --package bevy_mod_scripting_lua --test lua_tests` +// or filter using the prefix "lua test -" +fn main() { + // Parse command line arguments + let args = Arguments::from_args(); + + // Create a list of tests and/or benchmarks (in this case: two dummy tests). + let tests = discover_all_tests() + .into_iter() + .map(|t| Trial::test(t.name(), move || t.execute())); + + // Run all tests and exit the application appropriatly. + libtest_mimic::run(&args, tests.collect()).exit(); +} diff --git a/makefile b/makefile index 527d16560d..2bb24d424a 100644 --- a/makefile +++ b/makefile @@ -32,9 +32,11 @@ GENERATED_SRC_PATH=./crates/languages/bevy_mod_scripting_lua/src/bindings/provid GEN_BEVY_FEATURES=bevy_asset,bevy_gltf,bevy_animation,bevy_core_pipeline,bevy_ui,bevy_pbr,bevy_render,bevy_text,bevy_sprite,file_watcher,multi_threaded build_test_in_package: - @cargo test --no-run --lib --package ${PACKAGE} $(TEST_NAME) --features ${TEST_FEATURES} - @export OUTPUT=$$(find ./target/debug/deps/ -regex ".*${PACKAGE}[^.]*" -printf "%T@\t%Tc %6k KiB %p\n" | sort -n -r | awk '{print $$NF}' | head -1); \ - mv $${OUTPUT} ./target/debug/test_binary && echo "Using: $${OUTPUT}" && ls -v ./target/debug/ | grep "test_binary" + @RUSTFLAGS=-g cargo test --no-run --all-targets --features ${TEST_FEATURES} --package ${PACKAGE} $(TEST_NAME) --message-format=json | jq -r 'first(select(.executable != null and .target.kind == ["test"])) | .executable' | xargs -I@ ln -fs @ ./target/debug/test_binary + +run_lua_tests: + cargo test --features=lua54 --package bevy_mod_scripting_lua --test lua_tests + comp_benches: RUSTFLAGS="-g" cargo bench --no-run From 8c16d8c10f56c22c5ce6672a55582f7c90ff5f98 Mon Sep 17 00:00:00 2001 From: makspll Date: Thu, 14 Nov 2024 14:04:47 +0000 Subject: [PATCH 08/22] Add lua test API and add pass more tests --- crates/bevy_api_gen/templates/mod.tera | 2 +- .../src/bindings/providers/bevy_ecs.rs | 72 +- .../src/bindings/providers/bevy_hierarchy.rs | 16 +- .../src/bindings/providers/bevy_input.rs | 452 +- .../src/bindings/providers/bevy_math.rs | 936 ++-- .../src/bindings/providers/bevy_reflect.rs | 4846 ++++++++--------- .../src/bindings/providers/bevy_time.rs | 84 +- .../src/bindings/providers/bevy_transform.rs | 76 +- .../src/bindings/providers/bevy_window.rs | 450 +- .../src/bindings/providers/mod.rs | 20 +- .../component_no_component_data.lua | 6 + .../component_with_component_data.lua | 9 +- .../bevy_mod_scripting_lua/tests/lua_tests.rs | 66 +- 13 files changed, 3536 insertions(+), 3499 deletions(-) create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/get_component/component_no_component_data.lua diff --git a/crates/bevy_api_gen/templates/mod.tera b/crates/bevy_api_gen/templates/mod.tera index 44530bb555..4032b344d9 100644 --- a/crates/bevy_api_gen/templates/mod.tera +++ b/crates/bevy_api_gen/templates/mod.tera @@ -4,7 +4,7 @@ #![cfg_attr(rustfmt, rustfmt_skip)] {% filter prettyplease %} {%- for crate in crates %} - pub(crate) mod {{ crate.name }}; + pub mod {{ crate.name }}; {% endfor -%} pub struct {{ api_name }}; diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs index bbda61844f..ede3306eff 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs @@ -159,6 +159,14 @@ pub struct OnReplace {} bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -168,6 +176,14 @@ pub struct OnReplace {} other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + "#, r#" /// Creates a new [`ComponentId`]. @@ -184,22 +200,6 @@ pub struct OnReplace {} #[lua()] fn index(_self: LuaReflectValProxy) -> usize; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - "#, r#" #[lua(metamethod="ToString")] @@ -216,26 +216,6 @@ pub struct ComponentId(); bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - #[lua(as_trait = "std::clone::Clone")] fn clone( _self: LuaReflectRefProxy, @@ -274,6 +254,26 @@ pub struct ComponentId(); this_run: LuaReflectValProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + "#, r#" #[lua(metamethod="ToString")] diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs index 5db574d547..64e548268e 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs @@ -79,14 +79,6 @@ pub struct Parent(); bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - -"#, - r#" - #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -104,6 +96,14 @@ pub struct Parent(); _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + "#, r#" #[lua(metamethod="ToString")] diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs index 6fb241e53a..78229eaf4b 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs @@ -41,6 +41,14 @@ pub struct Gamepad { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -58,14 +66,6 @@ pub struct Gamepad { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - "#, r#" #[lua(metamethod="ToString")] @@ -87,14 +87,6 @@ pub struct GamepadAxis {} _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - "#, r#" @@ -107,6 +99,14 @@ pub struct GamepadAxis {} other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + "#, r#" #[lua(metamethod="ToString")] @@ -151,6 +151,14 @@ pub struct GamepadSettings { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -160,14 +168,6 @@ pub struct GamepadSettings { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" @@ -192,14 +192,6 @@ pub struct KeyCode {} bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -217,6 +209,14 @@ pub struct KeyCode {} _self: LuaReflectRefProxy, ) -> (); +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -272,6 +272,14 @@ pub struct TouchInput { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -281,14 +289,6 @@ pub struct TouchInput { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" @@ -313,6 +313,14 @@ pub struct KeyboardFocusLost {} bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -330,14 +338,6 @@ pub struct KeyboardFocusLost {} _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - "#, r#" #[lua(metamethod="ToString")] @@ -360,6 +360,14 @@ pub struct KeyboardInput { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -369,14 +377,6 @@ pub struct KeyboardInput { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -395,14 +395,6 @@ pub struct AccumulatedMouseMotion { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -412,6 +404,14 @@ pub struct AccumulatedMouseMotion { other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -431,6 +431,14 @@ pub struct AccumulatedMouseScroll { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua(as_trait = "std::cmp::Eq")] fn assert_receiver_is_total_eq( _self: LuaReflectRefProxy, @@ -448,14 +456,6 @@ pub struct AccumulatedMouseScroll { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -476,6 +476,14 @@ pub struct MouseButtonInput { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -485,14 +493,6 @@ pub struct MouseButtonInput { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -549,6 +549,14 @@ pub struct MouseWheel { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -558,14 +566,6 @@ pub struct MouseWheel { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -756,6 +756,14 @@ pub struct GamepadConnectionEvent { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -765,14 +773,6 @@ pub struct GamepadConnectionEvent { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -789,6 +789,14 @@ pub struct GamepadEvent {} bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -806,14 +814,6 @@ pub struct GamepadEvent {} _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - "#, r#" #[lua(metamethod="ToString")] @@ -919,6 +919,14 @@ pub struct RawGamepadButtonChangedEvent { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -928,14 +936,6 @@ pub struct RawGamepadButtonChangedEvent { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -952,6 +952,14 @@ pub struct RawGamepadEvent {} bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -961,14 +969,6 @@ pub struct RawGamepadEvent {} other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -985,6 +985,14 @@ pub struct PinchGesture(f32); bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -994,14 +1002,6 @@ pub struct PinchGesture(f32); other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -1018,6 +1018,14 @@ pub struct RotationGesture(f32); bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -1027,14 +1035,6 @@ pub struct RotationGesture(f32); other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -1084,10 +1084,14 @@ pub struct PanGesture(ReflectReference); bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( _self: LuaReflectRefProxy, - ) -> (); + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -1099,14 +1103,10 @@ pub struct PanGesture(ReflectReference); "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + ) -> (); "#, r#" @@ -1132,14 +1132,10 @@ pub struct ButtonState {} bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( + #[lua(as_trait = "std::clone::Clone")] + fn clone( _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + ) -> LuaReflectValProxy; "#, r#" @@ -1208,10 +1204,14 @@ pub struct ButtonState {} "#, r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -1391,6 +1391,14 @@ pub struct AxisSettings {} bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" /// Filters the `new_value` based on the `old_value`, according to the [`ButtonAxisSettings`]. /// Returns the clamped `new_value`, according to the [`ButtonAxisSettings`], if the change /// exceeds the settings threshold, and `None` otherwise. @@ -1402,14 +1410,6 @@ pub struct AxisSettings {} old_value: std::option::Option, ) -> std::option::Option; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -1435,18 +1435,6 @@ pub struct ButtonAxisSettings { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - "#, r#" /// Creates a new rumble intensity with weak motor intensity set to the given value. @@ -1467,6 +1455,18 @@ pub struct ButtonAxisSettings { intensity: f32, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + "#, r#" #[lua(metamethod="ToString")] @@ -1486,10 +1486,10 @@ pub struct GamepadRumbleIntensity { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + ) -> (); "#, r#" @@ -1506,10 +1506,10 @@ pub struct GamepadRumbleIntensity { "#, r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( + #[lua(as_trait = "std::clone::Clone")] + fn clone( _self: LuaReflectRefProxy, - ) -> (); + ) -> LuaReflectValProxy; "#, r#" @@ -1527,10 +1527,14 @@ pub struct Key {} bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( _self: LuaReflectRefProxy, - ) -> (); + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -1543,14 +1547,10 @@ pub struct Key {} "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + ) -> (); "#, r#" @@ -1568,6 +1568,14 @@ pub struct NativeKeyCode {} bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -1577,14 +1585,6 @@ pub struct NativeKeyCode {} other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" @@ -1609,10 +1609,14 @@ pub struct NativeKey {} bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -1625,14 +1629,10 @@ pub struct NativeKey {} "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( + #[lua(as_trait = "std::clone::Clone")] + fn clone( _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + ) -> LuaReflectValProxy; "#, r#" @@ -1650,6 +1650,14 @@ pub struct MouseScrollUnit {} bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -1659,14 +1667,6 @@ pub struct MouseScrollUnit {} other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" @@ -1691,14 +1691,6 @@ pub struct TouchPhase {} bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -1708,6 +1700,14 @@ pub struct TouchPhase {} other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs index 67c56c306b..deab25b495 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs @@ -26,6 +26,14 @@ use crate::{ other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" /// Returns the aspect ratio as a f32 value. @@ -63,14 +71,6 @@ use crate::{ #[lua()] fn is_square(_self: LuaReflectRefProxy) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -87,6 +87,14 @@ pub struct AspectRatio(); bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + #[lua(as_trait = "std::clone::Clone")] fn clone( _self: LuaReflectRefProxy, @@ -104,14 +112,6 @@ pub struct AspectRatio(); other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - "#, r#" #[lua(metamethod="ToString")] @@ -169,19 +169,19 @@ pub struct CompassQuadrant {} bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -223,20 +223,20 @@ pub struct CompassQuadrant {} "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -256,30 +256,10 @@ pub struct Isometry2d { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" -/// Create a three-dimensional isometry from a translation with the given `x`, `y`, and `z` components. - - #[lua()] - fn from_xyz(x: f32, y: f32, z: f32) -> LuaReflectValProxy; - -"#, - r#" -/// The inverse isometry that undoes this one. - - #[lua()] - fn inverse( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Compute `iso1.inverse() * iso2` in a more efficient way for one-shot cases. -/// If the same isometry is used multiple times, it is more efficient to instead compute -/// the inverse once and use that for each transformation. - #[lua()] - fn inverse_mul( + #[lua(as_trait = "std::clone::Clone")] + fn clone( _self: LuaReflectRefProxy, - rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -294,9 +274,10 @@ pub struct Isometry2d { "#, r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -310,10 +291,29 @@ pub struct Isometry2d { "#, r#" +/// Create a three-dimensional isometry from a translation with the given `x`, `y`, and `z` components. - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, + #[lua()] + fn from_xyz(x: f32, y: f32, z: f32) -> LuaReflectValProxy; + +"#, + r#" +/// The inverse isometry that undoes this one. + + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Compute `iso1.inverse() * iso2` in a more efficient way for one-shot cases. +/// If the same isometry is used multiple times, it is more efficient to instead compute +/// the inverse once and use that for each transformation. + + #[lua()] + fn inverse_mul( + _self: LuaReflectRefProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -823,18 +823,6 @@ pub struct Rot2 { _self: LuaReflectValProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - "#, r#" @@ -851,6 +839,18 @@ pub struct Rot2 { _self: LuaReflectValProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + "#, r#" #[lua(metamethod="ToString")] @@ -867,6 +867,14 @@ pub struct Dir2(); bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -879,9 +887,9 @@ pub struct Dir2(); "#, r#" - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( - _self: LuaReflectValProxy, + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -961,14 +969,6 @@ pub struct Dir2(); _self: LuaReflectValProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -984,6 +984,22 @@ pub struct Dir3(); bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" /// Create a direction from its `x`, `y`, and `z` components, assuming the resulting vector is normalized. /// # Warning /// The vector produced from `x`, `y`, and `z` must be normalized, i.e its length must be `1.0`. @@ -1037,14 +1053,6 @@ pub struct Dir3(); _self: LuaReflectValProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" @@ -1057,14 +1065,6 @@ pub struct Dir3(); other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( - _self: LuaReflectValProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -1268,6 +1268,26 @@ pub struct IRect { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" /// Create a new rectangle from two corner points. /// The two points do not need to be the minimum and/or maximum corners. /// They only need to be two opposite corners. @@ -1432,26 +1452,6 @@ pub struct IRect { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -1471,14 +1471,6 @@ pub struct Rect { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -1488,14 +1480,6 @@ pub struct Rect { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - "#, r#" /// Create a new rectangle from two corner points. @@ -1642,10 +1626,26 @@ pub struct Rect { "#, r#" -#[lua(metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} "#] )] pub struct URect { @@ -1702,6 +1702,14 @@ pub struct Aabb2d { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" /// Get the radius of the bounding circle #[lua()] @@ -1716,14 +1724,6 @@ pub struct Aabb2d { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -1742,17 +1742,15 @@ pub struct BoundingCircle { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" -/// Create a new [`Circle`] from a `radius` - - #[lua()] - fn new(radius: f32) -> LuaReflectValProxy; -"#, - r#" -/// Get the diameter of the circle - - #[lua()] - fn diameter(_self: LuaReflectRefProxy) -> f32; + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -1764,15 +1762,17 @@ pub struct BoundingCircle { "#, r#" +/// Create a new [`Circle`] from a `radius` - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + #[lua()] + fn new(radius: f32) -> LuaReflectValProxy; + +"#, + r#" +/// Get the diameter of the circle + + #[lua()] + fn diameter(_self: LuaReflectRefProxy) -> f32; "#, r#" @@ -1792,14 +1792,6 @@ pub struct Circle { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -1809,6 +1801,14 @@ pub struct Circle { other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" /// Create a new [`Annulus`] from the radii of the inner and outer circle @@ -1994,18 +1994,6 @@ pub struct Arc2d { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" /// Create a new `Capsule2d` from a radius and length #[lua()] @@ -2023,6 +2011,18 @@ pub struct Arc2d { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + "#, r#" @@ -2049,6 +2049,18 @@ pub struct Capsule2d { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" /// Create a new [`CircularSector`] from a `radius` and an `angle` #[lua()] @@ -2164,18 +2176,6 @@ pub struct Capsule2d { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - "#, r#" #[lua(metamethod="ToString")] @@ -2194,14 +2194,6 @@ pub struct CircularSector { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -2323,6 +2315,14 @@ pub struct CircularSector { _self: LuaReflectRefProxy, ) -> f32; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -2341,6 +2341,14 @@ pub struct CircularSegment { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -2350,14 +2358,6 @@ pub struct CircularSegment { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" /// Create a new `Ellipse` from half of its width and height. @@ -2453,14 +2453,6 @@ pub struct Line2d { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -2470,6 +2462,14 @@ pub struct Line2d { other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -2487,6 +2487,24 @@ pub struct Plane2d { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" +/// Create a new `Rectangle` from a full width and height + + #[lua()] + fn new( + width: f32, + height: f32, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Create a `Rectangle` from a single length. +/// The resulting `Rectangle` will be the same size in every direction. + + #[lua()] + fn from_length(length: f32) -> LuaReflectValProxy; + +"#, + r#" #[lua(as_trait = "std::clone::Clone")] fn clone( @@ -2505,24 +2523,6 @@ pub struct Plane2d { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" -/// Create a new `Rectangle` from a full width and height - - #[lua()] - fn new( - width: f32, - height: f32, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Create a `Rectangle` from a single length. -/// The resulting `Rectangle` will be the same size in every direction. - - #[lua()] - fn from_length(length: f32) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -2540,14 +2540,6 @@ pub struct Rectangle { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" /// Create a new `RegularPolygon` /// from the radius of the circumcircle and a number of sides /// # Panics @@ -2645,6 +2637,14 @@ pub struct Rectangle { other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -2669,18 +2669,6 @@ pub struct RegularPolygon { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - "#, r#" /// Create a new `Rhombus` from a vertical and horizontal diagonal sizes. @@ -2732,14 +2720,26 @@ pub struct RegularPolygon { "#, r#" -#[lua(metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Rhombus { - half_diagonals: ReflectReference, + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Rhombus { + half_diagonals: ReflectReference, } #[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( @@ -2747,16 +2747,6 @@ pub struct Rhombus { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" -/// Create a new `Segment2d` from a direction and full length of the segment - - #[lua()] - fn new( - direction: LuaReflectValProxy, - length: f32, - ) -> LuaReflectValProxy; - -"#, - r#" #[lua( as_trait = "std::cmp::PartialEq::", @@ -2775,6 +2765,16 @@ pub struct Rhombus { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; +"#, + r#" +/// Create a new `Segment2d` from a direction and full length of the segment + + #[lua()] + fn new( + direction: LuaReflectValProxy, + length: f32, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -2793,18 +2793,6 @@ pub struct Segment2d { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" /// Checks if the triangle is degenerate, meaning it has zero area. /// A triangle is degenerate if the cross product of the vectors `ab` and `ac` has a length less than `10e-7`. /// This indicates that the three vertices are collinear or nearly collinear. @@ -2845,6 +2833,18 @@ pub struct Segment2d { _self: LuaReflectValProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + "#, r#" @@ -2870,20 +2870,20 @@ pub struct Triangle2d { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" -/// Computes the smallest [`BoundingSphere`] containing this [`Aabb3d`]. - #[lua()] - fn bounding_sphere( + #[lua(as_trait = "std::clone::Clone")] + fn clone( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + ) -> LuaReflectValProxy; "#, r#" +/// Computes the smallest [`BoundingSphere`] containing this [`Aabb3d`]. - #[lua(as_trait = "std::clone::Clone")] - fn clone( + #[lua()] + fn bounding_sphere( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + ) -> LuaReflectValProxy; "#, r#" @@ -2903,14 +2903,6 @@ pub struct Aabb3d { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" /// Get the radius of the bounding sphere #[lua()] @@ -2925,6 +2917,14 @@ pub struct Aabb3d { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -2944,14 +2944,6 @@ pub struct BoundingSphere { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -2975,6 +2967,14 @@ pub struct BoundingSphere { #[lua()] fn diameter(_self: LuaReflectRefProxy) -> f32; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -3009,6 +3009,14 @@ pub struct Sphere { #[lua()] fn from_length(length: f32) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" @@ -3021,14 +3029,6 @@ pub struct Sphere { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -3046,14 +3046,6 @@ pub struct Cuboid { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" /// Create a new `Cylinder` from a radius and full height #[lua()] @@ -3086,6 +3078,14 @@ pub struct Cuboid { #[lua()] fn base_area(_self: LuaReflectRefProxy) -> f32; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" @@ -3126,6 +3126,14 @@ pub struct Cylinder { other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" /// Create a new `Capsule3d` from a radius and length @@ -3146,14 +3154,6 @@ pub struct Cylinder { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -3248,14 +3248,6 @@ pub struct Cone { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -3265,6 +3257,14 @@ pub struct Cone { other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -3355,18 +3355,6 @@ pub struct Line3d { bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - #[lua(as_trait = "std::clone::Clone")] fn clone( _self: LuaReflectRefProxy, @@ -3382,6 +3370,18 @@ pub struct Line3d { length: f32, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + "#, r#" #[lua(metamethod="ToString")] @@ -3400,26 +3400,6 @@ pub struct Segment3d { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" - - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" /// Create a new `Torus` from an inner and outer radius. /// The inner radius is the radius of the hole, and the outer radius /// is the radius of the entire object @@ -3448,6 +3428,26 @@ pub struct Segment3d { #[lua()] fn outer_radius(_self: LuaReflectRefProxy) -> f32; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + "#, r#" #[lua(metamethod="ToString")] @@ -3466,6 +3466,26 @@ pub struct Torus { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" /// Checks if the triangle is degenerate, meaning it has zero area. /// A triangle is degenerate if the cross product of the vectors `ab` and `ac` has a length less than `10e-7`. /// This indicates that the three vertices are collinear or nearly collinear. @@ -3505,26 +3525,6 @@ pub struct Torus { _self: LuaReflectValProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -3686,14 +3686,6 @@ pub struct BoundingCircleCast { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" /// Construct a [`RayCast3d`] from a [`Ray3d`] and max distance. #[lua()] @@ -3722,6 +3714,14 @@ pub struct BoundingCircleCast { sphere: LuaReflectRefProxy, ) -> std::option::Option; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -3786,14 +3786,6 @@ pub struct AabbCast3d { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" /// Construct a [`BoundingSphereCast`] from a [`BoundingSphere`], [`Ray3d`], and max distance. #[lua()] @@ -3813,6 +3805,14 @@ pub struct AabbCast3d { sphere: LuaReflectValProxy, ) -> std::option::Option; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -3832,6 +3832,14 @@ pub struct BoundingSphereCast { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -3921,14 +3929,6 @@ pub struct BoundingSphereCast { value: f32, ) -> f32; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -3945,8 +3945,8 @@ pub struct Interval {} bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( + #[lua(as_trait = "std::cmp::PartialOrd::")] + fn lt( _self: LuaReflectRefProxy, other: LuaReflectRefProxy, ) -> bool; @@ -3954,24 +3954,17 @@ pub struct Interval {} "#, r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( + #[lua(as_trait = "std::cmp::PartialOrd::")] + fn le( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( - _self: LuaReflectValProxy, - ) -> LuaReflectValProxy; + other: LuaReflectRefProxy, + ) -> bool; "#, r#" #[lua(as_trait = "std::cmp::PartialOrd::")] - fn lt( + fn gt( _self: LuaReflectRefProxy, other: LuaReflectRefProxy, ) -> bool; @@ -3980,7 +3973,7 @@ pub struct Interval {} r#" #[lua(as_trait = "std::cmp::PartialOrd::")] - fn le( + fn ge( _self: LuaReflectRefProxy, other: LuaReflectRefProxy, ) -> bool; @@ -3988,21 +3981,28 @@ pub struct Interval {} "#, r#" - #[lua(as_trait = "std::cmp::PartialOrd::")] - fn gt( + #[lua(as_trait = "std::clone::Clone")] + fn clone( _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::PartialOrd::")] - fn ge( + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( _self: LuaReflectRefProxy, other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -4019,6 +4019,14 @@ pub struct FloatOrd(f32); bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -4028,14 +4036,6 @@ pub struct FloatOrd(f32); other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -4054,6 +4054,18 @@ pub struct Plane3d { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" +/// Get the signed volume of the tetrahedron. +/// If it's negative, the normal vector of the face defined by +/// the first three points using the right-hand rule points +/// away from the fourth vertex. + + #[lua()] + fn signed_volume( + _self: LuaReflectRefProxy, + ) -> f32; + +"#, + r#" #[lua( as_trait = "std::cmp::PartialEq::", @@ -4072,18 +4084,6 @@ pub struct Plane3d { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" -/// Get the signed volume of the tetrahedron. -/// If it's negative, the normal vector of the face defined by -/// the first three points using the right-hand rule points -/// away from the fourth vertex. - - #[lua()] - fn signed_volume( - _self: LuaReflectRefProxy, - ) -> f32; - "#, r#" #[lua(metamethod="ToString")] @@ -4102,6 +4102,14 @@ pub struct Tetrahedron { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -4111,14 +4119,6 @@ pub struct Tetrahedron { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs index 1659fd0a00..b8ebe738ad 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs @@ -1349,88 +1349,78 @@ pub struct RangeFull {} bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" +/// Adds two quaternions. +/// The sum is not guaranteed to be normalized. +/// Note that addition is not the same as combining the rotations represented by the +/// two quaternions! That corresponds to multiplication. - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" -/// Divides a quaternion by a scalar value. -/// The quotient is not guaranteed to be normalized. +/// Multiplies two quaternions. If they each represent a rotation, the result will +/// represent the combined rotation. +/// Note that due to floating point rounding the result may not be perfectly +/// normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: f32, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( _self: LuaReflectRefProxy, - rhs: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" -/// Multiplies a quaternion by a scalar value. -/// The product is not guaranteed to be normalized. - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: f32, ) -> LuaReflectValProxy; "#, r#" +/// Multiplies a quaternion and a 3D vector, returning the rotated vector. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - ) -> LuaReflectValProxy; + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Multiplies two quaternions. If they each represent a rotation, the result will -/// represent the combined rotation. -/// Note that due to floating point rounding the result may not be perfectly -/// normalized. -/// # Panics -/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. +/// Multiplies a quaternion by a scalar value. +/// The product is not guaranteed to be normalized. - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: f32, ) -> LuaReflectValProxy; "#, r#" -/// Subtracts the `rhs` quaternion from `self`. -/// The difference is not guaranteed to be normalized. - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Adds two quaternions. -/// The sum is not guaranteed to be normalized. -/// Note that addition is not the same as combining the rotations represented by the -/// two quaternions! That corresponds to multiplication. - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -1890,24 +1880,34 @@ pub struct RangeFull {} "#, r#" -/// Multiplies a quaternion and a 3D vector, returning the rotated vector. -/// # Panics -/// Will panic if `self` is not normalized when `glam_assert` is enabled. +/// Divides a quaternion by a scalar value. +/// The quotient is not guaranteed to be normalized. - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" +/// Subtracts the `rhs` quaternion from `self`. +/// The difference is not guaranteed to be normalized. - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -1925,12 +1925,39 @@ pub struct Quat(); bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Div::<&bevy::math::Vec3>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, rhs: f32, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + "#, r#" @@ -1943,10 +1970,19 @@ pub struct Quat(); "#, r#" - #[lua(as_trait = "std::ops::Mul::<&bevy::math::Vec3>", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f32, ) -> LuaReflectValProxy; "#, @@ -1961,19 +1997,19 @@ pub struct Quat(); "#, r#" - #[lua(as_trait = "std::ops::Add::<&bevy::math::Vec3>", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: f32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Add::<&bevy::math::Vec3>", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -2802,8 +2838,8 @@ pub struct Quat(); "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -2811,25 +2847,8 @@ pub struct Quat(); "#, r#" - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( - _self: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: f32, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::<&bevy::math::Vec3>", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Mul::<&bevy::math::Vec3>", composite = "mul")] + fn mul( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -2837,21 +2856,12 @@ pub struct Quat(); "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: f32, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - "#, r#" @@ -2863,28 +2873,27 @@ pub struct Quat(); "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: f32, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Sub::<&bevy::math::Vec3>", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -2896,15 +2905,6 @@ pub struct Quat(); rhs: f32, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::ops::Div::<&bevy::math::Vec3>", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -2937,25 +2937,51 @@ pub struct Vec3 { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Sub::<&bevy::math::IVec2>", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: i32, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" -/// Creates a new vector. - #[lua()] - fn new(x: i32, y: i32) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" -/// Creates a vector with all elements set to `v`. - - #[lua()] - fn splat(v: i32) -> LuaReflectValProxy; + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: i32, y: i32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: i32) -> LuaReflectValProxy; "#, r#" @@ -3464,30 +3490,21 @@ pub struct Vec3 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: i32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::<&bevy::math::IVec2>", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Rem::<&bevy::math::IVec2>", composite = "rem")] + fn rem( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - "#, r#" @@ -3499,40 +3516,35 @@ pub struct Vec3 { "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: i32, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::<&bevy::math::IVec2>", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: i32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); - -"#, - r#" - - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -3540,28 +3552,28 @@ pub struct Vec3 { "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::IVec2>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Add::<&bevy::math::IVec2>", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: i32, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Rem::<&bevy::math::IVec2>", composite = "rem")] + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] fn rem( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: i32, ) -> LuaReflectValProxy; "#, @@ -3576,8 +3588,8 @@ pub struct Vec3 { "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -3585,38 +3597,26 @@ pub struct Vec3 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: i32, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::<&bevy::math::IVec2>", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: i32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: i32, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" @@ -3649,300 +3649,152 @@ pub struct IVec2 { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, - rhs: i32, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, + #[lua(as_trait = "std::ops::Add::<&bevy::math::IVec3>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" +/// Creates a new vector. - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: i32, - ) -> LuaReflectValProxy; + #[lua()] + fn new(x: i32, y: i32, z: i32) -> LuaReflectValProxy; "#, r#" +/// Creates a vector with all elements set to `v`. - #[lua(as_trait = "std::ops::Mul::<&bevy::math::IVec3>", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + #[lua()] + fn splat(v: i32) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" +/// Creates a new vector from an array. - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + #[lua()] + fn from_array(a: [i32; 3]) -> LuaReflectValProxy; "#, r#" +/// `[x, y, z]` - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: i32, - ) -> LuaReflectValProxy; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i32; 3]; "#, r#" +/// Creates a 4D vector from `self` and the given `w` value. - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua()] + fn extend( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + w: i32, + ) -> LuaReflectValProxy; "#, r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( + #[lua()] + fn truncate( _self: LuaReflectValProxy, - ) -> LuaReflectValProxy; + ) -> LuaReflectValProxy; "#, r#" +/// Creates a 3D vector from `self` with the given value of `x`. - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua()] + fn with_x( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + x: i32, ) -> LuaReflectValProxy; "#, r#" +/// Creates a 3D vector from `self` with the given value of `y`. - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua()] + fn with_y( _self: LuaReflectValProxy, - rhs: i32, + y: i32, ) -> LuaReflectValProxy; "#, r#" +/// Creates a 3D vector from `self` with the given value of `z`. - #[lua(as_trait = "std::ops::Rem::<&bevy::math::IVec3>", composite = "rem")] - fn rem( + #[lua()] + fn with_z( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + z: i32, ) -> LuaReflectValProxy; "#, r#" +/// Computes the dot product of `self` and `rhs`. - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua()] + fn dot( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + ) -> i32; "#, r#" +/// Returns a vector where every component is the dot product of `self` and `rhs`. - #[lua(as_trait = "std::ops::Add::<&bevy::math::IVec3>", composite = "add")] - fn add( + #[lua()] + fn dot_into_vec( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" +/// Computes the cross product of `self` and `rhs`. - #[lua(as_trait = "std::ops::Div::<&bevy::math::IVec3>", composite = "div")] - fn div( + #[lua()] + fn cross( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" +/// Returns a vector containing the minimum values for each element of `self` and `rhs`. +/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - #[lua(as_trait = "std::ops::Sub::<&bevy::math::IVec3>", composite = "sub")] - fn sub( + #[lua()] + fn min( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); - -"#, - r#" - - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: i32, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Creates a new vector. - - #[lua()] - fn new(x: i32, y: i32, z: i32) -> LuaReflectValProxy; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua()] - fn splat(v: i32) -> LuaReflectValProxy; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua()] - fn select( - mask: LuaReflectValProxy, - if_true: LuaReflectValProxy, - if_false: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua()] - fn from_array(a: [i32; 3]) -> LuaReflectValProxy; - -"#, - r#" -/// `[x, y, z]` - - #[lua()] - fn to_array(_self: LuaReflectRefProxy) -> [i32; 3]; - -"#, - r#" -/// Creates a 4D vector from `self` and the given `w` value. - - #[lua()] - fn extend( - _self: LuaReflectValProxy, - w: i32, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. -/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - - #[lua()] - fn truncate( - _self: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Creates a 3D vector from `self` with the given value of `x`. - - #[lua()] - fn with_x( - _self: LuaReflectValProxy, - x: i32, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Creates a 3D vector from `self` with the given value of `y`. - - #[lua()] - fn with_y( - _self: LuaReflectValProxy, - y: i32, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Creates a 3D vector from `self` with the given value of `z`. - - #[lua()] - fn with_z( - _self: LuaReflectValProxy, - z: i32, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Computes the dot product of `self` and `rhs`. - - #[lua()] - fn dot( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> i32; - -"#, - r#" -/// Returns a vector where every component is the dot product of `self` and `rhs`. - - #[lua()] - fn dot_into_vec( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Computes the cross product of `self` and `rhs`. - - #[lua()] - fn cross( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Returns a vector containing the minimum values for each element of `self` and `rhs`. -/// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. - - #[lua()] - fn min( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -4339,107 +4191,186 @@ pub struct IVec2 { "#, r#" -#[lua(metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + "#, r#" -#[lua(metamethod="Index")] -fn index(self, idx: usize) -> LuaIdentityProxy { - _self[idx - 1] -} + + #[lua(as_trait = "std::ops::Mul::<&bevy::math::IVec3>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" -#[lua(metamethod="NewIndex")] -fn index(&mut self, idx: usize, val: i32) -> () { - _self[idx - 1] = val -} -"#] -)] -pub struct IVec3 { - x: i32, - y: i32, - z: i32, -} -#[derive(bevy_mod_scripting_derive::LuaProxy)] -#[proxy( - remote = "bevy::math::IVec4", - bms_core_path = "bevy_mod_scripting_core", - bms_lua_path = "crate", - functions[r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: i32, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] + #[lua(as_trait = "std::ops::Div::<&bevy::math::IVec3>", composite = "div")] fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: i32, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] + #[lua(as_trait = "std::ops::Add::", composite = "add")] fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, + #[lua(as_trait = "std::ops::Sub::<&bevy::math::IVec3>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, rhs: i32, - ) -> LuaReflectValProxy; + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::<&bevy::math::IVec3>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, rhs: i32, - ) -> LuaReflectValProxy; + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] fn sub( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> LuaIdentityProxy { + _self[idx - 1] +} +"#, + r#" +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: i32) -> () { + _self[idx - 1] = val +} +"#] +)] +pub struct IVec3 { + x: i32, + y: i32, + z: i32, +} +#[derive(bevy_mod_scripting_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::IVec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -4447,35 +4378,34 @@ pub struct IVec3 { "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: i32, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, + rhs: i32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::<&bevy::math::IVec4>", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, + #[lua(as_trait = "std::ops::Add::<&bevy::math::IVec4>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -4987,10 +4917,27 @@ pub struct IVec3 { "#, r#" - #[lua(as_trait = "std::ops::Add::<&bevy::math::IVec4>", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -5005,8 +4952,25 @@ pub struct IVec3 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -5014,12 +4978,30 @@ pub struct IVec3 { "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + #[lua(as_trait = "std::ops::Rem::<&bevy::math::IVec4>", composite = "rem")] fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: i32, + ) -> LuaReflectValProxy; + "#, r#" @@ -5032,8 +5014,26 @@ pub struct IVec3 { "#, r#" - #[lua(as_trait = "std::ops::Rem::<&bevy::math::IVec4>", composite = "rem")] - fn rem( + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::<&bevy::math::IVec4>", composite = "mul")] + fn mul( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -5070,45 +5070,117 @@ pub struct IVec4 { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" -/// Creates a new vector. - #[lua()] - fn new(x: i64, y: i64) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Creates a vector with all elements set to `v`. - #[lua()] - fn splat(v: i64) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - #[lua()] - fn select( - mask: LuaReflectValProxy, - if_true: LuaReflectValProxy, - if_false: LuaReflectValProxy, + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: i64, ) -> LuaReflectValProxy; "#, r#" -/// Creates a new vector from an array. - #[lua()] - fn from_array(a: [i64; 2]) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Div::<&bevy::math::I64Vec2>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -/// `[x, y]` - #[lua()] - fn to_array(_self: LuaReflectRefProxy) -> [i64; 2]; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::<&bevy::math::I64Vec2>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: i64, y: i64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: i64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [i64; 2]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i64; 2]; "#, r#" @@ -5589,36 +5661,9 @@ pub struct IVec4 { "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: i64, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( _self: LuaReflectValProxy, - rhs: i64, ) -> LuaReflectValProxy; "#, @@ -5633,26 +5678,25 @@ pub struct IVec4 { "#, r#" - #[lua(as_trait = "std::ops::Rem::<&bevy::math::I64Vec2>", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::<&bevy::math::I64Vec2>", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Sub::<&bevy::math::I64Vec2>", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -5660,10 +5704,10 @@ pub struct IVec4 { "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Rem::<&bevy::math::I64Vec2>", composite = "rem")] + fn rem( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -5678,36 +5722,10 @@ pub struct IVec4 { "#, r#" - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( - _self: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::ops::Add::<&bevy::math::I64Vec2>", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::<&bevy::math::I64Vec2>", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -5719,15 +5737,6 @@ pub struct IVec4 { rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: i64, - ) -> LuaReflectValProxy; - "#, r#" @@ -5737,21 +5746,12 @@ pub struct IVec4 { "#, r#" - #[lua(as_trait = "std::ops::Sub::<&bevy::math::I64Vec2>", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Mul::<&bevy::math::I64Vec2>", composite = "mul")] + fn mul( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -5770,82 +5770,240 @@ pub struct I64Vec2 { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" -/// Creates a new vector. - #[lua()] - fn new(x: i64, y: i64, z: i64) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" -/// Creates a vector with all elements set to `v`. - #[lua()] - fn splat(v: i64) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Sub::<&bevy::math::I64Vec3>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - #[lua()] - fn select( - mask: LuaReflectValProxy, - if_true: LuaReflectValProxy, - if_false: LuaReflectValProxy, + #[lua(as_trait = "std::ops::Add::<&bevy::math::I64Vec3>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" -/// Creates a new vector from an array. - #[lua()] - fn from_array(a: [i64; 3]) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" -/// `[x, y, z]` - #[lua()] - fn to_array(_self: LuaReflectRefProxy) -> [i64; 3]; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Creates a 4D vector from `self` and the given `w` value. - #[lua()] - fn extend( + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, - w: i64, - ) -> LuaReflectValProxy; + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. -/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. - #[lua()] - fn truncate( + #[lua(as_trait = "std::ops::Rem::<&bevy::math::I64Vec3>", composite = "rem")] + fn rem( _self: LuaReflectValProxy, - ) -> LuaReflectValProxy; + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" -/// Creates a 3D vector from `self` with the given value of `x`. - #[lua()] - fn with_x( - _self: LuaReflectValProxy, - x: i64, + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" -/// Creates a 3D vector from `self` with the given value of `y`. - #[lua()] - fn with_y( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::<&bevy::math::I64Vec3>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::<&bevy::math::I64Vec3>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector. + + #[lua()] + fn new(x: i64, y: i64, z: i64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector with all elements set to `v`. + + #[lua()] + fn splat(v: i64) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. + + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a new vector from an array. + + #[lua()] + fn from_array(a: [i64; 3]) -> LuaReflectValProxy; + +"#, + r#" +/// `[x, y, z]` + + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i64; 3]; + +"#, + r#" +/// Creates a 4D vector from `self` and the given `w` value. + + #[lua()] + fn extend( + _self: LuaReflectValProxy, + w: i64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. +/// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()]. + + #[lua()] + fn truncate( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `x`. + + #[lua()] + fn with_x( + _self: LuaReflectValProxy, + x: i64, + ) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a 3D vector from `self` with the given value of `y`. + + #[lua()] + fn with_y( _self: LuaReflectValProxy, y: i64, ) -> LuaReflectValProxy; @@ -6296,280 +6454,96 @@ pub struct I64Vec2 { "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( _self: LuaReflectValProxy, - rhs: i64, ) -> LuaReflectValProxy; "#, r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct I64Vec3 { + x: i64, + y: i64, + z: i64, +} +#[derive(bevy_mod_scripting_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::I64Vec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: i64, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Rem::<&bevy::math::I64Vec3>", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Div::<&bevy::math::I64Vec4>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" +/// Creates a new vector. - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( - _self: LuaReflectValProxy, - ) -> LuaReflectValProxy; + #[lua()] + fn new(x: i64, y: i64, z: i64, w: i64) -> LuaReflectValProxy; "#, r#" +/// Creates a vector with all elements set to `v`. - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + #[lua()] + fn splat(v: i64) -> LuaReflectValProxy; "#, r#" +/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use +/// for each element of `self`. +/// A true element in the mask uses the corresponding element from `if_true`, and false +/// uses the element from `if_false`. - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + #[lua()] + fn select( + mask: LuaReflectValProxy, + if_true: LuaReflectValProxy, + if_false: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" +/// Creates a new vector from an array. - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: i64, - ) -> LuaReflectValProxy; + #[lua()] + fn from_array(a: [i64; 4]) -> LuaReflectValProxy; "#, r#" +/// `[x, y, z, w]` - #[lua(as_trait = "std::ops::Sub::<&bevy::math::I64Vec3>", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: i64, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Add::<&bevy::math::I64Vec3>", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: i64, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::<&bevy::math::I64Vec3>", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Div::<&bevy::math::I64Vec3>", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" -#[lua(metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct I64Vec3 { - x: i64, - y: i64, - z: i64, -} -#[derive(bevy_mod_scripting_derive::LuaProxy)] -#[proxy( - remote = "bevy::math::I64Vec4", - bms_core_path = "bevy_mod_scripting_core", - bms_lua_path = "crate", - functions[r#" - - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: i64, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::<&bevy::math::I64Vec4>", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Div::<&bevy::math::I64Vec4>", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" -/// Creates a new vector. - - #[lua()] - fn new(x: i64, y: i64, z: i64, w: i64) -> LuaReflectValProxy; - -"#, - r#" -/// Creates a vector with all elements set to `v`. - - #[lua()] - fn splat(v: i64) -> LuaReflectValProxy; - -"#, - r#" -/// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use -/// for each element of `self`. -/// A true element in the mask uses the corresponding element from `if_true`, and false -/// uses the element from `if_false`. - - #[lua()] - fn select( - mask: LuaReflectValProxy, - if_true: LuaReflectValProxy, - if_false: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Creates a new vector from an array. - - #[lua()] - fn from_array(a: [i64; 4]) -> LuaReflectValProxy; - -"#, - r#" -/// `[x, y, z, w]` - - #[lua()] - fn to_array(_self: LuaReflectRefProxy) -> [i64; 4]; + #[lua()] + fn to_array(_self: LuaReflectRefProxy) -> [i64; 4]; "#, r#" @@ -7038,14 +7012,8 @@ pub struct I64Vec3 { "#, r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::<&bevy::math::I64Vec4>", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Sub::<&bevy::math::I64Vec4>", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -7053,26 +7021,25 @@ pub struct I64Vec3 { "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: i64, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Rem::<&bevy::math::I64Vec4>", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Mul::<&bevy::math::I64Vec4>", composite = "mul")] + fn mul( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -7080,8 +7047,8 @@ pub struct I64Vec3 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: i64, ) -> LuaReflectValProxy; @@ -7089,18 +7056,25 @@ pub struct I64Vec3 { "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -7115,8 +7089,8 @@ pub struct I64Vec3 { "#, r#" - #[lua(as_trait = "std::ops::Add::<&bevy::math::I64Vec4>", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Rem::<&bevy::math::I64Vec4>", composite = "rem")] + fn rem( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -7124,10 +7098,10 @@ pub struct I64Vec3 { "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: i64, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -7142,10 +7116,36 @@ pub struct I64Vec3 { "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] fn div( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: i64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::<&bevy::math::I64Vec4>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -7169,10 +7169,10 @@ pub struct I64Vec4 { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Sub::<&bevy::math::UVec2>", composite = "sub")] + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] fn sub( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -7193,34 +7193,8 @@ pub struct I64Vec4 { "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: u32, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -7228,10 +7202,10 @@ pub struct I64Vec4 { "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Add::<&bevy::math::UVec2>", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: u32, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -7246,19 +7220,10 @@ pub struct I64Vec4 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Rem::<&bevy::math::UVec2>", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: u32, ) -> LuaReflectValProxy; "#, @@ -7664,17 +7629,26 @@ pub struct I64Vec4 { "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + #[lua(as_trait = "std::ops::Rem::<&bevy::math::UVec2>", composite = "rem")] fn rem( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, rhs: u32, ) -> LuaReflectValProxy; @@ -7682,20 +7656,20 @@ pub struct I64Vec4 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::<&bevy::math::UVec2>", composite = "mul")] fn mul( _self: LuaReflectValProxy, - rhs: u32, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -7709,21 +7683,47 @@ pub struct I64Vec4 { "#, r#" - #[lua(as_trait = "std::ops::Mul::<&bevy::math::UVec2>", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::<&bevy::math::UVec2>", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::<&bevy::math::UVec2>", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -7755,17 +7755,8 @@ pub struct UVec2 { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Rem::<&bevy::math::UVec3>", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Add::<&bevy::math::UVec3>", composite = "add")] + fn add( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -7773,11 +7764,8 @@ pub struct UVec2 { "#, r#" - #[lua(as_trait = "std::ops::Div::<&bevy::math::UVec3>", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" @@ -7791,63 +7779,46 @@ pub struct UVec2 { "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: u32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::<&bevy::math::UVec3>", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, + rhs: u32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: u32, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, - rhs: u32, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Mul::<&bevy::math::UVec3>", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: u32, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -8292,53 +8263,70 @@ pub struct UVec2 { "#, r#" - #[lua(as_trait = "std::ops::Sub::<&bevy::math::UVec3>", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: u32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Div::<&bevy::math::UVec3>", composite = "div")] + fn div( _self: LuaReflectValProxy, - rhs: u32, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::<&bevy::math::UVec3>", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: u32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Sub::<&bevy::math::UVec3>", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: u32, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -8346,8 +8334,20 @@ pub struct UVec2 { "#, r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::<&bevy::math::UVec3>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -8381,8 +8381,17 @@ pub struct UVec3 { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Sub::<&bevy::math::UVec4>", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -8390,8 +8399,41 @@ pub struct UVec3 { "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -8399,12 +8441,20 @@ pub struct UVec3 { "#, r#" - #[lua(as_trait = "std::ops::Sub::<&bevy::math::UVec4>", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Div::<&bevy::math::UVec4>", composite = "div")] + fn div( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" @@ -8417,17 +8467,20 @@ pub struct UVec3 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, - rhs: u32, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + #[lua(as_trait = "std::ops::Mul::<&bevy::math::UVec4>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -8438,6 +8491,42 @@ pub struct UVec3 { rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::<&bevy::math::UVec4>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + "#, r#" /// Creates a new vector. @@ -8861,142 +8950,187 @@ pub struct UVec3 { "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#, + r#" +#[lua(metamethod="Index")] +fn index(self, idx: usize) -> LuaIdentityProxy { + _self[idx - 1] +} +"#, + r#" +#[lua(metamethod="NewIndex")] +fn index(&mut self, idx: usize, val: u32) -> () { + _self[idx - 1] = val +} +"#] +)] +pub struct UVec4 { + x: u32, + y: u32, + z: u32, + w: u32, +} +#[derive(bevy_mod_scripting_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::U64Vec2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::<&bevy::math::UVec4>", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::U64Vec2>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: u32, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::<&bevy::math::UVec4>", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: u32, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Mul::<&bevy::math::U64Vec2>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::<&bevy::math::U64Vec2>", composite = "sub")] fn sub( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] + #[lua(as_trait = "std::ops::Div::<&bevy::math::U64Vec2>", composite = "div")] fn div( - _self: LuaReflectValProxy, - rhs: u32, - ) -> LuaReflectValProxy; + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::<&bevy::math::U64Vec2>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, ) -> bool; "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: u32, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua(as_trait = "std::ops::Add::<&bevy::math::UVec4>", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" -#[lua(metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + "#, r#" -#[lua(metamethod="Index")] -fn index(self, idx: usize) -> LuaIdentityProxy { - _self[idx - 1] -} + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + "#, r#" -#[lua(metamethod="NewIndex")] -fn index(&mut self, idx: usize, val: u32) -> () { - _self[idx - 1] = val -} -"#] -)] -pub struct UVec4 { - x: u32, - y: u32, - z: u32, - w: u32, -} -#[derive(bevy_mod_scripting_derive::LuaProxy)] -#[proxy( - remote = "bevy::math::U64Vec2", - bms_core_path = "bevy_mod_scripting_core", - bms_lua_path = "crate", - functions[r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -9365,183 +9499,49 @@ pub struct UVec4 { #[lua()] fn saturating_mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Returns a vector containing the saturating division of `self` and `rhs`. -/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - - #[lua()] - fn saturating_div( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`. -/// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`. - - #[lua()] - fn wrapping_add_signed( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Returns a vector containing the saturating addition of `self` and signed vector `rhs`. -/// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`. - - #[lua()] - fn saturating_add_signed( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: u64, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::<&bevy::math::U64Vec2>", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: u64, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: u64, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Rem::<&bevy::math::U64Vec2>", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Add::<&bevy::math::U64Vec2>", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: u64, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Div::<&bevy::math::U64Vec2>", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" +/// Returns a vector containing the saturating division of `self` and `rhs`. +/// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + #[lua()] + fn saturating_div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" +/// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`. +/// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`. - #[lua(as_trait = "std::ops::Sub::<&bevy::math::U64Vec2>", composite = "sub")] - fn sub( + #[lua()] + fn wrapping_add_signed( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" +/// Returns a vector containing the saturating addition of `self` and signed vector `rhs`. +/// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`. - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, + #[lua()] + fn saturating_add_signed( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: u64, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -9563,28 +9563,18 @@ pub struct U64Vec2 { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: u64, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::ops::Add::<&bevy::math::U64Vec3>", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -9608,17 +9598,8 @@ pub struct U64Vec2 { "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, rhs: u64, ) -> LuaReflectValProxy; @@ -10065,68 +10046,44 @@ pub struct U64Vec2 { "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); - -"#, - r#" - - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::<&bevy::math::U64Vec3>", composite = "mul")] fn mul( _self: LuaReflectValProxy, - rhs: u64, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::<&bevy::math::U64Vec3>", composite = "div")] + #[lua(as_trait = "std::ops::Div::", composite = "div")] fn div( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::<&bevy::math::U64Vec3>", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: u64, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, - rhs: u64, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Rem::<&bevy::math::U64Vec3>", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Add::<&bevy::math::U64Vec3>", composite = "add")] + fn add( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -10143,166 +10100,93 @@ pub struct U64Vec2 { "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u64, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; -"#, - r#" -#[lua(metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct U64Vec3 { - x: u64, - y: u64, - z: u64, -} -#[derive(bevy_mod_scripting_derive::LuaProxy)] -#[proxy( - remote = "bevy::math::U64Vec4", - bms_core_path = "bevy_mod_scripting_core", - bms_lua_path = "crate", - functions[r#" - - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: u64, - ) -> LuaReflectValProxy; - "#, r#" #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: u64, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::<&bevy::math::U64Vec4>", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua(as_trait = "std::ops::Rem::<&bevy::math::U64Vec4>", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] + #[lua(as_trait = "std::ops::Div::<&bevy::math::U64Vec3>", composite = "div")] fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + #[lua(as_trait = "std::ops::Rem::<&bevy::math::U64Vec3>", composite = "rem")] fn rem( - _self: LuaReflectValProxy, - rhs: u64, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; "#, r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct U64Vec3 { + x: u64, + y: u64, + z: u64, +} +#[derive(bevy_mod_scripting_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::U64Vec4", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" - #[lua(as_trait = "std::ops::Div::<&bevy::math::U64Vec4>", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" - #[lua(as_trait = "std::ops::Sub::<&bevy::math::U64Vec4>", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -10728,8 +10612,98 @@ pub struct U64Vec3 { "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::<&bevy::math::U64Vec4>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::<&bevy::math::U64Vec4>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::<&bevy::math::U64Vec4>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: u64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::<&bevy::math::U64Vec4>", composite = "sub")] fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, rhs: u64, ) -> LuaReflectValProxy; @@ -10746,12 +10720,38 @@ pub struct U64Vec3 { "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: u64, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -10773,8 +10773,8 @@ pub struct U64Vec4 { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, rhs: f32, ) -> LuaReflectValProxy; @@ -10782,44 +10782,52 @@ pub struct U64Vec4 { "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, - rhs: f32, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Rem::<&bevy::math::Vec2>", composite = "rem")] + fn rem( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::<&bevy::math::Vec2>", composite = "add")] fn add( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -10827,26 +10835,26 @@ pub struct U64Vec4 { "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::<&bevy::math::Vec2>", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::<&bevy::math::Vec2>", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Sub::<&bevy::math::Vec2>", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -10854,21 +10862,29 @@ pub struct U64Vec4 { "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Mul::<&bevy::math::Vec2>", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: f32, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" /// Creates a new vector. @@ -11714,52 +11730,35 @@ pub struct U64Vec4 { "#, r#" - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( - _self: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( _self: LuaReflectValProxy, - rhs: f32, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Rem::<&bevy::math::Vec2>", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::<&bevy::math::Vec2>", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: f32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::<&bevy::math::Vec2>", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: f32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, rhs: f32, ) -> LuaReflectValProxy; @@ -11767,9 +11766,10 @@ pub struct U64Vec4 { "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, + #[lua(as_trait = "std::ops::Div::<&bevy::math::Vec2>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -11803,6 +11803,15 @@ pub struct Vec2 { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] fn rem( _self: LuaReflectValProxy, @@ -11812,17 +11821,17 @@ pub struct Vec2 { "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Mul::<&bevy::math::Vec3A>", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -11830,27 +11839,19 @@ pub struct Vec2 { "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] + #[lua(as_trait = "std::ops::Add::<&bevy::math::Vec3A>", composite = "add")] fn add( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: f32, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -11865,8 +11866,8 @@ pub struct Vec2 { "#, r#" - #[lua(as_trait = "std::ops::Add::<&bevy::math::Vec3A>", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Div::<&bevy::math::Vec3A>", composite = "div")] + fn div( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -11874,10 +11875,10 @@ pub struct Vec2 { "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] fn sub( _self: LuaReflectValProxy, - rhs: f32, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -11892,8 +11893,8 @@ pub struct Vec2 { "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, rhs: f32, ) -> LuaReflectValProxy; @@ -11901,10 +11902,10 @@ pub struct Vec2 { "#, r#" - #[lua(as_trait = "std::ops::Sub::<&bevy::math::Vec3A>", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -11919,8 +11920,8 @@ pub struct Vec2 { "#, r#" - #[lua(as_trait = "std::ops::Div::<&bevy::math::Vec3A>", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Sub::<&bevy::math::Vec3A>", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -11928,36 +11929,9 @@ pub struct Vec2 { "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( _self: LuaReflectRefProxy, - rhs: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( - _self: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::<&bevy::math::Vec3A>", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -12793,6 +12767,32 @@ pub struct Vec2 { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -12830,88 +12830,105 @@ pub struct Vec3A(); "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Rem::<&bevy::math::Vec4>", composite = "rem")] + fn rem( _self: LuaReflectValProxy, - rhs: f32, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, + #[lua(as_trait = "std::ops::Div::<&bevy::math::Vec4>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: f32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::<&bevy::math::Vec4>", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Sub::<&bevy::math::Vec4>", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: f32, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Rem::<&bevy::math::Vec4>", composite = "rem")] + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] fn rem( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: f32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( _self: LuaReflectRefProxy, - rhs: LuaReflectRefProxy, - ) -> bool; + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::<&bevy::math::Vec4>", composite = "add")] + #[lua(as_trait = "std::ops::Add::", composite = "add")] fn add( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: f32, ) -> LuaReflectValProxy; @@ -12919,27 +12936,28 @@ pub struct Vec3A(); "#, r#" - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( + #[lua(as_trait = "std::ops::Add::<&bevy::math::Vec4>", composite = "add")] + fn add( _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::<&bevy::math::Vec4>", composite = "div")] + #[lua(as_trait = "std::ops::Div::", composite = "div")] fn div( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::<&bevy::math::Vec4>", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: f32, ) -> LuaReflectValProxy; "#, @@ -13724,37 +13742,19 @@ pub struct Vec3A(); "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::<&bevy::math::Vec4>", composite = "mul")] fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: f32, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -13793,8 +13793,11 @@ pub struct Vec4(); "#, r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -13863,11 +13866,8 @@ pub struct Vec4(); "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" @@ -13887,6 +13887,23 @@ pub struct BVec2 { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" /// Creates a new vector mask. #[lua()] @@ -13949,29 +13966,12 @@ pub struct BVec2 { value: bool, ) -> (); -"#, - r#" - - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - "#, r#" #[lua(as_trait = "std::cmp::Eq")] fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); -"#, - r#" - - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -13992,17 +13992,16 @@ pub struct BVec3 { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); "#, r#" @@ -14071,10 +14070,11 @@ pub struct BVec3 { "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -14097,27 +14097,28 @@ pub struct BVec4 { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: f64, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::<&bevy::math::DVec2>", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: f64, ) -> LuaReflectValProxy; "#, @@ -14132,37 +14133,37 @@ pub struct BVec4 { "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: f64, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::ops::Rem::<&bevy::math::DVec2>", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::<&bevy::math::DVec2>", composite = "div")] + #[lua(as_trait = "std::ops::Div::", composite = "div")] fn div( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Add::<&bevy::math::DVec2>", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -15019,43 +15020,42 @@ pub struct BVec4 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Sub::<&bevy::math::DVec2>", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: f64, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: f64, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::<&bevy::math::DVec2>", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Div::<&bevy::math::DVec2>", composite = "div")] + fn div( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -15063,38 +15063,38 @@ pub struct BVec4 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: f64, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: f64, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: f64, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + #[lua(as_trait = "std::ops::Rem::<&bevy::math::DVec2>", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -15127,66 +15127,21 @@ pub struct DVec2 { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::<&bevy::math::DVec3>", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::<&bevy::math::DVec3>", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Div::", composite = "div")] + #[lua(as_trait = "std::ops::Div::", composite = "div")] fn div( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: f64, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: f64, - ) -> LuaReflectValProxy; - "#, r#" @@ -15198,45 +15153,10 @@ pub struct DVec2 { "#, r#" - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( - _self: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: f64, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: f64, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] fn rem( _self: LuaReflectValProxy, - rhs: f64, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -16071,6 +15991,60 @@ pub struct DVec2 { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::<&bevy::math::DVec3>", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: f64, + ) -> LuaReflectValProxy; + "#, r#" @@ -16080,6 +16054,23 @@ pub struct DVec2 { rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "std::ops::Add::<&bevy::math::DVec3>", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + "#, r#" @@ -16092,8 +16083,17 @@ pub struct DVec2 { "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -16101,8 +16101,8 @@ pub struct DVec2 { "#, r#" - #[lua(as_trait = "std::ops::Add::<&bevy::math::DVec3>", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Sub::<&bevy::math::DVec3>", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -16110,10 +16110,10 @@ pub struct DVec2 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, - rhs: f64, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -16148,9 +16148,10 @@ pub struct DVec3 { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, + #[lua(as_trait = "std::ops::Div::<&bevy::math::DVec4>", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -16165,17 +16166,17 @@ pub struct DVec3 { "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, - rhs: f64, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::<&bevy::math::DVec4>", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Add::<&bevy::math::DVec4>", composite = "add")] + fn add( _self: LuaReflectValProxy, rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -16183,17 +16184,16 @@ pub struct DVec3 { "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -16201,81 +16201,90 @@ pub struct DVec3 { "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Sub::<&bevy::math::DVec4>", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: f64, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: f64, + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::<&bevy::math::DVec4>", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: f64, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::<&bevy::math::DVec4>", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: f64, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::<&bevy::math::DVec4>", composite = "add")] + #[lua(as_trait = "std::ops::Add::", composite = "add")] fn add( _self: LuaReflectValProxy, - rhs: LuaReflectRefProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: f64, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( + #[lua(as_trait = "std::ops::Mul::<&bevy::math::DVec4>", composite = "mul")] + fn mul( _self: LuaReflectValProxy, + rhs: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Rem::", composite = "rem")] - fn rem( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: f64, ) -> LuaReflectValProxy; "#, @@ -17056,15 +17065,6 @@ pub struct DVec3 { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - "#, r#" @@ -17077,10 +17077,10 @@ pub struct DVec3 { "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Rem::", composite = "rem")] + fn rem( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: f64, ) -> LuaReflectValProxy; "#, @@ -17115,14 +17115,6 @@ pub struct DVec4 { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" - - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( - _self: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" /// Creates a 2x2 matrix from two column vectors. #[lua()] @@ -17384,17 +17376,25 @@ pub struct DVec4 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -17402,18 +17402,19 @@ pub struct DVec4 { "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, - rhs: f32, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -17428,8 +17429,8 @@ pub struct DVec4 { "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -17437,19 +17438,18 @@ pub struct DVec4 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( _self: LuaReflectValProxy, - rhs: f32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: f32, ) -> LuaReflectValProxy; "#, @@ -17486,8 +17486,8 @@ pub struct Mat2(); bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -17504,8 +17504,17 @@ pub struct Mat2(); "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -17513,11 +17522,38 @@ pub struct Mat2(); "#, r#" - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + "#, r#" /// Creates a 3x3 matrix from three column vectors. @@ -17907,23 +17943,6 @@ pub struct Mat2(); _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" @@ -17936,8 +17955,8 @@ pub struct Mat2(); "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -17945,30 +17964,11 @@ pub struct Mat2(); "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - rhs: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -18006,6 +18006,85 @@ pub struct Mat3 { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( + _self: LuaReflectValProxy, + rhs: f32, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" /// Creates a 3x3 matrix from three column vectors. #[lua()] @@ -18378,117 +18457,38 @@ pub struct Mat3 { "#, r#" -/// Takes the absolute value of each element in `self` - - #[lua()] - fn abs( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua()] - fn as_dmat3( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( - _self: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - rhs: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: f32, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, +/// Takes the absolute value of each element in `self` + + #[lua()] + fn abs( + _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: f32, - ) -> LuaReflectValProxy; + #[lua()] + fn as_dmat3( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + rhs: f32, + ) -> LuaReflectValProxy; "#, r#" @@ -18528,19 +18528,10 @@ pub struct Mat3A { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: f32, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: f32, ) -> LuaReflectValProxy; "#, @@ -19201,8 +19192,8 @@ pub struct Mat3A { "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -19210,28 +19201,37 @@ pub struct Mat3A { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( _self: LuaReflectValProxy, - rhs: f32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - ) -> LuaReflectValProxy; + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -19245,20 +19245,20 @@ pub struct Mat3A { "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: f32, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - rhs: LuaReflectRefProxy, - ) -> bool; + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19307,8 +19307,8 @@ pub struct Mat4 { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, rhs: f64, ) -> LuaReflectValProxy; @@ -19316,25 +19316,17 @@ pub struct Mat4 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( - _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -19342,19 +19334,11 @@ pub struct Mat4 { "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - rhs: LuaReflectRefProxy, - ) -> bool; + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" @@ -19596,28 +19580,44 @@ pub struct Mat4 { "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: f64, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: f64, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -19657,71 +19657,54 @@ pub struct DMat2 { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: f64, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - rhs: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( - _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( - _self: LuaReflectValProxy, - rhs: f64, + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; "#, @@ -20106,8 +20089,16 @@ pub struct DMat2 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -20121,6 +20112,15 @@ pub struct DMat2 { rhs: f64, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + "#, r#" #[lua(metamethod="ToString")] @@ -20159,10 +20159,18 @@ pub struct DMat3 { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -20768,32 +20776,25 @@ pub struct DMat3 { "#, r#" - #[lua()] - fn as_mat4( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( + #[lua()] + fn as_mat4( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -20810,35 +20811,34 @@ pub struct DMat3 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" - #[lua(as_trait = "std::ops::Div::", composite = "div")] - fn div( + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( _self: LuaReflectValProxy, - rhs: f64, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( _self: LuaReflectRefProxy, - rhs: LuaReflectRefProxy, - ) -> bool; + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Div::", composite = "div")] + fn div( _self: LuaReflectValProxy, rhs: f64, ) -> LuaReflectValProxy; @@ -20846,11 +20846,11 @@ pub struct DMat3 { "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + rhs: f64, + ) -> LuaReflectValProxy; "#, r#" @@ -20890,6 +20890,50 @@ pub struct DMat4 { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" /// Creates an affine transform from three column vectors. #[lua()] @@ -21072,50 +21116,6 @@ pub struct DMat4 { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - rhs: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -21134,32 +21134,6 @@ pub struct Affine2 { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" /// Creates an affine transform from three column vectors. #[lua()] @@ -21462,57 +21436,48 @@ pub struct Affine2 { "#, r#" -#[lua(metamethod="ToString")] -fn index(&self) -> String { - format!("{:?}", _self) -} -"#] -)] -pub struct Affine3A { - matrix3: bevy::math::Mat3A, - translation: bevy::math::Vec3A, -} -#[derive(bevy_mod_scripting_derive::LuaProxy)] -#[proxy( - remote = "bevy::math::DAffine2", - bms_core_path = "bevy_mod_scripting_core", - bms_lua_path = "crate", - functions[r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - rhs: LuaReflectRefProxy, - ) -> bool; + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; "#, r#" +#[lua(metamethod="ToString")] +fn index(&self) -> String { + format!("{:?}", _self) +} +"#] +)] +pub struct Affine3A { + matrix3: bevy::math::Mat3A, + translation: bevy::math::Vec3A, +} +#[derive(bevy_mod_scripting_derive::LuaProxy)] +#[proxy( + remote = "bevy::math::DAffine2", + bms_core_path = "bevy_mod_scripting_core", + bms_lua_path = "crate", + functions[r#" /// Creates an affine transform from three column vectors. #[lua()] @@ -21683,10 +21648,45 @@ pub struct Affine3A { /// Return the inverse of this transform. /// Note that if the transform is not invertible the result will be invalid. - #[lua()] - fn inverse( + #[lua()] + fn inverse( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -21706,6 +21706,15 @@ pub struct DAffine2 { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" /// Creates an affine transform from three column vectors. #[lua()] @@ -21975,15 +21984,6 @@ pub struct DAffine2 { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - rhs: LuaReflectRefProxy, - ) -> bool; - "#, r#" @@ -21993,6 +21993,14 @@ pub struct DAffine2 { rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" @@ -22002,14 +22010,6 @@ pub struct DAffine2 { rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -22028,21 +22028,29 @@ pub struct DAffine3 { bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" -/// Subtracts the `rhs` quaternion from `self`. -/// The difference is not guaranteed to be normalized. +/// Multiplies a quaternion and a 3D vector, returning the rotated vector. +/// # Panics +/// Will panic if `self` is not normalized when `glam_assert` is enabled. - #[lua(as_trait = "std::ops::Sub::", composite = "sub")] - fn sub( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; "#, r#" +/// Multiplies two quaternions. If they each represent a rotation, the result will +/// represent the combined rotation. +/// Note that due to floating point rounding the result may not be perfectly +/// normalized. +/// # Panics +/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. - #[lua(as_trait = "std::ops::Neg", composite = "neg")] - fn neg( + #[lua(as_trait = "std::ops::Mul::", composite = "mul")] + fn mul( _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; "#, @@ -22056,39 +22064,6 @@ pub struct DAffine3 { rhs: f64, ) -> LuaReflectValProxy; -"#, - r#" -/// Adds two quaternions. -/// The sum is not guaranteed to be normalized. -/// Note that addition is not the same as combining the rotations represented by the -/// two quaternions! That corresponds to multiplication. - - #[lua(as_trait = "std::ops::Add::", composite = "add")] - fn add( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" -/// Multiplies a quaternion and a 3D vector, returning the rotated vector. -/// # Panics -/// Will panic if `self` is not normalized when `glam_assert` is enabled. - - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( - _self: LuaReflectValProxy, - rhs: LuaReflectValProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" /// Divides a quaternion by a scalar value. @@ -22102,15 +22077,11 @@ pub struct DAffine3 { "#, r#" -/// Multiplies two quaternions. If they each represent a rotation, the result will -/// represent the combined rotation. -/// Note that due to floating point rounding the result may not be perfectly -/// normalized. -/// # Panics -/// Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. +/// Subtracts the `rhs` quaternion from `self`. +/// The difference is not guaranteed to be normalized. - #[lua(as_trait = "std::ops::Mul::", composite = "mul")] - fn mul( + #[lua(as_trait = "std::ops::Sub::", composite = "sub")] + fn sub( _self: LuaReflectValProxy, rhs: LuaReflectValProxy, ) -> LuaReflectValProxy; @@ -22118,11 +22089,18 @@ pub struct DAffine3 { "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( + #[lua(as_trait = "std::ops::Neg", composite = "neg")] + fn neg( + _self: LuaReflectValProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( _self: LuaReflectRefProxy, - rhs: LuaReflectRefProxy, - ) -> bool; + ) -> LuaReflectValProxy; "#, r#" @@ -22561,6 +22539,28 @@ pub struct DAffine3 { _self: LuaReflectValProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + rhs: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" +/// Adds two quaternions. +/// The sum is not guaranteed to be normalized. +/// Note that addition is not the same as combining the rotations represented by the +/// two quaternions! That corresponds to multiplication. + + #[lua(as_trait = "std::ops::Add::", composite = "add")] + fn add( + _self: LuaReflectValProxy, + rhs: LuaReflectValProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -22582,6 +22582,15 @@ pub struct DQuat { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] fn clone( _self: LuaReflectRefProxy, @@ -22595,15 +22604,6 @@ pub struct DQuat { _self: LuaReflectRefProxy, ) -> (); -"#, - r#" - - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - "#, r#" #[lua(metamethod="ToString")] @@ -22714,10 +22714,11 @@ pub struct BVec3A(); bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone( + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + rhs: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -22786,11 +22787,10 @@ pub struct BVec3A(); "#, r#" - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone( _self: LuaReflectRefProxy, - rhs: LuaReflectRefProxy, - ) -> bool; + ) -> LuaReflectValProxy; "#, r#" @@ -22861,38 +22861,6 @@ pub struct SmolStr(); bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" - - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); - -"#, - r#" -/// Creates a random UUID. -/// This uses the [`getrandom`] crate to utilise the operating system's RNG -/// as the source of random numbers. If you'd like to use a custom -/// generator, don't use this method: generate random bytes using your -/// custom generator and pass them to the -/// [`uuid::Builder::from_random_bytes`][from_random_bytes] function -/// instead. -/// Note that usage of this method requires the `v4` feature of this crate -/// to be enabled. -/// # Examples -/// Basic usage: -/// ``` -/// # use uuid::{Uuid, Version}; -/// let uuid = Uuid::new_v4(); -/// assert_eq!(Some(Version::Random), uuid.get_version()); -/// ``` -/// # References -/// * [UUID Version 4 in RFC 9562](https://www.ietf.org/rfc/rfc9562.html#section-5.4) -/// [`getrandom`]: https://crates.io/crates/getrandom -/// [from_random_bytes]: struct.Builder.html#method.from_random_bytes - - #[lua()] - fn new_v4() -> LuaReflectValProxy; - -"#, - r#" /// Returns the version number of the UUID. /// This represents the algorithm used to generate the value. /// This method is the future-proof alternative to [`Uuid::get_version`]. @@ -23074,6 +23042,44 @@ pub struct SmolStr(); _self: LuaReflectRefProxy, ) -> bevy::reflect::erased_serde::__private::serde::__private::Option<[u8; 6]>; +"#, + r#" + + #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] + fn clone(_self: LuaReflectRefProxy) -> LuaReflectValProxy; + +"#, + r#" +/// Creates a random UUID. +/// This uses the [`getrandom`] crate to utilise the operating system's RNG +/// as the source of random numbers. If you'd like to use a custom +/// generator, don't use this method: generate random bytes using your +/// custom generator and pass them to the +/// [`uuid::Builder::from_random_bytes`][from_random_bytes] function +/// instead. +/// Note that usage of this method requires the `v4` feature of this crate +/// to be enabled. +/// # Examples +/// Basic usage: +/// ``` +/// # use uuid::{Uuid, Version}; +/// let uuid = Uuid::new_v4(); +/// assert_eq!(Some(Version::Random), uuid.get_version()); +/// ``` +/// # References +/// * [UUID Version 4 in RFC 9562](https://www.ietf.org/rfc/rfc9562.html#section-5.4) +/// [`getrandom`]: https://crates.io/crates/getrandom +/// [from_random_bytes]: struct.Builder.html#method.from_random_bytes + + #[lua()] + fn new_v4() -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq(_self: LuaReflectRefProxy) -> (); + "#, r#" /// The 'nil UUID' (all zeros). @@ -23237,12 +23243,6 @@ pub struct SmolStr(); other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "bevy::reflect::erased_serde::__private::serde::__private::Clone")] - fn clone(_self: LuaReflectRefProxy) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs index a066640a81..c75985d924 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs @@ -63,10 +63,10 @@ pub struct Real {} bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( + #[lua(as_trait = "std::clone::Clone")] + fn clone( _self: LuaReflectRefProxy, - ) -> (); + ) -> LuaReflectValProxy; "#, r#" @@ -317,14 +317,6 @@ pub struct Real {} _self: LuaReflectRefProxy, ) -> u32; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" @@ -337,6 +329,14 @@ pub struct Real {} other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + "#, r#" #[lua(metamethod="ToString")] @@ -353,10 +353,10 @@ pub struct Timer {} bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( + #[lua(as_trait = "std::clone::Clone")] + fn clone( _self: LuaReflectRefProxy, - ) -> (); + ) -> LuaReflectValProxy; "#, r#" @@ -373,10 +373,10 @@ pub struct Timer {} "#, r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + ) -> (); "#, r#" @@ -414,31 +414,6 @@ pub struct Virtual {} bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" - - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" /// Create a new unpaused `Stopwatch` with no elapsed time. /// # Examples /// ``` @@ -551,6 +526,31 @@ pub struct Virtual {} #[lua()] fn reset(_self: LuaReflectRefMutProxy) -> (); +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua(as_trait = "std::cmp::PartialEq::", composite = "eq")] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + "#, r#" #[lua(metamethod="ToString")] diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs index f1c2607d4c..759124267a 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs @@ -24,14 +24,10 @@ use crate::{ bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( + #[lua(as_trait = "std::clone::Clone")] + fn clone( _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + ) -> LuaReflectValProxy; "#, r#" @@ -48,11 +44,29 @@ use crate::{ "#, r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, + #[lua( + as_trait = "std::ops::Mul::", + composite = "mul", + )] + fn mul( + _self: LuaReflectValProxy, + global_transform: LuaReflectValProxy< + bevy::transform::components::GlobalTransform, + >, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + "#, r#" @@ -124,20 +138,6 @@ use crate::{ transform: LuaReflectValProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul::", - composite = "mul", - )] - fn mul( - _self: LuaReflectValProxy, - global_transform: LuaReflectValProxy< - bevy::transform::components::GlobalTransform, - >, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -163,6 +163,20 @@ pub struct GlobalTransform(); other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua( + as_trait = "std::ops::Mul::", + composite = "mul", + )] + fn mul( + _self: LuaReflectValProxy, + global_transform: LuaReflectValProxy< + bevy::transform::components::GlobalTransform, + >, + ) -> LuaReflectValProxy; + "#, r#" /// Creates a new [`Transform`] at the position `(x, y, z)`. In 2d, the `z` component @@ -261,20 +275,6 @@ pub struct GlobalTransform(); _self: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua( - as_trait = "std::ops::Mul::", - composite = "mul", - )] - fn mul( - _self: LuaReflectValProxy, - global_transform: LuaReflectValProxy< - bevy::transform::components::GlobalTransform, - >, - ) -> LuaReflectValProxy; - "#, r#" diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs index 95df5fe7a7..46be3ee95d 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs @@ -25,6 +25,14 @@ use crate::{ bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -34,14 +42,6 @@ use crate::{ other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" @@ -68,18 +68,18 @@ pub struct CursorEntered { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + ) -> (); "#, r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( + #[lua(as_trait = "std::clone::Clone")] + fn clone( _self: LuaReflectRefProxy, - ) -> (); + ) -> LuaReflectValProxy; "#, r#" @@ -189,14 +189,6 @@ pub struct FileDragAndDrop {} bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - -"#, - r#" - #[lua(as_trait = "std::clone::Clone")] fn clone( _self: LuaReflectRefProxy, @@ -214,6 +206,14 @@ pub struct FileDragAndDrop {} other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + "#, r#" #[lua(metamethod="ToString")] @@ -230,14 +230,6 @@ pub struct Ime {} bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -247,6 +239,14 @@ pub struct Ime {} other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" @@ -270,6 +270,14 @@ pub struct MonitorSelection {} bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" /// Setting to true will attempt to maximize the window. /// Setting to false will attempt to un-maximize the window. @@ -341,14 +349,6 @@ pub struct MonitorSelection {} #[lua()] fn scale_factor(_self: LuaReflectRefProxy) -> f32; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -402,6 +402,14 @@ pub struct Window { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -411,14 +419,6 @@ pub struct Window { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" @@ -488,9 +488,11 @@ pub struct WindowPosition {} bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" +/// Checks if the constraints are valid. +/// Will output warnings if it isn't. - #[lua(as_trait = "std::clone::Clone")] - fn clone( + #[lua()] + fn check_constraints( _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -508,11 +510,9 @@ pub struct WindowPosition {} "#, r#" -/// Checks if the constraints are valid. -/// Will output warnings if it isn't. - #[lua()] - fn check_constraints( + #[lua(as_trait = "std::clone::Clone")] + fn clone( _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; @@ -537,6 +537,14 @@ pub struct WindowResizeConstraints { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -546,14 +554,6 @@ pub struct WindowResizeConstraints { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -693,6 +693,14 @@ pub struct WindowClosing { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + #[lua(as_trait = "std::clone::Clone")] fn clone( _self: LuaReflectRefProxy, @@ -710,14 +718,6 @@ pub struct WindowClosing { other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - "#, r#" #[lua(metamethod="ToString")] @@ -736,10 +736,14 @@ pub struct WindowClosed { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( _self: LuaReflectRefProxy, - ) -> (); + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -752,14 +756,10 @@ pub struct WindowClosed { "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + ) -> (); "#, r#" @@ -791,18 +791,18 @@ pub struct WindowCloseRequested { "#, r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( + #[lua(as_trait = "std::clone::Clone")] + fn clone( _self: LuaReflectRefProxy, - ) -> (); + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + ) -> (); "#, r#" @@ -863,14 +863,6 @@ pub struct RequestRedraw {} bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - -"#, - r#" - #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -880,6 +872,14 @@ pub struct RequestRedraw {} other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + "#, r#" @@ -907,6 +907,14 @@ pub struct WindowFocused { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -924,14 +932,6 @@ pub struct WindowFocused { _self: LuaReflectRefProxy, ) -> (); -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -987,14 +987,6 @@ pub struct WindowScaleFactorChanged { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -1004,6 +996,14 @@ pub struct WindowScaleFactorChanged { other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -1023,6 +1023,14 @@ pub struct WindowBackendScaleFactorChanged { bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -1040,14 +1048,6 @@ pub struct WindowBackendScaleFactorChanged { _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; -"#, - r#" - - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - "#, r#" #[lua(metamethod="ToString")] @@ -1067,22 +1067,18 @@ pub struct WindowThemeChanged { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + ) -> (); "#, r#" - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( + #[lua(as_trait = "std::clone::Clone")] + fn clone( _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + ) -> LuaReflectValProxy; "#, r#" @@ -1094,10 +1090,14 @@ pub struct WindowThemeChanged { "#, r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( _self: LuaReflectRefProxy, - ) -> (); + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -1156,14 +1156,6 @@ pub struct PrimaryWindow {} bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - -"#, - r#" - #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -1173,6 +1165,14 @@ pub struct PrimaryWindow {} other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + "#, r#" @@ -1272,14 +1272,6 @@ pub struct PrimaryMonitor {} bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - #[lua(as_trait = "std::cmp::Eq")] fn assert_receiver_is_total_eq( _self: LuaReflectRefProxy, @@ -1297,6 +1289,14 @@ pub struct PrimaryMonitor {} other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -1400,14 +1400,6 @@ pub struct CursorOptions { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - -"#, - r#" - #[lua(as_trait = "std::clone::Clone")] fn clone( _self: LuaReflectRefProxy, @@ -1425,6 +1417,14 @@ pub struct CursorOptions { other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + "#, r#" #[lua(metamethod="ToString")] @@ -1441,18 +1441,6 @@ pub struct PresentMode {} bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - -"#, - r#" - #[lua(as_trait = "std::cmp::Eq")] fn assert_receiver_is_total_eq( _self: LuaReflectRefProxy, @@ -1466,6 +1454,18 @@ pub struct PresentMode {} _self: LuaReflectRefProxy, ) -> LuaReflectValProxy; +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + "#, r#" #[lua(metamethod="ToString")] @@ -1481,14 +1481,6 @@ pub struct WindowMode {} bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" /// Creates a new [`WindowResolution`]. #[lua()] @@ -1634,6 +1626,14 @@ pub struct WindowMode {} other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + "#, r#" #[lua(metamethod="ToString")] @@ -1650,14 +1650,10 @@ pub struct WindowResolution {} bms_lua_path = "crate", functions[r#" - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; + ) -> (); "#, r#" @@ -1670,10 +1666,14 @@ pub struct WindowResolution {} "#, r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( _self: LuaReflectRefProxy, - ) -> (); + other: LuaReflectRefProxy, + ) -> bool; "#, r#" @@ -1691,6 +1691,14 @@ pub struct CompositeAlphaMode {} bms_lua_path = "crate", functions[r#" + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -1700,14 +1708,6 @@ pub struct CompositeAlphaMode {} other: LuaReflectRefProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - "#, r#" #[lua(metamethod="ToString")] @@ -1728,14 +1728,6 @@ pub struct EnabledButtons { bms_lua_path = "crate", functions[r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( - _self: LuaReflectRefProxy, - ) -> (); - -"#, - r#" - #[lua( as_trait = "std::cmp::PartialEq::", composite = "eq", @@ -1745,6 +1737,14 @@ pub struct EnabledButtons { other: LuaReflectRefProxy, ) -> bool; +"#, + r#" + + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( + _self: LuaReflectRefProxy, + ) -> (); + "#, r#" @@ -1768,6 +1768,26 @@ pub struct WindowLevel {} bms_core_path = "bevy_mod_scripting_core", bms_lua_path = "crate", functions[r#" + + #[lua(as_trait = "std::clone::Clone")] + fn clone( + _self: LuaReflectRefProxy, + ) -> LuaReflectValProxy; + +"#, + r#" + + #[lua( + as_trait = "std::cmp::PartialEq::", + composite = "eq", + )] + fn eq( + _self: LuaReflectRefProxy, + other: LuaReflectRefProxy, + ) -> bool; + +"#, + r#" /// Consumes the current maximize request, if it exists. This should only be called by window backends. #[lua()] @@ -1793,26 +1813,6 @@ pub struct WindowLevel {} _self: LuaReflectRefMutProxy, ) -> bool; -"#, - r#" - - #[lua(as_trait = "std::clone::Clone")] - fn clone( - _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; - -"#, - r#" - - #[lua( - as_trait = "std::cmp::PartialEq::", - composite = "eq", - )] - fn eq( - _self: LuaReflectRefProxy, - other: LuaReflectRefProxy, - ) -> bool; - "#, r#" #[lua(metamethod="ToString")] @@ -1841,18 +1841,18 @@ pub struct InternalWindowState {} "#, r#" - #[lua(as_trait = "std::cmp::Eq")] - fn assert_receiver_is_total_eq( + #[lua(as_trait = "std::clone::Clone")] + fn clone( _self: LuaReflectRefProxy, - ) -> (); + ) -> LuaReflectValProxy; "#, r#" - #[lua(as_trait = "std::clone::Clone")] - fn clone( + #[lua(as_trait = "std::cmp::Eq")] + fn assert_receiver_is_total_eq( _self: LuaReflectRefProxy, - ) -> LuaReflectValProxy; + ) -> (); "#, r#" diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/mod.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/mod.rs index 094ba75fd2..8354d705cc 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/mod.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/mod.rs @@ -2,16 +2,16 @@ #![allow(clippy::all)] #![allow(unused, deprecated, dead_code)] #![cfg_attr(rustfmt, rustfmt_skip)] -pub(crate) mod bevy_a11y; -pub(crate) mod bevy_ecs; -pub(crate) mod bevy_transform; -pub(crate) mod bevy_math; -pub(crate) mod bevy_input; -pub(crate) mod bevy_core; -pub(crate) mod bevy_time; -pub(crate) mod bevy_hierarchy; -pub(crate) mod bevy_window; -pub(crate) mod bevy_reflect; +pub mod bevy_a11y; +pub mod bevy_ecs; +pub mod bevy_transform; +pub mod bevy_math; +pub mod bevy_input; +pub mod bevy_core; +pub mod bevy_time; +pub mod bevy_hierarchy; +pub mod bevy_window; +pub mod bevy_reflect; pub struct LuaBevyScriptingPlugin; impl bevy::app::Plugin for LuaBevyScriptingPlugin { fn build(&self, app: &mut bevy::prelude::App) { diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_component/component_no_component_data.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_component/component_no_component_data.lua new file mode 100644 index 0000000000..c9f8550d9d --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/get_component/component_no_component_data.lua @@ -0,0 +1,6 @@ +local component = world:get_type_by_name("CompWithDefault") +local entity = _get_entity_with_test_component("CompWithDefault") +local retrieved = world:get_component(entity, component) + +assert(retrieved ~= nil, "Component was not found") +assert(retrieved._1 == "Initial Value", "Component data was not retrieved correctly, retrieved._1 was: " .. retrieved._1) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_component/component_with_component_data.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_component/component_with_component_data.lua index a519c47e98..264f4badca 100644 --- a/crates/languages/bevy_mod_scripting_lua/tests/data/get_component/component_with_component_data.lua +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/get_component/component_with_component_data.lua @@ -1,3 +1,6 @@ -let component = world:get_type_by_name("TestComponent") -world:get_component(entity, component) -// TODO \ No newline at end of file +local component = world:get_type_by_name("TestComponent") +local entity = _get_entity_with_test_component("TestComponent") +local retrieved = world:get_component(entity, component) + +assert(retrieved ~= nil, "Component was not found") +assert(retrieved.strings[1] == "Initial", "Component data was not retrieved correctly, retrieved.strings[1] was: " .. retrieved.strings[1]) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs b/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs index c4e6eb8b54..ddc5119a92 100644 --- a/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs +++ b/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs @@ -5,15 +5,17 @@ use bevy::{ MinimalPlugins, }; use bevy_mod_scripting_core::{ - bindings::{Proxy, ReflectAllocator, ReflectValProxy, WorldCallbackAccess}, + bindings::{Proxy, ReflectAllocator, ReflectReference, ReflectValProxy, WorldCallbackAccess}, context::ContextLoadingSettings, + error::ScriptError, event::CallbackLabel, script::ScriptId, }; use bevy_mod_scripting_lua::{ bindings::{ + providers::bevy_ecs::LuaEntity, proxy::{LuaProxied, LuaReflectValProxy}, - world::LuaWorld, + world::{GetWorld, LuaWorld}, }, lua_context_load, lua_handler, prelude::{Lua, LuaHookTriggers}, @@ -22,11 +24,12 @@ use bevy_mod_scripting_lua::{ use libtest_mimic::{Arguments, Failed, Trial}; use std::{ any::TypeId, + borrow::Cow, fs::{self, DirEntry}, io, path::{Path, PathBuf}, }; -use test_utils::test_data::setup_world; +use test_utils::test_data::{setup_world, EnumerateTestComponents}; /// Initializes world for tests fn init_app() -> App { @@ -44,6 +47,39 @@ fn init_app() -> App { app } +fn init_lua_test_utils(_script_name: &Cow<'static, str>, lua: &mut Lua) -> Result<(), ScriptError> { + let _get_entity_with_test_component = lua + .create_function(|l, s: String| { + let world = l.get_world().unwrap(); + let opt_entity = world.with_resource::(|_, mut allocator| { + let a = World::enumerate_test_components() + .iter() + .find(|(name, _, _)| name.contains(&s)) + .map(|(_, _, c)| { + let reference = ReflectReference::new_allocated( + c.unwrap_or(Entity::from_raw(9999)), + &mut allocator, + ); + <::Proxy>::from(reference) + }); + + a + }); + + Ok(opt_entity) + }) + .unwrap(); + + lua.globals() + .set( + "_get_entity_with_test_component", + _get_entity_with_test_component, + ) + .unwrap(); + + Ok(()) +} + struct Test { code: String, path: PathBuf, @@ -54,10 +90,13 @@ impl Test { // let lua = Lua::new(); // set file information let mut app = init_app(); - let context_settings: ContextLoadingSettings = - app.world_mut() - .remove_resource() - .ok_or("could not find context loading settings")?; + let mut context_settings: ContextLoadingSettings = app + .world_mut() + .remove_resource() + .ok_or("could not find context loading settings")?; + context_settings + .context_initializers + .push(init_lua_test_utils); let mut lua = lua_context_load( &(self.name()).into(), @@ -89,18 +128,7 @@ impl Test { } fn name(&self) -> String { - // use the path from teh "data" directory as the test name separated by hyphens - let test = self - .path - .to_string_lossy() - .split("data") - .skip(1) - .collect::>() - .join("data") - .trim_start_matches("/") - .replace("/", " - ") - .replace(".lua", ""); - format!("lua_test - {test}") + format!("lua_test - {}", self.path.to_string_lossy()) } } From 19985af27cf3f74ae65892172a3eea5fc5a876d6 Mon Sep 17 00:00:00 2001 From: makspll Date: Thu, 14 Nov 2024 14:05:40 +0000 Subject: [PATCH 09/22] remove git repo in test_utils --- crates/test_utils/Cargo.toml | 11 ++ crates/test_utils/src/asserts.rs | 1 + crates/test_utils/src/lib.rs | 2 + crates/test_utils/src/test_data.rs | 222 +++++++++++++++++++++++++++++ 4 files changed, 236 insertions(+) create mode 100644 crates/test_utils/Cargo.toml create mode 100644 crates/test_utils/src/asserts.rs create mode 100644 crates/test_utils/src/lib.rs create mode 100644 crates/test_utils/src/test_data.rs diff --git a/crates/test_utils/Cargo.toml b/crates/test_utils/Cargo.toml new file mode 100644 index 0000000000..9c3b96d895 --- /dev/null +++ b/crates/test_utils/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "test_utils" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +bevy = { workspace = true } + +[lib] +path = "src/lib.rs" diff --git a/crates/test_utils/src/asserts.rs b/crates/test_utils/src/asserts.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/crates/test_utils/src/asserts.rs @@ -0,0 +1 @@ + diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs new file mode 100644 index 0000000000..7a05954925 --- /dev/null +++ b/crates/test_utils/src/lib.rs @@ -0,0 +1,2 @@ +pub mod asserts; +pub mod test_data; diff --git a/crates/test_utils/src/test_data.rs b/crates/test_utils/src/test_data.rs new file mode 100644 index 0000000000..04400ad3e8 --- /dev/null +++ b/crates/test_utils/src/test_data.rs @@ -0,0 +1,222 @@ +use std::alloc::Layout; +use std::sync::{Arc, RwLock}; + +use bevy::ecs::{component::*, world::World}; +use bevy::prelude::*; +use bevy::reflect::*; + +/// Test component with Reflect and ReflectComponent registered +#[derive(Component, Reflect, PartialEq, Eq, Debug)] +#[reflect(Component)] +pub struct TestComponent { + pub strings: Vec, +} + +impl TestComponent { + pub fn init() -> Self { + Self { + strings: vec!["Initial".to_string(), "Value".to_string()], + } + } +} + +/// Test Resource with Reflect and ReflectResource registered +#[derive(Resource, Reflect, Default, PartialEq, Eq, Debug)] +#[reflect(Resource)] +pub struct TestResource { + pub bytes: Vec, +} + +impl TestResource { + pub fn init() -> Self { + Self { + bytes: vec![0, 1, 2, 3, 4, 5], + } + } +} + +/// Component with Reflect and ReflectFromWorld registered but no ReflectComponent +#[derive(Reflect, Component, PartialEq, Debug)] +#[reflect(FromWorld)] +pub struct CompWithFromWorld(pub String); + +impl Default for CompWithFromWorld { + fn default() -> Self { + Self(String::from("Default")) + } +} + +impl CompWithFromWorld { + pub fn init() -> Self { + Self(String::from("Initial Value")) + } +} + +/// Component with Reflect and ReflectDefault but no ReflectComponent +#[derive(Component, Reflect, PartialEq, Eq, Debug)] +#[reflect(Default)] +pub struct CompWithDefault(pub String); + +impl CompWithDefault { + pub fn init() -> Self { + Self(String::from("Initial Value")) + } +} + +impl Default for CompWithDefault { + fn default() -> Self { + Self(String::from("Default")) + } +} + +#[derive(Component, Reflect, PartialEq, Eq, Debug)] +#[reflect(Component, Default)] +pub struct CompWithDefaultAndComponentData(pub String); +impl Default for CompWithDefaultAndComponentData { + fn default() -> Self { + Self(String::from("Default")) + } +} + +impl CompWithDefaultAndComponentData { + pub fn init() -> Self { + Self(String::from("Initial Value")) + } +} + +#[derive(Component, Reflect, PartialEq, Eq, Debug)] +#[reflect(Component, FromWorld)] +pub struct CompWithFromWorldAndComponentData(pub String); +impl Default for CompWithFromWorldAndComponentData { + fn default() -> Self { + Self(String::from("Default")) + } +} + +impl CompWithFromWorldAndComponentData { + pub fn init() -> Self { + Self(String::from("Initial Value")) + } +} + +pub(crate) const TEST_COMPONENT_ID_START: usize = 20; +pub(crate) const TEST_ENTITY_ID_START: u32 = 0; + +pub trait GetTestComponentId { + fn test_component_id() -> ComponentId; +} + +pub trait GetTestEntityId { + fn test_entity_id() -> Entity; +} + +pub trait EnumerateTestComponents { + fn enumerate_test_components() -> Vec<(&'static str, ComponentId, Option)>; +} + +macro_rules! impl_test_component_ids { + ([$($comp_type:ty => $comp_id:expr),* $(,)?], [$($res_type:ty => $res_id:expr),* $(,)?]) => { + $( + impl GetTestComponentId for $comp_type { + fn test_component_id() -> ComponentId { + ComponentId::new(TEST_COMPONENT_ID_START + $comp_id) + } + } + + impl GetTestEntityId for $comp_type { + fn test_entity_id() -> Entity { + Entity::from_raw(TEST_ENTITY_ID_START + $comp_id) + } + } + )* + $( + impl GetTestComponentId for $res_type { + fn test_component_id() -> ComponentId { + ComponentId::new(TEST_COMPONENT_ID_START + $res_id) + } + } + )* + + pub(crate) fn init_all_components(world: &mut World, registry: &mut TypeRegistry) { + $( + world.register_component::<$comp_type>(); + registry.register::<$comp_type>(); + let registered_id = world.component_id::<$comp_type>().unwrap().index(); + assert_eq!(registered_id, TEST_COMPONENT_ID_START + $comp_id, "Test setup failed. Did you register components before running setup_world?"); + let entity = world.spawn(<$comp_type>::init()).id(); + assert_eq!(entity.index(), TEST_ENTITY_ID_START + $comp_id, "Test setup failed. Did you spawn entities before running setup_world?"); + assert_eq!(entity.generation(), 1, "Test setup failed. Did you spawn entities before running setup_world?"); + )* + $( + world.init_resource::<$res_type>(); + registry.register::<$res_type>(); + let registered_id = world.resource_id::<$res_type>().unwrap().index(); + assert_eq!(registered_id, TEST_COMPONENT_ID_START + $res_id, "Test setup failed. Did you register components before running setup_world?"); + )* + } + + impl EnumerateTestComponents for World { + fn enumerate_test_components() -> Vec<(&'static str, ComponentId, Option)> { + vec![ + $( + (std::any::type_name::<$comp_type>(), <$comp_type as GetTestComponentId>::test_component_id(), Some(<$comp_type as GetTestEntityId>::test_entity_id())) + ),* + $( + ,(std::any::type_name::<$res_type>(), <$res_type as GetTestComponentId>::test_component_id(), None) + )* + + ] + } + } + }; +} + +impl_test_component_ids!( + [ TestComponent => 0, + CompWithFromWorld => 1, + CompWithDefault => 2, + CompWithDefaultAndComponentData => 3, + CompWithFromWorldAndComponentData => 4 + ], + [ + TestResource => 5 + ] +); + +/// Initializes a default world with a set of test components and resources with various properties and implemantations. +pub fn setup_world(init: F) -> World { + let mut world = World::default(); + + // find the number of ComponentId's registered, fill it up until we hit the offset + while world.components().len() < TEST_COMPONENT_ID_START { + unsafe { + world.register_component_with_descriptor(ComponentDescriptor::new_with_layout( + format!("Filler{}", world.components().len()), + StorageType::Table, + Layout::new::(), + None, + )) + }; + } + + let mut type_registry = TypeRegistry::new(); + init_all_components(&mut world, &mut type_registry); + + init(&mut world, &mut type_registry); + + world.insert_resource(AppTypeRegistry(TypeRegistryArc { + internal: Arc::new(RwLock::new(type_registry)), + })); + + world +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn setup_works() { + setup_world(|_, _| {}); + } +} From 01dcf8ee9fdba0c0c06f963aee2b833ab8f59f61 Mon Sep 17 00:00:00 2001 From: makspll Date: Thu, 14 Nov 2024 17:03:38 +0000 Subject: [PATCH 10/22] add tests for api availability --- .../data/api_availability/api_available_on_callback.lua | 5 +++++ .../data/api_availability/api_available_on_script_load.lua | 3 +++ crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/api_availability/api_available_on_callback.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/api_availability/api_available_on_script_load.lua diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/api_availability/api_available_on_callback.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/api_availability/api_available_on_callback.lua new file mode 100644 index 0000000000..0048f7f653 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/api_availability/api_available_on_callback.lua @@ -0,0 +1,5 @@ +function on_test() + assert(world ~= nil, "World was not found") + assert(world:get_type_by_name("TestComponent") ~= nil, "Could not find TestComponent type") + Entity.from_raw(1) +end \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/api_availability/api_available_on_script_load.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/api_availability/api_available_on_script_load.lua new file mode 100644 index 0000000000..50c2e90ed8 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/api_availability/api_available_on_script_load.lua @@ -0,0 +1,3 @@ +assert(world ~= nil, "World was not found") +assert(world:get_type_by_name("TestComponent") ~= nil, "Could not find TestComponent type") +Entity.from_raw(1) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs b/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs index ddc5119a92..f0364e7fa3 100644 --- a/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs +++ b/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs @@ -111,7 +111,7 @@ impl Test { (), Entity::from_raw(1), &(self.name()).into(), - &CallbackLabel::new("test").ok_or("invalid callback label")?, + &CallbackLabel::new("on_test").ok_or("invalid callback label")?, &mut lua, &context_settings.context_pre_handling_initializers, &mut (), From 0f648524be5109fead22ddb5bccc4ef4d383afe9 Mon Sep 17 00:00:00 2001 From: makspll Date: Thu, 14 Nov 2024 17:25:56 +0000 Subject: [PATCH 11/22] remove unused file --- crates/bevy_mod_scripting_core/src/hosts.rs | 453 -------------------- 1 file changed, 453 deletions(-) delete mode 100644 crates/bevy_mod_scripting_core/src/hosts.rs diff --git a/crates/bevy_mod_scripting_core/src/hosts.rs b/crates/bevy_mod_scripting_core/src/hosts.rs deleted file mode 100644 index 1225782a42..0000000000 --- a/crates/bevy_mod_scripting_core/src/hosts.rs +++ /dev/null @@ -1,453 +0,0 @@ -//! All script host related stuff -use bevy::{asset::Asset, ecs::schedule::ScheduleLabel, prelude::*}; -use std::{ - collections::HashMap, - iter::once, - sync::atomic::{AtomicU32, Ordering}, -}; - -use crate::{ - asset::CodeAsset, - docs::DocFragment, - error::ScriptError, - event::{ScriptEvent, ScriptLoaded}, - world::WorldPointer, - ScriptErrorEvent, -}; - -/// Describes the target set of scripts this event should -/// be handled by -#[derive(Clone, Debug)] -pub enum Recipients { - /// Send to all scripts - All, - /// Send only to scripts on the given entity - Entity(Entity), - /// Send to script with the given ID - ScriptID(u32), - // Send to script with the given name - ScriptName(String), -} - -#[derive(Debug)] -/// Data used to describe a script instance. -pub struct ScriptData<'a> { - pub sid: u32, - pub entity: Entity, - pub name: &'a str, -} - -impl Recipients { - /// Returns true if the given script is a recipient - pub fn is_recipient(&self, c: &ScriptData) -> bool { - match self { - Recipients::All => true, - Recipients::Entity(e) => e == &c.entity, - Recipients::ScriptID(i) => i == &c.sid, - Recipients::ScriptName(n) => n == c.name, - } - } -} - -impl Default for Recipients { - fn default() -> Self { - Self::All - } -} - -/// A script host is the interface between your rust application -/// and the scripts in some interpreted language. -pub trait ScriptHost: Send + Sync + 'static + Default + Resource { - /// the type of the persistent script context, representing the execution context of the script - type ScriptContext: Send + Sync + 'static; - /// the type of events picked up by lua callbacks - type ScriptEvent: ScriptEvent; - /// the type of asset representing the script files for this host - type ScriptAsset: CodeAsset; - /// the type representing the target of api providers, i.e. the - /// script engine or the script context itself - type APITarget: Send + Sync + 'static; - /// the type of each doc fragment - type DocTarget: DocFragment; - - /// Loads a script in byte array format, the script name can be used - /// to send useful errors. - fn load_script( - &mut self, - script: &[u8], - script_data: &ScriptData, - providers: &mut APIProviders, - ) -> Result; - - /// Perform one-off initialization of scripts (happens for every new or re-loaded script) - fn setup_script( - &mut self, - script_data: &ScriptData, - ctx: &mut Self::ScriptContext, - providers: &mut APIProviders, - ) -> Result<(), ScriptError>; - - /// the main point of contact with the bevy world. - /// Scripts are called with appropriate events in the event order - fn handle_events<'a>( - &mut self, - world_ptr: &mut World, - events: &[Self::ScriptEvent], - ctxs: impl Iterator, &'a mut Self::ScriptContext)>, - providers: &mut APIProviders, - ); - - /// Loads and runs script instantaneously without storing any script data into the world. - /// The script id is set to `u32::MAX`. - fn run_one_shot( - &mut self, - script: &[u8], - script_name: &str, - entity: Entity, - world: &mut World, - event: Self::ScriptEvent, - ) -> Result<(), ScriptError> { - let fd = ScriptData { - name: script_name, - sid: u32::MAX, - entity, - }; - - let mut providers: APIProviders = world.remove_resource().unwrap(); - let mut ctx = self.load_script(script, &fd, &mut providers).unwrap(); - self.setup_script(&fd, &mut ctx, &mut providers)?; - let events = [event; 1]; - - self.handle_events(world, &events, once((fd, &mut ctx)), &mut providers); - - world.insert_resource(providers); - - Ok(()) - } - - /// Registers the script host with the given app, and attaches handlers to deal with spawning/removing scripts in the given System Set. - /// - /// Ideally place after any game logic which can spawn/remove/modify scripts to avoid frame lag. (typically `PostUpdate`) - fn register_with_app(app: &mut App, schedule: impl ScheduleLabel) { - #[derive(SystemSet, Hash, Debug, Eq, PartialEq, Clone, Copy)] - struct DummySet; - - Self::register_with_app_in_set(app, schedule, DummySet); - } - - /// Similar to `register_with_app` but allows you to specify a system set to add the handler to. - fn register_with_app_in_set(app: &mut App, schedule: impl ScheduleLabel, set: impl SystemSet); -} - -/// Implementors can modify a script context in order to enable -/// API access. ScriptHosts call `attach_api` when creating scripts -pub trait APIProvider: 'static + Send + Sync { - /// the type of script engine/context the API is attached to, this must be the same as the APITarget of the ScriptHost meant to receive it. - type APITarget: Send + Sync + 'static; - /// The type of script context the APIProvider works with, must be the same as the ScriptContext of the target ScriptHost. - type ScriptContext: Send + Sync + 'static; - /// The type of documentation fragment produced by the APIProvider, must be the same as the DocTarget of the target ScriptHost. - type DocTarget: DocFragment; - - /// provide the given script context with the API permamently. - /// Depending on the host, API's may be attached on a per-script basis - /// or on a per-engine basis. Rhai for example allows you to decouple the State of each script from the - /// engine. For one-time setup use `Self::setup_script` - fn attach_api(&mut self, api: &mut Self::APITarget) -> Result<(), ScriptError>; - - /// Hook executed every time a script is about to handle events, most notably used to "refresh" world pointers - fn setup_script_runtime( - &mut self, - _world_ptr: WorldPointer, - _script_data: &ScriptData, - _ctx: &mut Self::ScriptContext, - ) -> Result<(), ScriptError> { - Ok(()) - } - - /// Setup meant to be executed once for every single script. Use this if you need to consistently setup scripts. - /// For API's use `Self::attach_api` instead. - fn setup_script( - &mut self, - _script_data: &ScriptData, - _ctx: &mut Self::ScriptContext, - ) -> Result<(), ScriptError> { - Ok(()) - } - - /// Generate a piece of documentation to be merged with the other documentation fragments - /// provided by other API providers - fn get_doc_fragment(&self) -> Option { - None - } - - /// Some providers might provide additional types which need to be registered - /// with the reflection API to work. - fn register_with_app(&self, _app: &mut App) {} -} - -#[derive(Resource)] -/// Stores many API providers -pub struct APIProviders { - pub providers: Vec< - Box< - dyn APIProvider< - APITarget = T::APITarget, - DocTarget = T::DocTarget, - ScriptContext = T::ScriptContext, - >, - >, - >, -} - -impl Default for APIProviders { - fn default() -> Self { - Self { - providers: Default::default(), - } - } -} - -impl APIProviders { - pub fn attach_all(&mut self, ctx: &mut T::APITarget) -> Result<(), ScriptError> { - for p in self.providers.iter_mut() { - p.attach_api(ctx)?; - } - - Ok(()) - } - - pub fn setup_runtime_all( - &mut self, - world_ptr: WorldPointer, - script_data: &ScriptData, - ctx: &mut T::ScriptContext, - ) -> Result<(), ScriptError> { - for p in self.providers.iter_mut() { - p.setup_script_runtime(world_ptr.clone(), script_data, ctx)?; - } - - Ok(()) - } - - pub fn setup_all( - &mut self, - script_data: &ScriptData, - ctx: &mut T::ScriptContext, - ) -> Result<(), ScriptError> { - for p in self.providers.iter_mut() { - p.setup_script(script_data, ctx)?; - } - - Ok(()) - } - - pub fn gen_all(&self) -> Result<(), ScriptError> { - let mut d: Option = None; - for p in self.providers.iter() { - if let Some(f) = p.get_doc_fragment() { - if let Some(prev) = d { - d = Some(prev.merge(f)) - } else { - d = Some(f) - } - } - } - d.map(|d| d.gen_docs()).unwrap_or_else(|| Ok(())) - } -} - -/// A resource storing the script contexts for each script instance. -/// The reason we need this is to split the world borrow in our handle event systems, but this -/// has the added benefit that users don't see the contexts at all, and we can provide -/// generic handling for each new/removed script in one place. -/// -/// We keep this public for now since there is no API for communicating with scripts -/// outside of events. Later this might change. -#[derive(Resource)] -pub struct ScriptContexts { - /// holds script contexts for all scripts given their instance ids. - /// This also stores contexts which are not fully loaded hence the Option - pub context_entities: HashMap, String)>, -} - -impl Default for ScriptContexts { - fn default() -> Self { - Self { - context_entities: Default::default(), - } - } -} - -impl ScriptContexts { - pub fn script_owner(&self, script_id: u32) -> Option { - self.context_entities.get(&script_id).map(|(e, _c, _n)| *e) - } - - pub fn insert_context(&mut self, fd: ScriptData, ctx: Option) { - self.context_entities - .insert(fd.sid, (fd.entity, ctx, fd.name.to_owned())); - } - - pub fn remove_context(&mut self, script_id: u32) { - self.context_entities.remove(&script_id); - } - - pub fn has_context(&self, script_id: u32) -> bool { - self.context_entities - .get(&script_id) - .map_or(false, |(_, c, _)| c.is_some()) - } - - pub fn is_empty(&self) -> bool { - self.context_entities.is_empty() - } -} - -/// A struct defining an instance of a script asset. -/// Multiple instances of the same script can exist on the same entity -#[derive(Debug, Reflect)] -pub struct Script { - /// a strong handle to the script asset - handle: Handle, - - /// the name of the script, usually its file name + relative asset path - name: String, - - /// uniquely identifies the script instance (scripts which use the same asset don't necessarily have the same ID) - id: u32, -} - -static COUNTER: AtomicU32 = AtomicU32::new(0); - -impl Script { - /// creates a new script instance with the given name and asset handle - /// automatically gives this script instance a unique ID. - /// No two scripts instances ever share the same ID - pub fn new(name: String, handle: Handle) -> Self { - Self { - handle, - name, - id: COUNTER.fetch_add(1, Ordering::Relaxed), - } - } - - #[inline(always)] - /// returns the name of the script - pub fn name(&self) -> &str { - &self.name - } - - #[inline(always)] - /// returns the asset handle which this script is executing - pub fn handle(&self) -> &Handle { - &self.handle - } - - #[inline(always)] - /// returns the unique ID of this script instance - pub fn id(&self) -> u32 { - self.id - } - - /// reloads the script by deleting the old context and inserting a new one - /// if the script context never existed, it will after this call. - pub(crate) fn reload_script( - host: &mut H, - script: &Script, - script_assets: &Assets, - providers: &mut APIProviders, - contexts: &mut ScriptContexts, - event_writer: &mut EventWriter, - error_writer: &mut EventWriter, - ) { - debug!("reloading script {}", script.id); - - // retrieve owning entity - if let Some(entity) = contexts.script_owner(script.id()) { - // remove old context - contexts.remove_context(script.id()); - // insert new re-loaded context - Self::insert_new_script_context::( - host, - script, - entity, - script_assets, - providers, - contexts, - event_writer, - error_writer, - ); - } else { - // remove old context - contexts.remove_context(script.id()); - } - } - - /// checks if a script has loaded, and if so loads (`ScriptHost::load_script`), - /// sets up (`ScriptHost::setup_script`) and inserts its new context into the contexts resource - /// otherwise inserts None. Sends ScriptLoaded event if the script was loaded - pub(crate) fn insert_new_script_context( - host: &mut H, - new_script: &Script, - entity: Entity, - script_assets: &Assets, - providers: &mut APIProviders, - contexts: &mut ScriptContexts, - event_writer: &mut EventWriter, - error_writer: &mut EventWriter, - ) { - let fd = ScriptData { - sid: new_script.id(), - entity, - name: new_script.name(), - }; - - let script = match script_assets.get(&new_script.handle) { - Some(s) => s, - None => { - // not loaded yet - debug!("Inserted script which hasn't loaded yet {:?}", fd); - contexts.insert_context(fd, None); - return; - } - }; - debug!("Inserted script {:?}", fd); - - match host.load_script(script.bytes(), &fd, providers) { - Ok(mut ctx) => { - host.setup_script(&fd, &mut ctx, providers) - .expect("Failed to setup script"); - contexts.insert_context(fd, Some(ctx)); - event_writer.send(ScriptLoaded { - sid: new_script.id(), - }); - } - Err(e) => { - warn! {"Error in loading script {}:\n{}", &new_script.name,e} - // this script will now never execute, unless manually reloaded - // but contexts are left in a valid state - contexts.insert_context(fd, None); - error_writer.send(ScriptErrorEvent { error: e }); - } - } - } -} - -#[derive(Component, Debug, Reflect)] -#[reflect(Component, Default)] -/// The component storing many scripts. -/// Scripts receive information about the entity they are attached to -/// Scripts have unique identifiers and hence multiple copies of the same script -/// can be attached to the same entity -pub struct ScriptCollection { - pub scripts: Vec>, -} - -impl Default for ScriptCollection { - fn default() -> Self { - Self { - scripts: Default::default(), - } - } -} From 9022289b516ee0fb4ce148938a8758aa8c31ee87 Mon Sep 17 00:00:00 2001 From: makspll Date: Thu, 14 Nov 2024 17:30:31 +0000 Subject: [PATCH 12/22] make things clone --- crates/bevy_mod_scripting_core/src/asset.rs | 2 +- crates/bevy_mod_scripting_core/src/script.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_mod_scripting_core/src/asset.rs b/crates/bevy_mod_scripting_core/src/asset.rs index c61bb7c1bf..0833c413db 100644 --- a/crates/bevy_mod_scripting_core/src/asset.rs +++ b/crates/bevy_mod_scripting_core/src/asset.rs @@ -13,7 +13,7 @@ use bevy::{ use crate::{prelude::ScriptError, script::ScriptId}; /// Represents a script loaded into memory as an asset -#[derive(Asset, TypePath)] +#[derive(Asset, TypePath, Clone)] pub struct ScriptAsset { pub content: Box<[u8]>, /// The virtual filesystem path of the asset, used to map to the script Id for asset backed scripts diff --git a/crates/bevy_mod_scripting_core/src/script.rs b/crates/bevy_mod_scripting_core/src/script.rs index 4d39427b29..9817eb8bd1 100644 --- a/crates/bevy_mod_scripting_core/src/script.rs +++ b/crates/bevy_mod_scripting_core/src/script.rs @@ -8,7 +8,7 @@ use crate::{asset::ScriptAsset, context::ContextId}; pub type ScriptId = Cow<'static, str>; -#[derive(bevy::ecs::component::Component, Reflect)] +#[derive(bevy::ecs::component::Component, Reflect, Clone)] pub struct ScriptComponent(pub Vec); impl Deref for ScriptComponent { From 691b02b67bbbe9c47d81232b058f903b3b7d9cd0 Mon Sep 17 00:00:00 2001 From: makspll Date: Thu, 14 Nov 2024 22:12:11 +0000 Subject: [PATCH 13/22] Fix some tests --- .../src/bindings/query.rs | 9 ++- .../src/bindings/reference.rs | 27 ++++++++- .../src/bindings/world.rs | 47 +++++++-------- .../bevy_mod_scripting_lua/Cargo.toml | 1 + .../src/bindings/reference.rs | 16 ++--- .../src/bindings/world.rs | 23 ++++++-- ...t_no_default_or_from_world_data_errors.lua | 12 ++-- ..._with_default_no_component_data_errors.lua | 12 ++-- ...th_from_world_no_component_data_errors.lua | 12 ++-- ...y_entity_component_with_component_data.lua | 5 ++ .../missing_resource_returns_nil.lua | 2 + .../no_resource_data_returns_resource.lua | 5 ++ .../with_resource_data_returns_resource.lua | 5 ++ ...g.lua => missing_type_returns_nothing.lua} | 0 ...ty_entity_with_component_data_is_false.lua | 4 ++ .../data/has_component/no_component_data.lua | 3 + .../has_component/with_component_data.lua | 3 + .../empty_entity_does_nothing.lua | 5 ++ .../no_component_data_errors.lua | 7 +++ .../with_component_data_removes_component.lua | 5 ++ ...source_with_resource_data_does_nothing.lua | 4 ++ .../no_resource_data_errors.lua | 6 ++ .../with_resource_data_removes_resource.lua | 4 ++ .../bevy_mod_scripting_lua/tests/lua_tests.rs | 58 +++++++++++++++++-- crates/test_utils/src/asserts.rs | 1 - crates/test_utils/src/lib.rs | 1 - crates/test_utils/src/test_data.rs | 22 ++++++- 27 files changed, 226 insertions(+), 73 deletions(-) create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/get_component/empty_entity_component_with_component_data.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/get_resource/missing_resource_returns_nil.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/get_resource/no_resource_data_returns_resource.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/get_resource/with_resource_data_returns_resource.lua rename crates/languages/bevy_mod_scripting_lua/tests/data/get_type_by_name/{unregistered_type_returns_nothing.lua => missing_type_returns_nothing.lua} (100%) create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/has_component/empty_entity_with_component_data_is_false.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/has_component/no_component_data.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/has_component/with_component_data.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/remove_component/empty_entity_does_nothing.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/remove_component/no_component_data_errors.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/remove_component/with_component_data_removes_component.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/remove_resource/missing_resource_with_resource_data_does_nothing.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/remove_resource/no_resource_data_errors.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/remove_resource/with_resource_data_removes_resource.lua delete mode 100644 crates/test_utils/src/asserts.rs diff --git a/crates/bevy_mod_scripting_core/src/bindings/query.rs b/crates/bevy_mod_scripting_core/src/bindings/query.rs index 05f728a300..95421292ed 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/query.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/query.rs @@ -13,13 +13,19 @@ use std::{any::TypeId, ops::Deref, sync::Arc}; pub struct ScriptTypeRegistration { pub(crate) registration: Arc, pub component_id: Option, + pub resource_id: Option, } impl ScriptTypeRegistration { - pub fn new(registration: Arc, component_id: Option) -> Self { + pub fn new( + registration: Arc, + component_id: Option, + resource_id: Option, + ) -> Self { Self { registration, component_id, + resource_id, } } @@ -38,6 +44,7 @@ impl ScriptTypeRegistration { self.registration.type_info().type_id() } + /// Returns the [`ComponentId`] for this type, if it is a component or a resource. #[inline(always)] pub fn component_id(&self) -> Option { self.component_id diff --git a/crates/bevy_mod_scripting_core/src/bindings/reference.rs b/crates/bevy_mod_scripting_core/src/bindings/reference.rs index df7356e356..eaaf44e7ec 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/reference.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/reference.rs @@ -56,10 +56,33 @@ pub struct ReflectReference { pub reflect_path: Vec, } -// just a dummy standin for unregistered types -struct UnregisteredType; + impl ReflectReference { + + /// If this is a reference to something with a length accessible via reflection, returns that length. + pub fn len(&self, world: &WorldAccessGuard) -> Option { + world.with_resource(|world, type_registry: Mut| { + world.with_resource(|world, allocator: Mut| { + let type_registry = type_registry.read(); + self + .with_reflect(world, &type_registry, Some(&allocator), |r| { + match r.reflect_ref() { + bevy::reflect::ReflectRef::Struct(s) => Some(s.field_len()), + bevy::reflect::ReflectRef::TupleStruct(ts) => Some(ts.field_len()), + bevy::reflect::ReflectRef::Tuple(t) => Some(t.field_len()), + bevy::reflect::ReflectRef::List(l) => Some(l.len()), + bevy::reflect::ReflectRef::Array(a) => Some(a.len()), + bevy::reflect::ReflectRef::Map(m) => Some(m.len( )), + bevy::reflect::ReflectRef::Set(s) => Some(s.len()), + bevy::reflect::ReflectRef::Enum(e) => Some(e.field_len()), + bevy::reflect::ReflectRef::Opaque(_) => None, + } + }) + }) + }) + } + pub fn new_allocated( value: T, allocator: &mut ReflectAllocator, diff --git a/crates/bevy_mod_scripting_core/src/bindings/world.rs b/crates/bevy_mod_scripting_core/src/bindings/world.rs index 773619b9a7..7dc44dc92c 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/world.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/world.rs @@ -170,7 +170,7 @@ impl WorldCallbackAccess { world.remove_component(entity, registration) } - pub fn get_resource(&self, resource_id: ComponentId) -> ScriptResult { + pub fn get_resource(&self, resource_id: ComponentId) -> ScriptResult> { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); world.get_resource(resource_id) } @@ -290,10 +290,11 @@ impl<'w> WorldAccessGuard<'w> { /// Gets the component id of the given component or resource pub fn get_component_id(&self, id: TypeId) -> Option { - let components = self.cell.components(); - components - .get_id(id) - .or_else(|| components.get_resource_id(id)) + self.cell.components().get_id(id) + } + + pub fn get_resource_id(&self, id: TypeId) -> Option { + self.cell.components().get_resource_id(id) } /// Checks nobody else is currently accessing the world, and if so locks access to it until @@ -609,6 +610,7 @@ impl<'w> WorldAccessGuard<'w> { ScriptTypeRegistration::new( Arc::new(registration.clone()), world.get_component_id(registration.type_id()), + world.get_resource_id(registration.type_id()), ) }) }) @@ -733,19 +735,13 @@ impl<'w> WorldAccessGuard<'w> { Ok(()) } - pub fn get_resource(&self, resource_id: ComponentId) -> ScriptResult { - let component_info = self - .cell - .components() - .get_info(resource_id) - .ok_or_else(|| { - ScriptError::new_runtime_error(format!( - "Resource does not exist: {:?}", - resource_id - )) - })?; + pub fn get_resource(&self, resource_id: ComponentId) -> ScriptResult> { + let component_info = match self.cell.components().get_info(resource_id) { + Some(info) => info, + None => return Ok(None), + }; - Ok(ReflectReference { + Ok(Some(ReflectReference { base: ReflectBaseType { type_id: component_info .type_id() @@ -753,7 +749,7 @@ impl<'w> WorldAccessGuard<'w> { base_id: ReflectBase::Resource(resource_id), }, reflect_path: Default::default(), - }) + })) } pub fn remove_resource(&self, registration: ScriptTypeRegistration) -> ScriptResult<()> { @@ -772,7 +768,9 @@ impl<'w> WorldAccessGuard<'w> { } pub fn has_resource(&self, resource_id: ComponentId) -> bool { - self.cell.components().get_info(resource_id).is_some() + // Safety: we are not reading the value at all + let res_ptr = unsafe { self.cell.get_resource_by_id(resource_id) }; + res_ptr.is_some() } pub fn get_children(&self, entity: Entity) -> ScriptResult> { @@ -1520,6 +1518,7 @@ mod test { WorldCallbackAccess::with_callback_access(&mut world, |world| { let comp_ref = world .get_resource(TestResource::test_component_id()) + .unwrap() .unwrap(); assert_eq!( comp_ref, @@ -1542,13 +1541,9 @@ mod test { WorldCallbackAccess::with_callback_access(&mut world, |world| { let comp_ref = world.get_resource(fake_comp); match comp_ref { - Ok(_) => panic!("Expected error"), - Err(e) => { - assert_eq!(e.kind, ScriptErrorKind::RuntimeError); - assert_eq!( - e.reason.to_string(), - format!("Resource does not exist: {fake_comp:?}") - ) + Ok(None) => {} + e => { + panic!("Expected ok with none, got: {:?}", e); } } }); diff --git a/crates/languages/bevy_mod_scripting_lua/Cargo.toml b/crates/languages/bevy_mod_scripting_lua/Cargo.toml index 5c7bfa10a7..be2b581d5e 100644 --- a/crates/languages/bevy_mod_scripting_lua/Cargo.toml +++ b/crates/languages/bevy_mod_scripting_lua/Cargo.toml @@ -57,6 +57,7 @@ smallvec = "1.13" [dev-dependencies] test_utils = { workspace = true } libtest-mimic = "0.8" +regex = "1.11" [[test]] name = "lua_tests" diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs index 79903d04d2..7a7386b3c0 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs @@ -29,6 +29,11 @@ use super::{ pub struct LuaReflectReference(pub ReflectReference); impl LuaReflectReference { + pub fn len(&self, lua: &Lua) -> Result, mlua::Error> { + let world = lua.get_world()?; + Ok(self.0.len(&world)) + } + /// Queries the reflection system for a proxy registration for the underlying type. /// If found will convert to lua using this proxy /// If not found will use ::into_lua to convert to lua @@ -117,13 +122,6 @@ impl LuaReflectReference { e, )) }) - // r.set(other).map_err(|e| { - // ScriptError::new_runtime_error(format!( - // "Invalid assignment `{:?}` = `{:?}`. Wrong type.", - // self.0.clone(), - // e, - // )) - // }) })?; Ok(()) } else { @@ -223,6 +221,10 @@ impl TealData for LuaReflectReference { self_.set_with_lua_proxy(l, value) }, ); + + m.add_meta_function(MetaMethod::Len, |l, self_: LuaReflectReference| { + self_.len(l) + }) } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs index 9e5a0ccb6b..93bcc364c6 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs @@ -183,13 +183,19 @@ impl TealData for LuaWorld { methods.add_method( "get_resource", - |_, this, resource_id: LuaReflectValProxy| { + |_, this, registration: LuaValProxy| { let world = this.0.read().ok_or_else(|| { mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) })?; - let out: Result, ErrorProxy> = world - .proxy_call(resource_id, |resource_id| world.get_resource(resource_id)) - .map_err(mlua::Error::external)?; + let out: Result>, ErrorProxy> = + world + .proxy_call(registration, |registration| { + match registration.resource_id { + Some(resource_id) => world.get_resource(resource_id), + None => Ok(None), + } + }) + .map_err(mlua::Error::external)?; Ok(TypenameProxy::<_, LuaReflectRefProxy>::new(out)) }, @@ -213,12 +219,17 @@ impl TealData for LuaWorld { methods.add_method( "has_resource", - |_, this, resource_id: LuaReflectValProxy| { + |_, this, registration: LuaValProxy| { let world = this.0.read().ok_or_else(|| { mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) })?; let out: bool = world - .proxy_call(resource_id, |resource_id| world.has_resource(resource_id)) + .proxy_call(registration, |registration| { + match registration.resource_id { + Some(resource_id) => world.has_resource(resource_id), + None => false, + } + }) .map_err(mlua::Error::external)?; Ok(out) diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_no_default_or_from_world_data_errors.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_no_default_or_from_world_data_errors.lua index aa185b18f4..aa31351705 100644 --- a/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_no_default_or_from_world_data_errors.lua +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_no_default_or_from_world_data_errors.lua @@ -1,9 +1,7 @@ -function Test() - local entity = world:spawn() - local type = world:get_type_by_name('TestComponent') +local entity = world:spawn() +local type = world:get_type_by_name('TestComponent') + +assert_throws(function() world:add_default_component(entity, type) -end -local success,err = pcall(Test) -assert(not success, 'No error thrown') -assert(string.find(tostring(err), 'Does not have ReflectDefault or ReflectFromWorld'), 'Error contains wrong message: ' .. tostring(err)) \ No newline at end of file +end, "Does not have ReflectDefault or ReflectFromWorld data registered") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_default_no_component_data_errors.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_default_no_component_data_errors.lua index 709b6fe706..bf4ba3d294 100644 --- a/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_default_no_component_data_errors.lua +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_default_no_component_data_errors.lua @@ -1,10 +1,6 @@ -function Test() - local entity = world:spawn() - local _type = world:get_type_by_name('CompWithDefault') +local entity = world:spawn() +local _type = world:get_type_by_name('CompWithDefault') +assert_throws(function() world:add_default_component(entity, _type) -end - -local success,err = pcall(Test) -assert(not success, 'No error thrown') -assert(string.find(tostring(err), 'Does not have ReflectComponent'), 'Error contains wrong message: ' .. tostring(err)) \ No newline at end of file +end, "Does not have ReflectComponent") diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_from_world_no_component_data_errors.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_from_world_no_component_data_errors.lua index 777651855a..6f4f467703 100644 --- a/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_from_world_no_component_data_errors.lua +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/add_default_component/component_with_from_world_no_component_data_errors.lua @@ -1,10 +1,6 @@ -function Test() - local entity = world:spawn() - local _type = world:get_type_by_name('CompWithFromWorld') +local entity = world:spawn() +local _type = world:get_type_by_name('CompWithFromWorld') +assert_throws(function() world:add_default_component(entity, _type) -end - -local success,err = pcall(Test) -assert(not success, 'No error thrown') -assert(string.find(tostring(err), 'Does not have ReflectComponent'), 'Error contains wrong message: ' .. tostring(err)) \ No newline at end of file +end, 'Does not have ReflectComponent data registered') \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_component/empty_entity_component_with_component_data.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_component/empty_entity_component_with_component_data.lua new file mode 100644 index 0000000000..79d541883b --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/get_component/empty_entity_component_with_component_data.lua @@ -0,0 +1,5 @@ +local component = world:get_type_by_name("TestComponent") +local entity = world:spawn() +local retrieved = world:get_component(entity, component) + +assert(retrieved == nil, "Component found") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_resource/missing_resource_returns_nil.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_resource/missing_resource_returns_nil.lua new file mode 100644 index 0000000000..a2fd345a6f --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/get_resource/missing_resource_returns_nil.lua @@ -0,0 +1,2 @@ +local type = _get_mock_type() +assert(world:get_resource(type) == nil, "Resource should not exist") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_resource/no_resource_data_returns_resource.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_resource/no_resource_data_returns_resource.lua new file mode 100644 index 0000000000..8bd6133492 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/get_resource/no_resource_data_returns_resource.lua @@ -0,0 +1,5 @@ +local resource = world:get_type_by_name("ResourceWithDefault") + +local retrieved = world:get_resource(resource) +assert(retrieved ~= nil, "Resource should exist") +assert(retrieved._1 == "Initial Value", "Resource should have default value but got: " .. retrieved._1) diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_resource/with_resource_data_returns_resource.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_resource/with_resource_data_returns_resource.lua new file mode 100644 index 0000000000..2d21bf08a6 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/get_resource/with_resource_data_returns_resource.lua @@ -0,0 +1,5 @@ +local resource = world:get_type_by_name("TestResource") + +local retrieved = world:get_resource(resource) +assert(retrieved ~= nil, "Resource should exist") +assert(retrieved.bytes[2] == 1, "Resource should have default value but got resource with #retrieved.bytes[1]: " .. tostring(retrieved.bytes[2])) diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_type_by_name/unregistered_type_returns_nothing.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_type_by_name/missing_type_returns_nothing.lua similarity index 100% rename from crates/languages/bevy_mod_scripting_lua/tests/data/get_type_by_name/unregistered_type_returns_nothing.lua rename to crates/languages/bevy_mod_scripting_lua/tests/data/get_type_by_name/missing_type_returns_nothing.lua diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/has_component/empty_entity_with_component_data_is_false.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/has_component/empty_entity_with_component_data_is_false.lua new file mode 100644 index 0000000000..9f9fdff094 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/has_component/empty_entity_with_component_data_is_false.lua @@ -0,0 +1,4 @@ +local entity = world:spawn() +local type = world:get_type_by_name('TestComponent') + +assert(world:has_component(entity, type) == false, "Entity should not have component") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/has_component/no_component_data.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/has_component/no_component_data.lua new file mode 100644 index 0000000000..fc1129e5cc --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/has_component/no_component_data.lua @@ -0,0 +1,3 @@ +local entity = _get_entity_with_test_component("CompWithDefault") +local component = world:get_type_by_name("CompWithDefault") +assert(world:has_component(entity, component) == true, "Component was not found") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/has_component/with_component_data.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/has_component/with_component_data.lua new file mode 100644 index 0000000000..a15920ea94 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/has_component/with_component_data.lua @@ -0,0 +1,3 @@ +local entity = _get_entity_with_test_component("TestComponent") +local component = world:get_type_by_name("TestComponent") +assert(world:has_component(entity, component) == true, "Component was not found") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/remove_component/empty_entity_does_nothing.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/remove_component/empty_entity_does_nothing.lua new file mode 100644 index 0000000000..fd535a7f46 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/remove_component/empty_entity_does_nothing.lua @@ -0,0 +1,5 @@ +local entity = world:spawn() +local type = world:get_type_by_name('TestComponent') + +world:remove_component(entity, type) +world:remove_component(entity, type) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/remove_component/no_component_data_errors.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/remove_component/no_component_data_errors.lua new file mode 100644 index 0000000000..572cddd599 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/remove_component/no_component_data_errors.lua @@ -0,0 +1,7 @@ + +local entity = _get_entity_with_test_component("CompWithDefault") +local component = world:get_type_by_name("CompWithDefault") + +assert_throws(function () + world:remove_component(entity, component) +end, "Does not have ReflectComponent data registered") diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/remove_component/with_component_data_removes_component.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/remove_component/with_component_data_removes_component.lua new file mode 100644 index 0000000000..294430d420 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/remove_component/with_component_data_removes_component.lua @@ -0,0 +1,5 @@ + +local entity = _get_entity_with_test_component("TestComponent") +local component = world:get_type_by_name("TestComponent") +world:remove_component(entity, component) +assert(world:has_component(entity, component) == false, "Component was not removed") diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/remove_resource/missing_resource_with_resource_data_does_nothing.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/remove_resource/missing_resource_with_resource_data_does_nothing.lua new file mode 100644 index 0000000000..ae802adacb --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/remove_resource/missing_resource_with_resource_data_does_nothing.lua @@ -0,0 +1,4 @@ +local type = world:get_type_by_name("TestResource") + +world:remove_resource(type) +world:remove_resource(type) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/remove_resource/no_resource_data_errors.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/remove_resource/no_resource_data_errors.lua new file mode 100644 index 0000000000..03f456e7ff --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/remove_resource/no_resource_data_errors.lua @@ -0,0 +1,6 @@ + +local type = _get_mock_type() + +assert_throws(function () + world:remove_resource(type) +end, "Does not have ReflectResource data registered") diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/remove_resource/with_resource_data_removes_resource.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/remove_resource/with_resource_data_removes_resource.lua new file mode 100644 index 0000000000..86a21cb4ce --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/remove_resource/with_resource_data_removes_resource.lua @@ -0,0 +1,4 @@ + +local type = world:get_type_by_name("TestResource") +world:remove_resource(type) +assert(world:has_resource(type) == false, "Resource was not removed") diff --git a/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs b/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs index f0364e7fa3..189a2269df 100644 --- a/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs +++ b/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs @@ -2,10 +2,14 @@ use bevy::{ app::App, asset::{AssetPlugin, AssetServer}, prelude::{AppTypeRegistry, Entity, World}, + reflect::{Reflect, TypeRegistration}, MinimalPlugins, }; use bevy_mod_scripting_core::{ - bindings::{Proxy, ReflectAllocator, ReflectReference, ReflectValProxy, WorldCallbackAccess}, + bindings::{ + Proxy, ReflectAllocator, ReflectReference, ReflectValProxy, ScriptTypeRegistration, + WorldCallbackAccess, + }, context::ContextLoadingSettings, error::ScriptError, event::CallbackLabel, @@ -18,7 +22,7 @@ use bevy_mod_scripting_lua::{ world::{GetWorld, LuaWorld}, }, lua_context_load, lua_handler, - prelude::{Lua, LuaHookTriggers}, + prelude::{Lua, LuaFunction, LuaHookTriggers}, register_lua_values, LuaScriptingPlugin, ReflectLuaValue, }; use libtest_mimic::{Arguments, Failed, Trial}; @@ -28,6 +32,7 @@ use std::{ fs::{self, DirEntry}, io, path::{Path, PathBuf}, + sync::Arc, }; use test_utils::test_data::{setup_world, EnumerateTestComponents}; @@ -48,6 +53,16 @@ fn init_app() -> App { } fn init_lua_test_utils(_script_name: &Cow<'static, str>, lua: &mut Lua) -> Result<(), ScriptError> { + let _get_mock_type = lua + .create_function(|_, ()| { + #[derive(Reflect)] + struct Dummy; + let reg = + ScriptTypeRegistration::new(Arc::new(TypeRegistration::of::()), None, None); + Ok(::Proxy::from(reg)) + }) + .unwrap(); + let _get_entity_with_test_component = lua .create_function(|l, s: String| { let world = l.get_world().unwrap(); @@ -70,13 +85,41 @@ fn init_lua_test_utils(_script_name: &Cow<'static, str>, lua: &mut Lua) -> Resul }) .unwrap(); - lua.globals() + let assert_throws = lua + .create_function(|_, (f, regex): (LuaFunction, String)| { + let result = f.call::<(), ()>(()); + match result { + Ok(_) => Err(tealr::mlu::mlua::Error::RuntimeError( + "Expected function to throw error, but it did not.".into(), + )), + Err(e) => { + let error_message = e.to_string(); + let regex = regex::Regex::new(®ex).unwrap(); + if regex.is_match(&error_message) { + Ok(()) + } else { + Err(tealr::mlu::mlua::Error::RuntimeError(format!( + "Expected error message to match the regex: \n{}\n\nBut got:\n{}", + regex.as_str(), + error_message + ))) + } + } + } + }) + .unwrap(); + + let globals = lua.globals(); + globals .set( "_get_entity_with_test_component", _get_entity_with_test_component, ) .unwrap(); + globals.set("assert_throws", assert_throws).unwrap(); + + globals.set("_get_mock_type", _get_mock_type).unwrap(); Ok(()) } @@ -128,7 +171,14 @@ impl Test { } fn name(&self) -> String { - format!("lua_test - {}", self.path.to_string_lossy()) + format!( + "lua_test - {}", + self.path + .to_string_lossy() + .split(&format!("tests{}data", std::path::MAIN_SEPARATOR)) + .last() + .unwrap() + ) } } diff --git a/crates/test_utils/src/asserts.rs b/crates/test_utils/src/asserts.rs deleted file mode 100644 index 8b13789179..0000000000 --- a/crates/test_utils/src/asserts.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 7a05954925..363a59ff80 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs @@ -1,2 +1 @@ -pub mod asserts; pub mod test_data; diff --git a/crates/test_utils/src/test_data.rs b/crates/test_utils/src/test_data.rs index 04400ad3e8..cf5fc1cc23 100644 --- a/crates/test_utils/src/test_data.rs +++ b/crates/test_utils/src/test_data.rs @@ -35,6 +35,23 @@ impl TestResource { } } +/// Resource with Reflect and ReflectDefault registered but no ReflectResource +#[derive(Resource, Reflect, PartialEq, Eq, Debug)] +#[reflect(Default)] +pub struct ResourceWithDefault(pub String); + +impl Default for ResourceWithDefault { + fn default() -> Self { + Self(String::from("Default")) + } +} + +impl ResourceWithDefault { + pub fn init() -> Self { + Self(String::from("Initial Value")) + } +} + /// Component with Reflect and ReflectFromWorld registered but no ReflectComponent #[derive(Reflect, Component, PartialEq, Debug)] #[reflect(FromWorld)] @@ -148,7 +165,7 @@ macro_rules! impl_test_component_ids { assert_eq!(entity.generation(), 1, "Test setup failed. Did you spawn entities before running setup_world?"); )* $( - world.init_resource::<$res_type>(); + world.insert_resource::<$res_type>(<$res_type>::init()); registry.register::<$res_type>(); let registered_id = world.resource_id::<$res_type>().unwrap().index(); assert_eq!(registered_id, TEST_COMPONENT_ID_START + $res_id, "Test setup failed. Did you register components before running setup_world?"); @@ -179,7 +196,8 @@ impl_test_component_ids!( CompWithFromWorldAndComponentData => 4 ], [ - TestResource => 5 + TestResource => 5, + ResourceWithDefault => 6 ] ); From b9ca2b0aba0f201a849d34af86af5571159f7451 Mon Sep 17 00:00:00 2001 From: makspll Date: Thu, 14 Nov 2024 22:21:35 +0000 Subject: [PATCH 14/22] more tests --- ...ta_is_false.lua => empty_entity_mock_component_is_false.lua} | 2 +- .../tests/data/has_resource/existing_no_resource_data.lua | 2 ++ .../tests/data/has_resource/existing_with_resource_data.lua | 2 ++ .../has_resource/missing_resource_mock_resource_is_false.lua | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) rename crates/languages/bevy_mod_scripting_lua/tests/data/has_component/{empty_entity_with_component_data_is_false.lua => empty_entity_mock_component_is_false.lua} (68%) create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/has_resource/existing_no_resource_data.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/has_resource/existing_with_resource_data.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/has_resource/missing_resource_mock_resource_is_false.lua diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/has_component/empty_entity_with_component_data_is_false.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/has_component/empty_entity_mock_component_is_false.lua similarity index 68% rename from crates/languages/bevy_mod_scripting_lua/tests/data/has_component/empty_entity_with_component_data_is_false.lua rename to crates/languages/bevy_mod_scripting_lua/tests/data/has_component/empty_entity_mock_component_is_false.lua index 9f9fdff094..7c86b381a6 100644 --- a/crates/languages/bevy_mod_scripting_lua/tests/data/has_component/empty_entity_with_component_data_is_false.lua +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/has_component/empty_entity_mock_component_is_false.lua @@ -1,4 +1,4 @@ local entity = world:spawn() -local type = world:get_type_by_name('TestComponent') +local type = _get_mock_type() assert(world:has_component(entity, type) == false, "Entity should not have component") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/has_resource/existing_no_resource_data.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/has_resource/existing_no_resource_data.lua new file mode 100644 index 0000000000..f0d5e1fbf2 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/has_resource/existing_no_resource_data.lua @@ -0,0 +1,2 @@ +local component = world:get_type_by_name("ResourceWithDefault") +assert(world:has_resource(component) == true, "Resource was not found") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/has_resource/existing_with_resource_data.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/has_resource/existing_with_resource_data.lua new file mode 100644 index 0000000000..6976b8d800 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/has_resource/existing_with_resource_data.lua @@ -0,0 +1,2 @@ +local component = world:get_type_by_name("TestResource") +assert(world:has_resource(component) == true, "Resource was not found") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/has_resource/missing_resource_mock_resource_is_false.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/has_resource/missing_resource_mock_resource_is_false.lua new file mode 100644 index 0000000000..7f720c2f05 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/has_resource/missing_resource_mock_resource_is_false.lua @@ -0,0 +1,2 @@ +local type = _get_mock_type() +assert(world:has_resource(type) == false, "Resource should not exist") \ No newline at end of file From 21e33336ec42fc692411c39593f444cfc2a7f346 Mon Sep 17 00:00:00 2001 From: makspll Date: Fri, 15 Nov 2024 12:23:35 +0000 Subject: [PATCH 15/22] Complete test suite for world methods --- .../src/bindings/world.rs | 105 +++++++++++++++++- .../src/bindings/world.rs | 16 ++- .../tests/data/despawn/despawns_only_root.lua | 7 ++ .../data/despawn/invalid_entity_errors.lua | 3 + .../despawns_only_child.lua | 7 ++ .../invalid_entity_errors.lua | 3 + .../despawns_recursively.lua | 7 ++ .../invalid_entity_errors.lua | 3 + .../has_children_returns_them.lua | 9 ++ .../get_children/invalid_entity_errors.lua | 4 + .../no_children_returns_empty_table.lua | 4 + .../data/get_parent/has_parent_returns_it.lua | 9 ++ .../data/get_parent/invalid_entity_errors.lua | 4 + .../data/get_parent/no_parent_returns_nil.lua | 4 + .../adding_empty_list_does_nothing.lua | 5 + .../adds_children_at_correct_index.lua | 8 ++ .../adds_children_to_existing_enttity.lua | 7 ++ .../insert_children/invalid_entity_errors.lua | 10 ++ .../adding_empty_list_does_nothing.lua | 5 + .../adds_children_to_existing_enttity.lua | 7 ++ .../push_children/invalid_entity_errors.lua | 10 ++ .../bevy_mod_scripting_lua/tests/lua_tests.rs | 44 +++++--- 22 files changed, 258 insertions(+), 23 deletions(-) create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/despawn/despawns_only_root.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/despawn/invalid_entity_errors.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/despawn_descendants/despawns_only_child.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/despawn_descendants/invalid_entity_errors.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/despawn_recursive/despawns_recursively.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/despawn_recursive/invalid_entity_errors.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/get_children/has_children_returns_them.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/get_children/invalid_entity_errors.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/get_children/no_children_returns_empty_table.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/get_parent/has_parent_returns_it.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/get_parent/invalid_entity_errors.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/get_parent/no_parent_returns_nil.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/adding_empty_list_does_nothing.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/adds_children_at_correct_index.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/adds_children_to_existing_enttity.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/invalid_entity_errors.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/push_children/adding_empty_list_does_nothing.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/push_children/adds_children_to_existing_enttity.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/push_children/invalid_entity_errors.lua diff --git a/crates/bevy_mod_scripting_core/src/bindings/world.rs b/crates/bevy_mod_scripting_core/src/bindings/world.rs index 7dc44dc92c..e63f51399b 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/world.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/world.rs @@ -185,6 +185,11 @@ impl WorldCallbackAccess { world.has_resource(resource_id) } + pub fn has_entity(&self, entity: Entity) -> bool { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + world.has_entity(entity) + } + pub fn get_children(&self, entity: Entity) -> ScriptResult> { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); world.get_children(entity) @@ -588,6 +593,11 @@ impl<'w> WorldAccessGuard<'w> { )) } } + + /// checks if a given entity exists and is valid + pub fn is_valid_entity(&self, entity: Entity) -> bool { + self.cell.get_entity(entity).is_some() + } } /// Impl block for higher level world methods @@ -773,7 +783,18 @@ impl<'w> WorldAccessGuard<'w> { res_ptr.is_some() } + pub fn has_entity(&self, entity: Entity) -> bool { + self.is_valid_entity(entity) + } + pub fn get_children(&self, entity: Entity) -> ScriptResult> { + if !self.is_valid_entity(entity) { + return Err(ScriptError::new_runtime_error(format!( + "Entity does not exist or is not valid: {:?}", + entity + ))); + } + let access = self .get_component_access_typed::() .unwrap_or_else(|| panic!("{CONCURRENT_ACCESS_MSG}")); @@ -785,6 +806,13 @@ impl<'w> WorldAccessGuard<'w> { } pub fn get_parent(&self, entity: Entity) -> ScriptResult> { + if !self.is_valid_entity(entity) { + return Err(ScriptError::new_runtime_error(format!( + "Entity does not exist or is not valid: {:?}", + entity + ))); + } + let access = self .get_component_access_typed::() .unwrap_or_else(|| panic!("{CONCURRENT_ACCESS_MSG}")); @@ -795,6 +823,22 @@ impl<'w> WorldAccessGuard<'w> { } pub fn push_children(&self, parent: Entity, children: &[Entity]) -> ScriptResult<()> { + // verify entities exist + if !self.is_valid_entity(parent) { + return Err(ScriptError::new_runtime_error(format!( + "The parent Entity does not exist or is not valid: {:?}", + parent + ))); + } + for c in children { + if !self.is_valid_entity(*c) { + return Err(ScriptError::new_runtime_error(format!( + "the Entity does not exist or is not valid: {:?}", + c + ))); + } + } + if let Some(world) = self.get_whole_world_access() { let mut queue = CommandQueue::default(); let mut commands = Commands::new(&mut queue, world); @@ -808,6 +852,22 @@ impl<'w> WorldAccessGuard<'w> { } pub fn remove_children(&self, parent: Entity, children: &[Entity]) -> ScriptResult<()> { + if !self.is_valid_entity(parent) { + return Err(ScriptError::new_runtime_error(format!( + "The parent Entity does not exist or is not valid: {:?}", + parent + ))); + } + + for c in children { + if !self.is_valid_entity(*c) { + return Err(ScriptError::new_runtime_error(format!( + "the Entity does not exist or is not valid: {:?}", + c + ))); + } + } + if let Some(world) = self.get_whole_world_access() { let mut queue = CommandQueue::default(); let mut commands = Commands::new(&mut queue, world); @@ -826,6 +886,22 @@ impl<'w> WorldAccessGuard<'w> { index: usize, children: &[Entity], ) -> ScriptResult<()> { + if !self.is_valid_entity(parent) { + return Err(ScriptError::new_runtime_error(format!( + "parent Entity does not exist or is not valid: {:?}", + parent + ))); + } + + for c in children { + if !self.is_valid_entity(*c) { + return Err(ScriptError::new_runtime_error(format!( + "the Entity does not exist or is not valid: {:?}", + c + ))); + } + } + if let Some(world) = self.get_whole_world_access() { let mut queue = CommandQueue::default(); let mut commands = Commands::new(&mut queue, world); @@ -838,11 +914,18 @@ impl<'w> WorldAccessGuard<'w> { Ok(()) } - pub fn despawn_recursive(&self, entity: Entity) -> ScriptResult<()> { + pub fn despawn_recursive(&self, parent: Entity) -> ScriptResult<()> { + if !self.is_valid_entity(parent) { + return Err(ScriptError::new_runtime_error(format!( + "parent Entity does not exist or is not valid: {:?}", + parent + ))); + } + if let Some(world) = self.get_whole_world_access() { let mut queue = CommandQueue::default(); let mut commands = Commands::new(&mut queue, world); - commands.entity(entity).despawn_recursive(); + commands.entity(parent).despawn_recursive(); queue.apply(world); } else { panic!("{CONCURRENT_WORLD_ACCESS_MSG}") @@ -852,6 +935,13 @@ impl<'w> WorldAccessGuard<'w> { } pub fn despawn(&self, entity: Entity) -> ScriptResult<()> { + if !self.is_valid_entity(entity) { + return Err(ScriptError::new_runtime_error(format!( + "Entity does not exist or is not valid: {:?}", + entity + ))); + } + if let Some(world) = self.get_whole_world_access() { let mut queue = CommandQueue::default(); let mut commands = Commands::new(&mut queue, world); @@ -864,11 +954,18 @@ impl<'w> WorldAccessGuard<'w> { Ok(()) } - pub fn despawn_descendants(&self, entity: Entity) -> ScriptResult<()> { + pub fn despawn_descendants(&self, parent: Entity) -> ScriptResult<()> { + if !self.is_valid_entity(parent) { + return Err(ScriptError::new_runtime_error(format!( + "parent Entity does not exist or is not valid: {:?}", + parent + ))); + } + if let Some(world) = self.get_whole_world_access() { let mut queue = CommandQueue::default(); let mut commands = Commands::new(&mut queue, world); - commands.entity(entity).despawn_descendants(); + commands.entity(parent).despawn_descendants(); queue.apply(world); } else { panic!("{CONCURRENT_WORLD_ACCESS_MSG}") diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs index 93bcc364c6..f7ddbf5ed3 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs @@ -236,6 +236,20 @@ impl TealData for LuaWorld { }, ); + methods.add_method( + "has_entity", + |_, this, entity: LuaReflectValProxy| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let out: bool = world + .proxy_call(entity, |entity| world.has_entity(entity)) + .map_err(mlua::Error::external)?; + + Ok(out) + }, + ); + methods.add_method( "get_children", |_, this, entity: LuaReflectValProxy| { @@ -315,7 +329,7 @@ impl TealData for LuaWorld { })?; let out: Result<(), ErrorProxy> = world .proxy_call(args, |(parent, index, children)| { - world.insert_children(parent, index, &children) + world.insert_children(parent, index - 1, &children) }) .map_err(mlua::Error::external)?; diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/despawn/despawns_only_root.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/despawn/despawns_only_root.lua new file mode 100644 index 0000000000..2cc5a6f0b7 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/despawn/despawns_only_root.lua @@ -0,0 +1,7 @@ +local entity = world:spawn() +local child = world:spawn() +world:push_children(entity, {child}) +world:despawn(entity) + +assert(world:has_entity(entity) == false, "Parent should be despawned") +assert(world:has_entity(child) == true, "Child should not be despawned") diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/despawn/invalid_entity_errors.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/despawn/invalid_entity_errors.lua new file mode 100644 index 0000000000..de6961bebb --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/despawn/invalid_entity_errors.lua @@ -0,0 +1,3 @@ +assert_throws(function() + world:despawn_recursive(Entity.from_raw(9999)) +end, "parent Entity does not exist") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/despawn_descendants/despawns_only_child.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/despawn_descendants/despawns_only_child.lua new file mode 100644 index 0000000000..1b0f617540 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/despawn_descendants/despawns_only_child.lua @@ -0,0 +1,7 @@ +local entity = world:spawn() +local child = world:spawn() +world:push_children(entity, {child}) +world:despawn_descendants(entity) + +assert(world:has_entity(entity) == true, "Parent should not be despawned") +assert(world:has_entity(child) == false, "Child should be despawned") diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/despawn_descendants/invalid_entity_errors.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/despawn_descendants/invalid_entity_errors.lua new file mode 100644 index 0000000000..de6961bebb --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/despawn_descendants/invalid_entity_errors.lua @@ -0,0 +1,3 @@ +assert_throws(function() + world:despawn_recursive(Entity.from_raw(9999)) +end, "parent Entity does not exist") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/despawn_recursive/despawns_recursively.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/despawn_recursive/despawns_recursively.lua new file mode 100644 index 0000000000..554fe5dc9b --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/despawn_recursive/despawns_recursively.lua @@ -0,0 +1,7 @@ +local entity = world:spawn() +local child = world:spawn() +world:push_children(entity, {child}) +world:despawn_recursive(entity) + +assert(world:has_entity(entity) == false, "Parent should be despawned") +assert(world:has_entity(child) == false, "Child should be despawned") diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/despawn_recursive/invalid_entity_errors.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/despawn_recursive/invalid_entity_errors.lua new file mode 100644 index 0000000000..de6961bebb --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/despawn_recursive/invalid_entity_errors.lua @@ -0,0 +1,3 @@ +assert_throws(function() + world:despawn_recursive(Entity.from_raw(9999)) +end, "parent Entity does not exist") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_children/has_children_returns_them.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_children/has_children_returns_them.lua new file mode 100644 index 0000000000..7640c6f9c0 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/get_children/has_children_returns_them.lua @@ -0,0 +1,9 @@ +local entity = world:spawn() +local child = world:spawn(entity) + +world:push_children(entity, {child}) + +local children = world:get_children(entity) + +assert(#children == 1, "Expected 1 child") +assert(children[1]:index() == child:index(), "Child is the wrong entity") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_children/invalid_entity_errors.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_children/invalid_entity_errors.lua new file mode 100644 index 0000000000..2516a20860 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/get_children/invalid_entity_errors.lua @@ -0,0 +1,4 @@ + +assert_throws(function() + world:get_children(Entity.from_raw(9999)) +end, "Entity does not exist") diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_children/no_children_returns_empty_table.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_children/no_children_returns_empty_table.lua new file mode 100644 index 0000000000..49992aecf3 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/get_children/no_children_returns_empty_table.lua @@ -0,0 +1,4 @@ +local entity = world:spawn() +local children = world:get_children(entity) + +assert(#children == 0) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_parent/has_parent_returns_it.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_parent/has_parent_returns_it.lua new file mode 100644 index 0000000000..955a467b13 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/get_parent/has_parent_returns_it.lua @@ -0,0 +1,9 @@ +local entity = world:spawn() +local child = world:spawn(entity) + +world:push_children(entity, {child}) + +local parent = world:get_parent(child) + +assert(parent ~= nil, "Expected a parent") +assert(parent:index() == entity:index(), "Parent is the wrong entity") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_parent/invalid_entity_errors.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_parent/invalid_entity_errors.lua new file mode 100644 index 0000000000..06500f3360 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/get_parent/invalid_entity_errors.lua @@ -0,0 +1,4 @@ + +assert_throws(function() + world:get_parent(Entity.from_raw(9999)) +end, "Entity does not exist") diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/get_parent/no_parent_returns_nil.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/get_parent/no_parent_returns_nil.lua new file mode 100644 index 0000000000..723c709a56 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/get_parent/no_parent_returns_nil.lua @@ -0,0 +1,4 @@ +local entity = world:spawn() +local parent = world:get_parent(entity) + +assert(parent == nil, "Expected no parents") diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/adding_empty_list_does_nothing.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/adding_empty_list_does_nothing.lua new file mode 100644 index 0000000000..014d3bb892 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/adding_empty_list_does_nothing.lua @@ -0,0 +1,5 @@ +local entity = world:spawn() + +world:insert_children(entity,1 , {}) + +assert(#world:get_children(entity) == 0) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/adds_children_at_correct_index.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/adds_children_at_correct_index.lua new file mode 100644 index 0000000000..6f7f133beb --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/adds_children_at_correct_index.lua @@ -0,0 +1,8 @@ +local entity = world:spawn() +local child = world:spawn() +local child2 = world:spawn() + +world:insert_children(entity, 1, {child}) +world:insert_children(entity, 1, {child2}) + +assert(world:get_children(entity)[1]:index() == child2:index()) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/adds_children_to_existing_enttity.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/adds_children_to_existing_enttity.lua new file mode 100644 index 0000000000..b9360485fc --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/adds_children_to_existing_enttity.lua @@ -0,0 +1,7 @@ +local entity = world:spawn() +local child = world:spawn() +local child2 = world:spawn() + +world:insert_children(entity, 1, {child, child2}) + +assert(#world:get_children(entity) == 2) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/invalid_entity_errors.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/invalid_entity_errors.lua new file mode 100644 index 0000000000..528f1eb64d --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/insert_children/invalid_entity_errors.lua @@ -0,0 +1,10 @@ +local fake_entity = Entity.from_raw(9999) + +assert_throws(function() + world:insert_children(fake_entity, 1, {fake_entity}) +end, "parent Entity does not exist") + +local entity = world:spawn() +assert_throws(function() + world:insert_children(entity, 1, {fake_entity}) +end, "the Entity does not exist") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/push_children/adding_empty_list_does_nothing.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/push_children/adding_empty_list_does_nothing.lua new file mode 100644 index 0000000000..350383361a --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/push_children/adding_empty_list_does_nothing.lua @@ -0,0 +1,5 @@ +local entity = world:spawn() + +world:push_children(entity, {}) + +assert(#world:get_children(entity) == 0) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/push_children/adds_children_to_existing_enttity.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/push_children/adds_children_to_existing_enttity.lua new file mode 100644 index 0000000000..1f082f1a1d --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/push_children/adds_children_to_existing_enttity.lua @@ -0,0 +1,7 @@ +local entity = world:spawn() +local child = world:spawn() +local child2 = world:spawn() + +world:push_children(entity, {child, child2}) + +assert(#world:get_children(entity) == 2) \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/push_children/invalid_entity_errors.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/push_children/invalid_entity_errors.lua new file mode 100644 index 0000000000..eae6c3b0c4 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/push_children/invalid_entity_errors.lua @@ -0,0 +1,10 @@ +local fake_entity = Entity.from_raw(9999) + +assert_throws(function() + world:push_children(fake_entity, {fake_entity}) +end, "The parent Entity does not exist") + +local entity = world:spawn() +assert_throws(function() + world:push_children(entity, {fake_entity}) +end, "the Entity does not exist") \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs b/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs index 189a2269df..45f5d617fe 100644 --- a/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs +++ b/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs @@ -1,7 +1,7 @@ use bevy::{ app::App, asset::{AssetPlugin, AssetServer}, - prelude::{AppTypeRegistry, Entity, World}, + prelude::{AppTypeRegistry, Children, Entity, HierarchyPlugin, Parent, World}, reflect::{Reflect, TypeRegistration}, MinimalPlugins, }; @@ -30,7 +30,7 @@ use std::{ any::TypeId, borrow::Cow, fs::{self, DirEntry}, - io, + io, panic, path::{Path, PathBuf}, sync::Arc, }; @@ -46,9 +46,16 @@ fn init_app() -> App { // we probably should cut down some fat in here, but it's fast enough so meh app.add_plugins(AssetPlugin::default()) + .add_plugins(HierarchyPlugin) .add_plugins(LuaScriptingPlugin::<()>::default()) .add_plugins(bevy_mod_scripting_lua::bindings::providers::LuaBevyScriptingPlugin); + // for some reason hierarchy plugin doesn't register the children component + app.world_mut().register_component::(); + app.world_mut().register_component::(); + app.finish(); + app.cleanup(); + app } @@ -88,23 +95,24 @@ fn init_lua_test_utils(_script_name: &Cow<'static, str>, lua: &mut Lua) -> Resul let assert_throws = lua .create_function(|_, (f, regex): (LuaFunction, String)| { let result = f.call::<(), ()>(()); - match result { - Ok(_) => Err(tealr::mlu::mlua::Error::RuntimeError( - "Expected function to throw error, but it did not.".into(), - )), - Err(e) => { - let error_message = e.to_string(); - let regex = regex::Regex::new(®ex).unwrap(); - if regex.is_match(&error_message) { - Ok(()) - } else { - Err(tealr::mlu::mlua::Error::RuntimeError(format!( - "Expected error message to match the regex: \n{}\n\nBut got:\n{}", - regex.as_str(), - error_message - ))) - } + let err = match result { + Ok(_) => { + return Err(tealr::mlu::mlua::Error::RuntimeError( + "Expected function to throw error, but it did not.".into(), + )) } + Err(e) => e.to_string(), + }; + + let regex = regex::Regex::new(®ex).unwrap(); + if regex.is_match(&err) { + Ok(()) + } else { + Err(tealr::mlu::mlua::Error::RuntimeError(format!( + "Expected error message to match the regex: \n{}\n\nBut got:\n{}", + regex.as_str(), + err + ))) } }) .unwrap(); From 0b9e277b828acf86f91307cc066f775b596cd494 Mon Sep 17 00:00:00 2001 From: makspll Date: Fri, 15 Nov 2024 17:44:33 +0000 Subject: [PATCH 16/22] re-implement dynamic queries Co-authored-by: Lily --- .../src/bindings/query.rs | 105 ++++++++++----- .../src/bindings/world.rs | 6 +- .../src/bindings/mod.rs | 3 +- .../src/bindings/query.rs | 122 ++++++++++++++++++ .../src/bindings/world.rs | 21 +++ .../bevy_mod_scripting_lua/src/util.rs | 65 +++++++++- .../query/empty_query_returns_nothing.lua | 5 + .../query_returns_all_entities_matching.lua | 31 +++++ 8 files changed, 320 insertions(+), 38 deletions(-) create mode 100644 crates/languages/bevy_mod_scripting_lua/src/bindings/query.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/query/empty_query_returns_nothing.lua create mode 100644 crates/languages/bevy_mod_scripting_lua/tests/data/query/query_returns_all_entities_matching.lua diff --git a/crates/bevy_mod_scripting_core/src/bindings/query.rs b/crates/bevy_mod_scripting_core/src/bindings/query.rs index 95421292ed..cf2a4dfdf7 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/query.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/query.rs @@ -1,10 +1,14 @@ -use super::{ReflectReference, WorldCallbackAccess}; -use crate::prelude::ScriptResult; +use super::{ReflectReference, WorldAccessGuard, WorldCallbackAccess}; +use crate::{ + bindings::{CONCURRENT_WORLD_ACCESS_MSG, STALE_WORLD_MSG}, + prelude::ScriptResult, +}; use bevy::{ ecs::{component::ComponentId, entity::Entity}, + prelude::{EntityRef, QueryBuilder}, reflect::TypeRegistration, }; -use std::{any::TypeId, ops::Deref, sync::Arc}; +use std::{any::TypeId, collections::VecDeque, sync::Arc}; /// A wrapper around a `TypeRegistration` that provides additional information about the type. /// @@ -65,24 +69,14 @@ impl std::fmt::Display for ScriptTypeRegistration { } } -#[derive(Clone)] +#[derive(Clone, Default)] pub struct ScriptQueryBuilder { - world: WorldCallbackAccess, components: Vec, with: Vec, without: Vec, } impl ScriptQueryBuilder { - pub fn new(world: WorldCallbackAccess) -> Self { - Self { - world, - components: vec![], - with: vec![], - without: vec![], - } - } - pub fn components(&mut self, components: Vec) -> &mut Self { self.components.extend(components); self @@ -97,29 +91,76 @@ impl ScriptQueryBuilder { self.without.extend(without); self } - - pub fn build(&mut self) -> ScriptResult> { - self.world.query( - std::mem::take(&mut self.components), - std::mem::take(&mut self.with), - std::mem::take(&mut self.without), - ) - } } #[derive(Clone)] pub struct ScriptQueryResult(pub Entity, pub Vec); impl WorldCallbackAccess { - pub fn query( - &mut self, - components: Vec, - with: Vec, - without: Vec, - ) -> ScriptResult> { - // for c in components { - - // } - todo!() + pub fn query(&self, query: ScriptQueryBuilder) -> ScriptResult> { + // find the set of components + self.read() + .unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")) + .query(query) } } + +impl<'w> WorldAccessGuard<'w> { + pub fn query(&self, query: ScriptQueryBuilder) -> ScriptResult> { + let world = self + .get_whole_world_access() + .unwrap_or_else(|| panic!("{CONCURRENT_WORLD_ACCESS_MSG}")); + + let mut dynamic_query = QueryBuilder::::new(world); + + // we don't actually want to fetch the data for components now, only figure out + // which entities match the query + // so we might be being slightly overkill + for c in &query.components { + dynamic_query.ref_id(c.component_id().unwrap()); + } + + for w in query.with { + dynamic_query.with_id(w.component_id.unwrap()); + } + + for without_id in query.without { + dynamic_query.without_id(without_id.component_id.unwrap()); + } + + let mut built_query = dynamic_query.build(); + let query_result = built_query.iter(world); + + Ok(query_result + .map(|r| { + let references: Vec<_> = query + .components + .iter() + .map(|c| ReflectReference { + base: super::ReflectBaseType { + type_id: c.type_id(), + base_id: super::ReflectBase::Component(r.id(), c.component_id.unwrap()), + }, + reflect_path: vec![], + }) + .collect(); + ScriptQueryResult(r.id(), references) + }) + .collect()) + } +} + +#[cfg(test)] +mod test { + use test_utils::test_data::setup_world; + + use super::*; + + // #[test] + // fn test_simple_query() { + // let world = setup_world(|w,r|{ + // w.spawn(TestComponent::init()) + // w.spawn(Te) + // }) + // } +} diff --git a/crates/bevy_mod_scripting_core/src/bindings/world.rs b/crates/bevy_mod_scripting_core/src/bindings/world.rs index e63f51399b..63f42b520e 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/world.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/world.rs @@ -245,11 +245,11 @@ pub const DEFAULT_INTERVAL: Duration = Duration::from_millis(10); /// Provides safe access to the world via [`WorldAccess`] permissions, which enforce aliasing rules at runtime in multi-thread environments #[derive(Clone)] pub struct WorldAccessGuard<'w> { - cell: UnsafeWorldCell<'w>, + pub cell: UnsafeWorldCell<'w>, // TODO: this is fairly hefty, explore other ways to hand out locks on WorldAccess - accesses: Arc>>>, + pub accesses: Arc>>>, /// true if anybody has any access to the world - accesses_count: Arc, + pub accesses_count: Arc, // TODO can we track code/stack locations of things holding onto theese locks for debugging? } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/mod.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/mod.rs index 5a278b6306..78cd9549b3 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/mod.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/mod.rs @@ -1,7 +1,6 @@ -use bevy_mod_scripting_core::bindings::WorldCallbackAccess; - pub mod providers; pub mod proxy; +pub mod query; pub mod reference; pub mod std; pub mod type_registration; diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/query.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/query.rs new file mode 100644 index 0000000000..da545e2483 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/query.rs @@ -0,0 +1,122 @@ +use std::ops::{Deref, DerefMut}; + +use bevy::prelude::Entity; +use bevy_mod_scripting_core::bindings::{ + ReflectAllocator, ReflectReference, ScriptQueryBuilder, ScriptTypeRegistration, Unproxy, + ValProxy, +}; +use tealr::{ + mlu::{ + mlua::{IntoLua, Value}, + TealData, TypedFunction, + }, + ToTypename, +}; + +use crate::{impl_userdata_from_lua, impl_userdata_with_tealdata, util::Variadic}; + +use super::{ + proxy::{LuaProxied, LuaValProxy}, + reference::LuaReflectReference, + world::GetWorld, +}; + +#[derive(Default, Clone)] +pub struct LuaQueryBuilder(pub(crate) ScriptQueryBuilder); + +impl Deref for LuaQueryBuilder { + type Target = ScriptQueryBuilder; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for LuaQueryBuilder { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl LuaQueryBuilder {} + +impl LuaProxied for ScriptQueryBuilder { + type Proxy = LuaQueryBuilder; +} + +impl_userdata_from_lua!(LuaQueryBuilder); +impl_userdata_with_tealdata!(LuaQueryBuilder); + +impl TealData for LuaQueryBuilder { + fn add_methods<'lua, T: tealr::mlu::TealDataMethods<'lua, Self>>(methods: &mut T) { + methods.add_function( + "with", + |_, (mut this, mut query): (Self, Variadic>)| { + let registrations: Vec<_> = query + .iter_mut() + .map(|v| v.unproxy()) + .collect::>() + .map_err(tealr::mlu::mlua::Error::external)?; + this.0.with(registrations); + Ok(this) + }, + ); + + methods.add_function( + "without", + |_, (mut this, mut query): (Self, Variadic>)| { + let registrations: Vec<_> = query + .iter_mut() + .map(|v| v.unproxy()) + .collect::>() + .map_err(tealr::mlu::mlua::Error::external)?; + this.0.without(registrations); + Ok(this) + }, + ); + + methods.add_function("iter", |l, this: LuaQueryBuilder| { + let world = l.get_world()?; + let mut result = world + .query(this.0) + .map_err(tealr::mlu::mlua::Error::external)?; + let mut len = result.len(); + let iterator = TypedFunction::from_rust_mut( + move |lua, ()| { + if len > 0 { + let result = result + .pop_front() + .expect("invariant: len of array = len && len > 0"); + let entity = + world.with_resource::(|_, mut allocator| { + ReflectReference::new_allocated(result.0, &mut allocator) + }); + let proxy_entity = + ::Proxy::from(entity).into_lua(lua)?; + let component_refs: Vec<_> = result + .1 + .into_iter() + .map(|r| LuaReflectReference(r).to_lua_proxy(lua)) + .collect::>()?; + + len -= 1; + + Ok(Variadic::new( + std::iter::once(proxy_entity).chain(component_refs.into_iter()), + )) + } else { + Ok(Variadic::new(vec![Value::Nil, Value::Nil])) + } + }, + l, + )?; + Ok(iterator) + }); + } +} + +impl ToTypename for LuaQueryBuilder { + fn to_typename() -> tealr::Type { + tealr::Type::new_single("QueryBuilder", tealr::KindOfType::External) + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs index f7ddbf5ed3..3c143a5f0d 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs @@ -20,6 +20,7 @@ use tealr::{ }; use super::proxy::LuaReflectRefProxy; +use super::query::LuaQueryBuilder; use super::{ providers::bevy_ecs::LuaEntity, proxy::{ @@ -27,6 +28,7 @@ use super::{ }, type_registration::LuaTypeRegistration, }; +use crate::util::Variadic; use crate::{impl_userdata_from_lua, impl_userdata_with_tealdata}; pub struct Nil; @@ -375,6 +377,25 @@ impl TealData for LuaWorld { Ok(TypenameProxy::<_, Nil>::new(out)) }, ); + + methods.add_method( + "query", + |_, this, mut components: Variadic>| { + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + let mut builder = LuaQueryBuilder::default(); + let deque = components.0; + builder.components( + deque + .into_iter() + .map(|mut c| c.unproxy()) + .collect::>() + .map_err(tealr::mlu::mlua::Error::external)?, + ); + Ok(builder) + }, + ); } fn add_fields<'lua, F: tealr::mlu::TealDataFields<'lua, Self>>(_fields: &mut F) {} diff --git a/crates/languages/bevy_mod_scripting_lua/src/util.rs b/crates/languages/bevy_mod_scripting_lua/src/util.rs index 2652ee2f0a..52d4308a5c 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/util.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/util.rs @@ -1,3 +1,10 @@ +use std::ops::{Deref, DerefMut}; + +use tealr::{ + mlu::mlua::{FromLua, FromLuaMulti, IntoLua, IntoLuaMulti}, + ToTypename, +}; + /// generates path to the given script depending on build configuration. /// (optimized builds don't have the teal compiler available) /// @@ -163,7 +170,12 @@ macro_rules! impl_userdata_from_lua { _lua: &::tealr::mlu::mlua::Lua, ) -> Result { match value { - tealr::mlu::mlua::Value::UserData(ud) => Ok(ud.borrow::()?.clone()), + tealr::mlu::mlua::Value::UserData(ud) => { + // for types which deref to something else we need to be explicit + let self_ref: std::cell::Ref = ud.borrow::()?; + let self_ref: &Self = std::ops::Deref::deref(&self_ref); + Ok(self_ref.clone()) + } _ => { return Err(::tealr::mlu::mlua::Error::FromLuaConversionError { from: value.type_name(), @@ -198,3 +210,54 @@ macro_rules! impl_userdata_with_tealdata { } }; } + +/// Variadic newtype with [`ToTypename`] implemantation +pub struct Variadic(pub(crate) tealr::mlu::mlua::Variadic); + +impl Variadic { + pub fn new>(iter: I) -> Self { + Variadic(tealr::mlu::mlua::Variadic::from_iter(iter.into_iter())) + } +} + +impl Deref for Variadic { + type Target = tealr::mlu::mlua::Variadic; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for Variadic { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl ToTypename for Variadic { + fn to_typename() -> tealr::Type { + let single_type = T::to_typename(); + let collection_type = >::to_typename(); + tealr::Type::Or(vec![single_type, collection_type]) + } +} + +impl<'lua, T: FromLua<'lua>> FromLuaMulti<'lua> for Variadic { + fn from_lua_multi( + values: tealr::mlu::mlua::MultiValue<'lua>, + lua: &'lua tealr::mlu::mlua::Lua, + ) -> tealr::mlu::mlua::Result { + Ok(Variadic(tealr::mlu::mlua::Variadic::from_lua_multi( + values, lua, + )?)) + } +} + +impl<'lua, T: IntoLua<'lua>> IntoLuaMulti<'lua> for Variadic { + fn into_lua_multi( + self, + lua: &'lua tealr::mlu::mlua::Lua, + ) -> tealr::mlu::mlua::Result> { + self.0.into_lua_multi(lua) + } +} diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/query/empty_query_returns_nothing.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/query/empty_query_returns_nothing.lua new file mode 100644 index 0000000000..d31939bdb9 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/query/empty_query_returns_nothing.lua @@ -0,0 +1,5 @@ +local component_a = world:get_type_by_name("TestComponent") + +for entity,_ in world:query(component_a):with(component_a):without(component_a):iter() do + assert(false, "This should not be reached") +end \ No newline at end of file diff --git a/crates/languages/bevy_mod_scripting_lua/tests/data/query/query_returns_all_entities_matching.lua b/crates/languages/bevy_mod_scripting_lua/tests/data/query/query_returns_all_entities_matching.lua new file mode 100644 index 0000000000..b624260ed7 --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/tests/data/query/query_returns_all_entities_matching.lua @@ -0,0 +1,31 @@ +local entity_a = world:spawn() +local entity_b = world:spawn() +local entity_c = world:spawn() +local entity_d = _get_entity_with_test_component("CompWithFromWorldAndComponentData") + +local component_with = world:get_type_by_name("CompWithFromWorldAndComponentData") +local component_without = world:get_type_by_name("CompWithDefaultAndComponentData") + +world:add_default_component(entity_a, component_with) +world:add_default_component(entity_b, component_with) +world:add_default_component(entity_c, component_with) + +world:add_default_component(entity_b, component_without) + +local found_entities = {} +for entity, comp in world:query(component_with):with(component_with):without(component_without):iter() do + table.insert(found_entities, entity) +end + +assert(#found_entities == 3, "Expected 3 entities, got " .. #found_entities) + +expected_entities = { + entity_d, + entity_a, + entity_c, +} + +for i, entity in ipairs(found_entities) do + assert(entity:index() == expected_entities[i]:index(), "Expected entity " .. expected_entities[i]:index() .. " but got " .. entity:index()) +end + From debaa169f7a315570cc25caa784fc81b8a8bde7b Mon Sep 17 00:00:00 2001 From: makspll Date: Tue, 19 Nov 2024 15:26:07 +0000 Subject: [PATCH 17/22] Re-implement changes to rhai and rune, and fix event recipients example --- .github/workflows/bevy_mod_scripting.yml | 22 +- .github/workflows/doc_gen.yml | 2 +- .vscode/launch.json | 2 +- Cargo.toml | 44 +- assets/scripts/event_recipients.lua | 6 +- check.sh | 2 +- .../bevy_mod_scripting_core/src/commands.rs | 4 +- crates/bevy_mod_scripting_core/src/context.rs | 2 +- crates/bevy_mod_scripting_core/src/lib.rs | 55 +- crates/bevy_mod_scripting_core/src/runtime.rs | 20 +- crates/bevy_mod_scripting_core/src/systems.rs | 34 +- .../bevy_mod_scripting_lua/src/assets.rs | 1 - .../bevy_mod_scripting_lua/src/lib.rs | 25 +- .../bevy_mod_scripting_rhai/src/lib.rs | 505 +++++++++++------ .../bevy_mod_scripting_rune/src/lib.rs | 527 +++++++++--------- crates/macro_tests/Cargo.toml | 6 +- examples/lua/event_recipients.rs | 174 ++---- src/lib.rs | 22 +- 18 files changed, 787 insertions(+), 666 deletions(-) diff --git a/.github/workflows/bevy_mod_scripting.yml b/.github/workflows/bevy_mod_scripting.yml index 8524716b1a..4c5b625c4e 100644 --- a/.github/workflows/bevy_mod_scripting.yml +++ b/.github/workflows/bevy_mod_scripting.yml @@ -26,15 +26,15 @@ jobs: strategy: matrix: run_args: [ - {label: Windows - All Features, os: windows-latest, features: "lua54,rhai,teal,lua_script_api,rhai_script_api,rune", cross: x86_64-pc-windows-msvc }, - {label: MacOS - All Features, os: macOS-latest, features: "lua54,rhai,teal,lua_script_api,rhai_script_api,rune", cross: x86_64-apple-darwin }, - {label: Ubuntu - All Features, os: ubuntu-latest, features: "lua54,lua_script_api,rhai,teal,rhai_script_api,rune", cross: x86_64-unknown-linux-gnu }, - {label: Ubuntu Aarch64 - All Features, os: ubuntu-latest, features: "lua54,rhai,teal,lua_script_api,rhai_script_api,rune", cross: aarch64-unknown-linux-gnu }, - {label: Ubuntu - Lua51, os: ubuntu-latest, features: "lua51,lua_script_api", cross: x86_64-unknown-linux-gnu }, - {label: Ubuntu - Lua52, os: ubuntu-latest, features: "lua52,lua_script_api", cross: x86_64-unknown-linux-gnu }, - {label: Ubuntu - Lua53, os: ubuntu-latest, features: "lua53,lua_script_api", cross: x86_64-unknown-linux-gnu }, - {label: Ubuntu - Luajit, os: ubuntu-latest, features: "luajit,lua_script_api", cross: x86_64-unknown-linux-gnu }, - {label: Ubuntu - Luajit52, os: ubuntu-latest, features: "luajit52,lua_script_api", cross: x86_64-unknown-linux-gnu } + {label: Windows - All Features, os: windows-latest, features: "lua54,rhai,teal,rune", cross: x86_64-pc-windows-msvc }, + {label: MacOS - All Features, os: macOS-latest, features: "lua54,rhai,teal,rune", cross: x86_64-apple-darwin }, + {label: Ubuntu - All Features, os: ubuntu-latest, features: "lua54,rhai,teal,rune", cross: x86_64-unknown-linux-gnu }, + {label: Ubuntu Aarch64 - All Features, os: ubuntu-latest, features: "lua54,rhai,teal,rune", cross: aarch64-unknown-linux-gnu }, + {label: Ubuntu - Lua51, os: ubuntu-latest, features: "lua51", cross: x86_64-unknown-linux-gnu }, + {label: Ubuntu - Lua52, os: ubuntu-latest, features: "lua52", cross: x86_64-unknown-linux-gnu }, + {label: Ubuntu - Lua53, os: ubuntu-latest, features: "lua53", cross: x86_64-unknown-linux-gnu }, + {label: Ubuntu - Luajit, os: ubuntu-latest, features: "luajit", cross: x86_64-unknown-linux-gnu }, + {label: Ubuntu - Luajit52, os: ubuntu-latest, features: "luajit52", cross: x86_64-unknown-linux-gnu } ] steps: - if: runner.os == 'linux' @@ -94,7 +94,7 @@ jobs: - uses: actions-rs/cargo@v1 with: command: clippy - args: --features=lua54,rhai,teal,lua_script_api,rhai_script_api,rune --profile=ephemeral-build -- -D warnings + args: --features=lua54,rhai,teal,rune --profile=ephemeral-build -- -D warnings tests: name: Tests runs-on: ubuntu-latest @@ -114,7 +114,7 @@ jobs: - uses: actions-rs/cargo@v1 with: command: test - args: --workspace --features=lua54,rhai,teal,lua_script_api,rhai_script_api,rune --profile=ephemeral-build + args: --workspace --features=lua54,rhai,teal,rune --profile=ephemeral-build docs: name: Docs runs-on: ubuntu-latest diff --git a/.github/workflows/doc_gen.yml b/.github/workflows/doc_gen.yml index 0d8a75a703..ed7055970e 100644 --- a/.github/workflows/doc_gen.yml +++ b/.github/workflows/doc_gen.yml @@ -32,7 +32,7 @@ jobs: - uses: actions-rs/cargo@v1 with: command: run - args: --features=lua54,lua_script_api lua + args: --features=lua54 lua - run: cat ./assets/scripts/doc/tealr_doc_gen_config.json - name: Push to pages uses: cpina/github-action-push-to-another-repository@main diff --git a/.vscode/launch.json b/.vscode/launch.json index a6483eca38..67b227bd90 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -25,7 +25,7 @@ "build", "--example=game_of_life_lua", "--package=bevy_mod_scripting", - "--features=lua54,teal,lua_script_api", + "--features=lua54,teal", ], "filter": { "name": "game_of_life_lua", diff --git a/Cargo.toml b/Cargo.toml index c924731e43..e586aa3725 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,15 +21,7 @@ name = "bevy_mod_scripting" path = "src/lib.rs" [package.metadata."docs.rs"] -features = [ - "lua", - "lua54", - "rhai", - "lua_script_api", - "rhai_script_api", - "teal", - "rune", -] +features = ["lua", "lua54", "rhai", "teal", "rune"] [features] ## core @@ -46,7 +38,6 @@ luajit = ["bevy_mod_scripting_lua/luajit", "lua"] luajit52 = ["bevy_mod_scripting_lua/luajit52", "lua"] # optional -lua_script_api = ["bevy_script_api/lua"] unsafe_lua_modules = ["bevy_mod_scripting_lua/unsafe_lua_modules"] teal = ["bevy_mod_scripting_lua/teal"] mlua_serialize = ["bevy_mod_scripting_lua/mlua_serialize"] @@ -55,7 +46,6 @@ mlua_async = ["bevy_mod_scripting_lua/mlua_async"] ## rhai rhai = ["bevy_mod_scripting_rhai"] -rhai_script_api = ["bevy_script_api/rhai"] ## rune rune = ["bevy_mod_scripting_rune"] @@ -66,7 +56,6 @@ bevy_mod_scripting_core = { workspace = true } bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.8.0-alpha.1", optional = true } bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.8.0-alpha.1", optional = true } bevy_mod_scripting_rune = { path = "crates/languages/bevy_mod_scripting_rune", version = "0.8.0-alpha.1", optional = true } -bevy_script_api = { path = "crates/bevy_script_api", version = "0.8.0-alpha.1", optional = true } [workspace.dependencies] @@ -86,7 +75,6 @@ rhai-rand = "0.1" members = [ "crates/bevy_mod_scripting_core", "crates/bevy_event_priority", - "crates/bevy_script_api", "crates/languages/bevy_mod_scripting_lua", "crates/languages/bevy_mod_scripting_lua_derive", "crates/languages/bevy_mod_scripting_rhai", @@ -120,7 +108,7 @@ debug = false # path = "examples/lua/console_integration.rs" # required-features = [ # "lua54", -# "lua_script_api", +# # "bevy/file_watcher", # "bevy/multi_threaded", # ] @@ -130,7 +118,7 @@ debug = false # path = "examples/rhai/console_integration.rs" # required-features = [ # "rhai", -# "rhai_script_api", +# , # "bevy/file_watcher", # "bevy/multi_threaded", # ] @@ -143,32 +131,22 @@ required-features = ["lua54"] [[example]] name = "dynamic_queries_lua" path = "examples/lua/dynamic_queries.rs" -required-features = ["lua54", "lua_script_api"] +required-features = ["lua54"] [[example]] name = "dynamic_queries_rhai" path = "examples/rhai/dynamic_queries.rs" -required-features = ["rhai", "rhai_script_api"] +required-features = ["rhai"] [[example]] name = "game_of_life_lua" path = "examples/lua/game_of_life.rs" -required-features = [ - "lua54", - "lua_script_api", - "bevy/file_watcher", - "bevy/multi_threaded", -] +required-features = ["lua54", "bevy/file_watcher", "bevy/multi_threaded"] [[example]] +required-features = ["rhai", "bevy/file_watcher", "bevy/multi_threaded"] name = "game_of_life_rhai" path = "examples/rhai/game_of_life.rs" -required-features = [ - "rhai", - "rhai_script_api", - "bevy/file_watcher", - "bevy/multi_threaded", -] [[example]] name = "event_recipients_lua" @@ -183,22 +161,22 @@ required-features = ["lua54"] [[example]] name = "documentation_gen_lua" path = "examples/lua/documentation_gen.rs" -required-features = ["lua54", "teal", "lua_script_api"] +required-features = ["lua54", "teal"] [[example]] name = "bevy_api_lua" path = "examples/lua/bevy_api.rs" -required-features = ["lua54", "lua_script_api"] +required-features = ["lua54"] [[example]] name = "bevy_api_rhai" path = "examples/rhai/bevy_api.rs" -required-features = ["rhai", "rhai_script_api"] +required-features = ["rhai"] [[example]] name = "wrappers" path = "examples/wrappers.rs" -required-features = ["lua54", "lua_script_api"] +required-features = ["lua54"] [[example]] name = "minimal_rune" diff --git a/assets/scripts/event_recipients.lua b/assets/scripts/event_recipients.lua index 2aa50e2528..b846a742ae 100644 --- a/assets/scripts/event_recipients.lua +++ b/assets/scripts/event_recipients.lua @@ -1,4 +1,6 @@ function on_event(id) - print(string.format("on_event, script_id: %d, Handling:", script_id)) - print(string.format("\t-> id: %d", id)) + print(string.format("on_event, script_id: %s, Handling:", script_id)) + print(string.format("\t-> id : %d", id)) + print(string.format("\t-> entity : %s", entity)) + end diff --git a/check.sh b/check.sh index eb7a8f5488..18d7f7c1c4 100755 --- a/check.sh +++ b/check.sh @@ -6,5 +6,5 @@ CURRENT_DIR=$(basename "$PWD") if [[ "$CURRENT_DIR" == "bevy_api_gen" ]]; then cargo +nightly-2024-11-05 clippy --all-targets --message-format=json else - cargo clippy --workspace --all-targets --message-format=json --features="lua54 lua_script_api rhai rhai_script_api teal rune bevy/file_watcher bevy/multi_threaded" + cargo clippy --workspace --all-targets --message-format=json --features="lua54 rhai teal rune bevy/file_watcher bevy/multi_threaded" fi diff --git a/crates/bevy_mod_scripting_core/src/commands.rs b/crates/bevy_mod_scripting_core/src/commands.rs index d2b3618445..ddefeee03a 100644 --- a/crates/bevy_mod_scripting_core/src/commands.rs +++ b/crates/bevy_mod_scripting_core/src/commands.rs @@ -106,10 +106,12 @@ impl Command for CreateOrUpdateScript { // If None assign new context ID, otherwise assign the old one // If re-loading and different from the previous one, the old one will be removed let current_context_id = (assigner.assign)(script.as_deref(), &self.id, &self.content, &mut contexts); + debug!("Context assigned: {:?}", current_context_id); + let current_context_id = if let Some(id) = current_context_id { id } else { - let ctxt = (builder.load)(&self.id, &self.content, &settings.context_initializers, &settings.context_pre_handling_initializers, world, runtime.runtime.as_mut().unwrap()).unwrap(); + let ctxt = (builder.load)(&self.id, &self.content, &settings.context_initializers, &settings.context_pre_handling_initializers, world, &mut runtime.runtime).unwrap(); contexts.insert(ctxt) }; diff --git a/crates/bevy_mod_scripting_core/src/context.rs b/crates/bevy_mod_scripting_core/src/context.rs index 169cd831da..fcd5087cd5 100644 --- a/crates/bevy_mod_scripting_core/src/context.rs +++ b/crates/bevy_mod_scripting_core/src/context.rs @@ -136,7 +136,7 @@ pub struct ContextAssigner { impl Default for ContextAssigner { fn default() -> Self { Self { - assign: |_, _, _, c| Some(c.allocate_id()), + assign: |old, _, _, _| old.map(|s| s.context_id), remove: |id, _, c| _ = c.remove(id), } } diff --git a/crates/bevy_mod_scripting_core/src/lib.rs b/crates/bevy_mod_scripting_core/src/lib.rs index 92ed2a219f..8b5c0f00df 100644 --- a/crates/bevy_mod_scripting_core/src/lib.rs +++ b/crates/bevy_mod_scripting_core/src/lib.rs @@ -34,11 +34,12 @@ pub mod prelude { pub use {crate::docs::*, crate::error::*, crate::event::*, crate::systems::*, crate::*}; } -#[derive(Default)] /// Bevy plugin enabling scripting within the bevy mod scripting framework pub struct ScriptingPlugin { /// Callback for initiating the runtime - pub runtime_builder: Option R>, + pub runtime_builder: fn() -> R, + /// Settings for the runtime + pub runtime_settings: Option>, /// The handler used for executing callbacks in scripts pub callback_handler: Option>, /// The context builder for loading contexts @@ -47,6 +48,18 @@ pub struct ScriptingPlugin { pub context_assigner: Option>, } +impl Default for ScriptingPlugin { + fn default() -> Self { + Self { + runtime_builder: R::default, + runtime_settings: Default::default(), + callback_handler: Default::default(), + context_builder: Default::default(), + context_assigner: Default::default(), + } + } +} + impl Plugin for ScriptingPlugin { fn build(&self, app: &mut bevy::prelude::App) { app.add_event::() @@ -60,11 +73,10 @@ impl Plugin for ScriptingPlugin { extensions: &[], preprocessor: None, }) - // not every script host will have a runtime, for convenience we add a dummy runtime + .insert_resource(self.runtime_settings.as_ref().cloned().unwrap_or_default()) .insert_non_send_resource::>(RuntimeContainer { - runtime: self.runtime_builder.map(|f| f()), + runtime: (self.runtime_builder)(), }) - .init_non_send_resource::>() .init_non_send_resource::>() .insert_resource::>(CallbackSettings { callback_handler: self.callback_handler, @@ -86,7 +98,9 @@ pub trait AddRuntimeInitializer { impl AddRuntimeInitializer for App { fn add_runtime_initializer(&mut self, initializer: RuntimeInitializer) -> &mut Self { - self.world_mut().init_resource::>(); + if !self.world_mut().contains_resource::>() { + self.world_mut().init_resource::>(); + } self.world_mut() .resource_mut::>() .as_mut() @@ -180,3 +194,32 @@ impl StoreDocumentation for App { top_fragment.gen_docs() } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_default_scripting_plugin_initializes_all_resources_correctly() { + let mut app = App::new(); + #[derive(Default, Clone)] + struct A; + #[derive(Default, Clone)] + struct C; + #[derive(Default, Clone)] + struct R; + app.add_plugins(AssetPlugin::default()); + app.add_plugins(ScriptingPlugin::::default()); + + assert!(app.world().contains_resource::()); + assert!(app.world().contains_resource::()); + assert!(app.world().contains_resource::()); + assert!(app.world().contains_resource::>()); + assert!(app.world().contains_resource::>()); + assert!(app + .world() + .contains_resource::>()); + assert!(app.world().contains_non_send::>()); + assert!(app.world().contains_non_send::>()); + } +} diff --git a/crates/bevy_mod_scripting_core/src/runtime.rs b/crates/bevy_mod_scripting_core/src/runtime.rs index 6530829904..6b9fe7fb67 100644 --- a/crates/bevy_mod_scripting_core/src/runtime.rs +++ b/crates/bevy_mod_scripting_core/src/runtime.rs @@ -8,7 +8,7 @@ impl Runtime for T {} pub type RuntimeInitializer = fn(&mut R); -#[derive(Clone, Resource)] +#[derive(Resource)] pub struct RuntimeSettings { pub initializers: Vec>, } @@ -21,16 +21,16 @@ impl Default for RuntimeSettings { } } -/// Stores a particular runtime. -#[derive(Resource)] -pub struct RuntimeContainer { - pub runtime: Option, -} - -impl Default for RuntimeContainer { - fn default() -> Self { +impl Clone for RuntimeSettings { + fn clone(&self) -> Self { Self { - runtime: Default::default(), + initializers: self.initializers.clone(), } } } + +/// Stores a particular runtime. +#[derive(Resource)] +pub struct RuntimeContainer { + pub runtime: R, +} diff --git a/crates/bevy_mod_scripting_core/src/systems.rs b/crates/bevy_mod_scripting_core/src/systems.rs index 78ea221327..cf38c001e2 100644 --- a/crates/bevy_mod_scripting_core/src/systems.rs +++ b/crates/bevy_mod_scripting_core/src/systems.rs @@ -22,11 +22,9 @@ pub fn initialize_runtime( mut runtime: NonSendMut>, settings: Res>, ) { - if let Some(r) = runtime.runtime.as_mut() { - for initializer in settings.initializers.iter() { - (initializer)(r); - } - }; + for initializer in settings.initializers.iter() { + (initializer)(&mut runtime.runtime); + } } /// Processes and reacts appropriately to script asset events, and queues commands to update the internal script state @@ -95,16 +93,11 @@ pub fn event_handler( .remove_non_send_resource::>() .unwrap_or_else(|| { panic!( - "No runtime container for runtime {} found", + "No runtime container for runtime {} found. Was the scripting plugin initialized correctly?", type_name::() ) }); - let runtime = runtime_container.runtime.as_mut().unwrap_or_else(|| { - panic!( - "No valid runtime in runtime container for runtime {}", - type_name::() - ) - }); + let runtime = &mut runtime_container.runtime; let mut script_contexts = world .remove_non_send_resource::>() .unwrap_or_else(|| panic!("No script contexts found for context {}", type_name::())); @@ -246,10 +239,16 @@ mod test { }); app.add_systems(Update, event_handler::); app.insert_resource::(Scripts { scripts }); - app.insert_non_send_resource::>(RuntimeContainer { - runtime: Some(runtime), - }); + app.insert_non_send_resource::>(RuntimeContainer { runtime }); app.insert_non_send_resource::>(ScriptContexts { contexts }); + app.insert_resource(ContextLoadingSettings:: { + loader: None, + assigner: None, + context_initializers: vec![], + context_pre_handling_initializers: vec![], + }); + app.finish(); + app.cleanup(); app } @@ -315,8 +314,6 @@ mod test { assert_eq!( test_runtime .runtime - .as_ref() - .unwrap() .invocations .iter() .map(|(e, s)| (*e, s.clone())) @@ -390,6 +387,7 @@ mod test { "test_args_entity".to_owned(), crate::event::Recipients::Entity(test_entity_id), )); + app.update(); let test_context = app @@ -413,8 +411,6 @@ mod test { assert_eq!( test_runtime .runtime - .as_ref() - .unwrap() .invocations .iter() .map(|(e, s)| (*e, s.clone())) diff --git a/crates/languages/bevy_mod_scripting_lua/src/assets.rs b/crates/languages/bevy_mod_scripting_lua/src/assets.rs index b7d54e0c7a..79352f5d45 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/assets.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/assets.rs @@ -3,7 +3,6 @@ // reflect::TypePath, // utils::BoxedFuture, // }; -// use bevy_mod_scripting_core::asset::CodeAsset; // use anyhow::Error; diff --git a/crates/languages/bevy_mod_scripting_lua/src/lib.rs b/crates/languages/bevy_mod_scripting_lua/src/lib.rs index 3fac3c6553..4c73cc2610 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/lib.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/lib.rs @@ -7,15 +7,19 @@ use bevy::{ reflect::{FromType, GetTypeRegistration, PartialReflect, Reflect, TypePath}, }; use bevy_mod_scripting_core::{ - bindings::{ReflectReference, WorldCallbackAccess}, + bindings::{ReflectAllocator, ReflectReference, WorldCallbackAccess}, context::{ContextBuilder, ContextInitializer, ContextPreHandlingInitializer}, error::ScriptError, event::CallbackLabel, handler::Args, script::ScriptId, - ScriptingPlugin, + AddContextPreHandlingInitializer, ScriptingPlugin, +}; +use bindings::{ + providers::bevy_ecs::LuaEntity, + proxy::LuaProxied, + world::{GetWorld, LuaWorld}, }; -use bindings::{proxy::LuaProxied, world::LuaWorld}; pub use tealr; pub mod bindings; use tealr::mlu::mlua::{FromLua, Function, IntoLua, IntoLuaMulti, Lua, Value}; @@ -42,7 +46,8 @@ impl Default for LuaScriptingPlugin { LuaScriptingPlugin { scripting_plugin: ScriptingPlugin { context_assigner: None, - runtime_builder: None, + runtime_builder: Default::default, + runtime_settings: None, callback_handler: Some(lua_handler::), context_builder: Some(ContextBuilder:: { load: lua_context_load, @@ -76,6 +81,17 @@ impl Plugin for LuaScriptingPlugin { fn build(&self, app: &mut bevy::prelude::App) { self.scripting_plugin.build(app); register_lua_values(app); + app.add_context_pre_handling_initializer::<()>(|script_id, entity, context: &mut Lua| { + let world = context.get_world().unwrap(); + let lua_entity = world.with_resource::(|_, mut allocator| { + let reflect_reference = ReflectReference::new_allocated(entity, &mut allocator); + ::Proxy::from(reflect_reference) + }); + + context.globals().set("script_id", script_id.to_owned())?; + context.globals().set("entity", lua_entity)?; + Ok(()) + }); } } @@ -163,7 +179,6 @@ pub fn with_world Result<(), ScriptError>>( ) -> Result<(), ScriptError> { WorldCallbackAccess::with_callback_access(world, |guard| { context.globals().set("world", LuaWorld(guard.clone()))?; - // TODO set entity + script id as well f(context) }) } diff --git a/crates/languages/bevy_mod_scripting_rhai/src/lib.rs b/crates/languages/bevy_mod_scripting_rhai/src/lib.rs index cbb0eb1687..267f2758ae 100644 --- a/crates/languages/bevy_mod_scripting_rhai/src/lib.rs +++ b/crates/languages/bevy_mod_scripting_rhai/src/lib.rs @@ -1,202 +1,351 @@ -use crate::{ - assets::{RhaiFile, RhaiLoader}, - docs::RhaiDocFragment, +use bevy::{ + app::Plugin, + ecs::{entity::Entity, world::World}, }; -use bevy::{ecs::schedule::ScheduleLabel, prelude::*}; -use bevy_mod_scripting_core::{prelude::*, systems::*, world::WorldPointerGuard}; -use rhai::*; -use std::marker::PhantomData; +use bevy_mod_scripting_core::{ + bindings::WorldCallbackAccess, + context::{ContextAssigner, ContextBuilder, ContextInitializer, ContextPreHandlingInitializer}, + error::ScriptError, + event::CallbackLabel, + handler::Args, + script::ScriptId, + ScriptingPlugin, +}; +use rhai::{CallFnOptions, Engine, FnPtr, FuncArgs, Scope, AST}; -pub mod assets; -pub mod docs; pub use rhai; pub mod prelude { - pub use crate::{ - assets::{RhaiFile, RhaiLoader}, - docs::RhaiDocFragment, - RhaiContext, RhaiEvent, RhaiScriptHost, - }; pub use rhai; - pub use rhai::{Engine, FuncArgs}; + pub use rhai::FuncArgs; } -#[derive(Resource)] -pub struct RhaiScriptHost { - pub engine: Engine, - _ph: PhantomData, +pub trait RhaiEventArg: Args + FuncArgs {} +impl RhaiEventArg for T {} + +pub type RhaiRuntime = Engine; + +pub struct RhaiScriptContext { + pub ast: AST, + pub scope: Scope<'static>, } -#[allow(deprecated)] -impl Default for RhaiScriptHost { +pub struct RhaiScriptingPlugin { + pub scripting_plugin: ScriptingPlugin, +} + +impl Default for RhaiScriptingPlugin { fn default() -> Self { - let mut e = Engine::new(); - // prevent shadowing of `state`,`world` and `entity` in variable in scripts - e.on_def_var(|_, info, _| { - Ok(info.name() != "state" && info.name() != "world" && info.name() != "entity") - }); - - Self { - engine: e, - _ph: Default::default(), + RhaiScriptingPlugin { + scripting_plugin: ScriptingPlugin { + runtime_builder: RhaiRuntime::new, + runtime_settings: None, + callback_handler: Some(rhai_callback_handler::), + context_assigner: None, + context_builder: Some(ContextBuilder { + load: rhai_context_load, + reload: rhai_context_reload, + }), + }, } } } -pub struct RhaiContext { - pub ast: AST, - pub scope: Scope<'static>, +impl Plugin for RhaiScriptingPlugin { + fn build(&self, app: &mut bevy::prelude::App) { + self.scripting_plugin.build(app); + } } -#[derive(Clone, Event)] -/// A Rhai Hook. The result of creating this event will be -/// a call to the lua script with the hook_name and the given arguments -pub struct RhaiEvent { - pub hook_name: String, - pub args: A, - pub recipients: Recipients, +pub fn rhai_context_load( + script: &ScriptId, + content: &[u8], + initializers: &[ContextInitializer], + pre_handling_initializers: &[ContextPreHandlingInitializer], + world: &mut World, + runtime: &mut RhaiRuntime, +) -> Result { + let mut ast = runtime.compile(std::str::from_utf8(content)?)?; + ast.set_source(script.to_string()); + + let mut context = RhaiScriptContext { + ast, + scope: Scope::new(), + }; + with_world(world, &mut context, |mut context| { + initializers + .iter() + .try_for_each(|init| init(script, context))?; + + pre_handling_initializers + .iter() + .try_for_each(|init| init(script, Entity::from_raw(0), context))?; + + runtime.eval_ast_with_scope(&mut context.scope, &context.ast)?; + // do not invoke top level statements after the first time we run the script + context.ast.clear_statements(); + + Ok(()) + })?; + Ok(context) } -impl ScriptEvent for RhaiEvent { - fn recipients(&self) -> &crate::Recipients { - &self.recipients - } +pub fn rhai_context_reload( + script: &ScriptId, + content: &[u8], + context: &mut RhaiScriptContext, + initializers: &[ContextInitializer], + pre_handling_initializers: &[ContextPreHandlingInitializer], + world: &mut World, + runtime: &mut RhaiRuntime, +) -> Result<(), ScriptError> { + *context = rhai_context_load( + script, + content, + initializers, + pre_handling_initializers, + world, + runtime, + )?; + Ok(()) } -impl ScriptHost for RhaiScriptHost { - type ScriptContext = RhaiContext; - type ScriptEvent = RhaiEvent; - type ScriptAsset = RhaiFile; - type APITarget = Engine; - type DocTarget = RhaiDocFragment; - - fn register_with_app_in_set( - app: &mut bevy::prelude::App, - schedule: impl ScheduleLabel, - set: impl SystemSet, - ) { - app.add_priority_event::() - .init_asset::() - .init_asset_loader::() - .init_resource::>() - .init_resource::>() - .init_resource::>() - .register_type::>() - .register_type::>() - .register_type::>() - .add_systems( - schedule, - ( - script_add_synchronizer::, - script_remove_synchronizer::, - script_hot_reload_handler::, - ) - .chain() - .in_set(set), - ) - // setup engine - .add_systems( - Startup, - |mut providers: ResMut>, mut host: ResMut| { - providers - .attach_all(&mut host.engine) - .expect("Error in adding api's for rhai"); - }, - ); - } +#[allow(clippy::too_many_arguments)] +pub fn rhai_callback_handler( + args: A, + entity: Entity, + script_id: &ScriptId, + callback: &CallbackLabel, + context: &mut RhaiScriptContext, + pre_handling_initializers: &[ContextPreHandlingInitializer], + runtime: &mut RhaiRuntime, + world: &mut World, +) -> Result<(), ScriptError> { + with_world(world, context, |context| { + pre_handling_initializers + .iter() + .try_for_each(|init| init(script_id, entity, context))?; - fn setup_script( - &mut self, - script_data: &ScriptData, - ctx: &mut Self::ScriptContext, - providers: &mut APIProviders, - ) -> Result<(), ScriptError> { - providers.setup_all(script_data, ctx) - } + if context + .scope + .get_value::(callback.as_ref()) + .is_none() + { + // not subscribed to this handler + return Ok(()); + }; - fn load_script( - &mut self, - script: &[u8], - script_data: &ScriptData, - _: &mut APIProviders, - ) -> Result { - let mut scope = Scope::new(); - let mut ast = self - .engine - .compile( - std::str::from_utf8(script).map_err(|e| ScriptError::FailedToLoad { - script: script_data.name.to_owned(), - msg: e.to_string(), - })?, - ) - .map_err(|e| ScriptError::SyntaxError { - script: script_data.name.to_owned(), - msg: e.to_string(), - })?; - - ast.set_source(script_data.name); - - // persistent state for scripts - scope.push("state", Map::new()); - - Ok(RhaiContext { ast, scope }) - } + // we want the call to be able to impact the scope + let options = CallFnOptions::new().rewind_scope(false); + runtime.call_fn_with_options( + options, + &mut context.scope, + &context.ast, + callback.as_ref(), + args, + )?; + Ok(()) + }) +} - fn handle_events<'a>( - &mut self, - world: &mut World, - events: &[Self::ScriptEvent], - ctxs: impl Iterator, &'a mut Self::ScriptContext)>, - providers: &mut APIProviders, - ) { - // safety: - // - we have &mut World access - // - we do not use the original reference again anywhere in this function - let world = unsafe { WorldPointerGuard::new(world) }; - - ctxs.for_each(|(fd, ctx)| { - providers - .setup_runtime_all(world.clone(), &fd, ctx) - .expect("Failed to setup script runtime"); - - for event in events.iter() { - // check if this script should handle this event - if !event.recipients().is_recipient(&fd) { - continue; - }; - - match self.engine.call_fn( - &mut ctx.scope, - &ctx.ast, - &event.hook_name, - event.args.clone(), - ) { - Ok(v) => v, - Err(e) => { - let mut world = world.write(); - let mut state: CachedScriptState = world.remove_resource().unwrap(); - - match *e { - EvalAltResult::ErrorFunctionNotFound(..) => {} - _ => { - let (_, mut error_wrt, _) = state.event_state.get_mut(&mut world); - - let error = ScriptError::RuntimeError { - script: fd.name.to_string(), - msg: e.to_string(), - }; - error!("{}", error); - error_wrt.send(ScriptErrorEvent { error }); - } - } - - world.insert_resource(state); - } - }; - } - - // executing this at the end here means we execute global statements exactly once - // all this method call does is set a variable on the AST to NONE so should not affect performance - ctx.ast.clear_statements(); - }); - } +pub fn with_world Result<(), ScriptError>>( + world: &mut World, + context: &mut RhaiScriptContext, + f: F, +) -> Result<(), ScriptError> { + WorldCallbackAccess::with_callback_access(world, |guard| { + context.scope.push("world", guard.clone()); + f(context) + }) } +// use crate::{ +// assets::{RhaiFile, RhaiLoader}, +// docs::RhaiDocFragment, +// }; +// use bevy::{ecs::schedule::ScheduleLabel, prelude::*}; +// use bevy_mod_scripting_core::{prelude::*, systems::*}; +// use rhai::*; +// use std::marker::PhantomData; + +// pub mod assets; +// pub mod docs; +// pub use rhai; +// pub mod prelude { +// pub use crate::{ +// assets::{RhaiFile, RhaiLoader}, +// docs::RhaiDocFragment, +// RhaiContext, RhaiEvent, RhaiScriptHost, +// }; +// pub use rhai; +// pub use rhai::{RhaiRuntime, FuncArgs}; +// } + +// #[derive(Resource)] +// pub struct RhaiScriptHost { +// pub RhaiRuntime: RhaiRuntime, +// _ph: PhantomData, +// } + +// #[allow(deprecated)] +// impl Default for RhaiScriptHost { +// fn default() -> Self { +// let mut e = RhaiRuntime::new(); +// // prevent shadowing of `state`,`world` and `entity` in variable in scripts +// e.on_def_var(|_, info, _| { +// Ok(info.name() != "state" && info.name() != "world" && info.name() != "entity") +// }); + +// Self { +// RhaiRuntime: e, +// _ph: Default::default(), +// } +// } +// } + +// pub struct RhaiContext { +// pub ast: AST, +// pub scope: Scope<'static>, +// } + +// #[derive(Clone, Event)] +// /// A Rhai Hook. The result of creating this event will be +// /// a call to the lua script with the hook_name and the given arguments +// pub struct RhaiEvent { +// pub hook_name: String, +// pub args: A, +// pub recipients: Recipients, +// } + +// impl ScriptEvent for RhaiEvent { +// fn recipients(&self) -> &crate::Recipients { +// &self.recipients +// } +// } + +// impl ScriptHost for RhaiScriptHost { +// type ScriptContext = RhaiContext; +// type ScriptEvent = RhaiEvent; +// type ScriptAsset = RhaiFile; +// type APITarget = RhaiRuntime; +// type DocTarget = RhaiDocFragment; + +// fn register_with_app_in_set( +// app: &mut bevy::prelude::App, +// schedule: impl ScheduleLabel, +// set: impl SystemSet, +// ) { +// app.add_priority_event::() +// .init_asset::() +// .init_asset_loader::() +// .init_resource::>() +// .init_resource::>() +// .init_resource::>() +// .register_type::>() +// .register_type::>() +// .register_type::>() +// .add_systems( +// schedule, +// ( +// script_add_synchronizer::, +// script_remove_synchronizer::, +// script_hot_reload_handler::, +// ) +// .chain() +// .in_set(set), +// ) +// // setup RhaiRuntime +// .add_systems( +// Startup, +// |mut providers: ResMut>, mut host: ResMut| { +// providers +// .attach_all(&mut host.RhaiRuntime) +// .expect("Error in adding api's for rhai"); +// }, +// ); +// } + +// fn setup_script( +// &mut self, +// script_data: &ScriptData, +// ctx: &mut Self::ScriptContext, +// providers: &mut APIProviders, +// ) -> Result<(), ScriptError> { +// providers.setup_all(script_data, ctx) +// } + +// fn load_script( +// &mut self, +// script: &[u8], +// script_data: &ScriptData, +// _: &mut APIProviders, +// ) -> Result { +// let mut scope = Scope::new(); +// let mut ast = self +// .RhaiRuntime +// .compile( +// std::str::from_utf8(script).map_err(|e| ScriptError::FailedToLoad { +// script: script_data.name.to_owned(), +// msg: e.to_string(), +// })?, +// ) +// .map_err(|e| ScriptError::SyntaxError { +// script: script_data.name.to_owned(), +// msg: e.to_string(), +// })?; + +// ast.set_source(script_data.name); + +// // persistent state for scripts +// scope.push("state", Map::new()); + +// Ok(RhaiContext { ast, scope }) +// } + +// fn handle_events<'a>( +// &mut self, +// world: &mut World, +// events: &[Self::ScriptEvent], +// ctxs: impl Iterator, &'a mut Self::ScriptContext)>, +// _providers: &mut APIProviders, +// ) { +// ctxs.for_each(|(fd, ctx)| { +// for event in events.iter() { +// // check if this script should handle this event +// if !event.recipients().is_recipient(&fd) { +// continue; +// }; + +// match self.RhaiRuntime.call_fn( +// &mut ctx.scope, +// &ctx.ast, +// &event.hook_name, +// event.args.clone(), +// ) { +// Ok(v) => v, +// Err(e) => { +// let mut state: CachedScriptState = world.remove_resource().unwrap(); + +// match *e { +// EvalAltResult::ErrorFunctionNotFound(..) => {} +// _ => { +// let (_, mut error_wrt, _) = state.event_state.get_mut(world); + +// let error = ScriptError::RuntimeError { +// script: fd.name.to_string(), +// msg: e.to_string(), +// }; +// error!("{}", error); +// error_wrt.send(ScriptErrorEvent { error }); +// } +// } + +// world.insert_resource(state); +// } +// }; +// } + +// // executing this at the end here means we execute global statements exactly once +// // all this method call does is set a variable on the AST to NONE so should not affect performance +// ctx.ast.clear_statements(); +// }); +// } +// } diff --git a/crates/languages/bevy_mod_scripting_rune/src/lib.rs b/crates/languages/bevy_mod_scripting_rune/src/lib.rs index 4c7dc0652a..cbcc14d4ac 100644 --- a/crates/languages/bevy_mod_scripting_rune/src/lib.rs +++ b/crates/languages/bevy_mod_scripting_rune/src/lib.rs @@ -1,271 +1,292 @@ -use std::{marker::PhantomData, sync::Arc}; +use std::sync::Arc; -use bevy::prelude::*; -use bevy_mod_scripting_core::{ - prelude::*, - systems::{self, CachedScriptState}, - world::{WorldPointer, WorldPointerGuard}, -}; -use prelude::{RuneDocFragment, RuneFile, RuneLoader}; +use bevy_mod_scripting_core::ScriptingPlugin; use rune::{ - runtime::{Args, RuntimeContext, VmError, VmResult}, - Context, Diagnostics, Source, Sources, Unit, Vm, + runtime::{Args, RuntimeContext}, + Unit, Vm, }; -mod assets; -mod docs; - -pub mod prelude { - pub use crate::{ - assets::{RuneFile, RuneLoader}, - docs::RuneDocFragment, - RuneArgs, RuneEvent, RuneScriptContext, RuneScriptHost, - }; - pub use rune::{self, runtime::Args, Context}; -} - -/// Super trait adding additional bounds to Rune's `Args` trait. -/// It's gets automatically implemented for any type that implments `Args`, -/// so you should never have to manually implement it. -pub trait RuneArgs: Args + Clone + Send + Sync + 'static {} - -impl RuneArgs for T {} - -/// A Rune script hook. -#[derive(Debug, Clone, Event)] -pub struct RuneEvent { - /// The name of the Rune function to call. - pub hook_name: String, - /// The arguments to supply the function being invoked. If you - /// don't need any arguments, `()` is a good default value. - pub args: A, - /// The target set of scripts that should handle this event. - pub recipients: Recipients, -} - -impl ScriptEvent for RuneEvent { - fn recipients(&self) -> &Recipients { - &self.recipients - } -} - -/// A cached Rune Vm used to execute units. -struct RuneVm(Vm); +pub trait RuneEventArg: Args + Clone + Send + Sync + 'static {} +impl RuneEventArg for T {} -impl Default for RuneVm { - fn default() -> Self { - Self(Vm::new( - Arc::new(RuntimeContext::default()), - Arc::new(Unit::default()), - )) - } -} - -/// Script context for a rune script. pub struct RuneScriptContext { pub unit: Arc, pub runtime_context: Arc, } -#[derive(Resource)] -/// Rune script host. Enables Rune scripting. -pub struct RuneScriptHost { - _ph: PhantomData, +pub type RuneRuntime = Vm; + +pub struct RuneScriptingPlugin { + pub scripting_plugin: ScriptingPlugin, } -impl Default for RuneScriptHost { +impl Default for RuneScriptingPlugin { fn default() -> Self { Self { - _ph: Default::default(), + scripting_plugin: ScriptingPlugin { + runtime_builder: todo!(), + runtime_settings: todo!(), + callback_handler: todo!(), + context_builder: todo!(), + context_assigner: todo!(), + }, } } } -impl RuneScriptHost { - /// Helper function to handle errors from a Rune virtual machine. - /// - #[cold] - fn handle_rune_error(world: WorldPointer, error: VmError, script_data: &ScriptData<'_>) { - let mut world = world.write(); - let mut state: CachedScriptState = world.remove_resource().unwrap(); - - let (_, mut error_wrt, _) = state.event_state.get_mut(&mut world); - - let error = ScriptError::RuntimeError { - script: script_data.name.to_owned(), - msg: error.to_string(), - }; - - error!("{}", error); - - error_wrt.send(ScriptErrorEvent { error }); - world.insert_resource(state); - } -} - -impl ScriptHost for RuneScriptHost { - type ScriptContext = RuneScriptContext; - - type ScriptEvent = RuneEvent; - - type ScriptAsset = RuneFile; - - type APITarget = Context; - - type DocTarget = RuneDocFragment; - - fn register_with_app_in_set( - app: &mut App, - schedule: impl bevy::ecs::schedule::ScheduleLabel, - set: impl SystemSet, - ) { - app.add_priority_event::() - .init_asset::() - .init_asset_loader::() - .init_resource::>() - .init_resource::>() - .init_resource::>() - .register_type::>() - .register_type::>() - .register_type::>() - // Add a cached Vm as a non-send resource. - .insert_non_send_resource(RuneVm::default()) - // handle script insertions removal first - // then update their contexts later on script asset changes - .add_systems( - schedule, - ( - systems::script_add_synchronizer::, - systems::script_remove_synchronizer::, - systems::script_hot_reload_handler::, - ) - .chain() - .in_set(set), - ); - } - - fn load_script( - &mut self, - script: &[u8], - script_data: &ScriptData, - providers: &mut APIProviders, - ) -> Result { - let mut context = rune_modules::default_context().map_err(ScriptError::new_other)?; - - // Rune requires that we tell it what modules and types we'll be using before - // it compiles a file. - providers.attach_all(&mut context).unwrap(); - - let mut diagnostics = Diagnostics::new(); - - let mut sources = Sources::new(); - sources - .insert( - Source::new( - script_data.name, - std::str::from_utf8(script).expect("Slice is not UTF-8"), - ) - .map_err(|msg| ScriptError::FailedToLoad { - script: script_data.name.into(), - msg: msg.to_string(), - })?, - ) - .map_err(|msg| ScriptError::FailedToLoad { - script: script_data.name.into(), - msg: msg.to_string(), - })?; - - let result = rune::prepare(&mut sources) - .with_context(&context) - .with_diagnostics(&mut diagnostics) - .build(); - - if !diagnostics.is_empty() { - let mut writer = rune::termcolor::Buffer::no_color(); - - diagnostics - .emit(&mut writer, &sources) - .expect("Failed to write diagnostics to buffer"); - - return Err(ScriptError::SyntaxError { - script: script_data.name.into(), - msg: std::str::from_utf8(writer.as_slice()) - .expect("Slice was not UTF-8") - .to_owned(), - }); - } - - let unit = result.expect("Failed to build Rune unit."); - - let runtime_ctx = context - .runtime() - .expect("Failed to create Rune runtime context."); - - Ok(RuneScriptContext { - unit: Arc::new(unit), - runtime_context: Arc::new(runtime_ctx), - }) - } - - fn setup_script( - &mut self, - script_data: &ScriptData, - ctx: &mut Self::ScriptContext, - providers: &mut APIProviders, - ) -> Result<(), ScriptError> { - providers.setup_all(script_data, ctx) - } - - fn handle_events<'a>( - &mut self, - world: &mut World, - events: &[Self::ScriptEvent], - ctxs: impl Iterator, &'a mut Self::ScriptContext)>, - providers: &mut APIProviders, - ) { - // Grab the cached Vm. - let RuneVm(mut vm) = world.remove_non_send_resource::().unwrap(/* invariant */); - - { - // Safety: - // - we have &mut World access - // - we do not use the original reference again anywhere in this block. - // - the guard is dropped at the end of this block. - let world = unsafe { WorldPointerGuard::new(world) }; - - ctxs.for_each(|(script_data, ctx)| { - providers - .setup_runtime_all(world.clone(), &script_data, ctx) - .expect("Could not setup script runtime"); - - for event in events { - if !event.recipients().is_recipient(&script_data) { - continue; - } - - // Swap out the old context and old unit with the new ones. - *vm.context_mut() = Arc::clone(&ctx.runtime_context); - *vm.unit_mut() = Arc::clone(&ctx.unit); - - let mut exec = match vm.execute([event.hook_name.as_str()], event.args.clone()) - { - Ok(exec) => exec, - Err(error) => { - Self::handle_rune_error(world.clone(), error, &script_data); - continue; - } - }; - - if let VmResult::Err(error) = exec.complete() { - Self::handle_rune_error(world.clone(), error, &script_data); - } - } - }); - - // explictly release the pointer to world. - drop(world); - } - - world.insert_non_send_resource(RuneVm(vm)); - } -} +// use std::{marker::PhantomData, sync::Arc}; + +// use bevy::prelude::*; +// use bevy_mod_scripting_core::{ +// prelude::*, +// systems::{self, CachedScriptState}, +// }; +// use prelude::{RuneDocFragment, RuneFile, RuneLoader}; +// use rune::{ +// runtime::{Args, RuntimeContext, VmError, VmResult}, +// Context, Diagnostics, Source, Sources, Unit, Vm, +// }; + +// mod assets; +// mod docs; + +// pub mod prelude { +// pub use crate::{ +// assets::{RuneFile, RuneLoader}, +// docs::RuneDocFragment, +// RuneArgs, RuneEvent, RuneScriptContext, RuneScriptHost, +// }; +// pub use rune::{self, runtime::Args, Context}; +// } + +// /// Super trait adding additional bounds to Rune's `Args` trait. +// /// It's gets automatically implemented for any type that implments `Args`, +// /// so you should never have to manually implement it. +// pub trait RuneArgs: Args + Clone + Send + Sync + 'static {} + +// impl RuneArgs for T {} + +// /// A Rune script hook. +// #[derive(Debug, Clone, Event)] +// pub struct RuneEvent { +// /// The name of the Rune function to call. +// pub hook_name: String, +// /// The arguments to supply the function being invoked. If you +// /// don't need any arguments, `()` is a good default value. +// pub args: A, +// /// The target set of scripts that should handle this event. +// pub recipients: Recipients, +// } + +// impl ScriptEvent for RuneEvent { +// fn recipients(&self) -> &Recipients { +// &self.recipients +// } +// } + +// /// A cached Rune Vm used to execute units. +// struct RuneVm(Vm); + +// impl Default for RuneVm { +// fn default() -> Self { +// Self(Vm::new( +// Arc::new(RuntimeContext::default()), +// Arc::new(Unit::default()), +// )) +// } +// } + +// /// Script context for a rune script. +// pub struct RuneScriptContext { +// pub unit: Arc, +// pub runtime_context: Arc, +// } + +// #[derive(Resource)] +// /// Rune script host. Enables Rune scripting. +// pub struct RuneScriptHost { +// _ph: PhantomData, +// } + +// impl Default for RuneScriptHost { +// fn default() -> Self { +// Self { +// _ph: Default::default(), +// } +// } +// } + +// impl RuneScriptHost { +// /// Helper function to handle errors from a Rune virtual machine. +// /// +// #[cold] +// fn handle_rune_error(world: &mut World, error: VmError, script_data: &ScriptData<'_>) { +// let mut state: CachedScriptState = world.remove_resource().unwrap(); + +// let (_, mut error_wrt, _) = state.event_state.get_mut(world); + +// let error = ScriptError::RuntimeError { +// script: script_data.name.to_owned(), +// msg: error.to_string(), +// }; + +// error!("{}", error); + +// error_wrt.send(ScriptErrorEvent { error }); +// world.insert_resource(state); +// } +// } + +// impl ScriptHost for RuneScriptHost { +// type ScriptContext = RuneScriptContext; + +// type ScriptEvent = RuneEvent; + +// type ScriptAsset = RuneFile; + +// type APITarget = Context; + +// type DocTarget = RuneDocFragment; + +// fn register_with_app_in_set( +// app: &mut App, +// schedule: impl bevy::ecs::schedule::ScheduleLabel, +// set: impl SystemSet, +// ) { +// app.add_priority_event::() +// .init_asset::() +// .init_asset_loader::() +// .init_resource::>() +// .init_resource::>() +// .init_resource::>() +// .register_type::>() +// .register_type::>() +// .register_type::>() +// // Add a cached Vm as a non-send resource. +// .insert_non_send_resource(RuneVm::default()) +// // handle script insertions removal first +// // then update their contexts later on script asset changes +// .add_systems( +// schedule, +// ( +// systems::script_add_synchronizer::, +// systems::script_remove_synchronizer::, +// systems::script_hot_reload_handler::, +// ) +// .chain() +// .in_set(set), +// ); +// } + +// fn load_script( +// &mut self, +// script: &[u8], +// script_data: &ScriptData, +// providers: &mut APIProviders, +// ) -> Result { +// let mut context = rune_modules::default_context().map_err(ScriptError::new_other)?; + +// // Rune requires that we tell it what modules and types we'll be using before +// // it compiles a file. +// providers.attach_all(&mut context).unwrap(); + +// let mut diagnostics = Diagnostics::new(); + +// let mut sources = Sources::new(); +// sources +// .insert( +// Source::new( +// script_data.name, +// std::str::from_utf8(script).expect("Slice is not UTF-8"), +// ) +// .map_err(|msg| ScriptError::FailedToLoad { +// script: script_data.name.into(), +// msg: msg.to_string(), +// })?, +// ) +// .map_err(|msg| ScriptError::FailedToLoad { +// script: script_data.name.into(), +// msg: msg.to_string(), +// })?; + +// let result = rune::prepare(&mut sources) +// .with_context(&context) +// .with_diagnostics(&mut diagnostics) +// .build(); + +// if !diagnostics.is_empty() { +// let mut writer = rune::termcolor::Buffer::no_color(); + +// diagnostics +// .emit(&mut writer, &sources) +// .expect("Failed to write diagnostics to buffer"); + +// return Err(ScriptError::SyntaxError { +// script: script_data.name.into(), +// msg: std::str::from_utf8(writer.as_slice()) +// .expect("Slice was not UTF-8") +// .to_owned(), +// }); +// } + +// let unit = result.expect("Failed to build Rune unit."); + +// let runtime_ctx = context +// .runtime() +// .expect("Failed to create Rune runtime context."); + +// Ok(RuneScriptContext { +// unit: Arc::new(unit), +// runtime_context: Arc::new(runtime_ctx), +// }) +// } + +// fn setup_script( +// &mut self, +// script_data: &ScriptData, +// ctx: &mut Self::ScriptContext, +// providers: &mut APIProviders, +// ) -> Result<(), ScriptError> { +// providers.setup_all(script_data, ctx) +// } + +// fn handle_events<'a>( +// &mut self, +// world: &mut World, +// events: &[Self::ScriptEvent], +// ctxs: impl Iterator, &'a mut Self::ScriptContext)>, +// _providers: &mut APIProviders, +// ) { +// // Grab the cached Vm. +// let RuneVm(mut vm) = world.remove_non_send_resource::().unwrap(/* invariant */); + +// { +// ctxs.for_each(|(script_data, ctx)| { +// for event in events { +// if !event.recipients().is_recipient(&script_data) { +// continue; +// } + +// // Swap out the old context and old unit with the new ones. +// *vm.context_mut() = Arc::clone(&ctx.runtime_context); +// *vm.unit_mut() = Arc::clone(&ctx.unit); + +// let mut exec = match vm.execute([event.hook_name.as_str()], event.args.clone()) +// { +// Ok(exec) => exec, +// Err(error) => { +// Self::handle_rune_error(world, error, &script_data); +// continue; +// } +// }; + +// if let VmResult::Err(error) = exec.complete() { +// Self::handle_rune_error(world, error, &script_data); +// } +// } +// }); +// } + +// world.insert_non_send_resource(RuneVm(vm)); +// } +// } diff --git a/crates/macro_tests/Cargo.toml b/crates/macro_tests/Cargo.toml index 89eb194ccb..240b0c5eb9 100644 --- a/crates/macro_tests/Cargo.toml +++ b/crates/macro_tests/Cargo.toml @@ -16,11 +16,7 @@ debug = false [dev-dependencies] trybuild = "1.0" bevy = { version = "0.15.0-rc.3", default-features = false } -bevy_mod_scripting = { path = "../../", features = [ - "lua", - "lua_script_api", - "lua54", -] } +bevy_mod_scripting = { path = "../../", features = ["lua", "lua54"] } bevy_script_api = { path = "../bevy_script_api" } bevy_mod_scripting_lua = { path = "../languages/bevy_mod_scripting_lua" } bevy_mod_scripting_core = { path = "../bevy_mod_scripting_core" } diff --git a/examples/lua/event_recipients.rs b/examples/lua/event_recipients.rs index 3a8a75e106..310d50e5b2 100644 --- a/examples/lua/event_recipients.rs +++ b/examples/lua/event_recipients.rs @@ -1,134 +1,72 @@ -use bevy::prelude::*; +use bevy::{app::AppExit, core::FrameCount, prelude::*}; +use bevy_mod_scripting::lua::LuaScriptingPlugin; use bevy_mod_scripting::prelude::*; -use rand::prelude::SliceRandom; -use std::sync::atomic::Ordering::Relaxed; -use std::sync::{atomic::AtomicU32, Mutex}; - -#[derive(Clone)] -pub struct MyLuaArg(usize); - -impl<'lua> IntoLua<'lua> for MyLuaArg { - fn into_lua(self, lua: &'lua Lua) -> mlua::Result> { - self.0.into_lua(lua) - } -} - -#[derive(Default)] -pub struct LuaAPIProvider; - -/// the custom Lua api, world is provided via a global pointer, -/// and callbacks are defined only once at script creation -impl APIProvider for LuaAPIProvider { - type APITarget = Mutex; - type DocTarget = LuaDocFragment; - type ScriptContext = Mutex; - - fn attach_api(&mut self, ctx: &mut Self::APITarget) -> Result<(), ScriptError> { - // callbacks can receive any `ToLuaMulti` arguments, here '()' and - // return any `FromLuaMulti` arguments, here a `usize` - // check the Rlua documentation for more details - - let ctx = ctx.get_mut().unwrap(); - - ctx.globals() - .set( - "print", - ctx.create_function(|_ctx, msg: String| { - info!("{}", msg); - Ok(()) - }) - .map_err(ScriptError::new_other)?, - ) - .map_err(ScriptError::new_other)?; - - Ok(()) - } - - fn setup_script( - &mut self, - script_data: &ScriptData, - ctx: &mut Self::ScriptContext, - ) -> Result<(), ScriptError> { - let ctx = ctx.get_mut().unwrap(); - let globals = ctx.globals(); - globals - .set("script_id", script_data.sid) - .map_err(ScriptError::new_other)?; - Ok(()) - } +use bevy_mod_scripting_core::{ + asset::ScriptAsset, script::ScriptComponent, AddContextPreHandlingInitializer, +}; + +fn load_script( + server: Res, + mut commands: Commands, + mut handle: Local>, +) { + let path = "scripts/event_recipients.lua"; + let handle_ = server.load::(path); + *handle = handle_; + + commands.spawn(ScriptComponent::new(vec![ + "scripts/event_recipients.lua".into() + ])); + commands.spawn(ScriptComponent::new(vec![ + "scripts/event_recipients.lua".into() + ])); } -static COUNTER: AtomicU32 = AtomicU32::new(0); - -/// utility for generating random events from a list -fn fire_random_event(w: &mut PriorityEventWriter>, events: &[ScriptEventData]) { - let mut rng = rand::thread_rng(); - let id = COUNTER.fetch_add(1, Relaxed); - let arg = MyLuaArg(id as usize); - let event = events - .choose(&mut rng) - .map(|v| LuaEvent { - hook_name: v.0.to_string(), - args: arg, - recipients: v.1.clone(), - }) - .unwrap(); - - info!( - "\t - event: {},\t recipients: {:?},\t id: {}", - event.hook_name, event.recipients, id - ); - w.send(event, 0); +fn trigger_script_callback(mut writer: EventWriter>) { + writer.send(ScriptCallbackEvent::new_for_all( + OnEventCallback::into_callback_label(), + 1, + )); + + writer.send(ScriptCallbackEvent::new( + OnEventCallback::into_callback_label(), + 2, + Recipients::Entity(Entity::from_raw(6)), + )); } -fn do_update(mut w: PriorityEventWriter>) { - info!("Update, firing:"); - - let all_events = [ - ScriptEventData("on_event", Recipients::All), - ScriptEventData("on_event", Recipients::ScriptID(0)), - ScriptEventData("on_event", Recipients::ScriptID(1)), - ScriptEventData( - "on_event", - Recipients::ScriptName("scripts/event_recipients.lua".to_owned()), - ), - ]; - - // fire random event, for any of the system sets - fire_random_event(&mut w, &all_events); +fn quit_after_few_frames(mut exit: EventWriter, count: Res) { + if count.0 > 5 { + exit.send(AppExit::Success); + } } -#[derive(Clone)] -pub struct ScriptEventData(&'static str, Recipients); - -fn load_our_scripts(server: Res, mut commands: Commands) { - // spawn two identical scripts - // id's will be 0 and 1 - let path = "scripts/event_recipients.lua"; - let handle = server.load::(path); - let scripts = (0..2) - .map(|_| Script::::new(path.to_string(), handle.clone())) - .collect(); - - commands - .spawn(()) - .insert(ScriptCollection:: { scripts }); +pub struct OnEventCallback; +impl IntoCallbackLabel for OnEventCallback { + fn into_callback_label() -> CallbackLabel { + "on_event".into() + } } fn main() -> std::io::Result<()> { let mut app = App::new(); app.add_plugins(DefaultPlugins) - .add_plugins(ScriptingPlugin) - .add_systems(Startup, load_our_scripts) - // randomly fire events for either all scripts, - // the script with id 0 - // or the script with id 1 - .add_systems(Update, do_update) - .add_script_handler::, 0, 0>(PostUpdate) - .add_script_host::>(PostUpdate) - .add_api_provider::>(Box::new(LuaAPIProvider)); - app.run(); + .add_plugins(LuaScriptingPlugin::::default()) + .add_context_pre_handling_initializer::<()>(|_, e, ctx: &mut Lua| { + ctx.globals().set("entity", format!("{e:?}")).unwrap(); + Ok(()) + }) + .add_systems(Startup, load_script) + .add_systems( + Update, + ( + trigger_script_callback, + event_handler::.after(trigger_script_callback), + quit_after_few_frames, + ), + ) + .run(); Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index 82d53079ed..cb50ebb838 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,21 +7,11 @@ pub mod core { #[cfg(feature = "lua")] pub mod lua { pub use bevy_mod_scripting_lua::*; - - #[cfg(feature = "lua_script_api")] - pub mod api { - pub use bevy_script_api::lua::*; - } } #[cfg(feature = "rhai")] pub mod rhai { pub use bevy_mod_scripting_rhai::*; - - #[cfg(feature = "rhai_script_api")] - pub mod api { - pub use bevy_script_api::rhai::*; - } } #[cfg(feature = "rune")] @@ -29,11 +19,6 @@ pub mod rune { pub use bevy_mod_scripting_rune::*; } -#[cfg(any(feature = "lua_script_api", feature = "rhai_script_api"))] -pub mod api { - pub use bevy_script_api::*; -} - pub mod prelude { pub use bevy_mod_scripting_core::prelude::*; @@ -43,9 +28,6 @@ pub mod prelude { #[cfg(feature = "rhai")] pub use bevy_mod_scripting_rhai::prelude::*; - #[cfg(feature = "rune")] - pub use bevy_mod_scripting_rune::prelude::*; - - #[cfg(any(feature = "lua_script_api", feature = "rhai_script_api"))] - pub use bevy_script_api::prelude::*; + // #[cfg(feature = "rune")] + // pub use bevy_mod_scripting_rune::prelude::*; } From 1f329aad3cfe510861ada5301aab9564a312c58f Mon Sep 17 00:00:00 2001 From: makspll Date: Tue, 19 Nov 2024 20:08:47 +0000 Subject: [PATCH 18/22] update more examples --- assets/scripts/bevy_api.lua | 128 +++++++++++ assets/scripts/coroutines.lua | 3 +- assets/scripts/dynamic_queries.lua | 30 ++- .../src/bindings/reference.rs | 23 +- .../src/bindings/world.rs | 15 ++ .../bevy_mod_scripting_core/src/commands.rs | 13 +- crates/bevy_mod_scripting_core/src/systems.rs | 33 ++- .../src/bindings/reference.rs | 7 +- .../src/bindings/world.rs | 9 + examples/lua/bevy_api.rs | 215 +++--------------- examples/lua/complex_game_loop.rs | 193 ---------------- examples/lua/coroutines.rs | 56 +++-- examples/lua/dynamic_queries.rs | 47 ++-- examples/lua/event_recipients.rs | 16 +- 14 files changed, 324 insertions(+), 464 deletions(-) create mode 100644 assets/scripts/bevy_api.lua delete mode 100644 examples/lua/complex_game_loop.rs diff --git a/assets/scripts/bevy_api.lua b/assets/scripts/bevy_api.lua new file mode 100644 index 0000000000..5a1f0fc8f1 --- /dev/null +++ b/assets/scripts/bevy_api.lua @@ -0,0 +1,128 @@ +function table_to_string(t) + local result = "[" + for k,v in pairs(t) do + result = result .. string.format("%s:%s,",k,v) + end + return result .. "]" +end + + +-- the api provides us with 3 globals +print(entity) +print(script) +print(world) + +-- we first retrieve ID's for our component and resource by their short name (long name/full path also work) +local my_component_type = world:get_type_by_name("MyComponent") + +-- then ask the world to give us a reference to `MyComponent` on the entity we just spawned +-- resources work the same way, but we use `get_resource` instead of `get_component` +-- the comp object is resolved to a `bevy_script_api::script_ref::ReflectValue` which implements UserData. +-- we can use a custom proxy instead (by implementing LuaProxyable), but this is the simplest way to get started. +local comp = world:get_component(entity, my_component_type) +print("Before script: ", comp) + +print("============") + +-- the index metamethod on ReflectValue's uses bevy's reflection mechanism on top of some custom sub-reflection logic to +-- allow reflecting inside Options, Vectors etc. +-- when we index into ReflectValue's we either get back a custom proxy or another ReflectValue + +-- the LuaBevyAPIProvider provides us custom proxies for many bevy types as well as std types. +-- all of these implementations can be overridden via the bevy TypeRegistry +comp.usize = 2 +print("comp.usize after assigning to 2: ", comp.usize) + +-- vec's and matrices have custom __index and __newindex overrides +print("comp.vec2 before: ", comp.vec2) +comp.vec2[1] = 69 +print("comp.vec2 after: ", comp.vec2) + +-- Option's get converted to nil or the value inside +print("comp.option_vec3 before: ", comp.option_vec3) +comp.option_vec3 = Vec3.new(2,1,3) +print("comp.option_vec3 after: ", comp.option_vec3) + +-- reflection via index is indexed starting at 1, unlike in Rust to match Lua's indexing +print("comp.option_vec3[1] before: ", comp.option_vec3[1]) +comp.option_vec3[1] = 5 +print("comp.option_vec3[1] after: ", comp.option_vec3[1]) + +print("============") + +-- Vec references get converted to a custom proxy `LuaVec` which is +-- also assignable via lua tables + +print("comp.vec_of_option_bools before: ", table_to_string(comp.vec_of_option_bools)) +comp.vec_of_option_bools = {true,false,true} +print("comp.vec_of_option_bools after assignment: ", table_to_string(comp.vec_of_option_bools)) + +print("comp.vec_of_option_bools[1] before: ", comp.vec_of_option_bools[1]) +comp.vec_of_option_bools[1] = false +print("comp.vec_of_option_bools[1] after: ", comp.vec_of_option_bools[1]) + +-- there are some additional methods available on LuaVec proxies imitating the Vec api +print("comp.vec_of_option_bools before insert: ", table_to_string(comp.vec_of_option_bools)) +comp.vec_of_option_bools:insert(1,nil) +print("comp.vec_of_option_bools after insert: ", table_to_string(comp.vec_of_option_bools)) + +print("comp.vec_of_option_bools before push: ", table_to_string(comp.vec_of_option_bools)) +comp.vec_of_option_bools:push(false) +print("comp.vec_of_option_bools after push: ", table_to_string(comp.vec_of_option_bools)) + +print("comp.vec_of_option_bools len after push: ", #comp.vec_of_option_bools) + +print("comp.vec_of_option_bools before pop: ", table_to_string(comp.vec_of_option_bools)) +print(comp.vec_of_option_bools:pop()) +print("comp.vec_of_option_bools after pop: ", table_to_string(comp.vec_of_option_bools)) + +print("the pairs inside comp.vec_of_option_bools: ") +for k,v in pairs(comp.vec_of_option_bools) do + print(string.format(" - %s:%s",k,v)) +end + +comp.vec_of_option_bools:clear() +print("comp.vec_of_option_bools after clear: ", table_to_string(comp.vec_of_option_bools)) + +print("comp.vec_of_option_bools len after clear: ", #comp.vec_of_option_bools) +print("============") + +print("comp.option_vec_of_bools before: ", table_to_string(comp.option_vec_of_bools)) +print(comp.option_vec_of_bools:pop()) +print("comp.option_vec_of_bools after pop: ", table_to_string(comp.option_vec_of_bools)) + + +print("comp.option_vec_of_bools len after pop: ", #comp.option_vec_of_bools) + +print("the pairs inside comp.option_vec_of_bools: ") +for k,v in pairs(comp.option_vec_of_bools) do + print(string.format(" - %s:%s",k,v)) +end + +print("============") + +local complex_vec_op = Vec3.new(0,1,0):any_orthonormal_vector() + comp.mat3.x_axis +print("(0,1,0).any_orthonormal_vector() + mat3.x_axis is: ", complex_vec_op) + +local new_mat3 = Mat3.from_cols(Vec3.new(1,0,0),Vec3.new(0,1,0),Vec3.new(0,0,-1)) +print("new_mat3 is:", new_mat3) + +comp.vec2 = comp.vec2 + comp.vec2 +comp.usize = comp.vec2:min_element() +comp.f32 = comp.f32 + comp.f32 + comp.vec2:min_element() +comp.vec2 = Vec2.new(2,1) +comp.quat = Quat.from_xyzw(3,2,1,4) +comp.mat3.x_axis = Vec3.new(69,69,69) + +print("============") + +-- this is an example of something impossible to achieve with plain bevy reflection under the hood +comp.mat3[1][1] = 42 + +-- now let's retrieve these again to see if we actually changed their values permanently +comp = world:get_component(entity,my_component_type) + +print("After script:") +print(comp) + +world:exit() \ No newline at end of file diff --git a/assets/scripts/coroutines.lua b/assets/scripts/coroutines.lua index 8fec50daca..941e25cab9 100644 --- a/assets/scripts/coroutines.lua +++ b/assets/scripts/coroutines.lua @@ -1,7 +1,6 @@ local my_routine; function on_update() - if my_routine == nil then my_routine = coroutine.create(function() local starttime = os.time() @@ -18,7 +17,7 @@ function on_update() coroutine.resume(my_routine) else print("Couroutine has finished, no longer running") + world:exit() end end - end diff --git a/assets/scripts/dynamic_queries.lua b/assets/scripts/dynamic_queries.lua index 8128df28f8..92b217d110 100644 --- a/assets/scripts/dynamic_queries.lua +++ b/assets/scripts/dynamic_queries.lua @@ -1,9 +1,23 @@ -function on_event() - local component_a = world:get_type_by_name("ComponentA") - local component_b = world:get_type_by_name("ComponentB") - local component_c = world:get_type_by_name("ComponentC") - - for entity, _ in world:query(component_a):with(component_b):without(component_c):iter() do - print(entity) - end +local component_a = world:get_type_by_name("ComponentA") +local component_b = world:get_type_by_name("ComponentB") +local component_c = world:get_type_by_name("ComponentC") + +print("Querying for entities with component_a and without component_c") +for entity, c in world:query(component_a):without(component_c):iter() do + print("Entity with index: " .. entity:index() .. " component: " .. tostring(c)) +end + +print("Querying for entities with component_b and without component_a") +for entity, c in world:query(component_b):without(component_a):iter() do + print("Entity with index: " .. entity:index() .. " component: " .. tostring(c)) end + +print("Querying for all components at once") +for entity, c1,c2,c3 in world:query(component_a, component_b, component_c):iter() do + print("Entity with index: " .. entity:index()) + print("\tComponentA: " .. tostring(c1)) + print("\tComponentB: " .. tostring(c2)) + print("\tComponentC: " .. tostring(c3)) +end + +world:exit() \ No newline at end of file diff --git a/crates/bevy_mod_scripting_core/src/bindings/reference.rs b/crates/bevy_mod_scripting_core/src/bindings/reference.rs index eaaf44e7ec..b0ad73756b 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/reference.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/reference.rs @@ -57,9 +57,16 @@ pub struct ReflectReference { } - impl ReflectReference { + pub fn print_with_world(&self, world: &WorldAccessGuard) -> String { + let base = world.with_resource(|_, type_registry: Mut| { + self.base.display_with_type_name(&type_registry.read()) + }); + + format!("Reference(base: {}, path: {:?})", base, self.reflect_path) + } + /// If this is a reference to something with a length accessible via reflection, returns that length. pub fn len(&self, world: &WorldAccessGuard) -> Option { world.with_resource(|world, type_registry: Mut| { @@ -371,11 +378,15 @@ impl ReflectBaseType { } pub fn display_with_type_name(&self, type_registry: &TypeRegistry) -> String { - format!( - "ReflectBase({}, {:?})", - Self::type_name(self.type_id, type_registry), - self.base_id - ) + let type_name = Self::type_name(self.type_id, type_registry); + + let kind = match self.base_id { + ReflectBase::Component(entity, _) => "Component", + ReflectBase::Resource(_) => "Resource", + ReflectBase::Owned(id) => "Allocation", + }; + + format!("{}({})", kind, type_name) } } diff --git a/crates/bevy_mod_scripting_core/src/bindings/world.rs b/crates/bevy_mod_scripting_core/src/bindings/world.rs index 63f42b520e..d5b9a2f27b 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/world.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/world.rs @@ -18,6 +18,7 @@ use std::{ }; use bevy::{ + app::AppExit, ecs::{ component::{Component, ComponentId}, entity::Entity, @@ -234,6 +235,11 @@ impl WorldCallbackAccess { let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); world.despawn_descendants(entity) } + + pub fn exit(&self) { + let world = self.read().unwrap_or_else(|| panic!("{STALE_WORLD_MSG}")); + world.exit() + } } /// Unit of world access @@ -973,6 +979,15 @@ impl<'w> WorldAccessGuard<'w> { Ok(()) } + + /// Sends AppExit event to the world with success status + pub fn exit(&self) { + if let Some(world) = self.get_whole_world_access() { + world.send_event(AppExit::Success); + } else { + panic!("{CONCURRENT_WORLD_ACCESS_MSG}") + } + } } /// Having this is permission to access the contained [`ReflectAccessId`], there is no way to access anything safely through a [`WorldAccessGuard`] diff --git a/crates/bevy_mod_scripting_core/src/commands.rs b/crates/bevy_mod_scripting_core/src/commands.rs index ddefeee03a..2c5367b403 100644 --- a/crates/bevy_mod_scripting_core/src/commands.rs +++ b/crates/bevy_mod_scripting_core/src/commands.rs @@ -1,4 +1,4 @@ -use std::marker::PhantomData; +use std::{any::type_name, marker::PhantomData}; use bevy::{asset::Handle, ecs::world::Mut, log::debug, prelude::Command}; @@ -7,6 +7,7 @@ use crate::{ context::{Context, ContextLoadingSettings, ScriptContexts}, prelude::{Runtime, RuntimeContainer}, script::{Script, ScriptId, Scripts}, + systems::handle_script_errors, }; pub struct DeleteScript { @@ -111,8 +112,14 @@ impl Command for CreateOrUpdateScript { let current_context_id = if let Some(id) = current_context_id { id } else { - let ctxt = (builder.load)(&self.id, &self.content, &settings.context_initializers, &settings.context_pre_handling_initializers, world, &mut runtime.runtime).unwrap(); - contexts.insert(ctxt) + let ctxt = (builder.load)(&self.id, &self.content, &settings.context_initializers, &settings.context_pre_handling_initializers, world, &mut runtime.runtime); + match ctxt { + Ok(ctxt) => contexts.insert(ctxt), + Err(e) => { + handle_script_errors(world, &format!("Failed to load context for script with id: {}. With runtime type: {} and context type: {}", self.id, type_name::(), type_name::()), [e]); + return; + } + } }; if let Some(previous) = previous_context_id { diff --git a/crates/bevy_mod_scripting_core/src/systems.rs b/crates/bevy_mod_scripting_core/src/systems.rs index cf38c001e2..ae52b80653 100644 --- a/crates/bevy_mod_scripting_core/src/systems.rs +++ b/crates/bevy_mod_scripting_core/src/systems.rs @@ -6,6 +6,7 @@ use crate::{ bindings::ReflectAllocator, commands::{CreateOrUpdateScript, DeleteScript}, context::{Context, ContextLoadingSettings, ScriptContexts}, + error::{ScriptError, ScriptResult}, event::{IntoCallbackLabel, ScriptCallbackEvent, ScriptErrorEvent}, handler::{Args, CallbackSettings}, prelude::RuntimeSettings, @@ -181,18 +182,30 @@ pub fn event_handler( world.insert_non_send_resource(runtime_container); world.insert_non_send_resource(script_contexts); - for error in errors { - let mut error_events = world - .get_resource_mut::>() - .expect("Missing events resource"); - - bevy::log::error!( - "Encountered error in event handling for - Runtime {}, Context: {}, Args: {}. {}", + handle_script_errors( + world, + &format!( + "Encountered error in event handling for: Runtime {}, Context: {}, Args: {}", type_name::(), type_name::(), - type_name::(), - error.to_string() - ); + type_name::() + ), + errors, + ); +} + +/// Handles errors caused by script execution and sends them to the error event channel +pub(crate) fn handle_script_errors>( + world: &mut World, + context: &str, + errors: I, +) { + let mut error_events = world + .get_resource_mut::>() + .expect("Missing events resource"); + + for error in errors { + bevy::log::error!("{}. {}", context, error.to_string()); error_events.send(ScriptErrorEvent { error }); } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs index 7a7386b3c0..619f0e6760 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs @@ -224,7 +224,12 @@ impl TealData for LuaReflectReference { m.add_meta_function(MetaMethod::Len, |l, self_: LuaReflectReference| { self_.len(l) - }) + }); + + m.add_meta_function(MetaMethod::ToString, |lua, self_: LuaReflectReference| { + let world = lua.get_world()?; + Ok(self_.0.print_with_world(&world)) + }); } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs index 3c143a5f0d..4c954d86f9 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs @@ -396,6 +396,15 @@ impl TealData for LuaWorld { Ok(builder) }, ); + + methods.add_method("exit", |_, this, ()| { + // TODO: somehow end control flow on lua side + let world = this.0.read().ok_or_else(|| { + mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) + })?; + world.exit(); + Ok(()) + }); } fn add_fields<'lua, F: tealr::mlu::TealDataFields<'lua, Self>>(_fields: &mut F) {} diff --git a/examples/lua/bevy_api.rs b/examples/lua/bevy_api.rs index 493bec50b4..0177101cb8 100644 --- a/examples/lua/bevy_api.rs +++ b/examples/lua/bevy_api.rs @@ -1,9 +1,10 @@ +use asset::ScriptAsset; use bevy::app::AppExit; - use bevy::prelude::*; +use bevy_mod_scripting::lua::LuaScriptingPlugin; use bevy_mod_scripting::prelude::*; - -use bevy_script_api::lua::RegisterForeignLuaType; +use bevy_mod_scripting_lua::bindings::providers::LuaBevyScriptingPlugin; +use script::ScriptComponent; #[derive(Component, Default, Reflect)] #[reflect(Component)] @@ -18,188 +19,44 @@ pub struct MyComponent { option_vec_of_bools: Option>, } +fn load_script( + server: Res, + mut commands: Commands, + mut handle: Local>, +) { + let path = "scripts/bevy_api.lua"; + let handle_ = server.load::(path); + *handle = handle_; + + commands.spawn(ScriptComponent::new(vec![path.into()])); +} + +fn init_data(mut commands: Commands) { + commands.spawn(MyComponent { + usize: 5, + vec2: Vec2::new(1.0, 2.0), + f32: 6.7, + mat3: Mat3::from_cols( + Vec3::new(1.0, 2.0, 3.0), + Vec3::new(4.0, 5.0, 6.0), + Vec3::new(7.0, 8.0, 9.0), + ), + quat: Quat::from_xyzw(1.0, 2.0, 3.0, 4.0), + option_vec3: None, + vec_of_option_bools: vec![Some(true), None, Some(false)], + option_vec_of_bools: Some(vec![true, true, true]), + }); +} + fn main() -> std::io::Result<()> { let mut app = App::new(); app.add_plugins(DefaultPlugins) - .add_plugins(ScriptingPlugin) + .add_plugins(LuaScriptingPlugin::<()>::default()) + .add_plugins(LuaBevyScriptingPlugin) .register_type::() // note the implementation for Option is there, but we must register `LuaProxyable` for it - .register_foreign_lua_type::>() - .register_foreign_lua_type::>>() - .register_foreign_lua_type::>() - .register_foreign_lua_type::>>() - .add_script_host::>(PostUpdate) - .add_api_provider::>(Box::new(LuaBevyAPIProvider)) - .add_api_provider::>(Box::new(LuaCoreBevyAPIProvider)) - .add_systems(Startup, - |world: &mut World| { - - let entity = world.spawn(()) - .insert(MyComponent { - usize: 5, - vec2: Vec2::new(1.0, 2.0), - f32: 6.7, - mat3: Mat3::from_cols( - Vec3::new(1.0, 2.0, 3.0), - Vec3::new(4.0, 5.0, 6.0), - Vec3::new(7.0, 8.0, 9.0), - ), - quat: Quat::from_xyzw(1.0, 2.0, 3.0, 4.0), - option_vec3: None, - vec_of_option_bools: vec![Some(true), None, Some(false)], - option_vec_of_bools: Some(vec![true, true, true]), - }).id(); - - // run script - world.resource_scope(|world, mut host: Mut>| { - host.run_one_shot( - r#" - function table_to_string(t) - local result = "[" - for k,v in pairs(t) do - result = result .. string.format("%s:%s,",k,v) - end - return result .. "]" - end - - function once() - - -- the api provides us with 3 globals - print(entity) - print(script) - print(world) - - -- we first retrieve ID's for our component and resource by their short name (long name/full path also work) - local my_component_type = world:get_type_by_name("MyComponent") - - -- then ask the world to give us a reference to `MyComponent` on the entity we just spawned - -- resources work the same way, but we use `get_resource` instead of `get_component` - -- the comp object is resolved to a `bevy_script_api::script_ref::ReflectValue` which implements UserData. - -- we can use a custom proxy instead (by implementing LuaProxyable), but this is the simplest way to get started. - local comp = world:get_component(entity, my_component_type) - print("Before script: ", comp) - - print("============") - - -- the index metamethod on ReflectValue's uses bevy's reflection mechanism on top of some custom sub-reflection logic to - -- allow reflecting inside Options, Vectors etc. - -- when we index into ReflectValue's we either get back a custom proxy or another ReflectValue - - -- the LuaBevyAPIProvider provides us custom proxies for many bevy types as well as std types. - -- all of these implementations can be overridden via the bevy TypeRegistry - comp.usize = 2 - print("comp.usize after assigning to 2: ", comp.usize) - - -- vec's and matrices have custom __index and __newindex overrides - print("comp.vec2 before: ", comp.vec2) - comp.vec2[1] = 69 - print("comp.vec2 after: ", comp.vec2) - - -- Option's get converted to nil or the value inside - print("comp.option_vec3 before: ", comp.option_vec3) - comp.option_vec3 = Vec3.new(2,1,3) - print("comp.option_vec3 after: ", comp.option_vec3) - - -- reflection via index is indexed starting at 1, unlike in Rust to match Lua's indexing - print("comp.option_vec3[1] before: ", comp.option_vec3[1]) - comp.option_vec3[1] = 5 - print("comp.option_vec3[1] after: ", comp.option_vec3[1]) - - print("============") - - -- Vec references get converted to a custom proxy `LuaVec` which is - -- also assignable via lua tables - - print("comp.vec_of_option_bools before: ", table_to_string(comp.vec_of_option_bools)) - comp.vec_of_option_bools = {true,false,true} - print("comp.vec_of_option_bools after assignment: ", table_to_string(comp.vec_of_option_bools)) - - print("comp.vec_of_option_bools[1] before: ", comp.vec_of_option_bools[1]) - comp.vec_of_option_bools[1] = false - print("comp.vec_of_option_bools[1] after: ", comp.vec_of_option_bools[1]) - - -- there are some additional methods available on LuaVec proxies imitating the Vec api - print("comp.vec_of_option_bools before insert: ", table_to_string(comp.vec_of_option_bools)) - comp.vec_of_option_bools:insert(1,nil) - print("comp.vec_of_option_bools after insert: ", table_to_string(comp.vec_of_option_bools)) - - print("comp.vec_of_option_bools before push: ", table_to_string(comp.vec_of_option_bools)) - comp.vec_of_option_bools:push(false) - print("comp.vec_of_option_bools after push: ", table_to_string(comp.vec_of_option_bools)) - - print("comp.vec_of_option_bools len after push: ", #comp.vec_of_option_bools) - - print("comp.vec_of_option_bools before pop: ", table_to_string(comp.vec_of_option_bools)) - print(comp.vec_of_option_bools:pop()) - print("comp.vec_of_option_bools after pop: ", table_to_string(comp.vec_of_option_bools)) - - print("the pairs inside comp.vec_of_option_bools: ") - for k,v in pairs(comp.vec_of_option_bools) do - print(string.format(" - %s:%s",k,v)) - end - - comp.vec_of_option_bools:clear() - print("comp.vec_of_option_bools after clear: ", table_to_string(comp.vec_of_option_bools)) - - print("comp.vec_of_option_bools len after clear: ", #comp.vec_of_option_bools) - print("============") - - print("comp.option_vec_of_bools before: ", table_to_string(comp.option_vec_of_bools)) - print(comp.option_vec_of_bools:pop()) - print("comp.option_vec_of_bools after pop: ", table_to_string(comp.option_vec_of_bools)) - - - print("comp.option_vec_of_bools len after pop: ", #comp.option_vec_of_bools) - - print("the pairs inside comp.option_vec_of_bools: ") - for k,v in pairs(comp.option_vec_of_bools) do - print(string.format(" - %s:%s",k,v)) - end - - print("============") - - local complex_vec_op = Vec3.new(0,1,0):any_orthonormal_vector() + comp.mat3.x_axis - print("(0,1,0).any_orthonormal_vector() + mat3.x_axis is: ", complex_vec_op) - - local new_mat3 = Mat3.from_cols(Vec3.new(1,0,0),Vec3.new(0,1,0),Vec3.new(0,0,-1)) - print("new_mat3 is:", new_mat3) - - comp.vec2 = comp.vec2 + comp.vec2 - comp.usize = comp.vec2:min_element() - comp.f32 = comp.f32 + comp.f32 + comp.vec2:min_element() - comp.vec2 = Vec2.new(2,1) - comp.quat = Quat.from_xyzw(3,2,1,4) - comp.mat3.x_axis = Vec3.new(69,69,69) - - print("============") - - -- this is an example of something impossible to achieve with plain bevy reflection under the hood - comp.mat3[1][1] = 42 - - -- now let's retrieve these again to see if we actually changed their values permanently - comp = world:get_component(entity,my_component_type) - - print("After script:") - print(comp) - end - "# - .as_bytes(), - "script.lua", - entity, - world, - LuaEvent { - hook_name: "once".to_owned(), - args: (), - recipients: Recipients::All, - }, - ) - .expect("Something went wrong in the script!"); - }); - - world.send_event(AppExit::Success); - }, - ); + .add_systems(Startup, (init_data, load_script)); app.run(); diff --git a/examples/lua/complex_game_loop.rs b/examples/lua/complex_game_loop.rs deleted file mode 100644 index 55efa6573a..0000000000 --- a/examples/lua/complex_game_loop.rs +++ /dev/null @@ -1,193 +0,0 @@ -use bevy::core::FrameCount; -use bevy::ecs::schedule::ScheduleLabel; -use bevy::prelude::*; -use bevy_mod_scripting::prelude::*; -use rand::prelude::SliceRandom; -use std::sync::atomic::AtomicU32; -use std::sync::atomic::Ordering::Relaxed; - -#[derive(Clone)] -/// The type we will be using to send data to Lua -pub struct MyLuaArg(usize); - -impl<'lua> IntoLua<'lua> for MyLuaArg { - fn into_lua(self, lua: &'lua Lua) -> mlua::Result> { - self.0.into_lua(lua) - } -} - -/// Used to assign events unique ids -static COUNTER: AtomicU32 = AtomicU32::new(0); - -/// The event firing logic we will use at the each stage of the game loop -/// Fires a random event from the pool of all events i.e. one of: -/// - on_pre_physics, priority: 0 -/// - on_post_physics, priority: 11 -/// - on_pre_physics, priority: 21 -fn fire_random_event(w: &mut PriorityEventWriter>>) { - let mut rng = rand::thread_rng(); - let id = COUNTER.fetch_add(1, Relaxed); - let arg = MyLuaArg(id as usize); - let (event, prio) = [ - ("on_pre_physics", 0), - ("on_post_physics", 11), - ("on_post_update", 21), - ] - .choose(&mut rng) - .map(|v| { - let mut args = mlua::Variadic::new(); - args.push(arg); - ( - LuaEvent { - hook_name: v.0.to_string(), - args, - recipients: Recipients::All, - }, - v.1, - ) - }) - .unwrap(); - - info!( - "\t - event: {},\t prio: {},\t id: {}", - event.hook_name, prio, id - ); - w.send(event, prio); -} - -/// physics stage logic, represents a bunch of systems sending events of various types and priorities -fn do_physics(mut w: PriorityEventWriter>>) { - info!("Physics, firing:"); - - for _ in 0..5 { - fire_random_event(&mut w); - } -} - -/// update stage logic, fired each frame, represents a bunch of systems sending events of various types and priorities -/// we fire just one since we want to keep the output clean -fn do_update(mut w: PriorityEventWriter>>) { - info!("Update, firing:"); - - fire_random_event(&mut w); -} - -/// We will run this system at the end of each update to make the output easier to read -fn print_frame_count(frame: Res) { - info!("================ Frame no {} End ================", frame.0); -} - -fn load_our_script(server: Res, mut commands: Commands) { - let path = "scripts/complex_game_loop.lua"; - let handle = server.load::(path); - - commands.spawn(()).insert(ScriptCollection:: { - scripts: vec![Script::::new(path.to_string(), handle)], - }); -} - -#[derive(ScheduleLabel, Debug, Clone, PartialEq, Eq, Hash, SystemSet)] -enum ComplexGameLoopSet { - Physics, - PrePhysicsScripts, - PostPhysicsScripts, - PostUpdateScripts, - EndFrame, -} - -fn main() -> std::io::Result<()> { - const TIMESTEP_2_PER_SECOND: f64 = 30.0 / 60.0; - - let mut app = App::new(); - - // first let's configure the set orders: - // we run the pre-physics scripts before physics (duh) - // we run the post-physics scripts after physics - // we run the post-update scripts after post-update - // pretty straightforward, note we use FixedUpdate for physics, which means it runs less often than Update - app.add_plugins(DefaultPlugins) - .insert_resource(Time::::from_seconds(TIMESTEP_2_PER_SECOND)) - .add_plugins(ScriptingPlugin) - .add_systems(Startup, load_our_script) - .configure_sets( - FixedUpdate, - ComplexGameLoopSet::PrePhysicsScripts.before(ComplexGameLoopSet::Physics), - ) - .configure_sets( - FixedUpdate, - ComplexGameLoopSet::PostPhysicsScripts.after(ComplexGameLoopSet::Physics), - ) - .configure_sets( - PostUpdate, - ComplexGameLoopSet::EndFrame.after(ComplexGameLoopSet::PostUpdateScripts), - ); - - // Now let's configure our game's main logic/engine systems - app.add_systems(FixedUpdate, do_physics.in_set(ComplexGameLoopSet::Physics)) - // main update logic system set (every frame) - .add_systems(Update, do_update) - .add_systems( - PostUpdate, - print_frame_count.in_set(ComplexGameLoopSet::EndFrame), - ); - - // Finally let's configure the scripting systems. - // Think of the priority value of events as their "order" - // Events with priority "1" go before events of priority "2" - app - // --- script handler system sets - // pre_physics, event priority: [0,10] inclusive - // handlers always ignore the events of lower priority than their range - // meaning this one will only handle pre_physics events - .add_script_handler_to_set::>, 0, 10>( - FixedUpdate, - ComplexGameLoopSet::PrePhysicsScripts, - ) - // post_physics, event priority: [11,20] inclusive - // This handler one will only ever handle post_physics events, - // events of higher priority [0-11] are discarded completely - // (the logic being: if we are at a point in time where we are handling post_physics events, we don't care about pre_physics events) - .add_script_handler_to_set::>, 11, 20>( - FixedUpdate, - ComplexGameLoopSet::PostPhysicsScripts, - ) - // post_update, priority: [21,30] inclusive - // similar to before, only post_update events are handled - .add_script_handler_to_set::>, 21, 30>( - PostUpdate, - ComplexGameLoopSet::PostUpdateScripts, - ) - // finally we add core script host systems to PostUpdate - // these handle the scripts themselves i.e. add/remove/modify them when necessary - .add_script_host_to_set::>>( - PostUpdate, - ComplexGameLoopSet::PostUpdateScripts, - ); - // We have 2 core systems - - // Physics (twice per second), fires 5 random events - // Update (every frame), fires 1 random event - - // and 3 event handlers - - // pre_physics (twice per second) - // post_physics (twice per second) - // post_update (every frame) - - // each of those spawns a single random event from the pool of all events - // when a handler encounters an event of higher priority outside its range, that event is discarded - // when a handler encounters an event of lower priority outside its range, it's left in the queue - // therefore - // in our case, Physics systems can generate events which can be handled by post_update, - // but Update cannot send events which are handled by anything other than post_update - - // note that regardless of the order in which the events were spawned - // priority decides the order in which they are executed - // in case of identical priority, order is the tie-breaker (earlier events launch first) - - // interestingly, because the Main bevy scheduler runs FixedUpdate systems *before* any Update systems, in this case - // on_pre_physics events will *never* be handled! (they are discarded by the post_physics handler, and the update system never runs before physics) - app.run(); - - Ok(()) -} diff --git a/examples/lua/coroutines.rs b/examples/lua/coroutines.rs index 2285984a6d..9c41bb56a7 100644 --- a/examples/lua/coroutines.rs +++ b/examples/lua/coroutines.rs @@ -1,39 +1,49 @@ +use asset::ScriptAsset; use bevy::prelude::*; +use bevy_mod_scripting::lua::LuaScriptingPlugin; use bevy_mod_scripting::prelude::*; +use script::ScriptComponent; -/// fire on_update -fn do_update(mut w: PriorityEventWriter>) { - let event = LuaEvent { - hook_name: "on_update".to_owned(), - args: (), - recipients: Recipients::All, - }; - - w.send(event, 0); +struct OnEventCallback; +impl IntoCallbackLabel for OnEventCallback { + fn into_callback_label() -> CallbackLabel { + "on_update".into() + } } -fn load_our_scripts(server: Res, mut commands: Commands) { +fn load_script( + server: Res, + mut commands: Commands, + mut handle: Local>, +) { let path = "scripts/coroutines.lua"; - let handle = server.load::(path); - let script = Script::::new(path.to_string(), handle); + let handle_ = server.load::(path); + *handle = handle_; + + commands.spawn(ScriptComponent::new(vec![path.into()])); +} - commands.spawn(()).insert(ScriptCollection:: { - scripts: vec![script], - }); +fn send_event(mut writer: EventWriter>) { + writer.send(ScriptCallbackEvent::new_for_all( + OnEventCallback::into_callback_label(), + (), + )); } fn main() -> std::io::Result<()> { let mut app = App::new(); app.add_plugins(DefaultPlugins) - .add_plugins(ScriptingPlugin) - .add_systems(Startup, load_our_scripts) - // randomly fire events for either all scripts, - // the script with id 0 - // or the script with id 1 - .add_systems(Update, do_update) - .add_script_handler::, 0, 0>(PostUpdate) - .add_script_host::>(PostUpdate); + .add_plugins(LuaScriptingPlugin::<()>::default()) + .add_systems(Startup, load_script) + .add_systems( + Update, + ( + send_event, + event_handler::.after(send_event), + ), + ); + app.run(); Ok(()) diff --git a/examples/lua/dynamic_queries.rs b/examples/lua/dynamic_queries.rs index 9a07eb646d..d2e89aac31 100644 --- a/examples/lua/dynamic_queries.rs +++ b/examples/lua/dynamic_queries.rs @@ -1,5 +1,8 @@ -use bevy::prelude::*; +use asset::ScriptAsset; +use bevy::{core::FrameCount, prelude::*}; use bevy_mod_scripting::prelude::*; +use bevy_mod_scripting_lua::{bindings::providers::LuaBevyScriptingPlugin, LuaScriptingPlugin}; +use script::ScriptComponent; #[derive(Component, Reflect)] #[reflect(Component)] @@ -13,22 +16,32 @@ pub struct ComponentB; #[reflect(Component)] pub struct ComponentC; +fn load_script( + server: Res, + mut commands: Commands, + mut handle: Local>, +) { + let path = "scripts/dynamic_queries.lua"; + let handle_ = server.load::(path); + *handle = handle_; + + commands.spawn(ScriptComponent::new(vec![path.into()])); +} + fn main() { let mut app = App::new(); - app.add_plugins((DefaultPlugins, ScriptingPlugin)) + app.add_plugins(DefaultPlugins); + app.add_plugins(LuaScriptingPlugin::<()>::default()); + app.add_plugins(LuaBevyScriptingPlugin) .register_type::() .register_type::() .register_type::() - .add_script_host::>(PostUpdate) - .add_script_handler::, 0, 0>(PostUpdate) - .add_api_provider::>(Box::new(LuaBevyAPIProvider)) - .add_api_provider::>(Box::new(LuaCoreBevyAPIProvider)) - .add_systems(Startup, (setup, apply_deferred, run).chain()) + .add_systems(Startup, (setup, load_script)) .run(); } -fn setup(mut commands: Commands, asset_server: Res) { +fn setup(mut commands: Commands) { commands.spawn((ComponentA,)); commands.spawn((ComponentA, ComponentB)); commands.spawn((ComponentA, ComponentC)); @@ -43,22 +56,4 @@ fn setup(mut commands: Commands, asset_server: Res) { commands.spawn((ComponentC, ComponentA)); commands.spawn((ComponentC, ComponentB)); commands.spawn((ComponentC, ComponentA, ComponentB)); - - let path = "scripts/dynamic_queries.lua"; - let handle = asset_server.load(path); - - commands.spawn(ScriptCollection:: { - scripts: vec![Script::new(path.into(), handle)], - }); -} - -fn run(mut events: PriorityEventWriter>) { - events.send( - LuaEvent { - hook_name: "on_event".into(), - args: (), - recipients: Recipients::All, - }, - 0, - ); } diff --git a/examples/lua/event_recipients.rs b/examples/lua/event_recipients.rs index 310d50e5b2..861b88381b 100644 --- a/examples/lua/event_recipients.rs +++ b/examples/lua/event_recipients.rs @@ -1,9 +1,7 @@ use bevy::{app::AppExit, core::FrameCount, prelude::*}; use bevy_mod_scripting::lua::LuaScriptingPlugin; use bevy_mod_scripting::prelude::*; -use bevy_mod_scripting_core::{ - asset::ScriptAsset, script::ScriptComponent, AddContextPreHandlingInitializer, -}; +use bevy_mod_scripting_core::{asset::ScriptAsset, script::ScriptComponent}; fn load_script( server: Res, @@ -14,12 +12,8 @@ fn load_script( let handle_ = server.load::(path); *handle = handle_; - commands.spawn(ScriptComponent::new(vec![ - "scripts/event_recipients.lua".into() - ])); - commands.spawn(ScriptComponent::new(vec![ - "scripts/event_recipients.lua".into() - ])); + commands.spawn(ScriptComponent::new(vec![path.into()])); + commands.spawn(ScriptComponent::new(vec![path.into()])); } fn trigger_script_callback(mut writer: EventWriter>) { @@ -53,10 +47,6 @@ fn main() -> std::io::Result<()> { app.add_plugins(DefaultPlugins) .add_plugins(LuaScriptingPlugin::::default()) - .add_context_pre_handling_initializer::<()>(|_, e, ctx: &mut Lua| { - ctx.globals().set("entity", format!("{e:?}")).unwrap(); - Ok(()) - }) .add_systems(Startup, load_script) .add_systems( Update, From d1f37a86791449519cfb39535d2f623d4f5dcbdf Mon Sep 17 00:00:00 2001 From: makspll Date: Sun, 24 Nov 2024 17:32:49 +0000 Subject: [PATCH 19/22] register option lua types for ALL THE TYPES BABY --- assets/scripts/bevy_api.lua | 221 +++--- crates/bevy_api_gen/templates/header.tera | 4 +- .../src/bindings/allocator.rs | 34 +- .../src/bindings/reference.rs | 29 +- .../src/bindings/world.rs | 15 + crates/bevy_mod_scripting_core/src/lib.rs | 1 + .../src/reflection_extensions.rs | 112 +++ crates/bevy_mod_scripting_core/src/systems.rs | 14 +- .../src/bindings/providers/bevy_a11y.rs | 2 +- .../src/bindings/providers/bevy_core.rs | 2 +- .../src/bindings/providers/bevy_ecs.rs | 2 +- .../src/bindings/providers/bevy_hierarchy.rs | 2 +- .../src/bindings/providers/bevy_input.rs | 2 +- .../src/bindings/providers/bevy_math.rs | 2 +- .../src/bindings/providers/bevy_reflect.rs | 2 +- .../src/bindings/providers/bevy_time.rs | 2 +- .../src/bindings/providers/bevy_transform.rs | 2 +- .../src/bindings/providers/bevy_window.rs | 2 +- .../src/bindings/reference.rs | 55 +- .../bevy_mod_scripting_lua/src/lib.rs | 125 +--- .../bevy_mod_scripting_lua/src/type_data.rs | 665 ++++++++++++++++++ examples/lua/bevy_api.rs | 72 +- 22 files changed, 1093 insertions(+), 274 deletions(-) create mode 100644 crates/bevy_mod_scripting_core/src/reflection_extensions.rs create mode 100644 crates/languages/bevy_mod_scripting_lua/src/type_data.rs diff --git a/assets/scripts/bevy_api.lua b/assets/scripts/bevy_api.lua index 5a1f0fc8f1..cefd120e61 100644 --- a/assets/scripts/bevy_api.lua +++ b/assets/scripts/bevy_api.lua @@ -7,122 +7,135 @@ function table_to_string(t) end --- the api provides us with 3 globals -print(entity) -print(script) -print(world) - --- we first retrieve ID's for our component and resource by their short name (long name/full path also work) -local my_component_type = world:get_type_by_name("MyComponent") - --- then ask the world to give us a reference to `MyComponent` on the entity we just spawned --- resources work the same way, but we use `get_resource` instead of `get_component` --- the comp object is resolved to a `bevy_script_api::script_ref::ReflectValue` which implements UserData. --- we can use a custom proxy instead (by implementing LuaProxyable), but this is the simplest way to get started. -local comp = world:get_component(entity, my_component_type) -print("Before script: ", comp) - -print("============") - --- the index metamethod on ReflectValue's uses bevy's reflection mechanism on top of some custom sub-reflection logic to --- allow reflecting inside Options, Vectors etc. --- when we index into ReflectValue's we either get back a custom proxy or another ReflectValue - --- the LuaBevyAPIProvider provides us custom proxies for many bevy types as well as std types. --- all of these implementations can be overridden via the bevy TypeRegistry -comp.usize = 2 -print("comp.usize after assigning to 2: ", comp.usize) - --- vec's and matrices have custom __index and __newindex overrides -print("comp.vec2 before: ", comp.vec2) -comp.vec2[1] = 69 -print("comp.vec2 after: ", comp.vec2) - --- Option's get converted to nil or the value inside -print("comp.option_vec3 before: ", comp.option_vec3) -comp.option_vec3 = Vec3.new(2,1,3) -print("comp.option_vec3 after: ", comp.option_vec3) - --- reflection via index is indexed starting at 1, unlike in Rust to match Lua's indexing -print("comp.option_vec3[1] before: ", comp.option_vec3[1]) -comp.option_vec3[1] = 5 -print("comp.option_vec3[1] after: ", comp.option_vec3[1]) - -print("============") - --- Vec references get converted to a custom proxy `LuaVec` which is --- also assignable via lua tables - -print("comp.vec_of_option_bools before: ", table_to_string(comp.vec_of_option_bools)) -comp.vec_of_option_bools = {true,false,true} -print("comp.vec_of_option_bools after assignment: ", table_to_string(comp.vec_of_option_bools)) - -print("comp.vec_of_option_bools[1] before: ", comp.vec_of_option_bools[1]) -comp.vec_of_option_bools[1] = false -print("comp.vec_of_option_bools[1] after: ", comp.vec_of_option_bools[1]) - --- there are some additional methods available on LuaVec proxies imitating the Vec api -print("comp.vec_of_option_bools before insert: ", table_to_string(comp.vec_of_option_bools)) -comp.vec_of_option_bools:insert(1,nil) -print("comp.vec_of_option_bools after insert: ", table_to_string(comp.vec_of_option_bools)) - -print("comp.vec_of_option_bools before push: ", table_to_string(comp.vec_of_option_bools)) -comp.vec_of_option_bools:push(false) -print("comp.vec_of_option_bools after push: ", table_to_string(comp.vec_of_option_bools)) - -print("comp.vec_of_option_bools len after push: ", #comp.vec_of_option_bools) - -print("comp.vec_of_option_bools before pop: ", table_to_string(comp.vec_of_option_bools)) -print(comp.vec_of_option_bools:pop()) -print("comp.vec_of_option_bools after pop: ", table_to_string(comp.vec_of_option_bools)) - -print("the pairs inside comp.vec_of_option_bools: ") -for k,v in pairs(comp.vec_of_option_bools) do - print(string.format(" - %s:%s",k,v)) -end +function on_event() -comp.vec_of_option_bools:clear() -print("comp.vec_of_option_bools after clear: ", table_to_string(comp.vec_of_option_bools)) + print(entity) + print(script) + print(world) -print("comp.vec_of_option_bools len after clear: ", #comp.vec_of_option_bools) -print("============") -print("comp.option_vec_of_bools before: ", table_to_string(comp.option_vec_of_bools)) -print(comp.option_vec_of_bools:pop()) -print("comp.option_vec_of_bools after pop: ", table_to_string(comp.option_vec_of_bools)) + local my_component_type = world:get_type_by_name("MyComponent") + local comp = world:get_component(entity, my_component_type) + print("Before script: ", comp) -print("comp.option_vec_of_bools len after pop: ", #comp.option_vec_of_bools) -print("the pairs inside comp.option_vec_of_bools: ") -for k,v in pairs(comp.option_vec_of_bools) do - print(string.format(" - %s:%s",k,v)) -end + print(comp.option_usize) + comp.option_usize = 69 + print(comp.option_usize) + comp.option_usize = nil + print(comp.option_usize) + world:exit() + + print(comp.vec_of_usize) + print(comp.vec_of_usize[2]) + comp.vec_of_usize[2] = 69 + print(comp.vec_of_usize[2]) + world:exit() + + print("============") + + -- the index metamethod on ReflectValue's uses bevy's reflection mechanism on top of some custom sub-reflection logic to + -- allow reflecting inside Options, Vectors etc. + -- when we index into ReflectValue's we either get back a custom proxy or another ReflectValue + + -- the LuaBevyAPIProvider provides us custom proxies for many bevy types as well as std types. + -- all of these implementations can be overridden via the bevy TypeRegistry + print("Hello:", comp.usize._1) + comp.usize[1] = 2 + print("comp.usize after assigning to 2: ", comp.usize._1) + + -- vec's and matrices have custom __index and __newindex overrides + print("comp.vec2 before: ", comp.vec2) + comp.vec2[1] = 69 + print("comp.vec2 after: ", comp.vec2) + + -- Option's get converted to nil or the value inside + print("comp.option_vec3 before: ", comp.option_vec3) + comp.option_vec3 = Vec3.new(2,1,3) + print("comp.option_vec3 after: ", comp.option_vec3) + + -- reflection via index is indexed starting at 1, unlike in Rust to match Lua's indexing + print("comp.option_vec3[1] before: ", comp.option_vec3[1]) + comp.option_vec3[1] = 5 + print("comp.option_vec3[1] after: ", comp.option_vec3[1]) + + print("============") + + -- Vec references get converted to a custom proxy `LuaVec` which is + -- also assignable via lua tables + + print("comp.vec_of_option_bools before: ", table_to_string(comp.vec_of_option_bools)) + comp.vec_of_option_bools = {true,false,true} + print("comp.vec_of_option_bools after assignment: ", table_to_string(comp.vec_of_option_bools)) + + print("comp.vec_of_option_bools[1] before: ", comp.vec_of_option_bools[1]) + comp.vec_of_option_bools[1] = false + print("comp.vec_of_option_bools[1] after: ", comp.vec_of_option_bools[1]) + + -- there are some additional methods available on LuaVec proxies imitating the Vec api + print("comp.vec_of_option_bools before insert: ", table_to_string(comp.vec_of_option_bools)) + comp.vec_of_option_bools:insert(1,nil) + print("comp.vec_of_option_bools after insert: ", table_to_string(comp.vec_of_option_bools)) + + print("comp.vec_of_option_bools before push: ", table_to_string(comp.vec_of_option_bools)) + comp.vec_of_option_bools:push(false) + print("comp.vec_of_option_bools after push: ", table_to_string(comp.vec_of_option_bools)) + + print("comp.vec_of_option_bools len after push: ", #comp.vec_of_option_bools) + + print("comp.vec_of_option_bools before pop: ", table_to_string(comp.vec_of_option_bools)) + print(comp.vec_of_option_bools:pop()) + print("comp.vec_of_option_bools after pop: ", table_to_string(comp.vec_of_option_bools)) + + print("the pairs inside comp.vec_of_option_bools: ") + for k,v in pairs(comp.vec_of_option_bools) do + print(string.format(" - %s:%s",k,v)) + end + + comp.vec_of_option_bools:clear() + print("comp.vec_of_option_bools after clear: ", table_to_string(comp.vec_of_option_bools)) + + print("comp.vec_of_option_bools len after clear: ", #comp.vec_of_option_bools) + print("============") + + print("comp.option_vec_of_bools before: ", table_to_string(comp.option_vec_of_bools)) + print(comp.option_vec_of_bools:pop()) + print("comp.option_vec_of_bools after pop: ", table_to_string(comp.option_vec_of_bools)) + + + print("comp.option_vec_of_bools len after pop: ", #comp.option_vec_of_bools) + + print("the pairs inside comp.option_vec_of_bools: ") + for k,v in pairs(comp.option_vec_of_bools) do + print(string.format(" - %s:%s",k,v)) + end -print("============") + print("============") -local complex_vec_op = Vec3.new(0,1,0):any_orthonormal_vector() + comp.mat3.x_axis -print("(0,1,0).any_orthonormal_vector() + mat3.x_axis is: ", complex_vec_op) + local complex_vec_op = Vec3.new(0,1,0):any_orthonormal_vector() + comp.mat3.x_axis + print("(0,1,0).any_orthonormal_vector() + mat3.x_axis is: ", complex_vec_op) -local new_mat3 = Mat3.from_cols(Vec3.new(1,0,0),Vec3.new(0,1,0),Vec3.new(0,0,-1)) -print("new_mat3 is:", new_mat3) + local new_mat3 = Mat3.from_cols(Vec3.new(1,0,0),Vec3.new(0,1,0),Vec3.new(0,0,-1)) + print("new_mat3 is:", new_mat3) -comp.vec2 = comp.vec2 + comp.vec2 -comp.usize = comp.vec2:min_element() -comp.f32 = comp.f32 + comp.f32 + comp.vec2:min_element() -comp.vec2 = Vec2.new(2,1) -comp.quat = Quat.from_xyzw(3,2,1,4) -comp.mat3.x_axis = Vec3.new(69,69,69) + comp.vec2 = comp.vec2 + comp.vec2 + comp.usize = comp.vec2:min_element() + comp.f32 = comp.f32 + comp.f32 + comp.vec2:min_element() + comp.vec2 = Vec2.new(2,1) + comp.quat = Quat.from_xyzw(3,2,1,4) + comp.mat3.x_axis = Vec3.new(69,69,69) -print("============") + print("============") --- this is an example of something impossible to achieve with plain bevy reflection under the hood -comp.mat3[1][1] = 42 + -- this is an example of something impossible to achieve with plain bevy reflection under the hood + comp.mat3[1][1] = 42 --- now let's retrieve these again to see if we actually changed their values permanently -comp = world:get_component(entity,my_component_type) + -- now let's retrieve these again to see if we actually changed their values permanently + comp = world:get_component(entity,my_component_type) -print("After script:") -print(comp) + print("After script:") + print(comp) -world:exit() \ No newline at end of file + world:exit() +end \ No newline at end of file diff --git a/crates/bevy_api_gen/templates/header.tera b/crates/bevy_api_gen/templates/header.tera index 5404318ea2..02f0fa1b81 100644 --- a/crates/bevy_api_gen/templates/header.tera +++ b/crates/bevy_api_gen/templates/header.tera @@ -12,7 +12,7 @@ use super::{{crate}}::*; use bevy_mod_scripting_core::{AddContextInitializer, StoreDocumentation, bindings::ReflectReference}; {% if args.self_is_bms_lua %} -use crate::{bindings::proxy::{LuaReflectRefProxy,LuaReflectRefMutProxy,LuaReflectValProxy,LuaValProxy,LuaIdentityProxy},RegisterLua, tealr::mlu::mlua::IntoLua}; +use crate::{bindings::proxy::{LuaReflectRefProxy,LuaReflectRefMutProxy,LuaReflectValProxy,LuaValProxy,LuaIdentityProxy},type_data::RegisterLua, tealr::mlu::mlua::IntoLua}; {% else %} -use bevy_mod_scripting::{lua::bindings::proxy::{LuaReflectRefProxy,LuaReflectRefMutProxy,LuaReflectValProxy,LuaValProxy,LuaIdentityProxy}, RegisterLua, tealr::mlu::mlua::IntoLua}; +use bevy_mod_scripting::{lua::bindings::proxy::{LuaReflectRefProxy,LuaReflectRefMutProxy,LuaReflectValProxy,LuaValProxy,LuaIdentityProxy}, type_data::RegisterLua, tealr::mlu::mlua::IntoLua}; {% endif %} \ No newline at end of file diff --git a/crates/bevy_mod_scripting_core/src/bindings/allocator.rs b/crates/bevy_mod_scripting_core/src/bindings/allocator.rs index c6394bc6f9..ef2c710a31 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/allocator.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/allocator.rs @@ -1,6 +1,6 @@ use bevy::ecs::system::Resource; use bevy::reflect::{PartialReflect, Reflect}; -use std::any::TypeId; +use std::any::{Any, TypeId}; use std::cell::UnsafeCell; use std::collections::HashMap; use std::fmt::{Display, Formatter}; @@ -45,18 +45,46 @@ pub struct ReflectAllocator { } impl ReflectAllocator { - /// Allocates a new [`Reflect`] value and returns an [`AllocationId`] which can be used to access it later + /// Allocates a new [`Reflect`] value and returns an [`AllocationId`] which can be used to access it later. + /// Use [`Self::allocate_boxed`] if you already have an allocated boxed value. pub fn allocate( &mut self, value: T, ) -> (ReflectAllocationId, ReflectAllocation) { + let type_id = value.get_represented_type_info().map(|i| i.type_id()); + let id = ReflectAllocationId(self.allocations.len()); let value = ReflectAllocation::new(Arc::new(UnsafeCell::new(value))); self.allocations.insert(id, value.clone()); - self.types.insert(id, TypeId::of::()); + if let Some(type_id) = type_id { + self.types.insert(id, type_id); + } (id, value) } + /// Moves the given boxed [`PartialReflect`] value into the allocator, returning an [`AllocationId`] which can be used to access it later + pub fn allocate_boxed( + &mut self, + existing: Box, + ) -> (ReflectAllocationId, ReflectAllocation) { + let type_id = existing.get_represented_type_info().map(|i| i.type_id()); + let id = ReflectAllocationId(self.allocations.len()); + + let raw_ptr = Box::into_raw(existing); + // Safety: + // - we are the only ones to have access to this value since we have the Box + // - UnsafeCell is repr(transparent), meaning we can safely transmute between it and the trait object + // TODO: I don't think we can use this, because from_raw has a pre-condition that requires the pointer to have been an arc before + let arc: Arc> = + unsafe { Arc::from_raw(raw_ptr as *const _) }; + let allocation = ReflectAllocation::new(arc); + self.allocations.insert(id, allocation.clone()); + if let Some(type_id) = type_id { + self.types.insert(id, type_id); + } + (id, allocation) + } + pub fn get(&self, id: ReflectAllocationId) -> Option { self.allocations.get(&id).cloned() } diff --git a/crates/bevy_mod_scripting_core/src/bindings/reference.rs b/crates/bevy_mod_scripting_core/src/bindings/reference.rs index b0ad73756b..47ca7117c2 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/reference.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/reference.rs @@ -59,11 +59,17 @@ pub struct ReflectReference { impl ReflectReference { + /// Prints the reference using the world to resolve type names. pub fn print_with_world(&self, world: &WorldAccessGuard) -> String { - let base = world.with_resource(|_, type_registry: Mut| { - self.base.display_with_type_name(&type_registry.read()) - }); + world.with_resource(|_, type_registry: Mut| { + let type_registry = type_registry.read(); + self.print_with_type_registry(&type_registry) + }) + } + /// Prints the reference using the type registry to resolve type names. Prefer this over [`Self::print_with_world`] if you have a type registry available. + pub fn print_with_type_registry(&self, type_registry: &TypeRegistry) -> String { + let base = self.base.display_with_type_name(type_registry); format!("Reference(base: {}, path: {:?})", base, self.reflect_path) } @@ -90,7 +96,7 @@ impl ReflectReference { }) } - pub fn new_allocated( + pub fn new_allocated( value: T, allocator: &mut ReflectAllocator, ) -> ReflectReference { @@ -104,6 +110,21 @@ impl ReflectReference { } } + pub fn new_allocated_boxed( + value: Box, + allocator: &mut ReflectAllocator, + ) -> ReflectReference { + let type_id = value.get_represented_type_info().map(|i| i.type_id()).expect("Expected type info for boxed value"); + let (id, _) = allocator.allocate_boxed(value); + ReflectReference { + base: ReflectBaseType { + type_id, + base_id: ReflectBase::Owned(id), + }, + reflect_path: Vec::default(), + } + } + /// Indexes into the reflect path inside this reference. /// You can use [`Self::reflect`] and [`Self::reflect_mut`] to get the actual value. pub fn index_path>(&mut self, index: T) { diff --git a/crates/bevy_mod_scripting_core/src/bindings/world.rs b/crates/bevy_mod_scripting_core/src/bindings/world.rs index d5b9a2f27b..2481ec4d4a 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/world.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/world.rs @@ -472,6 +472,21 @@ impl<'w> WorldAccessGuard<'w> { out } + /// Convenience to get commonly used resources at the same time. Internally identical to [`Self::with_resource`] + pub fn with_allocator_and_type_registry< + O, + F: FnOnce(&Self, Mut, Mut) -> O, + >( + &self, + f: F, + ) -> O { + self.with_resource(|world, registry: Mut| { + world.with_resource(|world, allocator: Mut| { + f(world, registry, allocator) + }) + }) + } + /// Call a function on a type which can be proxied, first by unproxying the input with world access, /// then calling the function and finally proxying the output with the allocator. pub fn proxy_call<'i, O: Proxy, T: Unproxy, F: Fn(T::Output<'_>) -> O::Input<'i>>( diff --git a/crates/bevy_mod_scripting_core/src/lib.rs b/crates/bevy_mod_scripting_core/src/lib.rs index 8b5c0f00df..67a1ce74d0 100644 --- a/crates/bevy_mod_scripting_core/src/lib.rs +++ b/crates/bevy_mod_scripting_core/src/lib.rs @@ -26,6 +26,7 @@ pub mod docs; pub mod error; pub mod event; pub mod handler; +pub mod reflection_extensions; pub mod runtime; pub mod script; pub mod systems; diff --git a/crates/bevy_mod_scripting_core/src/reflection_extensions.rs b/crates/bevy_mod_scripting_core/src/reflection_extensions.rs new file mode 100644 index 0000000000..19ca2fa664 --- /dev/null +++ b/crates/bevy_mod_scripting_core/src/reflection_extensions.rs @@ -0,0 +1,112 @@ +use bevy::reflect::PartialReflect; + +use crate::error::ScriptError; + +/// Extension trait for [`PartialReflect`] providing additional functionality for working with specific types. +pub trait PartialReflectExt { + /// Check if the represented type is from the given crate and has the given type identifier, + /// returns false if not representing any type or if the type is not from the given crate or does not have the given type identifier. + fn is_type(&self, crate_name: Option<&str>, type_ident: &str) -> bool; + + /// Equivalent to [`PartialReflectExt::is_type`] but returns an appropriate error if the type is not the expected one. + fn expect_type(&self, crate_name: Option<&str>, type_ident: &str) -> Result<(), ScriptError>; + + /// If the type is an option, returns either the inner value or None if the option is None. + /// Errors if the type is not an option. + fn as_option(&self) -> Result, ScriptError>; +} + +impl PartialReflectExt for T { + fn is_type(&self, crate_name: Option<&str>, type_ident: &str) -> bool { + self.get_represented_type_info().is_some_and(|v| { + let table = v.type_path_table(); + table.crate_name() == crate_name && table.ident() == Some(type_ident) + }) + } + + fn expect_type(&self, crate_name: Option<&str>, type_ident: &str) -> Result<(), ScriptError> { + if !self.is_type(crate_name, type_ident) { + return Err(ScriptError::new_runtime_error(format!( + "Expected type {type_ident}{}, but got {}", + crate_name + .map(|s| format!(" from crate {s}")) + .unwrap_or_default(), + self.get_represented_type_info() + .map(|ti| ti.type_path()) + .unwrap_or_else(|| "dynamic type with no type information") + ))); + } + Ok(()) + } + + /// If the type is an option, returns either the inner value or None if the option is None. + /// Errors if the type is not an option. + fn as_option(&self) -> Result, ScriptError> { + self.expect_type(Some("core"), "Option")?; + + if let bevy::reflect::ReflectRef::Enum(e) = self.reflect_ref() { + if let Some(field) = e.field_at(0) { + return Ok(Some(field)); + } else { + return Ok(None); + } + } + + unreachable!("core::Option is an enum with a tuple variant") + } +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_type_no_crate() { + assert!(42.is_type(None, "i32")); + assert!(42.expect_type(None, "i32").is_ok()); + } + + #[test] + fn test_is_type_with_crate() { + assert!(Some(42).is_type(Some("core"), "Option")); + assert!(Some(42).expect_type(Some("core"), "Option").is_ok()); + } + + #[test] + fn test_is_type_negative() { + assert!(!Some(42).is_type(Some("std"), "Option")); + assert_eq!( + "Encountered Runtime Error error in a script: Expected type Option from crate std, but got core::option::Option", + Some(42) + .expect_type(Some("std"), "Option") + .unwrap_err() + .to_string() + ); + } + + #[test] + fn test_as_option_some() { + assert_eq!( + &42, + Some(42) + .as_option() + .unwrap() + .unwrap() + .try_downcast_ref::() + .unwrap() + ); + } + + #[test] + fn test_as_option_none() { + assert!(None::.as_option().unwrap().is_none()); + } + + #[test] + fn test_as_option_error() { + assert_eq!( + "Encountered Runtime Error error in a script: Expected type Option from crate core, but got i32", + 42.as_option().unwrap_err().to_string() + ); + } +} diff --git a/crates/bevy_mod_scripting_core/src/systems.rs b/crates/bevy_mod_scripting_core/src/systems.rs index ae52b80653..b5c6fafefc 100644 --- a/crates/bevy_mod_scripting_core/src/systems.rs +++ b/crates/bevy_mod_scripting_core/src/systems.rs @@ -46,7 +46,19 @@ pub fn sync_script_data( }; // get the path let asset = script_assets.get(*id); - let asset = asset.as_ref().expect("Asset was expected to be loaded!"); + let asset = match asset.as_ref() { + Some(a) => a, + None => { + if remove { + debug!( + "Script presumably failed to load, no need to remove anything, ignoring." + ); + continue; + } else { + panic!("Asset was expected to be loaded!"); + } + } + }; let path = &asset.asset_path; // convert it to script id diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_a11y.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_a11y.rs index 991607f1cb..8827603674 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_a11y.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_a11y.rs @@ -12,7 +12,7 @@ use crate::{ LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, LuaIdentityProxy, }, - RegisterLua, tealr::mlu::mlua::IntoLua, + type_data::RegisterLua, tealr::mlu::mlua::IntoLua, }; #[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_core.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_core.rs index 050cbea514..81510b9c0b 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_core.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_core.rs @@ -12,7 +12,7 @@ use crate::{ LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, LuaIdentityProxy, }, - RegisterLua, tealr::mlu::mlua::IntoLua, + type_data::RegisterLua, tealr::mlu::mlua::IntoLua, }; #[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs index ede3306eff..e62e60366c 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_ecs.rs @@ -11,7 +11,7 @@ use crate::{ LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, LuaIdentityProxy, }, - RegisterLua, tealr::mlu::mlua::IntoLua, + type_data::RegisterLua, tealr::mlu::mlua::IntoLua, }; #[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs index 64e548268e..bbe353b36b 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_hierarchy.rs @@ -13,7 +13,7 @@ use crate::{ LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, LuaIdentityProxy, }, - RegisterLua, tealr::mlu::mlua::IntoLua, + type_data::RegisterLua, tealr::mlu::mlua::IntoLua, }; #[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs index 78229eaf4b..c55b025c1e 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_input.rs @@ -14,7 +14,7 @@ use crate::{ LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, LuaIdentityProxy, }, - RegisterLua, tealr::mlu::mlua::IntoLua, + type_data::RegisterLua, tealr::mlu::mlua::IntoLua, }; #[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs index deab25b495..49f55cbfb4 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_math.rs @@ -11,7 +11,7 @@ use crate::{ LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, LuaIdentityProxy, }, - RegisterLua, tealr::mlu::mlua::IntoLua, + type_data::RegisterLua, tealr::mlu::mlua::IntoLua, }; #[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs index b8ebe738ad..b5e5699ac5 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_reflect.rs @@ -10,7 +10,7 @@ use crate::{ LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, LuaIdentityProxy, }, - RegisterLua, tealr::mlu::mlua::IntoLua, + type_data::RegisterLua, tealr::mlu::mlua::IntoLua, }; #[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs index c75985d924..34b1e2fd95 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_time.rs @@ -12,7 +12,7 @@ use crate::{ LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, LuaIdentityProxy, }, - RegisterLua, tealr::mlu::mlua::IntoLua, + type_data::RegisterLua, tealr::mlu::mlua::IntoLua, }; #[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs index 759124267a..9ce8f17e40 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_transform.rs @@ -15,7 +15,7 @@ use crate::{ LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, LuaIdentityProxy, }, - RegisterLua, tealr::mlu::mlua::IntoLua, + type_data::RegisterLua, tealr::mlu::mlua::IntoLua, }; #[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs index 46be3ee95d..1814800abc 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/providers/bevy_window.rs @@ -16,7 +16,7 @@ use crate::{ LuaReflectRefProxy, LuaReflectRefMutProxy, LuaReflectValProxy, LuaValProxy, LuaIdentityProxy, }, - RegisterLua, tealr::mlu::mlua::IntoLua, + type_data::RegisterLua, tealr::mlu::mlua::IntoLua, }; #[derive(bevy_mod_scripting_derive::LuaProxy)] #[proxy( diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs index 619f0e6760..52c3734a16 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs @@ -8,7 +8,9 @@ use bevy::{ reflect::{OffsetAccess, ParsedPath, ReflectFromReflect}, }; use bevy_mod_scripting_core::{ - bindings::{ReflectAllocator, ReflectReference, Unproxy, WorldCallbackAccess}, + bindings::{ + ReflectAllocator, ReflectReference, ReflectionPathElem, Unproxy, WorldCallbackAccess, + }, error::ScriptError, }; use tealr::mlu::{ @@ -25,9 +27,15 @@ use super::{ /// Lua UserData wrapper for [`bevy_mod_scripting_core::bindings::ReflectReference`]. /// Acts as a lua reflection interface. Any value which is registered in the type registry can be interacted with using this type. -#[derive(Debug, Clone, tealr::mlu::UserData, tealr::ToTypename)] +#[derive(Debug, Clone, tealr::mlu::UserData, tealr::ToTypename, PartialEq)] pub struct LuaReflectReference(pub ReflectReference); +impl AsRef for LuaReflectReference { + fn as_ref(&self) -> &ReflectReference { + &self.0 + } +} + impl LuaReflectReference { pub fn len(&self, lua: &Lua) -> Result, mlua::Error> { let world = lua.get_world()?; @@ -78,6 +86,8 @@ impl LuaReflectReference { } pub fn set_with_lua_proxy(&self, lua: &Lua, value: Value) -> Result<(), mlua::Error> { + bevy::log::debug!("Setting lua reflect reference with value: {:?}", value); + let world = lua.get_world()?; let result: Result<(), ScriptError> = world.with_resource(|world, type_registry: Mut| { @@ -85,30 +95,44 @@ impl LuaReflectReference { let type_registry = type_registry.read(); let type_id = self.0 - .with_reflect(world, &type_registry, Some(&allocator), |r| r.type_id()); + .with_reflect(world, &type_registry, Some(&allocator), |r| { + r.get_represented_type_info().map(|t| t.type_id()) + }); - if let Some(type_data) = type_registry.get_type_data::(type_id) + // convenience, ideally we probably should just avoid lookups when no type id is here, but for now we just use a dummy type nothing will ever + // be registered for. If the type we're reflecting doesn't represent anything or a registered type, we use a generic reflect reference. + struct Unknown; + let type_id_or_dummy = type_id.unwrap_or(TypeId::of::()); + bevy::log::debug!("Target type is {:?}", type_registry.get_type_info(type_id_or_dummy).map(|t| t.type_path())); + + if let Some(type_data) = + type_registry.get_type_data::(type_id_or_dummy) { + bevy::log::debug!("Setting value with ReflectLuaValue registration"); self.0 .with_reflect_mut(world, &type_registry, Some(&allocator), |r| { Ok((type_data.set_value)(r, value, lua)?) }) } else if let Some(type_data) = - type_registry.get_type_data::(type_id) + type_registry.get_type_data::(type_id_or_dummy) { + bevy::log::debug!("Setting value with ReflectLuaProxied registration"); + let other = (type_data.from_proxy)(value, lua)?; // first we need to get a copy of the other value let other = other .with_reflect(world, &type_registry, Some(&allocator), |r| { type_registry - .get_type_data::(r.type_id()) + .get_type_data::(type_id_or_dummy) .and_then(|from_reflect_td| from_reflect_td.from_reflect(r)) }) .ok_or_else(|| { ScriptError::new_reflection_error(format!( "Failed to call ReflectFromReflect for type id: {:?}", - type_registry.get_type_info(type_id).map(|t| t.type_path()) + type_registry + .get_type_info(type_id_or_dummy) + .map(|t| t.type_path()) )) })?; @@ -117,18 +141,23 @@ impl LuaReflectReference { .with_reflect_mut(world, &type_registry, Some(&allocator), |r| { r.try_apply(other.as_partial_reflect()).map_err(|e| { ScriptError::new_runtime_error(format!( - "Invalid assignment `{:?}` = `{:?}`. Wrong type.", - self.0.clone(), + "Invalid assignment `{:?}` = `{:?}`. {e}.", + self.0.print_with_type_registry(&type_registry), e, )) }) })?; Ok(()) } else { + bevy::log::debug!("No registration found, throwing error"); + // we don't know how to assign the value + // prod to see if it's a common container (i.e. Option or Vec) + Err(ScriptError::new_runtime_error(format!( - "Invalid assignment `{:?}` = `{:?}`. Wrong type.", - self.0.clone(), + "Invalid assignment `{:?}` = `{:?}`. The underlying type does: `{}` not support assignment.", + self.0.print_with_type_registry(&type_registry), value, + type_registry.get_type_info(type_id_or_dummy).map(|t| t.type_path()).unwrap_or_else(|| "Unknown") ))) } }) @@ -216,8 +245,10 @@ impl TealData for LuaReflectReference { MetaMethod::NewIndex, |l, (mut self_, key, value): (LuaReflectReference, Value, Value)| { let mut elem = Self::parse_value_index(key)?; + bevy::log::debug!("New index with parsed path: {:?}", elem); Self::to_host_index(&mut elem); self_.0.index_path(elem); + bevy::log::debug!("New reflect reference after: {:?}", self_.0); self_.set_with_lua_proxy(l, value) }, ); @@ -247,7 +278,7 @@ mod test { }; use bevy_mod_scripting_derive::LuaProxy; - use crate::{bindings::world::LuaWorld, RegisterLua}; + use crate::{bindings::world::LuaWorld, type_data::RegisterLua}; use super::*; diff --git a/crates/languages/bevy_mod_scripting_lua/src/lib.rs b/crates/languages/bevy_mod_scripting_lua/src/lib.rs index 4c73cc2610..c163b6027b 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/lib.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/lib.rs @@ -1,10 +1,12 @@ pub mod assets; pub mod docs; +pub mod type_data; pub mod util; use bevy::{ - app::{App, Plugin}, + app::{App, Plugin, Startup}, ecs::{entity::Entity, world::World}, - reflect::{FromType, GetTypeRegistration, PartialReflect, Reflect, TypePath}, + prelude::{AppTypeRegistry, Mut}, + reflect::{impl_reflect, FromType, GetTypeRegistration, PartialReflect, Reflect, TypePath}, }; use bevy_mod_scripting_core::{ bindings::{ReflectAllocator, ReflectReference, WorldCallbackAccess}, @@ -23,6 +25,9 @@ use bindings::{ pub use tealr; pub mod bindings; use tealr::mlu::mlua::{FromLua, Function, IntoLua, IntoLuaMulti, Lua, Value}; +use type_data::{ + pre_register_common_containers, register_lua_values, ReflectLuaProxied, ReflectLuaValue, +}; pub mod prelude { pub use crate::tealr::{ @@ -58,25 +63,6 @@ impl Default for LuaScriptingPlugin { } } -pub fn register_lua_values(app: &mut bevy::prelude::App) { - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); - app.register_lua_value::(); -} - impl Plugin for LuaScriptingPlugin { fn build(&self, app: &mut bevy::prelude::App) { self.scripting_plugin.build(app); @@ -93,6 +79,11 @@ impl Plugin for LuaScriptingPlugin { Ok(()) }); } + + fn cleanup(&self, app: &mut App) { + let mut type_registry = app.world_mut().get_resource_mut().unwrap(); + pre_register_common_containers(&mut type_registry); + } } pub fn lua_context_load( @@ -182,95 +173,3 @@ pub fn with_world Result<(), ScriptError>>( f(context) }) } - -/// Registers a lua proxy object via the reflection system -pub trait RegisterLua { - fn register_lua_proxy( - &mut self, - ) -> &mut Self - where - T::Proxy: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, - T::Proxy: From + AsRef; - - fn register_lua_value(&mut self) -> &mut Self - where - T: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, - T: Reflect + Clone + TypePath + GetTypeRegistration; -} - -impl RegisterLua for App { - fn register_lua_proxy( - &mut self, - ) -> &mut Self - where - T::Proxy: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, - T::Proxy: From + AsRef, - { - self.register_type::(); - self.register_type_data::() - } - - fn register_lua_value(&mut self) -> &mut Self - where - T: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, - T: Reflect + Clone + TypePath + GetTypeRegistration, - { - self.register_type::(); - self.register_type_data::() - } -} - -/// Stores the procedure used to convert a lua value to a reflect value and vice versa, Used for types which are represented in lua via proxies which store -/// a reference to the actual value. -/// This is used for types which are represented in lua with pass by reference semantics -#[derive(Clone)] -pub struct ReflectLuaProxied { - pub into_proxy: - for<'l> fn(ReflectReference, &'l Lua) -> Result, tealr::mlu::mlua::Error>, - pub from_proxy: - for<'l> fn(Value<'l>, &'l Lua) -> Result, -} - -impl FromType for ReflectLuaProxied -where - T::Proxy: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, - T::Proxy: From + AsRef, -{ - fn from_type() -> Self { - Self { - into_proxy: |p, l| T::Proxy::from(p).into_lua(l), - from_proxy: |v, l| T::Proxy::from_lua(v, l).map(|p| p.as_ref().clone()), - } - } -} - -/// Stores the procedure used to convert a lua value to a reflect value and vice versa, Used for types which are represented directly in lua with -/// pass by value semantics, These need to implement [`Clone`] -#[derive(Clone)] -pub struct ReflectLuaValue { - pub into_value: - for<'l> fn(&dyn PartialReflect, &'l Lua) -> Result, tealr::mlu::mlua::Error>, - pub set_value: for<'l> fn( - &mut dyn PartialReflect, - Value<'l>, - &'l Lua, - ) -> Result<(), tealr::mlu::mlua::Error>, - pub from_value: - for<'l> fn(Value<'l>, &'l Lua) -> Result, tealr::mlu::mlua::Error>, -} - -impl IntoLua<'l> + for<'l> FromLua<'l>> FromType - for ReflectLuaValue -{ - fn from_type() -> Self { - Self { - into_value: |v, l| v.try_downcast_ref::().unwrap().clone().into_lua(l), - set_value: |t, v, l| { - let t = t.try_downcast_mut::().unwrap(); - *t = T::from_lua(v, l)?; - Ok(()) - }, - from_value: |v, l| T::from_lua(v, l).map(|v| Box::new(v) as Box), - } - } -} diff --git a/crates/languages/bevy_mod_scripting_lua/src/type_data.rs b/crates/languages/bevy_mod_scripting_lua/src/type_data.rs new file mode 100644 index 0000000000..629fca061f --- /dev/null +++ b/crates/languages/bevy_mod_scripting_lua/src/type_data.rs @@ -0,0 +1,665 @@ +use std::{ + any::TypeId, + collections::{HashMap, HashSet}, + sync::Arc, +}; + +use bevy::{ + app::App, + log::debug, + prelude::{AppTypeRegistry, Mut}, + reflect::{ + impl_reflect, DynamicEnum, DynamicTuple, DynamicVariant, FromType, GetTypeRegistration, + ParsedPath, PartialReflect, Reflect, ReflectFromReflect, ReflectPathError, TypePath, + TypeRegistration, + }, +}; +use bevy_mod_scripting_core::{ + bindings::{DeferredReflection, ReflectAllocator, ReflectReference, ReflectionPathElem}, + error::ScriptError, + reflection_extensions::PartialReflectExt, +}; +use tealr::mlu::mlua::{FromLua, IntoLua, Lua, Value}; + +use crate::bindings::{proxy::LuaProxied, world::GetWorld}; + +/// Stores the procedure used to convert a lua value to a reflect value and vice versa, Used for types which are represented in lua via proxies which store +/// a reference to the actual value. +/// This is used for types which are represented in lua with pass by reference semantics +#[derive(Clone)] +pub struct ReflectLuaProxied { + pub into_proxy: Arc< + dyn for<'l> Fn(ReflectReference, &'l Lua) -> Result, tealr::mlu::mlua::Error> + + Send + + Sync + + 'static, + >, + pub from_proxy: Arc< + dyn for<'l> Fn(Value<'l>, &'l Lua) -> Result + + Send + + Sync + + 'static, + >, +} + +impl ReflectLuaProxied { + /// Generates a type data which can be used on [`Option`] types which are represented in lua with pass by reference semantics + fn new_for_option( + inner_lua_proxied_data: &ReflectLuaProxied, + option_from_reflect: &ReflectFromReflect, + ) -> Self { + let ref_into_option = |mut r: ReflectReference| { + r.index_path(ParsedPath::parse_static("0").expect("Invalid reflection path")); + r + }; + let into_proxy_clone = inner_lua_proxied_data.into_proxy.clone(); + let from_proxy_clone = inner_lua_proxied_data.from_proxy.clone(); + let option_from_reflect = option_from_reflect.clone(); + Self { + into_proxy: Arc::new(move |reflect_ref, l| { + // read the value and check if it is None, if so return nil + // otherwise use the inner type's into_proxy + let world = l.get_world()?; + let is_some = world + .with_allocator_and_type_registry(|_, type_registry, allocator| { + let type_registry = type_registry.read(); + reflect_ref.with_reflect(&world, &type_registry, Some(&allocator), |s| { + s.as_option().map(|r| r.is_some()) + }) + }) + .map_err(tealr::mlu::mlua::Error::external)?; + + if is_some { + (into_proxy_clone)(ref_into_option(reflect_ref), l) + } else { + Ok(Value::Nil) + } + }), + from_proxy: Arc::new(move |v, l| { + if v.is_nil() { + // we need to allocate a new reflect reference since we don't have one existing + let dynamic_value = DynamicEnum::new("None", DynamicVariant::Unit); + + let world = l.get_world()?; + let reflect_ref = + world.with_resource(|w, mut allocator: Mut| { + let value = option_from_reflect + .from_reflect(&dynamic_value) + .ok_or_else(|| { + tealr::mlu::mlua::Error::external( + ScriptError::new_reflection_error(""), + ) + })? + .into_partial_reflect(); + Ok::<_, tealr::mlu::mlua::Error>(ReflectReference::new_allocated_boxed( + value, + &mut allocator, + )) + })?; + + Ok(reflect_ref) + } else { + let mut inner_ref = (from_proxy_clone)(v, l)?; + inner_ref.reflect_path.pop(); + Ok(inner_ref) + } + }), + } + } +} + +impl FromType for ReflectLuaProxied +where + T::Proxy: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, + T::Proxy: From + AsRef, +{ + fn from_type() -> Self { + Self { + into_proxy: Arc::new(|p, l| T::Proxy::from(p).into_lua(l)), + from_proxy: Arc::new(|v, l| T::Proxy::from_lua(v, l).map(|p| p.as_ref().clone())), + } + } +} + +/// Stores the procedure used to convert a lua value to a reflect value and vice versa, Used for types which are represented directly in lua with +/// pass by value semantics, These need to implement [`Clone`] +#[derive(Clone)] +pub struct ReflectLuaValue { + pub into_value: Arc< + dyn for<'l> Fn(&dyn PartialReflect, &'l Lua) -> Result, tealr::mlu::mlua::Error> + + Send + + Sync + + 'static, + >, + pub set_value: Arc< + dyn for<'l> Fn( + &mut dyn PartialReflect, + Value<'l>, + &'l Lua, + ) -> Result<(), tealr::mlu::mlua::Error> + + Send + + Sync + + 'static, + >, + pub from_value: Arc< + dyn for<'l> Fn( + Value<'l>, + &'l Lua, + ) -> Result, tealr::mlu::mlua::Error> + + Send + + Sync + + 'static, + >, +} + +impl ReflectLuaValue { + /// generates implementation for an inner type wrapped by an option + /// + /// the option should check if the value is None if so return nil, + /// if the value is some use ReflectLuaValue implementation of the inner type. + /// + /// If there is a type mismatch at any point will return an error + pub fn new_for_option( + inner_reflect_lua_value: &ReflectLuaValue, + option_from_reflect: &ReflectFromReflect, + ) -> Self { + let into_value_clone = inner_reflect_lua_value.into_value.clone(); + // we have to do this so the closures can be moved into the arc + let from_value_clone = inner_reflect_lua_value.from_value.clone(); + let from_value_clone2 = inner_reflect_lua_value.from_value.clone(); + let from_reflect_clone = option_from_reflect.clone(); + Self { + into_value: Arc::new(move |r, lua| { + r.as_option() + .map_err(tealr::mlu::mlua::Error::external)? + .map(|inner| (into_value_clone)(inner, lua)) + .unwrap_or_else(|| Ok(Value::Nil)) + }), + set_value: Arc::new(move |r, v, l| { + if v.is_nil() { + r.apply(&DynamicEnum::new("None", DynamicVariant::Unit)); + } else { + r.apply(&DynamicEnum::new( + "Some", + DynamicVariant::Tuple([(from_value_clone)(v, l)?].into_iter().collect()), + )); + } + Ok(()) + }), + from_value: Arc::new(move |v, l| { + let dynamic_option = if v.is_nil() { + DynamicEnum::new("None", DynamicVariant::Unit) + } else { + let inner = (from_value_clone2)(v, l)?; + DynamicEnum::new("Some", DynamicVariant::Tuple([inner].into_iter().collect())) + }; + + let reflect_option = from_reflect_clone + .from_reflect(&dynamic_option) + .ok_or_else(|| { + tealr::mlu::mlua::Error::external(ScriptError::new_runtime_error( + "Failed to convert to option", + )) + })?; + Ok(reflect_option.into_partial_reflect()) + }), + } + } +} + +impl IntoLua<'l> + for<'l> FromLua<'l>> FromType + for ReflectLuaValue +{ + fn from_type() -> Self { + Self { + into_value: Arc::new(|v, l| v.try_downcast_ref::().unwrap().clone().into_lua(l)), + set_value: Arc::new(|t, v, l| { + let t = t.try_downcast_mut::().unwrap(); + *t = T::from_lua(v, l)?; + Ok(()) + }), + from_value: Arc::new(|v, l| { + T::from_lua(v, l).map(|v| Box::new(v) as Box) + }), + } + } +} + +/// Registers a lua proxy object via the reflection system +pub trait RegisterLua { + fn register_lua_proxy( + &mut self, + ) -> &mut Self + where + T::Proxy: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, + T::Proxy: From + AsRef; + + fn register_lua_value(&mut self) -> &mut Self + where + T: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, + T: Reflect + Clone + TypePath + GetTypeRegistration; +} + +impl RegisterLua for App { + fn register_lua_proxy( + &mut self, + ) -> &mut Self + where + T::Proxy: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, + T::Proxy: From + AsRef, + { + self.register_type::(); + self.register_type_data::() + } + + fn register_lua_value(&mut self) -> &mut Self + where + T: for<'l> IntoLua<'l> + for<'l> FromLua<'l>, + T: Reflect + Clone + TypePath + GetTypeRegistration, + { + self.register_type::(); + self.register_type_data::() + } +} + +/// Checks if the type registration is for a type which matches the pattern `core::option::Option`, and extracts `T`'s typeId as well as the Option's typeId +fn destructure_option_type(reg: &TypeRegistration) -> Option<(TypeId, TypeId)> { + let type_path_table = reg.type_info().type_path_table(); + let is_core = type_path_table.crate_name().is_some_and(|s| s == "core"); + let is_option = type_path_table.ident().is_some_and(|s| s == "Option"); + + if is_core && is_option { + reg.type_info() + .generics() + .get_named("T") + .map(|t| (reg.type_id(), t.type_id())) + } else { + None + } +} + +/// iterates over type data for all types which have registered [`ReflectLuaProxied`] and [`ReflectLuaValue`] implementations, +/// and registers corresponding [`Option`] [`Result`] etc type data equivalents +pub fn pre_register_common_containers(type_registry: &mut AppTypeRegistry) { + let mut type_registry = type_registry.write(); + + let mut lua_value_insertions: HashMap = Default::default(); + let mut lua_proxied_insertions: HashMap = Default::default(); + for (option_type_id, inner_type_id) in type_registry.iter().filter_map(destructure_option_type) + { + if let Some(inner_lua_value_data) = + type_registry.get_type_data::(inner_type_id) + { + if let Some(option_from_reflect) = + type_registry.get_type_data::(option_type_id) + { + let option_lua_proxied_data = + ReflectLuaValue::new_for_option(&inner_lua_value_data, &option_from_reflect); + + lua_value_insertions.insert(option_type_id, option_lua_proxied_data); + } + } + + if let Some(inner_lua_proxied_data) = + type_registry.get_type_data::(inner_type_id) + { + if let Some(option_from_reflect) = + type_registry.get_type_data::(option_type_id) + { + let option_lua_proxied_data = + ReflectLuaProxied::new_for_option(inner_lua_proxied_data, option_from_reflect); + + lua_proxied_insertions.insert(option_type_id, option_lua_proxied_data); + } + } + } + + for (type_id, lua_value_data) in lua_value_insertions { + type_registry + .get_mut(type_id) + .expect("We just found the type id from the type registry") + .insert(lua_value_data); + } + + for (type_id, lua_proxied_data) in lua_proxied_insertions { + type_registry + .get_mut(type_id) + .expect("We just found the type id from the type registry") + .insert(lua_proxied_data); + } +} + +pub fn register_lua_values(app: &mut bevy::prelude::App) { + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); + app.register_lua_value::(); +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::bindings::{reference::LuaReflectReference, world::LuaWorld}; + use bevy::{ + prelude::World, + reflect::{TypeRegistry, TypeRegistryArc}, + }; + use bevy_mod_scripting_core::bindings::WorldCallbackAccess; + use std::sync::Arc; + + #[derive(Reflect)] + struct Proxied(usize); + + impl LuaProxied for Proxied { + type Proxy = LuaReflectReference; + } + + fn setup_type_registry() -> AppTypeRegistry + where + T1: GetTypeRegistration, + T2: GetTypeRegistration, + { + let mut type_registry = TypeRegistry::default(); + type_registry.register::(); + type_registry.register::(); + + let type_registry_arc = TypeRegistryArc { + internal: Arc::new(type_registry.into()), + }; + AppTypeRegistry(type_registry_arc) + } + + #[test] + fn test_pre_register_common_containers_lua_value() { + let mut app_type_registry = setup_type_registry::>(); + app_type_registry + .write() + .register_type_data::(); + + pre_register_common_containers(&mut app_type_registry); + + let type_registry = app_type_registry.read(); + let option_type_id = std::any::TypeId::of::>(); + let option_type_registration = type_registry.get(option_type_id).unwrap(); + + let type_data = option_type_registration.contains::(); + assert!(type_data, "Option should have type data"); + } + + #[test] + fn test_pre_register_common_containers_lua_proxy() { + let mut app_type_registry = setup_type_registry::>(); + app_type_registry + .write() + .register_type_data::(); + + pre_register_common_containers(&mut app_type_registry); + + let type_registry = app_type_registry.read(); + let option_type_id = std::any::TypeId::of::>(); + let option_type_registration = type_registry.get(option_type_id).unwrap(); + + let type_data = option_type_registration.contains::(); + assert!(type_data, "Option should have type data"); + } + + #[test] + fn test_option_lua_proxy_impl_into_proxy() { + let mut app_type_registry = setup_type_registry::>(); + app_type_registry + .write() + .register_type_data::(); + let mut world = World::default(); + + pre_register_common_containers(&mut app_type_registry); + + let type_registry = app_type_registry.read(); + let option_type_data = type_registry + .get_type_data::(std::any::TypeId::of::>()) + .unwrap() + .clone(); + let inner_type_data = type_registry + .get_type_data::(std::any::TypeId::of::()) + .unwrap() + .clone(); + + let mut allocator = ReflectAllocator::default(); + let inner_value = ReflectReference::new_allocated(Proxied(4), &mut allocator); + let some_value = ReflectReference::new_allocated(Some(Proxied(4)), &mut allocator); + let none_value = ReflectReference::new_allocated(None::, &mut allocator); + world.insert_resource(allocator); + drop(type_registry); + world.insert_resource(app_type_registry); + + let lua = Lua::new(); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + lua.globals().set("world", LuaWorld(world.clone())).unwrap(); + + // option::some into_proxy should be equivalent result to inner_type into_proxy apart from the reflect path + let expected_into_value = (inner_type_data.into_proxy)(inner_value, &lua).unwrap(); + let gotten_into_value = (option_type_data.into_proxy)(some_value, &lua).unwrap(); + + let converted_into_value = LuaReflectReference::from_lua(expected_into_value, &lua) + .unwrap() + .0 + .reflect_path; + + let mut converted_gotten_into_value = + LuaReflectReference::from_lua(gotten_into_value, &lua) + .unwrap() + .0 + .reflect_path; + converted_gotten_into_value.pop(); + + assert_eq!( + converted_into_value, converted_gotten_into_value, + "Option into_proxy should be equivalent to Proxied into_proxy for Some variant apart from the last element in the path" + ); + + // the none variant should be equivalent to Value::Nil + let expected_into_value = Value::Nil; + let gotten_into_value = (option_type_data.into_proxy)(none_value, &lua).unwrap(); + + assert_eq!( + expected_into_value, gotten_into_value, + "Option into_proxy should be equivalent to Value::Nil for None variant" + ); + }) + } + + #[test] + fn test_option_lua_proxy_impl_from_proxy() { + let mut app_type_registry = setup_type_registry::>(); + app_type_registry + .write() + .register_type_data::(); + let mut world = World::default(); + + pre_register_common_containers(&mut app_type_registry); + + let type_registry = app_type_registry.read(); + let option_type_data = type_registry + .get_type_data::(std::any::TypeId::of::>()) + .unwrap() + .clone(); + + let mut allocator = ReflectAllocator::default(); + let some_value = ReflectReference::new_allocated(Some(Proxied(4)), &mut allocator); + let none_value = ReflectReference::new_allocated(None::, &mut allocator); + world.insert_resource(allocator); + drop(type_registry); + world.insert_resource(app_type_registry); + + let lua = Lua::new(); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + lua.globals().set("world", LuaWorld(world.clone())).unwrap(); + + let some_lua_value = LuaReflectReference(some_value.clone()) + .into_lua(&lua) + .unwrap(); + let gotten_value = (option_type_data.from_proxy)(some_lua_value, &lua).unwrap(); + assert_eq!(gotten_value.reflect_path, some_value.reflect_path); + + let gotten_value = (option_type_data.from_proxy)(Value::Nil, &lua).unwrap(); + assert_eq!(gotten_value.reflect_path, none_value.reflect_path); + }) + } + + #[test] + fn test_option_lua_value_impl_into_value() { + let mut app_type_registry = setup_type_registry::>(); + app_type_registry + .write() + .register_type_data::(); + + pre_register_common_containers(&mut app_type_registry); + + let type_registry = app_type_registry.read(); + let option_type_data = type_registry + .get_type_data::(std::any::TypeId::of::>()) + .unwrap(); + let inner_type_data = type_registry + .get_type_data::(std::any::TypeId::of::()) + .unwrap(); + + // option::some into_value should be equivalent result to inner_type into_value + let lua = Lua::new(); + let value: usize = 5; + let option_value = Some(value); + let expected_into_value = (inner_type_data.into_value)(&value, &lua).unwrap(); + let gotten_into_value = (option_type_data.into_value)(&option_value, &lua).unwrap(); + + assert_eq!( + expected_into_value, gotten_into_value, + "Option into_value should be equivalent to usize into_value for Some variant" + ); + + // the none variant should be equivalent to Value::Nil + let option_value: Option = None; + let expected_into_value = Value::Nil; + let gotten_into_value = (option_type_data.into_value)(&option_value, &lua).unwrap(); + + assert_eq!( + expected_into_value, gotten_into_value, + "Option into_value should be equivalent to Value::Nil for None variant" + ); + } + + #[test] + fn test_option_lua_value_set_value() { + let mut app_type_registry = setup_type_registry::>(); + app_type_registry + .write() + .register_type_data::(); + + pre_register_common_containers(&mut app_type_registry); + + let type_registry = app_type_registry.read(); + let option_type_data = type_registry + .get_type_data::(std::any::TypeId::of::>()) + .unwrap(); + + // setting an existing Some variant works correctly + let lua = Lua::new(); + let mut target_option = Some(0usize); + (option_type_data.set_value)(&mut target_option, 5.into_lua(&lua).unwrap(), &lua).unwrap(); + assert_eq!( + target_option, + Some(5), + "Option set_value should set the value to Some(5)" + ); + + // setting an existing Some variant to nil should set the value to None + (option_type_data.set_value)(&mut target_option, Value::Nil, &lua).unwrap(); + assert_eq!( + target_option, None, + "Option set_value should set the value to None" + ); + + // setting a none variant should set the Some variant correctly + let mut target_option: Option = None; + (option_type_data.set_value)(&mut target_option, 5usize.into_lua(&lua).unwrap(), &lua) + .unwrap(); + assert_eq!( + target_option, + Some(5), + "Option set_value should set the value to None" + ); + + // setting a none variant to nil should stay as None + (option_type_data.set_value)(&mut target_option, Value::Nil, &lua).unwrap(); + assert_eq!( + target_option, None, + "Option set_value should set the value to None" + ); + } + + #[test] + fn test_option_lua_value_from_value() { + let mut app_type_registry = setup_type_registry::>(); + app_type_registry + .write() + .register_type_data::(); + + pre_register_common_containers(&mut app_type_registry); + + let type_registry = app_type_registry.read(); + let option_type_data = type_registry + .get_type_data::(std::any::TypeId::of::>()) + .unwrap(); + + // from_value should correctly work for concrete values + let lua = Lua::new(); + let value = 5usize; + let gotten_value = + (option_type_data.from_value)(value.into_lua(&lua).unwrap(), &lua).unwrap(); + + assert_eq!( + Some(value), + *gotten_value.try_downcast::>().unwrap(), + "Option from_value should correctly convert a value" + ); + + // from_value should correctly work for nil values + let nil_lua = Value::Nil; + let gotten_value = (option_type_data.from_value)(nil_lua, &lua).unwrap(); + assert_eq!( + None::, + *gotten_value.try_downcast::>().unwrap(), + "Option from_value should correctly convert a nil value" + ); + } + + #[test] + fn test_get_inner_type_id_option() { + let app_type_registry = setup_type_registry::>(); + + let type_registry = app_type_registry.read(); + let option_type_id = std::any::TypeId::of::>(); + let inner_type_id = std::any::TypeId::of::(); + let option_type_registration = type_registry.get(option_type_id).unwrap(); + + let (gotten_option_type_id, gotten_inner_type_id) = + destructure_option_type(option_type_registration).unwrap(); + assert_eq!( + gotten_inner_type_id, inner_type_id, + "Option should have inner type usize" + ); + assert_eq!( + gotten_option_type_id, option_type_id, + "Option should have type id Option" + ); + } +} diff --git a/examples/lua/bevy_api.rs b/examples/lua/bevy_api.rs index 0177101cb8..bbb8a7c382 100644 --- a/examples/lua/bevy_api.rs +++ b/examples/lua/bevy_api.rs @@ -17,35 +17,51 @@ pub struct MyComponent { option_vec3: Option, vec_of_option_bools: Vec>, option_vec_of_bools: Option>, + vec_of_usize: Vec, + option_usize: Option, } -fn load_script( - server: Res, - mut commands: Commands, - mut handle: Local>, -) { - let path = "scripts/bevy_api.lua"; - let handle_ = server.load::(path); - *handle = handle_; +const SCRIPT_NAME: &str = "scripts/bevy_api.lua"; - commands.spawn(ScriptComponent::new(vec![path.into()])); +fn load_script(server: Res, mut handle: Local>) { + let handle_ = server.load::(SCRIPT_NAME); + *handle = handle_; } fn init_data(mut commands: Commands) { - commands.spawn(MyComponent { - usize: 5, - vec2: Vec2::new(1.0, 2.0), - f32: 6.7, - mat3: Mat3::from_cols( - Vec3::new(1.0, 2.0, 3.0), - Vec3::new(4.0, 5.0, 6.0), - Vec3::new(7.0, 8.0, 9.0), - ), - quat: Quat::from_xyzw(1.0, 2.0, 3.0, 4.0), - option_vec3: None, - vec_of_option_bools: vec![Some(true), None, Some(false)], - option_vec_of_bools: Some(vec![true, true, true]), - }); + commands.spawn(( + MyComponent { + usize: 5, + vec2: Vec2::new(1.0, 2.0), + f32: 6.7, + mat3: Mat3::from_cols( + Vec3::new(1.0, 2.0, 3.0), + Vec3::new(4.0, 5.0, 6.0), + Vec3::new(7.0, 8.0, 9.0), + ), + quat: Quat::from_xyzw(1.0, 2.0, 3.0, 4.0), + option_vec3: None, + vec_of_option_bools: vec![Some(true), None, Some(false)], + option_vec_of_bools: Some(vec![true, true, true]), + vec_of_usize: vec![1, 2, 3], + option_usize: None, + }, + ScriptComponent::new(vec![SCRIPT_NAME.into()]), + )); +} + +struct EventCallbackLabel; +impl IntoCallbackLabel for EventCallbackLabel { + fn into_callback_label() -> CallbackLabel { + "on_event".into() + } +} + +pub fn send_event(mut writer: EventWriter>) { + writer.send(ScriptCallbackEvent::new_for_all( + EventCallbackLabel::into_callback_label(), + (), + )); } fn main() -> std::io::Result<()> { @@ -55,8 +71,14 @@ fn main() -> std::io::Result<()> { .add_plugins(LuaScriptingPlugin::<()>::default()) .add_plugins(LuaBevyScriptingPlugin) .register_type::() - // note the implementation for Option is there, but we must register `LuaProxyable` for it - .add_systems(Startup, (init_data, load_script)); + .add_systems(Startup, (init_data, load_script)) + .add_systems( + Update, + ( + send_event, + event_handler::.after(send_event), + ), + ); app.run(); From 60857bbc7fd4fd336d75a075ff24304a797ad5a2 Mon Sep 17 00:00:00 2001 From: makspll Date: Mon, 25 Nov 2024 08:27:24 +0000 Subject: [PATCH 20/22] register vec lua types FOR ALL THE TYPES BABY --- assets/scripts/bevy_api.lua | 12 +- .../src/reflection_extensions.rs | 18 +- .../bevy_mod_scripting_lua/src/type_data.rs | 334 +++++++++++++++--- .../bevy_mod_scripting_lua/tests/lua_tests.rs | 3 +- examples/lua/bevy_api.rs | 4 +- 5 files changed, 308 insertions(+), 63 deletions(-) diff --git a/assets/scripts/bevy_api.lua b/assets/scripts/bevy_api.lua index cefd120e61..f70bcc41cf 100644 --- a/assets/scripts/bevy_api.lua +++ b/assets/scripts/bevy_api.lua @@ -25,8 +25,8 @@ function on_event() print(comp.option_usize) comp.option_usize = nil print(comp.option_usize) - world:exit() + print("vec") print(comp.vec_of_usize) print(comp.vec_of_usize[2]) comp.vec_of_usize[2] = 69 @@ -35,16 +35,6 @@ function on_event() print("============") - -- the index metamethod on ReflectValue's uses bevy's reflection mechanism on top of some custom sub-reflection logic to - -- allow reflecting inside Options, Vectors etc. - -- when we index into ReflectValue's we either get back a custom proxy or another ReflectValue - - -- the LuaBevyAPIProvider provides us custom proxies for many bevy types as well as std types. - -- all of these implementations can be overridden via the bevy TypeRegistry - print("Hello:", comp.usize._1) - comp.usize[1] = 2 - print("comp.usize after assigning to 2: ", comp.usize._1) - -- vec's and matrices have custom __index and __newindex overrides print("comp.vec2 before: ", comp.vec2) comp.vec2[1] = 69 diff --git a/crates/bevy_mod_scripting_core/src/reflection_extensions.rs b/crates/bevy_mod_scripting_core/src/reflection_extensions.rs index 19ca2fa664..572f0245f6 100644 --- a/crates/bevy_mod_scripting_core/src/reflection_extensions.rs +++ b/crates/bevy_mod_scripting_core/src/reflection_extensions.rs @@ -14,6 +14,9 @@ pub trait PartialReflectExt { /// If the type is an option, returns either the inner value or None if the option is None. /// Errors if the type is not an option. fn as_option(&self) -> Result, ScriptError>; + + /// If the type is an iterable list-like type, returns an iterator over the elements. + fn as_list(&self) -> Result, ScriptError>; } impl PartialReflectExt for T { @@ -39,8 +42,6 @@ impl PartialReflectExt for T { Ok(()) } - /// If the type is an option, returns either the inner value or None if the option is None. - /// Errors if the type is not an option. fn as_option(&self) -> Result, ScriptError> { self.expect_type(Some("core"), "Option")?; @@ -54,6 +55,19 @@ impl PartialReflectExt for T { unreachable!("core::Option is an enum with a tuple variant") } + + fn as_list(&self) -> Result, ScriptError> { + if let bevy::reflect::ReflectRef::List(l) = self.reflect_ref() { + Ok(l.iter()) + } else { + Err(ScriptError::new_runtime_error(format!( + "Expected list-like type from crate core, but got {}", + self.get_represented_type_info() + .map(|ti| ti.type_path()) + .unwrap_or_else(|| "dynamic type with no type information") + ))) + } + } } #[cfg(test)] diff --git a/crates/languages/bevy_mod_scripting_lua/src/type_data.rs b/crates/languages/bevy_mod_scripting_lua/src/type_data.rs index 629fca061f..3c478cc5b4 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/type_data.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/type_data.rs @@ -9,9 +9,9 @@ use bevy::{ log::debug, prelude::{AppTypeRegistry, Mut}, reflect::{ - impl_reflect, DynamicEnum, DynamicTuple, DynamicVariant, FromType, GetTypeRegistration, - ParsedPath, PartialReflect, Reflect, ReflectFromReflect, ReflectPathError, TypePath, - TypeRegistration, + impl_reflect, DynamicEnum, DynamicList, DynamicTuple, DynamicVariant, FromType, + GetTypeRegistration, ParsedPath, PartialReflect, Reflect, ReflectFromReflect, + ReflectPathError, TypePath, TypeRegistration, }, }; use bevy_mod_scripting_core::{ @@ -153,6 +153,31 @@ pub struct ReflectLuaValue { } impl ReflectLuaValue { + fn dynamic_option_from_value<'lua>( + v: Value<'lua>, + lua: &'lua Lua, + from_value: &Arc< + dyn for<'l> Fn( + Value<'l>, + &'l Lua, + ) + -> Result, tealr::mlu::mlua::Error> + + Send + + Sync + + 'static, + >, + ) -> Result { + if v.is_nil() { + Ok(DynamicEnum::new("None", DynamicVariant::Unit)) + } else { + let inner = (from_value)(v, lua)?; + Ok(DynamicEnum::new( + "Some", + DynamicVariant::Tuple([inner].into_iter().collect()), + )) + } + } + /// generates implementation for an inner type wrapped by an option /// /// the option should check if the value is None if so return nil, @@ -176,32 +201,102 @@ impl ReflectLuaValue { .unwrap_or_else(|| Ok(Value::Nil)) }), set_value: Arc::new(move |r, v, l| { - if v.is_nil() { - r.apply(&DynamicEnum::new("None", DynamicVariant::Unit)); - } else { - r.apply(&DynamicEnum::new( - "Some", - DynamicVariant::Tuple([(from_value_clone)(v, l)?].into_iter().collect()), - )); - } + let dynamic = Self::dynamic_option_from_value(v, l, &from_value_clone)?; + r.apply(&dynamic); + Ok(()) }), from_value: Arc::new(move |v, l| { - let dynamic_option = if v.is_nil() { - DynamicEnum::new("None", DynamicVariant::Unit) - } else { - let inner = (from_value_clone2)(v, l)?; - DynamicEnum::new("Some", DynamicVariant::Tuple([inner].into_iter().collect())) - }; + let dynamic_option = Self::dynamic_option_from_value(v, l, &from_value_clone2)?; - let reflect_option = from_reflect_clone + from_reflect_clone .from_reflect(&dynamic_option) .ok_or_else(|| { tealr::mlu::mlua::Error::external(ScriptError::new_runtime_error( "Failed to convert to option", )) - })?; - Ok(reflect_option.into_partial_reflect()) + }) + .map(::into_partial_reflect) + }), + } + } + + fn dynamic_list_from_value<'lua>( + v: Value<'lua>, + lua: &'lua Lua, + from_value: &Arc< + dyn for<'l> Fn( + Value<'l>, + &'l Lua, + ) + -> Result, tealr::mlu::mlua::Error> + + Send + + Sync + + 'static, + >, + ) -> Result { + let table = if let Value::Table(t) = v { + t + } else { + return Err(tealr::mlu::mlua::Error::external( + ScriptError::new_runtime_error(format!( + "Cannot set value of type `{}` via type: `{}`. Expected table", + v.type_name(), + "List", + )), + )); + }; + + let lua_values = table.sequence_values().collect::, _>>()?; + + let converted_values = lua_values + .into_iter() + .map(|v| (from_value)(v, lua)) + .collect::, _>>()?; + + Ok(DynamicList::from_iter(converted_values)) + } + + pub fn new_for_list(inner_reflect_lua_value: &ReflectLuaValue) -> Self { + let into_value_clone = inner_reflect_lua_value.into_value.clone(); + let from_value_clone = inner_reflect_lua_value.from_value.clone(); + let from_value_clone2 = inner_reflect_lua_value.from_value.clone(); + // let vec_from_reflect = vec_from_reflect.clone(); + Self { + into_value: Arc::new(move |r, l| { + let inner = r.as_list().map_err(tealr::mlu::mlua::Error::external)?; + let inner = inner + .map(|i| (into_value_clone)(i, l)) + .collect::, _>>()?; + + l.create_table_from( + inner + .into_iter() + .enumerate() + .map(|(i, v)| (Value::Integer(i as i64 + 1), v)), + ) + .map(Value::Table) + }), + set_value: Arc::new(move |r, v, l| { + let dynamic = Self::dynamic_list_from_value(v, l, &from_value_clone)?; + r.apply(&dynamic); + Ok(()) + }), + from_value: Arc::new(move |v, l| { + let dynamic = Self::dynamic_list_from_value(v, l, &from_value_clone2)?; + + // vec_from_reflect + // .from_reflect(&dynamic) + // .ok_or_else(|| { + // tealr::mlu::mlua::Error::external(ScriptError::new_runtime_error( + // "Failed to convert to option", + // )) + // }) + // .map(::into_partial_reflect) + // TODO: testing this out, not returning a concrete type could be weird + // would anything but this impl care about this? + // Ok(Box::new(dynamic)) + Ok(Box::new(dynamic)) }), } } @@ -278,6 +373,21 @@ fn destructure_option_type(reg: &TypeRegistration) -> Option<(TypeId, TypeId)> { } } +fn destructure_vec_type(reg: &TypeRegistration) -> Option<(TypeId, TypeId)> { + let type_path_table = reg.type_info().type_path_table(); + let is_core = type_path_table.crate_name().is_some_and(|s| s == "alloc"); + let is_vec = type_path_table.ident().is_some_and(|s| s == "Vec"); + + if is_core && is_vec { + reg.type_info() + .generics() + .get_named("T") + .map(|t| (reg.type_id(), t.type_id())) + } else { + None + } +} + /// iterates over type data for all types which have registered [`ReflectLuaProxied`] and [`ReflectLuaValue`] implementations, /// and registers corresponding [`Option`] [`Result`] etc type data equivalents pub fn pre_register_common_containers(type_registry: &mut AppTypeRegistry) { @@ -294,7 +404,7 @@ pub fn pre_register_common_containers(type_registry: &mut AppTypeRegistry) { type_registry.get_type_data::(option_type_id) { let option_lua_proxied_data = - ReflectLuaValue::new_for_option(&inner_lua_value_data, &option_from_reflect); + ReflectLuaValue::new_for_option(inner_lua_value_data, option_from_reflect); lua_value_insertions.insert(option_type_id, option_lua_proxied_data); } @@ -314,6 +424,20 @@ pub fn pre_register_common_containers(type_registry: &mut AppTypeRegistry) { } } + for (vec_type_id, inner_type_id) in type_registry.iter().filter_map(destructure_vec_type) { + if let Some(inner_lua_value_data) = + type_registry.get_type_data::(inner_type_id) + { + // if let Some(vec_from_reflect) = + // type_registry.get_type_data::(vec_type_id) + // { + let vec_lua_value_data = ReflectLuaValue::new_for_list(inner_lua_value_data); + + lua_value_insertions.insert(vec_type_id, vec_lua_value_data); + // } + } + } + for (type_id, lua_value_data) in lua_value_insertions { type_registry .get_mut(type_id) @@ -381,38 +505,38 @@ mod tests { AppTypeRegistry(type_registry_arc) } + macro_rules! assert_transitively_registers { + ($target_type:ty, $container_type:ty, $type_data:ty) => {{ + let mut app_type_registry = setup_type_registry::<$target_type, $container_type>(); + app_type_registry + .write() + .register_type_data::<$target_type, $type_data>(); + + pre_register_common_containers(&mut app_type_registry); + + let type_registry = app_type_registry.read(); + let container_type_id = std::any::TypeId::of::<$container_type>(); + let container_type_registration = type_registry.get(container_type_id).unwrap(); + + let type_data = container_type_registration.contains::<$type_data>(); + assert!( + type_data, + "{:?} should have type data {:?}", + std::any::type_name::<$container_type>(), + std::any::type_name::<$type_data>() + ); + }}; + } + #[test] fn test_pre_register_common_containers_lua_value() { - let mut app_type_registry = setup_type_registry::>(); - app_type_registry - .write() - .register_type_data::(); - - pre_register_common_containers(&mut app_type_registry); - - let type_registry = app_type_registry.read(); - let option_type_id = std::any::TypeId::of::>(); - let option_type_registration = type_registry.get(option_type_id).unwrap(); - - let type_data = option_type_registration.contains::(); - assert!(type_data, "Option should have type data"); + assert_transitively_registers!(usize, Option, ReflectLuaValue); + assert_transitively_registers!(usize, Vec, ReflectLuaValue); } #[test] fn test_pre_register_common_containers_lua_proxy() { - let mut app_type_registry = setup_type_registry::>(); - app_type_registry - .write() - .register_type_data::(); - - pre_register_common_containers(&mut app_type_registry); - - let type_registry = app_type_registry.read(); - let option_type_id = std::any::TypeId::of::>(); - let option_type_registration = type_registry.get(option_type_id).unwrap(); - - let type_data = option_type_registration.contains::(); - assert!(type_data, "Option should have type data"); + assert_transitively_registers!(Proxied, Option, ReflectLuaProxied); } #[test] @@ -557,6 +681,42 @@ mod tests { ); } + #[test] + fn test_vec_lua_value_impl_into_value() { + let mut app_type_registry = setup_type_registry::>(); + app_type_registry + .write() + .register_type_data::(); + + pre_register_common_containers(&mut app_type_registry); + + let type_registry = app_type_registry.read(); + let option_type_data = type_registry + .get_type_data::(std::any::TypeId::of::>()) + .unwrap(); + let inner_type_data = type_registry + .get_type_data::(std::any::TypeId::of::()) + .unwrap(); + + // option::some into_value should be a table with the inner value converted to Lua + let lua = Lua::new(); + let value: usize = 5; + let option_value = vec![value]; + let expected_into_value = (inner_type_data.into_value)(&value, &lua).unwrap(); + let gotten_into_value = (option_type_data.into_value)(&option_value, &lua).unwrap(); + + assert_eq!( + expected_into_value, + gotten_into_value.as_table().unwrap().pop().unwrap(), + ); + + // an empty vec should be equivalent to an empty table + let vec_value: Vec = vec![]; + let gotten_into_value = (option_type_data.into_value)(&vec_value, &lua).unwrap(); + + assert!(gotten_into_value.as_table().unwrap().is_empty()); + } + #[test] fn test_option_lua_value_set_value() { let mut app_type_registry = setup_type_registry::>(); @@ -606,6 +766,47 @@ mod tests { ); } + #[test] + fn test_vec_lua_value_set_value() { + let mut app_type_registry = setup_type_registry::>(); + app_type_registry + .write() + .register_type_data::(); + + pre_register_common_containers(&mut app_type_registry); + + let type_registry = app_type_registry.read(); + let option_type_data = type_registry + .get_type_data::(std::any::TypeId::of::>()) + .unwrap(); + + // setting an existing vec + let lua = Lua::new(); + let new_vec = Value::Table( + lua.create_table_from(vec![(1, 5.into_lua(&lua).unwrap())]) + .unwrap(), + ); + let mut target_vec = vec![0usize]; + (option_type_data.set_value)(&mut target_vec, new_vec.clone(), &lua).unwrap(); + assert_eq!(target_vec, vec![5],); + + // setting an existing vec to an empty table should create a new empty vec + (option_type_data.set_value)( + &mut target_vec, + Value::Table( + lua.create_table_from(Vec::<(isize, usize)>::default()) + .unwrap(), + ), + &lua, + ) + .unwrap(); + assert_eq!(target_vec, Vec::::default(),); + + // setting an empty vec to a table with a value should set the vec to the value + (option_type_data.set_value)(&mut target_vec, new_vec, &lua).unwrap(); + assert_eq!(target_vec, vec![5],); + } + #[test] fn test_option_lua_value_from_value() { let mut app_type_registry = setup_type_registry::>(); @@ -642,6 +843,45 @@ mod tests { ); } + #[test] + fn test_vec_lua_value_from_value() { + let mut app_type_registry = setup_type_registry::>(); + app_type_registry + .write() + .register_type_data::(); + + pre_register_common_containers(&mut app_type_registry); + + let type_registry = app_type_registry.read(); + let option_type_data = type_registry + .get_type_data::(std::any::TypeId::of::>()) + .unwrap(); + + // from_value should correctly work for concrete values + let lua = Lua::new(); + let value = vec![5usize]; + let gotten_value = + (option_type_data.from_value)(value.into_lua(&lua).unwrap(), &lua).unwrap(); + + assert_eq!( + gotten_value + .as_list() + .unwrap() + .map(|v| *v.try_downcast_ref::().unwrap()) + .collect::>() + .pop(), + Some(5usize) + ); + + // from_value should correctly work for empty lists + let nil_lua = Value::Table( + lua.create_table_from(Vec::<(isize, usize)>::default()) + .unwrap(), + ); + let gotten_value = (option_type_data.from_value)(nil_lua, &lua).unwrap(); + assert!(gotten_value.as_list().unwrap().count() == 0); + } + #[test] fn test_get_inner_type_id_option() { let app_type_registry = setup_type_registry::>(); diff --git a/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs b/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs index 45f5d617fe..92f38d9b96 100644 --- a/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs +++ b/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs @@ -23,7 +23,8 @@ use bevy_mod_scripting_lua::{ }, lua_context_load, lua_handler, prelude::{Lua, LuaFunction, LuaHookTriggers}, - register_lua_values, LuaScriptingPlugin, ReflectLuaValue, + type_data::{register_lua_values, ReflectLuaValue}, + LuaScriptingPlugin, }; use libtest_mimic::{Arguments, Failed, Trial}; use std::{ diff --git a/examples/lua/bevy_api.rs b/examples/lua/bevy_api.rs index bbb8a7c382..5e496fd8a2 100644 --- a/examples/lua/bevy_api.rs +++ b/examples/lua/bevy_api.rs @@ -14,11 +14,11 @@ pub struct MyComponent { usize: usize, f32: f32, mat3: Mat3, + vec_of_usize: Vec, + option_usize: Option, option_vec3: Option, vec_of_option_bools: Vec>, option_vec_of_bools: Option>, - vec_of_usize: Vec, - option_usize: Option, } const SCRIPT_NAME: &str = "scripts/bevy_api.lua"; From e347a8b962ec28fe7f02cfe9ecae1510bad88bce Mon Sep 17 00:00:00 2001 From: makspll Date: Sun, 1 Dec 2024 20:52:50 +0000 Subject: [PATCH 21/22] improve type data, and add iterator to reflect ref --- .vscode/settings.json | 2 +- assets/scripts/bevy_api.lua | 19 +- crates/bevy_mod_scripting_core/Cargo.toml | 6 +- .../src/bindings/allocator.rs | 44 +- .../src/bindings/proxy.rs | 27 +- .../src/bindings/reference.rs | 193 +-- .../src/bindings/world.rs | 199 +-- crates/bevy_mod_scripting_core/src/error.rs | 43 +- .../src/reflection_extensions.rs | 229 +++- .../bevy_mod_scripting_lua/Cargo.toml | 2 +- .../src/bindings/query.rs | 2 +- .../src/bindings/reference.rs | 281 +++-- .../src/bindings/world.rs | 12 +- .../bevy_mod_scripting_lua/src/lib.rs | 2 +- .../bevy_mod_scripting_lua/src/type_data.rs | 1122 +++++++++-------- .../bevy_mod_scripting_lua/tests/lua_tests.rs | 2 +- examples/lua/bevy_api.rs | 2 + 17 files changed, 1306 insertions(+), 881 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 3c966b296b..980f809761 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,4 +24,4 @@ ], "rust-analyzer.showUnlinkedFileNotification": false, // "rust-analyzer.semanticHighlighting.operator.enable": false -} +} \ No newline at end of file diff --git a/assets/scripts/bevy_api.lua b/assets/scripts/bevy_api.lua index f70bcc41cf..c8748f0026 100644 --- a/assets/scripts/bevy_api.lua +++ b/assets/scripts/bevy_api.lua @@ -19,19 +19,26 @@ function on_event() local comp = world:get_component(entity, my_component_type) print("Before script: ", comp) - + print("\noption") print(comp.option_usize) comp.option_usize = 69 print(comp.option_usize) comp.option_usize = nil print(comp.option_usize) - print("vec") - print(comp.vec_of_usize) - print(comp.vec_of_usize[2]) - comp.vec_of_usize[2] = 69 + print("\nvec") + print(table_to_string(comp.vec_of_usize)) + comp.vec_of_usize = {42,69,72} + comp.vec_of_usize[1] = 0 print(comp.vec_of_usize[2]) - world:exit() + print(table_to_string(comp.vec_of_usize)) + comp.vec_of_usize = {} + print(table_to_string(comp.vec_of_usize)) + comp.vec_of_usize = comp.vec_of_usize2 + print(table_to_string(comp.vec_of_usize)) + comp.vec_of_usize = comp.vec_of_usize + print(table_to_string(comp.vec_of_usize)) + print("============") diff --git a/crates/bevy_mod_scripting_core/Cargo.toml b/crates/bevy_mod_scripting_core/Cargo.toml index c2bb18dcb8..45eac55116 100644 --- a/crates/bevy_mod_scripting_core/Cargo.toml +++ b/crates/bevy_mod_scripting_core/Cargo.toml @@ -19,14 +19,18 @@ path = "src/lib.rs" # if enabled enables documentation updating in optimized builds doc_always = [] +# if enabled enables some common mlua trait implementations +mlua_impls = ["mlua"] [dependencies] +mlua = { version = "0.9", optional = true } + bevy = { workspace = true, default-features = false, features = ["bevy_asset"] } thiserror = "1.0.31" paste = "1.0.7" parking_lot = "0.12.1" lockable = "0.0.8" smallvec = "1.11" - +itertools = "0.13" [dev-dependencies] test_utils = { workspace = true } diff --git a/crates/bevy_mod_scripting_core/src/bindings/allocator.rs b/crates/bevy_mod_scripting_core/src/bindings/allocator.rs index ef2c710a31..b338950ec2 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/allocator.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/allocator.rs @@ -62,28 +62,28 @@ impl ReflectAllocator { (id, value) } - /// Moves the given boxed [`PartialReflect`] value into the allocator, returning an [`AllocationId`] which can be used to access it later - pub fn allocate_boxed( - &mut self, - existing: Box, - ) -> (ReflectAllocationId, ReflectAllocation) { - let type_id = existing.get_represented_type_info().map(|i| i.type_id()); - let id = ReflectAllocationId(self.allocations.len()); - - let raw_ptr = Box::into_raw(existing); - // Safety: - // - we are the only ones to have access to this value since we have the Box - // - UnsafeCell is repr(transparent), meaning we can safely transmute between it and the trait object - // TODO: I don't think we can use this, because from_raw has a pre-condition that requires the pointer to have been an arc before - let arc: Arc> = - unsafe { Arc::from_raw(raw_ptr as *const _) }; - let allocation = ReflectAllocation::new(arc); - self.allocations.insert(id, allocation.clone()); - if let Some(type_id) = type_id { - self.types.insert(id, type_id); - } - (id, allocation) - } + // /// Moves the given boxed [`PartialReflect`] value into the allocator, returning an [`AllocationId`] which can be used to access it later + // pub fn allocate_boxed( + // &mut self, + // existing: Box, + // ) -> (ReflectAllocationId, ReflectAllocation) { + // let type_id = existing.get_represented_type_info().map(|i| i.type_id()); + // let id = ReflectAllocationId(self.allocations.len()); + + // let raw_ptr = Box::into_raw(existing); + // // Safety: + // // - we are the only ones to have access to this value since we have the Box + // // - UnsafeCell is repr(transparent), meaning we can safely transmute between it and the trait object + // // TODO: I don't think we can use this, because from_raw has a pre-condition that requires the pointer to have been an arc before + // let arc: Arc> = + // unsafe { Arc::from_raw(raw_ptr as *const _) }; + // let allocation = ReflectAllocation::new(arc); + // self.allocations.insert(id, allocation.clone()); + // if let Some(type_id) = type_id { + // self.types.insert(id, type_id); + // } + // (id, allocation) + // } pub fn get(&self, id: ReflectAllocationId) -> Option { self.allocations.get(&id).cloned() diff --git a/crates/bevy_mod_scripting_core/src/bindings/proxy.rs b/crates/bevy_mod_scripting_core/src/bindings/proxy.rs index 9bc77465a5..ce1002b537 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/proxy.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/proxy.rs @@ -186,14 +186,7 @@ where ) -> ScriptResult> { let reflect_ref: &ReflectReference = self.0.as_ref(); let access = reflect_ref.base.base_id.get_reflect_access_id(); - let access = guard - .get_access_timeout(access, DEFAULT_TIMEOUT, DEFAULT_INTERVAL) - .ok_or_else(|| { - ScriptError::new_reflection_error(format!( - "Could not unproxy type: `{}`. Aliasing access.", - std::any::type_name::() - )) - })?; + let access = guard.get_access_timeout(access, DEFAULT_TIMEOUT, DEFAULT_INTERVAL); let out = reflect_ref.reflect( guard.as_unsafe_world_cell(), &access, @@ -248,14 +241,7 @@ where ) -> ScriptResult<()> { let reflect_ref: &ReflectReference = self.0.as_ref(); let access = reflect_ref.base.base_id.get_reflect_access_id(); - let access = guard - .get_access_timeout(access, DEFAULT_TIMEOUT, DEFAULT_INTERVAL) - .ok_or_else(|| { - ScriptError::new_reflection_error(format!( - "Could not unproxy type: `{}`. Aliasing access.", - std::any::type_name::() - )) - })?; + let access = guard.get_access_timeout(access, DEFAULT_TIMEOUT, DEFAULT_INTERVAL); accesses.push(access); Ok(()) } @@ -309,14 +295,7 @@ where ) -> ScriptResult<()> { let reflect_ref: &ReflectReference = self.0.as_ref(); let access = reflect_ref.base.base_id.get_reflect_access_id(); - let access = guard - .get_access_timeout(access, DEFAULT_TIMEOUT, DEFAULT_INTERVAL) - .ok_or_else(|| { - ScriptError::new_reflection_error(format!( - "Could not unproxy type: `{}`. Aliasing access.", - std::any::type_name::() - )) - })?; + let access = guard.get_access_timeout(access, DEFAULT_TIMEOUT, DEFAULT_INTERVAL); accesses.push(access); Ok(()) } diff --git a/crates/bevy_mod_scripting_core/src/bindings/reference.rs b/crates/bevy_mod_scripting_core/src/bindings/reference.rs index 47ca7117c2..6860faa3d9 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/reference.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/reference.rs @@ -36,7 +36,7 @@ use smallvec::SmallVec; use crate::{ bindings::{ReflectAllocation, ReflectAllocationId}, - prelude::{ReflectAllocator, ScriptError, ScriptResult}, + prelude::{ReflectAllocator, ScriptError, ScriptResult}, reflection_extensions::TypeIdExtensions, }; use super::{ @@ -59,6 +59,11 @@ pub struct ReflectReference { impl ReflectReference { + /// Creates a new infinite iterator. This iterator will keep returning the next element reference forever. + pub fn into_iter_infinite(self) -> ReflectRefIter { + ReflectRefIter::new_indexed(self) + } + /// Prints the reference using the world to resolve type names. pub fn print_with_world(&self, world: &WorldAccessGuard) -> String { world.with_resource(|_, type_registry: Mut| { @@ -74,48 +79,29 @@ impl ReflectReference { } /// If this is a reference to something with a length accessible via reflection, returns that length. - pub fn len(&self, world: &WorldAccessGuard) -> Option { - world.with_resource(|world, type_registry: Mut| { - world.with_resource(|world, allocator: Mut| { - let type_registry = type_registry.read(); - self - .with_reflect(world, &type_registry, Some(&allocator), |r| { - match r.reflect_ref() { - bevy::reflect::ReflectRef::Struct(s) => Some(s.field_len()), - bevy::reflect::ReflectRef::TupleStruct(ts) => Some(ts.field_len()), - bevy::reflect::ReflectRef::Tuple(t) => Some(t.field_len()), - bevy::reflect::ReflectRef::List(l) => Some(l.len()), - bevy::reflect::ReflectRef::Array(a) => Some(a.len()), - bevy::reflect::ReflectRef::Map(m) => Some(m.len( )), - bevy::reflect::ReflectRef::Set(s) => Some(s.len()), - bevy::reflect::ReflectRef::Enum(e) => Some(e.field_len()), - bevy::reflect::ReflectRef::Opaque(_) => None, - } - }) + pub fn len(&self, world: &WorldAccessGuard) -> ScriptResult> { + self + .with_reflect(world, |r, _, _| { + match r.reflect_ref() { + bevy::reflect::ReflectRef::Struct(s) => Some(s.field_len()), + bevy::reflect::ReflectRef::TupleStruct(ts) => Some(ts.field_len()), + bevy::reflect::ReflectRef::Tuple(t) => Some(t.field_len()), + bevy::reflect::ReflectRef::List(l) => Some(l.len()), + bevy::reflect::ReflectRef::Array(a) => Some(a.len()), + bevy::reflect::ReflectRef::Map(m) => Some(m.len( )), + bevy::reflect::ReflectRef::Set(s) => Some(s.len()), + bevy::reflect::ReflectRef::Enum(e) => Some(e.field_len()), + bevy::reflect::ReflectRef::Opaque(_) => None, + } }) - }) } - pub fn new_allocated( + pub fn new_allocated( value: T, allocator: &mut ReflectAllocator, ) -> ReflectReference { + let type_id = value.get_represented_type_info().map(|i| i.type_id()).unwrap_or_else(|| panic!("Type '{}' has no represented type information to allocate with.", std::any::type_name::())); let (id, _) = allocator.allocate(value); - ReflectReference { - base: ReflectBaseType { - type_id: TypeId::of::(), - base_id: ReflectBase::Owned(id), - }, - reflect_path: Vec::default(), - } - } - - pub fn new_allocated_boxed( - value: Box, - allocator: &mut ReflectAllocator, - ) -> ReflectReference { - let type_id = value.get_represented_type_info().map(|i| i.type_id()).expect("Expected type info for boxed value"); - let (id, _) = allocator.allocate_boxed(value); ReflectReference { base: ReflectBaseType { type_id, @@ -132,61 +118,64 @@ impl ReflectReference { } /// A form of [`Self::reflect`] which does the access checks for you. - /// Panics if it waits for access too long to prevent deadlocks. - pub fn with_reflect O>( + #[track_caller] + pub fn with_reflect O>( &self, world: &WorldAccessGuard, - type_registry: &TypeRegistry, - allocator: Option<&ReflectAllocator>, f: F, - ) -> O { + ) -> ScriptResult { let access = world .get_access_timeout( self.base.base_id.get_reflect_access_id(), DEFAULT_TIMEOUT, DEFAULT_INTERVAL, - ) - .unwrap_or_else(|| panic!("Timeout when waiting for access for: `{:?}`", self)); - - let reflect = self - .reflect( - world.as_unsafe_world_cell(), - &access, - type_registry, - allocator, - ) - .unwrap(); - let o = f(reflect); + ); + + let out = world.with_allocator_and_type_registry(|_, type_registry, allocator| { + let type_registry = type_registry.read(); + let reflect = self + .reflect( + world.as_unsafe_world_cell(), + &access, + &type_registry, + Some(&allocator), + )?; + let o = f(reflect, &type_registry, &allocator); + + Ok(o) + }); + world.release_access(access); - o + out } - pub fn with_reflect_mut O>( + #[track_caller] + pub fn with_reflect_mut O>( &self, world: &WorldAccessGuard, - type_registry: &TypeRegistry, - allocator: Option<&ReflectAllocator>, f: F, - ) -> O { + ) -> ScriptResult { let mut access = world .get_access_timeout( self.base.base_id.get_reflect_access_id(), DEFAULT_TIMEOUT, DEFAULT_INTERVAL, - ) - .unwrap_or_else(|| panic!("Timeout when waiting for access for: `{:?}`", self)); - - let reflect = self - .reflect_mut( - world.as_unsafe_world_cell(), - &mut access, - type_registry, - allocator, - ) - .unwrap(); - let o = f(reflect); + ); + let out = world.with_allocator_and_type_registry(|_, type_registry, mut allocator| { + let type_registry = type_registry.read(); + let reflect = self + .reflect_mut( + world.as_unsafe_world_cell(), + &mut access, + &type_registry, + Some(&allocator), + )?; + let o = f(reflect, &type_registry, &mut allocator); + Ok(o) + }); + world.release_access(access); - o + out } /// Returns `Ok(())` if the given access is sufficient to read the value or an appropriate error otherwise @@ -566,3 +555,65 @@ impl PartialEq for DeferredReflection { } impl Eq for DeferredReflection {} + + +/// A generic iterator over any reflected value. +/// Unlike a normal iterator, this one does not have a halting condition, it will keep returning elements forever. +/// The iterator does not try to access the value, it just works out the next index/key to access. +/// You will know you've reached the end when you get an error when trying to access the next element. +#[derive(Debug,Clone)] +pub struct ReflectRefIter { + pub(crate) base: ReflectReference, + // TODO: support maps etc + pub(crate) index: IterationKey, +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum IterationKey { + Index(usize), +} + +impl ReflectRefIter { + pub fn new_indexed(base: ReflectReference) -> Self { + Self { base, index: IterationKey::Index(0) } + } + + pub fn index(&self) -> IterationKey { + self.index.clone() + } + + /// Returns the next element in the iterator, it does not have a halting condition + pub fn next_ref(&mut self) -> (ReflectReference, IterationKey) { + let index = self.index(); + let next = match &mut self.index { + IterationKey::Index(i) => { + let mut next = self.base.clone(); + let parsed_path = ParsedPath::parse(&format!("[{}]", *i)).expect("invariant violated"); + next.index_path(ReflectionPathElem::Reflection(parsed_path)); + *i += 1; + next + } + }; + (next, index) + } +} + +impl Iterator for ReflectRefIter { + type Item = Result; + + fn next(&mut self) -> Option { + let result: Result<_, _> = { + match &mut self.index { + IterationKey::Index(i) => { + let mut next = self.base.clone(); + let parsed_path = ParsedPath::parse(&i.to_string()).unwrap(); + next.index_path(ReflectionPathElem::Reflection(parsed_path)); + *i += 1; + Ok(next) + } + } + }; + + return Some(result); + } +} \ No newline at end of file diff --git a/crates/bevy_mod_scripting_core/src/bindings/world.rs b/crates/bevy_mod_scripting_core/src/bindings/world.rs index 2481ec4d4a..02e7f8f212 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/world.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/world.rs @@ -10,6 +10,7 @@ use std::{ any::TypeId, fmt::Debug, marker::PhantomData, + mem, sync::{ atomic::{AtomicUsize, Ordering}, Arc, Weak, @@ -248,12 +249,52 @@ pub type WorldAccessUnit<'w> = WorldAccessWrite<'w>; pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(5); pub const DEFAULT_INTERVAL: Duration = Duration::from_millis(10); +enum WorldAccessValue<'w> { + Free(WorldAccessWrite<'w>), + Locked(std::panic::Location<'static>), +} + +impl<'w> WorldAccessValue<'w> { + fn is_locked(&self) -> bool { + matches!(self, WorldAccessValue::Locked(_)) + } + + fn as_location(&self) -> Option> { + match self { + WorldAccessValue::Free(_) => None, + WorldAccessValue::Locked(location) => Some(*location), + } + } + + fn into_access(self) -> Option> { + match self { + WorldAccessValue::Free(access) => Some(access), + WorldAccessValue::Locked(_) => None, + } + } + + #[track_caller] + fn take(&mut self) -> Option> { + mem::replace( + self, + WorldAccessValue::Locked(*std::panic::Location::caller()), + ) + .into_access() + } +} + +impl<'w> From> for WorldAccessValue<'w> { + fn from(value: WorldAccessWrite<'w>) -> Self { + WorldAccessValue::Free(value) + } +} + /// Provides safe access to the world via [`WorldAccess`] permissions, which enforce aliasing rules at runtime in multi-thread environments #[derive(Clone)] pub struct WorldAccessGuard<'w> { pub cell: UnsafeWorldCell<'w>, // TODO: this is fairly hefty, explore other ways to hand out locks on WorldAccess - pub accesses: Arc>>>, + accesses: Arc>>, /// true if anybody has any access to the world pub accesses_count: Arc, // TODO can we track code/stack locations of things holding onto theese locks for debugging? @@ -282,7 +323,7 @@ impl<'w> WorldAccessGuard<'w> { .unwrap(); let val = val.value().unwrap(); - val.is_none() + val.is_locked() }) .collect() } @@ -308,6 +349,7 @@ impl<'w> WorldAccessGuard<'w> { self.cell.components().get_resource_id(id) } + #[track_caller] /// Checks nobody else is currently accessing the world, and if so locks access to it until /// [`release_whole_world_access`] is called. pub fn get_whole_world_access(&self) -> Option<&mut World> { @@ -325,6 +367,17 @@ impl<'w> WorldAccessGuard<'w> { self.accesses_count.fetch_sub(1, Ordering::Relaxed); } + pub fn get_access_location(&self, raid: ReflectAccessId) -> Option> { + let guard = self + .accesses + .blocking_lock(raid, lockable::SyncLimit::no_limit()) + .unwrap(); + let guard = guard.value().unwrap(); + + guard.as_location() + } + + #[track_caller] /// Tries to get access to the given reflect access id, if it's already given out returns `None`. If you want to wait for access, use [`WorldAccessGuard::get_access_timeout`] instead. /// Remember to release this access once done with [`WorldAccessGuard::release_access`] or nobody else will be able to access this id!. /// @@ -335,13 +388,14 @@ impl<'w> WorldAccessGuard<'w> { .blocking_lock(raid, lockable::SyncLimit::no_limit()) .unwrap(); let guard = guard.value_or_insert_with(|| { - Some(WorldAccessWrite { + WorldAccessWrite { raid, _ph: PhantomData, - }) + } + .into() }); - if guard.is_some() { + if !guard.is_locked() { self.accesses_count.fetch_add(1, Ordering::Relaxed); guard.take() } else { @@ -355,12 +409,13 @@ impl<'w> WorldAccessGuard<'w> { /// /// # Panic /// Will panic once access was not available after the timeout was reached + #[track_caller] pub fn get_access_timeout( &self, raid: ReflectAccessId, timeout: Duration, interval: Duration, - ) -> Option> { + ) -> WorldAccessUnit<'w> { let mut access = self.get_access(raid); let start = std::time::Instant::now(); @@ -368,10 +423,14 @@ impl<'w> WorldAccessGuard<'w> { std::thread::sleep(interval); access = self.get_access(raid); if start.elapsed() > timeout { - return None; + panic!( + "Timed out while waiting for access to {:?}. This is likely a deadlock. The access is being held by: {:?}", + raid, + self.get_access_location(raid) + ); } } - access + access.expect("invariant") } /// Releases access to the given reflect access id @@ -387,14 +446,15 @@ impl<'w> WorldAccessGuard<'w> { // should not be possible, we are the only ones who can instantiate WorldAccessUnit assert!( - guard.is_none(), + guard.is_locked(), "Invariant violated, an access has been released by someone else already who shouldn't have been able to do so" ); self.accesses_count.fetch_sub(1, Ordering::Relaxed); - *guard = Some(access); + *guard = WorldAccessValue::Free(access); } + #[track_caller] /// Get access to the given component_id, this is the only way to access a component/resource safely (in the context of the world access guard) /// since you can only access this component_id through a RwLock, there is no way to break aliasing rules. /// Additionally the 'w lifetime prevents you from storing this access outside the lifetime of the underlying cell @@ -406,6 +466,7 @@ impl<'w> WorldAccessGuard<'w> { self.get_access(access_id) } + #[track_caller] /// Similar to [`Self::get_component_access`] but typed, additionally panics if the component is not registered pub fn get_component_access_typed(&self) -> Option> { self.get_component_access( @@ -418,6 +479,7 @@ impl<'w> WorldAccessGuard<'w> { ) } + #[track_caller] /// Get access to the given component_id, this is the only way to access a component/resource safely (in the context of the world access guard) /// since you can only access this component_id through a RwLock, there is no way to break aliasing rules. /// Additionally the 'w lifetime prevents you from storing this access outside the lifetime of the underlying cell @@ -425,6 +487,7 @@ impl<'w> WorldAccessGuard<'w> { self.get_component_access(cid) } + #[track_caller] /// Similar to [`Self::get_resource_access`] but typed, additionally panics if the resource is not registered pub fn get_resource_access_typed(&self) -> Option> { self.get_resource_access( @@ -437,6 +500,7 @@ impl<'w> WorldAccessGuard<'w> { ) } + #[track_caller] /// Get access to the given allocation_id, this is the only way to access a script owned value safely (in the context of the world access guard) pub fn get_allocation_access(&self, id: ReflectAllocationId) -> Option> { let access_id = ReflectAccessId { @@ -446,6 +510,7 @@ impl<'w> WorldAccessGuard<'w> { self.get_access(access_id) } + #[track_caller] /// Provides access to a resource via callback. Panics if the resource does not exist or if waiting for access times out. pub fn with_resource) -> O>(&self, f: F) -> O { let cid = self @@ -454,14 +519,7 @@ impl<'w> WorldAccessGuard<'w> { .resource_id::() .unwrap_or_else(|| panic!("Resource not registered: `{}`", std::any::type_name::())); - let mut access = self - .get_access_timeout(cid.into(), DEFAULT_TIMEOUT, DEFAULT_INTERVAL) - .unwrap_or_else(|| { - panic!( - "Timed out while waiting for access to resource: `{}`", - std::any::type_name::() - ) - }); + let mut access = self.get_access_timeout(cid.into(), DEFAULT_TIMEOUT, DEFAULT_INTERVAL); let resource = self .get_resource_with_access_mut::(&mut access) @@ -472,6 +530,7 @@ impl<'w> WorldAccessGuard<'w> { out } + #[track_caller] /// Convenience to get commonly used resources at the same time. Internally identical to [`Self::with_resource`] pub fn with_allocator_and_type_registry< O, @@ -487,6 +546,7 @@ impl<'w> WorldAccessGuard<'w> { }) } + #[track_caller] /// Call a function on a type which can be proxied, first by unproxying the input with world access, /// then calling the function and finally proxying the output with the allocator. pub fn proxy_call<'i, O: Proxy, T: Unproxy, F: Fn(T::Output<'_>) -> O::Input<'i>>( @@ -521,6 +581,7 @@ impl<'w> WorldAccessGuard<'w> { Ok(proxied_output) } + #[track_caller] /// Get access to the given component, this is the only way to access a component/resource safely (in the context of the world access guard) pub fn get_component_with_access( &self, @@ -545,6 +606,7 @@ impl<'w> WorldAccessGuard<'w> { } } + #[track_caller] /// Get access to the given component, this is the only way to access a component/resource safely (in the context of the world access guard) pub fn get_component_with_access_mut( &self, @@ -569,6 +631,7 @@ impl<'w> WorldAccessGuard<'w> { } } + #[track_caller] /// Get access to the given resource pub fn get_resource_with_access( &self, @@ -592,6 +655,7 @@ impl<'w> WorldAccessGuard<'w> { } } + #[track_caller] /// Get access to the given resource, this is the only way to access a component/resource safely (in the context of the world access guard) pub fn get_resource_with_access_mut( &self, @@ -1105,25 +1169,20 @@ mod test { let world = world.read().unwrap(); // test read - world.with_resource(|world, allocator: Mut| { - world.with_resource(|world, type_registry: Mut| { - let type_registry = type_registry.read(); - ref_.with_reflect(world, &type_registry, Some(&allocator), |reflect| { - let orig = reflect.try_downcast_ref::(); - - let orig = match orig { - Some(v) => v, - None => { - panic!( - "Could not downcast value {reflect:?} to {}", - std::any::type_name::() - ) - } - }; - - assert_eq!(orig, &expected); - }) - }) + ref_.with_reflect(&world, |reflect, _, _| { + let orig = reflect.try_downcast_ref::(); + + let orig = match orig { + Some(v) => v, + None => { + panic!( + "Could not downcast value {reflect:?} to {}", + std::any::type_name::() + ) + } + }; + + assert_eq!(orig, &expected); }); assert!( @@ -1159,47 +1218,37 @@ mod test { WorldCallbackAccess::with_callback_access(&mut world, |world| { let world = world.read().unwrap(); // test set - world.with_resource(|world, allocator: Mut| { - world.with_resource(|world, type_registry: Mut| { - let type_registry = type_registry.read(); - ref_.with_reflect_mut(world, &type_registry, Some(&allocator), |reflect| { - let orig = reflect.try_downcast_mut::(); - - let orig = match orig { - Some(v) => v, - None => { - panic!( - "Could not downcast value {reflect:?} to {}", - std::any::type_name::() - ) - } - }; - - *orig = expected.clone(); - }) - }) + ref_.with_reflect_mut(&world, |reflect, _, _| { + let orig = reflect.try_downcast_mut::(); + + let orig = match orig { + Some(v) => v, + None => { + panic!( + "Could not downcast value {reflect:?} to {}", + std::any::type_name::() + ) + } + }; + + *orig = expected.clone(); }); // test read - world.with_resource(|world, allocator: Mut| { - world.with_resource(|world, type_registry: Mut| { - let type_registry = type_registry.read(); - ref_.with_reflect(world, &type_registry, Some(&allocator), |reflect| { - let orig = reflect.try_downcast_ref::(); - - let orig = match orig { - Some(v) => v, - None => { - panic!( - "Could not downcast value {reflect:?} to {}", - std::any::type_name::() - ) - } - }; - - assert_eq!(orig, &expected); - }) - }) + ref_.with_reflect(&world, |reflect, _, _| { + let orig = reflect.try_downcast_ref::(); + + let orig = match orig { + Some(v) => v, + None => { + panic!( + "Could not downcast value {reflect:?} to {}", + std::any::type_name::() + ) + } + }; + + assert_eq!(orig, &expected); }); post_check(&world); }); diff --git a/crates/bevy_mod_scripting_core/src/error.rs b/crates/bevy_mod_scripting_core/src/error.rs index 9bcdc9127c..e3a62864b8 100644 --- a/crates/bevy_mod_scripting_core/src/error.rs +++ b/crates/bevy_mod_scripting_core/src/error.rs @@ -3,7 +3,7 @@ use std::{ sync::Arc, }; -use bevy::reflect::Reflect; +use bevy::reflect::{ApplyError, Reflect}; use thiserror::Error; use crate::{bindings::ReflectAllocationId, bindings::ReflectReference}; @@ -144,38 +144,9 @@ impl std::fmt::Display for ScriptError { } } -// #[derive(Error, Debug, Clone)] -// pub enum ReflectionError { -// #[error("Base reference `{base}` is invalid. {reason}")] -// InvalidBaseReference { base: String, reason: String }, -// #[error("Cannot safely access `{base}`. {reason}")] -// InsufficientAccess { base: String, reason: String }, -// #[error("Tried to access `{base:?}` with insufficient provenance. {reason}")] -// InsufficientProvenance { -// base: ReflectReference, -// reason: String, -// }, -// #[error("Cannot downcast reference: {reference:?} to: {to}")] -// CannotDowncast { -// reference: ReflectReference, -// to: String, -// }, -// #[error("Could not assign `{rhs}` to `{lhs:?}`. {reason}")] -// InvalidAssignment { -// lhs: ReflectReference, -// rhs: String, -// reason: String, -// }, -// #[error("Failed to build concrete type from &Reflect type: `{ref_}`. Does this type have a FromReflect type data?")] -// FromReflectFailure { ref_: String }, -// #[error("Could not dereference script allocation with ID: {id}. {reason}")] -// AllocationError { -// id: ReflectAllocationId, -// reason: String, -// }, -// #[error("Attempted to access world via stale world reference. Did you store a reference to a world across a frame boundary?")] -// StaleWorldAccess, - -// #[error("{0}")] -// Other(String), -// } +#[cfg(feature = "mlua_impls")] +impl From for mlua::Error { + fn from(value: ScriptError) -> Self { + mlua::Error::external(value) + } +} diff --git a/crates/bevy_mod_scripting_core/src/reflection_extensions.rs b/crates/bevy_mod_scripting_core/src/reflection_extensions.rs index 572f0245f6..014a78ae19 100644 --- a/crates/bevy_mod_scripting_core/src/reflection_extensions.rs +++ b/crates/bevy_mod_scripting_core/src/reflection_extensions.rs @@ -1,4 +1,7 @@ -use bevy::reflect::PartialReflect; +use std::{any::TypeId, cmp::max}; + +use bevy::reflect::{List, PartialReflect}; +use itertools::Itertools; use crate::error::ScriptError; @@ -15,8 +18,35 @@ pub trait PartialReflectExt { /// Errors if the type is not an option. fn as_option(&self) -> Result, ScriptError>; + /// Similar to [`PartialReflectExt::as_option`] but for mutable references. + fn as_option_mut(&mut self) -> Result, ScriptError>; + /// If the type is an iterable list-like type, returns an iterator over the elements. fn as_list(&self) -> Result, ScriptError>; + + /// If the type is an iterable list-like type, sets the elements of the list to the elements of the other list-like type. + /// This acts as a set operation, so the left list will have the same length as the right list after this operation. + fn set_as_list< + F: Fn(&mut dyn PartialReflect, &dyn PartialReflect) -> Result<(), ScriptError>, + >( + &mut self, + other: Box, + apply: F, + ) -> Result<(), ScriptError>; + } + +pub trait TypeIdExtensions { + fn type_id_or_dummy(&self) -> TypeId; +} + +impl TypeIdExtensions for Option { + fn type_id_or_dummy(&self) -> TypeId { + struct UknownType; + match self { + Some(t) => *t, + None => TypeId::of::(), + } + } } impl PartialReflectExt for T { @@ -43,8 +73,6 @@ impl PartialReflectExt for T { } fn as_option(&self) -> Result, ScriptError> { - self.expect_type(Some("core"), "Option")?; - if let bevy::reflect::ReflectRef::Enum(e) = self.reflect_ref() { if let Some(field) = e.field_at(0) { return Ok(Some(field)); @@ -53,7 +81,29 @@ impl PartialReflectExt for T { } } - unreachable!("core::Option is an enum with a tuple variant") + Err(ScriptError::new_runtime_error(format!( + "Expected enum type, but got type which is not an enum: {}", + self.get_represented_type_info() + .map(|ti| ti.type_path()) + .unwrap_or_else(|| "dynamic type with no type information") + ))) + } + + fn as_option_mut(&mut self) -> Result, ScriptError> { + let type_info = self.get_represented_type_info().map(|ti| ti.type_path()); + match self.reflect_mut() { + bevy::reflect::ReflectMut::Enum(e) => { + if let Some(field) = e.field_at_mut(0) { + Ok(Some(field)) + } else { + Ok(None) + } + } + _ => Err(ScriptError::new_runtime_error(format!( + "Expected enum type, but got type which is not an enum: {}", + type_info.unwrap_or("dynamic type with no type information") + ))), + } } fn as_list(&self) -> Result, ScriptError> { @@ -68,8 +118,94 @@ impl PartialReflectExt for T { ))) } } + + fn set_as_list< + F: Fn(&mut dyn PartialReflect, &dyn PartialReflect) -> Result<(), ScriptError>, + >( + &mut self, + mut other: Box, + apply: F, + ) -> Result<(), ScriptError> { + match (self.reflect_mut(), other.reflect_mut()) { + (bevy::reflect::ReflectMut::List(l), bevy::reflect::ReflectMut::List(r)) => { + + let excess_elems = max(l.len() as isize - r.len() as isize, 0) as usize; + let to_be_inserted_elems = max(r.len() as isize - l.len() as isize, 0) as usize; + let apply_range = 0..(r.len() - to_be_inserted_elems); + + // remove in reverse order + (r.len()..l.len()).rev().for_each(|i| { + l.remove(i); + }); + + // pop then insert in reverse order of popping (last elem -> first elem to insert) + let to_insert = (0..to_be_inserted_elems).rev().map(|_| { + r.pop().expect("invariant") + }).collect::>(); + + to_insert.into_iter().rev().for_each(|e| { + l.push(e); + }); + + // at this point l is at least as long as r + + // apply to existing elements in the list + for i in apply_range { + apply(l.get_mut(i).expect("invariant"), r.get(i).expect("invariant"))?; + }; + + + + // for right_elem in r.iter() { + // if let Some(left_elem) = l.get_mut(i) { + // apply(left_elem, right_elem)? + // } else { + // shorter = true; + // break; + // } + // i+=1; + // }; + + + + Ok(()) + } + _ => Err(ScriptError::new_reflection_error(format!( + "Could not set {} with {}. Both need to reflect as list types, but at least one does not.", + self.reflect_type_path(), + other.reflect_type_path() + ))), + } + } + + // fn set_as_list>>( + // &mut self, + // other: I, + // ) -> Result<(), ScriptError> { + // if let bevy::reflect::ReflectMut::List(list) = self.reflect_mut() { + // let mut left_index = 0; + // for i in other { + // if let Some(left_item) = list.get_mut(left_index) { + // left_item.apply + // } else { + // } + // left_index += 1; + // } + // Ok(()) + // } else { + // Err(ScriptError::new_runtime_error(format!( + // "Expected list-like type from crate core, but got {}", + // self.get_represented_type_info() + // .map(|ti| ti.type_path()) + // .unwrap_or_else(|| "dynamic type with no type information") + // ))) + // } + // } } + + + #[cfg(test)] mod test { use super::*; @@ -123,4 +259,89 @@ mod test { 42.as_option().unwrap_err().to_string() ); } + + #[test] + fn test_as_list() { + let list = vec![1, 2, 3]; + let list_ref: &dyn PartialReflect = &list; + let iter = list_ref + .as_list() + .unwrap() + .map(|r| *r.try_downcast_ref::().unwrap()) + .collect::>(); + assert_eq!(list, iter); + } + + #[test] + fn test_set_as_list_equal_length() { + let mut list = vec![1, 2, 3]; + let other = vec![4, 5, 6]; + let other_ref: Box = Box::new(other.clone()); + list + .set_as_list(other_ref, |l, r| { + *l.try_downcast_mut::().unwrap() = *r.try_downcast_ref::().unwrap(); + Ok(()) + }) + .unwrap(); + assert_eq!(other, list); + } + + + #[test] + fn test_set_as_list_shortening() { + let mut list = vec![1, 2, 3]; + let other = vec![4, 5]; + let other_ref: Box = Box::new(other.clone()); + list + .set_as_list(other_ref, |l, r| { + *l.try_downcast_mut::().unwrap() = *r.try_downcast_ref::().unwrap(); + Ok(()) + }) + .unwrap(); + assert_eq!(other, list); + } + + #[test] + fn test_set_as_list_lengthening() { + let mut list = vec![1, 2]; + let other = vec![4, 5, 6]; + let other_ref: Box = Box::new(other.clone()); + list + .set_as_list(other_ref, |l, r| { + *l.try_downcast_mut::().unwrap() = *r.try_downcast_ref::().unwrap(); + Ok(()) + }) + .unwrap(); + assert_eq!(other, list); + } + + + #[test] + fn test_set_as_list_empty() { + let mut list = vec![1, 2]; + let other = Vec::::default(); + let other_ref: Box = Box::new(other.clone()); + list + .set_as_list(other_ref, |l, r| { + *l.try_downcast_mut::().unwrap() = *r.try_downcast_ref::().unwrap(); + Ok(()) + }) + .unwrap(); + assert_eq!(other, list); + } + + + #[test] + fn test_set_as_list_targe_empty() { + let mut list = Vec::::default(); + let other = vec![1]; + let other_ref: Box = Box::new(other.clone()); + list + .set_as_list(other_ref, |l, r| { + *l.try_downcast_mut::().unwrap() = *r.try_downcast_ref::().unwrap(); + Ok(()) + }) + .unwrap(); + assert_eq!(other, list); + } } diff --git a/crates/languages/bevy_mod_scripting_lua/Cargo.toml b/crates/languages/bevy_mod_scripting_lua/Cargo.toml index be2b581d5e..3b2e9b0d2f 100644 --- a/crates/languages/bevy_mod_scripting_lua/Cargo.toml +++ b/crates/languages/bevy_mod_scripting_lua/Cargo.toml @@ -40,7 +40,7 @@ path = "src/lib.rs" [dependencies] bevy = { workspace = true, default-features = false } -bevy_mod_scripting_core = { workspace = true } +bevy_mod_scripting_core = { workspace = true, features = ["mlua_impls"] } bevy_mod_scripting_derive = { path = "../../bevy_mod_scripting_derive" } tealr = { version = "0.9", features = [ "mlua_vendored", diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/query.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/query.rs index da545e2483..5e5b1d0cfb 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/query.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/query.rs @@ -76,7 +76,7 @@ impl TealData for LuaQueryBuilder { ); methods.add_function("iter", |l, this: LuaQueryBuilder| { - let world = l.get_world()?; + let world = l.get_world(); let mut result = world .query(this.0) .map_err(tealr::mlu::mlua::Error::external)?; diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs index 52c3734a16..ea2fe5e40d 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs @@ -9,16 +9,20 @@ use bevy::{ }; use bevy_mod_scripting_core::{ bindings::{ - ReflectAllocator, ReflectReference, ReflectionPathElem, Unproxy, WorldCallbackAccess, + ReflectAllocator, ReflectRefIter, ReflectReference, ReflectionPathElem, Unproxy, + WorldCallbackAccess, }, error::ScriptError, }; use tealr::mlu::{ + generics::Q, mlua::{self, FromLua, IntoLua, Lua, MetaMethod, UserData, Value}, - TealData, + TealData, TypedFunction, }; -use crate::{impl_userdata_from_lua, ReflectLuaProxied, ReflectLuaValue}; +use crate::{ + impl_userdata_from_lua, impl_userdata_with_tealdata, ReflectLuaProxied, ReflectLuaValue, +}; use super::{ proxy::{LuaProxied, LuaValProxy}, @@ -38,8 +42,10 @@ impl AsRef for LuaReflectReference { impl LuaReflectReference { pub fn len(&self, lua: &Lua) -> Result, mlua::Error> { - let world = lua.get_world()?; - Ok(self.0.len(&world)) + let world = lua.get_world(); + self.0 + .len(&world) + .map_err(tealr::mlu::mlua::Error::external) } /// Queries the reflection system for a proxy registration for the underlying type. @@ -47,123 +53,100 @@ impl LuaReflectReference { /// If not found will use ::into_lua to convert to lua pub fn to_lua_proxy(self, lua: &Lua) -> Result, mlua::Error> { // note we do not need to refer to LuaWorld here, it does not matter what the proxy is, that's pretty neat, - let world = lua.get_world()?; + let world = lua.get_world(); // TODO: i don't like the pingponging between errors here, need something more ergonomic - let result: Result = - world.with_resource(|world, type_registry: Mut| { - world.with_resource(|world, allocator: Mut| { - let type_registry = type_registry.read(); - - // first we need the type id of the pointed to object to figure out how to work with it - let type_id = - self.0 - .with_reflect(world, &type_registry, Some(&allocator), |r| { - r.get_represented_type_info().map(|t| t.type_id()) - }); - - // convenience, ideally we probably should just avoid lookups when no type id is here, but for now we just use a dummy type nothing will ever - // be registered for. If the type we're reflecting doesn't represent anything or a registered type, we use a generic reflect reference. - struct Dummy; - let type_id_or_dummy = type_id.unwrap_or(TypeId::of::()); - - if let Some(type_data) = - type_registry.get_type_data::(type_id_or_dummy) - { - self.0 - .with_reflect(world, &type_registry, Some(&allocator), |r| { - Ok((type_data.into_value)(r, lua)?) - }) - } else if let Some(type_data) = - type_registry.get_type_data::(type_id_or_dummy) - { - Ok((type_data.into_proxy)(self.0.clone(), lua)?) - } else { - Ok(self.clone().into_lua(lua)?) - } - }) - }); - result.map_err(mlua::Error::external) + // first we need the type id of the pointed to object to figure out how to work with it + let type_id = self.0.with_reflect(&world, |r, _, _| { + r.get_represented_type_info().map(|t| t.type_id()) + })?; + + // convenience, ideally we probably should just avoid lookups when no type id is here, but for now we just use a dummy type nothing will ever + // be registered for. If the type we're reflecting doesn't represent anything or a registered type, we use a generic reflect reference. + struct Dummy; + let type_id_or_dummy = type_id.unwrap_or(TypeId::of::()); + + if let Some(type_data) = world.with_resource::(|_, type_registry| { + type_registry + .read() + .get_type_data::(type_id_or_dummy) + .cloned() + }) { + self.0 + .with_reflect(&world, |r, _, _| (type_data.into_value)(r, lua))? + } else if let Some(type_data) = + world.with_resource::(|_, type_registry| { + type_registry + .read() + .get_type_data::(type_id_or_dummy) + .cloned() + }) + { + Ok((type_data.into_proxy)(self.0.clone(), lua)?) + } else { + Ok(self.clone().into_lua(lua)?) + } } pub fn set_with_lua_proxy(&self, lua: &Lua, value: Value) -> Result<(), mlua::Error> { bevy::log::debug!("Setting lua reflect reference with value: {:?}", value); - let world = lua.get_world()?; - let result: Result<(), ScriptError> = - world.with_resource(|world, type_registry: Mut| { - world.with_resource(|world, allocator: Mut| { + let world = lua.get_world(); + let type_id = self.0.with_reflect(&world, |r, _, _| { + r.get_represented_type_info().map(|t| t.type_id()) + })?; + + // convenience, ideally we probably should just avoid lookups when no type id is here, but for now we just use a dummy type nothing will ever + // be registered for. If the type we're reflecting doesn't represent anything or a registered type, we use a generic reflect reference. + struct Unknown; + let type_id_or_dummy = type_id.unwrap_or(TypeId::of::()); + + if let Some(type_data) = world.with_resource::(|_, type_registry| { + type_registry + .read() + .get_type_data::(type_id_or_dummy) + .cloned() + }) { + bevy::log::debug!("Setting value with ReflectLuaValue registration"); + let other = (type_data.from_value)(value, lua)?; + let o = self + .0 + .with_reflect_mut(&world, |r, _, _| r.try_apply(other.as_partial_reflect()))?; + } else if let Some(type_data) = + world.with_resource::(|_, type_registry| { + type_registry + .read() + .get_type_data::(type_id_or_dummy) + .cloned() + }) + { + bevy::log::debug!("Setting value with ReflectLuaProxied registration"); + let other = (type_data.from_proxy)(value, lua)?; + let other = other.with_reflect(&world, |r, _, _| r.clone_value())?; + // now we can set it + self.0.with_reflect_mut(&world, |r, _, _| { + if let Some(set) = type_data.opt_set { + set(r, other) + } else { + r.try_apply(other.as_partial_reflect()) + .map_err(ScriptError::new_reflection_error)?; + Ok(()) + } + })??; + } else { + bevy::log::debug!("No registration found, throwing error"); + // we don't know how to assign the value + // prod to see if it's a common container (i.e. Option or Vec) + world.with_resource::(|_,type_registry| { let type_registry = type_registry.read(); - let type_id = - self.0 - .with_reflect(world, &type_registry, Some(&allocator), |r| { - r.get_represented_type_info().map(|t| t.type_id()) - }); - - // convenience, ideally we probably should just avoid lookups when no type id is here, but for now we just use a dummy type nothing will ever - // be registered for. If the type we're reflecting doesn't represent anything or a registered type, we use a generic reflect reference. - struct Unknown; - let type_id_or_dummy = type_id.unwrap_or(TypeId::of::()); - bevy::log::debug!("Target type is {:?}", type_registry.get_type_info(type_id_or_dummy).map(|t| t.type_path())); - - if let Some(type_data) = - type_registry.get_type_data::(type_id_or_dummy) - { - bevy::log::debug!("Setting value with ReflectLuaValue registration"); - self.0 - .with_reflect_mut(world, &type_registry, Some(&allocator), |r| { - Ok((type_data.set_value)(r, value, lua)?) - }) - } else if let Some(type_data) = - type_registry.get_type_data::(type_id_or_dummy) - { - bevy::log::debug!("Setting value with ReflectLuaProxied registration"); - - let other = (type_data.from_proxy)(value, lua)?; - - // first we need to get a copy of the other value - let other = other - .with_reflect(world, &type_registry, Some(&allocator), |r| { - type_registry - .get_type_data::(type_id_or_dummy) - .and_then(|from_reflect_td| from_reflect_td.from_reflect(r)) - }) - .ok_or_else(|| { - ScriptError::new_reflection_error(format!( - "Failed to call ReflectFromReflect for type id: {:?}", - type_registry - .get_type_info(type_id_or_dummy) - .map(|t| t.type_path()) - )) - })?; - - // now we can set it - self.0 - .with_reflect_mut(world, &type_registry, Some(&allocator), |r| { - r.try_apply(other.as_partial_reflect()).map_err(|e| { - ScriptError::new_runtime_error(format!( - "Invalid assignment `{:?}` = `{:?}`. {e}.", - self.0.print_with_type_registry(&type_registry), - e, - )) - }) - })?; - Ok(()) - } else { - bevy::log::debug!("No registration found, throwing error"); - // we don't know how to assign the value - // prod to see if it's a common container (i.e. Option or Vec) - - Err(ScriptError::new_runtime_error(format!( - "Invalid assignment `{:?}` = `{:?}`. The underlying type does: `{}` not support assignment.", - self.0.print_with_type_registry(&type_registry), - value, - type_registry.get_type_info(type_id_or_dummy).map(|t| t.type_path()).unwrap_or_else(|| "Unknown") - ))) - } - }) - }); - - result.map_err(mlua::Error::external) + Err(ScriptError::new_runtime_error(format!( + "Invalid assignment `{:?}` = `{:?}`. The underlying type does: `{}` not support assignment.", + self.0.print_with_type_registry(&type_registry), + value, + type_registry.get_type_info(type_id_or_dummy).map(|t| t.type_path()).unwrap_or_else(|| "Unknown") + ))) + })?; + }; + Ok(()) } /// Adjusts all the numeric accesses in the path from 1-indexed to 0-indexed @@ -210,7 +193,6 @@ impl LuaReflectReference { } } } - impl_userdata_from_lua!(LuaReflectReference); impl LuaProxied for ReflectReference { @@ -229,26 +211,47 @@ impl From for LuaReflectReference { } } +#[derive(Debug, Clone, tealr::mlu::UserData, tealr::ToTypename)] +pub struct LuaReflectRefIter(pub ReflectRefIter); +impl_userdata_from_lua!(LuaReflectRefIter); + +impl TealData for LuaReflectRefIter { + fn add_methods<'lua, T: tealr::mlu::TealDataMethods<'lua, Self>>(_methods: &mut T) {} + + fn add_fields<'lua, F: tealr::mlu::TealDataFields<'lua, Self>>(_fields: &mut F) {} +} + impl TealData for LuaReflectReference { fn add_methods<'lua, T: tealr::mlu::TealDataMethods<'lua, Self>>(m: &mut T) { m.add_meta_function( MetaMethod::Index, |l, (mut self_, key): (LuaReflectReference, Value)| { + bevy::log::debug!( + "ReflectReference::Index with key: {:?} and value: {:?}", + key, + self_ + ); // catchall, parse the path let mut elem = Self::parse_value_index(key)?; Self::to_host_index(&mut elem); self_.0.index_path(elem); + bevy::log::debug!("Target reflect reference after indexing key: {:?}", self_.0); self_.to_lua_proxy(l) }, ); m.add_meta_function( MetaMethod::NewIndex, |l, (mut self_, key, value): (LuaReflectReference, Value, Value)| { + bevy::log::debug!( + "ReflectReference::NewIndex with key: {:?} and value: {:?}", + key, + value + ); + let mut elem = Self::parse_value_index(key)?; - bevy::log::debug!("New index with parsed path: {:?}", elem); Self::to_host_index(&mut elem); self_.0.index_path(elem); - bevy::log::debug!("New reflect reference after: {:?}", self_.0); + bevy::log::debug!("Target reflect reference after indexing key: {:?}", self_.0); self_.set_with_lua_proxy(l, value) }, ); @@ -257,8 +260,46 @@ impl TealData for LuaReflectReference { self_.len(l) }); + #[cfg(any( + feature = "lua54", + feature = "lua53", + feature = "lua52", + feature = "luajit52", + ))] + m.add_meta_function(MetaMethod::Pairs, |l, s: LuaReflectReference| { + bevy::log::debug!("ReflectReference::Pairs with value: {:?}", s); + let mut iterator_base = s.0.into_iter_infinite(); + let iterator = TypedFunction::from_rust_mut( + move |l, ()| { + let (next_ref, idx) = iterator_base.next_ref(); + bevy::log::debug!("iteration: {:?}", idx); + let next = LuaReflectReference(next_ref).to_lua_proxy(l); + let next = match next { + Ok(n) => Some(n), + Err(e) => { + bevy::log::debug!("Error in iteration: {:?}", e); + None + } + }; + bevy::log::debug!("next: {:?}", next); + // TODO: we should differentiate between no more values and an actual error + match (next, idx) { + (None, bevy_mod_scripting_core::bindings::IterationKey::Index(_)) => { + Ok((Value::Nil, Value::Nil)) + } + (Some(n), bevy_mod_scripting_core::bindings::IterationKey::Index(i)) => { + Ok((Value::Integer((i + 1) as i64), n)) + } + } + }, + l, + )?; + + Ok((iterator, Value::Nil, Value::Nil)) + }); + m.add_meta_function(MetaMethod::ToString, |lua, self_: LuaReflectReference| { - let world = lua.get_world()?; + let world = lua.get_world(); Ok(self_.0.print_with_world(&world)) }); } @@ -327,7 +368,7 @@ mod test { let reflect_ref = LuaReflectReference(ReflectReference::new_allocated(val, &mut allocator)); world.insert_resource(allocator); - WorldCallbackAccess::with_callback_access(&mut world, |access| { + WorldCallbackAccess::with_callback_access(world, |access| { let globals = lua.globals(); globals.set("test", reflect_ref.clone()).unwrap(); globals.set("world", LuaWorld(access.clone())).unwrap(); diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs index 4c954d86f9..b817776c3f 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/world.rs @@ -397,7 +397,7 @@ impl TealData for LuaWorld { }, ); - methods.add_method("exit", |_, this, ()| { + methods.add_method("exit", |lua, this, ()| { // TODO: somehow end control flow on lua side let world = this.0.read().ok_or_else(|| { mlua::Error::external(ScriptError::new_reflection_error("Stale world access")) @@ -424,11 +424,12 @@ impl From<&LuaWorld> for WorldCallbackAccess { } pub trait GetWorld { - fn get_world(&self) -> Result>, mlua::Error>; + fn get_world(&self) -> Arc>; + fn try_get_world(&self) -> Result>, mlua::Error>; } impl GetWorld for mlua::Lua { - fn get_world(&self) -> Result>, mlua::Error> { + fn try_get_world(&self) -> Result>, mlua::Error> { self.globals() .get::<_, LuaValProxy>("world")? .unproxy() @@ -439,4 +440,9 @@ impl GetWorld for mlua::Lua { }) .map_err(mlua::Error::external) } + + fn get_world(&self) -> Arc> { + self.try_get_world() + .expect("global 'world' did not exist or was invalid. Cannot retrieve world") + } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/lib.rs b/crates/languages/bevy_mod_scripting_lua/src/lib.rs index c163b6027b..bbe60977e8 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/lib.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/lib.rs @@ -68,7 +68,7 @@ impl Plugin for LuaScriptingPlugin { self.scripting_plugin.build(app); register_lua_values(app); app.add_context_pre_handling_initializer::<()>(|script_id, entity, context: &mut Lua| { - let world = context.get_world().unwrap(); + let world = context.get_world(); let lua_entity = world.with_resource::(|_, mut allocator| { let reflect_reference = ReflectReference::new_allocated(entity, &mut allocator); ::Proxy::from(reflect_reference) diff --git a/crates/languages/bevy_mod_scripting_lua/src/type_data.rs b/crates/languages/bevy_mod_scripting_lua/src/type_data.rs index 3c478cc5b4..d046750c51 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/type_data.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/type_data.rs @@ -1,5 +1,6 @@ use std::{ - any::TypeId, + any::{Any, TypeId}, + clone, collections::{HashMap, HashSet}, sync::Arc, }; @@ -10,8 +11,8 @@ use bevy::{ prelude::{AppTypeRegistry, Mut}, reflect::{ impl_reflect, DynamicEnum, DynamicList, DynamicTuple, DynamicVariant, FromType, - GetTypeRegistration, ParsedPath, PartialReflect, Reflect, ReflectFromReflect, - ReflectPathError, TypePath, TypeRegistration, + GetTypeRegistration, List, ParsedPath, PartialReflect, Reflect, ReflectFromReflect, + ReflectMut, ReflectPathError, TypeInfo, TypePath, TypeRegistration, }, }; use bevy_mod_scripting_core::{ @@ -19,15 +20,16 @@ use bevy_mod_scripting_core::{ error::ScriptError, reflection_extensions::PartialReflectExt, }; -use tealr::mlu::mlua::{FromLua, IntoLua, Lua, Value}; +use tealr::mlu::mlua::{FromLua, IntoLua, Lua, Table, Value}; -use crate::bindings::{proxy::LuaProxied, world::GetWorld}; +use crate::bindings::{proxy::LuaProxied, reference::LuaReflectReference, world::GetWorld}; /// Stores the procedure used to convert a lua value to a reflect value and vice versa, Used for types which are represented in lua via proxies which store /// a reference to the actual value. /// This is used for types which are represented in lua with pass by reference semantics #[derive(Clone)] pub struct ReflectLuaProxied { + // TODO: should these be script errors? pub into_proxy: Arc< dyn for<'l> Fn(ReflectReference, &'l Lua) -> Result, tealr::mlu::mlua::Error> + Send @@ -40,34 +42,38 @@ pub struct ReflectLuaProxied { + Sync + 'static, >, + /// Optional override for setting behavior, should be respected by all handling types for unproxying to work recurively. + /// Normally used when [`PartialReflect::apply`] does not do the right thing. + pub opt_set: Option< + Arc< + dyn for<'l> Fn( + &mut dyn PartialReflect, + Box, + ) -> Result<(), ScriptError> + + Send + + Sync + + 'static, + >, + >, } impl ReflectLuaProxied { /// Generates a type data which can be used on [`Option`] types which are represented in lua with pass by reference semantics - fn new_for_option( - inner_lua_proxied_data: &ReflectLuaProxied, - option_from_reflect: &ReflectFromReflect, - ) -> Self { + fn new_for_option(inner_lua_proxied_data: &ReflectLuaProxied, container_type_info: &'static TypeInfo) -> Self { let ref_into_option = |mut r: ReflectReference| { r.index_path(ParsedPath::parse_static("0").expect("Invalid reflection path")); r }; let into_proxy_clone = inner_lua_proxied_data.into_proxy.clone(); let from_proxy_clone = inner_lua_proxied_data.from_proxy.clone(); - let option_from_reflect = option_from_reflect.clone(); + // let from_proxy_clone = inner_lua_proxied_data.from_proxy.clone(); Self { into_proxy: Arc::new(move |reflect_ref, l| { // read the value and check if it is None, if so return nil // otherwise use the inner type's into_proxy - let world = l.get_world()?; - let is_some = world - .with_allocator_and_type_registry(|_, type_registry, allocator| { - let type_registry = type_registry.read(); - reflect_ref.with_reflect(&world, &type_registry, Some(&allocator), |s| { - s.as_option().map(|r| r.is_some()) - }) - }) - .map_err(tealr::mlu::mlua::Error::external)?; + let world = l.get_world(); + let is_some = reflect_ref + .with_reflect(&world, |s, _, _| s.as_option().map(|r| r.is_some()))??; if is_some { (into_proxy_clone)(ref_into_option(reflect_ref), l) @@ -77,33 +83,169 @@ impl ReflectLuaProxied { }), from_proxy: Arc::new(move |v, l| { if v.is_nil() { + bevy::log::debug!("Option from proxy: Nil"); // we need to allocate a new reflect reference since we don't have one existing - let dynamic_value = DynamicEnum::new("None", DynamicVariant::Unit); - - let world = l.get_world()?; + let mut dynamic_value = DynamicEnum::new("None", DynamicVariant::Unit); + dynamic_value.set_represented_type(Some(container_type_info)); + let world = l.get_world(); let reflect_ref = - world.with_resource(|w, mut allocator: Mut| { - let value = option_from_reflect - .from_reflect(&dynamic_value) - .ok_or_else(|| { - tealr::mlu::mlua::Error::external( - ScriptError::new_reflection_error(""), - ) - })? - .into_partial_reflect(); - Ok::<_, tealr::mlu::mlua::Error>(ReflectReference::new_allocated_boxed( - value, + world.with_resource(|_, mut allocator: Mut| { + Ok::<_, tealr::mlu::mlua::Error>(ReflectReference::new_allocated( + dynamic_value, &mut allocator, )) })?; Ok(reflect_ref) } else { + bevy::log::debug!("Option from proxy: {:?}", v); let mut inner_ref = (from_proxy_clone)(v, l)?; inner_ref.reflect_path.pop(); Ok(inner_ref) } }), + opt_set: None, + } + } + + fn dynamic_list_from_value<'lua>( + v: Table<'lua>, + lua: &'lua Lua, + from_proxy: &Arc< + dyn for<'l> Fn( + Value<'l>, + &'l Lua, + ) + -> Result, tealr::mlu::mlua::Error> + + Send + + Sync + + 'static, + >, + container_type_info: &'static TypeInfo + ) -> Result { + let lua_values = v.sequence_values().collect::, _>>()?; + + let converted_values = lua_values + .into_iter() + .map(|v| (from_proxy)(v, lua)) + .collect::, _>>()?; + + let mut dynamic_type = DynamicList::from_iter(converted_values); + dynamic_type.set_represented_type(Some(container_type_info)); + Ok(dynamic_type) + } + + fn dynamic_list_from_proxy<'lua>( + v: Table<'lua>, + lua: &'lua Lua, + from_proxy: &Arc< + dyn for<'l> Fn(Value<'l>, &'l Lua) -> Result + + Send + + Sync + + 'static, + >, + container_type_info: &'static TypeInfo, + ) -> Result { + let lua_values = v.sequence_values().collect::, _>>()?; + + // TODO: less allocations plz, i can't be bothered to do this right now + let converted_values = lua_values + .into_iter() + .map(|v| (from_proxy)(v, lua)) + .collect::, _>>()?; + let world = lua.get_world(); + + let boxed_values = converted_values + .into_iter() + .map(|v| v.with_reflect(&world, |r, _, _| r.clone_value())) + .collect::, _>>()?; + + let mut dynamic_type = DynamicList::from_iter(boxed_values); + // TODO: what to do with this memory, I think it's fine to leave hanging till exit + dynamic_type.set_represented_type(Some(container_type_info)); + Ok(dynamic_type) + } + + fn new_for_listlike_value( + inner_lua_value_data: &ReflectLuaValue, + container_type_info: &'static TypeInfo, + ) -> Self { + let from_value_clone = inner_lua_value_data.from_value.clone(); + Self { + into_proxy: Arc::new(|r, l| LuaReflectReference(r).into_lua(l)), + from_proxy: Arc::new(move |v, l| { + if let Value::Table(t) = v { + let dynamic_table = Self::dynamic_list_from_value(t, l, &from_value_clone, container_type_info)?; + let world = l.get_world(); + let allocated = + world.with_resource(|_, mut allocator: Mut| { + ReflectReference::new_allocated(dynamic_table, &mut allocator) + }); + Ok(allocated) + } else { + LuaReflectReference::from_lua(v, l).map(|v| v.0) + } + }), + opt_set: Some(Arc::new(|r, other| { + r.set_as_list(other, |a, b| { + Ok(a.try_apply(b)?) + }) + })), + } + } + + fn new_for_listlike_proxy(inner_lua_proxied_data: &ReflectLuaProxied) -> Self { + // let from_proxy_clone = inner_lua_proxied_data.from_proxy.clone(); + Self { + into_proxy: Arc::new(|r, l| LuaReflectReference(r).into_lua(l)), + // from_proxy: Arc::new(|v, l| { + // // if it's a table, set existing elements using underlying from proxy + // // if it's a ref, return the ref + + // if let Value::Table(t) = v { + // let ts = t.sequence_values::(); + // for e in ts { + // let v = e?; + // let elem_ref = (from_proxy_clone)(v, l)?; + // } + // } else { + // LuaReflectReference::from_lua(v, l) + // } + // }), + from_proxy: Arc::new(|v, l| { + // can either be a table or a direct ref + // construct dynamic vec either way + // if let Value::Table(t) = v { + // for v in t.sequence_values::() { + // let lua_elem = v?; + // } + // } else { + // todo!() + // } + todo!() + }), + opt_set: todo!(), // set_from_proxy: todo!(), // set_from_proxy: Arc::new(|r, v, l| { + // // let table = if let Value::Table(t) = v { + // // t + // // } else { + // // return Err(tealr::mlu::mlua::Error::external( + // // ScriptError::new_runtime_error(format!( + // // "Cannot set value of type `{}` via type: `{}`. Expected table", + // // v.type_name(), + // // "List", + // // )), + // // )); + // // }; + + // // let lua_values = table.sequence_values().collect::, _>>()?; + + // // let converted_values = lua_values + // // .into_iter() + // // .map(|v| (from_proxy)(v, lua)) + // // .collect::, _>>()?; + + // // let target_list = r.as_list().map_err(tealr::mlu::mlua::Error::external)?; + // // }), } } } @@ -117,6 +259,16 @@ where Self { into_proxy: Arc::new(|p, l| T::Proxy::from(p).into_lua(l)), from_proxy: Arc::new(|v, l| T::Proxy::from_lua(v, l).map(|p| p.as_ref().clone())), + opt_set: None, + // set_from_proxy: Arc::new(|r, v, l| { + // let proxy = T::Proxy::from_lua(v, l).map(|p| p.as_ref().clone())?; + // let world = l.get_world(); + // proxy.with_reflect(&world, |other, _, _| { + // r.apply(other); + // Ok::<_, tealr::mlu::mlua::Error>(()) + // })?; + // Ok(()) + // }), } } } @@ -131,16 +283,16 @@ pub struct ReflectLuaValue { + Sync + 'static, >, - pub set_value: Arc< - dyn for<'l> Fn( - &mut dyn PartialReflect, - Value<'l>, - &'l Lua, - ) -> Result<(), tealr::mlu::mlua::Error> - + Send - + Sync - + 'static, - >, + // pub set_value: Arc< + // dyn for<'l> Fn( + // &mut dyn PartialReflect, + // Value<'l>, + // &'l Lua, + // ) -> Result<(), tealr::mlu::mlua::Error> + // + Send + // + Sync + // + 'static, + // >, pub from_value: Arc< dyn for<'l> Fn( Value<'l>, @@ -166,16 +318,18 @@ impl ReflectLuaValue { + Sync + 'static, >, + container_type_info: &'static TypeInfo, ) -> Result { - if v.is_nil() { - Ok(DynamicEnum::new("None", DynamicVariant::Unit)) + let mut dynamic_enum = if v.is_nil() { + DynamicEnum::new("None", DynamicVariant::Unit) } else { let inner = (from_value)(v, lua)?; - Ok(DynamicEnum::new( - "Some", - DynamicVariant::Tuple([inner].into_iter().collect()), - )) - } + DynamicEnum::new("Some", DynamicVariant::Tuple([inner].into_iter().collect())) + }; + + dynamic_enum.set_represented_type(Some(container_type_info)); + + Ok(dynamic_enum) } /// generates implementation for an inner type wrapped by an option @@ -184,15 +338,10 @@ impl ReflectLuaValue { /// if the value is some use ReflectLuaValue implementation of the inner type. /// /// If there is a type mismatch at any point will return an error - pub fn new_for_option( - inner_reflect_lua_value: &ReflectLuaValue, - option_from_reflect: &ReflectFromReflect, - ) -> Self { + pub fn new_for_option(inner_reflect_lua_value: &ReflectLuaValue, container_type_info: &'static TypeInfo) -> Self { let into_value_clone = inner_reflect_lua_value.into_value.clone(); // we have to do this so the closures can be moved into the arc - let from_value_clone = inner_reflect_lua_value.from_value.clone(); let from_value_clone2 = inner_reflect_lua_value.from_value.clone(); - let from_reflect_clone = option_from_reflect.clone(); Self { into_value: Arc::new(move |r, lua| { r.as_option() @@ -200,106 +349,100 @@ impl ReflectLuaValue { .map(|inner| (into_value_clone)(inner, lua)) .unwrap_or_else(|| Ok(Value::Nil)) }), - set_value: Arc::new(move |r, v, l| { - let dynamic = Self::dynamic_option_from_value(v, l, &from_value_clone)?; - r.apply(&dynamic); - - Ok(()) - }), from_value: Arc::new(move |v, l| { - let dynamic_option = Self::dynamic_option_from_value(v, l, &from_value_clone2)?; - - from_reflect_clone - .from_reflect(&dynamic_option) - .ok_or_else(|| { - tealr::mlu::mlua::Error::external(ScriptError::new_runtime_error( - "Failed to convert to option", - )) - }) - .map(::into_partial_reflect) - }), - } - } + let dynamic_option = Self::dynamic_option_from_value(v, l, &from_value_clone2, container_type_info)?; - fn dynamic_list_from_value<'lua>( - v: Value<'lua>, - lua: &'lua Lua, - from_value: &Arc< - dyn for<'l> Fn( - Value<'l>, - &'l Lua, - ) - -> Result, tealr::mlu::mlua::Error> - + Send - + Sync - + 'static, - >, - ) -> Result { - let table = if let Value::Table(t) = v { - t - } else { - return Err(tealr::mlu::mlua::Error::external( - ScriptError::new_runtime_error(format!( - "Cannot set value of type `{}` via type: `{}`. Expected table", - v.type_name(), - "List", - )), - )); - }; - - let lua_values = table.sequence_values().collect::, _>>()?; - - let converted_values = lua_values - .into_iter() - .map(|v| (from_value)(v, lua)) - .collect::, _>>()?; - - Ok(DynamicList::from_iter(converted_values)) - } - - pub fn new_for_list(inner_reflect_lua_value: &ReflectLuaValue) -> Self { - let into_value_clone = inner_reflect_lua_value.into_value.clone(); - let from_value_clone = inner_reflect_lua_value.from_value.clone(); - let from_value_clone2 = inner_reflect_lua_value.from_value.clone(); - // let vec_from_reflect = vec_from_reflect.clone(); - Self { - into_value: Arc::new(move |r, l| { - let inner = r.as_list().map_err(tealr::mlu::mlua::Error::external)?; - let inner = inner - .map(|i| (into_value_clone)(i, l)) - .collect::, _>>()?; - - l.create_table_from( - inner - .into_iter() - .enumerate() - .map(|(i, v)| (Value::Integer(i as i64 + 1), v)), - ) - .map(Value::Table) - }), - set_value: Arc::new(move |r, v, l| { - let dynamic = Self::dynamic_list_from_value(v, l, &from_value_clone)?; - r.apply(&dynamic); - Ok(()) - }), - from_value: Arc::new(move |v, l| { - let dynamic = Self::dynamic_list_from_value(v, l, &from_value_clone2)?; - - // vec_from_reflect - // .from_reflect(&dynamic) - // .ok_or_else(|| { - // tealr::mlu::mlua::Error::external(ScriptError::new_runtime_error( - // "Failed to convert to option", - // )) - // }) - // .map(::into_partial_reflect) - // TODO: testing this out, not returning a concrete type could be weird - // would anything but this impl care about this? - // Ok(Box::new(dynamic)) - Ok(Box::new(dynamic)) + Ok(Box::new(dynamic_option)) }), + // set_value: Arc::new(move |r, v, l| { + // let dynamic = Self::dynamic_option_from_value(v, l, &from_value_clone)?; + // r.apply(&dynamic); + // Ok(()) + // }), } } + + // fn dynamic_list_from_value<'lua>( + // v: Value<'lua>, + // lua: &'lua Lua, + // from_value: &Arc< + // dyn for<'l> Fn( + // Value<'l>, + // &'l Lua, + // ) + // -> Result, tealr::mlu::mlua::Error> + // + Send + // + Sync + // + 'static, + // >, + // ) -> Result { + // let table = if let Value::Table(t) = v { + // t + // } else { + // return Err(tealr::mlu::mlua::Error::external( + // ScriptError::new_runtime_error(format!( + // "Cannot set value of type `{}` via type: `{}`. Expected table", + // v.type_name(), + // "List", + // )), + // )); + // }; + + // let lua_values = table.sequence_values().collect::, _>>()?; + + // let converted_values = lua_values + // .into_iter() + // .map(|v| (from_value)(v, lua)) + // .collect::, _>>()?; + // let dynamic_type = DynamicList::from_iter(converted_values); + // // TODO: set the represented type, need to pass type info + // // dynamic_type.set_represented_type(represented_type); + // Ok(dynamic_type) + // } + + // pub fn new_for_list(inner_reflect_lua_value: &ReflectLuaValue) -> Self { + // let into_value_clone = inner_reflect_lua_value.into_value.clone(); + // let from_value_clone = inner_reflect_lua_value.from_value.clone(); + // let from_value_clone2 = inner_reflect_lua_value.from_value.clone(); + // Self { + // into_value: Arc::new(move |r, l| { + // let inner = r.as_list().map_err(tealr::mlu::mlua::Error::external)?; + // let inner = inner + // .map(|i| (into_value_clone)(i, l)) + // .collect::, _>>()?; + + // let t = l.create_table_from( + // inner + // .into_iter() + // .enumerate() + // .map(|(i, v)| (Value::Integer(i as i64 + 1), v)), + // )?; + + // Ok(Value::Table(t)) + // }), + // set_value: Arc::new(move |r, v, l| { + // let dynamic = Self::dynamic_list_from_value(v, l, &from_value_clone)?; + + // // apply will not remove excess elements + // if let ReflectMut::List(list) = r.reflect_mut() { + // if dynamic.len() < list.len() { + // (dynamic.len()..list.len()).rev().for_each(|i| { + // list.remove(i); + // }); + // } + // } + // println!("reflect: {:?}", r); + // println!("dynamic: {:?}", dynamic); + + // r.apply(&dynamic); + // Ok(()) + // }), + // from_value: Arc::new(move |v, l| { + // let dynamic = Self::dynamic_list_from_value(v, l, &from_value_clone2)?; + // Ok(Box::new(dynamic)) + // }), + // } + // } } impl IntoLua<'l> + for<'l> FromLua<'l>> FromType @@ -307,13 +450,27 @@ impl IntoLua<'l> + for<'l> FromLua<'l>> FromType { fn from_type() -> Self { Self { - into_value: Arc::new(|v, l| v.try_downcast_ref::().unwrap().clone().into_lua(l)), - set_value: Arc::new(|t, v, l| { - let t = t.try_downcast_mut::().unwrap(); - *t = T::from_lua(v, l)?; - Ok(()) + into_value: Arc::new(|v, l| { + bevy::log::debug!("Converting lua value to lua: {:?}", v); + v.try_downcast_ref::() + .unwrap_or_else(|| { + panic!( + "Expected type: {}, got: {}", + std::any::type_name::(), + v.reflect_type_path() + ) + }) + .clone() + .into_lua(l) }), + // set_value: Arc::new(|t, v, l| { + // bevy::log::debug!("Setting lua value: {:?}, with {:?}", t, v); + // let t = t.try_downcast_mut::().unwrap(); + // *t = T::from_lua(v, l)?; + // Ok(()) + // }), from_value: Arc::new(|v, l| { + bevy::log::debug!("Building concrete type from lua value: {:?}", v); T::from_lua(v, l).map(|v| Box::new(v) as Box) }), } @@ -373,19 +530,11 @@ fn destructure_option_type(reg: &TypeRegistration) -> Option<(TypeId, TypeId)> { } } -fn destructure_vec_type(reg: &TypeRegistration) -> Option<(TypeId, TypeId)> { - let type_path_table = reg.type_info().type_path_table(); - let is_core = type_path_table.crate_name().is_some_and(|s| s == "alloc"); - let is_vec = type_path_table.ident().is_some_and(|s| s == "Vec"); +fn destructure_list_type(reg: &TypeRegistration) -> Option<(TypeId, TypeId)> { + let type_path_table = reg.type_info().as_list().ok()?; - if is_core && is_vec { - reg.type_info() - .generics() - .get_named("T") - .map(|t| (reg.type_id(), t.type_id())) - } else { - None - } + let inner_type_id = type_path_table.item_ty().id(); + Some((reg.type_id(), inner_type_id)) } /// iterates over type data for all types which have registered [`ReflectLuaProxied`] and [`ReflectLuaValue`] implementations, @@ -397,44 +546,32 @@ pub fn pre_register_common_containers(type_registry: &mut AppTypeRegistry) { let mut lua_proxied_insertions: HashMap = Default::default(); for (option_type_id, inner_type_id) in type_registry.iter().filter_map(destructure_option_type) { + let container_type_info = type_registry.get(option_type_id).expect("invariant").type_info(); + // TODO: reuse the leaked box in both branches when either is true if let Some(inner_lua_value_data) = type_registry.get_type_data::(inner_type_id) { - if let Some(option_from_reflect) = - type_registry.get_type_data::(option_type_id) - { - let option_lua_proxied_data = - ReflectLuaValue::new_for_option(inner_lua_value_data, option_from_reflect); - - lua_value_insertions.insert(option_type_id, option_lua_proxied_data); - } + let option_lua_proxied_data = ReflectLuaValue::new_for_option(inner_lua_value_data, Box::leak(Box::new(container_type_info.clone()))); + lua_value_insertions.insert(option_type_id, option_lua_proxied_data); } if let Some(inner_lua_proxied_data) = type_registry.get_type_data::(inner_type_id) { - if let Some(option_from_reflect) = - type_registry.get_type_data::(option_type_id) - { - let option_lua_proxied_data = - ReflectLuaProxied::new_for_option(inner_lua_proxied_data, option_from_reflect); + let option_lua_proxied_data = ReflectLuaProxied::new_for_option(inner_lua_proxied_data, Box::leak(Box::new(container_type_info.clone()))); - lua_proxied_insertions.insert(option_type_id, option_lua_proxied_data); - } + lua_proxied_insertions.insert(option_type_id, option_lua_proxied_data); } } - for (vec_type_id, inner_type_id) in type_registry.iter().filter_map(destructure_vec_type) { + for (vec_type_id, inner_type_id) in type_registry.iter().filter_map(destructure_list_type) { + let container_type_info = type_registry.get(vec_type_id).expect("invariant").type_info(); if let Some(inner_lua_value_data) = type_registry.get_type_data::(inner_type_id) { - // if let Some(vec_from_reflect) = - // type_registry.get_type_data::(vec_type_id) - // { - let vec_lua_value_data = ReflectLuaValue::new_for_list(inner_lua_value_data); - - lua_value_insertions.insert(vec_type_id, vec_lua_value_data); - // } + let vec_lua_proxied_data = + ReflectLuaProxied::new_for_listlike_value(inner_lua_value_data, Box::leak(Box::new(container_type_info.clone()))); + lua_proxied_insertions.insert(vec_type_id, vec_lua_proxied_data); } } @@ -483,7 +620,7 @@ mod tests { use bevy_mod_scripting_core::bindings::WorldCallbackAccess; use std::sync::Arc; - #[derive(Reflect)] + #[derive(Reflect, Debug, PartialEq)] struct Proxied(usize); impl LuaProxied for Proxied { @@ -505,16 +642,29 @@ mod tests { AppTypeRegistry(type_registry_arc) } - macro_rules! assert_transitively_registers { + macro_rules! prepare_type_registry_with_common_containers { ($target_type:ty, $container_type:ty, $type_data:ty) => {{ - let mut app_type_registry = setup_type_registry::<$target_type, $container_type>(); - app_type_registry - .write() - .register_type_data::<$target_type, $type_data>(); + { + let mut type_registry = setup_type_registry::<$target_type, $container_type>(); + type_registry + .write() + .register_type_data::<$target_type, $type_data>(); - pre_register_common_containers(&mut app_type_registry); + pre_register_common_containers(&mut type_registry); + type_registry + } + }}; + } - let type_registry = app_type_registry.read(); + macro_rules! assert_transitively_registers { + ($target_type:ty = $inner_type_data:ty, $container_type:ty = $type_data:ty) => {{ + let type_registry = prepare_type_registry_with_common_containers!( + $target_type, + $container_type, + $inner_type_data + ); + + let type_registry = type_registry.read(); let container_type_id = std::any::TypeId::of::<$container_type>(); let container_type_registration = type_registry.get(container_type_id).unwrap(); @@ -528,358 +678,302 @@ mod tests { }}; } - #[test] - fn test_pre_register_common_containers_lua_value() { - assert_transitively_registers!(usize, Option, ReflectLuaValue); - assert_transitively_registers!(usize, Vec, ReflectLuaValue); - } + macro_rules! assert_lua_value_into_equals { + ($target_type:ty, $container_type:ty, $type_data:ty, $val:expr => $exp:expr) => {{ + let type_registry = prepare_type_registry_with_common_containers!( + $target_type, + $container_type, + $type_data + ); - #[test] - fn test_pre_register_common_containers_lua_proxy() { - assert_transitively_registers!(Proxied, Option, ReflectLuaProxied); + let type_registry = type_registry.read(); + let container_type_id = std::any::TypeId::of::<$container_type>(); + let container_type_data = type_registry + .get_type_data::<$type_data>(container_type_id) + .unwrap(); + let l = Lua::new(); + let out = (container_type_data.into_value)(&$val, &l).unwrap(); + assert_eq!(out, $exp); + }}; } - #[test] - fn test_option_lua_proxy_impl_into_proxy() { - let mut app_type_registry = setup_type_registry::>(); - app_type_registry - .write() - .register_type_data::(); - let mut world = World::default(); - - pre_register_common_containers(&mut app_type_registry); - - let type_registry = app_type_registry.read(); - let option_type_data = type_registry - .get_type_data::(std::any::TypeId::of::>()) - .unwrap() - .clone(); - let inner_type_data = type_registry - .get_type_data::(std::any::TypeId::of::()) - .unwrap() - .clone(); - - let mut allocator = ReflectAllocator::default(); - let inner_value = ReflectReference::new_allocated(Proxied(4), &mut allocator); - let some_value = ReflectReference::new_allocated(Some(Proxied(4)), &mut allocator); - let none_value = ReflectReference::new_allocated(None::, &mut allocator); - world.insert_resource(allocator); - drop(type_registry); - world.insert_resource(app_type_registry); - - let lua = Lua::new(); - WorldCallbackAccess::with_callback_access(&mut world, |world| { - lua.globals().set("world", LuaWorld(world.clone())).unwrap(); - - // option::some into_proxy should be equivalent result to inner_type into_proxy apart from the reflect path - let expected_into_value = (inner_type_data.into_proxy)(inner_value, &lua).unwrap(); - let gotten_into_value = (option_type_data.into_proxy)(some_value, &lua).unwrap(); - - let converted_into_value = LuaReflectReference::from_lua(expected_into_value, &lua) - .unwrap() - .0 - .reflect_path; - - let mut converted_gotten_into_value = - LuaReflectReference::from_lua(gotten_into_value, &lua) - .unwrap() - .0 - .reflect_path; - converted_gotten_into_value.pop(); - - assert_eq!( - converted_into_value, converted_gotten_into_value, - "Option into_proxy should be equivalent to Proxied into_proxy for Some variant apart from the last element in the path" + macro_rules! assert_lua_container_value_from_equals { + ($target_type:ty, $container_type:ty, $type_data:ty, $val:expr => $exp:expr) => {{ + let type_registry = prepare_type_registry_with_common_containers!( + $target_type, + $container_type, + $type_data ); - // the none variant should be equivalent to Value::Nil - let expected_into_value = Value::Nil; - let gotten_into_value = (option_type_data.into_proxy)(none_value, &lua).unwrap(); + let type_registry = type_registry.read(); + let container_type_id = std::any::TypeId::of::<$container_type>(); + let container_type_data = type_registry + .get_type_data::<$type_data>(container_type_id) + .unwrap(); + let l = Lua::new(); + let out = (container_type_data.from_value)($val, &l).unwrap(); + assert!(out.reflect_partial_eq(&$exp).unwrap()); + }}; + } - assert_eq!( - expected_into_value, gotten_into_value, - "Option into_proxy should be equivalent to Value::Nil for None variant" + // macro_rules! assert_lua_container_value_after_set_equals { + // ($target_type:ty, $container_type:ty, $type_data:ty, $val:expr => $set:expr => $exp:expr) => {{ + // let type_registry = prepare_type_registry_with_common_containers!( + // $target_type, + // $container_type, + // $type_data + // ); + + // let type_registry = type_registry.read(); + // let container_type_id = std::any::TypeId::of::<$container_type>(); + // let container_type_data = type_registry + // .get_type_data::<$type_data>(container_type_id) + // .unwrap(); + // let l = Lua::new(); + // let mut target = $val; + // (container_type_data.set_value)(&mut target, $set, &l).unwrap(); + // assert!( + // target.reflect_partial_eq(&$exp).unwrap(), + // "Expected {:?} got: {:?}", + // $exp, + // target + // ); + // }}; + // } + + macro_rules! assert_lua_container_proxy_into_proxy { + (;WITH; $target_type:ty = $inner_type_data:ty, $container_type:ty = $type_data:ty ;FROM; $val:expr ;INTO; $exp:expr) => {{ + let app_type_registry = prepare_type_registry_with_common_containers!( + $target_type, + $container_type, + $inner_type_data ); - }) + let mut world = World::new(); + + let type_registry = app_type_registry.read(); + let container_type_id = std::any::TypeId::of::<$container_type>(); + let container_type_data = type_registry + .get_type_data::<$type_data>(container_type_id) + .unwrap() + .clone(); + + let mut allocator = ReflectAllocator::default(); + let allocated_value = ReflectReference::new_allocated($val, &mut allocator); + world.insert_resource(allocator); + drop(type_registry); + world.insert_resource(app_type_registry); + let lua = Lua::new(); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + lua.globals().set("world", LuaWorld(world.clone())).unwrap(); + + let gotten_into_value = + (container_type_data.into_proxy)(allocated_value, &lua).unwrap(); + let converted_ref = LuaReflectReference::from_lua(gotten_into_value.clone(), &lua) + .expect(&format!( + "Could not convert to lua reflect reference got: {:?}", + gotten_into_value + )) + .0; + let world = world.read().unwrap(); + converted_ref.with_reflect(&world, |r, _, _| { + assert!( + r.reflect_partial_eq(&$exp).unwrap(), + "Expected {:?} got {:?}", + $exp, + r + ); + }); + }); + }}; } - #[test] - fn test_option_lua_proxy_impl_from_proxy() { - let mut app_type_registry = setup_type_registry::>(); - app_type_registry - .write() - .register_type_data::(); - let mut world = World::default(); + macro_rules! assert_lua_container_proxy_opt_set { + ($allocator:ident, $lua:ident ;WITH; $target_type:ty = $inner_type_data:ty, $container_type:ty = $type_data:ty ;SET; $val:expr ;TO; $set:expr ;EXPECT; $exp:expr) => {{ + let app_type_registry = prepare_type_registry_with_common_containers!( + $target_type, + $container_type, + $inner_type_data + ); + let mut world = World::new(); - pre_register_common_containers(&mut app_type_registry); + let type_registry = app_type_registry.read(); + let container_type_id = std::any::TypeId::of::<$container_type>(); + let container_type_data = type_registry + .get_type_data::<$type_data>(container_type_id) + .unwrap() + .clone(); + + let mut $allocator = ReflectAllocator::default(); + drop(type_registry); + world.insert_resource(app_type_registry); + let $lua = Lua::new(); + let set_expr = Box::new($set); + world.insert_resource($allocator); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + $lua.globals() + .set("world", LuaWorld(world.clone())) + .unwrap(); + let mut target = $val; + (container_type_data.opt_set.unwrap())(&mut target, set_expr).unwrap(); + assert!(target.reflect_partial_eq(&$exp).unwrap()); + }); + }}; + } - let type_registry = app_type_registry.read(); - let option_type_data = type_registry - .get_type_data::(std::any::TypeId::of::>()) - .unwrap() - .clone(); - - let mut allocator = ReflectAllocator::default(); - let some_value = ReflectReference::new_allocated(Some(Proxied(4)), &mut allocator); - let none_value = ReflectReference::new_allocated(None::, &mut allocator); - world.insert_resource(allocator); - drop(type_registry); - world.insert_resource(app_type_registry); - - let lua = Lua::new(); - WorldCallbackAccess::with_callback_access(&mut world, |world| { - lua.globals().set("world", LuaWorld(world.clone())).unwrap(); - - let some_lua_value = LuaReflectReference(some_value.clone()) - .into_lua(&lua) - .unwrap(); - let gotten_value = (option_type_data.from_proxy)(some_lua_value, &lua).unwrap(); - assert_eq!(gotten_value.reflect_path, some_value.reflect_path); + macro_rules! assert_lua_container_proxy_into_proxy_lua_only { + (;WITH; $target_type:ty = $inner_type_data:ty, $container_type:ty = $type_data:ty ;FROM; $val:expr ;INTO; $exp:expr) => {{ + let app_type_registry = prepare_type_registry_with_common_containers!( + $target_type, + $container_type, + $inner_type_data + ); + let mut world = World::new(); - let gotten_value = (option_type_data.from_proxy)(Value::Nil, &lua).unwrap(); - assert_eq!(gotten_value.reflect_path, none_value.reflect_path); - }) + let type_registry = app_type_registry.read(); + let container_type_id = std::any::TypeId::of::<$container_type>(); + let container_type_data = type_registry + .get_type_data::<$type_data>(container_type_id) + .unwrap() + .clone(); + + let mut allocator = ReflectAllocator::default(); + let allocated_value = ReflectReference::new_allocated($val, &mut allocator); + world.insert_resource(allocator); + drop(type_registry); + world.insert_resource(app_type_registry); + let lua = Lua::new(); + WorldCallbackAccess::with_callback_access(&mut world, |world| { + lua.globals().set("world", LuaWorld(world.clone())).unwrap(); + + let gotten_into_value = + (container_type_data.into_proxy)(allocated_value, &lua).unwrap(); + assert_eq!(gotten_into_value, $exp); + }); + }}; } #[test] - fn test_option_lua_value_impl_into_value() { - let mut app_type_registry = setup_type_registry::>(); - app_type_registry - .write() - .register_type_data::(); - - pre_register_common_containers(&mut app_type_registry); - - let type_registry = app_type_registry.read(); - let option_type_data = type_registry - .get_type_data::(std::any::TypeId::of::>()) - .unwrap(); - let inner_type_data = type_registry - .get_type_data::(std::any::TypeId::of::()) - .unwrap(); - - // option::some into_value should be equivalent result to inner_type into_value - let lua = Lua::new(); - let value: usize = 5; - let option_value = Some(value); - let expected_into_value = (inner_type_data.into_value)(&value, &lua).unwrap(); - let gotten_into_value = (option_type_data.into_value)(&option_value, &lua).unwrap(); - - assert_eq!( - expected_into_value, gotten_into_value, - "Option into_value should be equivalent to usize into_value for Some variant" - ); - - // the none variant should be equivalent to Value::Nil - let option_value: Option = None; - let expected_into_value = Value::Nil; - let gotten_into_value = (option_type_data.into_value)(&option_value, &lua).unwrap(); - - assert_eq!( - expected_into_value, gotten_into_value, - "Option into_value should be equivalent to Value::Nil for None variant" - ); + fn test_pre_register_common_containers_lua_value() { + assert_transitively_registers!(usize = ReflectLuaValue, Option = ReflectLuaValue); + assert_transitively_registers!(usize = ReflectLuaValue, Vec = ReflectLuaProxied); } #[test] - fn test_vec_lua_value_impl_into_value() { - let mut app_type_registry = setup_type_registry::>(); - app_type_registry - .write() - .register_type_data::(); - - pre_register_common_containers(&mut app_type_registry); - - let type_registry = app_type_registry.read(); - let option_type_data = type_registry - .get_type_data::(std::any::TypeId::of::>()) - .unwrap(); - let inner_type_data = type_registry - .get_type_data::(std::any::TypeId::of::()) - .unwrap(); - - // option::some into_value should be a table with the inner value converted to Lua - let lua = Lua::new(); - let value: usize = 5; - let option_value = vec![value]; - let expected_into_value = (inner_type_data.into_value)(&value, &lua).unwrap(); - let gotten_into_value = (option_type_data.into_value)(&option_value, &lua).unwrap(); - - assert_eq!( - expected_into_value, - gotten_into_value.as_table().unwrap().pop().unwrap(), - ); - - // an empty vec should be equivalent to an empty table - let vec_value: Vec = vec![]; - let gotten_into_value = (option_type_data.into_value)(&vec_value, &lua).unwrap(); - - assert!(gotten_into_value.as_table().unwrap().is_empty()); + fn test_pre_register_common_containers_lua_proxy() { + assert_transitively_registers!(Proxied = ReflectLuaProxied, Option = ReflectLuaProxied ); } #[test] - fn test_option_lua_value_set_value() { - let mut app_type_registry = setup_type_registry::>(); - app_type_registry - .write() - .register_type_data::(); - - pre_register_common_containers(&mut app_type_registry); - - let type_registry = app_type_registry.read(); - let option_type_data = type_registry - .get_type_data::(std::any::TypeId::of::>()) - .unwrap(); - - // setting an existing Some variant works correctly - let lua = Lua::new(); - let mut target_option = Some(0usize); - (option_type_data.set_value)(&mut target_option, 5.into_lua(&lua).unwrap(), &lua).unwrap(); - assert_eq!( - target_option, - Some(5), - "Option set_value should set the value to Some(5)" + fn test_option_container_impls() { + // Inner Value + // into + assert_lua_value_into_equals!( + usize, + Option, + ReflectLuaValue, + Some(2usize) => Value::Integer(2) ); - - // setting an existing Some variant to nil should set the value to None - (option_type_data.set_value)(&mut target_option, Value::Nil, &lua).unwrap(); - assert_eq!( - target_option, None, - "Option set_value should set the value to None" + assert_lua_value_into_equals!( + usize, + Option, + ReflectLuaValue, + None:: => Value::Nil ); - // setting a none variant should set the Some variant correctly - let mut target_option: Option = None; - (option_type_data.set_value)(&mut target_option, 5usize.into_lua(&lua).unwrap(), &lua) - .unwrap(); - assert_eq!( - target_option, - Some(5), - "Option set_value should set the value to None" + // from + assert_lua_container_value_from_equals!( + usize, + Option, + ReflectLuaValue, + Value::Integer(2) => Some(2usize) ); - - // setting a none variant to nil should stay as None - (option_type_data.set_value)(&mut target_option, Value::Nil, &lua).unwrap(); - assert_eq!( - target_option, None, - "Option set_value should set the value to None" + assert_lua_container_value_from_equals!( + usize,Option, + ReflectLuaValue, + Value::Nil => None:: ); - } - - #[test] - fn test_vec_lua_value_set_value() { - let mut app_type_registry = setup_type_registry::>(); - app_type_registry - .write() - .register_type_data::(); - pre_register_common_containers(&mut app_type_registry); - - let type_registry = app_type_registry.read(); - let option_type_data = type_registry - .get_type_data::(std::any::TypeId::of::>()) - .unwrap(); - - // setting an existing vec - let lua = Lua::new(); - let new_vec = Value::Table( - lua.create_table_from(vec![(1, 5.into_lua(&lua).unwrap())]) - .unwrap(), + // set + // assert_lua_container_value_after_set_equals!( + // usize, Option, + // ReflectLuaValue, + // Some(2usize) => Value::Nil => None:: + // ); + // assert_lua_container_value_after_set_equals!( + // usize, Option, + // ReflectLuaValue, + // None:: => Value::Integer(2) => Some(2usize) + // ); + // assert_lua_container_value_after_set_equals!( + // usize, Option, + // ReflectLuaValue, + // None:: => Value::Nil => None:: + // ); + // assert_lua_container_value_after_set_equals!( + // usize, Option, + // ReflectLuaValue, + // Some(2usize) => Value::Integer(3) => Some(3usize) + // ); + + // Inner Proxy + // into + assert_lua_container_proxy_into_proxy!( + ;WITH; Proxied = ReflectLuaProxied, Option = ReflectLuaProxied + ;FROM; Some(Proxied(2)) + ;INTO; Proxied(2usize)); + assert_lua_container_proxy_into_proxy_lua_only!( + ;WITH; Proxied = ReflectLuaProxied, Option = ReflectLuaProxied + ;FROM; None:: + ;INTO; Value::Nil ); - let mut target_vec = vec![0usize]; - (option_type_data.set_value)(&mut target_vec, new_vec.clone(), &lua).unwrap(); - assert_eq!(target_vec, vec![5],); - - // setting an existing vec to an empty table should create a new empty vec - (option_type_data.set_value)( - &mut target_vec, - Value::Table( - lua.create_table_from(Vec::<(isize, usize)>::default()) - .unwrap(), - ), - &lua, - ) - .unwrap(); - assert_eq!(target_vec, Vec::::default(),); - - // setting an empty vec to a table with a value should set the vec to the value - (option_type_data.set_value)(&mut target_vec, new_vec, &lua).unwrap(); - assert_eq!(target_vec, vec![5],); + + // set from + // assert_lua_container_proxy_opt_set!(alloc, lua, Proxied, Option, ReflectLuaProxied, + // Some(Proxied(2)) + // => None:: + // => None::); + // assert_lua_container_proxy_opt_set!(alloc, lua, Proxied, Option, ReflectLuaProxied, + // None:: + // => Proxied(2)// LuaReflectReference(ReflectReference::new_allocated(Proxied(2), &mut alloc)) + // => Some(Proxied(2))); + // assert_lua_container_proxy_opt_set!(alloc, lua, Proxied, Option, ReflectLuaProxied, + // Some(Proxied(2)) + // => Proxied(3) // LuaReflectReference(ReflectReference::new_allocated(Proxied(3), &mut alloc)) + // => Some(Proxied(3))); + // assert_lua_container_proxy_opt_set!(alloc, lua, Proxied, Option, ReflectLuaProxied, + // None:: + // => None:: + // => None::); } #[test] - fn test_option_lua_value_from_value() { - let mut app_type_registry = setup_type_registry::>(); - app_type_registry - .write() - .register_type_data::(); - - pre_register_common_containers(&mut app_type_registry); - - let type_registry = app_type_registry.read(); - let option_type_data = type_registry - .get_type_data::(std::any::TypeId::of::>()) - .unwrap(); - - // from_value should correctly work for concrete values - let lua = Lua::new(); - let value = 5usize; - let gotten_value = - (option_type_data.from_value)(value.into_lua(&lua).unwrap(), &lua).unwrap(); - - assert_eq!( - Some(value), - *gotten_value.try_downcast::>().unwrap(), - "Option from_value should correctly convert a value" + fn test_listlike_container_impls() { + // Inner Value + // into + assert_lua_container_proxy_into_proxy!( + ;WITH; usize = ReflectLuaValue, Vec = ReflectLuaProxied + ;FROM; vec![Proxied(2), Proxied(3)] + ;INTO; vec![Proxied(2), Proxied(3)] ); - - // from_value should correctly work for nil values - let nil_lua = Value::Nil; - let gotten_value = (option_type_data.from_value)(nil_lua, &lua).unwrap(); - assert_eq!( - None::, - *gotten_value.try_downcast::>().unwrap(), - "Option from_value should correctly convert a nil value" + assert_lua_container_proxy_into_proxy!( + ;WITH; usize = ReflectLuaValue, Vec = ReflectLuaProxied + ;FROM; Vec::::default() + ;INTO; Vec::::default() ); - } - - #[test] - fn test_vec_lua_value_from_value() { - let mut app_type_registry = setup_type_registry::>(); - app_type_registry - .write() - .register_type_data::(); - pre_register_common_containers(&mut app_type_registry); - - let type_registry = app_type_registry.read(); - let option_type_data = type_registry - .get_type_data::(std::any::TypeId::of::>()) - .unwrap(); - - // from_value should correctly work for concrete values - let lua = Lua::new(); - let value = vec![5usize]; - let gotten_value = - (option_type_data.from_value)(value.into_lua(&lua).unwrap(), &lua).unwrap(); - - assert_eq!( - gotten_value - .as_list() - .unwrap() - .map(|v| *v.try_downcast_ref::().unwrap()) - .collect::>() - .pop(), - Some(5usize) + assert_lua_container_proxy_opt_set!(alloc, lua + ;WITH; usize = ReflectLuaValue, Vec = ReflectLuaProxied + ;SET; Vec::::default() + ;TO; Vec::::default() + ;EXPECT; Vec::::default() ); - // from_value should correctly work for empty lists - let nil_lua = Value::Table( - lua.create_table_from(Vec::<(isize, usize)>::default()) - .unwrap(), + assert_lua_container_proxy_opt_set!(alloc, lua + ;WITH; usize = ReflectLuaValue, Vec = ReflectLuaProxied + ;SET; Vec::::default() + ;TO; vec![Proxied(2)] + ;EXPECT; vec![Proxied(2)] ); - let gotten_value = (option_type_data.from_value)(nil_lua, &lua).unwrap(); - assert!(gotten_value.as_list().unwrap().count() == 0); } #[test] diff --git a/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs b/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs index 92f38d9b96..778bb8c3ef 100644 --- a/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs +++ b/crates/languages/bevy_mod_scripting_lua/tests/lua_tests.rs @@ -73,7 +73,7 @@ fn init_lua_test_utils(_script_name: &Cow<'static, str>, lua: &mut Lua) -> Resul let _get_entity_with_test_component = lua .create_function(|l, s: String| { - let world = l.get_world().unwrap(); + let world = l.get_world(); let opt_entity = world.with_resource::(|_, mut allocator| { let a = World::enumerate_test_components() .iter() diff --git a/examples/lua/bevy_api.rs b/examples/lua/bevy_api.rs index 5e496fd8a2..51088c542b 100644 --- a/examples/lua/bevy_api.rs +++ b/examples/lua/bevy_api.rs @@ -15,6 +15,7 @@ pub struct MyComponent { f32: f32, mat3: Mat3, vec_of_usize: Vec, + vec_of_usize2: Vec, option_usize: Option, option_vec3: Option, vec_of_option_bools: Vec>, @@ -44,6 +45,7 @@ fn init_data(mut commands: Commands) { vec_of_option_bools: vec![Some(true), None, Some(false)], option_vec_of_bools: Some(vec![true, true, true]), vec_of_usize: vec![1, 2, 3], + vec_of_usize2: vec![4, 5, 6], option_usize: None, }, ScriptComponent::new(vec![SCRIPT_NAME.into()]), From 5f34f88aa7eb6f4da84beef3df00469df5cad4f1 Mon Sep 17 00:00:00 2001 From: makspll Date: Mon, 2 Dec 2024 19:01:47 +0000 Subject: [PATCH 22/22] WIP --- .../src/bindings/reference.rs | 111 ++++++++++++------ .../src/reflection_extensions.rs | 97 +++++++++------ .../src/bindings/reference.rs | 25 ++-- .../bevy_mod_scripting_lua/src/lib.rs | 3 + .../bevy_mod_scripting_lua/src/type_data.rs | 34 ++++-- 5 files changed, 177 insertions(+), 93 deletions(-) diff --git a/crates/bevy_mod_scripting_core/src/bindings/reference.rs b/crates/bevy_mod_scripting_core/src/bindings/reference.rs index 6860faa3d9..13305542ae 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/reference.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/reference.rs @@ -28,15 +28,14 @@ use bevy::{ }, ptr::Ptr, reflect::{ - Access, ParsedPath, PartialReflect, Reflect, ReflectFromPtr, ReflectPath, ReflectPathError, - TypeInfo, TypeRegistry, + Access, DynamicEnum, DynamicTuple, ParsedPath, PartialReflect, Reflect, ReflectFromPtr, ReflectPath, ReflectPathError, TypeInfo, TypeRegistry }, }; use smallvec::SmallVec; use crate::{ bindings::{ReflectAllocation, ReflectAllocationId}, - prelude::{ReflectAllocator, ScriptError, ScriptResult}, reflection_extensions::TypeIdExtensions, + prelude::{ReflectAllocator, ScriptError, ScriptResult}, reflection_extensions::{PartialReflectExt, TypeIdExtensions}, }; use super::{ @@ -64,6 +63,16 @@ impl ReflectReference { ReflectRefIter::new_indexed(self) } + /// Attempts to insert into the reflected value, if the underlying supports inserting at usize indices + pub fn insert_at(&mut self, world: &WorldAccessGuard, index: usize, elem: ReflectReference) -> ScriptResult<()> { + self.with_reflect_mut(world, |target, type_registry, allocator| { + elem.with_reflect_only(world, type_registry, allocator, |other,_,_| { + target.insert_at(index, other.clone_value()) + })? + })??; + Ok(()) + } + /// Prints the reference using the world to resolve type names. pub fn print_with_world(&self, world: &WorldAccessGuard) -> String { world.with_resource(|_, type_registry: Mut| { @@ -119,10 +128,23 @@ impl ReflectReference { /// A form of [`Self::reflect`] which does the access checks for you. #[track_caller] - pub fn with_reflect O>( + pub fn with_reflect O>( &self, world: &WorldAccessGuard, f: F, + ) -> ScriptResult { + world.with_allocator_and_type_registry(|world, type_registry, mut allocator| { + let type_registry = type_registry.write(); + self.with_reflect_only(world, &type_registry, &mut allocator, f) + }) + } + + pub fn with_reflect_only O>( + &self, + world: &WorldAccessGuard, + type_registry: &TypeRegistry, + allocator: &mut ReflectAllocator, + f: F, ) -> ScriptResult { let access = world .get_access_timeout( @@ -131,22 +153,16 @@ impl ReflectReference { DEFAULT_INTERVAL, ); - let out = world.with_allocator_and_type_registry(|_, type_registry, allocator| { - let type_registry = type_registry.read(); - let reflect = self - .reflect( - world.as_unsafe_world_cell(), - &access, - &type_registry, - Some(&allocator), - )?; - let o = f(reflect, &type_registry, &allocator); - - Ok(o) - }); + let reflect = self + .reflect( + world.as_unsafe_world_cell(), + &access, + type_registry, + Some(allocator), + ).map(|r| f(r, type_registry, allocator)); world.release_access(access); - out + reflect } #[track_caller] @@ -154,6 +170,19 @@ impl ReflectReference { &self, world: &WorldAccessGuard, f: F, + ) -> ScriptResult { + world.with_allocator_and_type_registry(|_, type_registry, mut allocator| { + let type_registry = type_registry.read(); + self.with_reflect_mut_only(world, &type_registry, &mut allocator, f) + }) + } + + pub fn with_reflect_mut_only O>( + &self, + world: &WorldAccessGuard, + type_registry: &TypeRegistry, + allocator: &mut ReflectAllocator, + f: F, ) -> ScriptResult { let mut access = world .get_access_timeout( @@ -161,21 +190,17 @@ impl ReflectReference { DEFAULT_TIMEOUT, DEFAULT_INTERVAL, ); - let out = world.with_allocator_and_type_registry(|_, type_registry, mut allocator| { - let type_registry = type_registry.read(); - let reflect = self - .reflect_mut( - world.as_unsafe_world_cell(), - &mut access, - &type_registry, - Some(&allocator), - )?; - let o = f(reflect, &type_registry, &mut allocator); - Ok(o) - }); + let reflect = self + .reflect_mut( + world.as_unsafe_world_cell(), + &mut access, + type_registry, + Some(allocator), + ).map(|r| f(r, type_registry, allocator)); + world.release_access(access); - out + reflect } /// Returns `Ok(())` if the given access is sufficient to read the value or an appropriate error otherwise @@ -456,12 +481,14 @@ impl ReflectBase { } /// An element in the reflection path, the base reference included -#[derive(Clone, PartialEq, Eq, Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum ReflectionPathElem { /// A standard reflection path, i.e. `.field_name[vec_index]`, pre-parsed since we construct once potentially use many times Reflection(ParsedPath), /// a deferred reflection DeferredReflection(DeferredReflection), + /// a no-op reflection, i.e. a reference to the base object, useful identity to have + Identity } impl ReflectionPathElem { @@ -511,6 +538,7 @@ impl<'a> ReflectPath<'a> for &'a ReflectionPathElem { match self { ReflectionPathElem::Reflection(path) => path.reflect_element(root), ReflectionPathElem::DeferredReflection(f) => (f.get)(root), + ReflectionPathElem::Identity => Ok(root), } } @@ -521,6 +549,7 @@ impl<'a> ReflectPath<'a> for &'a ReflectionPathElem { match self { ReflectionPathElem::Reflection(path) => path.reflect_element_mut(root), ReflectionPathElem::DeferredReflection(defref) => (defref.get_mut)(root), + ReflectionPathElem::Identity => Ok(root) } } } @@ -542,6 +571,22 @@ pub struct DeferredReflection { >, } +/// Given a function, repeats it with a mutable reference for the get_mut deferred variant +#[macro_export] +macro_rules! new_deferred_reflection { + (|$root:ident| {$($get:tt)*}) => { + DeferredReflection::from(( + |$root: &dyn PartialReflect| -> Result<&dyn PartialReflect, ReflectPathError<'static>> { + $($get)* + }, + |$root: &mut dyn PartialReflect| -> Result<&mut dyn PartialReflect, ReflectPathError<'static>> { + $($get)* + }, + )) + }; +} + + impl Debug for DeferredReflection { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str("DeferredReflection") @@ -614,6 +659,6 @@ impl Iterator for ReflectRefIter { } }; - return Some(result); + Some(result) } } \ No newline at end of file diff --git a/crates/bevy_mod_scripting_core/src/reflection_extensions.rs b/crates/bevy_mod_scripting_core/src/reflection_extensions.rs index 014a78ae19..ad2ec4dd1f 100644 --- a/crates/bevy_mod_scripting_core/src/reflection_extensions.rs +++ b/crates/bevy_mod_scripting_core/src/reflection_extensions.rs @@ -33,8 +33,11 @@ pub trait PartialReflectExt { other: Box, apply: F, ) -> Result<(), ScriptError>; - } + + /// Inserts into the type at the given key, if the type supports inserting with the given key + fn insert_at(&mut self, index: usize, value: Box) -> Result<(), ScriptError>; +} pub trait TypeIdExtensions { fn type_id_or_dummy(&self) -> TypeId; } @@ -129,7 +132,6 @@ impl PartialReflectExt for T { match (self.reflect_mut(), other.reflect_mut()) { (bevy::reflect::ReflectMut::List(l), bevy::reflect::ReflectMut::List(r)) => { - let excess_elems = max(l.len() as isize - r.len() as isize, 0) as usize; let to_be_inserted_elems = max(r.len() as isize - l.len() as isize, 0) as usize; let apply_range = 0..(r.len() - to_be_inserted_elems); @@ -153,20 +155,6 @@ impl PartialReflectExt for T { for i in apply_range { apply(l.get_mut(i).expect("invariant"), r.get(i).expect("invariant"))?; }; - - - - // for right_elem in r.iter() { - // if let Some(left_elem) = l.get_mut(i) { - // apply(left_elem, right_elem)? - // } else { - // shorter = true; - // break; - // } - // i+=1; - // }; - - Ok(()) } @@ -178,29 +166,27 @@ impl PartialReflectExt for T { } } - // fn set_as_list>>( - // &mut self, - // other: I, - // ) -> Result<(), ScriptError> { - // if let bevy::reflect::ReflectMut::List(list) = self.reflect_mut() { - // let mut left_index = 0; - // for i in other { - // if let Some(left_item) = list.get_mut(left_index) { - // left_item.apply - // } else { - // } - // left_index += 1; - // } - // Ok(()) - // } else { - // Err(ScriptError::new_runtime_error(format!( - // "Expected list-like type from crate core, but got {}", - // self.get_represented_type_info() - // .map(|ti| ti.type_path()) - // .unwrap_or_else(|| "dynamic type with no type information") - // ))) - // } - // } + fn insert_at(&mut self, index: usize, value: Box) -> Result<(), ScriptError> { + match self.reflect_mut() { + bevy::reflect::ReflectMut::List(l) => { + l.insert(index, value); + Ok(()) + }, + bevy::reflect::ReflectMut::Map(m) => { + m.insert_boxed(Box::new(index), value); + Ok(()) + }, + bevy::reflect::ReflectMut::Set(s) => { + s.insert_boxed(value); + Ok(()) + }, + _ => Err(ScriptError::new_reflection_error(format!( + "Could not insert into {}. The type does not support insertion at a key.", + self.reflect_type_path() + ))), + } + } + } @@ -344,4 +330,37 @@ mod test { .unwrap(); assert_eq!(other, list); } + + #[test] + fn test_insert_at_vec() { + let mut list = vec![1, 2, 3]; + let value = 4; + let value_ref: Box = Box::new(value); + list.insert_at(&1, value_ref).unwrap(); + assert_eq!(vec![1, 4, 2, 3], list); + } + + #[test] + fn test_insert_at_map() { + let mut map = std::collections::HashMap::::default(); + let value = 4; + let value_ref: Box = Box::new(value); + map.insert(1, 2); + map.insert(2, 3); + map.insert(3, 4); + map.insert_at(&1, value_ref).unwrap(); + assert_eq!(4, map[&1]); + } + + #[test] + fn test_insert_at_set() { + let mut set = std::collections::HashSet::::default(); + let value = 4; + let value_ref: Box = Box::new(value); + set.insert(1); + set.insert(2); + set.insert(3); + set.insert_at(&1, value_ref).unwrap(); + assert!(set.contains(&4)); + } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs index ea2fe5e40d..17908091a3 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/bindings/reference.rs @@ -108,9 +108,10 @@ impl LuaReflectReference { }) { bevy::log::debug!("Setting value with ReflectLuaValue registration"); let other = (type_data.from_value)(value, lua)?; - let o = self - .0 - .with_reflect_mut(&world, |r, _, _| r.try_apply(other.as_partial_reflect()))?; + self.0.with_reflect_mut(&world, |r, _, _| { + r.try_apply(other.as_partial_reflect()) + .map_err(ScriptError::new_reflection_error) + })??; } else if let Some(type_data) = world.with_resource::(|_, type_registry| { type_registry @@ -193,6 +194,7 @@ impl LuaReflectReference { } } } + impl_userdata_from_lua!(LuaReflectReference); impl LuaProxied for ReflectReference { @@ -211,16 +213,6 @@ impl From for LuaReflectReference { } } -#[derive(Debug, Clone, tealr::mlu::UserData, tealr::ToTypename)] -pub struct LuaReflectRefIter(pub ReflectRefIter); -impl_userdata_from_lua!(LuaReflectRefIter); - -impl TealData for LuaReflectRefIter { - fn add_methods<'lua, T: tealr::mlu::TealDataMethods<'lua, Self>>(_methods: &mut T) {} - - fn add_fields<'lua, F: tealr::mlu::TealDataFields<'lua, Self>>(_fields: &mut F) {} -} - impl TealData for LuaReflectReference { fn add_methods<'lua, T: tealr::mlu::TealDataMethods<'lua, Self>>(m: &mut T) { m.add_meta_function( @@ -256,6 +248,13 @@ impl TealData for LuaReflectReference { }, ); + m.add_function_mut( + "insert", + |l, (mut self_, key): (LuaReflectReference, usize, LuaReflect)| { + self_.0.insert_at(key, l.get_world()) + }, + ); + m.add_meta_function(MetaMethod::Len, |l, self_: LuaReflectReference| { self_.len(l) }); diff --git a/crates/languages/bevy_mod_scripting_lua/src/lib.rs b/crates/languages/bevy_mod_scripting_lua/src/lib.rs index bbe60977e8..2c4527256b 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/lib.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/lib.rs @@ -82,6 +82,9 @@ impl Plugin for LuaScriptingPlugin { fn cleanup(&self, app: &mut App) { let mut type_registry = app.world_mut().get_resource_mut().unwrap(); + + // we register up to two levels of nesting, if more are needed, the user will have to do this manually + pre_register_common_containers(&mut type_registry); pre_register_common_containers(&mut type_registry); } } diff --git a/crates/languages/bevy_mod_scripting_lua/src/type_data.rs b/crates/languages/bevy_mod_scripting_lua/src/type_data.rs index d046750c51..5abd838a5f 100644 --- a/crates/languages/bevy_mod_scripting_lua/src/type_data.rs +++ b/crates/languages/bevy_mod_scripting_lua/src/type_data.rs @@ -16,9 +16,7 @@ use bevy::{ }, }; use bevy_mod_scripting_core::{ - bindings::{DeferredReflection, ReflectAllocator, ReflectReference, ReflectionPathElem}, - error::ScriptError, - reflection_extensions::PartialReflectExt, + bindings::{DeferredReflection, ReflectAllocator, ReflectReference, ReflectionPathElem}, error::ScriptError, new_deferred_reflection, reflection_extensions::PartialReflectExt }; use tealr::mlu::mlua::{FromLua, IntoLua, Lua, Table, Value}; @@ -62,11 +60,13 @@ impl ReflectLuaProxied { fn new_for_option(inner_lua_proxied_data: &ReflectLuaProxied, container_type_info: &'static TypeInfo) -> Self { let ref_into_option = |mut r: ReflectReference| { r.index_path(ParsedPath::parse_static("0").expect("Invalid reflection path")); + // why is this necessary? well we need for the from_proxy to work correctly + // we need to know if the reference came from this impl so we can pop the last element + r.index_path(ReflectionPathElem::Identity); r }; let into_proxy_clone = inner_lua_proxied_data.into_proxy.clone(); let from_proxy_clone = inner_lua_proxied_data.from_proxy.clone(); - // let from_proxy_clone = inner_lua_proxied_data.from_proxy.clone(); Self { into_proxy: Arc::new(move |reflect_ref, l| { // read the value and check if it is None, if so return nil @@ -98,10 +98,27 @@ impl ReflectLuaProxied { Ok(reflect_ref) } else { - bevy::log::debug!("Option from proxy: {:?}", v); + // this ref could've come from this into_proxy or from something else, we need to differentiate here + // we need to let mut inner_ref = (from_proxy_clone)(v, l)?; - inner_ref.reflect_path.pop(); - Ok(inner_ref) + if inner_ref.reflect_path.last().is_some_and(|p| p == &ReflectionPathElem::Identity) { + // if the last path element is identity, then it came from this impl + // we need to remove the path derefing to the inner value and we're done + inner_ref.reflect_path.pop(); + Ok(inner_ref) + } else { + // otherwise we need to wrap it in an option dynamically so it's an option, to do that we need to reflect the value and box it + let world = l.get_world(); + let reflect_ref = inner_ref.with_reflect(&world, |r,_, mut allocator| { + let mut dynamic = DynamicEnum::new("Some", DynamicVariant::Tuple([r.clone_value()].into_iter().collect())); + dynamic.set_represented_type(Some(container_type_info)); + ReflectReference::new_allocated( + dynamic, + &mut allocator, + ) + })?; + Ok(reflect_ref) + } } }), opt_set: None, @@ -538,7 +555,8 @@ fn destructure_list_type(reg: &TypeRegistration) -> Option<(TypeId, TypeId)> { } /// iterates over type data for all types which have registered [`ReflectLuaProxied`] and [`ReflectLuaValue`] implementations, -/// and registers corresponding [`Option`] [`Result`] etc type data equivalents +/// and registers corresponding [`Option`] [`Result`] etc type data equivalents. +/// for combinations of nested containers, this should be run more times per level of nesting required. pub fn pre_register_common_containers(type_registry: &mut AppTypeRegistry) { let mut type_registry = type_registry.write();