embedding?

Discussion in 'Ruby' started by Eric Smith, Feb 28, 2004.

  1. Eric Smith

    Eric Smith Guest

    I've written some simulators in C that use Tcl and custom commands as an
    embedded debugger language.

    Tcl works OK, but I don't like the language very well. It's simple, but
    not very elegant Ruby looks like a much better language.

    Is there any documentation or example code showing embedding Ruby in
    a C program? A Google search turns up some C++ stuff, but it didn't
    seem very helpful.

    Is it possible to create multiple independent Ruby interpreter contexts?

    Thanks,
    Eric

    [If you want to reply by private email, please remove the obvious
    spam-proofing from my email address.]
     
    Eric Smith, Feb 28, 2004
    #1
    1. Advertising

  2. Eric Smith

    Mark Hubbart Guest

    Since nobody else has said anything yet, I guess I will :)

    On Feb 28, 2004, at 9:44 AM, Eric Smith wrote:

    > Is there any documentation or example code showing embedding Ruby in
    > a C program? A Google search turns up some C++ stuff, but it didn't
    > seem very helpful.


    Have you looked in the PickAxe guide? There's a nice section there that
    might answer your questions. Look under "Ruby in its Setting >>
    Extending Ruby" for the goods.

    > Is it possible to create multiple independent Ruby interpreter
    > contexts?


    I'm a little behind with my C 'skillz', but looking at the pickaxe, I
    would guess no. But as I said, I'm very rusty.

    --Mark
     
    Mark Hubbart, Feb 29, 2004
    #2
    1. Advertising

  3. Eric Smith

    Chad Fowler Guest

    On Feb 28, 2004, at 12:44 PM, Eric Smith wrote:
    > elegant Ruby looks like a much better language.
    >
    > Is there any documentation or example code showing embedding Ruby in
    > a C program? A Google search turns up some C++ stuff, but it didn't
    > seem very helpful.
    >


    Have a look at README.ext in the source distribution for Ruby.


    > Is it possible to create multiple independent Ruby interpreter
    > contexts?
    >


    Unfortunately not (yet).
     
    Chad Fowler, Feb 29, 2004
    #3
  4. Eric Smith

    shasckaw Guest

    Eric Smith wrote:
    > I've written some simulators in C that use Tcl and custom commands as an
    > embedded debugger language.
    >
    > Tcl works OK, but I don't like the language very well. It's simple, but
    > not very elegant Ruby looks like a much better language.
    >
    > Is there any documentation or example code showing embedding Ruby in
    > a C program? A Google search turns up some C++ stuff, but it didn't
    > seem very helpful.
    >
    > Is it possible to create multiple independent Ruby interpreter contexts?
    >
    > Thanks,
    > Eric
    >
    > [If you want to reply by private email, please remove the obvious
    > spam-proofing from my email address.]

    Have you tried Lua instead of Tcl? I've heard that even pythoners think
    lua is better than python for embedding. I don't know if ruby can easily
    be embedded, but I'm sure it's the case for Lua.

    Lio
     
    shasckaw, Feb 29, 2004
    #4
  5. Eric Smith

    Eric Smith Guest

    I wrote:
    >> I've written some simulators in C that use Tcl and custom commands as
    >> an embedded debugger language. Tcl works OK, but I don't like the
    >> language very well. It's simple, but not very elegant


    shasckaw <> writes:
    > Have you tried Lua instead of Tcl? I've heard that even pythoners
    > think lua is better than python for embedding. I don't know if ruby
    > can easily be embedded, but I'm sure it's the case for Lua.


    Actually I have looked at Lua. The syntax makes it less than
    ideally suited for my reqirement. For instance, when a user wants
    to examine a dozen memory locations starting at octal location 2074, he
    or she will want to type
    examine 02074 12
    or maybe
    examine 02074, 12
    but not
    examine (02074, 12)

    The first syntax is easily achieved with Tcl but as far as I can tell,
    only the third works in Lua. It looks like the second and third should
    both work in Ruby.

    I wrote:
    >> Is there any documentation or example code showing embedding Ruby in
    >> a C program?


    I just discovered the "Extending Ruby" chapter of "Programming Ruby",
    and it seems to have the information I was looking for.

    I wrote:
    >> Is it possible to create multiple independent Ruby interpreter contexts?


    I still haven't found any way to do that.
     
    Eric Smith, Feb 29, 2004
    #5
  6. Eric Smith

    anon luker Guest

    Eric Smith <> wrote in message news:<>...
    <snip>
    > >> Is it possible to create multiple independent Ruby interpreter contexts?

    >
    > I still haven't found any way to do that.


    I'm a bit out of my element on this one, but I don't believe it is
    generally possible. I have seen somewhere, although I unfortunately
    have no reference, that it is also between impractical and impossible
    to "reset" an embedded interpreter by destroying and recreating an
    embedded instance. Finally, since Ruby does not use native threading,
    embedded scripts may not be properly discouraged from using broken
    threading constructs. All of these factors (plus regex licensing,
    last I heard) seem to strongly encourage extending over embedding.
    The biggest drawback would be the case where you wish to make multiple
    scripting interfaces/languages avaliable to your application.

    If your app supports Windows, COM is almost certainly your best
    option. I don't think there is anything else as elegant or effective.
     
    anon luker, Mar 1, 2004
    #6
  7. Eric Smith

    Dave Taylor Guest

    On Sun, 29 Feb 2004 15:12:23 +0100, shasckaw <> wrote:

    > Eric Smith wrote:
    >> I've written some simulators in C that use Tcl and custom commands as an
    >> embedded debugger language.
    >>
    >> Tcl works OK, but I don't like the language very well. It's simple, but
    >> not very elegant Ruby looks like a much better language.
    >>
    >> Is there any documentation or example code showing embedding Ruby in
    >> a C program? A Google search turns up some C++ stuff, but it didn't
    >> seem very helpful.
    >>
    >> Is it possible to create multiple independent Ruby interpreter contexts?
    >>
    >> Thanks,
    >> Eric
    >>
    >> [If you want to reply by private email, please remove the obvious
    >> spam-proofing from my email address.]

    > Have you tried Lua instead of Tcl? I've heard that even pythoners think
    > lua is better than python for embedding. I don't know if ruby can easily
    > be embedded, but I'm sure it's the case for Lua.
    >
    > Lio
    >


    Lua is very easy to embed into C... There is a few good tutorials on the
    subject (one of which I am writing).
    If your interested in the Lua route - go to
    http://lua-users.org/wiki/SimpleLuaApiExample for a simple example of
    embedding Lua in C.

    --
    Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
     
    Dave Taylor, Mar 1, 2004
    #7
  8. Eric Smith

    Laza Guest

    On 28 Feb 2004 09:42:13 -0800, Eric Smith
    <> wrote:
    > Is there any documentation or example code showing embedding Ruby in
    > a C program? A Google search turns up some C++ stuff, but it didn't
    > seem very helpful.


    Sure,

    All modern small scripting languages are made with provisions in mind to
    - extend the language with C code
    - embed the language in C code
    Start from the examples in the Ruby book:

    http://www.ruby-doc.org/docs/ruby-doc-bundle/ProgrammingRuby/book/ext_ruby.html#S6


    Also, note that you can use rubyscript2exe library to convert ruby apps
    into a self-extracting EXE that contains Ruby interpreter.

    --
    -Laza
    http://lazax.com/blog
    laza @ cs.columbia.edu
     
    Laza, May 13, 2004
    #8
    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.
Similar Threads
  1. =?Utf-8?B?SW1kYWQ=?=

    Embedding a Control in DataGrid

    =?Utf-8?B?SW1kYWQ=?=, Jan 24, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    599
    Patrick
    Jan 24, 2005
  2. Boris R.
    Replies:
    0
    Views:
    462
    Boris R.
    Oct 15, 2003
  3. David F. Skoll
    Replies:
    2
    Views:
    870
    David F. Skoll
    Nov 14, 2003
  4. Frank Iannarilli

    Embedding Perl into C: Why?

    Frank Iannarilli, Jun 2, 2004, in forum: Perl
    Replies:
    1
    Views:
    505
    Sean Lynch
    Jun 3, 2004
  5. Kris De Schutter

    embedding Perl

    Kris De Schutter, Aug 18, 2004, in forum: Perl
    Replies:
    1
    Views:
    486
    penguinista
    Aug 18, 2004
Loading...

Share This Page