From: Bill Kelly Date: 2008-03-28T09:45:19+09:00 Subject: Re: embedding ruby (*not* extending) From: "John Smith" > > BTW: I am developing inside a cross-platform application. It uses: > > * Microsoft Visual Studion 2008 > * gcc - at least v3.3.3 (for Linux and MacOS) Hi, We embed ruby into a cross-platform application, as well. (MSVC 2003 on Windows, gcc 4.0.1 on OS X, at the moment.) The embedding code we use today is still very similar to what I posted a couple years ago here: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/178389 Looks like the main difference now is that we now longer call NtInitialize (our own program startup has already taken care of that stuff.) We also ship a subset of the ruby standard library with our app, as we don't want to depend on any particular version of ruby being preinstalled on the system. So we set up some include paths for ruby to point to the application-local stdlib. For ex: #ifdef PLATFORM_WINDOWS inc_path = PathOps::concat(application_path, "ruby/lib/ruby/1.8"); ruby_incpush(inc_path.c_str()); inc_path = PathOps::concat(application_path, "ruby/lib/ruby/1.8/i386-mswin32"); ruby_incpush(inc_path.c_str()); #endif #ifdef PLATFORM_MACOSX inc_path = PathOps::concat(application_path, "ruby/lib/ruby/1.8"); ruby_incpush(inc_path.c_str()); inc_path = PathOps::concat(application_path, "ruby/lib/ruby/1.8/powerpc-darwin8.3.0"); ruby_incpush(inc_path.c_str()); #endif Architecturally, we run ruby (1.8.4) on its own native thread, and communicate between the ruby thread and native application threads via a bridge (using boost::recursive_mutex and boost::condition.) (Actually the ruby side doesn't use boost::condition, but polls at about 10Hz. When we switch to ruby 1.9, we'll be able to eliminate the polling on the ruby side.) Be careful if you run ruby on a different thread than the main thread, as the default pthread stack size for threads other than the main thread is very small. We modified the boost thread library to specify a much larger stack size when creating threads on OS X. Hope this helps, Bill