ChaiScript麻烦

时间:2010-03-23 18:07:05

标签: c++ qt chaiscript

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

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

在应用程序paint-event中:

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)

我做错了什么?

1 个答案:

答案 0 :(得分:1)

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

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