我在C ++和Qt中使用脚本语言ChaiScript。我已经定义了这样的功能:

void ChaiPainter::drawRectangle(QPainter *painter, int x, int y, int height, int width)
{
    painter.drawRect(x, y, width, height);
}


并在应用程序绘制事件中:

void MainWindow::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);

    chaiPainter->mChai.add(chaiscript::var(&painter), "painter");
    chaiPainter->mChai.add(chaiscript::fun(&ChaiPainter::drawRectangle), "drawRect");

    chaiPainter->mChai("drawRect(painter, 5, 5, 100, 100)");
}


错误是:


  'chaiscript :: Eval_Error'what():
  错误:“没有匹配功能
  分派给功能为“ drawRect”的人
  在(1,1)进行评估时


我做错了什么?

最佳答案

从文档看来,您需要使用fun(mem_fn, instance)表单来获取预绑定函数:

chaiPainter->mChai.add(
    chaiscript::fun(&ChaiPainter::drawRectangle, chaiPainter), "drawRect");

10-06 04:07