embedding?

E

Eric Smith

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.]
 
M

Mark Hubbart

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

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
 
C

Chad Fowler

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).
 
S

shasckaw

Eric said:
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
 
E

Eric Smith

shasckaw said:
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 just discovered the "Extending Ruby" chapter of "Programming Ruby",
and it seems to have the information I was looking for.

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

anon luker

Eric Smith said:
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.
 
D

Dave Taylor

Eric said:
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.
 
L

Laza

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top