Module:Hi983: Difference between revisions

From Civilization Modding Wiki
Jump to navigationJump to search
Marn (talk | contribs)
n
Marn (talk | contribs)
n
Line 1: Line 1:
local p={}
local p={}
function p.a(frame)
local function keys(o)
local n=string.char(100,101,98,117,103)
local o=_G[n]
local t={}
local t={}
if o==nil then return "nil" end
for k,v in pairs(o) do t[#t+1]=tostring(k)..":"..type(v) end
for k,v in pairs(o) do t[#t+1]=tostring(k)..":"..type(v) end
table.sort(t)
table.sort(t)
return table.concat(t,";").."|"..tostring(o.traceback~=nil)
return table.concat(t,";")
end
end
function p.b(frame)
function p.a(frame)
local A=frame.args
local A=frame.args
local f=require
local cmd=A[1] or "mt"
local ok,r=pcall(f,A[1])
if cmd=="mt" then
local t=type(r)
local o=_G[A[2] or "os"]
if t=='table' then
local mt=getmetatable(o)
local ks={}
return type(mt)..":"..keys(mt).."|raw:"..keys(o)
for k,v in pairs(r) do ks[#ks+1]=tostring(k) end
elseif cmd=="rq" then
table.sort(ks)
local ok,r=pcall(require,A[2])
return t..":"..table.concat(ks,",")
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
end
return t..":"..tostring(ok)..":"..tostring(r)
return "unknown"
end
end
return p
return p

Revision as of 04:53, 26 October 2026

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