Ruby 1.8.0 embedded

Hello,

I use ruby 1.8.0 embedded in a C++ application under Win2000. I use the
following piece of code:

int state=0;
ruby_init();
rb_load_protect(rb_new_str2(path),Qfalse,&state);
if (state != 0)
{
//error handling

}
ruby_cleanup(state);

If the ruby script is o.k. I have no problems, but if the ruby script has
an error (state not equal to 0) I get problems. The second time I call this
piece of code ruby crashes then.
Is there a bug in ruby_cleanup or shoul I use other functions?
Next question: is it possible to stop the ruby interpreter when
interpreting a script? How can this be done?
Another question: is it possible to “step” through a ruby script when ruby
is embedded?

Thanks,

Stefan Staudt

Dipl-Ing. Stefan Staudt

stefan.staudt@isw.uni-stuttgart.de
Tel: +49 (0)711 / 121-2462
Tel: +49 (0)711 / 121-2443 (SERCOS Competence Center)
FAX: +49 (0)711 121-2413

Institut fuer Steuerungstechnik der Werkzeugmaschinen
und Fertigungseinrichtungen (ISW)
Seidenstr. 36
D-70174 Stuttgart

If the ruby script is o.k. I have no problems, but if the ruby script has
an error (state not equal to 0) I get problems.

You are lucky

svg% cat test.c
#include "ruby.h"

static void
tt(char *path)
{
    int state = 0;

    ruby_init();
    ruby_init_loadpath();
    rb_load_protect(rb_str_new2(path), Qfalse, &state);
    if (state != 0) {
        VALUE err = rb_inspect(rb_gv_get("$!"));
        fprintf(stderr, "error %s\n", RSTRING(err)->ptr);
    }
    ruby_cleanup(state);
}

int main()
{
    tt("b.rb");
    tt("b.rb");
}
svg%

svg% cat b.rb
#!/usr/bin/ruby
p Object
svg%

svg% ./test
Object
error #<SystemStackError: stack level too deep>
Segmentation fault
svg%

Is there a bug in ruby_cleanup or shoul I use other functions?

ruby_init() and ruby_cleanup() don't do what you think.

Next question: is it possible to stop the ruby interpreter when
interpreting a script? How can this be done?

  use 2 threads

Another question: is it possible to "step" through a ruby script when ruby
is embedded?

Well, you can define a trace function.

Guy Decoux