Module:Devmodule/sandbox

-- //Invokes global modules from dev.wikia.com -- syntax -- local p ={} -- Creates a pseudo frame local pseudoFrame ={} function pseudoFrame.new (originalFrame) local self = {} if originalFrame and type(originalFrame)=="table" then for sName,oFunc in pairs(originalFrame) do           self[sName] = function (self,...) tArgs = unpack(arg) return originalFrame[sName](originalFrame,tArgs) end end else return error("Frame must be a table.") end self.args = mw.clone(originalFrame.args) self.args["#modulename"] = nil self.args["#mod"] = nil self.args["#fname"] = nil function self:getParent if (originalFrame:getParent) then return pseudoFrame.new (originalFrame:getParent) end end return self end --Strips away devmodule's parameter from frame and creates new frame function p.main(originalFrame) local sModuleName,sFunctionName local frame = pseudoFrame.new(originalFrame) local oFrameParent = originalFrame:getParent local oFrameChild = originalFrame if oFrameParent then sModuleName,sFunctionName = getInvokeDetails(oFrameParent) if not sModuleName  then sModuleName,sFunctionName = getInvokeDetails (oFrameChild) end else sModuleName,sFunctionName = getInvokeDetails (oFrameChild) end if type(sModuleName)=="string" then sModuleName= sModuleName:sub(1,1):upper .. sModuleName:sub(2) else return error("Right syntax:\#invoke:devmodule|aa|bb|cc|#fname=main|#modulename=if") end local bStatus,sResults = pcall(loadModule,sModuleName,sFunctionName,frame) if not(bStatus) then local bModuleUnavailable = sResults:match("module.*("..sModuleName..").*not found") if (bModuleUnavailable) then return "`Module:".. sModuleName .."` doesn't exist in dev.wikia ." end end return sResults end

function getInvokeDetails(oFrame) if oFrame and oFrame.args then local sModuleName= oFrame.args["#mod"] or oFrame.args["#modulename"] local sFunctionName = oFrame.args["#fname"] return sModuleName,sFunctionName end end

function loadModule(sModuleName,sFunctionName,frame) local globalModule = require("Dev:"..sModuleName) sFunctionName = sFunctionName or "main" if (sFunctionName) and globalModule[sFunctionName] then return globalModule[sFunctionName](frame) end end return p