我使用这段代码来验证 ChaiScript 中一组 Qt 对象的一些属性:
/// initialize the engine
boost::shared_ptr<chaiscript::ChaiScript> chai;
chai.reset(new chaiscript::ChaiScript());
std::cout << "ChaiScript engine created!!!" << std::endl;
///
/// register elements
//
assert(ui->checkBox);
chai->add(chaiscript::var(ui->checkBox), "checkBox");
///
/// adapt elements
/// QCheckBox
chai->add(chaiscript::fun(&QCheckBox::isTristate), "isTristate");
chai->add(chaiscript::fun(&QCheckBox::isChecked), "isChecked");
/// validate some properties
try
{
chai->eval("print(\"Starting evaluation...\")");
int answer_i = 0;
bool answer_b = false;
//answer_b = chai->eval<bool>("checkBox.isTristate()");
answer_b = chai->eval<bool>("checkBox.isChecked()");
std::cout << "ChaiScript::: " << answer_b << " :: " << answer_i << std::endl;
}
catch(std::exception e)
{
std::cout << "ChaiScript@Exception::: " << e.what() << std::endl;
}
问题是“isTristate()”调用有效,因为这是 QCheckBox 的本机方法。另一方面,“isChecked()”调用失败,我认为这是因为这是从 QAbstractButton 类继承的方法。
我究竟做错了什么?