Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread


By: Jordi p
RE: Running C++ - Ruby callbacks [ reply ]  
2008-02-25 00:50

Sorry, I am so used to my program that surely I am not explaining well at all. I guess an example will be clearer.

C++ program starts
Simulator::Load read a XML world file and calls World::Load that load itself and calls to Model::Load for each model defined in the file.

Now, the first Model::Load reads its name "cool_humanoid" and its program "blinking.rb" (among other info), configure itself and load the ruby program (this program will be running as long as this Model exists).

Eventually the simulator will enter in its mainLoop that basically calls PhysicsEngine::Update

World::Update calls every Model::Update

And Model::Update must call an update method of their ruby scripts.

The blinking.rb will access to its "parent" model ("cool_humanoid") look for its eyes bodies and moved them as appropiate.

- I need to load ruby programs from C++ (easily done with ::VM)
- The ruby program must access to the running World object singleton or get as parameter a pointer to its Model (I prefer the first solution), I don't know how to do this.
- The C++ objects will need to call running Ruby objects. cool_humanoid will call to Update of its script. I also don't know how to do this.
- Ruby programs will need to call methods that use pointer to objects (pointing to the parent,etc.) I don't know how to use a pointer to an (running or no) object in ruby.

I hope these are not too basic questions...

By: Paul Brannan
RE: Running C++ - Ruby callbacks [ reply ]  
2008-02-24 21:37
Your questions is somewhat vague, so forgive me if I hit the wrong target on my first pass. Can you do something like this:

Object system = Class(rb_cObject).const_get("System");
char const * object_name = "some_name"
Object my_object ="[]", object_name);
std::cout <<"foo") << std:endl;

By: Jordi p
Running C++ - Ruby callbacks [ reply ]  
2008-02-22 12:03

I don't know if this is possible with current rice, I need to not only use C++ classes from Ruby but objects and the other way round.

I am working on a robots simulator.
C++ will call a Ruby method called Update(), this method will inspect the current status of several objects of the simulator, changing them when appropriate.

If I call Rice::VM I think I will be able to load any ruby script with any parameter.
These parameters will likely be simulator object names (strings) or pointer to objects.
But once VM is running it seems it is not possible to know what objects are running inside it. So I don't know how to call those Ruby methods.
Also, I will need sooner or later to access to running C++ objects (likely getting their pointers) from Ruby.

The Ruby program once initialized will run as long as the C++ program runs and the objects there are not suppossed to die (I can not just run the VM each time)