1
1
//! Contains functions defined by the [`bevy_mod_scripting_core`] crate
2
2
3
3
use crate :: NamespaceBuilder ;
4
- use reflection_extensions:: { PartialReflectExt , TypeIdExtensions } ;
5
4
use bevy:: {
6
5
prelude:: * ,
7
- reflect:: {
8
- func:: FunctionRegistrationError , ParsedPath
9
- } ,
6
+ reflect:: { func:: FunctionRegistrationError , ParsedPath } ,
10
7
} ;
11
8
use bevy_mod_scripting_core:: * ;
12
9
use bindings:: {
13
- access_map:: ReflectAccessId , function:: {
10
+ access_map:: ReflectAccessId ,
11
+ function:: {
14
12
from:: { Ref , Val } ,
15
13
from_ref:: FromScriptRef ,
16
14
into_ref:: IntoScriptRef ,
17
15
script_function:: { CallerContext , ScriptFunctionMut } ,
18
- } , pretty_print:: DisplayWithWorld , script_value:: ScriptValue , ReflectReference , ReflectionPathExt , ScriptQueryBuilder , ScriptQueryResult , ScriptTypeRegistration , WorldCallbackAccess
16
+ } ,
17
+ pretty_print:: DisplayWithWorld ,
18
+ script_value:: ScriptValue ,
19
+ ReflectReference , ReflectionPathExt , ScriptQueryBuilder , ScriptQueryResult ,
20
+ ScriptTypeRegistration , WorldCallbackAccess ,
19
21
} ;
20
22
use error:: InteropError ;
21
-
23
+ use reflection_extensions :: { PartialReflectExt , TypeIdExtensions } ;
22
24
23
25
pub fn register_bevy_bindings ( app : & mut App ) {
24
26
#[ cfg( feature = "bevy_bindings" ) ]
@@ -134,29 +136,24 @@ pub fn register_world_functions(reg: &mut World) -> Result<(), FunctionRegistrat
134
136
. register ( "has_entity" , |s : WorldCallbackAccess , e : Val < Entity > | {
135
137
s. has_entity ( * e)
136
138
} )
137
- . register (
138
- "query" ,
139
- || {
140
- let query_builder = ScriptQueryBuilder :: default ( ) ;
141
- Ok ( Val ( query_builder) )
142
- } ,
143
- )
139
+ . register ( "query" , || {
140
+ let query_builder = ScriptQueryBuilder :: default ( ) ;
141
+ Ok ( Val ( query_builder) )
142
+ } )
144
143
. register ( "exit" , |s : WorldCallbackAccess | s. exit ( ) )
145
144
. register ( "log_all_allocations" , |s : WorldCallbackAccess | {
146
145
let world = s. try_read ( ) . expect ( "stale world" ) ;
147
146
let allocator = world. allocator ( ) ;
148
147
let allocator = allocator. read ( ) ;
149
- for ( id, _) in allocator. iter_allocations ( ) {
148
+ for ( id, _) in allocator. iter_allocations ( ) {
150
149
let raid = ReflectAccessId :: for_allocation ( id. clone ( ) ) ;
151
150
if world. claim_read_access ( raid) {
152
151
// Safety: ref released above
153
152
unsafe { world. release_access ( raid) } ;
154
153
} else {
155
154
panic ! ( "Failed to claim read access for allocation id: {}" , id. id( ) ) ;
156
155
}
157
-
158
156
}
159
-
160
157
} ) ;
161
158
Ok ( ( ) )
162
159
}
@@ -338,7 +335,6 @@ pub fn register_reflect_reference_functions(
338
335
Ok ( ( ) )
339
336
}
340
337
341
-
342
338
pub fn register_script_type_registration_functions (
343
339
registry : & mut World ,
344
340
) -> Result < ( ) , FunctionRegistrationError > {
@@ -360,11 +356,14 @@ pub fn register_script_query_builder_functions(
360
356
registry : & mut World ,
361
357
) -> Result < ( ) , FunctionRegistrationError > {
362
358
NamespaceBuilder :: < ScriptQueryBuilder > :: new ( registry)
363
- . register ( "component" , |s : Val < ScriptQueryBuilder > , components : Val < ScriptTypeRegistration > | {
364
- let mut builder = s. into_inner ( ) ;
365
- builder. component ( components. into_inner ( ) ) ;
366
- Val ( builder)
367
- } )
359
+ . register (
360
+ "component" ,
361
+ |s : Val < ScriptQueryBuilder > , components : Val < ScriptTypeRegistration > | {
362
+ let mut builder = s. into_inner ( ) ;
363
+ builder. component ( components. into_inner ( ) ) ;
364
+ Val ( builder)
365
+ } ,
366
+ )
368
367
. register (
369
368
"with" ,
370
369
|s : Val < ScriptQueryBuilder > , with : Val < ScriptTypeRegistration > | {
@@ -409,23 +408,23 @@ pub fn register_core_functions(app: &mut App) {
409
408
// we don't exclude from compilation here,
410
409
// since these are much smaller and still useful if not included initially
411
410
// perhaps people might want to include some but not all of these
412
-
413
- #[ cfg( feature= "core_functions" ) ]
411
+
412
+ #[ cfg( feature = "core_functions" ) ]
414
413
register_world_functions ( world) . expect ( "Failed to register world functions" ) ;
415
414
416
- #[ cfg( feature= "core_functions" ) ]
415
+ #[ cfg( feature = "core_functions" ) ]
417
416
register_reflect_reference_functions ( world)
418
417
. expect ( "Failed to register reflect reference functions" ) ;
419
418
420
- #[ cfg( feature= "core_functions" ) ]
419
+ #[ cfg( feature = "core_functions" ) ]
421
420
register_script_type_registration_functions ( world)
422
421
. expect ( "Failed to register script type registration functions" ) ;
423
422
424
- #[ cfg( feature= "core_functions" ) ]
423
+ #[ cfg( feature = "core_functions" ) ]
425
424
register_script_query_builder_functions ( world)
426
425
. expect ( "Failed to register script query builder functions" ) ;
427
426
428
- #[ cfg( feature= "core_functions" ) ]
427
+ #[ cfg( feature = "core_functions" ) ]
429
428
register_script_query_result_functions ( world)
430
429
. expect ( "Failed to register script query result functions" ) ;
431
430
}
0 commit comments