From: Daniel Harple Date: 2006-08-09T06:58:28+09:00 Subject: Re: Using C++ Member Function with rb_protect On Aug 8, 2006, at 5:34 PM, Mauricio Fernandez wrote: > 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): Thanks, I ended up with something similar. 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] = reinterpret_cast(this); args[1] = rb_str_new2(code); VALUE val = rb_protect(eval_protect, reinterpret_cast(args), &status); if (status) { } return val; } VALUE & sandbox() { return sandbox_; } private: VALUE sandbox_; static VALUE eval_protect(VALUE data) { VALUE *args = reinterpret_cast(data); return rb_funcall(reinterpret_cast(args[0])- >sandbox(), rb_intern("eval"), 1, args[1]); } }; -- Daniel