diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2019-05-20 22:37:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-20 22:37:01 +0200 |
commit | defd9602764c13d1b7753cf879bdbcdf56335b33 (patch) | |
tree | c387b6a7602d1a9737938cf9c3047a56f08d0244 /modules/gdnative/nativescript/nativescript.cpp | |
parent | fdea3d48b041cff23013e7a424e57c814ddd4dbd (diff) | |
parent | f7eb426e2ebafc5598b0e43baf37d9a50cea1648 (diff) | |
download | redot-engine-defd9602764c13d1b7753cf879bdbcdf56335b33.tar.gz |
Merge pull request #27886 from LeonardMeagher2/obj_to_string
Allow overriding how scripted objects are converted to strings
Diffstat (limited to 'modules/gdnative/nativescript/nativescript.cpp')
-rw-r--r-- | modules/gdnative/nativescript/nativescript.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index c2aa8427b4..f30c9da4c1 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -32,6 +32,7 @@ #include "gdnative/gdnative.h" +#include "core/core_string_names.h" #include "core/global_constants.h" #include "core/io/file_access_encrypted.h" #include "core/os/file_access.h" @@ -771,6 +772,27 @@ void NativeScriptInstance::notification(int p_notification) { call_multilevel("_notification", args, 1); } +String NativeScriptInstance::to_string(bool *r_valid) { + if (has_method(CoreStringNames::get_singleton()->_to_string)) { + Variant::CallError ce; + Variant ret = call(CoreStringNames::get_singleton()->_to_string, NULL, 0, ce); + if (ce.error == Variant::CallError::CALL_OK) { + if (ret.get_type() != Variant::STRING) { + if (r_valid) + *r_valid = false; + ERR_EXPLAIN("Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); + ERR_FAIL_V(String()); + } + if (r_valid) + *r_valid = true; + return ret.operator String(); + } + } + if (r_valid) + *r_valid = false; + return String(); +} + void NativeScriptInstance::refcount_incremented() { Variant::CallError err; call("_refcount_incremented", NULL, 0, err); |