Sha256: ea783af701b2deda96cd7f65bfa91b24906f110e9a40745d2c8178ab387c36a8

Contents?: true

Size: 1021 Bytes

Versions: 22

Compression:

Stored size: 1021 Bytes

Contents

# -*- coding: utf-8 -*-


%w[xot rays reflex]
  .map  {|s| File.expand_path "../../../#{s}/lib", __FILE__}
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}

require 'thread'
require 'reflex'


class Channel

  def initialize ()
    @c2s, @s2c = Queue.new, Queue.new
  end

  def send (obj, async = false)
    @c2s.push obj
    async ? obj : @s2c.pop
  end

  def receive ()
    @s2c.pop
  end

  def process ()
    reply eval @c2s.pop(true)
  rescue ThreadError
  rescue => e
    reply e.backtrace
  end

  def reply (obj)
    @s2c.push obj
  end

end# Channel


class PrimaryWindow < Reflex::Window

  attr_reader :channel

  def initialize ()
    super
    set :title,  "Reflex/REPL"
    set :frame, 100, 100, 320, 240

    @channel = Channel.new

    Thread.new do
      loop do
        print '> '
        puts @channel.send(gets).inspect
      end
    end
  end

  def on_update (dt)
    super
    @channel.process
  end

end# PrimaryWindow


Reflex.start do
  $window = PrimaryWindow.new.show
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
reflexion-0.1.29 samples/repl.rb
reflexion-0.1.28 samples/repl.rb
reflexion-0.1.27 samples/repl.rb
reflexion-0.1.26 samples/repl.rb
reflexion-0.1.25 samples/repl.rb
reflexion-0.1.24 samples/repl.rb
reflexion-0.1.23 samples/repl.rb
reflexion-0.1.22 samples/repl.rb
reflexion-0.1.21 samples/repl.rb
reflexion-0.1.20 samples/repl.rb
reflexion-0.1.19 samples/repl.rb
reflexion-0.1.17 samples/repl.rb
reflexion-0.1.16 samples/repl.rb
reflexion-0.1.15 samples/repl.rb
reflexion-0.1.14 samples/repl.rb
reflexion-0.1.13 samples/repl.rb
reflexion-0.1.12 samples/repl.rb
reflexion-0.1.11 samples/repl.rb
reflexion-0.1.10 samples/repl.rb
reflexion-0.1.9.1 samples/repl.rb