class FFI::Tcl::Interp

Constants

EVAL_DIRECT
EVAL_GLOBAL

Public Instance Methods

do_events_until(flag = 0) { || ... } click to toggle source
# File lib/ffi-tk/ffi/tcl/interp.rb, line 66
def do_events_until(flag = 0)
  begin
    wait_for_event(0.1)
    Tcl.do_one_event(flag)
  end until yield
end
do_events_while(flag = 0) { || ... } click to toggle source
# File lib/ffi-tk/ffi/tcl/interp.rb, line 73
def do_events_while(flag = 0)
  begin
    wait_for_event(0.1)
    Tcl.do_one_event(flag)
  end while yield
end
do_one_event(flag = 0) click to toggle source
# File lib/ffi-tk/ffi/tcl/interp.rb, line 62
def do_one_event(flag = 0)
  Tcl.do_one_event(flag)
end
eval(string) click to toggle source
# File lib/ffi-tk/ffi/tcl/interp.rb, line 80
def eval(string)
  if $DEBUG
    if string =~ /\n/
      puts "\neval: %p" % [string]
    else
      puts "\neval: %s" % [string]
    end
  end

  code = Tcl.eval_ex(self, string, string.bytesize, EVAL_DIRECT)
  puts 'eval= %p' % [code] if $DEBUG
  return true if code == 0

  message = guess_result.to_s
  puts 'eval= %p' % [message] if $DEBUG

  if message.empty?
    raise 'Failure during eval of: %p' % [string]
  else
    raise '%s during eval of: %p' % [message, string]
  end
end
guess_result() click to toggle source
# File lib/ffi-tk/ffi/tcl/interp.rb, line 18
def guess_result
  EvalResult.guess(self, Obj.new(Tcl.get_obj_result(self)))
end
inspect() click to toggle source
# File lib/ffi-tk/ffi/tcl/interp.rb, line 14
def inspect
  'Interp'
end
obj_result() click to toggle source
# File lib/ffi-tk/ffi/tcl/interp.rb, line 22
def obj_result
  Obj.new(Tcl.get_obj_result(self))
end
obj_result=(ruby_obj) click to toggle source
# File lib/ffi-tk/ffi/tcl/interp.rb, line 26
def obj_result=(ruby_obj)
  obj =
    case ruby_obj
    when true
      Tcl.new_boolean_obj(1)
    when false
      Tcl.new_boolean_obj(0)
    when String
      Tcl.new_string_obj(ruby_obj, ruby_obj.bytesize)
    when Integer
      Tcl.new_int_obj(ruby_obj)
    when Exception
      string = [ruby_obj.message, *ruby_obj.backtrace].join("\n")
      Tcl.new_string_obj(string, string.bytesize)
    else
      if ruby_obj.respond_to?(:to_tcl)
        ruby_obj.to_tcl
      else
        raise ArgumentError, "Don't know how to set %p automatically" % [ruby_obj]
      end
    end

  Tcl.set_obj_result(self, obj)
end
wait_for_event(seconds = 0.0) click to toggle source
# File lib/ffi-tk/ffi/tcl/interp.rb, line 51
def wait_for_event(seconds = 0.0)
  if seconds && seconds > 0.0
    seconds, microseconds = (seconds * 1000).divmod(1000)
    time = TclTime.new(seconds, microseconds)
  else
    time = nil
  end

  Tcl.wait_for_event(time)
end