Aug 21, 2014

personal note 8 - Debug

(1) What happened:
I wanted to see callstack.

(2) Solution
 module DebugView
    def parse_caller(at)
      if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
        return [$2, $3] #file = $1; line = $2.to_i; method = $3
      end
    end
  
    def track
    return if !$TEST
        stack = []
      caller.each { |arr| stack.push( parse_caller(arr) ) }
      stack.pop; stack.pop
      self.trace(stack)
    end
end

call DebugView.track

(3) Remained Problems
caller returns [filename, line, method].
but in rgss3, filename has no meaning since all scripts are loaded in single file.

Q. why DebugView?
A. ('w') < because it was there.

No comments:

Post a Comment