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/gdscript/gdscript.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/gdscript/gdscript.cpp')
-rw-r--r-- | modules/gdscript/gdscript.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index d7a809eb5f..3fb9268702 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -30,6 +30,7 @@ #include "gdscript.h" +#include "core/core_string_names.h" #include "core/engine.h" #include "core/global_constants.h" #include "core/io/file_access_encrypted.h" @@ -1234,6 +1235,27 @@ void GDScriptInstance::notification(int p_notification) { } } +String GDScriptInstance::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(); +} + Ref<Script> GDScriptInstance::get_script() const { return script; |