File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
crates/bevy_mod_scripting_functions/src Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -656,6 +656,25 @@ impl GlobalNamespace {
656656 & mut allocator,
657657 ) )
658658 }
659+
660+ /// Constructs a hash map. Useful for languages which do not make the distinction between lists and dictionaries.
661+ ///
662+ /// Arguments:
663+ /// * `map_or_list`: The list or map to convert to a hash map.
664+ /// Returns:
665+ /// * `hashMap`: The converted hash map
666+ fn map (
667+ map_or_list : Union < HashMap < String , ScriptValue > , Vec < ScriptValue > > ,
668+ ) -> HashMap < String , ScriptValue > {
669+ match map_or_list. into_left ( ) {
670+ Ok ( map) => map,
671+ Err ( list) => list
672+ . into_iter ( )
673+ . enumerate ( )
674+ . map ( |( k, v) | ( k. to_string ( ) , v) )
675+ . collect ( ) ,
676+ }
677+ }
659678}
660679
661680pub fn register_core_functions ( app : & mut App ) {
You can’t perform that action at this time.
0 commit comments