Boxed_Value from C++ to be assigned in script


#1

heho!
i want to do something like this:

std::shared_ptr<chaiscript::Boxed_Value> bvptr;
chai.add(chaiscript::var(bvptr),"bvptr");
chai.eval("var anything = 1234;bvptr = anything;"); // NOPE!
chai.eval("var anything = 1234;bvptr := anything;"); // NOPE!
chai.eval("var & anything = 1234;bvptr := anything;"); // NOPE!
chai.eval("var & anything = 1234;bvptr = anything;"); // NOPE!

where anything could be any chaiscript-var/object.

now i tried different combinations of &s and :s but i can’t get it to work. not sure if this is meant to work this way, boxed_value being in c++ and then getting “filled” from script.

currently i need it to unit-test my delayed event type.

insights welcome.


#2

Could not get it to work like that, so i went with a plain

chaiscript::Boxed_Value bv;

as my event’s member and the scripted function that assign it uses a line like

event.bv := anything;

i still have to test what happens if anything gets deleted in different places, hope whatever the actual type inside the bv is this way won’t leak when removing events.

i don’t really understand how boxed_value does it’s magic, or what it actually consists of. (i imagine some kind of pointer and type-info.)
but putting a ref/ptr(?) into the box rather than putting the box into a shared_ptr seems to work so far.


#3

I’ve gone through a lot of effort to make sure that inside of script Boxed_Value “just works” and is kind of invisible, so I’m not surprised that you had a hard time getting it to be visible like that.

Internally a boxed_value is a shared_ptr to an any-like thing, plus the type info to go along with it.


#4

Oh well, in that case Boxed_Value already is exactly what i wanted it to be and there should be no need for my weird plan of putting it in a shared_ptr. Thanks for the confirmation.