From: Mauricio Fernandez Date: 2006-08-09T06:34:29+09:00 Subject: Re: Using C++ Member Function with rb_protect On Wed, Aug 09, 2006 at 05:57:53AM +0900, Daniel Harple wrote: > On Aug 8, 2006, at 4:45 PM, Francis Cianfrocca wrote: > > >What happens if you remove the & in this line: > > > >VALUE val = rb_protect(&Sandbox::eval_protect, > > I get this compile error: > > test.cpp: In member function ‘VALUE Sandbox::eval(char*)’: > test.cpp:15: error: argument of type ‘VALUE (Sandbox::)(VALUE)’ does > not match ‘VALUE (*)(VALUE)’ Of course it won't work that way, being a member function (it is given a reference to this too...). You'd have to do something like this (it's been a while without writing any C++, so take this with a grain of salt): class Sandbox { public: Sandbox() { sandbox_ = rb_funcall(rb_const_get(rb_cObject, rb_intern("Sandbox")), rb_intern("safe"), 0); } virtual ~Sandbox() { } VALUE eval(char * code) { int status = 0; VALUE args[2]; args[0] = (VALUE)this; args[1] = rb_str_new2(code); VALUE val = rb_protect(&call_eval_protect, (VALUE)args, &status); if (status) { /* handle error... */ } return val; } private: static VALUE call_eval_protect(VALUE args) { Sandbox *me = ((Sanbox *)args)[0]; VALUE code = ((VALUE *)args)[1]; return rb_funcall(me->sandbox_, rb_intern("eval"), 1, code); } VALUE sandbox_; }; -- Mauricio Fernandez - http://eigenclass.org - singular Ruby