<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.americanmusicclub.com/index.php?action=history&amp;feed=atom&amp;title=Module%3ATable</id>
	<title>Module:Table - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.americanmusicclub.com/index.php?action=history&amp;feed=atom&amp;title=Module%3ATable"/>
	<link rel="alternate" type="text/html" href="https://wiki.americanmusicclub.com/index.php?title=Module:Table&amp;action=history"/>
	<updated>2026-04-05T03:20:57Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.7</generator>
	<entry>
		<id>https://wiki.americanmusicclub.com/index.php?title=Module:Table&amp;diff=28709&amp;oldid=prev</id>
		<title>Amc-admin: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://wiki.americanmusicclub.com/index.php?title=Module:Table&amp;diff=28709&amp;oldid=prev"/>
		<updated>2018-01-13T00:28:58Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = {}&lt;br /&gt;
&lt;br /&gt;
-- A number of functions, most of them imported from [[wikt:Module:table]], a&lt;br /&gt;
-- spinoff of [[Module:TableTools]].&lt;br /&gt;
&lt;br /&gt;
local libraryUtil = require(&amp;#039;libraryUtil&amp;#039;)&lt;br /&gt;
local checkType = libraryUtil.checkType&lt;br /&gt;
local checkTypeMulti = libraryUtil.checkTypeMulti&lt;br /&gt;
&lt;br /&gt;
local function _check(funcName, expectType)&lt;br /&gt;
	if type(expectType) == &amp;quot;string&amp;quot; then&lt;br /&gt;
		return function(argIndex, arg, nilOk)&lt;br /&gt;
			checkType(funcName, argIndex, arg, expectType, nilOk)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		return function(argIndex, arg, expectType, nilOk)&lt;br /&gt;
			if type(expectType) == &amp;quot;table&amp;quot; then&lt;br /&gt;
				checkTypeMulti(funcName, argIndex, arg, expectType, nilOk)&lt;br /&gt;
			else&lt;br /&gt;
				checkType(funcName, argIndex, arg, expectType, nilOk)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
	Returns a list of the keys in a table, sorted using either a default&lt;br /&gt;
	comparison function or a custom keySort function.&lt;br /&gt;
]]&lt;br /&gt;
function p.keysToList(t, keySort, checked)&lt;br /&gt;
	if not checked then&lt;br /&gt;
		local check = _check(&amp;#039;keysToList&amp;#039;)&lt;br /&gt;
		check(1, t, &amp;#039;table&amp;#039;)&lt;br /&gt;
		check(2, keySort, &amp;#039;function&amp;#039;, true)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local list = {}&lt;br /&gt;
	local index = 1&lt;br /&gt;
	for key, value in pairs(t) do&lt;br /&gt;
		list[index] = key&lt;br /&gt;
		index = index + 1&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- Place numbers before strings, otherwise sort using &amp;lt;.&lt;br /&gt;
	if not keySort then&lt;br /&gt;
		keySort = function(item1, item2)&lt;br /&gt;
			-- &amp;quot;number&amp;quot; &amp;lt; &amp;quot;string&amp;quot;, so numbers will be sorted before strings.&lt;br /&gt;
			local type1, type2 = type(item1), type(item2)&lt;br /&gt;
			if type1 ~= type2 then&lt;br /&gt;
				return type1 &amp;lt; type2&lt;br /&gt;
			else&lt;br /&gt;
				return item1 &amp;lt; item2&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	table.sort(list, keySort)&lt;br /&gt;
	&lt;br /&gt;
	return list&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
	Iterates through a table, with the keys sorted using the keysToList function.&lt;br /&gt;
	If there are only numerical keys, sparseIpairs is probably more efficient.&lt;br /&gt;
]]&lt;br /&gt;
function p.sortedPairs(t, keySort)&lt;br /&gt;
	local check = _check(&amp;#039;keysToList&amp;#039;)&lt;br /&gt;
	check(1, t, &amp;#039;table&amp;#039;)&lt;br /&gt;
	check(2, keySort, &amp;#039;function&amp;#039;, true)&lt;br /&gt;
	&lt;br /&gt;
	local list = p.keysToList(t, keySort, true)&lt;br /&gt;
	&lt;br /&gt;
	local i = 0&lt;br /&gt;
	return function()&lt;br /&gt;
		i = i + 1&lt;br /&gt;
		local key = list[i]&lt;br /&gt;
		if key ~= nil then&lt;br /&gt;
			return key, t[key]&lt;br /&gt;
		else&lt;br /&gt;
			return nil, nil&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
	Returns true if all keys in the table are consecutive integers starting at 1.&lt;br /&gt;
--]]&lt;br /&gt;
function p.isArray(t)&lt;br /&gt;
	checkType(&amp;quot;isArray&amp;quot;, 1, t, &amp;quot;table&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	local i = 0&lt;br /&gt;
	for k, v in pairs(t) do&lt;br /&gt;
		i = i + 1&lt;br /&gt;
		if t[i] == nil then&lt;br /&gt;
			return false&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- { &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot; } -&amp;gt; { a = 1, b = 2, c = 3 }&lt;br /&gt;
function p.invert(array)&lt;br /&gt;
	checkType(&amp;quot;invert&amp;quot;, 1, array, &amp;quot;table&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	local map = {}&lt;br /&gt;
	for i, v in ipairs(array) do&lt;br /&gt;
		map[v] = i&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return map&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
	{ &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot; } -&amp;gt; { [&amp;quot;a&amp;quot;] = true, [&amp;quot;b&amp;quot;] = true, [&amp;quot;c&amp;quot;] = true }&lt;br /&gt;
--]]&lt;br /&gt;
function p.listToSet(t)&lt;br /&gt;
	checkType(&amp;quot;listToSet&amp;quot;, 1, t, &amp;quot;table&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	local set = {}&lt;br /&gt;
	for _, item in ipairs(t) do&lt;br /&gt;
		set[item] = true&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return set&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
	Recursive deep copy function&lt;br /&gt;
]]&lt;br /&gt;
function p.deepCopy(orig, noMetatable)&lt;br /&gt;
    local orig_type = type(orig)&lt;br /&gt;
    local copy&lt;br /&gt;
    if orig_type == &amp;#039;table&amp;#039; then&lt;br /&gt;
        copy = {}&lt;br /&gt;
        for orig_key, orig_value in pairs(orig) do&lt;br /&gt;
            copy[p.deepCopy(orig_key, noMetatable)] = p.deepCopy(orig_value, noMetatable)&lt;br /&gt;
        end&lt;br /&gt;
        if not noMetatable then&lt;br /&gt;
        	setmetatable(copy, p.deepCopy(getmetatable(orig)))&lt;br /&gt;
        end&lt;br /&gt;
    else -- number, string, boolean, etc&lt;br /&gt;
        copy = orig&lt;br /&gt;
    end&lt;br /&gt;
    return copy&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
	Concatenates all values in the table that are indexed by a number, in order.&lt;br /&gt;
	sparseConcat{ a, nil, c, d }  =&amp;gt;  &amp;quot;acd&amp;quot;&lt;br /&gt;
	sparseConcat{ nil, b, c, d }  =&amp;gt;  &amp;quot;bcd&amp;quot;&lt;br /&gt;
]]&lt;br /&gt;
function p.sparseConcat(t, sep, i, j)&lt;br /&gt;
	local list = {}&lt;br /&gt;
	&lt;br /&gt;
	local list_i = 0&lt;br /&gt;
	for _, v in require(&amp;quot;Module:TableTools&amp;quot;).sparseIpairs(t) do&lt;br /&gt;
		list_i = list_i + 1&lt;br /&gt;
		list[list_i] = v&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return table.concat(list, sep, i, j)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Amc-admin</name></author>
	</entry>
</feed>