Invoking Ruby code from a low-level language?

Discussion in 'Ruby' started by Alex Fulton, Dec 11, 2008.

  1. Alex Fulton

    Alex Fulton Guest

    Hi, my sincerest apologies if this question has already been answered
    somewhere, but google didn't turn anything up...

    I'm working on a small university research project which is trying to
    create a network weathermap by creating a large distributed P2P network
    of clients installed on ordinary users' home computers, and collecting
    data by running traces etc between the different peers.

    We want to use a high-level language and GUI library for the interface,
    and FXRuby seems to be a good option for this, but, due to the sort of
    computers this client is going to be deployed on (home users,
    predominantly Windows, probably not tech-savvy and reluctant to make any
    changes to their systems), most of them will probably not have a Ruby
    interpreter installed. Rather than forcing people to download Ruby and
    Fox and install them themselves, in addition to installing our client,
    we would prefer to be able to bundle the Ruby interpreter and GUI
    libraries into our application (as dynamic libraries or something) and
    then write most of the program in C (the startup code, the
    communications layer, etc), and only have the user-interaction stuff
    written in Ruby.

    So, is it possible to have a C program that invokes Ruby code via an
    interpreter library? I'm sure I've seen some apps do this with Python,
    but I'm not sure if it's possible with Ruby or not...

    Thanks,
    Alex Fulton
    (Computer Science department, University of Auckland, New Zealand)
    --
    Posted via http://www.ruby-forum.com/.
     
    Alex Fulton, Dec 11, 2008
    #1
    1. Advertising

  2. Alex Fulton

    Marc Heiler Guest

    > Rather than forcing people to download Ruby and
    > Fox and install them themselves, in addition to installing our client,
    > we would prefer to be able to bundle the Ruby interpreter and GUI
    > libraries into our application (as dynamic libraries or something) and
    > then write most of the program in C (the startup code, the
    > communications layer, etc), and only have the user-interaction stuff
    > written in Ruby.


    Have a look at http://www.erikveen.dds.nl/rubyscript2exe/

    Also you may want to look at Ruby-C
    http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html
    --
    Posted via http://www.ruby-forum.com/.
     
    Marc Heiler, Dec 11, 2008
    #2
    1. Advertising

  3. Alex Fulton

    Alex Fulton Guest

    Alex Fulton, Dec 11, 2008
    #3
  4. Alex Fulton

    Phlip Guest

    Alex Fulton wrote:
    >> Have a look at http://www.erikveen.dds.nl/rubyscript2exe/

    >
    > That looks perfect. Not exactly what I had in mind, but it should serve
    > our purposes admirably.


    Have a look at Shoes. It's a complete platform built around Ruby, with both
    installers and a package system - Shy. I would compare it favorably to the old
    Amulet GUI for situations like weather maps.
     
    Phlip, Dec 12, 2008
    #4
  5. Alex Fulton wrote:
    > Hi, my sincerest apologies if this question has already been answered
    > somewhere, but google didn't turn anything up...
    >
    > I'm working on a small university research project which is trying to
    > create a network weathermap by creating a large distributed P2P network
    > of clients installed on ordinary users' home computers, and collecting
    > data by running traces etc between the different peers.
    >
    > We want to use a high-level language and GUI library for the interface,
    > and FXRuby seems to be a good option for this, but, due to the sort of
    > computers this client is going to be deployed on (home users,
    > predominantly Windows, probably not tech-savvy and reluctant to make any
    > changes to their systems), most of them will probably not have a Ruby
    > interpreter installed. Rather than forcing people to download Ruby and
    > Fox and install them themselves, in addition to installing our client,
    > we would prefer to be able to bundle the Ruby interpreter and GUI
    > libraries into our application (as dynamic libraries or something) and
    > then write most of the program in C (the startup code, the
    > communications layer, etc), and only have the user-interaction stuff
    > written in Ruby.
    >
    > So, is it possible to have a C program that invokes Ruby code via an
    > interpreter library? I'm sure I've seen some apps do this with Python,
    > but I'm not sure if it's possible with Ruby or not...
    >
    > Thanks,
    > Alex Fulton
    > (Computer Science department, University of Auckland, New Zealand)


    see the section "Embedding a Ruby Interpreter" in the pickaxe book and google
    for the same for examples...
     
    Reid Thompson, Dec 12, 2008
    #5
  6. On Fri, Dec 12, 2008 at 07:59:39AM +0900, Alex Fulton wrote:
    > Hi, my sincerest apologies if this question has already been answered
    > somewhere, but google didn't turn anything up...
    >
    > I'm working on a small university research project which is trying to
    > create a network weathermap by creating a large distributed P2P network
    > of clients installed on ordinary users' home computers, and collecting
    > data by running traces etc between the different peers.
    >
    > We want to use a high-level language and GUI library for the interface,
    > and FXRuby seems to be a good option for this, but, due to the sort of
    > computers this client is going to be deployed on (home users,
    > predominantly Windows, probably not tech-savvy and reluctant to make any
    > changes to their systems), most of them will probably not have a Ruby
    > interpreter installed. Rather than forcing people to download Ruby and
    > Fox and install them themselves, in addition to installing our client,
    > we would prefer to be able to bundle the Ruby interpreter and GUI
    > libraries into our application (as dynamic libraries or something) and
    > then write most of the program in C (the startup code, the
    > communications layer, etc), and only have the user-interaction stuff
    > written in Ruby.
    >
    > So, is it possible to have a C program that invokes Ruby code via an
    > interpreter library? I'm sure I've seen some apps do this with Python,
    > but I'm not sure if it's possible with Ruby or not...


    The 3 different ways to do this that I know of are:

    - Shoes : http://shoooes.net/
    - rubyscript2exe : http://www.erikveen.dds.nl/rubyscript2exe/
    - Crate : http://copiousfreetime.rubyforge.org/crate/

    Of the 3, Shoes has the gui support, and is probably the easiest to get going
    with. Crate may work the best if you have other libraries to compile against
    for your application to work.

    Disclaimer: I'm the author of crate.

    enjoy,

    -jeremy

    --
    ========================================================================
    Jeremy Hinegardner
     
    Jeremy Hinegardner, Dec 16, 2008
    #6
  7. Alex Fulton

    Alex Fulton Guest

    Wow, thanks for the replies everyone. This has given me a lot of
    material to get going on (and my boss is now getting irate because I'm
    spending too much time researching options and not enough time actually
    coding :p).

    But I've done some research on embedding ruby interpreters (via ruby.h),
    and while it seems like this task should be almost trivially easy, I
    can't seem to find a copy of the actual embedded interpreter library and
    headers. I did a search on my computer (a Mac) for ruby.h, and it turned
    up some platform-specific ruby embedding stuff for making OSX apps, but
    I'm interested in a more generic solution.

    Any thoughts?
    --
    Posted via http://www.ruby-forum.com/.
     
    Alex Fulton, Dec 16, 2008
    #7
  8. On Wed, Dec 17, 2008 at 05:22:10AM +0900, Alex Fulton wrote:
    > Wow, thanks for the replies everyone. This has given me a lot of
    > material to get going on (and my boss is now getting irate because I'm
    > spending too much time researching options and not enough time actually
    > coding :p).
    >
    > But I've done some research on embedding ruby interpreters (via ruby.h),
    > and while it seems like this task should be almost trivially easy, I
    > can't seem to find a copy of the actual embedded interpreter library and
    > headers. I did a search on my computer (a Mac) for ruby.h, and it turned
    > up some platform-specific ruby embedding stuff for making OSX apps, but
    > I'm interested in a more generic solution.
    >
    > Any thoughts?


    There isn't anything different to link against for the embedded ruby interpreter
    vs the noral interpreter. Its the same library libruby or libruby-static
    depending on your compilation shared/static needs. The ruby.h that you found is
    probably the ruby.h that you need to look at. On my Mac, the ruby.h is:

    mac shipped ruby : /usr/lib/ruby/1.8/universal-darwin9.0/ruby.h
    ports ruby : /opt/local/lib/ruby/1.8/i686-darwin9.5.0/ruby.h

    One thing you could do to see how to build an application that uses embedded
    ruby is to look at crate. It is has a very thin wrapper around embedded
    ruby.

    http://github.com/copiousfreetime/crate/tree/master/data/crate_boot.c

    Pretty much everything I used to figure out embedded ruby was
    http://metaeditor.sourceforge.net/embed/ and the 'Embedding a Ruby Interpreter'
    section in the Programming Ruby 2nd ed.

    hopefully that will help some.

    enjoy,

    -jeremy
    --
    ========================================================================
    Jeremy Hinegardner
     
    Jeremy Hinegardner, Dec 16, 2008
    #8
  9. Alex Fulton

    Alex Fulton Guest

    Great, thanks very much! It's good to hear from another Mac user, as
    different platforms seem to have vastly different ways of dealing with
    this.
    --
    Posted via http://www.ruby-forum.com/.
     
    Alex Fulton, Dec 16, 2008
    #9
  10. On Wed, Dec 17, 2008 at 06:23:58AM +0900, Alex Fulton wrote:
    > Great, thanks very much! It's good to hear from another Mac user, as
    > different platforms seem to have vastly different ways of dealing with
    > this.


    Easiest/Best way is to just download the ruby tarball and look at the ruby.h
    that ships. That works on every platform :).

    enjoy,

    -jeremy

    --
    ========================================================================
    Jeremy Hinegardner
     
    Jeremy Hinegardner, Dec 16, 2008
    #10
  11. Alex Fulton wrote:
    > Wow, thanks for the replies everyone. This has given me a lot of
    > material to get going on (and my boss is now getting irate because I'm
    > spending too much time researching options and not enough time actually
    > coding :p).
    >
    > But I've done some research on embedding ruby interpreters (via ruby.h),
    > and while it seems like this task should be almost trivially easy, I
    > can't seem to find a copy of the actual embedded interpreter library and
    > headers. I did a search on my computer (a Mac) for ruby.h, and it turned
    > up some platform-specific ruby embedding stuff for making OSX apps, but
    > I'm interested in a more generic solution.
    >
    > Any thoughts?


    two simple examples -- google for more/more complex examples.

    http://my.opera.com/subjam/blog/embedding-ruby-in-c-programs
     
    Reid Thompson, Dec 16, 2008
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page