Hi again
I managed to integrate Ruby into my game engine now, but i have got
the following problem, This should be a simple test C++ Class exported
to ruby:
#define RB_METHOD(func) ((VALUE (*) ())func)
#define RB_FINALIZER(func) ((void (*)(...))func)
class Simple
{
public:
void Log(const char * message ) { LogDebug(("%s ID:
%u",message,m_id)); }
static int id;
int m_id;
Simple() { m_id = id; id ++; LogDebug(("Constructing simple")); }
~Simple() { LogDebug(("Destructing simple")); }
};
int Simple::id = 0;
VALUE cFunc;
static void Simple_Delete(Simple * obj)
{
delete obj;
}
static VALUE Simple_New(VALUE self)
{
Simple * sObj = new Simple();
return Data_Wrap_Struct(cFunc,0,RB_FINALIZER(Simple_Delete),sObj);
}
static VALUE Simple_Log(VALUE self,VALUE string)
{
Simple * sObj = NULL;
Data_Get_Struct(self,class Simple,sObj);
sObj->Log(STR2CSTR(string));
return string;
}
static void RegisterSimple()
{
cFunc = rb_define_class("brutus",rb_cObject);
rb_define_method(cFunc,"log",RB_METHOD(Simple_Log),1);
rb_define_singleton_method(cFunc,"new",RB_METHOD(Simple_New),0);
}
But, a call to RegisterSimple crashes my progam....
I am using MSVC60, with teh mswin32-ruby16.dll all my modules are
linked the same as Ruby itself using Multithreaded DLL .... any ideas
on this one ?