1
DebugWatch = DebugInstrument:extend
6
onNew = function (self)
7
self.title.text = 'Watch'
8
self.labels = self:add(Text:new{ font = self.font })
9
self.values = self:add(Text:new{ font = self.font })
10
self.lineHeight = self.labels._fontObj:getHeight()
12
debugger.watch = function (exp, label) self:addExpression(exp, label) end
15
-- Method: addExpression
16
-- Adds an expression to be watched.
19
-- expression - expression to evaluate as a string
20
-- label - string label, defaults to expression
22
addExpression = function (self, expression, label)
24
table.insert(self._watches, { label = label or expression,
25
func = loadstring('return ' .. expression) })
27
self.contentHeight = #self._watches * self.lineHeight + 2 * self.spacing
30
onUpdate = function (self)
34
for _, watch in pairs(self._watches) do
35
local ok, value = pcall(watch.func)
36
if not ok then value = nil end
37
self.labels.text = self.labels.text .. watch.label .. '\n'
38
self.values.text = self.values.text .. tostring(value) .. '\n'
42
onResize = function (self, x, y, width, height)
43
self.labels.y, self.values.y = y + self.spacing, y + self.spacing
44
self.labels.height, self.values.height = height, height
46
self.labels.x = x + self.spacing
47
self.labels.width = width / 2 - self.spacing * 2
49
self.values.x = self.labels.x + self.labels.width + self.spacing
50
self.values.width = self.labels.width