<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://www.verzauberte-welten.de/index.php?action=history&amp;feed=atom&amp;title=Modul%3ATableTools%2Fdoc</id>
	<title>Modul:TableTools/doc - Versionsgeschichte</title>
	<link rel="self" type="application/atom+xml" href="https://www.verzauberte-welten.de/index.php?action=history&amp;feed=atom&amp;title=Modul%3ATableTools%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://www.verzauberte-welten.de/index.php?title=Modul:TableTools/doc&amp;action=history"/>
	<updated>2026-04-05T23:37:03Z</updated>
	<subtitle>Versionsgeschichte dieser Seite in Verzauberte Welten e.V.</subtitle>
	<generator>MediaWiki 1.39.8</generator>
	<entry>
		<id>https://www.verzauberte-welten.de/index.php?title=Modul:TableTools/doc&amp;diff=467&amp;oldid=prev</id>
		<title>mw&gt;Totest01 am 2. März 2015 um 14:34 Uhr</title>
		<link rel="alternate" type="text/html" href="https://www.verzauberte-welten.de/index.php?title=Modul:TableTools/doc&amp;diff=467&amp;oldid=prev"/>
		<updated>2015-03-02T14:34:58Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{documentation subpage}}&lt;br /&gt;
{{module rating|beta}}&lt;br /&gt;
&lt;br /&gt;
This module includes a number of functions for dealing with Lua tables. It is a meta-module, meant to be called from other Lua modules, and should not be called directly from #invoke.&lt;br /&gt;
&lt;br /&gt;
== Loading the module ==&lt;br /&gt;
&lt;br /&gt;
To use any of the functions, first you must load the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local TableTools = require('Module:TableTools')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== isPositiveInteger ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
TableTools.isPositiveInteger(value)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Returns &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; if &amp;lt;code&amp;gt;''value''&amp;lt;/code&amp;gt; is a positive integer, and &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; if not. Although it doesn't operate on tables, it is included here as it is useful for determining whether a given table key is in the array part or the hash part of a table.&lt;br /&gt;
&lt;br /&gt;
== isNan ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
TableTools.isNan(value)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Returns &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; if &amp;lt;code&amp;gt;''value''&amp;lt;/code&amp;gt; is a NaN value, and &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; if not. Although it doesn't operate on tables, it is included here as it is useful for determining whether a value can be a valid table key. (Lua will generate an error if a NaN value is used as a table key.)&lt;br /&gt;
&lt;br /&gt;
== shallowClone ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
TableTools.shallowClone(t)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Returns a clone of a table. The value returned is a new table, but all subtables and functions are shared. Metamethods are respected, but the returned table will have no metatable of its own. If you want to make a new table with no shared subtables and with metatables transferred, you can use [[mw:Extension:Scribunto/Lua reference manual#mw.clone|mw.clone]] instead.&lt;br /&gt;
&lt;br /&gt;
== removeDuplicates ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
TableTools.removeDuplicates(t)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Removes duplicate values from an array. This function is only designed to work with standard arrays: keys that are not positive integers are ignored, as are all values after the first &amp;lt;code&amp;gt;nil&amp;lt;/code&amp;gt; value. (For arrays containing &amp;lt;code&amp;gt;nil&amp;lt;/code&amp;gt; values, you can use [[#compressSparseArray|compressSparseArray]] first.) The function tries to preserve the order of the array: the earliest non-unique value is kept, and all subsequent duplicate values are removed. For example, for the table {{code snippet|code={5, 4, 4, 3, 4, 2, 2, 1}|lang=lua}} removeDuplicates will return {{code snippet|code={5, 4, 3, 2, 1}|lang=lua}}&lt;br /&gt;
&lt;br /&gt;
== numKeys ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
TableTools.numKeys(t)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Takes a table &amp;lt;code&amp;gt;''t''&amp;lt;/code&amp;gt; and returns an array containing the numbers of any positive integer keys that have non-nil values, sorted in numerical order. For example, for the table {{code snippet|code={'foo', nil, 'bar', 'baz', a = 'b'}|lang=lua}}, numKeys will return {{code snippet|code={1, 3, 4}|lang=lua}}.&lt;br /&gt;
&lt;br /&gt;
== affixNums ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
TableTools.affixNums(t, prefix, suffix)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Takes a table &amp;lt;code&amp;gt;''t''&amp;lt;/code&amp;gt; and returns an array containing the numbers of keys with the optional prefix &amp;lt;code&amp;gt;''prefix''&amp;lt;/code&amp;gt; and the optional suffix &amp;lt;code&amp;gt;''suffix''&amp;lt;/code&amp;gt;. For example, for the table {{code snippet|code={a1 = 'foo', a3 = 'bar', a6 = 'baz'}|lang=lua}} and the prefix &amp;lt;code&amp;gt;'a'&amp;lt;/code&amp;gt;, affixNums will return {{code snippet|code={1, 3, 6}|lang=lua}}. All characters in &amp;lt;code&amp;gt;''prefix''&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;''suffix''&amp;lt;/code&amp;gt; are interpreted literally.&lt;br /&gt;
&lt;br /&gt;
== numData ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
TableTools.numData(t, compress)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Given a table with keys like &amp;quot;foo1&amp;quot;, &amp;quot;bar1&amp;quot;, &amp;quot;foo2&amp;quot;, and &amp;quot;baz2&amp;quot;, returns a table of subtables in the format {{code snippet|code={ [1] = {foo = 'text', bar = 'text'}, [2] = {foo = 'text', baz = 'text'} }|lang=lua}}. Keys that don't end with an integer are stored in a subtable named &amp;quot;other&amp;quot;. The compress option compresses the table so that it can be iterated over with ipairs.&lt;br /&gt;
&lt;br /&gt;
== compressSparseArray ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
TableTools.compressSparseArray(t)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Takes an array &amp;lt;code&amp;gt;''t''&amp;lt;/code&amp;gt; with one or more nil values, and removes the nil values while preserving the order, so that the array can be safely traversed with ipairs. Any keys that are not positive integers are removed. For example, for the table {{code snippet|code={1, nil, foo = 'bar', 3, 2}|lang=lua}}, compressSparseArray will return {{code snippet|code={1, 3, 2}|lang=lua}}.&lt;br /&gt;
&lt;br /&gt;
== sparseIpairs ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
TableTools.sparseIpairs(t)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is an iterator function for traversing a sparse array &amp;lt;code&amp;gt;''t''&amp;lt;/code&amp;gt;. It is similar to [[mw:Extension:Scribunto/Lua reference manual#ipairs|ipairs]], but will continue to iterate until the highest numerical key, whereas ipairs may stop after the first &amp;lt;code&amp;gt;nil&amp;lt;/code&amp;gt; value. Any keys that are not positive integers are ignored.&lt;br /&gt;
&lt;br /&gt;
Usually sparseIpairs is used in a generic &amp;lt;code&amp;gt;for&amp;lt;/code&amp;gt; loop.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
for i, v in TableTools.sparseIpairs(t) do&lt;br /&gt;
   -- code block&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that sparseIpairs uses the [[mw:Extension:Scribunto/Lua reference manual#pairs|pairs]] function in its implementation. Although some table keys appear to be ignored, all table keys are accessed when it is run.&lt;br /&gt;
&lt;br /&gt;
== size ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
TableTools.size(t)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finds the size of a key/value pair table. For example, for the table {{code snippet|code={foo = 'foo', bar = 'bar'}|lang=lua}}, size will return &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;. The function will also work on arrays, but for arrays it is more efficient to use the # operator. Note that to find the table size, this function uses the [[mw:Extension:Scribunto/Lua reference manual#pairs|pairs]] function to iterate through all of the table keys.&lt;br /&gt;
&lt;br /&gt;
== inTable ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
TableTools.inTable(t, val)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Returns true (more precise: the corresponding key), if &amp;lt;code&amp;gt;val&amp;lt;/code&amp;gt; is found in table &amp;lt;code&amp;gt;t&amp;lt;/code&amp;gt;, false otherwise. Does no type or case mangling (aka if 'a' is in table and val is 'A', return false).&lt;br /&gt;
&lt;br /&gt;
== printTable ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
TableTools.printTable(t)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Returns a string representation of table &amp;lt;code&amp;gt;t&amp;lt;/code&amp;gt;. This is best put between {{tag|pre}} and normally used for debug purposes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;includeonly&amp;gt;{{#ifeq:{{SUBPAGENAME}}|sandbox||&lt;br /&gt;
[[Category:Lua metamodules]]&lt;br /&gt;
}}&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>mw&gt;Totest01</name></author>
	</entry>
</feed>