词条 | Module:Sandbox/Wnt/DisplayLuaTableContents |
释义 | local p={} local debuglog = "" function p.flat(t) local todo = {t} local pointer = 1 local flat = {} local marked = {} marked[t] = true for i, j in pairs(todo[pointer]) do if ((type(j) == table) and (not marked[j])) then debuglog = debuglog .. "marking" .. tostring(j) marked[j] = true table.insert(todo, j) end if (not flat[i]) then debuglog = debuglog .. "new item" .. tostring(i) flat[i] = {j = true} else if (not flat[i][j]) then flat[i][j] = true end end end pointer = pointer + 1 end debuglog = debuglog .. tostring(#flat) return flat end function p.tostring(t, delimiter) if not delimiter then delimiter = "" end local flat = p.flat(t) local outarray = {} for i, j in pairs(flat) do debuglog = debuglog .. tostring(i) .. tostring(j) local kk = {} for k in pairs(j) do table.insert(kk, k) end table.insert(outarray, table.concat(kk, delimiter)) end return table.concat(outarray, delimiter) end function p.demo(frame) local a = {j=1, 2, 3} table.insert(a,a) -- a[a] = a -- (this may be just too crazy; getting "attempt to call a table value") return p.tostring(a)..debuglog end
function p.main(frame) local args=frame.args local pargs=frame.getParent(frame) local dispvar="mw" if pargs then dispvar=pargs.dispvar or pargs[1] or dispvar end if args then dispvar=args.dispvar or args[1] or dispvar end local base=_G[dispvar] local novar, containssomething if base then else base={};novar=yes end local output="''Contents of the array '''''" .. tostring(dispvar) .. "''':" if novar then output = output .. "nil." end local ns=0 local count=0 for i,j in pairs(base) do containssomething="yes" output=output .. " end return p |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。