0

I'm using script language ChaiScript with c++ and Qt. I've defined such function:

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

And in application 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)");
}

The error is:

'chaiscript::Eval_Error' what(): Error: "No matching function to dispatch to with function 'drawRect'" during evaluation at (1, 1)

What I do wrong?

Max Frai
  • 61,946
  • 78
  • 197
  • 306

1 Answers1

1

From the documentation it looks like you need to use the fun(mem_fn, instance) form to get pre-bound functions:

chaiPainter->mChai.add(
    chaiscript::fun(&ChaiPainter::drawRectangle, chaiPainter), "drawRect");
Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236