Testasd » History » Version 73
Per Amundsen, 02/09/2023 05:03 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 | 70 | Per Amundsen | Adds/removes/inserts/modifies items in a multi dimensional table/array. |
10 | 67 | Per Amundsen | |
11 | 65 | Per Amundsen | *Parameters* |
12 | |||
13 | <name> - Name of the table to modify. |
||
14 | [N..] - Indicates the item should be added/inserted/deleted from sub table position N, subsequent N parameters travels further down. |
||
15 | <N> - The Nth item in a table or sub table to modify. |
||
16 | <item> - The item name. |
||
17 | <value> - The item value. |
||
18 | |||
19 | 45 | Per Amundsen | *Switches* |
20 | |||
21 | 64 | Per Amundsen | -a - Add a new item to a table. |
22 | -e - Edit a item in a table. |
||
23 | -i - Insert a new item to a table. |
||
24 | -d - Delete a item from a table. |
||
25 | -f - Free/delete a table. |
||
26 | 62 | Per Amundsen | -T - Indicates the type is text. |
27 | -N - Indicates the type is a number. |
||
28 | -B - Indicates the type is a boolean. |
||
29 | -A - Indicates the type is a sub table/array. |
||
30 | |||
31 | 66 | Per Amundsen | --------------------------------------------------------- |
32 | |||
33 | 1 | Per Amundsen | *$marray(name, N, [N..])* |
34 | |||
35 | 67 | Per Amundsen | Gets the Nth item in a table, subsequent N parameters gets the Nth item from a sub table, infinite sub depth. |
36 | 45 | Per Amundsen | |
37 | 71 | Per Amundsen | *Parameters* |
38 | |||
39 | name - The outer table name. |
||
40 | N - The Nth item in the table. |
||
41 | [N..] - The Nth item in a sub table, subsequent N parameters travels further down. |
||
42 | |||
43 | *Properties* |
||
44 | 49 | Per Amundsen | |
45 | 72 | Per Amundsen | .item - Gets the item name. |
46 | 1 | Per Amundsen | .value - Gets the item value. |
47 | 73 | Per Amundsen | .type - Get the item type. (0 = text, 1 = number, 2 = bool, 3 = sub table) |
48 | 55 | Per Amundsen | .json - Generate a json table from all items in the current table and all sub tables. |
49 | .ini - Generate a ini output from all items in the current table and all sub tables. |
||
50 | 63 | Per Amundsen | .xml - Generate a xml output from all items in the current table and all sub tables. |
51 | 1 | Per Amundsen | |
52 | *Example* |
||
53 | 56 | Per Amundsen | |
54 | 1 | Per Amundsen | <pre> |
55 | 56 | Per Amundsen | ; Add item1/value1 to the table 'table1'. |
56 | 62 | Per Amundsen | //marray -a table1 item1 value1 |
57 | 56 | Per Amundsen | |
58 | 62 | Per Amundsen | ; Add sub table 'item2' to the table 'table1'. |
59 | //marray -aA table1 item2 value2 |
||
60 | 57 | Per Amundsen | |
61 | 55 | Per Amundsen | ; Insert item3/value3 at position '1' in the table 'table1'. |
62 | 62 | Per Amundsen | //marray -i table1 1 item3 value3 |
63 | 55 | Per Amundsen | |
64 | ; Print number of items in table 'table1'. |
||
65 | //echo -ag Number of items in table1 is $marray(table1, 0) |
||
66 | |||
67 | ; Print the first items in table 'table1'. |
||
68 | 1 | Per Amundsen | //echo -ag First item in table1 is $marray(table1, 1).item |
69 | 55 | Per Amundsen | |
70 | 1 | Per Amundsen | ; Delete the first item in table 'table1'. |
71 | 55 | Per Amundsen | //marray -d table1 1 |
72 | |||
73 | ; Free the table 'table1'. |
||
74 | //marray -f table1 |
||
75 | |||
76 | ; Add a new sub table to table 'table1', |
||
77 | 62 | Per Amundsen | //marray -aA table1 sub1 sub1 |
78 | 55 | Per Amundsen | |
79 | 56 | Per Amundsen | ; Add a new item to the sub table located at position '1' in table 'table1'. |
80 | 62 | Per Amundsen | //marray -a table1 1 item1 value1 |
81 | 55 | Per Amundsen | |
82 | ; Print the first item in the table 'table1', which is a sub table. |
||
83 | //echo -ag First item in table1 is $marray(table1, 1).item - $marray(table1, 1).type |
||
84 | |||
85 | ; Print the first item in the sub table located at position '1' in table 'table1'. |
||
86 | //echo -ag First item in sub table1 is $marray(table1, 1, 1).item |
||
87 | 63 | Per Amundsen | |
88 | ; Generates a json output of table 'table1'. |
||
89 | // echo -ag $marray(table1).json |
||
90 | |||
91 | ; Generates a ini output of table 'table1'. |
||
92 | // echo -ag $marray(table1).ini |
||
93 | |||
94 | 69 | Per Amundsen | ; Generates a xml output of sub table at position '1' in table 'table1'. |
95 | 63 | Per Amundsen | // echo -ag $marray(table1, 1).xml |
96 | 1 | Per Amundsen | </pre> |