Module:SandboxFrame

local p = {}

--global ? foo = 1 _G.foo = 2

--[[ -- This returns a function that adds a number to its argument function makeAdder( n )   return function( x )        -- The variable n from the outer scope is available here to be added to x        return x + n    end end

local add5 = makeAdder( 5 ) mw.log( add5( 6 ) ) -- prints 11 --]]

local function pc( fcn, args ) -- protected-calls always return true/false first.. if args == nil then return 'missing args for pcall. \n' end local ok, result = pcall( fcn, args ) if ok then return result else return 'ERROR...msg=' .. result .. '\n' end end

local function listTypes local ty   local result result = ';Types\n' result = result .. ':type(ty)=' .. type(ty) .. '\n' ty = true result = result .. ':type(ty)=' .. type(ty) .. '\n' ty = 'string' result = result .. ':type(ty)=' .. type(ty) .. '\n' ty = 8 result = result .. ':type(ty)=' .. type(ty) .. '\n' ty = {} result = result .. ':type(ty)=' .. type(ty) .. '\n' ty = function ( x ) return x end result = result .. ':type(ty)=' .. type(ty) .. '\n'

return result end

local function tableToString(t) local key local value local result result = '' for key, value in pairs(t) do       if (tonumber(key) ~= nil) then result = result .. ':table[' .. key .. '] is ' .. value .. '\n' else result = result .. ':table[\'' .. key .. '\'] is ' .. value .. '\n' end end return result end -- globals.lua -- show all global variables

seen={} xmsg=""

function dump(t,i) seen[t]=true local s={} local n=0 for k in pairs(t) do		n=n+1 s[n]=k end table.sort(s) for i,v in ipairs(s) do -- global-print is not available... --		print(i,v) --		xmsg = xmsg .. '<<' .. i .. '>>,<<' .. v .. '>>\n' xmsg = xmsg .. 'k[' .. i .. ']=\'' .. v .. '\'\n' v=t[v] if type(v)=="table" and not seen[v] then dump(v,i.."\t") end end end

--dump(_G,"") -- from: http://www.lua.org/cgi-bin/demo?globals

local function listGlobals local k   local v    local result result = ';listGlobals\n' xmsg = "" --   dump(_G,"") result = result .. xmsg return result end

function p.Setup(frame) local result result = ';Setup\n' result = result .. listTypes .. '\n' --   result = result .. listGlobals .. '\n' result = result .. pc( listGlobals, "" ) .. '\n' result = result .. ':Lua-version=' .. _VERSION .. '\n' return result end

function p.Setuptbd(frame) local result result = ';Setup\n' result = result .. ':loaded=' .. tableToString(package.loaded) .. '\n' result = result .. ':getCurrentFrame=' .. mw.getCurrentFrame(frame) .. '\n' result = result .. ':dumpObject=' .. mw.dumpObject(frame) .. '\n' result = result .. ':allToString=' .. mw.allToString(frame) .. '\n' return result end

function p.args(frame) -- note: frame.args is a metatable, so need a mw.clone to do table-functions...   return ';args\n' .. tableToString(frame.args) end

function p.pargs(frame) return ';Parent-args\n' .. tableToString(frame:getParent.args) end

function p.callParserFunction(frame) --   return ';callParserFunction\n:' .. frame:callParserFunction('#time', 'Y-m-d H:i:s') .. '\n' -- see: https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Frame_object -- beware paren-vs-brace --   return ';callParserFunction\n:' .. frame:callParserFunction{ name = '#time', args = {'Y-m-d H:i:s'} } .. '\n' --   return ';callParserFunction\n:' .. frame:callParserFunction('#PAGEID:Module:SandboxFrame' ) .. '\n' return ';callParserFunction - NO JOY...\n:' end

function p.expandTemplate(frame) --   return ';expandTemplate\n:' .. frame:expandTemplate({title = 'Template:Sandbox', args = {'arg1', 'arg2'}}) .. '\n' --   return ';expandTemplate\n:' .. frame:expandTemplate({title = 'Level', args = {'arg1', 'arg2'}}) .. '\n' local msg0 = ';expandTemplate-0 \n:' local msg1 = ';expandTemplate-1 \t:' msg1 = msg1 .. frame:expandTemplate({title = 'IIC', args = {'green', '60px'}}) ..'\n' local msg2 = ';expandTemplate-2 -- direct\n:' -- cannot use NUMERICAL value 4 --   msg2 = msg2 .. frame:expandTemplate({title = 'DunHeroInfo', args = {'Yeti', 4}}) ..'\n' msg2 = msg2 .. frame:expandTemplate({title = 'DunHeroInfo', args = {'Yeti', '4'}}) ..'\n' local msg3 = ';expandTemplate-2 -- via-args-passed...\t:' -- IMPORTANT to do...   -- cannot shorten ? local title local args args = mw.clone(frame.args) msg3 = msg3 .. ';args1\t' .. tableToString(args) .. '\n' title = table.remove(args,1) msg3 = msg3 .. type(title) .. ';args2-rem\t' .. tableToString(args) -- stupid template re-creates the frame.args again... --   msg3 = msg3 .. frame:expandTemplate({title=title,args=args}) --   msg3 = msg3 .. frame:expandTemplate({title=title,args=mw.clone(args)}) msg3 = msg3 .. frame:expandTemplate({title=title,args={args[1],}}) return msg1 .. msg2 .. msg3 .. '\n' end

function p.extensionTag(frame) --   return ';extensionTag\n:' .. frame:extensionTag('nowiki', 'text', {}) .. '\n' return ';extensionTag - NO JOY...\n:' end

function p.getParent(frame) frame = frame:getParent return ';getParent-Title\n:' .. frame:getTitle .. '\n' end

function p.getTitle(frame) return ';getTitle\n:' .. frame:getTitle .. '\n' end

return p