These are chat archives for ChaiScript/ChaiScript

14th
Jan 2017
Martin Chang
@marty1885
Jan 14 2017 08:04
At least that's what issue#216 asking
That issues is asking for help on loading different version of the same function using chaiscript.
If you mean calling the same function a bunch of times. It's as simple as
for(int i=0;i<10000;i++)
    chai.eval("foo();");
Raoul Wols
@rwols
Jan 14 2017 11:18
I see, very cool
Raoul Wols
@rwols
Jan 14 2017 11:53
So now, how would I call a chai functionfoo from C++ with arguments?
Let's say I have def foo(int x) { ... } in my chai file
Raoul Wols
@rwols
Jan 14 2017 11:58
Can I do something like auto f = chai.eval<std::function<void(int)>>("foo"); in C++ ?
Martin Chang
@marty1885
Jan 14 2017 12:18
yes, I think this is exactly how it should be done.
Martin Chang
@marty1885
Jan 14 2017 12:36
BTW, I totally forgot about the retrieving variable part in your question.
Suppose there is a line in your chaiscript code global val = 0;
You retrieve the value using this line of code int val = chai.eval<int>("val");
Raoul Wols
@rwols
Jan 14 2017 23:17
Alright cool
If I do auto f = chai.eval<std::function<void(int)>>("foo");, then the function definition is copied by value, right?
So if another chai script changes the definition of foo by saying foo = ..., then that change wouldn't reflect in f, right?
In other words, every time I want to call the most recent definition of foo, I'd have to do auto f = chai.eval<std::function<void(int)>>("foo");, and then call that f
Am I correct in this reasoning?