capitalex a révisé ce gist . Aller à la révision
2 files changed, 268 insertions
main.nv(fichier créé)
@@ -0,0 +1,223 @@ | |||
1 | + | |_| low-level clear action | |
2 | + | I seriously need to write a generator for these... | |
3 | + | |clearing (@table id), @table id| | |
4 | + | |clearing (@table id)| | |
5 | + | ||
6 | + | |clearing (@table row), @table row| | |
7 | + | |clearing (@table row)| | |
8 | + | ||
9 | + | |clearing (pretty print rows iterator), pretty print rows iterator| | |
10 | + | |clearing (pretty print rows iterator)| | |
11 | + | ||
12 | + | |clearing (print number iterator), print number iterator| | |
13 | + | |clearing (print number iterator)| | |
14 | + | ||
15 | + | ||
16 | + | |_| high-level clear action | |
17 | + | |clear (@table id)| | |
18 | + | , clearing (@table id):9007199254740991 | |
19 | + | ||
20 | + | |clear (@table row)| | |
21 | + | , clearing (@table row):9007199254740991 | |
22 | + | ||
23 | + | |clear (pretty print rows iterator)| | |
24 | + | , clearing (pretty print rows iterator):9007199254740991 | |
25 | + | ||
26 | + | |clear (print number iterator)| | |
27 | + | , clearing (print number iterator):9007199254740991 | |
28 | + | ||
29 | + | ||
30 | + | ||
31 | + | |_| low-level restore from temporary storage action | |
32 | + | |restoring (pretty print row index), temporary (pretty print row index)| | |
33 | + | , pretty print row index | |
34 | + | |restoring (pretty print row index)| | |
35 | + | ||
36 | + | ||
37 | + | ||
38 | + | |_| low-level move action | |
39 | + | |moving (@table size) to (pretty print rows iterator), @table size| | |
40 | + | , pretty print rows iterator | |
41 | + | |moving (@table size) to (pretty print rows iterator)| | |
42 | + | ||
43 | + | ||
44 | + | ||
45 | + | |_| low-level copy action | |
46 | + | |copying (pretty print row index) to (@table row), pretty print row index| | |
47 | + | , copying (pretty print row index) to (@table row) | |
48 | + | , temporary (pretty print row index) | |
49 | + | , @table row | |
50 | + | ||
51 | + | |copying (pretty print row index) to (@table row)| | |
52 | + | , restoring (pretty print row index) | |
53 | + | ||
54 | + | ||
55 | + | ||
56 | + | |_| high-level move action | |
57 | + | |move (@table size) to (pretty print rows iterator)| | |
58 | + | , clear (pretty print rows iterator) | |
59 | + | , moving (@table size) to (pretty print rows iterator):9007199254740991 | |
60 | + | ||
61 | + | |move (@table size) to (print number iterator)| | |
62 | + | , clear (print number iterator) | |
63 | + | , moving (@table size) to (print number iterator):9007199254740991 | |
64 | + | ||
65 | + | ||
66 | + | |_| high-level copy action | |
67 | + | |copy (pretty print row index) to (@table row)| | |
68 | + | , clear (@table row) | |
69 | + | , copying (pretty print row index) to (@table row):9007199254740991 | |
70 | + | ||
71 | + | ||
72 | + | ||
73 | + | |_| Define our tables | |
74 | + | |#table, singles| | |
75 | + | , 1st | |
76 | + | ||
77 | + | |#table, doubles| | |
78 | + | , 1st, 2nd | |
79 | + | ||
80 | + | |#table, triples| | |
81 | + | , 1st, 2nd, 3rd | |
82 | + | ||
83 | + | ||
84 | + | ||
85 | + | |_| Operations to select a table by id | |
86 | + | Hand written to show a general pattern for this | |
87 | + | |set (@table id) to (singles) table| @table id:1 | |
88 | + | |set (@table id) to (doubles) table| @table id:2 | |
89 | + | |set (@table id) to (triples) table| @table id:3 | |
90 | + | ||
91 | + | |select (singles) table| | |
92 | + | , clear (@table id) | |
93 | + | , set (@table id) to (singles) table | |
94 | + | ||
95 | + | |select (doubles) table| | |
96 | + | , clear (@table id) | |
97 | + | , set (@table id) to (doubles) table | |
98 | + | ||
99 | + | |select (triples) table| | |
100 | + | , clear (@table id) | |
101 | + | , set (@table id) to (triples) table | |
102 | + | ||
103 | + | ||
104 | + | ||
105 | + | |_| ports for reading the size of a table | |
106 | + | |#port, on get table size | |
107 | + | , needs, @get table size | |
108 | + | , reads, @table id| | |
109 | + | , @table size, @no such table | |
110 | + | |#port body, on get table size, lua| | |
111 | + | if self.tables[table_id] then | |
112 | + | counters["@table size"] = #self.tables[table_id] | |
113 | + | else | |
114 | + | counters["@no such table"] = 1 | |
115 | + | end | |
116 | + | ||
117 | + | ||
118 | + | |_| Read data from the command line and pump it into a table. | |
119 | + | |#port, on read singles, needs, @read singles| | |
120 | + | |#port body, on read singles, lua| | |
121 | + | local input = io.read("*a") | |
122 | + | for left, right in input:gmatch("(%d+)") do | |
123 | + | self.tables:push_row("singles", | |
124 | + | { ["1st"] = tonumber(left) or 0 | |
125 | + | } | |
126 | + | ) | |
127 | + | end | |
128 | + | ||
129 | + | |#port, on read doubles, needs, @read doubles| | |
130 | + | |#port body, on read doubles, lua| | |
131 | + | local input = io.read("*a") | |
132 | + | for left, right in input:gmatch("(%d+),%s*(%d+)") do | |
133 | + | self.tables:push_row("doubles", | |
134 | + | { ["1st"] = tonumber(left) or 0 | |
135 | + | , ["2nd"] = tonumber(right) or 0 | |
136 | + | } | |
137 | + | ) | |
138 | + | end | |
139 | + | ||
140 | + | |#port, on read triples, needs, @read triples| | |
141 | + | |#port body, on read triples, lua| | |
142 | + | local input = io.read("*a") | |
143 | + | for left, right in input:gmatch("(%d+),%s*(%d+),%s*(%d+)") do | |
144 | + | self.tables:push_row("triples", | |
145 | + | { ["1st"] = tonumber(left) or 0 | |
146 | + | , ["2nd"] = tonumber(right) or 0 | |
147 | + | , ["3rd"] = tonumber(right) or 0 | |
148 | + | } | |
149 | + | ) | |
150 | + | end | |
151 | + | ||
152 | + | ||
153 | + | |_| A generic operations over a table | |
154 | + | |#port, on pretty print row | |
155 | + | , needs, @pretty print row, | |
156 | + | , reads, @table id, @table row| | |
157 | + | |#port body, on pretty print row, lua| | |
158 | + | local rows = self.tables[table_id] | |
159 | + | local row = rows[table_row] | |
160 | + | io.write(rows.name .. " #" .. tostring(table_row) .. ": ") | |
161 | + | local mapping = self.tables.mappings[rows.name] | |
162 | + | local assembled_row = {} | |
163 | + | for key, index in pairs(mapping) do | |
164 | + | assembled_row[key] = row[index] | |
165 | + | end | |
166 | + | pprint(assembled_row) | |
167 | + | ||
168 | + | ||
169 | + | ||
170 | + | |_| loop to pretty print the rows of any table | |
171 | + | |pretty print rows| | |
172 | + | , clear (@table row) | |
173 | + | , get table size for (pretty print rows) | |
174 | + | , pretty printing rows | |
175 | + | ||
176 | + | |get table size for (pretty print rows)| | |
177 | + | , @get table size | |
178 | + | , move (@table size) to (pretty print rows iterator) | |
179 | + | ||
180 | + | |pretty printing rows, pretty print rows iterator| | |
181 | + | , pretty print row index | |
182 | + | , copy (pretty print row index) to (@table row) | |
183 | + | , pretty print row | |
184 | + | , next pretty print rows | |
185 | + | ||
186 | + | |pretty printing rows| | |
187 | + | ||
188 | + | |pretty print row| | |
189 | + | , @pretty print row | |
190 | + | ||
191 | + | |next pretty print rows| | |
192 | + | , pretty printing rows | |
193 | + | ||
194 | + | |pretty print row index| | |
195 | + | ||
196 | + | ||
197 | + | || 1st: read singles | |
198 | + | , 2nd: pretty print singles | |
199 | + | , 3rd: read doubles | |
200 | + | , 4th: pretty print doubles | |
201 | + | , 5th: read triples | |
202 | + | , 6th: pretty print triples | |
203 | + | ||
204 | + | |1st: read singles| | |
205 | + | , @read singles | |
206 | + | ||
207 | + | |2nd: pretty print singles| | |
208 | + | , select (singles) table | |
209 | + | , pretty print rows | |
210 | + | ||
211 | + | |3rd: read doubles| | |
212 | + | , @read doubles | |
213 | + | ||
214 | + | |4th: pretty print doubles| | |
215 | + | , select (doubles) table | |
216 | + | , pretty print rows | |
217 | + | ||
218 | + | |5th: read triples| | |
219 | + | , @read triples | |
220 | + | ||
221 | + | |6th: pretty print triples| | |
222 | + | , select (triples) table | |
223 | + | , pretty print rows |
output.txt(fichier créé)
@@ -0,0 +1,45 @@ | |||
1 | + | 123 | |
2 | + | 234 | |
3 | + | 25 | |
4 | + | singles #1: { | |
5 | + | ['1st'] = 123 | |
6 | + | } | |
7 | + | singles #2: { | |
8 | + | ['1st'] = 234 | |
9 | + | } | |
10 | + | singles #3: { | |
11 | + | ['1st'] = 25 | |
12 | + | } | |
13 | + | 123, 234 | |
14 | + | 43, 192 | |
15 | + | 392, 123 | |
16 | + | doubles #1: { | |
17 | + | ['1st'] = 123, | |
18 | + | ['2nd'] = 234 | |
19 | + | } | |
20 | + | doubles #2: { | |
21 | + | ['1st'] = 43, | |
22 | + | ['2nd'] = 192 | |
23 | + | } | |
24 | + | doubles #3: { | |
25 | + | ['1st'] = 392, | |
26 | + | ['2nd'] = 123 | |
27 | + | } | |
28 | + | 123, 439, 192 | |
29 | + | 203, 291, 398 | |
30 | + | 192, 43, 212 | |
31 | + | triples #1: { | |
32 | + | ['1st'] = 123, | |
33 | + | ['2nd'] = 439, | |
34 | + | ['3rd'] = 439 | |
35 | + | } | |
36 | + | triples #2: { | |
37 | + | ['1st'] = 203, | |
38 | + | ['2nd'] = 291, | |
39 | + | ['3rd'] = 291 | |
40 | + | } | |
41 | + | triples #3: { | |
42 | + | ['1st'] = 192, | |
43 | + | ['2nd'] = 43, | |
44 | + | ['3rd'] = 43 | |
45 | + | } |
Plus récent
Plus ancien