diff --git a/.github/workflows/bevy_mod_scripting.yml b/.github/workflows/bevy_mod_scripting.yml index 0371b0760b..0a050e75e1 100644 --- a/.github/workflows/bevy_mod_scripting.yml +++ b/.github/workflows/bevy_mod_scripting.yml @@ -85,12 +85,23 @@ jobs: matrix: run_args: ${{fromJson(needs.generate-job-matrix.outputs.matrix)}} steps: + - name: Free Disk Space (Ubuntu) + if: runner.os == 'Linux' + uses: jlumbroso/free-disk-space@main + with: + tool-cache: false + android: true + dotnet: true + haskell: true + large-packages: true + docker-images: true + swap-storage: true + # - if: runner.os == 'linux' + # run: | + # sudo rm -rf /usr/share/dotnet; sudo rm -rf /opt/ghc; sudo rm -rf "/usr/local/share/boost"; sudo rm -rf "$AGENT_TOOLSDIRECTORY" - name: Checkout if: ${{ needs.check-needs-run.outputs.any-changes == 'true' }} uses: actions/checkout@v4 - - if: runner.os == 'linux' - run: | - sudo rm -rf /usr/share/dotnet; sudo rm -rf /opt/ghc; sudo rm -rf "/usr/local/share/boost"; sudo rm -rf "$AGENT_TOOLSDIRECTORY" - uses: actions-rs/toolchain@v1 if: ${{ needs.check-needs-run.outputs.any-changes == 'true' }} with: diff --git a/crates/bevy_mod_scripting_core/Cargo.toml b/crates/bevy_mod_scripting_core/Cargo.toml index dec63456e9..177c63d94f 100644 --- a/crates/bevy_mod_scripting_core/Cargo.toml +++ b/crates/bevy_mod_scripting_core/Cargo.toml @@ -30,10 +30,7 @@ rhai = { version = "1.21", default-features = false, features = [ "sync", ], optional = true } -bevy = { workspace = true, default-features = false, features = [ - "bevy_asset", - "reflect_functions", -] } +bevy = { workspace = true, default-features = false, features = ["bevy_asset"] } thiserror = "1.0.31" parking_lot = "0.12.1" diff --git a/crates/bevy_mod_scripting_core/src/bindings/function/script_function.rs b/crates/bevy_mod_scripting_core/src/bindings/function/script_function.rs index 3249a40dbf..eb3b040ecb 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/function/script_function.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/function/script_function.rs @@ -8,10 +8,7 @@ use crate::{ error::InteropError, ScriptValue, }; -use bevy::{ - prelude::{Reflect, Resource}, - reflect::func::FunctionError, -}; +use bevy::prelude::{Reflect, Resource}; use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use std::borrow::Cow; use std::collections::{HashMap, VecDeque}; @@ -604,10 +601,7 @@ macro_rules! impl_script_function { if let Some(default) = <$param>::default_value() { default } else { - return Err(InteropError::function_call_error(FunctionError::ArgCountMismatch{ - expected: expected_arg_count, - received: received_args_len - })); + return Err(InteropError::argument_count_mismatch(expected_arg_count,received_args_len)); } } }; @@ -695,10 +689,7 @@ mod test { InteropError::function_interop_error( "my_fn", Namespace::Global, - InteropError::function_call_error(FunctionError::ArgCountMismatch { - expected: 2, - received: 1 - }) + InteropError::argument_count_mismatch(2, 1) ) ); }); diff --git a/crates/bevy_mod_scripting_core/src/bindings/pretty_print.rs b/crates/bevy_mod_scripting_core/src/bindings/pretty_print.rs index 7f207f3fb5..daf489c967 100644 --- a/crates/bevy_mod_scripting_core/src/bindings/pretty_print.rs +++ b/crates/bevy_mod_scripting_core/src/bindings/pretty_print.rs @@ -310,15 +310,10 @@ impl ReflectReferencePrinter { ReflectRef::Opaque(o) => { self.pretty_print_value_opaque(o, output); } - ReflectRef::Function(f) => { - output.push_str("Function("); - output.push_str( - f.info() - .name() - .unwrap_or(&Cow::Borrowed("")) - .as_ref(), - ); - output.push(')'); + // for function_reflection from bevy or other feature gated things + #[allow(unreachable_patterns)] + _ => { + output.push_str(&format!("{:?}", v)); } } } diff --git a/crates/bevy_mod_scripting_core/src/error.rs b/crates/bevy_mod_scripting_core/src/error.rs index 057a5cb6ca..6b5c67bbbc 100644 --- a/crates/bevy_mod_scripting_core/src/error.rs +++ b/crates/bevy_mod_scripting_core/src/error.rs @@ -10,7 +10,7 @@ use crate::bindings::{ use bevy::{ ecs::component::ComponentId, prelude::Entity, - reflect::{func::FunctionError, PartialReflect, Reflect}, + reflect::{PartialReflect, Reflect}, }; use std::{ any::TypeId, @@ -481,13 +481,6 @@ impl InteropError { })) } - /// Thrown when the error happens after a function call, and an error is thrown by bevy. - /// - /// I.e. mismatch in args, or invalid number of arguments - pub fn function_call_error(inner: FunctionError) -> Self { - Self(Arc::new(InteropErrorInner::FunctionCallError { inner })) - } - /// Thrown when an error happens during argument conversion in a function call pub fn function_arg_conversion_error(argument: String, error: InteropError) -> Self { Self(Arc::new(InteropErrorInner::FunctionArgConversionError { @@ -555,6 +548,14 @@ impl InteropError { variant_name: variant_name.to_string(), })) } + + /// Thrown when the number of arguments in a function call does not match. + pub fn argument_count_mismatch(expected: usize, got: usize) -> Self { + Self(Arc::new(InteropErrorInner::ArgumentCountMismatch { + expected, + got, + })) + } } /// For errors to do with reflection, type conversions or other interop issues @@ -684,11 +685,6 @@ pub(crate) enum InteropErrorInner { /// The component that was invalid component_id: ComponentId, }, - /// Thrown when an error happens in a function call - FunctionCallError { - /// The inner error that occurred - inner: FunctionError, - }, /// Thrown when an error happens during argument conversion in a function call MissingFunctionError { /// The type that the function was attempted to be called on @@ -739,6 +735,8 @@ pub(crate) enum InteropErrorInner { type_id: TypeId, variant_name: String, }, + /// Thrown when the number of arguments in a function call does not match. + ArgumentCountMismatch { expected: usize, got: usize }, } /// For test purposes @@ -879,10 +877,6 @@ impl PartialEq for InteropErrorInner { InteropErrorInner::InvalidComponent { component_id: a }, InteropErrorInner::InvalidComponent { component_id: b }, ) => a == b, - ( - InteropErrorInner::FunctionCallError { inner: a }, - InteropErrorInner::FunctionCallError { inner: b }, - ) => a == b, ( InteropErrorInner::MissingFunctionError { on: a, @@ -947,6 +941,16 @@ impl PartialEq for InteropErrorInner { variant_name: d, }, ) => a == c && b == d, + ( + InteropErrorInner::ArgumentCountMismatch { + expected: a, + got: b, + }, + InteropErrorInner::ArgumentCountMismatch { + expected: c, + got: d, + }, + ) => a == c && b == d, _ => false, } } @@ -1084,12 +1088,6 @@ macro_rules! function_arg_conversion_error { }; } -macro_rules! function_call_error { - ($inner:expr) => { - format!("Error in function call: {}", $inner) - }; -} - macro_rules! better_conversion_exists { ($context:expr) => { format!("Unfinished conversion in context of: {}. A better conversion exists but caller didn't handle the case.", $context) @@ -1248,9 +1246,6 @@ impl DisplayWithWorld for InteropErrorInner { InteropErrorInner::FunctionArgConversionError { argument, error } => { function_arg_conversion_error!(argument, error.display_with_world(world)) }, - InteropErrorInner::FunctionCallError { inner } => { - function_call_error!(inner) - }, InteropErrorInner::BetterConversionExists{ context } => { better_conversion_exists!(context) }, @@ -1277,6 +1272,12 @@ impl DisplayWithWorld for InteropErrorInner { type_id.display_with_world(world) ) }, + InteropErrorInner::ArgumentCountMismatch { expected, got } => { + format!( + "Argument count mismatch, expected: {}, got: {}", + expected, got + ) + }, } } @@ -1387,9 +1388,6 @@ impl DisplayWithWorld for InteropErrorInner { InteropErrorInner::FunctionArgConversionError { argument, error } => { function_arg_conversion_error!(argument, error.display_without_world()) }, - InteropErrorInner::FunctionCallError { inner } => { - function_call_error!(inner) - }, InteropErrorInner::BetterConversionExists{ context } => { better_conversion_exists!(context) }, @@ -1416,6 +1414,12 @@ impl DisplayWithWorld for InteropErrorInner { type_id.display_without_world() ) }, + InteropErrorInner::ArgumentCountMismatch { expected, got } => { + format!( + "Argument count mismatch, expected: {}, got: {}", + expected, got + ) + }, } } } diff --git a/crates/bevy_mod_scripting_core/src/reflection_extensions.rs b/crates/bevy_mod_scripting_core/src/reflection_extensions.rs index cc42a26a7b..a18d0ea051 100644 --- a/crates/bevy_mod_scripting_core/src/reflection_extensions.rs +++ b/crates/bevy_mod_scripting_core/src/reflection_extensions.rs @@ -4,9 +4,7 @@ use crate::{ bindings::{ReflectReference, WorldGuard}, error::InteropError, }; -use bevy::reflect::{ - func::Return, FromReflect, PartialReflect, Reflect, ReflectFromReflect, ReflectMut, TypeInfo, -}; +use bevy::reflect::{PartialReflect, Reflect, ReflectFromReflect, ReflectMut, TypeInfo}; use std::{ any::{Any, TypeId}, cmp::max, @@ -460,37 +458,6 @@ impl TypeInfoExtensions for TypeInfo { } } -/// Extension trait for [`Return`] providing additional functionality for working with return values. -pub trait ReturnValExt<'a> { - /// Try to convert the return value into the concrete type, or return a boxed partial reflect if the conversion fails. - fn try_into_or_boxed( - self, - ) -> Result>; - - /// Get a reference to the partial reflect value. - fn as_ref(&'a self) -> &'a dyn PartialReflect; -} - -impl<'a> ReturnValExt<'a> for Return<'a> { - fn as_ref(&'a self) -> &'a dyn PartialReflect { - match self { - Return::Owned(f) => f.as_partial_reflect(), - Return::Ref(r) => r.as_partial_reflect(), - Return::Mut(r) => r.as_partial_reflect(), - } - } - - fn try_into_or_boxed( - self, - ) -> Result> { - match self { - Return::Owned(partial_reflect) => partial_reflect.try_take::(), - Return::Ref(r) => T::from_reflect(r).ok_or_else(|| r.clone_value()), - Return::Mut(r) => T::from_reflect(r).ok_or_else(|| r.clone_value()), - } - } -} - #[cfg(test)] mod test { use bevy::reflect::{DynamicMap, Map}; diff --git a/crates/bevy_mod_scripting_functions/Cargo.toml b/crates/bevy_mod_scripting_functions/Cargo.toml index cd770378c5..647285744a 100644 --- a/crates/bevy_mod_scripting_functions/Cargo.toml +++ b/crates/bevy_mod_scripting_functions/Cargo.toml @@ -18,7 +18,6 @@ bevy_bindings = [] [dependencies] bevy = { workspace = true, features = [ - "reflect_functions", "bevy_asset", "bevy_animation", "bevy_core_pipeline", @@ -27,7 +26,6 @@ bevy = { workspace = true, features = [ "bevy_render", "bevy_text", "bevy_sprite", - "file_watcher", "multi_threaded", ] } profiling = { workspace = true } diff --git a/crates/ladfile_builder/src/lib.rs b/crates/ladfile_builder/src/lib.rs index 0de0665b47..2544d5ab80 100644 --- a/crates/ladfile_builder/src/lib.rs +++ b/crates/ladfile_builder/src/lib.rs @@ -3,7 +3,12 @@ pub mod plugin; use bevy_mod_scripting_core::{ bindings::{ - function::{namespace::Namespace, script_function::FunctionCallContext}, + function::{ + namespace::Namespace, + script_function::{ + DynamicScriptFunction, DynamicScriptFunctionMut, FunctionCallContext, + }, + }, ReflectReference, }, docgen::{ @@ -12,10 +17,7 @@ use bevy_mod_scripting_core::{ }, match_by_type, }; -use bevy_reflect::{ - func::{DynamicFunction, DynamicFunctionMut}, - NamedField, TypeInfo, TypeRegistry, Typed, UnnamedField, -}; +use bevy_reflect::{NamedField, TypeInfo, TypeRegistry, Typed, UnnamedField}; use ladfile::*; use std::{ any::TypeId, @@ -53,8 +55,8 @@ fn primitive_from_type_id(type_id: TypeId) -> Option { i: OsString => return Some(LadBMSPrimitiveKind::OsString), i: PathBuf => return Some(LadBMSPrimitiveKind::PathBuf), i: FunctionCallContext => return Some(LadBMSPrimitiveKind::FunctionCallContext), - i: DynamicFunction => return Some(LadBMSPrimitiveKind::DynamicFunction), - i: DynamicFunctionMut => return Some(LadBMSPrimitiveKind::DynamicFunctionMut), + i: DynamicScriptFunction => return Some(LadBMSPrimitiveKind::DynamicFunction), + i: DynamicScriptFunctionMut => return Some(LadBMSPrimitiveKind::DynamicFunctionMut), i: ReflectReference => return Some(LadBMSPrimitiveKind::ReflectReference) }); None @@ -101,8 +103,8 @@ impl<'t> LadFileBuilder<'t> { .add_bms_primitive::("A heap allocated OS string") .add_bms_primitive::("A heap allocated file path") .add_bms_primitive::("Function call context, if accepted by a function, means the function can access the world in arbitrary ways.") - .add_bms_primitive::("A callable dynamic function") - .add_bms_primitive::("A stateful and callable dynamic function") + .add_bms_primitive::("A callable dynamic function") + .add_bms_primitive::("A stateful and callable dynamic function") .add_bms_primitive::("A reference to a reflectable type"); builder