Skip to content

Commit de204bc

Browse files
authored
fix: remove reflect_functions and file_watcher flags from bevy dependency (#316)
1 parent 31760ea commit de204bc

File tree

8 files changed

+67
-102
lines changed

8 files changed

+67
-102
lines changed

.github/workflows/bevy_mod_scripting.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,23 @@ jobs:
8585
matrix:
8686
run_args: ${{fromJson(needs.generate-job-matrix.outputs.matrix)}}
8787
steps:
88+
- name: Free Disk Space (Ubuntu)
89+
if: runner.os == 'Linux'
90+
uses: jlumbroso/free-disk-space@main
91+
with:
92+
tool-cache: false
93+
android: true
94+
dotnet: true
95+
haskell: true
96+
large-packages: true
97+
docker-images: true
98+
swap-storage: true
99+
# - if: runner.os == 'linux'
100+
# run: |
101+
# sudo rm -rf /usr/share/dotnet; sudo rm -rf /opt/ghc; sudo rm -rf "/usr/local/share/boost"; sudo rm -rf "$AGENT_TOOLSDIRECTORY"
88102
- name: Checkout
89103
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' }}
90104
uses: actions/checkout@v4
91-
- if: runner.os == 'linux'
92-
run: |
93-
sudo rm -rf /usr/share/dotnet; sudo rm -rf /opt/ghc; sudo rm -rf "/usr/local/share/boost"; sudo rm -rf "$AGENT_TOOLSDIRECTORY"
94105
- uses: actions-rs/toolchain@v1
95106
if: ${{ needs.check-needs-run.outputs.any-changes == 'true' }}
96107
with:

crates/bevy_mod_scripting_core/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ rhai = { version = "1.21", default-features = false, features = [
3030
"sync",
3131
], optional = true }
3232

33-
bevy = { workspace = true, default-features = false, features = [
34-
"bevy_asset",
35-
"reflect_functions",
36-
] }
33+
bevy = { workspace = true, default-features = false, features = ["bevy_asset"] }
3734

3835
thiserror = "1.0.31"
3936
parking_lot = "0.12.1"

crates/bevy_mod_scripting_core/src/bindings/function/script_function.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ use crate::{
88
error::InteropError,
99
ScriptValue,
1010
};
11-
use bevy::{
12-
prelude::{Reflect, Resource},
13-
reflect::func::FunctionError,
14-
};
11+
use bevy::prelude::{Reflect, Resource};
1512
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
1613
use std::borrow::Cow;
1714
use std::collections::{HashMap, VecDeque};
@@ -604,10 +601,7 @@ macro_rules! impl_script_function {
604601
if let Some(default) = <$param>::default_value() {
605602
default
606603
} else {
607-
return Err(InteropError::function_call_error(FunctionError::ArgCountMismatch{
608-
expected: expected_arg_count,
609-
received: received_args_len
610-
}));
604+
return Err(InteropError::argument_count_mismatch(expected_arg_count,received_args_len));
611605
}
612606
}
613607
};
@@ -695,10 +689,7 @@ mod test {
695689
InteropError::function_interop_error(
696690
"my_fn",
697691
Namespace::Global,
698-
InteropError::function_call_error(FunctionError::ArgCountMismatch {
699-
expected: 2,
700-
received: 1
701-
})
692+
InteropError::argument_count_mismatch(2, 1)
702693
)
703694
);
704695
});

crates/bevy_mod_scripting_core/src/bindings/pretty_print.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,10 @@ impl ReflectReferencePrinter {
310310
ReflectRef::Opaque(o) => {
311311
self.pretty_print_value_opaque(o, output);
312312
}
313-
ReflectRef::Function(f) => {
314-
output.push_str("Function(");
315-
output.push_str(
316-
f.info()
317-
.name()
318-
.unwrap_or(&Cow::Borrowed("<unnamed function>"))
319-
.as_ref(),
320-
);
321-
output.push(')');
313+
// for function_reflection from bevy or other feature gated things
314+
#[allow(unreachable_patterns)]
315+
_ => {
316+
output.push_str(&format!("{:?}", v));
322317
}
323318
}
324319
}

crates/bevy_mod_scripting_core/src/error.rs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::bindings::{
1010
use bevy::{
1111
ecs::component::ComponentId,
1212
prelude::Entity,
13-
reflect::{func::FunctionError, PartialReflect, Reflect},
13+
reflect::{PartialReflect, Reflect},
1414
};
1515
use std::{
1616
any::TypeId,
@@ -481,13 +481,6 @@ impl InteropError {
481481
}))
482482
}
483483

484-
/// Thrown when the error happens after a function call, and an error is thrown by bevy.
485-
///
486-
/// I.e. mismatch in args, or invalid number of arguments
487-
pub fn function_call_error(inner: FunctionError) -> Self {
488-
Self(Arc::new(InteropErrorInner::FunctionCallError { inner }))
489-
}
490-
491484
/// Thrown when an error happens during argument conversion in a function call
492485
pub fn function_arg_conversion_error(argument: String, error: InteropError) -> Self {
493486
Self(Arc::new(InteropErrorInner::FunctionArgConversionError {
@@ -555,6 +548,14 @@ impl InteropError {
555548
variant_name: variant_name.to_string(),
556549
}))
557550
}
551+
552+
/// Thrown when the number of arguments in a function call does not match.
553+
pub fn argument_count_mismatch(expected: usize, got: usize) -> Self {
554+
Self(Arc::new(InteropErrorInner::ArgumentCountMismatch {
555+
expected,
556+
got,
557+
}))
558+
}
558559
}
559560

