I’m trying to make an interface between PhysX and Ruby and I got stucked
on the very beggining. XD
I have an NxPhysicsSDK pointer, pointing to an object (duh) and I would
like to store this pointer into an Ruby VALUE object. I don’t really
need to see it’s value outside the extension class (being clear:
everything would be encapsulated), but I only find conversions from C
pointers, not C++ objects.
Does anyone have a tip?
You need to either build your own C wrapper around the C++ and expose
that
in Ruby as you cannot just map C++ objects to Ruby’s C-API.
Or you use a tool like Rice ( http://rice.rubyforge.org ) or SWIG to
wrap
the C++ into Ruby.
I would also recommend looking into Rb++ (
http://rbplusplus.rubyforge.org )
which IMO (though slightly biased) is easier to deal with than SWIG.
Jason
On Thu, Dec 17, 2009 at 10:42 AM, Yuri Albuquerque
Well, I installed Rice’s gem and when I try to run my extconf.rb it
returns:
extconf.rb:1:in `require’: no such file to load – mkmf-rice (LoadError)
from extconf.rb:1
For some reason, Ruby is not finding this file.
I’ll try with Rb++ and see what I get.
Yuri Albuquerque wrote:
Well, I installed Rice’s gem and when I try to run my extconf.rb it
returns:
extconf.rb:1:in `require’: no such file to load – mkmf-rice (LoadError)
from extconf.rb:1
For some reason, Ruby is not finding this file.
I’ll try with Rb++ and see what I get.
Forget it. I forgot to include require ‘rubygems’ on my extconf.rb
Thank you.
But I’ll still try Rb++, too. ^^
Well, I have two new doubts:
1 - When an object is created on PhysX, it’s not directly with a
constructor. For example, if I want to create an NxPhysicsSDK object, I
have to do this:
NxPhysicsSDK *sdk = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, 0, 0);
What do I have to do to convert this on an initialize method on Rice?
2 - If I try to use Rb++, it asks for a namespace. PhysX does not use
namespaces. What should I do in this case? Ignore this step?
Yuri Albuquerque wrote:
I’m trying to make an interface between PhysX and Ruby and I got stucked
on the very beggining. XD
I have an NxPhysicsSDK pointer, pointing to an object (duh) and I would
like to store this pointer into an Ruby VALUE object. I don’t really
need to see it’s value outside the extension class (being clear:
everything would be encapsulated), but I only find conversions from C
pointers, not C++ objects.
theoretically you should be able to store a struct in a ruby object that
can contain pointers to anything.
is an example project that has pointers to a C++ object [a google hash
map].
The trick is wrapping all your ruby code in an extern “C” { } block.
GL.
-r
Roger P. wrote:
theoretically you should be able to store a struct in a ruby object that
can contain pointers to anything.
GitHub - rdp/google_hash: wrapper for google's hash functions, for ruby
is an example project that has pointers to a C++ object [a google hash
map].
The trick is wrapping all your ruby code in an extern “C” { } block.
GL.
-r
Thanks to your tip, I am very closer to what I want to do than ever. I
didn’t needed to make any gluecode between C and C++, I’m writing
directly gluecode between Ruby and C++.
Thank you very much.