blob: cbdbc8d1c5e7cebad1d2596248880791979c9818 [file] [log] [blame]
mike@reedtribe.org0e59b792013-05-21 03:24:37 +00001-- just a helper function to dump the parameters, for debugging
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +00002function tostr(t)
3 local str = ""
4 for k, v in next, t do
mike@reedtribe.org0e59b792013-05-21 03:24:37 +00005 if #str > 0 then
6 str = str .. ", "
7 end
8 if type(k) == "number" then
9 str = str .. "[" .. k .. "] = "
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +000010 else
mike@reedtribe.org0e59b792013-05-21 03:24:37 +000011 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.org1c5a94f2013-05-16 04:20:23 +000017 end
18 end
19 return str
20end
21
mike@reedtribe.orgf02fe3d2013-05-21 12:20:39 +000022total = {}
23
24function setcanvas(c)
25 canvas = c
26end
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +000027
mike@reedtribe.org0e59b792013-05-21 03:24:37 +000028-- called with the parameters to each canvas.draw call
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +000029function accumulate(t)
mike@reedtribe.orgf02fe3d2013-05-21 12:20:39 +000030 local n = total[t.verb] or 0
31 total[t.verb] = n + 1
32
reed@google.com14f584b2013-05-21 14:19:53 +000033 if false and t.verb == "drawRect" then
mike@reedtribe.orgf02fe3d2013-05-21 12:20:39 +000034 local m = canvas:getTotalMatrix()
35 print("... ", tostr(m), "\n")
36 end
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +000037
mike@reedtribe.org0e59b792013-05-21 03:24:37 +000038 -- 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.comdff7e112013-05-15 19:34:20 +000046end
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +000047
mike@reedtribe.org0e59b792013-05-21 03:24:37 +000048-- lua_pictures will call this function after all of the files have been
49-- "accumulated"
reed@google.comdff7e112013-05-15 19:34:20 +000050function summarize()
mike@reedtribe.orgf02fe3d2013-05-21 12:20:39 +000051 io.write("\n", tostr(total), "\n")
reed@google.comdff7e112013-05-15 19:34:20 +000052end
53