[GDNative] better API struct versioning

This commit is contained in:
Karroffel 2017-11-10 12:08:09 +01:00
parent fd4921375a
commit 7ae2de8997
4 changed files with 50 additions and 19 deletions

View file

@ -35,34 +35,47 @@ def _build_gdnative_api_struct_header(api):
'extern "C" {', 'extern "C" {',
'#endif', '#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 {', 'enum GDNATIVE_API_TYPES {',
'\tGDNATIVE_' + api['core']['type'] + ',' '\tGDNATIVE_' + api['core']['type'] + ','
] ]
for name in api['extensions']: for name in api['extensions']:
out += ['\tGDNATIVE_' + api['extensions'][name]['type'] + ','] out += ['\tGDNATIVE_EXT_' + api['extensions'][name]['type'] + ',']
out += ['};', ''] out += ['};', '']
for name in api['extensions']: for name in api['extensions']:
out += [ out += [
'typedef struct godot_gdnative_' + name + '_api_struct {', 'typedef struct godot_gdnative_ext_' + name + '_api_struct {',
'\tunsigned int type;', '\tunsigned int type;',
'\tconst void *next;' '\tgodot_gdnative_api_version version;',
'\tconst godot_gdnative_api_struct *next;'
] ]
for funcdef in api['extensions'][name]['api']: for funcdef in api['extensions'][name]['api']:
args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']]) 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.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 += [ out += [
'typedef struct godot_gdnative_api_struct {', 'typedef struct godot_gdnative_core_api_struct {',
'\tunsigned int type;', '\tunsigned int type;',
'\tconst void *next;', '\tgodot_gdnative_api_version version;',
'\tconst godot_gdnative_api_struct *next;',
'\tunsigned int num_extensions;', '\tunsigned int num_extensions;',
'\tconst void **extensions;', '\tconst godot_gdnative_api_struct **extensions;',
] ]
for funcdef in api['core']['api']: 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.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args))
out += [ out += [
'} godot_gdnative_api_struct;', '} godot_gdnative_core_api_struct;',
'', '',
'#ifdef __cplusplus', '#ifdef __cplusplus',
'}', '}',
@ -91,8 +104,9 @@ def _build_gdnative_api_struct_source(api):
for name in api['extensions']: for name in api['extensions']:
out += [ out += [
'extern const godot_gdnative_' + name + '_api_struct api_extension_' + name + '_struct = {', 'extern const godot_gdnative_ext_' + name + '_api_struct api_extension_' + name + '_struct = {',
'\tGDNATIVE_' + api['extensions'][name]['type'] + ',', '\tGDNATIVE_EXT_' + api['extensions'][name]['type'] + ',',
'\t{' + str(api['extensions'][name]['version']['major']) + ', ' + str(api['extensions'][name]['version']['minor']) + '},',
'\tNULL,' '\tNULL,'
] ]
@ -101,16 +115,17 @@ def _build_gdnative_api_struct_source(api):
out += ['};\n'] out += ['};\n']
out += ['', 'const void *gdnative_extensions_pointers[] = {'] out += ['', 'const godot_gdnative_api_struct *gdnative_extensions_pointers[] = {']
for name in api['extensions']: 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 += ['};\n']
out += [ out += [
'extern const godot_gdnative_api_struct api_struct = {', 'extern const godot_gdnative_core_api_struct api_struct = {',
'\tGDNATIVE_' + api['core']['type'] + ',', '\tGDNATIVE_' + api['core']['type'] + ',',
'\t{' + str(api['core']['version']['major']) + ', ' + str(api['core']['version']['minor']) + '},',
'\tNULL,', '\tNULL,',
'\t' + str(len(api['extensions'])) + ',', '\t' + str(len(api['extensions'])) + ',',
'\tgdnative_extensions_pointers,', '\tgdnative_extensions_pointers,',

View file

@ -41,7 +41,7 @@ const String init_symbol = "godot_gdnative_init";
const String terminate_symbol = "godot_gdnative_terminate"; const String terminate_symbol = "godot_gdnative_terminate";
// Defined in gdnative_api_struct.gen.cpp // 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] = { String GDNativeLibrary::platform_names[NUM_PLATFORMS + 1] = {
"X11_32bit", "X11_32bit",

View file

@ -1,6 +1,10 @@
{ {
"core": { "core": {
"type": "CORE_1_0_0", "type": "CORE",
"version": {
"major": 1,
"minor": 0
},
"api": [ "api": [
{ {
"name": "godot_color_new_rgba", "name": "godot_color_new_rgba",
@ -5604,7 +5608,11 @@
}, },
"extensions": { "extensions": {
"nativescript": { "nativescript": {
"type": "NATIVESCRIPT_1_0_0", "type": "NATIVESCRIPT",
"version": {
"major": 1,
"minor": 0
},
"api": [ "api": [
{ {
"name": "godot_nativescript_register_class", "name": "godot_nativescript_register_class",
@ -5670,7 +5678,11 @@
] ]
}, },
"pluginscript": { "pluginscript": {
"type": "PLUGINSCRIPT_1_0_0", "type": "PLUGINSCRIPT",
"version": {
"major": 1,
"minor": 0
},
"api": [ "api": [
{ {
"name": "godot_pluginscript_register_language", "name": "godot_pluginscript_register_language",
@ -5682,7 +5694,11 @@
] ]
}, },
"nativearvr": { "nativearvr": {
"type": "NATIVEARVR_1_0_0", "type": "NATIVEARVR",
"version": {
"major": 1,
"minor": 0
},
"api": [ "api": [
{ {
"name": "godot_arvr_register_interface", "name": "godot_arvr_register_interface",

View file

@ -237,7 +237,7 @@ typedef struct {
uint64_t editor_api_hash; uint64_t editor_api_hash;
uint64_t no_api_hash; uint64_t no_api_hash;
godot_object *gd_native_library; // pointer to GDNativeLibrary that is being initialized 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; const godot_string *active_library_path;
} godot_gdnative_init_options; } godot_gdnative_init_options;