ChaiScript is the first and only scripting language designed from the ground up with C++ compatibility and modern design in mind. It is an ECMAScript-inspired, embedded functional-like language.
ChaiScript is licensed under the BSD license.
ChaiScript is the first and only scripting language designed from the ground up with C++ compatibility and modern design in mind. It is an ECMAScript-inspired, embedded functional-like language.
ChaiScript is licensed under the BSD license.
Due to an increased release schedule, and the nature of ChaiScript being a header-only library, binary releases will be made less often. Previous releases can be found on github.
Version: 4.2.0 Released: 12/1/2012
(Requires Boost)
Source (tar.bz2)
Source (zip)
Version: 5.2.0 Released: 12/1/2012
(Requires C++11 Compiler)
Source (tar.bz2)
Source (zip)
Hi,i want to get function object in c++ and call later the function.
chaiscript code:
def fun(x)
{
return x*x;
}
var f = fun(x);
sendFun(f);c++ code:
void sendFun(ChaiScript_Language::Function f)
{
f.call();
}Thanks for help.
PS: i try to include #include but i have some errors :
E:\chaiscript-3.1.0-Source\include\chaiscript\language\chaiscript_prelude_docs.hpp|27|error: 'Type_Info' does not name a type|
E:\chaiscript-3.1.0-Source\include\chaiscript\language\chaiscript_prelude_docs.hpp|30|error: 'string' has not been declared|
...
I'm trying to do this : attr
I'm trying to do this :
What parameter must have sendfun ?
Second question :
Thanks for help.
If you want a bound member
If you want a bound member function, your example might look like:
attr myclass::value; def myclass::myclass() { this.value = 5; } def myclass::function(x) { this.value+=x; } var obj = myclass(); sendfun(bind(function, obj, _));The result of "bind" in the above example is a function that takes one parameter and calls: obj.function(parameter).
Similarly, for your second example, you might use bind, or you might just pass both parameters into your function, depending on your need:
dofun(obj, function); def doFun(obj, function) { obj.function(); }-Jason
Certainly, a complete example
Certainly, a complete example of what you want to do is in the unit test suite: https://github.com/ChaiScript/ChaiScript/blob/master/unittests/functor_c....
For completeness, I'll copy it here and simplify it for your case. Also, please note that "fun" is a reserved word in ChaiScript.
The best way to do what you want is to specify the exact parameters you want the function to take and return in C++ using a
boost::functionwrapper (orstd::functionin C++11).There are more generic methods but they are generally not recommended for end users. What do you think of this?
Thanks,this is exactly what i
Thanks,this is exactly what i wanted !