summaryrefslogtreecommitdiffstats
path: root/include/core
diff options
context:
space:
mode:
authorBastiaan Olij <mux213@gmail.com>2019-05-02 23:00:47 +1000
committerGitHub <noreply@github.com>2019-05-02 23:00:47 +1000
commit7defa6f77e956bb0bac005741518fa657d2a8753 (patch)
treee5264f986509dd74a258177e84cc593de301a85e /include/core
parent877de75d8bfb2dc2f30b6a8d1968157f485125a1 (diff)
parent0b4be7bbfaf9ba7def310b4b01e4c7786ff19099 (diff)
downloadredot-cpp-7defa6f77e956bb0bac005741518fa657d2a8753.tar.gz
Merge pull request #271 from Windfisch/fix-register-property
Fix registering properties of reference-types by applying bruvzg's patch
Diffstat (limited to 'include/core')
-rw-r--r--include/core/Godot.hpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/include/core/Godot.hpp b/include/core/Godot.hpp
index 6fd3303..4789632 100644
--- a/include/core/Godot.hpp
+++ b/include/core/Godot.hpp
@@ -326,8 +326,13 @@ void register_property(const char *name, P(T::*var), P default_value, godot_meth
godot_string *_hint_string = (godot_string *)&hint_string;
godot_property_attributes attr = {};
- attr.type = def_val.get_type();
- attr.default_value = *(godot_variant *)&def_val;
+ if (def_val.get_type() == Variant::NIL) {
+ attr.type = Variant::OBJECT;
+ } else {
+ attr.type = def_val.get_type();
+ attr.default_value = *(godot_variant *)&def_val;
+ }
+
attr.hint = hint;
attr.rset_type = rpc_mode;
attr.usage = usage;
@@ -356,12 +361,19 @@ template <class T, class P>
void register_property(const char *name, void (T::*setter)(P), P (T::*getter)(), P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") {
Variant def_val = default_value;
+ godot_string *_hint_string = (godot_string *)&hint_string;
+
godot_property_attributes attr = {};
- attr.type = def_val.get_type();
- attr.default_value = *(godot_variant *)&def_val;
+ if (def_val.get_type() == Variant::NIL) {
+ attr.type = Variant::OBJECT;
+ } else {
+ attr.type = def_val.get_type();
+ attr.default_value = *(godot_variant *)&def_val;
+ }
attr.hint = hint;
attr.rset_type = rpc_mode;
attr.usage = usage;
+ attr.hint_string = *_hint_string;
_PropertySetFunc<T, P> *wrapped_set = (_PropertySetFunc<T, P> *)godot::api->godot_alloc(sizeof(_PropertySetFunc<T, P>));
wrapped_set->f = setter;