Sha256: 512069576e6d7475b0329f7ceca5695cb383516ad18c02a9dd4b30695aa50bb0

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

Contents

#!/usr/bin/env ruby

#    Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常)
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

module Ludy
  TRACE_EVENT   = 0
  TRACE_FILE    = 1
  TRACE_LINE    = 2
  TRACE_MSG     = 3
  TRACE_BINDING = 4
  TRACE_CLASS   = 5

  def callstack levels = -1
    st = Thread.current[:callstack]
    if levels then st && st[levels - 2] else st end
  end
  module_function :callstack
end # of Ludy

set_trace_func lambda{ |*args|
  case args[Ludy::TRACE_EVENT]
    when /call$/
      (Thread.current[:callstack] ||= []).push args
    when /return$/
      (Thread.current[:callstack] ||= []).pop
  end
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ludy-0.0.3 lib/ludy/callstack.rb
ludy-0.0.5 lib/ludy/callstack.rb
ludy-0.0.6 lib/ludy/callstack.rb
ludy-0.0.7 lib/ludy/callstack.rb
ludy-0.0.8 lib/ludy/callstack.rb
ludy-0.0.4 lib/ludy/callstack.rb
ludy-0.0.9 lib/ludy/callstack.rb