Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GDNative] refactored API struct into core and extensions #12779

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 55 additions & 7 deletions modules/gdnative/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,37 @@ def _build_gdnative_api_struct_header(api):
'extern "C" {',
'#endif',
'',
'enum GDNATIVE_API_TYPES {',
'\tGDNATIVE_' + api['core']['type'] + ','
]

for name in api['extensions']:
out += ['\tGDNATIVE_' + api['extensions'][name]['type'] + ',']

out += ['};', '']

for name in api['extensions']:
out += [
'typedef struct godot_gdnative_' + name + '_api_struct {',
'\tunsigned int type;',
'\tconst void *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 += [
'typedef struct godot_gdnative_api_struct {',
'\tvoid *next;',
'\tconst char *version;',
'\tunsigned int type;',
'\tconst void *next;',
'\tunsigned int num_extensions;',
'\tconst void **extensions;',
]

for funcdef in api['api']:
for funcdef in api['core']['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))

Expand All @@ -61,14 +86,37 @@ def _build_gdnative_api_struct_source(api):
'/* THIS FILE IS GENERATED DO NOT EDIT */',
'',
'#include <gdnative_api_struct.gen.h>',
'',
'const char *_gdnative_api_version = "%s";' % api['version'],
''
]

for name in api['extensions']:
out += [
'extern const godot_gdnative_' + name + '_api_struct api_extension_' + name + '_struct = {',
'\tGDNATIVE_' + api['extensions'][name]['type'] + ',',
'\tNULL,'
]

for funcdef in api['extensions'][name]['api']:
out.append('\t%s,' % funcdef['name'])

out += ['};\n']

out += ['', 'const void *gdnative_extensions_pointers[] = {']

for name in api['extensions']:
out += ['\t(void *)&api_extension_' + name + '_struct,']

out += ['};\n']

out += [
'extern const godot_gdnative_api_struct api_struct = {',
'\tGDNATIVE_' + api['core']['type'] + ',',
'\tNULL,',
'\t_gdnative_api_version,',
'\t' + str(len(api['extensions'])) + ',',
'\tgdnative_extensions_pointers,',
]

for funcdef in api['api']:
for funcdef in api['core']['api']:
out.append('\t%s,' % funcdef['name'])
out.append('};\n')

Expand Down
Loading