@@ -70,24 +70,24 @@ impl FunctionCallContext {
70
70
}
71
71
}
72
72
73
- #[ derive( Clone , Reflect ) ]
73
+ #[ derive( Reflect , Clone ) ]
74
74
#[ reflect( opaque) ]
75
75
/// A dynamic script function.
76
76
pub struct DynamicScriptFunction {
77
77
/// The meta information about the function
78
- pub info : FunctionInfo ,
78
+ pub info : Arc < FunctionInfo > ,
79
79
// TODO: info about the function, this is hard right now because of non 'static lifetimes in wrappers, we can't use TypePath etc
80
80
func : Arc <
81
81
dyn Fn ( FunctionCallContext , VecDeque < ScriptValue > ) -> ScriptValue + Send + Sync + ' static ,
82
82
> ,
83
83
}
84
84
85
- #[ derive( Clone , Reflect ) ]
85
+ #[ derive( Reflect , Clone ) ]
86
86
#[ reflect( opaque) ]
87
87
/// A dynamic mutable script function.
88
88
pub struct DynamicScriptFunctionMut {
89
89
/// The meta information about the function
90
- pub info : FunctionInfo ,
90
+ pub info : Arc < FunctionInfo > ,
91
91
func : Arc <
92
92
RwLock <
93
93
// I'd rather consume an option or something instead of having the RWLock but I just wanna get this release out
@@ -129,30 +129,9 @@ impl DynamicScriptFunction {
129
129
}
130
130
131
131
/// Set the meta information about the function
132
- pub fn with_info ( self , info : FunctionInfo ) -> Self {
133
- Self { info, ..self }
134
- }
135
-
136
- /// Set the name of the function
137
- pub fn with_name < N : Into < Cow < ' static , str > > > ( self , name : N ) -> Self {
138
- Self {
139
- info : FunctionInfo {
140
- name : name. into ( ) ,
141
- ..self . info
142
- } ,
143
- func : self . func ,
144
- }
145
- }
146
-
147
- /// Set the namespace of the function
148
- pub fn with_namespace ( self , namespace : Namespace ) -> Self {
149
- Self {
150
- info : FunctionInfo {
151
- namespace,
152
- ..self . info
153
- } ,
154
- func : self . func ,
155
- }
132
+ pub fn with_info ( mut self , info : FunctionInfo ) -> Self {
133
+ self . info = Arc :: new ( info) ;
134
+ self
156
135
}
157
136
}
158
137
@@ -187,30 +166,9 @@ impl DynamicScriptFunctionMut {
187
166
}
188
167
189
168
/// Set the meta information about the function
190
- pub fn with_info ( self , info : FunctionInfo ) -> Self {
191
- Self { info, ..self }
192
- }
193
-
194
- /// Set the name of the function
195
- pub fn with_name < N : Into < Cow < ' static , str > > > ( self , name : N ) -> Self {
196
- Self {
197
- info : FunctionInfo {
198
- name : name. into ( ) ,
199
- ..self . info
200
- } ,
201
- func : self . func ,
202
- }
203
- }
204
-
205
- /// Set the namespace of the function
206
- pub fn with_namespace ( self , namespace : Namespace ) -> Self {
207
- Self {
208
- info : FunctionInfo {
209
- namespace,
210
- ..self . info
211
- } ,
212
- func : self . func ,
213
- }
169
+ pub fn with_info ( mut self , info : FunctionInfo ) -> Self {
170
+ self . info = Arc :: new ( info) ;
171
+ self
214
172
}
215
173
}
216
174
@@ -248,10 +206,11 @@ where
248
206
{
249
207
fn from ( fn_ : F ) -> Self {
250
208
DynamicScriptFunction {
251
- info : FunctionInfo :: default ( ) ,
209
+ info : FunctionInfo :: default ( )
210
+ . with_name ( std:: any:: type_name :: < F > ( ) )
211
+ . into ( ) ,
252
212
func : Arc :: new ( fn_) ,
253
213
}
254
- . with_name ( std:: any:: type_name :: < F > ( ) )
255
214
}
256
215
}
257
216
@@ -261,10 +220,11 @@ where
261
220
{
262
221
fn from ( fn_ : F ) -> Self {
263
222
DynamicScriptFunctionMut {
264
- info : FunctionInfo :: default ( ) ,
223
+ info : FunctionInfo :: default ( )
224
+ . with_name ( std:: any:: type_name :: < F > ( ) )
225
+ . into ( ) ,
265
226
func : Arc :: new ( RwLock :: new ( fn_) ) ,
266
227
}
267
- . with_name ( std:: any:: type_name :: < F > ( ) )
268
228
}
269
229
}
270
230
@@ -711,7 +671,7 @@ mod test {
711
671
#[ test]
712
672
fn test_invalid_amount_of_args_errors_nicely ( ) {
713
673
let fn_ = |a : usize , b : usize | a + b;
714
- let script_function = fn_. into_dynamic_script_function ( ) . with_name ( "my_fn" ) ;
674
+ let script_function = fn_. into_dynamic_script_function ( ) ;
715
675
716
676
with_local_world ( || {
717
677
let out = script_function. call (
@@ -723,7 +683,7 @@ mod test {
723
683
assert_eq ! (
724
684
out. unwrap_err( ) ,
725
685
InteropError :: function_interop_error(
726
- "my_fn " ,
686
+ "<bevy_mod_scripting_core::bindings::function::script_function::test::test_invalid_amount_of_args_errors_nicely::{{closure}} as bevy_mod_scripting_core::bindings::function::script_function::ScriptFunction<fn(usize, usize) -> usize>>::into_dynamic_script_function::{{closure}} " ,
727
687
Namespace :: Global ,
728
688
InteropError :: argument_count_mismatch( 2 , 1 )
729
689
)
@@ -737,7 +697,7 @@ mod test {
737
697
struct Comp ;
738
698
739
699
let fn_ = |_a : crate :: bindings:: function:: from:: Mut < Comp > | 0usize ;
740
- let script_function = fn_. into_dynamic_script_function ( ) . with_name ( "my_fn" ) ;
700
+ let script_function = fn_. into_dynamic_script_function ( ) ;
741
701
742
702
with_local_world ( || {
743
703
let out = script_function. call (
0 commit comments