@@ -352,6 +352,31 @@ namespace emscripten {
352
352
);
353
353
}
354
354
};
355
+
356
+ template <typename FunctorType, typename ReturnType, typename ... Args>
357
+ struct FunctorInvoker {
358
+ static typename internal::BindingType<ReturnType>::WireType invoke (
359
+ FunctorType& function,
360
+ typename internal::BindingType<Args>::WireType... args
361
+ ) {
362
+ return internal::BindingType<ReturnType>::toWireType (
363
+ function (
364
+ internal::BindingType<Args>::fromWireType (args)...)
365
+ );
366
+ }
367
+ };
368
+
369
+ template <typename FunctorType, typename ... Args>
370
+ struct FunctorInvoker <FunctorType, void , Args...> {
371
+ static void invoke (
372
+ FunctorType& function,
373
+ typename internal::BindingType<Args>::WireType... args
374
+ ) {
375
+ function (
376
+ internal::BindingType<Args>::fromWireType (args)...);
377
+ }
378
+ };
379
+
355
380
}
356
381
357
382
// //////////////////////////////////////////////////////////////////////////////
@@ -487,37 +512,6 @@ namespace emscripten {
487
512
}
488
513
};
489
514
490
- template <typename FunctorType, typename ReturnType, typename ThisType, typename ... Args>
491
- struct FunctorInvoker {
492
-
493
- static typename internal::BindingType<ReturnType>::WireType invoke (
494
- FunctorType& function,
495
- typename internal::BindingType<ThisType>::WireType wireThis,
496
- typename internal::BindingType<Args>::WireType... args
497
- ) {
498
- return internal::BindingType<ReturnType>::toWireType (
499
- function (
500
- internal::BindingType<ThisType>::fromWireType (wireThis),
501
- internal::BindingType<Args>::fromWireType (args)...)
502
- );
503
- }
504
- };
505
-
506
- template <typename FunctorType, typename ThisType, typename ... Args>
507
- struct FunctorInvoker <FunctorType, void , ThisType, Args...> {
508
- using FunctionType = std::function<void (ThisType, Args...)>;
509
-
510
- static void invoke (
511
- FunctorType& function,
512
- typename internal::BindingType<ThisType>::WireType wireThis,
513
- typename internal::BindingType<Args>::WireType... args
514
- ) {
515
- function (
516
- internal::BindingType<ThisType>::fromWireType (wireThis),
517
- internal::BindingType<Args>::fromWireType (args)...);
518
- }
519
- };
520
-
521
515
template <typename MemberPointer,
522
516
typename ReturnType,
523
517
typename ThisType,
@@ -1142,6 +1136,64 @@ namespace emscripten {
1142
1136
1143
1137
struct DeduceArgumentsTag {};
1144
1138
1139
+ // //////////////////////////////////////////////////////////////////////////
1140
+ // RegisterClassConstructor
1141
+ // //////////////////////////////////////////////////////////////////////////
1142
+
1143
+ template <typename T>
1144
+ struct RegisterClassConstructor ;
1145
+
1146
+ template <typename ReturnType, typename ... Args>
1147
+ struct RegisterClassConstructor <ReturnType (*)(Args...)> {
1148
+
1149
+ template <typename ClassType, typename ... Policies>
1150
+ static void invoke (ReturnType (*factory)(Args...)) {
1151
+ typename WithPolicies<allow_raw_pointers, Policies...>::template ArgTypeList<ReturnType, Args...> args;
1152
+ auto invoke = &Invoker<ReturnType, Args...>::invoke;
1153
+ _embind_register_class_constructor (
1154
+ TypeID<ClassType>::get (),
1155
+ args.getCount (),
1156
+ args.getTypes (),
1157
+ getSignature (invoke),
1158
+ reinterpret_cast <GenericFunction>(invoke),
1159
+ reinterpret_cast <GenericFunction>(factory));
1160
+ }
1161
+ };
1162
+
1163
+ template <typename ReturnType, typename ... Args>
1164
+ struct RegisterClassConstructor <std::function<ReturnType (Args...)>> {
1165
+
1166
+ template <typename ClassType, typename ... Policies>
1167
+ static void invoke (std::function<ReturnType (Args...)> factory) {
1168
+ typename WithPolicies<Policies...>::template ArgTypeList<ReturnType, Args...> args;
1169
+ auto invoke = &FunctorInvoker<decltype (factory), ReturnType, Args...>::invoke;
1170
+ _embind_register_class_constructor (
1171
+ TypeID<ClassType>::get (),
1172
+ args.getCount (),
1173
+ args.getTypes (),
1174
+ getSignature (invoke),
1175
+ reinterpret_cast <GenericFunction>(invoke),
1176
+ reinterpret_cast <GenericFunction>(getContext (factory)));
1177
+ }
1178
+ };
1179
+
1180
+ template <typename ReturnType, typename ... Args>
1181
+ struct RegisterClassConstructor <ReturnType (Args...)> {
1182
+
1183
+ template <typename ClassType, typename Callable, typename ... Policies>
1184
+ static void invoke (Callable& factory) {
1185
+ typename WithPolicies<Policies...>::template ArgTypeList<ReturnType, Args...> args;
1186
+ auto invoke = &FunctorInvoker<decltype (factory), ReturnType, Args...>::invoke;
1187
+ _embind_register_class_constructor (
1188
+ TypeID<ClassType>::get (),
1189
+ args.getCount (),
1190
+ args.getTypes (),
1191
+ getSignature (invoke),
1192
+ reinterpret_cast <GenericFunction>(invoke),
1193
+ reinterpret_cast <GenericFunction>(getContext (factory)));
1194
+ }
1195
+ };
1196
+
1145
1197
// //////////////////////////////////////////////////////////////////////////
1146
1198
// RegisterClassMethod
1147
1199
// //////////////////////////////////////////////////////////////////////////
@@ -1328,20 +1380,15 @@ namespace emscripten {
1328
1380
policies...);
1329
1381
}
1330
1382
1331
- template <typename ... Args, typename ReturnType, typename ... Policies>
1332
- EMSCRIPTEN_ALWAYS_INLINE const class_& constructor (ReturnType (*factory)(Args...), Policies...) const {
1333
- using namespace internal ;
1383
+ template <typename Signature = internal::DeduceArgumentsTag, typename Callable, typename ... Policies>
1384
+ EMSCRIPTEN_ALWAYS_INLINE const class_& constructor (Callable callable, Policies...) const {
1334
1385
1335
- // TODO: allows all raw pointers... policies need a rethink
1336
- typename WithPolicies<allow_raw_pointers, Policies...>::template ArgTypeList<ReturnType, Args...> args;
1337
- auto invoke = &Invoker<ReturnType, Args...>::invoke;
1338
- _embind_register_class_constructor (
1339
- TypeID<ClassType>::get (),
1340
- args.getCount (),
1341
- args.getTypes (),
1342
- getSignature (invoke),
1343
- reinterpret_cast <GenericFunction>(invoke),
1344
- reinterpret_cast <GenericFunction>(factory));
1386
+ using invoker = internal::RegisterClassConstructor<
1387
+ typename std::conditional<std::is_same<Signature, internal::DeduceArgumentsTag>::value,
1388
+ Callable,
1389
+ Signature>::type>;
1390
+
1391
+ invoker::template invoke<ClassType, Policies...>(callable);
1345
1392
return *this ;
1346
1393
}
1347
1394
0 commit comments