#!/usr/bin/env ruby
# frozen_string_literal: true

lib = if File.symlink?(__FILE__)
        File.expand_path('../../lib/ffi-tk', File.readlink(__FILE__))
      else
        File.expand_path('../../lib/ffi-tk', __FILE__)
      end

require lib

Tk.init

begin
  require 'readline'

  while line = Readline.readline('> ', true)
    begin
      p eval(line)
    rescue => ex
      puts "#{ex.class}: #{ex}", *ex.backtrace
    end
  end
rescue LoadError
  while line = $stdin.gets
    line.strip!

    begin
      p eval(line)
    rescue => ex
      puts "#{ex.class}: #{ex}", *ex.backtrace
    end
  end
end