Turns out we can simplify and reuse a lot of code :o
This commit is contained in:
Родитель
f23cc669e3
Коммит
3adc0bd5ed
|
@ -834,39 +834,6 @@ function __embind_register_class_constructor(
|
|||
var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
|
||||
invoker = FUNCTION_TABLE[invoker];
|
||||
|
||||
requestDeferredRegistration(function() {
|
||||
var classType = requireRegisteredType(rawClassType, 'class');
|
||||
var humanName = 'constructor ' + classType.name;
|
||||
var argTypes = requireArgumentTypes(rawArgTypes, humanName);
|
||||
classType.constructor.body = function() {
|
||||
if (arguments.length !== argCount - 1) {
|
||||
throwBindingError(humanName + ' called with ' + arguments.length + ' arguments, expected ' + (argCount-1));
|
||||
}
|
||||
var destructors = [];
|
||||
var args = new Array(argCount);
|
||||
args[0] = rawConstructor;
|
||||
for (var i = 1; i < argCount; ++i) {
|
||||
args[i] = argTypes[i].toWireType(destructors, arguments[i - 1]);
|
||||
}
|
||||
|
||||
var ptr = invoker.apply(null, args);
|
||||
runDestructors(destructors);
|
||||
|
||||
return classType.Handle.call(this, ptr);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function __embind_register_class_smart_ptr_constructor(
|
||||
rawClassType,
|
||||
argCount,
|
||||
rawArgTypesAddr,
|
||||
invoker,
|
||||
rawConstructor
|
||||
) {
|
||||
var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
|
||||
invoker = FUNCTION_TABLE[invoker];
|
||||
|
||||
requestDeferredRegistration(function() {
|
||||
var classType = requireRegisteredType(rawClassType, 'class');
|
||||
var humanName = 'constructor ' + classType.name;
|
||||
|
|
|
@ -116,13 +116,6 @@ namespace emscripten {
|
|||
GenericFunction invoker,
|
||||
GenericFunction constructor);
|
||||
|
||||
void _embind_register_class_smart_ptr_constructor(
|
||||
TYPEID classType,
|
||||
unsigned argCount,
|
||||
TYPEID argTypes[],
|
||||
GenericFunction invoker,
|
||||
GenericFunction constructor);
|
||||
|
||||
void _embind_register_class_method(
|
||||
TYPEID classType,
|
||||
const char* methodName,
|
||||
|
@ -633,7 +626,7 @@ namespace emscripten {
|
|||
class_& constructor(ClassType* (*factory)(Args...), Policies...) {
|
||||
using namespace internal;
|
||||
|
||||
typename WithPolicies<Policies...>::template ArgTypeList<void, Args...> args;
|
||||
typename WithPolicies<Policies...>::template ArgTypeList<AllowedRawPointer<ClassType>, Args...> args;
|
||||
_embind_register_class_constructor(
|
||||
TypeID<ClassType>::get(),
|
||||
args.count,
|
||||
|
@ -643,15 +636,15 @@ namespace emscripten {
|
|||
return *this;
|
||||
}
|
||||
|
||||
template<typename SmartPtr, typename... Args>
|
||||
class_& constructor(SmartPtr (*factory)(Args...)) {
|
||||
template<typename SmartPtr, typename... Args, typename... Policies>
|
||||
class_& constructor(SmartPtr (*factory)(Args...), Policies...) {
|
||||
using namespace internal;
|
||||
|
||||
// todo: generate unique name
|
||||
// TODO: generate unique name
|
||||
smart_ptr<SmartPtr>("SmartPtr");
|
||||
|
||||
typename WithPolicies<>::template ArgTypeList<SmartPtr, Args...> args;
|
||||
_embind_register_class_smart_ptr_constructor(
|
||||
typename WithPolicies<Policies...>::template ArgTypeList<SmartPtr, Args...> args;
|
||||
_embind_register_class_constructor(
|
||||
TypeID<ClassType>::get(),
|
||||
args.count,
|
||||
args.types,
|
||||
|
|
Загрузка…
Ссылка в новой задаче