These are chat archives for ChaiScript/ChaiScript

13th
Mar 2017
David Marchbanks
@ptdave20
Mar 13 2017 16:13

Question that I am having trouble finding a example / explanation for an error I am having. I am attempting to move my game engine scripting language over to chai as a test, and having problems binding a class and it's functions over to chai.

Window.h:

static void Register(chaiscript::ChaiScript &chai) {
        chai.add(chaiscript::user_type<Window>(),"Window");
        chai.add(chaiscript::constructor<Window()>(),"Window");

        chai.add(chaiscript::fun(&Window::run),"run");
        chai.add(chaiscript::fun(&Window::createWindow),"createWindow");
        chai.add(chaiscript::fun(&Window::openConfig),"openConfig");
        chai.add(chaiscript::fun(&Window::stop),"stop");
    }

main.chai:

auto window = Window();

window.createWindow();
window.run();

With the output of:

terminate called after throwing an instance of 'std::bad_function_call'
  what():  bad_function_call
can anyone explain to me why this is happening?
David Marchbanks
@ptdave20
Mar 13 2017 19:23
nevermind, found it. Turns out I needed to change my register to look like this:
    static void Register(chaiscript::ChaiScript &chai) {
        chai.add(chaiscript::user_type<Window>(),"Window");
        chai.add(chaiscript::constructor<Window()>(),"Window")
            .add(chaiscript::fun(&Window::run),"run")
            .add(chaiscript::fun(&Window::createWindow),"createWindow")
            .add(chaiscript::fun(&Window::openConfig),"openConfig")
            .add(chaiscript::fun(&Window::stop),"stop");
    }