diff options
author | Emmanuel Leblond <emmanuel.leblond@gmail.com> | 2017-11-21 20:09:08 +0100 |
---|---|---|
committer | Emmanuel Leblond <emmanuel.leblond@gmail.com> | 2017-11-21 20:09:08 +0100 |
commit | b075f13988f2db892d6c27d1e223c7b10d28ee41 (patch) | |
tree | aef70e9e36e49265df12c79da5fa854e7af7d2f7 | |
parent | 640856f4d4f4e4d10e9f793caf6ac6f4d22678e6 (diff) |
Fix&prettify gdnative_api_struct.gen.h GDNATIVE_API_INIT macro generation
-rw-r--r-- | modules/gdnative/SCsub | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub index 485bf4b9df..54d0672a5b 100644 --- a/modules/gdnative/SCsub +++ b/modules/gdnative/SCsub @@ -19,19 +19,27 @@ def _spaced(e): return e if e[-1] == '*' else e + ' ' def _build_gdnative_api_struct_header(api): - ext_wrappers = '' + gdnative_api_init_macro = [ + '\textern const godot_gdnative_core_api_struct *_gdnative_wrapper_api_struct;' + ] for name in api['extensions']: - ext_wrappers += ' extern const godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct;' + gdnative_api_init_macro.append( + '\textern const godot_gdnative_ext_{0}_api_struct *_gdnative_wrapper_{0}_api_struct;'.format(name)) - ext_init = 'for (int i = 0; i < _gdnative_wrapper_api_struct->num_extensions; i++) { ' - ext_init += 'switch (_gdnative_wrapper_api_struct->extensions[i]->type) {' + gdnative_api_init_macro.append('\t_gdnative_wrapper_api_struct = options->api_struct;') + gdnative_api_init_macro.append('\tfor (int i = 0; i < _gdnative_wrapper_api_struct->num_extensions; i++) { ') + gdnative_api_init_macro.append('\t\tswitch (_gdnative_wrapper_api_struct->extensions[i]->type) {') for name in api['extensions']: - ext_init += 'case GDNATIVE_EXT_' + api['extensions'][name]['type'] + ': ' - ext_init += '_gdnative_wrapper_' + name + '_api_struct = (' + 'godot_gdnative_ext_' + name + '_api_struct *) _gdnative_wrapper_api_struct->extensions[i]; break;' - - ext_init += '}' + gdnative_api_init_macro.append( + '\t\t\tcase GDNATIVE_EXT_%s:' % api['extensions'][name]['type']) + gdnative_api_init_macro.append( + '\t\t\t\t_gdnative_wrapper_{0}_api_struct = (godot_gdnative_ext_{0}_api_struct *)' + ' _gdnative_wrapper_api_struct->extensions[i];'.format(name)) + gdnative_api_init_macro.append('\t\t\t\tbreak;') + gdnative_api_init_macro.append('\t\t}') + gdnative_api_init_macro.append('\t}') out = [ '/* THIS FILE IS GENERATED DO NOT EDIT */', @@ -43,7 +51,7 @@ def _build_gdnative_api_struct_header(api): '#include <nativescript/godot_nativescript.h>', '#include <pluginscript/godot_pluginscript.h>', '', - '#define GDNATIVE_API_INIT(options) do { extern const godot_gdnative_api_struct *_gdnative_wrapper_api_struct;' + ext_wrappers + ' _gdnative_wrapper_api_struct = options->api_struct; ' + ext_init + ' } while (0)', + '#define GDNATIVE_API_INIT(options) do { \\\n' + ' \\\n'.join(gdnative_api_init_macro) + ' \\\n } while (0)', '', '#ifdef __cplusplus', 'extern "C" {', @@ -179,7 +187,7 @@ def _build_gdnative_wrapper_code(api): ] for name in api['extensions']: - out.append('godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct;') + out.append('godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct = 0;') out += [''] |