Embedding Ruby as a plugin (e.g. PhotoShop)

G

Glenn Lewis

I'm trying to embed Ruby as a plugin to a program called
Animation:Master (http://www.hash.com/). Everything compiles
and links without errors, and my plugin loads into A:M, and
my file requestor pops up for selecting which script I wish
to run through the Ruby interpreter.

After this, though, I can't seem to get Ruby to run.

If I try this:

int myargc = 2;
char* myargv[] = { "ruby", "c:/src/hi.rb", 0 };
ruby_init();
ruby_options(myargc, myargv);
ruby_run(); // - crash

the entire application crashes on the call to ruby_run.
If, however, I try this:

ruby_init();
ruby_script("embedded");
rb_load_file("c:/src/hi.rb");
ruby_run(); // - hangs

the entire application just hangs... I have to kill it myself.

Just to test out my sanity, I built a separate executable with
the above 2 snipits, and each of them worked fine as a stand-alone
program.

I've tried linking to C:\ruby\lib\msvcrt-ruby18.lib
as well as C:\ruby\lib\msvcrt-ruby18-static.lib
and they behave the same.

Can anyone think of what I might be doing wrong?
My e-mail address is: glenn at hometot periodcom
Thanks!
-- Glenn Lewis

P.S. Notice how Paint Shop Pro has a python plugin for it?
It would be cool if someone wrote a Ruby plugin for it. Thanks.
 
S

Simon Strandgaard

I'm trying to embed Ruby as a plugin to a program called
Animation:Master (http://www.hash.com/). Everything compiles
and links without errors, and my plugin loads into A:M, and
my file requestor pops up for selecting which script I wish
to run through the Ruby interpreter.

After this, though, I can't seem to get Ruby to run.

If I try this:

int myargc = 2;
char* myargv[] = { "ruby", "c:/src/hi.rb", 0 };
ruby_init();
ruby_options(myargc, myargv);
ruby_run(); // - crash

Watch out about "ruby_run()".. see:
http://www.rubygarden.org/ruby?RubyApi/RubyRun



the entire application crashes on the call to ruby_run.
If, however, I try this:

ruby_init();
ruby_script("embedded");
rb_load_file("c:/src/hi.rb");
ruby_run(); // - hangs

the entire application just hangs... I have to kill it myself.

Just to test out my sanity, I built a separate executable with
the above 2 snipits, and each of them worked fine as a stand-alone
program.

I've tried linking to C:\ruby\lib\msvcrt-ruby18.lib
as well as C:\ruby\lib\msvcrt-ruby18-static.lib
and they behave the same.

Can anyone think of what I might be doing wrong?
My e-mail address is: glenn at hometot periodcom
Thanks!
-- Glenn Lewis

P.S. Notice how Paint Shop Pro has a python plugin for it?
It would be cool if someone wrote a Ruby plugin for it. Thanks.

Great initiative. BTW: I recommend using SWIG as much as possible.



I have written a tutorial on how to embed Ruby into C++, its located here:
http://aeditor.rubyforge.org/ruby_cplusplus/index.html

First you will need to download this skeleton project, though:
http://raa.ruby-lang.org/list.rhtml?name=rubyembed
It works on unix... no idea if it works on Windows (many has downloaded
but nobody has yet submitted a windows-makefile, you are welcome).


Just ask if you have any trouble.
 
G

Glenn Lewis

What is the correct way to load a Ruby script into the
top-level namespace?

In other words, from within a script, I want to simulate
the behavior of having called the script on the command-line,
such as "ruby myscript.rb"... From within another script,
how do I load "myscript.rb" into the top-level namespace?

Thanks! (I couldn't find this by searching the RubyGarden
or the RubyWiki... sorry if this is a FAQ.)

-- Glenn Lewis
 
P

Phil Tomson

What is the correct way to load a Ruby script into the
top-level namespace?

In other words, from within a script, I want to simulate
the behavior of having called the script on the command-line,
such as "ruby myscript.rb"... From within another script,
how do I load "myscript.rb" into the top-level namespace?

Thanks! (I couldn't find this by searching the RubyGarden
or the RubyWiki... sorry if this is a FAQ.)

load should do what you want.

load "myscript.rb"

Phil
 

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,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top