From: Jason Roelofs Date: 2008-03-27T23:48:03+09:00 Subject: Re: embedding ruby (*not* extending) I'll expound on Stephan's post about Rice. Embedding Ruby with Rice is very easy: int main(int argc, char * argv[]) { Rice::VM vm(argc, argv); vm.run() } You've now got access to the Ruby VM in your application. You can use all of the normal Ruby C API calls, or you can use Rice's C++ API to get a hold of Ruby information. A couple of examples (not tested, may not be exactly correct): Calling your global (Kernel) method fact(): Ruby: def fact(a, b) ... end C++: int result = Module(rb_mKernel).call("fact", 1, 2); Or to get a hold of a class defined in your Ruby code Ruby: class MyClass .... end C++ // There's a better way to do this, I can't find it right now Rice:Class myClass = Class(Module(rb_mKernel).const_get("MyClass").call("new")); myClass.call("myFunc"); And when you need to expose C++ classes into Ruby, that's trivially easy (you've probably looked at luabind, it's similar): define_class("MyClass") .define_method("method_name", &ClassType::method); and in your Ruby you can now: m = MyClass.new m.method_name Hope that helps. If you give this library a try any questions you have can be sent to me, Paul Brannan (pbrannan@atdesk.com) or join #ruby-rice on freenode. Jason R. On Thu, Mar 27, 2008 at 9:46 AM, Marc Heiler wrote: > > There is just enough information on the first version of PickAxe to > > get you started. > > I think I disagree on this aspect. Getting started probably means very > sparse documentation, I just hope that people that are knowledgable > about it and did so, write a little bit about it. I even found some very > good blogs or entries therein explaining not-so-often-used tricks in the > Ruby-C land. ;-) > -- > Posted via http://www.ruby-forum.com/. > >