Ruby/C++ Interfaces
DescriptionThe C++ classes have to be interfaced to Ruby. I have already created an interface for the Color class. Here is some important information.
1. In the header of the file there is a definition for Ruby's Class instance. The naming convention (taken from the documentation) is rb_cCLASSNAME and rb_mMODULENAME. Like in the Color class, add an "extern VALUE NAME;" in the header and a "VALUE NAME;" in the source file. You will notice the rb_cColor variable.
2. Each class and module needs to have a "static void createRubyInterface()" method declared in the header and implemented. I have added this method for every RGSS class, you have to implement it.
3. You can find out all necessary calls here:
http://www.ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html#S84. Don't bother too much with methods that have default arguments or have overloaded definitions (meaning there are several functions with the same number, but different arguments). Just put the normal number of arguments there. I will take care of rewriting the code so it works with any number of arguments. Of course, if you want to learn a bit more, you can do that yourself anyway. I have already implemented Color::initialize and Color::set in that way.
5. Don't forget to use the conversion marcos like INT2NUM or rb_float_new if you define interfaces constants and class variables.
6. Every method HAS TO return a VALUE. If not actual value is returned in C++, then the return value is Qnil. Again. Refer to the Color class. The first Argument is "VALUE self" and that one is never counter when using interface definitions like rb_define_method. Just compare the actual methods and the interface definitions in Color.
7. You don't have to implement the methods. You just have to add the interface calls and edit the method declarations so they can work with Ruby.
8. All methods are static.
9. Be careful with getters and setters. For attr_reader, attr_writer and attr_accessor you can simply use something like "rb_define_attr(rb_cColor, "red", 1, 0);" where the 3rd argument sets read access (0 for no, 1 for yes) and the 4th argument sets write access (0 for no, 1 for yes). Basically using 1, 0 is attr_reader; 0, 1 is attr_writer and 1, 1 is attr_accessor.
PriorityCritical. Before this task is completed, not further development can be done.
PrerequisitesNone.
AssignedForeverZer0
game_guy
Ryex
Everything elseI have also interfaced Graphics and Input so you can get more examples there.
There are many classes, make sure you do them one by one and post here which are done so the others don't do your work as well.
Always refer to Graphics, Input and Color if you get stuck. If you still can't figure out how to do things, post. Since you all know Ruby, most things should be clear or you should at least be able to figure it out easily.