Hi,
In message "[ruby-talk:00839] Ruby as an extension language ?"
on 99/10/03, Artur Matos <ei96024 / fe.up.pt> writes:
| I'm looking for an extension language (aka a macro language) for
|a large program i'm developing. After seeing some alternatives, I think
|Ruby could make a nice extension language for my program.
Quite possibly.
| The problem is I don't find specific information for using
|Ruby this way, only as a standalone scripting language. Is
|it possible to use Ruby as an extension language ? If it is, I would like
|to know how :
|
| - to embeb the ruby interpreter in my program.
| - to interface ruby with C/C++ calls. (specialy
|C++, as my program is written in C++)
Did you check out README.EXT file in the distribution?
Hope that helps, especially for the latter.
To embed the interpreter, First, you need to initialize the
interpreter by calling:
ruby_init();
And then invoke the interpreter by calling
rb_eval_string(str);
or
rb_eval_string_protect(str, &status);
rb_eval_string_protect() does not jump out by the exception. if the
exception raised it set the status variable to non-zero. So you don't
have to protect against any global exits.
Because Ruby is written in C, you have to declare the prototypes of
the Ruby calling functions within `extern "C"'.
matz.