These are chat archives for ChaiScript/ChaiScript

10th
Sep 2015
Phil Cooper-King
@PhilCK
Sep 10 2015 16:59

How is Chai with return references. I thought I had this working in the past.

struct Bar
{
   void say_hello() { /* hello */ }

   Foo *m_parent;
};

struct Foo
{
    Bar& get_bar() { return bar; }

    Bar bar;
};

Foo foo;
foo.bar.m_parent = &foo;
chai.add_global(chai_s::var(foo, "foo");

When chai calls back into foo.get_bar() foo is fine, however by the time we get into say_hello() the ptr back to foo is corrupted.

Phil Cooper-King
@PhilCK
Sep 10 2015 17:11
Actually ptr's are the same, I assuming I've done something wrong.
Phil Cooper-King
@PhilCK
Sep 10 2015 17:26
It does seem to work with chai.eval("GLOBAL foo = Foo()");
Phil Cooper-King
@PhilCK
Sep 10 2015 19:37
argh, ignore me. chai_s::var(&foo, "foo") some copying going on, bed for me.