/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: 2013-08-25 00:16:36 UTC
  • Revision ID: josh@9ix.org-20130825001636-xoivc9byo1mdx0fu
1 goal in each maze

Show diffs side-by-side

added added

removed removed

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