diff options
-rwxr-xr-x | src/embind/embind.js | 72 | ||||
-rwxr-xr-x | system/include/emscripten/bind.h | 27 | ||||
-rwxr-xr-x | system/include/emscripten/wire.h | 5 |
3 files changed, 49 insertions, 55 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js index e121732f..88a4ee8d 100755 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -154,7 +154,11 @@ function requireArgumentTypes(argCount, argTypes, name) { var argTypeImpls = new Array(argCount); for (var i = 0; i < argCount; ++i) { var argType = HEAP32[(argTypes >> 2) + i]; - argTypeImpls[i] = requireRegisteredType(argType, name + " parameter " + i); + if (i == 0) { + argTypeImpls[i] = requireRegisteredType(argType, name + " return value"); + } else { + argTypeImpls[i] = requireRegisteredType(argType, name + " parameter " + i); + } } return argTypeImpls; } @@ -167,30 +171,28 @@ function runDestructors(destructors) { } } -function makeInvoker(name, returnType, argCount, argTypes, invoker, fn) { +function makeInvoker(name, argCount, argTypes, invoker, fn) { return function() { - if (arguments.length !== argCount) { - throw new BindingError('function ' + name + ' called with ' + arguments.length + ' arguments, expected ' + argCount); + if (arguments.length !== argCount - 1) { + throw new BindingError('function ' + name + ' called with ' + arguments.length + ' arguments, expected ' + argCount - 1); } var destructors = []; - var args = new Array(argCount + 1); + var args = new Array(argCount); args[0] = fn; - for (var i = 0; i < argCount; ++i) { - args[i + 1] = argTypes[i].toWireType(destructors, arguments[i]); + for (var i = 1; i < argCount; ++i) { + args[i] = argTypes[i].toWireType(destructors, arguments[i-1]); } - var rv = returnType.fromWireType(invoker.apply(null, args)); + var rv = argTypes[0].fromWireType(invoker.apply(null, args)); runDestructors(destructors); return rv; }; } -function __embind_register_function(name, returnType, argCount, argTypes, invoker, fn) { +function __embind_register_function(name, argCount, argTypes, invoker, fn) { name = Pointer_stringify(name); - returnType = requireRegisteredType(returnType, "Function " + name + " return value"); invoker = FUNCTION_TABLE[invoker]; argTypes = requireArgumentTypes(argCount, argTypes, name); - - exposePublicSymbol(name, makeInvoker(name, returnType, argCount, argTypes, invoker, fn)); + exposePublicSymbol(name, makeInvoker(name, argCount, argTypes, invoker, fn)); } function __embind_register_tuple(tupleType, name, constructor, destructor) { @@ -558,6 +560,9 @@ function __embind_register_class( var pointerName = name + '*'; registerType(pointerType, pointerName, { name: pointerName, + fromWireType: function(ptr) { + return new Handle(ptr); + }, toWireType: function(destructors, o) { return o.ptr; } @@ -586,13 +591,13 @@ function __embind_register_class_constructor( constructor = FUNCTION_TABLE[constructor]; classType.constructor.body = function() { - if (arguments.length !== argCount) { - throw new BindingError('emscripten binding ' + humanName + ' called with ' + arguments.length + ' arguments, expected ' + argCount); + if (arguments.length !== argCount - 1) { + throw new BindingError('emscripten binding ' + humanName + ' called with ' + arguments.length + ' arguments, expected ' + (argCount-1)); } var destructors = []; - var args = new Array(argCount); - for (var i = 0; i < argCount; ++i) { - args[i] = argTypes[i].toWireType(destructors, arguments[i]); + var args = new Array(argCount-1); + for (var i = 1; i < argCount; ++i) { + args[i-1] = argTypes[i].toWireType(destructors, arguments[i-1]); } var ptr = constructor.apply(null, args); @@ -605,7 +610,6 @@ function __embind_register_class_constructor( function __embind_register_class_method( classType, methodName, - returnType, argCount, argTypes, invoker, @@ -616,7 +620,6 @@ function __embind_register_class_method( methodName = Pointer_stringify(methodName); var humanName = classType.name + '.' + methodName; - returnType = requireRegisteredType(returnType, 'method ' + humanName + ' return value'); argTypes = requireArgumentTypes(argCount, argTypes, 'method ' + humanName); invoker = FUNCTION_TABLE[invoker]; memberFunction = copyMemberPointer(memberFunction, memberFunctionSize); @@ -626,19 +629,19 @@ function __embind_register_class_method( if (!this.ptr) { throw new BindingError('cannot call emscripten binding method ' + humanName + ' on deleted object'); } - if (arguments.length !== argCount) { - throw new BindingError('emscripten binding method ' + humanName + ' called with ' + arguments.length + ' arguments, expected ' + argCount); + if (arguments.length !== argCount - 1) { + throw new BindingError('emscripten binding method ' + humanName + ' called with ' + arguments.length + ' arguments, expected ' + (argCount-1)); } var destructors = []; - var args = new Array(argCount + 2); + var args = new Array(argCount + 1); args[0] = this.ptr; args[1] = memberFunction; - for (var i = 0; i < argCount; ++i) { - args[i + 2] = argTypes[i].toWireType(destructors, arguments[i]); + for (var i = 1; i < argCount; ++i) { + args[i + 1] = argTypes[i].toWireType(destructors, arguments[i-1]); } - var rv = returnType.fromWireType(invoker.apply(null, args)); + var rv = argTypes[0].fromWireType(invoker.apply(null, args)); runDestructors(destructors); return rv; }; @@ -705,7 +708,6 @@ function __embind_register_pointer_cast_method( function __embind_register_class_classmethod( classType, methodName, - returnType, argCount, argTypes, invoker, @@ -714,22 +716,18 @@ function __embind_register_class_classmethod( classType = requireRegisteredType(classType, 'class'); methodName = Pointer_stringify(methodName); var humanName = classType.name + '.' + methodName; - returnType = requireRegisteredType(returnType, 'classmethod ' + humanName + ' return value'); argTypes = requireArgumentTypes(argCount, argTypes, 'classmethod ' + humanName); invoker = FUNCTION_TABLE[invoker]; - - classType.constructor[methodName] = makeInvoker(humanName, returnType, argCount, argTypes, invoker, fn); + classType.constructor[methodName] = makeInvoker(humanName, argCount, argTypes, invoker, fn); } function __embind_register_class_operator_call( classType, - returnType, argCount, argTypes, invoker ) { classType = requireRegisteredType(classType, 'class'); - returnType = requireRegisteredType(returnType, 'method ' + humanName + ' return value'); argTypes = requireArgumentTypes(argCount, argTypes, 'method ' + humanName); invoker = FUNCTION_TABLE[invoker]; var humanName = classType.name + '.' + 'operator_call'; @@ -738,18 +736,18 @@ function __embind_register_class_operator_call( if (!this.ptr) { throw new BindingError('cannot call emscripten binding method ' + humanName + ' on deleted object'); } - if (arguments.length !== argCount) { - throw new BindingError('emscripten binding method ' + humanName + ' called with ' + arguments.length + ' arguments, expected ' + argCount); + if (arguments.length !== argCount - 1) { + throw new BindingError('emscripten binding method ' + humanName + ' called with ' + arguments.length + ' arguments, expected ' + (argCount-1)); } var destructors = []; - var args = new Array(argCount + 1); + var args = new Array(argCount); args[0] = this.ptr; - for (var i = 0; i < argCount; ++i) { - args[i + 1] = argTypes[i].toWireType(destructors, arguments[i]); + for (var i = 1; i < argCount; ++i) { + args[i] = argTypes[i].toWireType(destructors, arguments[i-1]); } - var rv = returnType.fromWireType(invoker.apply(null, args)); + var rv = argTypes[0].fromWireType(invoker.apply(null, args)); runDestructors(destructors); return rv; }; diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 7c59a0ce..08118259 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -48,7 +48,6 @@ namespace emscripten { void _embind_register_function( const char* name, - TYPEID returnType, unsigned argCount, TYPEID argTypes[], GenericFunction invoker, @@ -126,7 +125,6 @@ namespace emscripten { void _embind_register_class_method( TYPEID classType, const char* methodName, - TYPEID returnType, unsigned argCount, TYPEID argTypes[], GenericFunction invoker, @@ -157,7 +155,6 @@ namespace emscripten { void _embind_register_class_classmethod( TYPEID classType, const char* methodName, - TYPEID returnType, unsigned argCount, TYPEID argTypes[], GenericFunction invoker, @@ -165,7 +162,6 @@ namespace emscripten { void _embind_register_class_operator_call( TYPEID classType, - TYPEID returnType, unsigned argCount, TYPEID argTypes[], GenericFunction invoker @@ -206,7 +202,11 @@ namespace emscripten { template<int Index> struct arg { - static constexpr int index = Index; + static constexpr int index = Index + 1; + }; + + struct ret_val { + static constexpr int index = 0; }; template<typename Slot> @@ -282,10 +282,9 @@ namespace emscripten { registerStandardTypes(); - typename WithPolicies<Policies...>::template ArgTypeList<Args...> args; + typename WithPolicies<Policies...>::template ArgTypeList<ReturnType, Args...> args; _embind_register_function( name, - TypeID<ReturnType>::get(), args.count, args.types, reinterpret_cast<GenericFunction>(&Invoker<ReturnType, Args...>::invoke), @@ -661,7 +660,7 @@ namespace emscripten { class_& constructor(Policies...) { using namespace internal; - typename WithPolicies<Policies...>::template ArgTypeList<ConstructorArgs...> args; + typename WithPolicies<Policies...>::template ArgTypeList<void, ConstructorArgs...> args; _embind_register_class_constructor( TypeID<ClassType>::get(), args.count, @@ -674,11 +673,10 @@ namespace emscripten { class_& method(const char* methodName, ReturnType (ClassType::*memberFunction)(Args...), Policies...) { using namespace internal; - typename WithPolicies<Policies...>::template ArgTypeList<Args...> args; + typename WithPolicies<Policies...>::template ArgTypeList<ReturnType, Args...> args; _embind_register_class_method( TypeID<ClassType>::get(), methodName, - TypeID<ReturnType>::get(), args.count, args.types, reinterpret_cast<GenericFunction>(&MethodInvoker<ClassType, ReturnType, Args...>::invoke), @@ -691,11 +689,10 @@ namespace emscripten { class_& method(const char* methodName, ReturnType (ClassType::*memberFunction)(Args...) const, Policies...) { using namespace internal; - typename WithPolicies<Policies...>::template ArgTypeList<Args...> args; + typename WithPolicies<Policies...>::template ArgTypeList<ReturnType, Args...> args; _embind_register_class_method( TypeID<ClassType>::get(), methodName, - TypeID<ReturnType>::get(), args.count, args.types, reinterpret_cast<GenericFunction>(&ConstMethodInvoker<ClassType, ReturnType, Args...>::invoke), @@ -723,11 +720,10 @@ namespace emscripten { class_& classmethod(const char* methodName, ReturnType (*classMethod)(Args...), Policies...) { using namespace internal; - typename WithPolicies<Policies...>::template ArgTypeList<Args...> args; + typename WithPolicies<Policies...>::template ArgTypeList<ReturnType, Args...> args; _embind_register_class_classmethod( TypeID<ClassType>::get(), methodName, - TypeID<ReturnType>::get(), args.count, args.types, reinterpret_cast<internal::GenericFunction>(&internal::Invoker<ReturnType, Args...>::invoke), @@ -739,10 +735,9 @@ namespace emscripten { class_& calloperator(Policies...) { using namespace internal; - typename WithPolicies<Policies...>::template ArgTypeList<Args...> args; + typename WithPolicies<Policies...>::template ArgTypeList<ReturnType, Args...> args; _embind_register_class_operator_call( TypeID<ClassType>::get(), - TypeID<ReturnType>::get(), args.count, args.types, reinterpret_cast<internal::GenericFunction>(&internal::FunctorInvoker<ClassType, ReturnType, Args...>::invoke)); diff --git a/system/include/emscripten/wire.h b/system/include/emscripten/wire.h index 99c4f926..bb70f26c 100755 --- a/system/include/emscripten/wire.h +++ b/system/include/emscripten/wire.h @@ -104,7 +104,6 @@ namespace emscripten { template<typename... Policies> static void fill(TYPEID* argTypes) { typedef typename ExecutePolicies<Policies...>::template With<T, Index>::type TransformT; - *argTypes = TypeID<TransformT>::get(); return ArgTypes<Index + 1, Remaining...>::template fill<Policies...>(argTypes + 1); } @@ -204,7 +203,9 @@ namespace emscripten { template<typename T> struct BindingType<T*> { typedef T* WireType; - + static WireType toWireType(T* p) { + return p; + } static T* fromWireType(WireType wt) { return wt; } |