diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/hello_world.json | 38 | ||||
-rw-r--r-- | examples/hello_world.rb | 50 |
2 files changed, 88 insertions, 0 deletions
diff --git a/examples/hello_world.json b/examples/hello_world.json new file mode 100644 index 0000000..295b10d --- /dev/null +++ b/examples/hello_world.json @@ -0,0 +1,38 @@ +{ + "kls": "Edoors::Spin", + "timestamp": "2012-06-10 23:17:15 +0200", + "name": "dom0", + "hibernation": false, + "inner_room": { + "iotas": { + "input": { + "kls": "InputDoor", + "name": "input" + }, + "output": { + "kls": "OutputDoor", + "name": "output" + } + }, + "links": { + "input": [ + { + "kls": "Edoors::Link", + "src": "input", + "dsts": "output", + "fields": null, + "cond_fields": null, + "cond_value": null + } + ] + } + }, + "sys_fifo": [ + + ], + "app_fifo": [ + + ], + "debug_errors": false, + "debug_routing": false +} diff --git a/examples/hello_world.rb b/examples/hello_world.rb new file mode 100644 index 0000000..69befd4 --- /dev/null +++ b/examples/hello_world.rb @@ -0,0 +1,50 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +# run from project top directory with : ruby -Ilib examples/hello_world.rb +# +require 'edoors' +# +class InputDoor < Edoors::Door + # + def start! + # stimulate myself + send_p require_p(Edoors::Particle), Edoors::ACT_GET + end + # + def receive_p p + if p.action==Edoors::ACT_GET + p.reset! + p.set_data 'txt', "hello world" + send_p p # will follow the default link + else + puts p.action + # we can release it or let the Door do it + release_p p + end + end + # +end +# +class OutputDoor < Edoors::Door + # + def receive_p p + puts p.get_data('txt') + # let the door release it + end + # +end +# +if $0 == __FILE__ + # + dom0 = Edoors::Spin.new 'dom0' + input = InputDoor.new 'input', dom0 + output = OutputDoor.new 'output', dom0 + dom0.add_link Edoors::Link.new('input', 'output', nil, nil, nil) + # + dom0.spin! + dom0.hibernate! + # +end +# +# EOF |