godot icon indicating copy to clipboard operation
godot copied to clipboard

[RTL] Add `pop_all`, `push_context` and `pop_context` methods, and use it for `print_rich` to avoid unclosed tags.

Open bruvzg opened this issue 2 years ago • 4 comments

Fixes https://github.com/godotengine/godot/issues/78520

Before After
Screenshot 2023-07-04 at 09 50 44 Screenshot 2023-07-04 at 09 51 06

bruvzg avatar Jul 04 '23 06:07 bruvzg

Are there any benefits to doing this other than less code? Just curious if I should still do things the old way unless necessary.

MewPurPur avatar Jul 04 '23 11:07 MewPurPur

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.

bruvzg avatar Jul 04 '23 12:07 bruvzg

The only real advantage, there's no need to count push_ calls to match with the same number of pops.

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.

YuriSizov avatar Jul 07 '23 18:07 YuriSizov

Added push_context / pop_context as well.

bruvzg avatar Jul 09 '23 18:07 bruvzg

Thanks! Now someone could do a pass simplifying calls in the built-in help :)

YuriSizov avatar Jul 14 '23 17:07 YuriSizov

Code simplification with new methods? I'm in.

MewPurPur avatar Jul 14 '23 18:07 MewPurPur