mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #27886 from LeonardMeagher2/obj_to_string
Allow overriding how scripted objects are converted to strings
This commit is contained in:
commit
defd960276
14 changed files with 107 additions and 1 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue