aboutsummaryrefslogtreecommitdiff
path: root/src/embind/embind.js
diff options
context:
space:
mode:
authorJukka Jylanki <jjylanki@imvu.com>2013-04-02 12:26:32 +0300
committerJukka Jylänki <jujjyl@gmail.com>2013-04-12 14:27:10 +0300
commite8afd54698387cb38dafdea9317c764440063909 (patch)
tree9b759a55a253f3d11d065674755c5a0c7fd55620 /src/embind/embind.js
parentdef5681c4f191c5e273765624b200619a50cf805 (diff)
Add support for binding multiple class constructors with embind. The ctors must have different number of arguments each.
Diffstat (limited to 'src/embind/embind.js')
-rwxr-xr-xsrc/embind/embind.js17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index 16e29d9e..c298d8ba 100755
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -814,10 +814,13 @@ function __embind_register_class(
if (Object.getPrototypeOf(this) !== instancePrototype) {
throw new BindingError("Use 'new' to construct " + name);
}
- var body = registeredClass.constructor_body;
- if (undefined === body) {
+ if (undefined === registeredClass.constructor_body) {
throw new BindingError(name + " has no accessible constructor");
}
+ var body = registeredClass.constructor_body[arguments.length];
+ if (undefined === body) {
+ throw new BindingError("Tried to invoke ctor of " + name + " with invalid number of parameters (" + arguments.length + ") - expected (" + Object.keys(registeredClass.constructor_body).toString() + ") parameters instead!");
+ }
return body.apply(this, arguments);
});
@@ -884,12 +887,18 @@ function __embind_register_class_constructor(
classType = classType[0];
var humanName = 'constructor ' + classType.name;
- classType.registeredClass.constructor_body = function() {
+ if (undefined === classType.registeredClass.constructor_body) {
+ classType.registeredClass.constructor_body = [];
+ }
+ if (undefined !== classType.registeredClass.constructor_body[argCount - 1]) {
+ throw new BindingError("Cannot register multiple constructors with identical number of parameters (" + (argCount-1) + ") for class '" + classType.name + "'! Overload resolution is currently only performed using the parameter count, not actual type info!");
+ }
+ classType.registeredClass.constructor_body[argCount - 1] = function() {
throwUnboundTypeError('Cannot construct ' + classType.name + ' due to unbound types', rawArgTypes);
};
whenDependentTypesAreResolved([], rawArgTypes, function(argTypes) {
- classType.registeredClass.constructor_body = function() {
+ classType.registeredClass.constructor_body[argCount - 1] = function() {
if (arguments.length !== argCount - 1) {
throwBindingError(humanName + ' called with ' + arguments.length + ' arguments, expected ' + (argCount-1));
}