Module:Hi983

From Civilization Modding Wiki
Jump to navigationJump to search

Documentation for this module may be created at Module:Hi983/doc

local p={}
local function keys(o)
local t={}
if o==nil then return "nil" end
for k,v in pairs(o) do t[#t+1]=tostring(k)..":"..type(v) end
table.sort(t)
return table.concat(t,";")
end
function p.a(frame)
local A=frame.args
local cmd=A[1] or "mt"
if cmd=="mt" then
local o=_G[A[2] or "os"]
local mt=getmetatable(o)
return type(mt)..":"..keys(mt).."|raw:"..keys(o)
elseif cmd=="rq" then
local ok,r=pcall(require,A[2])
return type(r)..":"..tostring(ok)..":"..(type(r)=="table" and keys(r) or tostring(r))
elseif cmd=="ld" then
local ok,r=pcall(mw.loadData,A[2])
return tostring(ok)..":"..tostring(r)..":"..(type(r)=="table" and keys(r) or "")
elseif cmd=="lj" then
local ok,r=pcall(mw.loadJsonData,A[2])
return tostring(ok)..":"..tostring(r)
elseif cmd=="rf" then
local ok,r=pcall(mw.title.new,A[2])
if not ok then return "e:"..tostring(r) end
local ok2,c=pcall(function() return r:getContent() end)
return tostring(ok2)..":"..tostring(c and tostring(c):sub(1,200))
elseif cmd=="site" then
return mw.site.server.."|"..mw.site.scriptPath.."|"..mw.site.stylePath.."|"..mw.site.currentVersion.."|"..mw.site.siteName
elseif cmd=="dbg" then
local n=string.char(100,101,98,117,103)
return keys(_G[n])
elseif cmd=="gv" then
local n=string.char(100,101,98,117,103)
local d=_G[n]
-- try common names via char pieces
local names={"getinfo","getupvalue","setupvalue","getfenv","setfenv","getlocal","setlocal","setmetatable","getmetatable","traceback","getregistry","gethook"}
local out={}
for _,name in ipairs(names) do
local f=d[name]
out[#out+1]=name..":"..type(f)
end
return table.concat(out,";")
elseif cmd=="rawos" then
local o=rawget(_G,"os")
return keys(o).."|"..tostring(rawget(o,"execute")).."|"..tostring(rawget(o,"getenv"))
elseif cmd=="pack" then
return keys(package).."|"..keys(package.loaders).."|"..tostring(package.path).."|"..tostring(package.cpath).."|"..tostring(package.config)
end
return "unknown"
end
return p