Skip to content

Add more functions to ArrayStack#2019

Merged
peace-maker merged 4 commits intoalliedmodders:masterfrom
Mikusch:adt_stack-functions
Sep 27, 2023
Merged

Add more functions to ArrayStack#2019
peace-maker merged 4 commits intoalliedmodders:masterfrom
Mikusch:adt_stack-functions

Conversation

@Mikusch
Copy link
Contributor

@Mikusch Mikusch commented Jul 18, 2023

ArrayStack can be useful at times, but the lack of functions makes it pretty limiting. This PR adds new natives for peeking at the top value of the stack without actually removing it, as well as a property to fetch the amount of elements in the stack.

Adds the following natives:
ArrayStack.Top
ArrayStack.TopString
ArrayStack.TopArray

And a property:
ArrayStack.Length

@Mooshua
Copy link

Mooshua commented Jul 19, 2023

More of a bikeshed, but a term more people will probably be familiar with (and I believe better explains it's behavior) for Top is Peek.

@Mikusch
Copy link
Contributor Author

Mikusch commented Jul 19, 2023

More of a bikeshed, but a term more people will probably be familiar with (and I believe better explains it's behavior) for Top is Peek.

I thought about using ArrayStack.Peek but decided not to, since most implementations I looked at do use the Top naming, for example C++'s std::stack and Valve's CUtlStack.

@Mikusch Mikusch requested a review from dvander July 30, 2023 16:10
@sapphonie
Copy link
Contributor

More of a bikeshed, but a term more people will probably be familiar with (and I believe better explains it's behavior) for Top is Peek.

I thought about using ArrayStack.Peek but decided not to, since most implementations I looked at do use the Top naming, for example C++'s std::stack and Valve's CUtlStack.

Why not both? Make Peek an alias for Top?

Copy link
Member

@peace-maker peace-maker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thank you! I think keeping it close to the SDK naming is sane.

@peace-maker peace-maker merged commit 1e8db95 into alliedmodders:master Sep 27, 2023
@Mikusch Mikusch deleted the adt_stack-functions branch September 27, 2023 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants