Module:Sandbox/BotAntony

From Terraria Wiki
Jump to navigation Jump to search

No documentation subpage exists yet for this module. Create one now.


local p = {}

local data = mw.loadData("Module:GameText/loaddata-en")

local function spairs(t, order)
    -- collect the keys
    local keys = {}
    for k in pairs(t) do keys[#keys+1] = k end

    -- if order function given, sort by it by passing the table and keys a, b,
    -- otherwise just sort the keys 
    if order then
        table.sort(keys, function(a,b) return order(t, a, b) end)
    else
        table.sort(keys)
    end

    -- return the iterator function
    local i = 0
    return function()
        i = i + 1
        if keys[i] then
            return keys[i], t[keys[i]]
        end
    end
end


function p.main()
	local t = {}
	for mainKey, keys in spairs(data) do
		t[mainKey] = {}
		for k, _ in spairs(keys) do
			t[mainKey][k] = mainKey .. '.' .. k
		end
	end
	return '<pre>' .. mw.text.jsonEncode(t, mw.text.JSON_PRESERVE_KEYS) .. '</pre>'
end

return p