Module:Table/documentation: Difference between revisions

From The Languages of David J. Peterson
Jump to navigation Jump to search
m (Djpwikiadmin moved page Module:Table/doc to Module:Table/documentation)
No edit summary
 
Line 5: Line 5:
Functions by what they do:
Functions by what they do:
* Create a new table:
* Create a new table:
** <code class="n">shallowClone</code>, <code class="n">shallowcopy</code>, <code class="n">deepcopy</code>, <code class="n">removeDuplicates</code>, <code class="n">numKeys</code>, <code class="n">affixNums</code>, <code class="n">numData</code>, <code class="n">compressSparseArray</code>, <code class="n">keysToList</code>, <code class="n">reverse</code>, <code class="n">invert</code>, <code class="n">listToSet</code>
** {{#invoke:string|gsub|shallowClone, shallowcopy, deepcopy, removeDuplicates, numKeys, affixNums, numData, compressSparseArray, keysToList, reverse, invert, listToSet|%a+|3=<code class="n">%1</code>}}
* Create an array:
* Create an array:
** <code class="n">removeDuplicates</code>, <code class="n">numKeys</code>, <code class="n">affixNums</code>, <code class="n">compressSparseArray</code>, <code class="n">keysToList</code>, <code class="n">reverse</code>
** {{#invoke:string|gsub|removeDuplicates, numKeys, affixNums, compressSparseArray, keysToList, reverse|%a+|3=<code class="n">%1</code>}}
* Return information about the table:
* Return information about the table:
** <code class="n">size</code>, <code class="n">length</code>, <code class="n">contains</code>, <code class="n">keyFor</code>, <code class="n">isArray</code>
** {{#invoke:string|gsub|size, length, contains, keyFor, isArray, deepEquals, deepEqualsList|%a+|3=<code class="n">%1</code>}}
* Treat the table as an array (that is, operate on the values in the array portion of the table: values indexed by consecutive integers starting at {{code|lua|1}}):
* Treat the table as an array (that is, operate on the values in the array portion of the table: values indexed by consecutive integers starting at {{code|lua|1}}):
** <code class="n">removeDuplicates</code>, <code class="n">length</code>, <code class="n">contains</code>, <code class="n">serialCommaJoin</code>, <code class="n">reverseIpairs</code>, <code class="n">reverse</code>, <code class="n">invert</code>, <code class="n">listToSet</code>, <code class="n">isArray</code>
** {{#invoke:string|gsub|removeDuplicates, length, contains, serialCommaJoin, reverseIpairs, reverse, invert, listToSet, isArray, deepEqualsList|%a+|3=<code class="n">%1</code>}}
* Treat a table as a sparse array (that is, operate on values indexed by non-consecutive integers):
* Treat a table as a sparse array (that is, operate on values indexed by non-consecutive integers):
** <code class="n">numKeys</code>, <code class="n">maxIndex</code>, <code class="n">compressSparseArray</code>, <code class="n">sparseConcat</code>, <code class="n">sparseIpairs</code>
** {{#invoke:string|gsub|numKeys, maxIndex, compressSparseArray, sparseConcat, sparseIpairs|%a+|3=<code class="n">%1</code>}}
* Generate an iterator:
* Generate an iterator:
** <code class="n">sparseIpairs</code>, <code class="n">sortedPairs</code>, <code class="n">reverseIpairs</code>
** {{#invoke:string|gsub|sparseIpairs, sortedPairs, reverseIpairs|%a+|3=<code class="n">%1</code>}}
* Other:
* Other:
** <code class="n">sparseConcat</code>, <code class="n">serialCommaJoin</code>, <code class="n">reverseConcat</code>
** {{#invoke:string|gsub|sparseConcat, serialCommaJoin, reverseConcat|%a+|3=<code class="n">%1</code>}}


The original version was a copy of {{w|Module:TableTools}} on Wikipedia via [[c:Module:TableTools|Module:TableTools]] on Commons, but new functions have been added since then.
The original version was a copy of {{w|Module:TableTools}} on Wikipedia via [[c:Module:TableTools|Module:TableTools]] on Commons, but new functions have been added since then.
Line 23: Line 23:
<includeonly>
<includeonly>
[[Category:Lua metamodules]]
[[Category:Lua metamodules]]
[[Category:Wiktionary modules]]
</includeonly>
</includeonly>

Latest revision as of 21:01, 18 September 2023

This module provides functions for dealing with Lua tables. All of them, except for two helper functions, take a table as their first argument.

Some functions are available as methods in the arrays created by Module:array.

Functions by what they do:

  • Create a new table:
    • shallowClone, shallowcopy, deepcopy, removeDuplicates, numKeys, affixNums, numData, compressSparseArray, keysToList, reverse, invert, listToSet
  • Create an array:
    • removeDuplicates, numKeys, affixNums, compressSparseArray, keysToList, reverse
  • Return information about the table:
    • size, length, contains, keyFor, isArray, deepEquals, deepEqualsList
  • Treat the table as an array (that is, operate on the values in the array portion of the table: values indexed by consecutive integers starting at 1):
    • removeDuplicates, length, contains, serialCommaJoin, reverseIpairs, reverse, invert, listToSet, isArray, deepEqualsList
  • Treat a table as a sparse array (that is, operate on values indexed by non-consecutive integers):
    • numKeys, maxIndex, compressSparseArray, sparseConcat, sparseIpairs
  • Generate an iterator:
    • sparseIpairs, sortedPairs, reverseIpairs
  • Other:
    • sparseConcat, serialCommaJoin, reverseConcat

The original version was a copy of Module:TableTools on Wikipedia via Module:TableTools on Commons, but new functions have been added since then.