/ld27

To get this branch, use:
bzr branch /bzr/ld27

« back to all changes in this revision

Viewing changes to zoetrope/debug/locals.lua

  • Committer: Josh C
  • Date: 2014-07-03 14:41:57 UTC
  • Revision ID: josh@9ix.org-20140703144157-xydxt62xzcdq6bdk
cluke009 zoetrope + my spritebatch changes

Show diffs side-by-side

added added

removed removed

 
1
-- Class: DebugLocals
 
2
-- Shows all local variables for a particular stack level.
 
3
 
 
4
DebugLocals = DebugInstrument:extend
 
5
{
 
6
        visible = false,
 
7
        width = 'narrow',
 
8
 
 
9
        onNew = function (self)
 
10
                self.title.text = 'Locals'
 
11
                self.names = self:add(Text:new{ font = self.font })
 
12
                self.values = self:add(Text:new{ font = self.font })
 
13
                self.lineHeight = self.names._fontObj:getHeight()
 
14
 
 
15
                debugger.showLocals = function (level) self:showLocals(level) end
 
16
                debugger.hideLocals = function (level) self.visible = false end
 
17
        end,
 
18
 
 
19
        -- Method: showLocals
 
20
        -- Makes the instrument visible and shows all locals at a stack level.
 
21
        -- To hide this instrument, just set its visible property to false.
 
22
        --
 
23
        -- Arguments:
 
24
        --              level - level to show
 
25
        --
 
26
        -- Returns:
 
27
        --              nothing
 
28
 
 
29
        showLocals = function (self, level)
 
30
                self.visible = true
 
31
                self.contentHeight = 2 * self.spacing
 
32
                self.names.text = ''
 
33
                self.values.text = ''
 
34
 
 
35
                local i = 1
 
36
 
 
37
                while true do
 
38
                        local name, value = debug.getlocal(level, i)
 
39
                        if not name then break end
 
40
 
 
41
                        -- skip variables named (*temporary*)
 
42
 
 
43
                        if not string.match(name, '^%(') then
 
44
                                self.names.text = self.names.text .. name .. '\n'
 
45
                                self.values.text = self.values.text .. tostring(value) .. '\n'
 
46
                                self.contentHeight = self.contentHeight + self.lineHeight
 
47
                        end
 
48
 
 
49
                        i = i + 1
 
50
                end
 
51
        end,
 
52
 
 
53
        onResize = function (self, x, y, width, height)
 
54
                self.names.y, self.values.y = y + self.spacing, y + self.spacing
 
55
                self.names.height, self.values.height = height, height
 
56
 
 
57
                self.names.x = x + self.spacing
 
58
                self.names.width = width * 0.3 - self.spacing * 2
 
59
                
 
60
                self.values.x = self.names.x + self.names.width + self.spacing
 
61
                self.values.width = width * 0.7
 
62
        end
 
63
}