From: ts Date: 2001-09-01T02:15:18+09:00 Subject: [ruby-talk:20634] Re: Calling class member functions from C++ >>>>> "B" == =?ISO-8859-1?Q?Bernhard Gl=FCck?= writes: [...] B> class SpaceShip < Mesh B> def OnDoSomething ( dummy ) B> Log("Just a dummy log output") B> end B> end B> m = SpaceShip.new() B> AddToGame( m ) [...] B> Of particular interest should be the obj->linkScriptClass call where B> the self VALUE is stored.... shouldn't the self VALUE be a handle to B> the SpaceShip class B> instance when used in the code above ? Well difficult to reply without seeing completely the code. Apparently the self VALUE is SpaceShip B> static VALUE cname##New( VALUE self ) \ B> { \ B> ObjectPtr * inst = new ObjectPtr(); \ B> *inst = Factory()->CreateObject(#cname); \ B> VALUE t = Data_Wrap_Struct(self,0,SE_DELETE(cname##Delete),inst); \ B> rb_obj_call_init(t, 0, NULL); \ B> Object * obj = inst->Get(); \ obj-> LinkScriptClass( self ); \ B> return t; \ B> } \ B> And when I try to call the SpaceShip method it crashes all the time, I B> am doing so B> In the upper cases m_msg contains "DoSomething" B> and val is the VALUE stored in the above procedure ( the C++ Ruby B> "Constructor" ) if `val' is `self' of the above procedure then it's SpaceShip B> String callString = "On"; B> callString += m_msg; B> // Generated for the method B> ID callId = rb_intern( callString ); B> // Now create the parameter array for the call... B> Array args; B> // And make the script call B> rb_funcall2_protect( val,callId,args.Size(),args.Begin() ); Here you are calling the class method SpaceShift::OnDoSomething and not the instance method SpaceShift#OnDoSomething Guy Decoux