aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-08-13 14:37:07 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-08-13 14:37:07 -0700
commite281a8d74bd44b1a1681398bf1158c69589b3ee8 (patch)
treeb07d5e8bad646a29896a07b69f2397599af19968
parentb680c96640fef3f67d4d96c95231dd57a9535f6f (diff)
optimize bindings argument fixing
-rwxr-xr-xtools/bindings_generator.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/tools/bindings_generator.py b/tools/bindings_generator.py
index 8e4bb7b6..49cd72aa 100755
--- a/tools/bindings_generator.py
+++ b/tools/bindings_generator.py
@@ -149,6 +149,9 @@ for classname, clazz in classes.iteritems():
# Explore all functions we need to generate, including parent classes, handling of overloading, etc.
+def clean_type(t):
+ return t.replace('const ', '').replace('struct ', '').replace('&', '').replace('*', '').replace(' ', '')
+
for classname, clazz in parsed.classes.iteritems():
clazz['final_methods'] = {}
@@ -290,10 +293,9 @@ def generate_class(generating_classname, classname, clazz): # TODO: deprecate ge
if constructor:
generating_classname_suffixed += suffix
- argfixes = '\n'.join(map(lambda arg: ''' %s = (%s && %s.ptr) ? %s.ptr : %s;''' % (arg['name'], arg['name'], arg['name'], arg['name'], arg['name']), args))
+ # C
for i in method['num_args']:
- # C
# If we are returning a *copy* of an object, we return instead to a ref of a static held here. This seems the best compromise
staticize = not constructor and ret.replace(' ', '') != 'void' and method['returns'] in classes and (not method['returns_reference'] and not method['returns_pointer'])
@@ -316,6 +318,17 @@ def generate_class(generating_classname, classname, clazz): # TODO: deprecate ge
c_funcs.append(fullname + '_p' + str(i))
# JS
+
+ print 'zz types:', map(lambda arg: arg['type'], args)
+
+ argfixes = ''
+ justargs_fixed = justargs[:]
+ for i in range(len(args)):
+ arg = args[i]
+ if clean_type(arg['type']) in classes:
+ argfixes += ' var %(arg)s__p = %(arg)s ? %(arg)s.ptr : 0;\n' % { 'arg': justargs[i] }
+ justargs_fixed[i] += '__p'
+
calls = ''
print 'js loopin', method['num_args'], '|', len(args)#, args
for i in method['num_args']:
@@ -328,12 +341,12 @@ def generate_class(generating_classname, classname, clazz): # TODO: deprecate ge
if constructor:
if not dupe:
calls += '''this.ptr = _%s_p%d(%s);
-''' % (fullname, i, ', '.join(justargs[:i]))
+''' % (fullname, i, ', '.join(justargs_fixed[:i]))
else:
calls += '''this.ptr = _%s_p%d(%s);
-''' % (fullname, i, ', '.join(justargs[:i]))
+''' % (fullname, i, ', '.join(justargs_fixed[:i]))
else:
- return_value = '''_%s_p%d(%s)''' % (fullname, i, ', '.join((['this.ptr'] if need_self else []) + justargs[:i]))
+ return_value = '''_%s_p%d(%s)''' % (fullname, i, ', '.join((['this.ptr'] if need_self else []) + justargs_fixed[:i]))
print 'zz making return', classname, method['name'], method['returns'], return_value
if method['returns'] in classes:
# Generate a wrapper