diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-08-07 15:53:18 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-08-07 15:53:18 -0700 |
commit | 19d18fbffd8f79bbe7cece5806903b2a6c1561e9 (patch) | |
tree | f10a39d307919475ff0c23083a4ea90dc107dade | |
parent | b9becbdc9b8d3e22b13220f4a1ce741a2fcbfb16 (diff) |
export option for bindings generator to play nicely with closure compiler advanced opts
-rwxr-xr-x | tools/bindings_generator.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/tools/bindings_generator.py b/tools/bindings_generator.py index 21f8ce5e..171c1d10 100755 --- a/tools/bindings_generator.py +++ b/tools/bindings_generator.py @@ -29,6 +29,10 @@ We generate the following: change all arguments of type float& to float by "type_processor": "lambda t: t if t != 'float&' else 'float'" + export: If true, will export all bindings in the .js file. This allows + you to run something like closure compiler advanced opts on + the library+bindings, and the bindings will remain accessible. + For example, JSON can be { "ignored": "class1,class2::func" }. The C bindings file is basically a tiny C wrapper around the C++ code. @@ -55,6 +59,7 @@ basename = sys.argv[1] ignored = [] type_processor = lambda t: t +export = 0 if '--' in sys.argv: index = sys.argv.index('--') @@ -65,6 +70,8 @@ if '--' in sys.argv: ignored = json['ignored'].split(',') if json.get('type_processor'): type_processor = eval(json['type_processor']) + if json.get('export'): + export = json['export'] print 'zz ignoring', ignored @@ -339,13 +346,19 @@ function %s(%s) { } %s.prototype = %s.prototype; ''' % (mname_suffixed, ', '.join(justargs), argfixes, calls, mname_suffixed, classname) + + if export: + js_text += ''' +this['%s'] = %s; +''' % (mname_suffixed, mname_suffixed) + else: js_text = ''' -%s.prototype.%s = function(%s) { +%s.prototype%s = function(%s) { %s %s } -''' % (generating_classname_head, mname_suffixed, ', '.join(justargs), argfixes, calls) +''' % (generating_classname_head, ('.' + mname_suffixed) if not export else ("['" + mname_suffixed + "']"), ', '.join(justargs), argfixes, calls) js_text = js_text.replace('\n\n', '\n').replace('\n\n', '\n') gen_js.write(js_text) |