10 #include <emscripten/bind.h>
11 #include <emscripten/val.h>
13 #include <boost/preprocessor/repetition/repeat.hpp>
14 #include <boost/preprocessor/punctuation/comma_if.hpp>
15 #include <boost/preprocessor/stringize.hpp>
17 #include <pre/type_traits/function_traits.hpp>
19 #ifndef JS_BIND_MAX_ARITY
25 # define JS_BIND_MAX_ARITY 16
28 #define JS_BIND_DETAIL_ARGS_EACH(z, n, unused) BOOST_PP_COMMA_IF(n) emscripten::val
30 #define JS_BIND_DETAIL_ARGS(COUNT) BOOST_PP_REPEAT(COUNT, JS_BIND_DETAIL_ARGS_EACH, unused)
32 #define JS_BIND_DETAIL_EACH(z, n, return_type) \
33 emscripten::class_<std::function<return_type(JS_BIND_DETAIL_ARGS(n))>>( \
34 BOOST_PP_STRINGIZE(return_type) BOOST_PP_STRINGIZE(n) "ArgsFunctor") \
36 .function("opcall", &std::function<return_type(JS_BIND_DETAIL_ARGS(n))>::operator());
38 #define JS_BIND_DETAIL_GENERATE_BINDINGS() \
39 BOOST_PP_REPEAT(JS_BIND_MAX_ARITY, JS_BIND_DETAIL_EACH, void) \
40 BOOST_PP_REPEAT(JS_BIND_MAX_ARITY, JS_BIND_DETAIL_EACH, emscripten::val)
42 #define JS_BIND_FUNCTION_TYPES_EACH(z, n, return_type) \
44 struct functor_t<std::is_same<return_type, void>::value, n> \
46 typedef ::std::function<return_type(JS_BIND_DETAIL_ARGS(n))> type; \
49 #define JS_BIND_FUNCTION_TYPES() \
50 BOOST_PP_REPEAT(JS_BIND_MAX_ARITY, JS_BIND_FUNCTION_TYPES_EACH, void) \
51 BOOST_PP_REPEAT(JS_BIND_MAX_ARITY, JS_BIND_FUNCTION_TYPES_EACH, emscripten::val)
53 #define JS_BIND_DETAIL_FWD(...) ::std::forward<decltype(__VA_ARGS__)>(__VA_ARGS__)
65 template <
class F,
class... Args>
70 template <
typename... Args>
76 static constexpr
size_t value = 0;
82 static constexpr
size_t value = (std::is_placeholder<typename std::decay<T>::type>
::value) ? 1 : 0;
85 template <
typename Arg,
typename... Args>
92 template <const
bool returns_
void, const
size_t arity>
97 template <
class F,
class... Args>
101 using pre::type_traits::function_traits;
103 using result_type =
typename function_traits<std::decay_t<F>>::result_type;
110 callback_t functor = bind_result;
113 auto functor_adapter =
115 return functor_adapter;
#define JS_BIND_DETAIL_FWD(...)
Definition: functions.hpp:53
Definition: file_dialog.hpp:6
emscripten::val bind(F &&f, Args &&... args)
Equivalent of std::bind returning a javascript functor.
Definition: functions.hpp:98
emscripten::val val
Definition: val.hpp:5
Definition: functions.hpp:81
static constexpr size_t value
Definition: functions.hpp:82
Definition: functions.hpp:71
Definition: functions.hpp:93