These are chat archives for ChaiScript/ChaiScript

13th
Apr 2017
Brigham Keys, Esq.
@bkeys
Apr 13 2017 01:00
Yeah I am having the same issue; I cannot even get chaiscript to work with a parameter
The examples are frustrating because they always use constants as the parameter, which for anyone who wants to script something beyond "hello world" is screwed
Passing constants as a parameter is a pretty useless example if you ask me
I want to know how I pass my own C++ variables into the chaiscript functions
Brigham Keys, Esq.
@bkeys
Apr 13 2017 01:25
Nevermind, I managed to figure it out
Jason Turner
@lefticus
Apr 13 2017 02:38
@bkeys @Wizardo367 You might be looking for the automatic conversion to std::function support? It's the most natural way to work with ChaiScript functions from C++: https://github.com/ChaiScript/ChaiScript/blob/develop/cheatsheet.md#sharing-functions
Harish Bhagat
@Wizardo367
Apr 13 2017 12:34
I got the example working, however I get a memory error when trying to do this using a function inside of a ChaiScript class. However it works fine when the function is outside the class.

C++

chai_Update = _file.eval<std::function<void(double)>>("Update");

ChaiScript

class Script
{

def Script()
{ 
}

def Start()
{

}

def Update(dt)
{ 
print("Time: " + dt);
}

def LateUpdate(dt)
{ 
}

def Destroy()
{ 
}

}
Harish Bhagat
@Wizardo367
Apr 13 2017 13:01
Nvm, figured it out. Thanks for the help. Here's the solution in case anyone else is having trouble.
    auto obj = _file.eval(id);
    chai_Update = _file.eval<std::function<void(chaiscript::Boxed_Value&, double)>>("Update");
    chai_Update(obj, 50);