These are chat archives for ChaiScript/ChaiScript

6th
Sep 2015
Phil Cooper-King
@PhilCK
Sep 06 2015 07:47
Hello is it possible to pass class instance callbacks? add_callback(MyClass::on_callback); type thing? I get incomplele function call, which I assume is down the the need to pass this.
Jason Turner
@lefticus
Sep 06 2015 16:02
you could do something like: chai.add(chaiscript::fun([&obj]() { obj.on_callback(); }), "my_callback")) if you want to pass a bound member object function
Phil Cooper-King
@PhilCK
Sep 06 2015 16:49

I'm not sure I understand. That would be a callback from chai to c++ correct? Rather than c++ to chai.

I currently have callbacks exposed as a client operation in chai.

def Foo::Foo()
{
   self.set_collision_callback(collision_cb);
}

and I was wondering if its possible to set a member function from chai.

def Foo::Foo()
{
   self.set_collision_callback(Foo::on_collision);
}

The first method is good enough just wondered if I could do it to a member function.

Jason Turner
@lefticus
Sep 06 2015 18:32

Right, so if I understand correctly, you could do the same thing, just from the ChaiScript side:

self.set_collision_callback(fun[this](this.collision_cb();))