$mtable » History » Version 2
Per Amundsen, 02/23/2023 05:18 PM
| 1 | 1 | Per Amundsen | _Added in 4.4_ |
|---|---|---|---|
| 2 | |||
| 3 | *$mtable(name, N, [N..])* |
||
| 4 | |||
| 5 | Gets the Nth item in a table, subsequent N parameters gets the Nth item from a sub table, infinite sub depth. |
||
| 6 | |||
| 7 | _See also [[/mtable]]._ |
||
| 8 | |||
| 9 | *Parameters* |
||
| 10 | |||
| 11 | 2 | Per Amundsen | table(ktable). |
| 12 | |*Parameter*|*Description*| |
||
| 13 | | name | The outer table name. | |
||
| 14 | | N | The Nth item in the table. | |
||
| 15 | | [N..] | The Nth item in a sub table, subsequent N parameters travels further down. | |
||
| 16 | 1 | Per Amundsen | |
| 17 | *Properties* |
||
| 18 | |||
| 19 | 2 | Per Amundsen | table(ktable). |
| 20 | |*Property*|*Description*| |
||
| 21 | | .item | Gets the item name. | |
||
| 22 | | .value | Gets the item value. | |
||
| 23 | | .type | Get the item type. (0 = text, 1 = number, 2 = bool, 3 = sub table) | |
||
| 24 | | .json | Generate a json table from all items in the current table and all sub tables. | |
||
| 25 | | .ini | Generate a ini output from all items in the current table and all sub tables. | |
||
| 26 | | .xml | Generate a xml output from all items in the current table and all sub tables. | |
||
| 27 | 1 | Per Amundsen | |
| 28 | <pre> |
||
| 29 | ; Add item1/value1 to the table 'table1'. |
||
| 30 | //mtable -a table1 item1 value1 |
||
| 31 | |||
| 32 | ; Add sub table 'item2' to the table 'table1'. |
||
| 33 | //mtable -aA table1 item2 value2 |
||
| 34 | |||
| 35 | ; Insert item3/value3 at position '1' in the table 'table1'. |
||
| 36 | //mtable -i table1 1 item3 value3 |
||
| 37 | |||
| 38 | ; Print number of items in table 'table1'. |
||
| 39 | //echo -ag Number of items in table1 is $mtable(table1, 0) |
||
| 40 | |||
| 41 | ; Print the first items in table 'table1'. |
||
| 42 | //echo -ag First item in table1 is $mtable(table1, 1).item |
||
| 43 | |||
| 44 | ; Delete the first item in table 'table1'. |
||
| 45 | //mtable -d table1 1 |
||
| 46 | |||
| 47 | ; Free the table 'table1'. |
||
| 48 | //mtable -f table1 |
||
| 49 | |||
| 50 | ; Add a new sub table to table 'table1', |
||
| 51 | //mtable -aA table1 sub1 sub1 |
||
| 52 | |||
| 53 | ; Add a new item to the sub table located at position '1' in table 'table1'. |
||
| 54 | //mtable -a table1 1 item1 value1 |
||
| 55 | |||
| 56 | ; Print the first item in the table 'table1', which is a sub table. |
||
| 57 | //echo -ag First item in table1 is $mtable(table1, 1).item - $mtable(table1, 1).type |
||
| 58 | |||
| 59 | ; Print the first item in the sub table located at position '1' in table 'table1'. |
||
| 60 | //echo -ag First item in sub table1 is $mtable(table1, 1, 1).item |
||
| 61 | |||
| 62 | ; Generates a json output of table 'table1'. |
||
| 63 | // echo -ag $mtable(table1).json |
||
| 64 | |||
| 65 | ; Generates a ini output of table 'table1'. |
||
| 66 | // echo -ag $mtable(table1).ini |
||
| 67 | |||
| 68 | ; Generates a xml output of sub table at position '1' in table 'table1'. |
||
| 69 | // echo -ag $mtable(table1, 1).xml |
||
| 70 | </pre> |