mike@reedtribe.org | 0e59b79 | 2013-05-21 03:24:37 +0000 | [diff] [blame] | 1 | -- just a helper function to dump the parameters, for debugging |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 2 | function tostr(t) |
| 3 | local str = "" |
| 4 | for k, v in next, t do |
mike@reedtribe.org | 0e59b79 | 2013-05-21 03:24:37 +0000 | [diff] [blame] | 5 | if #str > 0 then |
| 6 | str = str .. ", " |
| 7 | end |
| 8 | if type(k) == "number" then |
| 9 | str = str .. "[" .. k .. "] = " |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 10 | else |
mike@reedtribe.org | 0e59b79 | 2013-05-21 03:24:37 +0000 | [diff] [blame] | 11 | str = str .. tostring(k) .. " = " |
| 12 | end |
| 13 | if type(v) == "table" then |
| 14 | str = str .. "{ " .. tostr(v) .. " }" |
| 15 | else |
| 16 | str = str .. tostring(v) |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 17 | end |
| 18 | end |
| 19 | return str |
| 20 | end |
| 21 | |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 22 | total = {} |
| 23 | |
| 24 | function setcanvas(c) |
| 25 | canvas = c |
| 26 | end |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 27 | |
mike@reedtribe.org | 0e59b79 | 2013-05-21 03:24:37 +0000 | [diff] [blame] | 28 | -- called with the parameters to each canvas.draw call |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 29 | function accumulate(t) |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 30 | local n = total[t.verb] or 0 |
| 31 | total[t.verb] = n + 1 |
| 32 | |
reed@google.com | 14f584b | 2013-05-21 14:19:53 +0000 | [diff] [blame] | 33 | if false and t.verb == "drawRect" then |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 34 | local m = canvas:getTotalMatrix() |
| 35 | print("... ", tostr(m), "\n") |
| 36 | end |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 37 | |
mike@reedtribe.org | 0e59b79 | 2013-05-21 03:24:37 +0000 | [diff] [blame] | 38 | -- enable to dump all of the parameters we were sent |
| 39 | if false then |
| 40 | -- dump the params in t, specifically showing the verb first, which we |
| 41 | -- then nil out so it doesn't appear in tostr() |
| 42 | io.write(t.verb, " ") |
| 43 | t.verb = nil |
| 44 | io.write(tostr(t), "\n") |
| 45 | end |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 46 | end |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 47 | |
mike@reedtribe.org | 0e59b79 | 2013-05-21 03:24:37 +0000 | [diff] [blame] | 48 | -- lua_pictures will call this function after all of the files have been |
| 49 | -- "accumulated" |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 50 | function summarize() |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 51 | io.write("\n", tostr(total), "\n") |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 52 | end |
| 53 | |