I am too noob to embed an interpreter in my MSVC project. Plz denoob me

I’m trying to embed an interpreter in a DirectX project, so I’m using
MSVC. I grabbed the Ruby 1.9.3 source and compiled it with MSVC’s nmake
tool.

The make runs and ‘nmake test’ reports no problems. I then ‘nmake
install’ and the installed version seems to run acceptably. So I grab
the necessary files to embed and throw them into my project. I can
compile, but running the program gives nothing but segfaults.

Attached is a complete (very complete) explanation of the process I’m
using to create my segfault producer. Here’s the C code of the project
itself (this is just what I’m using to test embedding before I try
putting Ruby into the main project):

#include “ruby.h”
#pragma comment (lib, “msvcr90-ruby191.lib”)

int main() {
ruby_init();
char* options[] = {"", “test.rb”};
void* node = ruby_options(2, options);
return ruby_run_node(node);
}

If I build this in release mode and run it from the prompt I get a
detailed segfault message from Ruby. If I build in debug mode I just
get a ‘standard’ windows crash. The text of the Ruby error message is
at the bottom of the attached file.

So my question is basically, “What am I doing wrong here?”

I’m guessing it’s either something I’m not reconfiguring in MSVC or else
it’s just that my embed code is incorrect. Possibly there’s something
going wrong in the build of the lib file. Either way I’m running out
of hair to pull out. I’m working on this at home and the internet there
is on the blink, so I have to go elsewhere to get online and look for
solutions. Please help. Your advice may be the only thing that saves
what’s left of my hair.

Thank you. :slight_smile:

On Dec 19, 2011, at 17:24 , Khat H. wrote:

#include “ruby.h”
#pragma comment (lib, “msvcr90-ruby191.lib”)

int main() {
ruby_init();
char* options[] = {"", “test.rb”};
void* node = ruby_options(2, options);
return ruby_run_node(node);
}

Ruby’s main.c has the following:

ruby_sysinit(&argc, &argv);
{
    RUBY_INIT_STACK;
    ruby_init();
    return ruby_run_node(ruby_options(argc, argv));
}

so it looks like you’re missing RUBY_INIT_STACK and ruby_sysinit. The
latter looks like it has special code specific to windows tho I’m not
familiar with it.

I’ll give it another go round with those, but I think I tried that
before. If I remember correctly I had some kind of compiler problems
with RUBY_INIT_STACK. All of the embedding discussions I’ve seen poking
around google didn’t mention it so I figured it wasn’t used in
embedding. Anyway, I’ll try messing with that again. Thank you. :slight_smile:

Any further advice would be welcome, as I mentioned I have to collect
this information and then go back home and tinker with it away from the
internet, so I’d really like to get as much advice as possible before
returning to the secret-lab/stinky-bachelor-pad.

Awesome. I’ll take these docs back with me and see what I can get.
Thank you. :slight_smile:

Is there anyone who’s embedded Ruby under MSVC? I’m willing to go back
a few version numbers if I can get a silver bullet.

Khat H. писал 20.12.2011 08:23:

internet, so I’d really like to get as much advice as possible before
returning to the secret-lab/stinky-bachelor-pad.

You can see the workaround for RUBY_INIT_STACK I have in ColdRuby which
allows
it to be run not only in the stackframes directly under the one used to
call
ruby_init() here: [1].

You’re specifically interested in lines 30[2] (definition),
57[3] (initialization) and 163[4] (invocation).

1:
https://github.com/whitequark/coldruby/blob/master/libcoldruby/MRIRubyCompiler.cpp
2:
https://github.com/whitequark/coldruby/blob/master/libcoldruby/MRIRubyCompiler.cpp#L30
3:
https://github.com/whitequark/coldruby/blob/master/libcoldruby/MRIRubyCompiler.cpp#L57
4:
https://github.com/whitequark/coldruby/blob/master/libcoldruby/MRIRubyCompiler.cpp#L163

I got it running! :slight_smile:

ruby_sysinit() was what I needed. When I had tried it before I had
thought that it wasn’t working because when I ran the compiled exe from
the shell it seemed to be freezing. It wasn’t freezing, it was just
that I had provided no arguments so it had gone into line-by-line mode
just like it was supposed to.

My mastery of idiocy is nearly complete.
bows deeply

Anyway, if anyone is out there who’s looking to embed Ruby 1.9.3 in
Visual C++ 2008 the file attached to this post contains my main.cpp,
which shows how I’m doing it.

Thank you everyone for your help. Now that I’ve got the interpreter
running I can seek out and explore new and more interesting problems and
errors! Seriously though, this has been the sticking point in the
project for a long time now and now it’s working. I’ve been coding like
mad the past few days and several of my core modules are already up and
running. Thank you!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs