Testasd » History » Version 64
Per Amundsen, 02/08/2023 09:38 AM
| 1 | 45 | Per Amundsen | h1. Multidimensional arrays |
|---|---|---|---|
| 2 | |||
| 3 | 62 | Per Amundsen | */marray -aTNBAV <name> [N..] <item> <value>* |
| 4 | */marray -eTNBAV <name> [N..] <N> <item> <value>* |
||
| 5 | 1 | Per Amundsen | */marray -iTNBAV <name> [N..] <N> <item> <value>* |
| 6 | */marray -d <name> [N..] <N>* |
||
| 7 | 54 | Per Amundsen | */marray -f <name>* |
| 8 | |||
| 9 | 45 | Per Amundsen | *Switches* |
| 10 | |||
| 11 | 64 | Per Amundsen | -a - Add a new item to a table. |
| 12 | -e - Edit a item in a table. |
||
| 13 | -i - Insert a new item to a table. |
||
| 14 | -d - Delete a item from a table. |
||
| 15 | -f - Free/delete a table. |
||
| 16 | 62 | Per Amundsen | -T - Indicates the type is text. |
| 17 | -N - Indicates the type is a number. |
||
| 18 | -B - Indicates the type is a boolean. |
||
| 19 | -A - Indicates the type is a sub table/array. |
||
| 20 | -V - TODO Indicates the type is a binvar.. |
||
| 21 | |||
| 22 | 50 | Per Amundsen | *$marray(name, N, [N..])* |
| 23 | 1 | Per Amundsen | |
| 24 | 45 | Per Amundsen | gets the Nth item in a table, subsequent N parameters gets the Nth item from a sub table, infinite sub depth. |
| 25 | |||
| 26 | 1 | Per Amundsen | *Switches* |
| 27 | 49 | Per Amundsen | |
| 28 | 60 | Per Amundsen | .item - Get item. |
| 29 | 55 | Per Amundsen | .value - Get item value. |
| 30 | 62 | Per Amundsen | .type - Get item type. (0 = text, 1 = number, 2 = bool, 3 = binvar, 4 = sub table) |
| 31 | 55 | Per Amundsen | .json - Generate a json table from all items in the current table and all sub tables. |
| 32 | .ini - Generate a ini output from all items in the current table and all sub tables. |
||
| 33 | 63 | Per Amundsen | .xml - Generate a xml output from all items in the current table and all sub tables. |
| 34 | 1 | Per Amundsen | |
| 35 | *Example* |
||
| 36 | 56 | Per Amundsen | |
| 37 | 1 | Per Amundsen | <pre> |
| 38 | 56 | Per Amundsen | ; Add item1/value1 to the table 'table1'. |
| 39 | 62 | Per Amundsen | //marray -a table1 item1 value1 |
| 40 | 56 | Per Amundsen | |
| 41 | 62 | Per Amundsen | ; Add sub table 'item2' to the table 'table1'. |
| 42 | //marray -aA table1 item2 value2 |
||
| 43 | 57 | Per Amundsen | |
| 44 | 55 | Per Amundsen | ; Insert item3/value3 at position '1' in the table 'table1'. |
| 45 | 62 | Per Amundsen | //marray -i table1 1 item3 value3 |
| 46 | 55 | Per Amundsen | |
| 47 | ; Print number of items in table 'table1'. |
||
| 48 | //echo -ag Number of items in table1 is $marray(table1, 0) |
||
| 49 | |||
| 50 | ; Print the first items in table 'table1'. |
||
| 51 | 1 | Per Amundsen | //echo -ag First item in table1 is $marray(table1, 1).item |
| 52 | 55 | Per Amundsen | |
| 53 | 1 | Per Amundsen | ; Delete the first item in table 'table1'. |
| 54 | 55 | Per Amundsen | //marray -d table1 1 |
| 55 | |||
| 56 | ; Free the table 'table1'. |
||
| 57 | //marray -f table1 |
||
| 58 | |||
| 59 | ; Add a new sub table to table 'table1', |
||
| 60 | 62 | Per Amundsen | //marray -aA table1 sub1 sub1 |
| 61 | 55 | Per Amundsen | |
| 62 | 56 | Per Amundsen | ; Add a new item to the sub table located at position '1' in table 'table1'. |
| 63 | 62 | Per Amundsen | //marray -a table1 1 item1 value1 |
| 64 | 55 | Per Amundsen | |
| 65 | ; Print the first item in the table 'table1', which is a sub table. |
||
| 66 | //echo -ag First item in table1 is $marray(table1, 1).item - $marray(table1, 1).type |
||
| 67 | |||
| 68 | ; Print the first item in the sub table located at position '1' in table 'table1'. |
||
| 69 | //echo -ag First item in sub table1 is $marray(table1, 1, 1).item |
||
| 70 | 63 | Per Amundsen | |
| 71 | ; Generates a json output of table 'table1'. |
||
| 72 | // echo -ag $marray(table1).json |
||
| 73 | |||
| 74 | ; Generates a ini output of table 'table1'. |
||
| 75 | // echo -ag $marray(table1).ini |
||
| 76 | |||
| 77 | ; Generates a xml output of sub at position '1' in table 'table1'. |
||
| 78 | // echo -ag $marray(table1, 1).xml |
||
| 79 | 1 | Per Amundsen | </pre> |