FANDOM


local p = {}
local inspect = require('Dev:Inspect')
 
--------------------------------------------------------------------------------
-- Here is the solution:
--------------------------------------------------------------------------------
 
-- <onlyinclude><nowiki>
function p.final(frame)
    local clone = mw.clone(frame)
    local metatable = getmetatable(clone.args)
 
    metatable.__index = nil
    metatable.__pairs = nil
 
    clone.args.bb = nil
    clone.args.cc = nil
 
    return '<pre>' .. inspect(clone) .. '</pre>'
end
-- (Ignore this line.)</nowiki></onlyinclude>
 
--------------------------------------------------------------------------------
-- Everything below this point is kept for posterity.
--------------------------------------------------------------------------------
 
local function makePseudoFrame(frame)
    if type(frame) ~= "table" then
        error("frame must be a table")
    end
 
    local pseudoFrame = {}
 
    for name in pairs(frame) do
        pseudoFrame[name] = function (pseudoFrame, ...)
            return frame[name](frame, ...)
        end
    end
 
    pseudoFrame.args = mw.clone(frame.args)
    pseudoFrame.args.a = nil
 
    function pseudoFrame:getParent()
        if frame:getParent() then
            return makePseudoFrame(frame:getParent())
        end
    end
 
    return pseudoFrame
end
 
function p.usePseudoFrame(frame)
    local pseudoFrame = makePseudoFrame(frame)
 
    return '<pre>' .. inspect(pseudoFrame) .. '</pre>'
end
 
--------------------------------------------------------------------------------
 
function p.keepMetatable(frame)
    local clone = mw.clone(frame)
 
    clone.args.a = nil
 
    return '<pre>' .. inspect(clone) .. '</pre>'
end
 
--------------------------------------------------------------------------------
 
function p.removeMetatable(frame)
    local clone = mw.clone(frame)
 
    setmetatable(clone.args, nil)
    clone.args.a = nil
 
    return '<pre>' .. inspect(clone) .. '</pre>'
end
 
--------------------------------------------------------------------------------
 
function p.reattachMetatable(frame)
    local clone = mw.clone(frame)
    local metatable = getmetatable(clone.args)
 
    setmetatable(clone.args, nil)
    clone.args.a = nil
    setmetatable(clone.args, metatable)
 
    return '<pre>' .. inspect(clone) .. '</pre>'
end
 
--------------------------------------------------------------------------------
 
function p.attachMetatableClone(frame)
    local clone = mw.clone(frame)
    local metatable = getmetatable(clone.args)
    local metatableClone = mw.clone(metatable)
 
    setmetatable(clone.args, nil)
    clone.args.a = nil
    setmetatable(clone.args, metatableClone)
 
    return '<pre>' .. inspect(clone) .. '</pre>'
end
 
--------------------------------------------------------------------------------
 
function p.removeMetamethod(frame)
    local clone = mw.clone(frame)
    local metatable = getmetatable(clone.args)
 
    metatable.__index = nil
    clone.args.a = nil
 
    return '<pre>' .. inspect(clone) .. '</pre>'
end
 
--------------------------------------------------------------------------------
 
local function buildNewMetatable(frame)
    local clone = mw.clone(frame)
    local mt = {}
 
    function mt.__pairs()
        return next, clone.args
    end
 
    function mt.__ipairs()
        local function inext(_, i)
            local value = clone.args[i + 1]
 
            if value then
                return i + 1, value
            end
        end
 
        return inext, nil, 0
    end
 
    setmetatable(clone.args, mt)
    clone.args.b = nil
    clone.args[2] = nil
 
    return clone
end
 
function p.useNewMetatable(frame)
    local clone = buildNewMetatable(frame)
 
    return '<pre>' .. inspect(clone) .. '</pre>'
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.