You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would it be possible to add the ability to bind a member function? There is
already the ability for a c function like:
m->set( "c_function", SLB::FuncCall::create(c_function));
But could we have something like:
struct Foo
{
int Bar(int a, int b) { return a*b; }
};
Foo f;
m->set( "Bar", SLB::FuncCall::create(Foo::Bar), &f);
Original issue reported on code.google.com by [email protected] on 16 Feb 2012 at 4:51
The text was updated successfully, but these errors were encountered:
I will consider it but there the problem of how SLB should treat the memory of
object "f", for example:
{
Foo f;
m->set("Bar", ... , &f);
}
after the block f is no longer a valid pointer... but this, can lead to memory
leaks:
{
Foo *f = new Foo();
m->set("Bar", ... , &f);
}
So, in the end its better to wrap Foo class with SLB and make some sort of
wrapper around a given object instead. I will consider how to do it, but if you
have any insight about the management of the memory it would be great to know.
It is a tricky problem. I think the only options are to force the user to make
sure they don't do silly things like that and hope they manage their memory
correctly, OR do something like you have mentioned and have a wrapper that SLB
uses to manage the lifetime of the object. The user then might do something
like (if they wanted to manually remove the binding and clean the memory being
used):
m->unset("Bar");
However, this doesn't stop them from doing silly things like this:
{
Foo *f = new Foo();
m->set("Bar", ... , &f);
delete f;
m->unset("Bar"); // potential crash
}
I don't think this is a major concern though as the user should still be
responsible for overall management.
In any case, I think adding member function support would be really useful
feature. I just moved over to SLB from luabind and I'm really liking it. The
member function ability is the only thing I feel it is lacking at the moment.
Nice work so far!
Original issue reported on code.google.com by
[email protected]
on 16 Feb 2012 at 4:51The text was updated successfully, but these errors were encountered: