Jump to content

Module:Amalthea

Unchecked
From Wikipedia

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

--require "mw.lang"
--require "mw.page"
--require "mw.query"
--require "mw.site"
--require "mw.time"
--require "mw.title"
--require "mw.text"
--require "mw.url"
require "hex"
--require "bin"
--require "ustring"

local p = {}

local function count(tbl)
  local res=0
  for k,v in pairs(tbl) do res=res+1 end
  return res
end

local function listGlobalsHelper(obj, indent)
    local foo = ''
    for k, v in pairs(obj) do
        if k ~= "_G" then
            foo = foo .. indent .. "'" .. k .. "' => "
            if type(v)=='table' then
                if count(v)==0 then
                    foo = foo .. "{ }\n"
                else
                    foo = foo .. "{\n" .. listGlobalsHelper(v, indent .. '  ') .. indent .. "}\n"
                end
            else
                foo = foo .. tostring(v) .. "\n"
            end
        end
    end
    return foo
end

function p.listGlobals()
    return "<pre>"..listGlobalsHelper(_G, '').."</pre>"
end

function p.testUnicode()
    return 'test: öäüßمدیا מיוחד Мэдыя '
end

function testUnicode2Helper(s)
    return "'" .. s .. "': " .. s:len() .. "\n"
end
function p.testUnicode2()
    return testUnicode2Helper("$") .. testUnicode2Helper("¢") .. testUnicode2Helper("€") .. testUnicode2Helper("𤭢");
end
function p.testUnicode2Raw(frame)
    return testUnicode2Helper(frame.args[1]);
end

return p