|
1 | 1 | # table
|
2 |
| -A built-in type representing associative arrays, [see details](https://www.lua.org/pil/2.5.html) |
| 2 | +> A built-in type representing associative arrays, [see details](https://www.lua.org/pil/2.5.html) |
| 3 | +
|
| 4 | +<!-- toc --> |
| 5 | + |
3 | 6 |
|
4 | 7 | ---
|
5 | 8 | ## Functions
|
6 |
| -### `clear`(t : [`table`](../../API/builtins/table.md)) {#clear} |
7 |
| -Recursively clears and removes all table elements. |
8 |
| -### `copy`(t : [`table`](../../API/builtins/table.md)) {#copy} |
| 9 | +### clear(t : [`table`](../../API/builtins/table.md)) {#clear} |
| 10 | +> Recursively clears and removes all table elements. |
| 11 | +### copy(t : [`table`](../../API/builtins/table.md)) {#copy} |
9 | 12 | `->`[`table`](../../API/builtins/table.md)
|
10 | 13 |
|
11 |
| -Copy the metatable and all first level elements of the given table into a |
12 |
| -new table. Use table.rcopy to do a recursive copy of all elements |
13 |
| -### `count`(t : [`table`](../../API/builtins/table.md)) {#count} |
14 |
| -Count the number of items of a table, also works for non index |
15 |
| -based tables (using pairs). |
16 |
| -### examples: |
17 |
| -```lua |
18 |
| -t = {["a"]=1, ["b"]=1}; print(table.count(t)) --> 2 |
19 |
| -``` |
20 |
| -### `create`(t : [`table`](../../API/builtins/table.md)[`?`](../../API/builtins/nil.md)) {#create} |
| 14 | +> Copy the metatable and all first level elements of the given table into a |
| 15 | +> new table. Use table.rcopy to do a recursive copy of all elements |
| 16 | +### count(t : [`table`](../../API/builtins/table.md)) {#count} |
| 17 | +> Count the number of items of a table, also works for non index |
| 18 | +> based tables (using pairs). |
| 19 | +> #### examples: |
| 20 | +> ```lua |
| 21 | +> t = {["a"]=1, ["b"]=1}; print(table.count(t)) --> 2 |
| 22 | +> ``` |
| 23 | +### create(t : [`table`](../../API/builtins/table.md)[`?`](../../API/builtins/nil.md)) {#create} |
21 | 24 | `->`[`table`](../../API/builtins/table.md) | tablelib
|
22 | 25 |
|
23 |
| -Create a new, or convert an exiting table to an object that uses the global |
24 |
| -'table.XXX' functions as methods, just like strings in Lua do. |
25 |
| -### examples: |
26 |
| -```lua |
27 |
| -t = table.create(); t:insert("a"); rprint(t) -> [1] = a; |
28 |
| -t = table.create{1,2,3}; print(t:concat("|")); -> "1|2|3"; |
29 |
| -``` |
30 |
| -### `find`(t : [`table`](../../API/builtins/table.md), value : [`any`](../../API/builtins/any.md), start_index : [`integer`](../../API/builtins/integer.md)[`?`](../../API/builtins/nil.md)) {#find} |
| 26 | +> Create a new, or convert an exiting table to an object that uses the global |
| 27 | +> 'table.XXX' functions as methods, just like strings in Lua do. |
| 28 | +> #### examples: |
| 29 | +> ```lua |
| 30 | +> t = table.create(); t:insert("a"); rprint(t) -> [1] = a; |
| 31 | +> t = table.create{1,2,3}; print(t:concat("|")); -> "1|2|3"; |
| 32 | +> ``` |
| 33 | +### find(t : [`table`](../../API/builtins/table.md), value : [`any`](../../API/builtins/any.md), start_index : [`integer`](../../API/builtins/integer.md)[`?`](../../API/builtins/nil.md)) {#find} |
31 | 34 | `->`key_or_nil : [`string`](../../API/builtins/string.md) | [`number`](../../API/builtins/number.md)[`?`](../../API/builtins/nil.md)
|
32 | 35 |
|
33 |
| -Find first match of *value* in the given table, starting from element |
34 |
| -number *start_index*.<br> |
35 |
| -Returns the first *key* that matches the value or nil |
36 |
| -### examples: |
37 |
| -```lua |
38 |
| -t = {"a", "b"}; table.find(t, "a") --> 1 |
39 |
| -t = {a=1, b=2}; table.find(t, 2) --> "b" |
40 |
| -t = {"a", "b", "a"}; table.find(t, "a", 2) --> "3" |
41 |
| -t = {"a", "b"}; table.find(t, "c") --> nil |
42 |
| -``` |
43 |
| -### `is_empty`(t : [`table`](../../API/builtins/table.md)) {#is_empty} |
| 36 | +> Find first match of *value* in the given table, starting from element |
| 37 | +> number *start_index*.<br> |
| 38 | +> Returns the first *key* that matches the value or nil |
| 39 | +> #### examples: |
| 40 | +> ```lua |
| 41 | +> t = {"a", "b"}; table.find(t, "a") --> 1 |
| 42 | +> t = {a=1, b=2}; table.find(t, 2) --> "b" |
| 43 | +> t = {"a", "b", "a"}; table.find(t, "a", 2) --> "3" |
| 44 | +> t = {"a", "b"}; table.find(t, "c") --> nil |
| 45 | +> ``` |
| 46 | +### is_empty(t : [`table`](../../API/builtins/table.md)) {#is_empty} |
44 | 47 | `->`[`boolean`](../../API/builtins/boolean.md)
|
45 | 48 |
|
46 |
| -Returns true when the table is empty, else false and will also work |
47 |
| -for non indexed tables |
48 |
| -### examples: |
49 |
| -```lua |
50 |
| -t = {}; print(table.is_empty(t)); -> true; |
51 |
| -t = {66}; print(table.is_empty(t)); -> false; |
52 |
| -t = {["a"] = 1}; print(table.is_empty(t)); -> false; |
53 |
| -### `keys`(t : [`table`](../../API/builtins/table.md)) {#keys} |
| 49 | +> Returns true when the table is empty, else false and will also work |
| 50 | +> for non indexed tables |
| 51 | +> #### examples: |
| 52 | +> ```lua |
| 53 | +> t = {}; print(table.is_empty(t)); -> true; |
| 54 | +> t = {66}; print(table.is_empty(t)); -> false; |
| 55 | +> t = {["a"] = 1}; print(table.is_empty(t)); -> false; |
| 56 | +### keys(t : [`table`](../../API/builtins/table.md)) {#keys} |
54 | 57 | `->`[`table`](../../API/builtins/table.md)
|
55 | 58 |
|
56 |
| -Return an indexed table of all keys that are used in the table. |
57 |
| -### examples: |
58 |
| -```lua |
59 |
| -t = {a="aa", b="bb"}; rprint(table.keys(t)); --> "a", "b" |
60 |
| -t = {"a", "b"}; rprint(table.keys(t)); --> 1, 2 |
61 |
| -``` |
62 |
| -### `rcopy`(t : [`table`](../../API/builtins/table.md)) {#rcopy} |
| 59 | +> Return an indexed table of all keys that are used in the table. |
| 60 | +> #### examples: |
| 61 | +> ```lua |
| 62 | +> t = {a="aa", b="bb"}; rprint(table.keys(t)); --> "a", "b" |
| 63 | +> t = {"a", "b"}; rprint(table.keys(t)); --> 1, 2 |
| 64 | +> ``` |
| 65 | +### rcopy(t : [`table`](../../API/builtins/table.md)) {#rcopy} |
63 | 66 | `->`[`table`](../../API/builtins/table.md)
|
64 | 67 |
|
65 |
| -Deeply copy the metatable and all elements of the given table recursively |
66 |
| -into a new table - create a clone with unique references. |
67 |
| -### `values`(t : [`table`](../../API/builtins/table.md)) {#values} |
| 68 | +> Deeply copy the metatable and all elements of the given table recursively |
| 69 | +> into a new table - create a clone with unique references. |
| 70 | +### values(t : [`table`](../../API/builtins/table.md)) {#values} |
68 | 71 | `->`[`table`](../../API/builtins/table.md)
|
69 | 72 |
|
70 |
| -Return an indexed table of all values that are used in the table |
71 |
| -### examples: |
72 |
| -```lua |
73 |
| - t = {a="aa", b="bb"}; rprint(table.values(t)); --> "aa", "bb" |
74 |
| - t = {"a", "b"}; rprint(table.values(t)); --> "a", "b" |
75 |
| -``` |
| 73 | +> Return an indexed table of all values that are used in the table |
| 74 | +> #### examples: |
| 75 | +> ```lua |
| 76 | +> t = {a="aa", b="bb"}; rprint(table.values(t)); --> "aa", "bb" |
| 77 | +> t = {"a", "b"}; rprint(table.values(t)); --> "a", "b" |
| 78 | +> ``` |
76 | 79 |
|
0 commit comments