Just a few comments...

jglueck / vol.at (Bernhard Glk) writes:

> 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)

In C, an empty parameter list is not the same as in C++, and so you
need the ... in here.  It should be:

#define RB_METHOD(func) ((VALUE (*) (...))func)

Otherwise you're casting it to the wrong type of function pointer.
I'm not sure if this is related to your crash or not, however.  (I
don't use your compiler, and it's undefined behavior.)  In reality,
I think casting a function pointer to one taking ... is also
undefined, but it works everywhere due to the fact that each item in
the VA_ARG is the same size as a VALUE. 

> void Log(const char * message ) { LogDebug(("%s ID:
> %u",message,m_id)); }

Your format flag is wrong.  m_id is an int, you want %d.

> 	static VALUE Simple_New(VALUE self)

If you're getting a warning for unused parameter, remove 'self' from
the parameter list.  That way the VALUE is an unnamed parameter,
indicating you don't intend to actually make use of that argument.

>{
>	Simple * sObj = new Simple();
>	return Data_Wrap_Struct(cFunc,0,RB_FINALIZER(Simple_Delete),sObj);
> 	}

Just a note... there is a severe difficulty in writing ruby extensions
in C++ due to ruby exceptions using longjmp.  If, for example the
allocation of the ruby object (in Data_Wrap_Struct) fails, it throws a
ruby exception, then you leak your Simple object.  Even if you put
your simple object in an auto_ptr, it would still leak, because the
auto_ptr would not be destroyed.  (And whenever a local variable has a
destructor that needs to be called is skipped due to longjmp (which
happens all the time in Ruby extensions, due to ruby throwing
"exceptions") your program is undefined.  I've been struggling with
this for a while, and so far haven't found any satifactory solutions.
I'm still trying to come up with some, however.

> 	static VALUE Simple_Log(VALUE self,VALUE string)

'string' is a poor variable name, since the C++ standard library
defines 'string' already.  While it's in the std namespace, many
compilers don't quite get namespaces right, and many programmers hoist
the std namespace into the global namespace anyway.

>{
>	Simple * sObj = NULL;
>	Data_Get_Struct(self,class Simple,sObj);

Small nitpick, but assigning NULL to sObj is a wasted operation,
because you immediately overwrite that NULL value in the
Data_Get_Struct macro.  

>       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);
>}

I don't see anything wrong in RegisterSimple, once the macro is
fixed.  (I know far less about Ruby than I do about C++ though, so I
may easily be overlooking something.)

Hope this helps.
-- 
Chris