/ld27

To get this branch, use:
bzr branch http://9ix.org/bzr/ld27

« back to all changes in this revision

Viewing changes to zoetrope/debug/stack.lua

  • Committer: Josh C
  • Date: 2014-07-05 00:05:23 UTC
  • Revision ID: josh@9ix.org-20140705000523-qxhxpi5ixst875zb
control by touch ("mouse")

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- Class: DebugStack
 
2
-- This shows a stack trace for a particular stack level.
 
3
 
 
4
DebugStack = DebugInstrument:extend
 
5
{
 
6
        visible = false,
 
7
        width = 'narrow',
 
8
 
 
9
        onNew = function (self)
 
10
                self.title.text = 'Stack'
 
11
                self.text = self:add(Text:new{ font = self.font, wordWrap = false })
 
12
                self.lineHeight = self.text._fontObj:getHeight()
 
13
 
 
14
                debugger.showStack = function (level) self:showStack(level) end
 
15
                debugger.hideStack = function() self.visible = false end
 
16
        end,
 
17
 
 
18
        -- Method: showStack
 
19
        -- Makes the instrument visible and shows a stack trace.
 
20
        -- To hide this, just set the instrument's visible property to false.
 
21
        --
 
22
        -- Arguments:
 
23
        --              level - stack level to show
 
24
        --
 
25
        -- Returns:
 
26
        --              nothing
 
27
        
 
28
        showStack = function (self, level)
 
29
                self.text.text = ''
 
30
                self.visible = true
 
31
                self.contentHeight = self.spacing * 2
 
32
 
 
33
                local info
 
34
 
 
35
                repeat
 
36
                        info = debug.getinfo(level, 'nlS')
 
37
                        
 
38
                        if info then
 
39
                                self.contentHeight = self.contentHeight + self.lineHeight
 
40
 
 
41
                                if info.name and info.name ~= '' then
 
42
                                        self.text.text = self.text.text .. info.name .. '()\n'
 
43
                                elseif not info.name then
 
44
                                        self.text.text = self.text.text .. '(anonymous function)\n'
 
45
                                else
 
46
                                        self.text.text = self.text.text .. '(tail call)\n'
 
47
                                end
 
48
 
 
49
                                if info.currentline ~= -1 then
 
50
                                        self.text.text = self.text.text .. '    ' .. info.short_src ..
 
51
                                                         ':' .. info.currentline .. '\n'
 
52
 
 
53
                                        self.contentHeight = self.contentHeight + self.lineHeight
 
54
                                end
 
55
                        end
 
56
 
 
57
                        level = level + 1
 
58
                until not info
 
59
        end,
 
60
 
 
61
        onResize = function (self, x, y, width, height)
 
62
                self.text.x = x + self.spacing
 
63
                self.text.y = y + self.spacing
 
64
                self.text.width = width - self.spacing * 2
 
65
                self.text.height = height - self.spacing * 2
 
66
        end
 
67
}