Search code examples
chaiscript

Move semantics and std::unique_ptr in chaiscript


How can I register a method that relies on move semantics and std::unique_ptr with chaiscript's engine? Here's an example piece of code I cannot get to work using chaiscript 5.8.5 :

class Element;
class MyClass
{
public:
    void addElement(std::unique_ptr<Element>&&);
};

chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module());
chaiscript::utility::add_class<MyClass>(*m, "MyClass", {
    chaiscript::constructor<MyClass ()>()
}, {
    {chaiscript::fun(&MyClass::addElement), "addElement"},
});

This generates the following error from within chaiscript:

dispatchkit/boxed_cast_helper.hpp:43:46: error: 'type name' declared as a pointer to a reference of type 'std::__1::unique_ptr std::__1::default_delete > &&' return *static_cast(p);


Solution

  • r-values and unique_ptr now have support in the develop branch (to become version 6.0.0) of ChaiScript, but at the time this question was asked it was not possible.