Difference between revisions of "ObjectType:stack"
Jump to navigation
Jump to search
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | {{ObjectType-Vitals|stack|[[LavishScript]]|[[ObjectType:objectcontainer|objectcontainer]]|NULL|stack|yes|LSStack *}} | ||
== Overview == | == Overview == | ||
− | |||
A '''stack''' is a first-in last-out list of objects. | A '''stack''' is a first-in last-out list of objects. | ||
== Members == | == Members == | ||
− | *sub-type ''' | + | *sub-type '''Top''': Retrieves the first object in the stack |
== Methods == | == Methods == | ||
Line 35: | Line 35: | ||
== Viewing the stack == | == Viewing the stack == | ||
− | To access the first object in the stack (e.g. the first person in line), use the | + | To access the first object in the stack (e.g. the first person in line), use the Top member, as demonstrated in this example |
=== Example 1 === | === Example 1 === | ||
variable stack:int MyStack | variable stack:int MyStack | ||
MyStack:Push[15] | MyStack:Push[15] | ||
MyStack:Push[25] | MyStack:Push[25] | ||
− | echo \${MyStack. | + | echo \${MyStack.Top} should be 25: ${MyStack.Top} |
MyStack:Pop | MyStack:Pop | ||
/* Only 15 is now in the stack */ | /* Only 15 is now in the stack */ | ||
− | echo \${MyStack. | + | echo \${MyStack.Top} should be 15: ${MyStack.Top} |
== See Also == | == See Also == | ||
− | + | {{LavishScript:ObjectType}} | |
− | |||
− |
Latest revision as of 16:14, 8 July 2018
stack | |
Defined By | LavishScript |
Inherits | objectcontainer |
Reduces To | NULL |
Variable Object Type | stack |
Uses Sub-Types | yes |
C/C++ Type | LSStack * |
Contents
Overview
A stack is a first-in last-out list of objects.
Members
- sub-type Top: Retrieves the first object in the stack
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
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).
Example 1
Declaring a stack of "int"
variable stack:int MyStack
Adding items to a stack
To add an item to a stack, use the stack method, as demonstrated in this example
Example 1
variable stack:int MyStack MyStack:Push[15] MyStack:Push[25]
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
Example 1
variable stack:int MyStack MyStack:Push[15] MyStack:Push[25] MyStack:Pop /* Only 15 is now in the stack */
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
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}
See Also
LavishScript Object Types
- Text
- string - mutablestring - unistring
- Numbers
- byte - float - float64 - int - uint - int64
- Boolean (TRUE/FALSE)
- bool
- Pointers
- boolptr - byteptr - floatptr - float64ptr - intptr - uintptr - int64ptr - rgbptr - stringptr
- Containers
- objectcontainer - array - index - collection - queue - stack - set - variablescope
- JSON
- jsonobject - jsonarray - jsonvaluecontainer - jsonvalue
- Iteration
- iterator - jsoniterator
- Date/Time
- time
- File Handling
- filepath - file - filelist - filelistentry
- Tasks
- lavishmachine - Accessed via the Top-Level Object LMAC
- task - tasklibrary - taskmanager - tasktype - taskpulseargs - elmactaskstate