Add support for automatic conversion between chaiscript functions and boost::function. Might merit some look to see how much overhead this adds.
This commit is contained in:
25
unittests/functor_cast_test.cpp
Normal file
25
unittests/functor_cast_test.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <chaiscript/utility/utility.hpp>
|
||||
|
||||
double test_call(const boost::function<double (int)> &f, int val)
|
||||
{
|
||||
return f(val);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
chaiscript::ChaiScript chai;
|
||||
|
||||
chai.add(chaiscript::fun(&test_call), "test_call");
|
||||
|
||||
chai.eval("def func(i) { return i * 3.5; };");
|
||||
double d = chai.eval<double>("test_call(func, 3)");
|
||||
|
||||
if (d == 3 * 3.5)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user