Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions crates/bevy_mod_scripting_functions/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HashMap<String, ScriptValue>, Vec<ScriptValue>>,
) -> HashMap<String, ScriptValue> {
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) {
Expand Down
Loading