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

Discussion in 'Ruby' started by Glenn Lewis, Jan 1, 2004.

  1. Glenn Lewis

    Glenn Lewis Guest

    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.
     
    Glenn Lewis, Jan 1, 2004
    #1
    1. Advertising

  2. On Thu, 01 Jan 2004 09:47:41 +0900, Glenn Lewis wrote:

    > 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.

    --
    Simon Strandgaard
     
    Simon Strandgaard, Jan 3, 2004
    #2
    1. Advertising

  3. Glenn Lewis

    Glenn Lewis Guest

    Loading a script in the top-level namespace?

    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
     
    Glenn Lewis, Jan 6, 2004
    #3
  4. Glenn Lewis

    Phil Tomson Guest

    Re: Loading a script in the top-level namespace?

    In article <>,
    Glenn Lewis <> wrote:
    >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
     
    Phil Tomson, Jan 6, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PilotYid
    Replies:
    1
    Views:
    631
    Andrew Thompson
    Oct 31, 2005
  2. Marcin Cenkier
    Replies:
    1
    Views:
    5,428
    Marcin Cenkier
    Apr 12, 2006
  3. Svein Brekke

    photoshop plugin from Python script

    Svein Brekke, Sep 28, 2004, in forum: Python
    Replies:
    0
    Views:
    433
    Svein Brekke
    Sep 28, 2004
  4. Jimmy
    Replies:
    0
    Views:
    513
    Jimmy
    Mar 15, 2007
  5. Tobias Grimm

    Embedding Ruby as plugin

    Tobias Grimm, Aug 16, 2004, in forum: Ruby
    Replies:
    4
    Views:
    102
    Tobias Grimm
    Aug 17, 2004
Loading...

Share This Page