Game Development Reference
In-Depth Information
-- get num of values from stack
local num = num or 1
-- return table
local entries = {}
-- get values into entries
for i = 1, num do
-- get last entry
if #self._entries ~= 0 then
table.insert(entries, self._entries[#self._entries])
-- remove last value
table.remove(self._entries)
else
break
end
end
-- return unpacked entries
return unpack(entries)
end
-- get the number of entries on the stack
function theStack:getn()
return #self._entries
end
-- print the list values on the stack
function theStack:list()
for i,v in pairs(self._entries) do
print(i, v)
end
end
return theStack
end
And using it is as simple as this:
myStack = _stack:create()
myStack:push("A","small","world")
print(myStack:pop(2))
myStack:list()
print(myStack:pop(1))
Converting Between Parameters and Tables
Sometimes functions take a variable number of parameters and sometimes they take tables. A
simple example would be in the case of colors that are specified as a tuple, but in some functions
they would be required to be given as r, g, and b values instead of the table.
 
Search WWH ::




Custom Search