-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow overriding how scripted objects are converted to strings #27886
Conversation
Please edit the commit log to be more explicit, the first line of a Git commit log is it's title and should be a short but clear indication of what the commit does. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should cache the StringName
for "to_string"
(check core_string_names.cpp). Otherwise, it looks good.
@neikeq, I'll get this done during my lunch break today |
Should the method be named |
@Calinou I felt like omitting the
|
@neikeq I've added Edit: |
Ran clang-format, we should be good to go now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be bound with BIND_VMETHOD
so that it is properly identified as virtual
in the documentation (see _get_property_list
in object.cpp
, or all the virtual callbacks in node.cpp
).
The documentation should also be improved to mention that the method can be overridden from script to customize the String representation of objects. And I would describe what the default representation means ([name:rid]
).
Finally, I know that it's not done consistently but I think we do favor putting a leading underscore on virtual methods that can be overridden. See e.g. how get_minimum_size
calls _get_minimum_size
from scripts if overridden in control.cpp
. So you would still call to_string()
in your code (or it will be called behind the hood by print()
), but you can customize it by overriding _to_string()
.
@akien-mga I've implemented you requested changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NativeScript parts looks fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems mostly good to me, just a few nitpicks on documentation.
solves #26796 - ADD `String to_string()` method to Object which can be overriden by `String _to_string()` in scripts - ADD `String to_string(r_valid)` method to ScriptInstance to allow langauges to control how scripted objects are converted to strings - IMPLEMENT to_string for GDScriptInstance, VisualScriptInstance, and NativeScriptInstance - ADD Documentation about `Object.to_string` and `Object._to_string` - Changed `Variant::operator String` to use `obj->to_string()`
@akien-mga I've made changes to the documentation. Let me know if you'd prefer a better example, or that I use this kind of wording.
|
Thanks a lot for your contribution! :) |
Amazing! thank you @akien-mga |
solves #26796
String to_string()
method to Object which can be overriden by scriptsString to_string(r_valid)
method to ScriptInstance to allow langauges to control how scripted objects are converted to stringsObject.to_string
Variant::operator String
to useobj->to_string()