summaryrefslogtreecommitdiff
path: root/modules/gdnative
diff options
context:
space:
mode:
authorThomas Herzog <thomas.herzog@mail.com>2017-07-19 13:07:06 +0200
committerGitHub <noreply@github.com>2017-07-19 13:07:06 +0200
commit45b498c4e056e313e06b169d64f991b32db30423 (patch)
treee846cefb4dd0263e0160d8ec4d5bfe07b4d2a90e /modules/gdnative
parentc5ba9d9b7c6d7d2c08d01b13af87748af4dee8a2 (diff)
parent535290d2e7b25aced99a6b33acc2a75a60960801 (diff)
Merge pull request #9699 from RameshRavone/master
[gdnative] `Object::_get` return type and dynamic property
Diffstat (limited to 'modules/gdnative')
-rw-r--r--modules/gdnative/api_generator.cpp2
-rw-r--r--modules/gdnative/gdnative.cpp62
2 files changed, 64 insertions, 0 deletions
diff --git a/modules/gdnative/api_generator.cpp b/modules/gdnative/api_generator.cpp
index d5f22ee7a3..a9d1f96287 100644
--- a/modules/gdnative/api_generator.cpp
+++ b/modules/gdnative/api_generator.cpp
@@ -268,6 +268,8 @@ List<ClassAPI> generate_c_api_classes() {
method_api.method_name = method_api.method_name.get_slice(":", 0);
} else if (m->get().return_val.type != Variant::NIL) {
method_api.return_type = m->get().return_val.hint == PROPERTY_HINT_RESOURCE_TYPE ? m->get().return_val.hint_string : Variant::get_type_name(m->get().return_val.type);
+ } else if (m->get().return_val.name != "") {
+ method_api.return_type = m->get().return_val.name;
} else {
method_api.return_type = "void";
}
diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp
index 12d806250b..348d8533ad 100644
--- a/modules/gdnative/gdnative.cpp
+++ b/modules/gdnative/gdnative.cpp
@@ -847,6 +847,16 @@ bool GDNativeInstance::set(const StringName &p_name, const Variant &p_value) {
script->script_data->properties[p_name].setter.set_func((godot_object *)owner, script->script_data->properties[p_name].setter.method_data, userdata, *(godot_variant *)&p_value);
return true;
}
+
+ Map<StringName, GDNativeScriptData::Method>::Element *E = script->script_data->methods.find("_set");
+ if (E) {
+ Variant name = p_name;
+ const Variant *args[2] = { &name, &p_value };
+
+ E->get().method.method((godot_object *)owner, E->get().method.method_data, userdata, 2, (godot_variant **)args);
+ return true;
+ }
+
return false;
}
@@ -856,14 +866,66 @@ bool GDNativeInstance::get(const StringName &p_name, Variant &r_ret) const {
if (script->script_data->properties.has(p_name)) {
godot_variant value = script->script_data->properties[p_name].getter.get_func((godot_object *)owner, script->script_data->properties[p_name].getter.method_data, userdata);
r_ret = *(Variant *)&value;
+ godot_variant_destroy(&value);
+ return true;
+ }
+
+ Map<StringName, GDNativeScriptData::Method>::Element *E = script->script_data->methods.find("_get");
+ if (E) {
+ Variant name = p_name;
+ const Variant *args[1] = { &name };
+
+ godot_variant result = E->get().method.method((godot_object *)owner, E->get().method.method_data, userdata, 1, (godot_variant **)args);
+ r_ret = *(Variant *)&result;
+ godot_variant_destroy(&result);
return true;
}
+
return false;
}
void GDNativeInstance::get_property_list(List<PropertyInfo> *p_properties) const {
script->get_script_property_list(p_properties);
// TODO: dynamic properties
+
+ Map<StringName, GDNativeScriptData::Method>::Element *E = script->script_data->methods.find("_get_property_list");
+ if (E) {
+ godot_variant result = E->get().method.method((godot_object *)owner, E->get().method.method_data, userdata, 0, NULL);
+ Variant ret = *(Variant *)&result;
+ godot_variant_destroy(&result);
+
+ if (ret.get_type() != Variant::ARRAY) {
+ ERR_EXPLAIN("Wrong type for _get_property_list, must be an array of dictionaries.");
+ ERR_FAIL();
+ }
+
+ Array arr = ret;
+ for (int i = 0; i < arr.size(); i++) {
+ Dictionary d = arr[i];
+ ERR_CONTINUE(!d.has("name"))
+ ERR_CONTINUE(!d.has("type"))
+
+ PropertyInfo pinfo;
+
+ pinfo.type = Variant::Type(d["type"].operator int());
+ ERR_CONTINUE(pinfo.type < 0 || pinfo.type >= Variant::VARIANT_MAX);
+
+ pinfo.name = d["name"];
+ ERR_CONTINUE(pinfo.name == "");
+
+ if (d.has("hint")) {
+ pinfo.hint = PropertyHint(d["hint"].operator int());
+ }
+ if (d.has("hint_string")) {
+ pinfo.hint_string = d["hint_string"];
+ }
+ if (d.has("usage")) {
+ pinfo.usage = d["usage"];
+ }
+
+ p_properties->push_back(pinfo);
+ }
+ }
}
Variant::Type GDNativeInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const {