So, thanks to the wonderfull work of Wannabe && FenixFyreX, the RPG Maker Community is now able to benefit from loading .so files into the maker directly.
Alot (perhaps most) of you may be thinking "what the hell is a .so file?", so here is a short explanation from my understanding;
A .so file is essentially the same as a .dll file, with one major exception... Rather than being called each time its required via some API call, the .so is able to implant new methods into the ruby (RGSS) environment directly.
Consider the following...
# Ruby Codedef some_method(value) return value >= 100 ? true : falseend# End Ruby CodeThis simple method checks if the value passed as argument 1 is greater or equal to the value of 100. if yes, it returns true and false otherwise.
Now what if we wanted to write this method in C? There are many reasons for why you may wish to do such a thing, performance being the most common, but I'm not really going into that...
Normally, we would have had to do something like this..
# Ruby Codedef some_method(value) @method_api ||= Win32API.new('DllName','FunctionName','i','i') return @method_api.call(value) != 0 ? true : falseend# End Ruby Code
As you can see, this is fairly pointless. Its likely that performance would actually be lost in such a transition; however, if we where able to perform even more of the code on the C side of things (ideally all of it), it could potentially become far superior..
An Example of a much faster way to write such a function within a .so file:
// C Code#include "ruby.h" VALUE FunctionName(VALUE self,VALUE ruby_value){ return NUM2INT(ruby_value) >= 100 ? Qtrue : Qfalse;} VALUE rb_DEKModule = Qnil; void Init_Tutorial(){ rb_DEKModule = rb_define_module("DEK"); rb_define_singleton_method(rb_DEKModule, "function_name", FunctionName, 1);}// End C CodeThe end result of this code is almost identical to using the above Ruby + dll. ie - the ruby method function_name calls the C method FunctionName when called.
So, I wrote a tutorial on how to bring the ability to load a .so into your rpg maker projects. This tutorial can be found HERE.
Annd.. Here is a link to a demo containing a working Tutorial.so file.
Any questions ??
Alot (perhaps most) of you may be thinking "what the hell is a .so file?", so here is a short explanation from my understanding;
A .so file is essentially the same as a .dll file, with one major exception... Rather than being called each time its required via some API call, the .so is able to implant new methods into the ruby (RGSS) environment directly.
Consider the following...
# Ruby Codedef some_method(value) return value >= 100 ? true : falseend# End Ruby CodeThis simple method checks if the value passed as argument 1 is greater or equal to the value of 100. if yes, it returns true and false otherwise.
Now what if we wanted to write this method in C? There are many reasons for why you may wish to do such a thing, performance being the most common, but I'm not really going into that...
Normally, we would have had to do something like this..
# Ruby Codedef some_method(value) @method_api ||= Win32API.new('DllName','FunctionName','i','i') return @method_api.call(value) != 0 ? true : falseend# End Ruby Code
Code:
// C Codeint FunctionName(int value){ if (value >= 100) { return 1; } return 0;}// End C Code
An Example of a much faster way to write such a function within a .so file:
// C Code#include "ruby.h" VALUE FunctionName(VALUE self,VALUE ruby_value){ return NUM2INT(ruby_value) >= 100 ? Qtrue : Qfalse;} VALUE rb_DEKModule = Qnil; void Init_Tutorial(){ rb_DEKModule = rb_define_module("DEK"); rb_define_singleton_method(rb_DEKModule, "function_name", FunctionName, 1);}// End C CodeThe end result of this code is almost identical to using the above Ruby + dll. ie - the ruby method function_name calls the C method FunctionName when called.
So, I wrote a tutorial on how to bring the ability to load a .so into your rpg maker projects. This tutorial can be found HERE.
Annd.. Here is a link to a demo containing a working Tutorial.so file.
Any questions ??
Last edited by a moderator:
