“Paul Brannan” pbrannan@atdesk.com wrote in message
news:20020725194932.O22783@atdesk.com…
I’m curious about this. I’ve embedded Ruby in more than a few
applications, and while it’s not simple (I have to worry about
exception-safety, for example, which isn’t an easy problem to begin
with), it’s certainly not “very difficult,” imo.
Can you describe what the tasks for Ruby where in these applications?
Some questions:
a) What problems come up when embedding Ruby make it “very difficult”?
As given below, lack of documentation, a not very cleanly interpreter state
and problems with thread-safety. But I would go with lack of docs and
examples as the main reason.
b) Would more documentation on the subject be helpful?
YES! Also, one or two simple example applications.
And answers to questions like
- what does ruby_run() do exactly? (without having to dive in the source to
get the answer)
- how do you get top-level objects, method, etc.
- how can you execute a Ruby script from a C/C++/other application (e.g. has
Ruby embedded in it), preferably a script precompiled to memory, and after
that transfers control back to the application
c) What do other languages (perl, python, scheme, etc.) do that make
embedding them into applications easier?
Well, the language that I love most when it comes to easy embedding is Lua.
The main reason is that the interpreter state is fully encapsulated in a
Lua-managed block of mem. Although you need to pass the pointer to this
state for every API call you do, there are no globals anywere and it makes
it a breeze to create another Lua-interpreter in memory. The two states
won’t bite each other because you always explicitly pass the interpreter
state you’re working with.
And I’m also not sure Ruby is ready for a threaded environment yet.
d) What else could Ruby do to make this task easier? Would a library
help?
Can you be a bit more specific on what kind of library and what it would do?
e) Has the author of this comment tried using SWIG? Did it make his
job easier or harder?
Use SWIG to do what? Generate interface definitions of my own programs?
That’s not very useful is it, I want to embed Ruby in my stuff, there is
no need for it to know anything the particular application I’m writing. The
Ruby API in the headers should be all that is necessary to do embedding.
Regards,
Paul