added godot_dictionary_get_with_default to GDNative
Recently, Dictionary::get() was introduced, which acts like a index operator but allows the caller to specify a default value to return instead of issuing an error. This commit adds a new GDNative function that includes the default value.
This commit is contained in:
parent
a01dca79e2
commit
56bb22c988
3 changed files with 35 additions and 8 deletions
|
@ -155,12 +155,26 @@ godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_self) {
|
||||||
return raw_dest;
|
return raw_dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GDNative core 1.1
|
||||||
|
|
||||||
godot_bool GDAPI godot_dictionary_erase_with_return(godot_dictionary *p_self, const godot_variant *p_key) {
|
godot_bool GDAPI godot_dictionary_erase_with_return(godot_dictionary *p_self, const godot_variant *p_key) {
|
||||||
Dictionary *self = (Dictionary *)p_self;
|
Dictionary *self = (Dictionary *)p_self;
|
||||||
const Variant *key = (const Variant *)p_key;
|
const Variant *key = (const Variant *)p_key;
|
||||||
return self->erase(*key);
|
return self->erase(*key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
godot_variant GDAPI godot_dictionary_get_with_default(const godot_dictionary *p_self, const godot_variant *p_key, const godot_variant *p_default) {
|
||||||
|
const Dictionary *self = (const Dictionary *)p_self;
|
||||||
|
const Variant *key = (const Variant *)p_key;
|
||||||
|
const Variant *def = (const Variant *)p_default;
|
||||||
|
|
||||||
|
godot_variant raw_dest;
|
||||||
|
Variant *dest = (Variant *)&raw_dest;
|
||||||
|
memnew_placement(dest, Variant(self->get(*key, *def)));
|
||||||
|
|
||||||
|
return raw_dest;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -106,6 +106,23 @@
|
||||||
["const godot_real", "p_t"]
|
["const godot_real", "p_t"]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "godot_dictionary_get_with_default",
|
||||||
|
"return_type": "godot_variant",
|
||||||
|
"arguments": [
|
||||||
|
["const godot_dictionary *", "p_self"],
|
||||||
|
["const godot_variant *", "p_key"],
|
||||||
|
["const godot_variant *", "p_default"]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "godot_dictionary_erase_with_return",
|
||||||
|
"return_type": "bool",
|
||||||
|
"arguments": [
|
||||||
|
["godot_dictionary *", "p_self"],
|
||||||
|
["const godot_variant *", "p_key"]
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "godot_node_path_get_as_property_path",
|
"name": "godot_node_path_get_as_property_path",
|
||||||
"return_type": "godot_node_path",
|
"return_type": "godot_node_path",
|
||||||
|
@ -233,14 +250,6 @@
|
||||||
["const godot_vector3 *", "p_scale"]
|
["const godot_vector3 *", "p_scale"]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "godot_dictionary_erase_with_return",
|
|
||||||
"return_type": "bool",
|
|
||||||
"arguments": [
|
|
||||||
["godot_dictionary *", "p_self"],
|
|
||||||
["const godot_variant *", "p_key"]
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "godot_is_instance_valid",
|
"name": "godot_is_instance_valid",
|
||||||
"return_type": "bool",
|
"return_type": "bool",
|
||||||
|
|
|
@ -94,8 +94,12 @@ godot_bool GDAPI godot_dictionary_operator_equal(const godot_dictionary *p_self,
|
||||||
|
|
||||||
godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_self);
|
godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_self);
|
||||||
|
|
||||||
|
// GDNative core 1.1
|
||||||
|
|
||||||
godot_bool GDAPI godot_dictionary_erase_with_return(godot_dictionary *p_self, const godot_variant *p_key);
|
godot_bool GDAPI godot_dictionary_erase_with_return(godot_dictionary *p_self, const godot_variant *p_key);
|
||||||
|
|
||||||
|
godot_variant GDAPI godot_dictionary_get_with_default(const godot_dictionary *p_self, const godot_variant *p_key, const godot_variant *p_default);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue