Forum: Ruby How to use Ruby interpreter as Windows DLL library?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Stanislav S. (Guest)
on 2006-02-04 13:53
I have an idea (program, that uses Ruby interpreter). And I dont know
how to use Ruby interpreter in my program. I looking for manuals (but I
dont know English very well and I cannot find information about this) or
ideas how can I do this. If you can, please, write: is it possible to
use Ruby as DLL in my program?  How can I call interpreter functions and
how can I set (and get) variables values. And is correct to use Ruby as
DLL in commercial program?
Russian programmer :)
Stanislav S. (Guest)
on 2006-02-04 13:55
Oh... Calling from C/C++... Windows XP platform.
Dean W. (Guest)
on 2006-02-04 19:48
(Received via mailing list)
I don't know if this helps, but RubyScript2Exe

  http://www.erikveen.dds.nl/rubyscript2exe/index.html

is a great tool for converting your ruby scripts into a standalone
windows executable, including an embedded Ruby interpreter and all the
required libraries. I'm using it for running Ruby as part of an
application installer where I don't expect the user to have Ruby
installed already.

The only drawback I've seen is that the exe's tend to be large, even
for small scripts (~1 MB). Not an issue for me, however.

dean

On 2/4/06, Stanislav S. <removed_email_address@domain.invalid> wrote:
> Oh... Calling from C/C++... Windows XP platform.
>
> --
> Posted via http://www.ruby-forum.com/.
>
>


--
Dean W.
http://www.aspectprogramming.com
http://www.newaspects.com
http://www.contract4j.org
Bill K. (Guest)
on 2006-02-04 22:14
(Received via mailing list)
Hi,

From: "Stanislav S." <removed_email_address@domain.invalid>
>
>I have an idea (program, that uses Ruby interpreter). And I dont know
> how to use Ruby interpreter in my program. I looking for manuals (but I
> dont know English very well and I cannot find information about this) or
> ideas how can I do this. If you can, please, write: is it possible to
> use Ruby as DLL in my program?  How can I call interpreter functions and
> how can I set (and get) variables values. And is correct to use Ruby as
> DLL in commercial program?
> Russian programmer :)

Here's some very basic code to load and run a ruby script from C/C++

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#ifdef _WIN32
  // ruby win32 init
  int argc = 0;
  char **argv = 0;
  NtInitialize(&argc, &argv);
#endif

  ruby_init();
  ruby_script("embedded");

  // TODO - rb_str_new2 could call ruby_raise if out of memory, so we
should
  // catch that possible exception here
  //
  int status;
  rb_load_protect(rb_str_new2("ruby-program.rb"), 0, &status);
  if (status == 0) {
    int state = ruby_exec();
  }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

See the README.EXT file in your Ruby installation for more info.

See also: http://metaeditor.sourceforge.net/embed/ for much more
sophisticated
examples...


Hope this helps,

Regards,

Bill
Stanislav S. (Guest)
on 2006-02-04 22:21
Bill K. wrote:
> Hi,
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> See the README.EXT file in your Ruby installation for more info.
>
> See also: http://metaeditor.sourceforge.net/embed/ for much more
> sophisticated
> examples...
>
>
> Hope this helps,
>
> Regards,
>
> Bill

Thanks a lot for your way!!! Thanks!  Thanks!  Thanks! =)
This topic is locked and can not be replied to.