aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/embind/embind.js12
-rwxr-xr-xsystem/include/emscripten/bind.h19
2 files changed, 22 insertions, 9 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index 277515a5..5a0699ba 100755
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -788,10 +788,13 @@ function __embind_register_class_constructor(
rawClassType,
argCount,
rawArgTypesAddr,
+ invoker,
rawConstructor
) {
var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
- rawConstructor = FUNCTION_TABLE[rawConstructor];
+ invoker = FUNCTION_TABLE[invoker];
+ rawConstructor = rawConstructor;
+
requestDeferredRegistration(function() {
var classType = requireRegisteredType(rawClassType, 'class');
var humanName = 'constructor ' + classType.name;
@@ -801,12 +804,13 @@ function __embind_register_class_constructor(
throw new BindingError('emscripten binding ' + humanName + ' called with ' + arguments.length + ' arguments, expected ' + (argCount-1));
}
var destructors = [];
- var args = new Array(argCount - 1);
+ var args = new Array(argCount);
+ args[0] = rawConstructor;
for (var i = 1; i < argCount; ++i) {
- args[i - 1] = argTypes[i].toWireType(destructors, arguments[i - 1]);
+ args[i] = argTypes[i].toWireType(destructors, arguments[i - 1]);
}
- var ptr = rawConstructor.apply(null, args);
+ var ptr = invoker.apply(null, args);
runDestructors(destructors);
return classType.Handle.call(this, ptr);
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h
index 33e1cc43..257c7334 100755
--- a/system/include/emscripten/bind.h
+++ b/system/include/emscripten/bind.h
@@ -113,6 +113,7 @@ namespace emscripten {
TYPEID classType,
unsigned argCount,
TYPEID argTypes[],
+ GenericFunction invoker,
GenericFunction constructor);
void _embind_register_class_method(
@@ -211,7 +212,7 @@ namespace emscripten {
template<typename ReturnType, typename... Args>
struct Invoker {
static typename internal::BindingType<ReturnType>::WireType invoke(
- ReturnType (fn)(Args...),
+ ReturnType (*fn)(Args...),
typename internal::BindingType<Args>::WireType... args
) {
return internal::BindingType<ReturnType>::toWireType(
@@ -225,7 +226,7 @@ namespace emscripten {
template<typename... Args>
struct Invoker<void, Args...> {
static void invoke(
- void (fn)(Args...),
+ void (*fn)(Args...),
typename internal::BindingType<Args>::WireType... args
) {
return fn(
@@ -655,15 +656,23 @@ namespace emscripten {
}
template<typename... ConstructorArgs, typename... Policies>
- class_& constructor(Policies...) {
+ class_& constructor(Policies... policies) {
+ return constructor(
+ &internal::operator_new<ClassType, ConstructorArgs...>,
+ policies...);
+ }
+
+ template<typename... Args, typename... Policies>
+ class_& constructor(ClassType* (*factory)(Args...), Policies...) {
using namespace internal;
- typename WithPolicies<Policies...>::template ArgTypeList<void, ConstructorArgs...> args;
+ typename WithPolicies<Policies...>::template ArgTypeList<void, Args...> args;
_embind_register_class_constructor(
TypeID<ClassType>::get(),
args.count,
args.types,
- reinterpret_cast<GenericFunction>(&raw_constructor<ClassType, ConstructorArgs...>));
+ reinterpret_cast<GenericFunction>(&Invoker<ClassType*, Args...>::invoke),
+ reinterpret_cast<GenericFunction>(factory));
return *this;
}