diff options
author | Karroffel <therzog@mail.de> | 2017-11-10 12:08:09 +0100 |
---|---|---|
committer | Karroffel <therzog@mail.de> | 2017-11-10 12:08:09 +0100 |
commit | 7ae2de8997fadd692f5e43839633fbfdf3816e66 (patch) | |
tree | bdc8bbeb41af742e4fe8ed21af933822aecf7450 /modules/gdnative | |
parent | fd4921375a10123b504b746914715d516aac1216 (diff) |
[GDNative] better API struct versioning
Diffstat (limited to 'modules/gdnative')
-rw-r--r-- | modules/gdnative/SCsub | 41 | ||||
-rw-r--r-- | modules/gdnative/gdnative.cpp | 2 | ||||
-rw-r--r-- | modules/gdnative/gdnative_api.json | 24 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/gdnative.h | 2 |
4 files changed, 50 insertions, 19 deletions
diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub index c0d1d114d7..cd29140d5d 100644 --- a/modules/gdnative/SCsub +++ b/modules/gdnative/SCsub @@ -35,34 +35,47 @@ def _build_gdnative_api_struct_header(api): 'extern "C" {', '#endif', '', + 'typedef struct godot_gdnative_api_version {', + '\tunsigned int major;', + '\tunsigned int minor;', + '} godot_gdnative_api_version;', + '', + 'typedef struct godot_gdnative_api_struct {', + '\tunsigned int type;', + '\tgodot_gdnative_api_version version;', + '\tconst godot_gdnative_api_struct *next;', + '} godot_gdnative_api_struct;', + '', 'enum GDNATIVE_API_TYPES {', '\tGDNATIVE_' + api['core']['type'] + ',' ] for name in api['extensions']: - out += ['\tGDNATIVE_' + api['extensions'][name]['type'] + ','] + out += ['\tGDNATIVE_EXT_' + api['extensions'][name]['type'] + ','] out += ['};', ''] for name in api['extensions']: out += [ - 'typedef struct godot_gdnative_' + name + '_api_struct {', + 'typedef struct godot_gdnative_ext_' + name + '_api_struct {', '\tunsigned int type;', - '\tconst void *next;' + '\tgodot_gdnative_api_version version;', + '\tconst godot_gdnative_api_struct *next;' ] for funcdef in api['extensions'][name]['api']: args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']]) out.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args)) - out += ['} godot_gdnative_' + name + '_api_struct;', ''] + out += ['} godot_gdnative_ext_' + name + '_api_struct;', ''] out += [ - 'typedef struct godot_gdnative_api_struct {', + 'typedef struct godot_gdnative_core_api_struct {', '\tunsigned int type;', - '\tconst void *next;', + '\tgodot_gdnative_api_version version;', + '\tconst godot_gdnative_api_struct *next;', '\tunsigned int num_extensions;', - '\tconst void **extensions;', + '\tconst godot_gdnative_api_struct **extensions;', ] for funcdef in api['core']['api']: @@ -70,7 +83,7 @@ def _build_gdnative_api_struct_header(api): out.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args)) out += [ - '} godot_gdnative_api_struct;', + '} godot_gdnative_core_api_struct;', '', '#ifdef __cplusplus', '}', @@ -91,8 +104,9 @@ def _build_gdnative_api_struct_source(api): for name in api['extensions']: out += [ - 'extern const godot_gdnative_' + name + '_api_struct api_extension_' + name + '_struct = {', - '\tGDNATIVE_' + api['extensions'][name]['type'] + ',', + 'extern const godot_gdnative_ext_' + name + '_api_struct api_extension_' + name + '_struct = {', + '\tGDNATIVE_EXT_' + api['extensions'][name]['type'] + ',', + '\t{' + str(api['extensions'][name]['version']['major']) + ', ' + str(api['extensions'][name]['version']['minor']) + '},', '\tNULL,' ] @@ -101,16 +115,17 @@ def _build_gdnative_api_struct_source(api): out += ['};\n'] - out += ['', 'const void *gdnative_extensions_pointers[] = {'] + out += ['', 'const godot_gdnative_api_struct *gdnative_extensions_pointers[] = {'] for name in api['extensions']: - out += ['\t(void *)&api_extension_' + name + '_struct,'] + out += ['\t(godot_gdnative_api_struct *)&api_extension_' + name + '_struct,'] out += ['};\n'] out += [ - 'extern const godot_gdnative_api_struct api_struct = {', + 'extern const godot_gdnative_core_api_struct api_struct = {', '\tGDNATIVE_' + api['core']['type'] + ',', + '\t{' + str(api['core']['version']['major']) + ', ' + str(api['core']['version']['minor']) + '},', '\tNULL,', '\t' + str(len(api['extensions'])) + ',', '\tgdnative_extensions_pointers,', diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 3fc04a5498..832a0cb859 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -41,7 +41,7 @@ const String init_symbol = "godot_gdnative_init"; const String terminate_symbol = "godot_gdnative_terminate"; // Defined in gdnative_api_struct.gen.cpp -extern const godot_gdnative_api_struct api_struct; +extern const godot_gdnative_core_api_struct api_struct; String GDNativeLibrary::platform_names[NUM_PLATFORMS + 1] = { "X11_32bit", diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 2a67911aac..da32dc06e8 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -1,6 +1,10 @@ { "core": { - "type": "CORE_1_0_0", + "type": "CORE", + "version": { + "major": 1, + "minor": 0 + }, "api": [ { "name": "godot_color_new_rgba", @@ -5604,7 +5608,11 @@ }, "extensions": { "nativescript": { - "type": "NATIVESCRIPT_1_0_0", + "type": "NATIVESCRIPT", + "version": { + "major": 1, + "minor": 0 + }, "api": [ { "name": "godot_nativescript_register_class", @@ -5670,7 +5678,11 @@ ] }, "pluginscript": { - "type": "PLUGINSCRIPT_1_0_0", + "type": "PLUGINSCRIPT", + "version": { + "major": 1, + "minor": 0 + }, "api": [ { "name": "godot_pluginscript_register_language", @@ -5682,7 +5694,11 @@ ] }, "nativearvr": { - "type": "NATIVEARVR_1_0_0", + "type": "NATIVEARVR", + "version": { + "major": 1, + "minor": 0 + }, "api": [ { "name": "godot_arvr_register_interface", diff --git a/modules/gdnative/include/gdnative/gdnative.h b/modules/gdnative/include/gdnative/gdnative.h index 25d45db306..8fa96fd3af 100644 --- a/modules/gdnative/include/gdnative/gdnative.h +++ b/modules/gdnative/include/gdnative/gdnative.h @@ -237,7 +237,7 @@ typedef struct { uint64_t editor_api_hash; uint64_t no_api_hash; godot_object *gd_native_library; // pointer to GDNativeLibrary that is being initialized - const struct godot_gdnative_api_struct *api_struct; + const struct godot_gdnative_core_api_struct *api_struct; const godot_string *active_library_path; } godot_gdnative_init_options; |