D
Daniel Harple
I'm having problems using a C++ member function with rb_protect. Here =20=
is the code:
class Sandbox {
public:
Sandbox() {
sandbox_ =3D rb_funcall(rb_const_get(rb_cObject, rb_intern=20
("Sandbox")),
rb_intern("safe"),
0);
}
virtual ~Sandbox() {
}
VALUE eval(char * code) {
int status =3D 0;
VALUE val =3D rb_protect(&Sandbox::eval_protect,
rb_str_new2(code),
&status);
if (status) { /* handle error... */ }
return val;
}
private:
VALUE eval_protect(VALUE code) {
return rb_funcall(sandbox_, rb_intern("eval"), 1, code);
}
VALUE sandbox_;
};
The compile fails with:
test.cpp: In member function =91VALUE Sandbox::eval(char*)=92:
test.cpp:18: error: cannot convert =91VALUE (Sandbox::*)(VALUE)=92 to =20=
=91VALUE (*)(VALUE)=92 for argument =911=92 to =91VALUE rb_protect(VALUE =
(*)=20
(VALUE), VALUE, int*)=92
$ ruby1.8 -v
ruby 1.8.5 (2006-08-06) [powerpc-darwin8.7.0]
$ g++ --version
powerpc-apple-darwin8-g++-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. =20
build 5341)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There =20
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR =20
PURPOSE.
Any ideas?
Thanks,
-- Daniel
is the code:
class Sandbox {
public:
Sandbox() {
sandbox_ =3D rb_funcall(rb_const_get(rb_cObject, rb_intern=20
("Sandbox")),
rb_intern("safe"),
0);
}
virtual ~Sandbox() {
}
VALUE eval(char * code) {
int status =3D 0;
VALUE val =3D rb_protect(&Sandbox::eval_protect,
rb_str_new2(code),
&status);
if (status) { /* handle error... */ }
return val;
}
private:
VALUE eval_protect(VALUE code) {
return rb_funcall(sandbox_, rb_intern("eval"), 1, code);
}
VALUE sandbox_;
};
The compile fails with:
test.cpp: In member function =91VALUE Sandbox::eval(char*)=92:
test.cpp:18: error: cannot convert =91VALUE (Sandbox::*)(VALUE)=92 to =20=
=91VALUE (*)(VALUE)=92 for argument =911=92 to =91VALUE rb_protect(VALUE =
(*)=20
(VALUE), VALUE, int*)=92
$ ruby1.8 -v
ruby 1.8.5 (2006-08-06) [powerpc-darwin8.7.0]
$ g++ --version
powerpc-apple-darwin8-g++-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. =20
build 5341)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There =20
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR =20
PURPOSE.
Any ideas?
Thanks,
-- Daniel