diff --git a/crates/bevy_mod_scripting_functions/src/core.rs b/crates/bevy_mod_scripting_functions/src/core.rs index 2142c5b3d5..8f22b99bcb 100644 --- a/crates/bevy_mod_scripting_functions/src/core.rs +++ b/crates/bevy_mod_scripting_functions/src/core.rs @@ -656,6 +656,25 @@ impl GlobalNamespace { &mut allocator, )) } + + /// Constructs a hash map. Useful for languages which do not make the distinction between lists and dictionaries. + /// + /// Arguments: + /// * `map_or_list`: The list or map to convert to a hash map. + /// Returns: + /// * `hashMap`: The converted hash map + fn map( + map_or_list: Union, Vec>, + ) -> HashMap { + match map_or_list.into_left() { + Ok(map) => map, + Err(list) => list + .into_iter() + .enumerate() + .map(|(k, v)| (k.to_string(), v)) + .collect(), + } + } } pub fn register_core_functions(app: &mut App) {