v0.13.6

table

namespaceavailable in: camelot

Status in wowlua

23 functions: 23 implemented, 0 recorded, 0 guessed.

Functions

functionwhat it doesstatus
concatReturns a concatenated string from a table.
not in Blizzard's documentation
implemented
containsReturns true if any value in the table compares equal to the specified value.
(table: table, value: any?): boolean
implemented
countReturns the number of entries in the table.
(table: table): number
implemented
createCreates an empty table with storage preallocated for the specified number of array and non-array entries.
(arraySizeHint: number, nodeSizeHint: number): table
implemented
foreachApply the function f to the elements of the table passed. On each iteration the function f is passed the key-value pair of that element in the table. table.foreach(tab, func); foreach(tab, func); From TableLibraryTutorial of lua-users.org. > table.foreach({1,"two",3}, print) -- print the key-value pairs 1 1 2 two 3 3 > table.foreach({1,"two",3,"four"}, function(k,v) print(string.rep(v,k)) end) 1 twotwo 333 fourfourfourfour If the function f returns a non-nil value the iteration loop terminates. > table.foreach({1,"two",3}, function(k,v) print(k,v) return k<2 and nil end) 1 1 2 two Tables can contain mixed key-value and index-value elements. table.foreach() will display all of the elements in a table. To only display the index-value elements see table.foreachi(). For more information about this subject see the TablesTutorial. > t = { 1,2,"three"; pi=3.14159, banana="yellow" } > table.foreach(t, print) 1 1 2 2 3 three pi 3.14159 banana yellow
not in Blizzard's documentation
implemented
foreachiFrom TableLibraryTutorial of lua-users.org. Apply the function f to the elements of the table passed. On each iteration the function f is passed the index-value pair of that element in the table. This is similar to table.foreach() except that index-value pairs are passed, not key-value pairs. If the function f returns a non-nil value the iteration loop terminates. > t = { 1,2,"three"; pi=3.14159, banana="yellow" } > table.foreachi(t, print) 1 1 2 2 3 three Note in the example only the indexed elements of the table are displayed. See the TablesTutorial for more information on key-value and index-value pairs. Also note that foreachi starts at index [1], increments the index by one repeatedly, and stops running as soon as it reaches a nil value. This is an example: > t = { [0] = "zero", --will not be counted [1] = "one", --will be counted; 1 [2] = "two", --will be counted; 2 [3] = "three", --will be counted; 3 ["four"] = "four", --will not be counted; returns 3 [5] = "five" } --will never be reached > foreachi(t, print) 1 one 2 two 3 three In the above, it starts at t[1] (*not* t[0]) and counts to t[3], printing the corresponding values along the way. It then checks t[4], sees it is nil, and stops running. t[5] is never checked - this *will not hit every array index in a table, only the consecutive ones from one up until it hits its first blank index.*
not in Blizzard's documentation
implemented
freezeMarks a supplied table as frozen, preventing any modifications to its contents, or replacement of its metatable. If the table has a pre-existing metatable with a '__newindex' table or function, assignments will pass through without raising errors. For tainted code, only tables created by the same addon making this function call are permitted to be frozen.
(table: table): table
implemented
getcountinfoReturns detailed information about the number and distribution of entries in the table.
(table: table): (number, number, number)
implemented
getn<!-- --> This is used to determine the size of a table. The size of a table is discussed at the top of this page. > = table.getn({1,2,3}) -- Lua will count the elements if no size is specified 3 > = table.getn({1,2,3; n=10}) -- note, n overrides counting the elements 10 > t = {1,2,3} > table.setn(t, 10) -- set our own size with setn() > = table.getn(t) 10 > = table.getn({1,2,3,nil,5,6}) -- sequence ends at element 3 due to nil value at 4 3 Note that Lua 5.1 has switched to the # operator. #t is the replacement for table.getn(t) > print( #{1,2,3} ) 3 However, it does not always behave as one might expect. Consider the following sequence: > t = { 1, 2, 3 } > dump (#t) 3 > t[1] = nil > dump (#t) 3 > dump (t) { [2] = 2 [3] = 3 } -- table: 0x807ff70 > dump (#{ [2] = 2, [3] = 3 }) 0 As you can see, the # operator is unpredictable in that it can return different values for tables with identical contents. The Lua 5.1 reference manual has this to say about it http://www.lua.org/manual/5.1/: The length of a table t is defined to be any integer index such that t[n] is not nil and t[n+1] is nil. In other words, be careful with this operator if you are using tables with holes in them. If your table has all its values between [1] and [n] for some n, with no nils in that range, the # operator will return n. Otherwise its result may be unclear. Note: The reason the returned values are different is because the tables are different. For indexed tables, or tables that start with index values like 1,2,3 for keys, use tinsert and tremove to change the contents. What # returns is actually correct, setting the index value to nil does not change the size of the table for index keys, tremove would.
not in Blizzard's documentation
implemented
indexofReturns the first integer index whose value compares equal to the specified value, searching consecutively from index 1 until the first nil value.
(table: table, value: any?): number?
implemented
insertFrom TableLibraryTutorial of lua-users.org. Insert a given value into a table. If a position is given insert the value before the element currently at that position: > t = { 1,3,"four" } > table.insert(t, 2, "two") -- insert "two" at position before element 2 > = table.concat(t, ", ") 1, two, 3, four If no position is specified we append the value to the end of the table: > table.insert(t, 5) -- no position given so append to end > = table.concat(t, ", ") 1, two, 3, four, 5 When a table has an element inserted both the size of the table and the element indices are updated: > t = { 1,"two",3 } -- create a table > = table.getn(t) -- find current size 3 > table.foreach(t, print) -- display the table contents 1 1 2 two 3 3 > table.insert(t, 1, "inserted") -- insert an element at the start > = table.concat(t, ", ") -- see what we have inserted, 1, two, 3 > = table.getn(t) -- find the size 4 > table.foreach(t, print) -- the indexes have been updated 1 inserted 2 1 3 two 4 3 When no position is specified the element is inserted at the end of the table according to the calculated size. The size of a table may be user specified and not reflect the number of elements, e.g., > t = { 1,"two",3; n=10 } -- create a table with user size > table.insert(t, "end") -- insert with no position inserts at "end" > table.foreach(t, print) -- display the table contents 1 1 2 two 3 3 11 end n 11
not in Blizzard's documentation
implemented
isemptyReturns true if the table contains no entries.
(table: table): boolean
implemented
isfrozenReturns true if a table has been marked as frozen.
(table: table): boolean
implemented
keysReturns an array containing the keys of the specified table.
(table: table): any
implemented
maxnReturns the largest positive numeric key of a table, or 0 if it has none. Unlike the # operator it walks the whole table, so gaps in the array do not matter. · by wowlua
not in Blizzard's documentation
implemented
remove*Reference: TableLibraryTutorial, Reference Manual* Remove an element from a table. If a position is specified the element at that position is removed. The remaining elements are reindexed sequentially and the size of the table is updated to reflect the change. The element removed is returned by this function. E.g., > t = { 1,"two",3,"four" } -- create a table > = table.getn(t) -- find the size 4 > table.foreach(t, print) -- have a look at the elements 1 1 2 two 3 3 4 four > = table.remove(t,2) -- remove element number 2 and display it two > table.foreach(t, print) -- display the updated table contents 1 1 2 3 3 four > = table.getn(t) -- find the size 3 If no position is given remove the last element in the table which is specified by the size of the table. E.g., > t = { 1,"two","three" } > = table.getn(t) -- find the table size (which is removed) 3 > table.foreach(t, print) -- display contents 1 1 2 two 3 three > = table.remove(t) -- remove the element at position "n" three > table.foreach(t, print) -- display updated contents 1 1 2 two > = table.getn(t) -- display new size 2 If the size of the table does not reflect the number of elements nothing is removed, e.g., > t = {1,2,3} > table.setn(t,10) -- set user size > table.foreach(t, print) -- display table contents, note size "n" is stored internally 1 1 2 2 3 3 > = table.getn(t) -- find the size 10 > = table.remove(t) -- remove last element nil > = table.getn(t) -- find the updated size 9 > table.foreach(t, print) -- display elements 1 1 2 2 3 3
not in Blizzard's documentation
implemented
removemultiRemoves count elements from a table starting at index pos. ... = table.removemulti(table[, pos[, count]])
not in Blizzard's documentation
implemented
removeunorderedRemoves the value at the specified integer index by replacing it with the last value in the array and shortening the array by one element. The order of values in the array is not preserved.
(table: table, index: number?): any?
implemented
removevalueRemoves all values equal to the specified value from the array portion of a table.
(table: table, value: any?): number
implemented
setnObsolete; throws an error if called.
not in Blizzard's documentation
implemented
sortSort the array portion of a table in-place (i.e. alter the table).
not in Blizzard's documentation
implemented
valuesReturns an array containing the values of the specified table.
(table: table): any
implemented
wipeWipes a table of all contents.
not in Blizzard's documentation
implemented

"by wowlua": no one documents this function, so wowlua wrote the description from its name, signature and behaviour.

sources

Signatures, events and structures: Blizzard's API documentation (Blizzard_APIDocumentationGenerated) (LuaTableExtensions system, camelot 1.60.1). Descriptions: Blizzard's API documentation (Blizzard_APIDocumentationGenerated); warcraft.wiki.gg's API pages, by its contributors, CC BY-SA 4.0 ↗; written by wowlua where no documentation describes the entry.