Storing Function in a .chai in C++


Is there a way to store a function which is defined in a script in c++ and execute it? I want to reduce the ammout of string lookups.

def update()
    //do stuff

In C++

function r = script("update()").function
r(); //instead of calling script("update()") every frame


Absolutely, this is the main feature that ChaiScript has that no one else has that I know of.

auto f = chai.eval<std::function<void ()>>("update");


See also:


Works perfect. Thanks