It looks like you're new here. If you want to get involved, click one of these buttons!
Queue = Core.class() function Queue:init(list) if not list then self.q = {} self.first = 0 self.last = -1 else self.q = list self.first = 1 self.last = #list end end function Queue:push(item) self.last = self.last + 1 self.q[self.last] = item end function Queue:pop() --local first = self.first if self.first <= self.last then --local q = self.q local value = self.q[self.first] self.q[self.first] = nil self.first = self.first + 1 return value end end function Queue:iterator() return function() return self:pop() end end function Queue:length() return (self.last-self.first+1) end |
local q = Queue.new({"apples", "oranges", "bananas"}) q:push("strawberries") q:push("grapes") print("The queue length: "..q:length()) print("Pop off the queue: "..q:pop()) for item in q:iterator() do print("Pop of the queue: "..item) end |
Likes: antix, talis, SinisterSoft
Comments
Dislikes: vitalitymobile
How would one go about applying a patch? Is Gideros tied to Lua 5.1? Is there a reason why we can not more to Lua 5.x?
Yes, Gideros is tied to 5.1 because for 5.3 we will need to rewrite each plugin to be compatible with it and of course Lua should be rewritten too (Gideros needs patched Lua to work). It is hard work. However I have patched our Lua with many good things from Lua 5.3 (like utf8, int64, bitwise ops etc) so it only misses few features from newer versions e.g. this '__len' property.
Likes: simwhi
@antix I've removed the setmetatable call and changed the following function:
Likes: antix
Likes: simwhi
http://www.lua.org/pil/11.4.html
Likes: simwhi
Fragmenter - animated loop machine and IKONOMIKON - the memory game
@totebo Thanks. I just wanted to share some knowledge and also learn more about Lua (especially the internal parts).
https://deluxepixel.com
Likes: SinisterSoft