public
Description: Erlectricity exposes Ruby to Erlang and vice versa.
Homepage:
Clone URL: git://github.com/mojombo/erlectricity.git
mojombo (author)
Wed Jun 04 23:30:12 -0700 2008
commit  772986662e0cbbb3a301d9ba289e7c12e905fac2
tree    4d550b077bdec5499c5c9fb44f9f3ed937e46645
parent  e00195e0dbccab00bb94cc5ab34a760c5fdc3927
name age message
file .gitignore Loading commit data...
file CONTRIBUTORS Fri Mar 07 15:16:07 -0800 2008 from svn [mojombo]
file History.txt Fri Mar 07 15:16:07 -0800 2008 from svn [mojombo]
file Manifest.txt Fri Mar 07 15:40:39 -0800 2008 update manifest [mojombo]
file README.txt
file Rakefile Fri Mar 07 15:18:47 -0800 2008 add ext to hoe [mojombo]
file erlectricity.gemspec
directory examples/
directory ext/
directory lib/
file setup.rb Fri Mar 07 15:16:07 -0800 2008 from svn [mojombo]
directory test/
README.txt
erlectricity
  by Scott Fleckenstein
     Tom Preston-Werner
     
     http://github.com/mojombo/erlectricity
     
== DESCRIPTION:

Erlectricity allows a Ruby program to receive and respond to Erlang messages
sent over the Erlang binary protocol.

== INSTALL:

$ gem install erlectricity

== USAGE (Ruby side):

require 'rubygems'
require 'erlectricity'
require 'stringio'

receive do |f|
  f.when(:echo, String) do |text|
    f.send!(:result, "You said: #{text}")
    f.receive_loop
  end
end

== USAGE (Erlang side):

-module(echo).
-export([test/0]).

test() ->
  Cmd = "ruby echo.rb",
  Port = open_port({spawn, Cmd}, [{packet, 4}, use_stdio, exit_status, binary]), 
  Payload = term_to_binary({echo, <<"hello world!">>}),
  port_command(Port, Payload),
  receive
    {Port, {data, Data}} ->
      {result, Text} = binary_to_term(Data),
      io:format("~p~n", [Text])
  end.