From: jglueck@... (=?ISO-8859-1?Q?Bernhard_Gl=FCck?=) Date: 2001-09-23T11:42:17+09:00 Subject: [ruby-talk:21564] Returnin own C++ type from ruby method Hi there again! After having solved so many problems with ruby with the great help of this newsgroup, i think I'll have another question for you all. In my game engine there is a C++ Class called "Message" which is exported to ruby... No problem it works quite well, I can instantiate it and use it no problem at all...However now i have some "Messages" that are not created by ruby but the C++ side of my program (incoming from the network ) and I want to pass it to a ruby method ( since the object is already exported with all methods it should work ) however what is the correct way to do this ? My message export code looks like this: / ----------------------------------------------------------------------------- static void MessageDelete( MessagePtr * inst ) { delete inst; } // ----------------------------------------------------------------------------- static VALUE MessageNew( VALUE self ) { MessagePtr * inst = new MessagePtr(); *inst = MessageCreate( "Message" ); VALUE t = Data_Wrap_Struct(self,0,SE_DELETE(MessageDelete),inst); rb_obj_call_init(t, 0, NULL); return t; } void ScriptExporter::DefineMessage() { m_messageClass = rb_define_class_under( GetModule(),"Msg",rb_cObject); rb_define_singleton_method( m_messageClass,"new",SE_METHOD(MessageNew),0 ); rb_define_method( m_messageClass,"Add",SE_METHOD(MessageAdd),1 ); rb_define_method( m_messageClass,"Get",SE_METHOD(MessageGet),1 ); rb_define_method( m_messageClass,"From",SE_METHOD(MessageFrom),0 ); rb_define_method( m_messageClass,"Sent",SE_METHOD(MessageSendTime),0 ); rb_define_method( m_messageClass,"Receive",SE_METHOD(MessageReceiveTime),0 ); rb_define_method( m_messageClass,"To",SE_METHOD(MessageTo1),1 ); } Now how do i send a Message i get from the C++ side ( so it's already constructed to a a method ? I would like to have it somehow like that: VALUE MessageWrap( MessagePtr & ptr ) { // I have no clue how to implement this } void Message::SendToScript( VALUE object,MessagePtr & self ) { String callString = "On"; callString += m_msg; // Generated for the method ID callId = rb_intern( callString.Get() ); // Now create the parameter array for the call... Array args; // Wrap the message into a value args[0] = MessageWrap( self ); if ( rb_respond_to( object,callId ) ) { rb_funcall2( object,callId,args.Size(),args.Begin() ); } else { LogWarning(("Object does not respond to message")); } } Bye the way in Ruby 1.6.4 the rb_class2name method seems to have a bug.. It fails after 28 successive class with the same parameters,, just to let you know... Thanks in advance Bernhard Gl�ck