Anonymous

Module:FunList: Difference between revisions

From Melvor Idle
Define metatable outside of ctor
(Add function overrides (as far as possible in Lua anyway) to first and firstordefault)
(Define metatable outside of ctor)
 
Line 1: Line 1:
local funlist = {}
local funlist = {}
funlist.__index = funlist
local funlist_mt = {
__index = funlist,
__pairs = function(t) return pairs(t.mytable) end,
__ipairs = function(t) return ipairs(t.mytable) end
}


-- Constructor
-- Constructor
function funlist.new(tbl)
function funlist.new(tbl)
     assert(type(tbl) == 'table')
     assert(type(tbl) == 'table', 'Value must be a non-nil table.')
 
    local self = setmetatable({}, {
local self = setmetatable({}, funlist_mt)
        __index = funlist,
        __pairs = function(self) return pairs(self.mytable) end,
        __ipairs = function(self) return ipairs(self.mytable) end
    })
      
      
self.mytable = tbl
self.mytable = tbl
2,875

edits