Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Table Class

function KnootTableClass(tbl)
    -- x = KnootTableClass() for create
    local tbl = tbl or {}
    
    local methods = {
        create = _create_instance,
        shift = function()
            local temp = tbl[1]
            table.remove(tbl,1)
            return temp
        end,
        pop = function()
            local temp = tbl[#tbl]
            tbl[#tbl] = nil
            return temp
        end,
        push = function(t, ...)
            local t = table.pack(...)
            for i = 0, #t do
                table.insert(tbl,t[i])
            end
            return #tbl
        end,
        unshift = function(t,...)
            local t = table.pack(...)
            for i=#t, 1, -1 do
                table.insert(tbl, 1, t[i])
            end
            return #tbl
        end,
        dump = function(tbl,l)
            local str = '{'
            l = l or 1
            if l>100 then return 'overstack' end
            for k,v in pairs(tbl) do
                str = str.."\n"..string.rep('\t', l)..k.." = "
                if type(v) == 'table' then
                    str = str..v:dump(l+1)
                elseif type(v) == 'function' then
                    str = str..'function'
                else
                    str = str..tostring(v)
                end
            end
            str = str..'\n'..string.rep('\t', l-1)..'}'
            return str
        end
    }
    
	setmetatable(tbl, {
        __index = setmetatable(
            methods, {}
        ),
        __newindex = function(t,k,v)
            local function metatable(t)
                t = KnootTableClass(t)
                for k,v in pairs(t) do
                    if type(v)=='table' then metatable(v) end
                end
                return t
            end
            if type(v) == 'table' then
                v=metatable(v)
            end
            
            rawset(t, k, v)
        end
    })

    return tbl
end
local t = KnootTableClass()
t.test = 123
t:push(7,14,{18,['test']={21,17}})
t[3]['Печать Триумвирата'] = {123, 321}
table.insert(t, {
		['itemName']={
			link = 'item',
			ico = 'iconFileDataID',
			need = {2},
			offSpec = {4},
			transmog = {1},
			lootSpec = 'lootSpec',
			isTransmog = 'isTransmog',
			ilvls = {{},{},{}},
			endTime = 'endTime',
			hide = 'hide',
			test = testRoll or false,
		}
	})
print(t:dump())

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.