godot
godot copied to clipboard
[RTL] Add `pop_all`, `push_context` and `pop_context` methods, and use it for `print_rich` to avoid unclosed tags.
Fixes https://github.com/godotengine/godot/issues/78520
| Before | After |
|---|---|
Are there any benefits to doing this other than less code? Just curious if I should still do things the old way unless necessary.
Are there any benefits to doing this other than less code?
pop_all should be faster, but in real use cases it probably won't have any visible effect. The only real advantage, there's no need to count push_ calls to match with the same number of pops.
The only real advantage, there's no need to count
push_calls to match with the same number ofpops.
I believe in our built-in documentation we have plenty of cases where we need to pop N levels from the stack, but not all of it. Would something like a scope or a context make sense as well?
push_context(); // Start counting pushes.
push_...();
push_...();
push_...();
push_...();
pop_context(); // Pops 4 stack levels and removes context.
Added push_context / pop_context as well.
Thanks! Now someone could do a pass simplifying calls in the built-in help :)
Code simplification with new methods? I'm in.