Ruby support
Hi,
I'm investigating a little about how could I create a breve plugin (or whatever is needed to accomplish this) so I can program in Ruby instead of Steve. I don't know if this is what it is called a "frontend language" because I get confused sometimes when I see examples of Steve code using calling other languages like Java, which I'm not interested in. I just wan't to write simulations in Ruby.
The documentation on how to do this is a little confusing. I tried looking around for the python support (which I think has the same intentions as I describe), but I still don't get how to accomplish this.
Could someone provide me a little guide on where to start? I have experience on using SWIG to glue ruby and C++, maybe this would help.
Thank you,
Matt.
- Login to post comments

follow the Python example in the current source
If you've been looking at the 2.4 source, you should switch to the latest Subversion source instead. The API has changed a bit since then, and support for Python is well on its way. All of the fundamentals are working in the latest Subversion source, and it's relatively little code (all in the Python directory). Specifically, look at the file python/python.cc.
Please post here if you have any other questions.
- jon
Ok, I'm getting it a litte
Ok, I'm getting it a litte more now. A few questions:
a) If I want a command line program that can be called like this: breve-ruby I need to create my own frontend application, right? The provided 'breve' application is just for loading Steve code (and the python support can be used from a Steve script, but not directly like I want with Ruby) as I see.
b) I actually need to create a different executable (I mean, not use bin/breve.cc), right? In the Makefiles I see that it is kind off assumed that Steve's frontend will be used. I couldn't find the LANGUAGE_FRONTEND_LIBRARY variable, as stated on the documentation.
c) Do I need to create classes in ruby that map to breve's objects (like controller, and such)? I mean, I imagine so, if I would like to create Controller objects in Ruby.
d) What could should I download and compile? 2.5b2? SVN?
So to sum it up, I would need to:
* Create a separate executable which would do similar things to bin/breve.cc
* Create a ruby language frontend and call this from the executable
* On the frontend, create a Ruby interpreter instance and implement the callbacks required by breve
The last part seems to be the most difficult.
Thanks for the help (and of course, breve),
Matt.
Even easier...
Actually, as part of some planned changes to the language frontend API, this whole process will get much easier -- you WON'T need to create a different executable. I haven't finished this aspect of the API yet, but I will soon.
The way it will work:
So with that in mind, the answers will be:
a) Ignore the seperate frontend -- it won't be neccessary.
b) Same deal -- you'll use the existing executables
c) Short answer: yes, you'll need to port the steve classes to Ruby. This is the best option.
Longer answer: strictly speaking, you don't have to, or you don't have to port them all. If you implement "bridging" to steve objects, then you won't have to reimplement the objects in Ruby -- you can just create and use "bridged" steve objects. If you look at the PythonTest.py file in the source, for example, you'll see that it creates a bridge instance of the steve class "Movie".
d) Download the SVN source and start from there.
So to simplify your summary:
* Just make the Ruby interpreter instance, callbacks and class files -- the rest will be taken care of.
- jon
Great, thanks. I will start
Great, thanks.
I will start on the common aspect of both approaches (the part of the Ruby interpreter and such).
Looking forward to see the new version,
Matt.
Actually, I have another
Actually, I have another question.
One thing I don't understand fully is what are the findMethod/findObject for. I mean, If I'm creating a Ruby interpreter instance under which I somehow create classes that map to breve classes and then, your application parses a ruby script which contains the simulation, why does (I mean, where in this process) does breve need to find Ruby methods/objects by name? I'm guessing this is for when I want to create a Steve script that calls Ruby code (for example). Since I'm not interested on the latter, would it suffice to go the other way around?
By this I mean to not let breve be an active app that calls ruby code, but to define a Ruby extension that lets an active ruby interpreter instance (like the command line 'ruby' executable) and a script in ruby, to call breve's functions.
Is this possible? I think it would make things a lot easier.
Matt.
Used for callbacks
Even if you don't want the steve <=> Ruby "bridging", findObject and findMethod will still be required for callbacks. When the breve engine triggers an event via collision, iterate or user interaction (or any number of other things), it will need to do a method lookup. The object lookup is used less, but I'm still not sure it can be eliminated altogether, so it's probably best to include it.
- jon
More questions
And I'm still going on... sorry for taking your time.
Ok, I will implement that then. But, just so I understand, under what circumstances will breve call the instantiate method? I looked inside the code and I could only find one reference to this method: brObjectInstantiate, and this will only call instantiate on Steve code.
I imagine the creation of instances of breve's Objects (like Real and such) from within the Ruby code itself (using some subclassing, similar to what the Python code does). But I saw that the Python definition for the 'instantiate' method increases references to the object (but doesn't create it, for the reasons recently explained).
I have a similar doubt regarding findMethod. Since in Ruby I can't retrieve local variables (only instance, and global variables) I need to know which variables will be search with this method. If I create an object on Ruby and tell breve that this is a new instance of a Real object (for example), doesn't breve know about this object now? Why does it need to be looked up by name?
EDIT: well, after looking at the code, it all got much clearer. Just one thing: I saw that before adding an object instance to breve I have to "define the object" (which I take to be something like a class definition). It is really hard for me to tell if I should call the brEngineAddObject (before the brEngineAddInstance) or not. Is there a way to check if the object is already defined? (I could look inside engine->objects, but that seems to be poking in the implementation.
Thank you,
Matt
The instantiate callback is
The instantiate callback is used to handle object bridging as well. This lets steve (for example) create Python objects using the same exact syntax as for creating steve objects. The user does not have to know that they are using the object bridge.
I'm not sure I understand what you say about the Python instantiate not creating the object: Python's instantiate DOES create the object (the "PyObject_Call" line is what does this).
All objects added to the breve engine MUST have a brObject defined using brEngineAddObject. The brObject tells the breve engine what language the object is and how it interacts with other objects. If you want an object to be added to the engine, you'll need to make sure brEngineAddObject has been defined.
In your frontend data, you can keep a dictionary mapping class name to brObject. If no brObject exists for a new object being created, then you can call brEngineAddObject.
- jon
Hi, again
I've written some more code taking the python support as an example. I have some further questions:
a) I've wanted to implement the isSubclass callback, but I don't know what are the pointers it receives. I couldn't take the python code as an example since that is not implemented.
b) Regarding the object hierarchy that will get constructed on Ruby side, how much does breve need/wants to know about it? I mean, suppose that I have ruby classes class A,B (which could be any class that breve doesn't care about) and classes BreveReal and BreveObject (on ruby, which represent breve's Real and Object classes, respectively) and let '<' denote 'is subclass of'. Then, suppose that A < B < BreveReal < BreveObject and I have an instance of A, do I need to create A, B, BreveReal and BreveObject classes in breve? Or does breve just need to know about the BreveReal and BreveObject (where all collision handlers and such are actually installed, but A might override them or not)?
Thanks again for your help, with any luck I can get this working.
Matt
Sorry for the delayed
Sorry for the delayed response here.
The isSubclass callback gets the object user data pointers for both classes as returned by the "findObject" callback.
breve only needs to know about a class if it is can be directly instantiated in breve and added to the breve engine. So BreveReal and BreveObject should probably exist, but A and B are probably not necessary.
- jon
ruby working...?
v01d,
Did you get your Ruby stuff working? I'd be interested in it if you did.
Cheers,
Steve
Hi, I got interested again
Hi, I got interested again in continuing a little work on this. I have a basic but functional version working. You can browse the code (and test it) at svn://v01d.com.ar/breve-ruby .
test.rb simply creates 10 mobile agents which have something like a flocking behaviour
test-collision.rb: tests physics a little
I still have to continue porting all of steve code (class definitions) to ruby, but it isn't very hard.
Matt
this is fantastic
This is fantastic. Ruby is my crack, er, code of choice these days and this would really be a great thing for me.
I'll check out your code when I get a chance.
C++ N00b
I downloaded your code but I'm not sure how to go about compiling and using it on OS X (I'm a complete C++ N00b).
Can you give me a push in the right direction?
You can email me at my username @yahoo.com
Thanks.
Steve
It requires a little
It requires a little knowledge of C++ and breve, since you need to compile the library (just do "make") but also you need to modify breve sources and recompile.
It requires a little
It requires a little knowledge of C++ and breve, since you need to compile the library (just do "make") but also you need to modify breve sources and recompile.
bummer
Bummer...so close, yet so far.
If anyone else is still
If anyone else is still interested, I set up a public website with some information on how to compile and test: http://breve-ruby.googlecode.com
PS: Is breve still maintained? I couldn't see any activity from the author.
this is great
The subject says it all. I look forward to checking this out. I couldn't quite make heads or tails of the stuff you sent me before...although I really appreciated it.
Cheers,
Steve
PS - I hope Breve is still being maintained.
This sites has really nice
This sites has really nice information which shows nice efforts of the author. If u are a student & are looking to get good marks in certification then you can get guideline & also reliable study materiel from
Exam Killer as well on a single click