560561
/// For errors to do with reflection, type conversions or other interop issues
@@ -684,11 +685,6 @@ pub(crate) enum InteropErrorInner {
684685
/// The component that was invalid
685686
component_id: ComponentId,
686687
},
687-
/// Thrown when an error happens in a function call
688-
FunctionCallError {
689-
/// The inner error that occurred
690-
inner: FunctionError,
691-
},
692688
/// Thrown when an error happens during argument conversion in a function call
693689
MissingFunctionError {
694690
/// The type that the function was attempted to be called on
@@ -739,6 +735,8 @@ pub(crate) enum InteropErrorInner {
739735
type_id: TypeId,
740736
variant_name: String,
741737
},
738+
/// Thrown when the number of arguments in a function call does not match.
739+
ArgumentCountMismatch { expected: usize, got: usize },
742740
}
743741

744742
/// For test purposes
@@ -879,10 +877,6 @@ impl PartialEq for InteropErrorInner {
879877
InteropErrorInner::InvalidComponent { component_id: a },
880878
InteropErrorInner::InvalidComponent { component_id: b },
881879
) => a == b,
882-
(
883-
InteropErrorInner::FunctionCallError { inner: a },
884-
InteropErrorInner::FunctionCallError { inner: b },
885-
) => a == b,
886880
(
887881
InteropErrorInner::MissingFunctionError {
888882
on: a,
@@ -947,6 +941,16 @@ impl PartialEq for InteropErrorInner {
947941
variant_name: d,
948942
},
949943
) => a == c && b == d,
944+
(
945+
InteropErrorInner::ArgumentCountMismatch {
946+
expected: a,
947+
got: b,
948+
},
949+
InteropErrorInner::ArgumentCountMismatch {
950+
expected: c,
951+
got: d,
952+
},
953+
) => a == c && b == d,
950954
_ => false,
951955
}
952956
}
@@ -1084,12 +1088,6 @@ macro_rules! function_arg_conversion_error {
10841088
};
10851089
}
10861090

1087-
macro_rules! function_call_error {
1088-
($inner:expr) => {
1089-
format!("Error in function call: {}", $inner)
1090-
};
1091-
}
1092-
10931091
macro_rules! better_conversion_exists {
10941092
($context:expr) => {
10951093
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 {
12481246
InteropErrorInner::FunctionArgConversionError { argument, error } => {
12491247
function_arg_conversion_error!(argument, error.display_with_world(world))
12501248
},
1251-
InteropErrorInner::FunctionCallError { inner } => {
1252-
function_call_error!(inner)
1253-
},
12541249
InteropErrorInner::BetterConversionExists{ context } => {
12551250
better_conversion_exists!(context)
12561251
},
@@ -1277,6 +1272,12 @@ impl DisplayWithWorld for InteropErrorInner {
12771272
type_id.display_with_world(world)
12781273
)
12791274
},
1275+
InteropErrorInner::ArgumentCountMismatch { expected, got } => {
1276+
format!(
1277+
"Argument count mismatch, expected: {}, got: {}",
1278+
expected, got
1279+
)
1280+
},
12801281
}
12811282
}
12821283

@@ -1387,9 +1388,6 @@ impl DisplayWithWorld for InteropErrorInner {
13871388
InteropErrorInner::FunctionArgConversionError { argument, error } => {
13881389
function_arg_conversion_error!(argument, error.display_without_world())
13891390
},
1390-
InteropErrorInner::FunctionCallError { inner } => {
1391-
function_call_error!(inner)
1392-
},
13931391
InteropErrorInner::BetterConversionExists{ context } => {
13941392
better_conversion_exists!(context)
13951393
},
@@ -1416,6 +1414,12 @@ impl DisplayWithWorld for InteropErrorInner {
14161414
type_id.display_without_world()
14171415
)
14181416
},
1417+
InteropErrorInner::ArgumentCountMismatch { expected, got } => {
1418+
format!(
1419+
"Argument count mismatch, expected: {}, got: {}",
1420+
expected, got
1421+
)
1422+
},
14191423
}
14201424
}
14211425
}

crates/bevy_mod_scripting_core/src/reflection_extensions.rs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use crate::{
44
bindings::{ReflectReference, WorldGuard},
55
error::InteropError,
66
};
7-
use bevy::reflect::{
8-
func::Return, FromReflect, PartialReflect, Reflect, ReflectFromReflect, ReflectMut, TypeInfo,
9-
};
7+
use bevy::reflect::{PartialReflect, Reflect, ReflectFromReflect, ReflectMut, TypeInfo};
108
use std::{
119
any::{Any, TypeId},
1210
cmp::max,
@@ -460,37 +458,6 @@ impl TypeInfoExtensions for TypeInfo {
460458
}
461459
}
462460

