These are chat archives for ChaiScript/ChaiScript

12th
Apr 2017
Harish Bhagat
@Wizardo367
Apr 12 2017 15:32
Hey, I've spent a day or two researching this but haven't found a solution. How do you pass a parameter from C++ to ChaiScript? In this case I need to pass a double (deltaTime). This is what I have atm.
Script::Script(std::string scriptName, std::string path) : id("obj_" + std::to_string(idNum + 1))
{    
    // Load script from file
    _file.eval_file(path);
    _file.eval("auto " + id + " = " + scriptName + "();");

    // Register base class
    _file.add(chaiscript::base_class<Component, Script>());

    // Register component functions
    _file.add(chaiscript::fun(&Script::Start), "Start");
    _file.add(chaiscript::fun(&Script::Update), "Update");
    _file.add(chaiscript::fun(&Script::LateUpdate), "LateUpdate");
    _file.add(chaiscript::fun(&Script::Destroy), "Destroy");
}

void Script::Update(double dt)
{
    _file.eval(id + ".Update()"); // Call ChaiScript function
}