0

Peculiarities with the ruby env in BrowserPlus

QUOTE (alexandermaccaw @ Dec 10 2008, 06:38 AM) <{POST_SNAPBACK}>
Sorry for the slow response.

Have been playing around with services, have a couple of questions.
* Why the need for bp_require? It looks like it needs an absolute path from the service folder too.
* Is bp.complete part of the async api. If so, that's really cool! This async api makes it really easy to add bonjour integration. Can I call it multiple times?
* Can I return Ruby objects?

I'm thinking a Bonjour api would look like this:

PlusJour.list(service_name, timeout=3)
PlusJour.register(service_name, name, port, text_record)

This sort of thing is currently really hard to test with the current workflow (especially since it deletes your code if you get anything wrong!), but I'm sure that'll change with the published api.
Can you PM me if there's some sort of private beta for that api.

Thanks,
Alex


Hey Alex,

require() will use relative paths from the rubystdlib installed. bp_require() will include relative to your service directory (where it's installed).

bp.complete is an async api. Once it's invoked the "transaction" is complete, so it may not be invoked multiple times.

but, you can take "callbacks" as arguments which can be invoked any number of times, here's a sample service that demonstrated:
CODE
class HelloRuby
def initialize(args)
log("init called with #{args.pretty_inspect}")
end

def log(str)
if false
File.open("/tmp/dbg.txt", "a") { |f| f.puts(str) }
end
end


def howdy(bp, args)
Thread.new(bp, args['callback']) do |bp,callback |
(0..10).each do |x|
str = "howdy there, for the #{x}th time"
log(str)
callback.invoke(str)
sleep 0.4
end
bp.complete("Hello world from my great corelet instance!")
end
end
end

rubyCoreletDefinition = {
'class' => "HelloRuby",
'name' => "HelloRuby",
'major_version' => 0,
'minor_version' => 0,
'micro_version' => 7,
'documentation' => 'A service that tests callbacks from ruby.',
'functions' =>
[
{
'name' => 'howdy',
'documentation' => "Say \"hello\" to the world",
'arguments' =>
[
{
'name' => 'callback',
'type' => 'callback',
'required' => true,
'documentation' => 'the callback to send a hello message to'
}
]
}
]
}


short on time, more later,
lloyd

by
4 Replies
  • To finish up,

    "Can I return ruby objects" - yes and no. supported ruby datatypes that will be mapped into corresponding javascript types include:
    float
    string
    fixnum
    boolean
    hash
    array
    Pathname
    nil

    As far as early access to the SDK? It should be out very shortly, but shoot an email to browserplus-feedback@yahoo-inc.com and I'll see what I can do.

    very best,
    lloyd
    0
  • QUOTE (Lloyd Hilaiel @ Dec 10 2008, 12:29 PM) <{POST_SNAPBACK}>
    require() will use relative paths from the rubystdlib installed. bp_require() will include relative to your service directory (where it's installed).


    Why add the service directory to the load path, like this:
    $:.unshift(File.dirname(__FILE__))

    Then you don't have to edit all the requires and turn them into bp_requires.
    0
  • QUOTE (alexandermaccaw @ Dec 11 2008, 02:07 AM) <{POST_SNAPBACK}>
    Why add the service directory to the load path, like this:
    $:.unshift(File.dirname(__FILE__))

    Then you don't have to edit all the requires and turn them into bp_requires.


    Hey Alex,

    The reason not to do this is an implementation detail. All services are run in the same process space, multiple ruby services actually use the same interpreter. This is a bit horrid, as mucking with global data (i.e. constants) in one ruby service will affect others.

    There is a way out that's on our roadmap, and that's to run services in distinct processes. This will add a bit more IPC overhead, but will provide better isolation of code and better overall system stability. It will also make the ruby environment much more robust.

    Currently the process split is something we're talking about doing in january, and after that point we can produce a 5.x ruby interpreter that gets rid of the bp_require.

    hope this makes that particular quirk more understandable.

    very best,
    lloyd
    0
  • QUOTE (alexandermaccaw @ Dec 11 2008, 02:07 AM) <{POST_SNAPBACK}>
    Why add the service directory to the load path, like this:
    $:.unshift(File.dirname(__FILE__))

    Then you don't have to edit all the requires and turn them into bp_requires.


    Hey Alex,

    The reason not to do this is an implementation detail. All services are run in the same process space, multiple ruby services actually use the same interpreter. This is a bit horrid, as mucking with global data (i.e. constants) in one ruby service will affect others.

    There is a way out that's on our roadmap, and that's to run services in distinct processes. This will add a bit more IPC overhead, but will provide better isolation of code and better overall system stability. It will also make the ruby environment much more robust.

    Currently the process split is something we're talking about doing in january, and after that point we can produce a 5.x ruby interpreter that gets rid of the bp_require.

    hope this makes that particular quirk more understandable.

    very best,
    lloyd
    0
This forum is locked.

Recent Posts

in Service Authors