我有下一个定义类:
class MyType {
public:
MyType();
MyType(int x);
MyType(std::initializer_list<MyType> list);
}
我在 ChaiScript v6.0.0 中注册了我的自定义类及其构造函数,如下所示:
chai.add(chaiscript::user_type<MyType>(), "MyType");
chai.add(chaiscript::constructor<MyType()>(), "MyType");
chai.add(chaiscript::constructor<MyType(int)>(), "MyType");
chai.add(chaiscript::constructor<MyType(std::initializer_list<MyType>)>(), "MyType");
我有下一个脚本:
std::string script1 = R""(
def Test1() {
var m = MyType();
}
Test1();
)"";
auto res = chai.eval<MyType>(script1);
std::string script2 = R""(
def Test2() {
var m = MyType(10);
}
Test2();
)"";
auto res2 = chai.eval<MyType>(script2);
std::string script3 = R""(
def Test3() {
var m = MyType({10, 20});
}
Test3();
)"";
auto res3 = chai.eval<MyType>(script3);
script1
并script2
运行没有问题,但script3
给我下一个执行错误:
Error: "Incomplete equation" during evaluation at (9, 14)
MyType(std::initializer_list<MyType>)
从 ChaiScript调用构造函数的正确方法是什么?