Add build_functor algorithm for constructing a boost function_object from a script snippet
This commit is contained in:
parent
d4ec79607f
commit
dc11237af9
@ -1,7 +1,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "chaiscript.hpp"
|
||||
#include "function_call.hpp"
|
||||
#include "chaiscript.hpp"
|
||||
#include <boost/function.hpp>
|
||||
|
||||
struct Callback_Handler
|
||||
@ -53,5 +53,11 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
cb_handler.do_callbacks();
|
||||
|
||||
boost::function<std::string (const std::string&, const std::string &)> f =
|
||||
dispatchkit::build_functor<std::string (const std::string &, const std::string &)>
|
||||
(chai, "function(x, y) { x + y }");
|
||||
|
||||
std::cout << "Functor call: " << f("Hello", " World") << std::endl;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define __boxed_value_hpp__
|
||||
|
||||
#include "type_info.hpp"
|
||||
#include <map>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/any.hpp>
|
||||
#include <boost/function.hpp>
|
||||
|
@ -222,6 +222,8 @@ namespace dispatchkit
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -11,6 +11,9 @@
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "proxy_functions.hpp"
|
||||
|
||||
namespace dispatchkit
|
||||
{
|
||||
@ -58,6 +61,13 @@ namespace dispatchkit
|
||||
FunctionType *p;
|
||||
return build_function_caller_helper(p, func);
|
||||
}
|
||||
|
||||
|
||||
template<typename FunctionType, typename ScriptEngine>
|
||||
boost::function<FunctionType> build_functor(ScriptEngine &e, const std::string &script)
|
||||
{
|
||||
return build_function_caller<FunctionType>(Cast_Helper<boost::shared_ptr<Proxy_Function> >()(e.evaluate_string(script)));
|
||||
}
|
||||
}
|
||||
|
||||
# endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user