ObjectType:stack
From Lavish Software Wiki
Contents |
[edit]
Overview
| stack | |
| Defined By | LavishScript |
| Inherits | objectcontainer |
| Reduces To | NULL |
| Variable Object Type | stack |
| Uses Sub-Types | yes |
| C/C++ Type | LSStack * |
A stack is a first-in last-out list of objects.
[edit]
Members
- sub-type Top: Retrieves the first object in the stack
[edit]
Methods
- Push[...]: Adds an object to the stack, passing any parameters to the initialization for the given object type
- Pop: Removes the first object in the stack
[edit]
Declaring stack Variables
stack objects require a sub-type -- an object type to be a stack of. Append the sub-type to the word stack, with a colon separating the words. It is possible to have sub-subtypes (such as stack:stack:int for a stack of stacks of ints).
[edit]
Example 1
Declaring a stack of "int"
variable stack:int MyStack
[edit]
Adding items to a stack
To add an item to a stack, use the stack method, as demonstrated in this example
[edit]
Example 1
variable stack:int MyStack MyStack:Push[15] MyStack:Push[25]
[edit]
Removing items from a stack
Items are removed in the order stackd -- the first item stackd is the first that will be removed. To remove an item, use the Pop method, as demonstrated in this example
[edit]
Example 1
variable stack:int MyStack MyStack:Push[15] MyStack:Push[25] MyStack:Pop /* Only 15 is now in the stack */
[edit]
Viewing the stack
To access the first object in the stack (e.g. the first person in line), use the Top member, as demonstrated in this example
[edit]
Example 1
variable stack:int MyStack
MyStack:Push[15]
MyStack:Push[25]
echo \${MyStack.Top} should be 25: ${MyStack.Top}
MyStack:Pop
/* Only 15 is now in the stack */
echo \${MyStack.Top} should be 15: ${MyStack.Top}
[edit]
