Module:Debug

-- //Helps debug lua modules using console by creating a pseudo frame and other useful functions Syntax: require("Module:debug").frame(childtable,parenttable) frame = require("Module:debug").frame({'aaa','sss'},{'zz'=8,'1'}) ex. frame.showargs, p.main(frame) Todo: Add more frame methods add debug traceback and debugging tools --

local p = {} local debugFrame = {}

-- //Creates a pseudo frame function debugFrame.new (args1,pArgs1) local self = {} self.args = {} self.pArgs ={args={}} function self:setArgs(childArgs,parentArgs) if childArgs then self.args =  childArgs or {} end if (parentArgs) then self.pArgs = {args= parentArgs} end end function self:getParent if (pArgs ) then return pArgs end end

function self:preprocess(sWikiText) return sWikiText end function self:showargs local sChild = nil--"Child parameters:\n" local sParent = "Parent parameters:\n" if (self.args) then for i,v in pairs(self.args) do               sChild = sChild .."\n Key: "..i .. "- Value: " ..v           end end if (self.pArgs.args) then for i,v in pairs(self.pArgs.args) do               sParent = sParent .."\n Key: "..i .. " - Value: " ..v            end end mw.log(sChild .."\n\n"..sParent) return sChild .."\n\n"..sParent end self:setArgs(args1,pArgs1) return self end

-- args,pArgs - table, e.g. {"abc","zz"} parameters from a page calling this module directly function p.frame(args,pArgs) return debugFrame.new(args,pArgs) end

-- Generates a tracebackfor a function -- ex. function fFunction x=1 +c end ; p.trace(fFunction) function p.trace(errFunction,...) local function testFunc return errFunction(unpack(arg)) end local success, result = xpcall(testFunc,       function(err)             mw.log(debug.traceback(err) )            return debug.traceback(err)         end) return success, result end

return p