463-
/// Extension trait for [`Return`] providing additional functionality for working with return values.
464-
pub trait ReturnValExt<'a> {
465-
/// Try to convert the return value into the concrete type, or return a boxed partial reflect if the conversion fails.
466-
fn try_into_or_boxed<T: PartialReflect + FromReflect>(
467-
self,
468-
) -> Result<T, Box<dyn PartialReflect>>;
469-
470-
/// Get a reference to the partial reflect value.
471-
fn as_ref(&'a self) -> &'a dyn PartialReflect;
472-
}
473-
474-
impl<'a> ReturnValExt<'a> for Return<'a> {
475-
fn as_ref(&'a self) -> &'a dyn PartialReflect {
476-
match self {
477-
Return::Owned(f) => f.as_partial_reflect(),
478-
Return::Ref(r) => r.as_partial_reflect(),
479-
Return::Mut(r) => r.as_partial_reflect(),
480-
}
481-
}
482-
483-
fn try_into_or_boxed<T: PartialReflect + FromReflect>(
484-
self,
485-
) -> Result<T, Box<dyn PartialReflect>> {
486-
match self {
487-
Return::Owned(partial_reflect) => partial_reflect.try_take::<T>(),
488-
Return::Ref(r) => T::from_reflect(r).ok_or_else(|| r.clone_value()),
489-
Return::Mut(r) => T::from_reflect(r).ok_or_else(|| r.clone_value()),
490-
}
491-
}
492-
}
493-
494461
#[cfg(test)]
495462
mod test {
496463
use bevy::reflect::{DynamicMap, Map};

crates/bevy_mod_scripting_functions/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ bevy_bindings = []
1818

1919
[dependencies]
2020
bevy = { workspace = true, features = [
21-
"reflect_functions",
2221
"bevy_asset",
2322
"bevy_animation",
2423
"bevy_core_pipeline",
@@ -27,7 +26,6 @@ bevy = { workspace = true, features = [
2726
"bevy_render",
2827
"bevy_text",
2928
"bevy_sprite",
30-
"file_watcher",
3129
"multi_threaded",
3230
] }
3331
profiling = { workspace = true }

crates/ladfile_builder/src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ pub mod plugin;
33

44
use bevy_mod_scripting_core::{
55
bindings::{
6-
function::{namespace::Namespace, script_function::FunctionCallContext},
6+
function::{
7+
namespace::Namespace,
8+
script_function::{
9+
DynamicScriptFunction, DynamicScriptFunctionMut, FunctionCallContext,
10+
},
11+
},
712
ReflectReference,
813
},
914
docgen::{
@@ -12,10 +17,7 @@ use bevy_mod_scripting_core::{
1217
},
1318
match_by_type,
1419
};
15-
use bevy_reflect::{
16-
func::{DynamicFunction, DynamicFunctionMut},
17-
NamedField, TypeInfo, TypeRegistry, Typed, UnnamedField,
18-
};
20+
use bevy_reflect::{NamedField, TypeInfo, TypeRegistry, Typed, UnnamedField};
1921
use ladfile::*;
2022
use std::{
2123
any::TypeId,
@@ -53,8 +55,8 @@ fn primitive_from_type_id(type_id: TypeId) -> Option<LadBMSPrimitiveKind> {
5355
i: OsString => return Some(LadBMSPrimitiveKind::OsString),
5456
i: PathBuf => return Some(LadBMSPrimitiveKind::PathBuf),
5557
i: FunctionCallContext => return Some(LadBMSPrimitiveKind::FunctionCallContext),
56-
i: DynamicFunction => return Some(LadBMSPrimitiveKind::DynamicFunction),
57-
i: DynamicFunctionMut => return Some(LadBMSPrimitiveKind::DynamicFunctionMut),
58+
i: DynamicScriptFunction => return Some(LadBMSPrimitiveKind::DynamicFunction),
59+
i: DynamicScriptFunctionMut => return Some(LadBMSPrimitiveKind::DynamicFunctionMut),
5860
i: ReflectReference => return Some(LadBMSPrimitiveKind::ReflectReference)
5961
});
6062
None
@@ -101,8 +103,8 @@ impl<'t> LadFileBuilder<'t> {
101103
.add_bms_primitive::<OsString>("A heap allocated OS string")
102104
.add_bms_primitive::<PathBuf>("A heap allocated file path")
103105
.add_bms_primitive::<FunctionCallContext>("Function call context, if accepted by a function, means the function can access the world in arbitrary ways.")
104-
.add_bms_primitive::<DynamicFunction>("A callable dynamic function")
105-
.add_bms_primitive::<DynamicFunctionMut>("A stateful and callable dynamic function")
106+
.add_bms_primitive::<DynamicScriptFunction>("A callable dynamic function")
107+
.add_bms_primitive::<DynamicScriptFunctionMut>("A stateful and callable dynamic function")
106108
.add_bms_primitive::<ReflectReference>("A reference to a reflectable type");
107109

108110
builder

0 commit comments

Comments
 (0)