0

我正在使用带有 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(): Error: "No matching function to dispatch to with function 'drawRect'" 在 (1, 1) 评估期间

我做错了什么?

4

1 回答 1

1

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

chaiPainter->mChai.add(
    chaiscript::fun(&ChaiPainter::drawRectangle, chaiPainter), "drawRect");
于 2010-03-23T18:39:23.587 回答