summaryrefslogtreecommitdiff
path: root/modules/gdnative/SCsub
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdnative/SCsub')
-rw-r--r--modules/gdnative/SCsub132
1 files changed, 115 insertions, 17 deletions
diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub
index a6ae143947..66b8d5cbdd 100644
--- a/modules/gdnative/SCsub
+++ b/modules/gdnative/SCsub
@@ -12,40 +12,94 @@ gdn_env.add_source_files(env.modules_sources, "nativescript/*.cpp")
gdn_env.Append(CPPPATH=['#modules/gdnative/include/'])
-SConscript("nativearvr/SCsub")
+SConscript("arvr/SCsub")
SConscript("pluginscript/SCsub")
def _spaced(e):
return e if e[-1] == '*' else e + ' '
def _build_gdnative_api_struct_header(api):
+ ext_wrappers = ''
+
+ for name in api['extensions']:
+ ext_wrappers += ' extern const godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct;'
+
+ ext_init = 'for (int i = 0; i < _gdnative_wrapper_api_struct->num_extensions; i++) { '
+ ext_init += 'switch (_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 += '}'
+
out = [
'/* THIS FILE IS GENERATED DO NOT EDIT */',
'#ifndef GODOT_GDNATIVE_API_STRUCT_H',
'#define GODOT_GDNATIVE_API_STRUCT_H',
'',
'#include <gdnative/gdnative.h>',
- '#include <nativearvr/godot_nativearvr.h>',
+ '#include <arvr/godot_arvr.h>',
'#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; _gdnative_wrapper_api_struct = options->api_struct; } while (0)',
+ '#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)',
'',
'#ifdef __cplusplus',
'extern "C" {',
'#endif',
'',
- 'typedef struct godot_gdnative_api_struct {',
- '\tvoid *next;',
- '\tconst char *version;',
+ 'typedef struct godot_gdnative_api_version {',
+ '\tunsigned int major;',
+ '\tunsigned int minor;',
+ '} godot_gdnative_api_version;',
+ '',
+ 'typedef struct godot_gdnative_api_struct godot_gdnative_api_struct;',
+ '',
+ 'struct godot_gdnative_api_struct {',
+ '\tunsigned int type;',
+ '\tgodot_gdnative_api_version version;',
+ '\tconst godot_gdnative_api_struct *next;',
+ '};',
+ '',
+ 'enum GDNATIVE_API_TYPES {',
+ '\tGDNATIVE_' + api['core']['type'] + ','
+ ]
+
+ for name in api['extensions']:
+ out += ['\tGDNATIVE_EXT_' + api['extensions'][name]['type'] + ',']
+
+ out += ['};', '']
+
+ for name in api['extensions']:
+ out += [
+ 'typedef struct godot_gdnative_ext_' + name + '_api_struct {',
+ '\tunsigned int type;',
+ '\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_ext_' + name + '_api_struct;', '']
+
+ out += [
+ 'typedef struct godot_gdnative_core_api_struct {',
+ '\tunsigned int type;',
+ '\tgodot_gdnative_api_version version;',
+ '\tconst godot_gdnative_api_struct *next;',
+ '\tunsigned int num_extensions;',
+ '\tconst godot_gdnative_api_struct **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))
out += [
- '} godot_gdnative_api_struct;',
+ '} godot_gdnative_core_api_struct;',
'',
'#ifdef __cplusplus',
'}',
@@ -61,14 +115,39 @@ 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'],
- 'extern const godot_gdnative_api_struct api_struct = {',
+ ''
+ ]
+
+ for name in api['extensions']:
+ out += [
+ '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,'
+ ]
+
+ for funcdef in api['extensions'][name]['api']:
+ out.append('\t%s,' % funcdef['name'])
+
+ out += ['};\n']
+
+ out += ['', 'const godot_gdnative_api_struct *gdnative_extensions_pointers[] = {']
+
+ for name in api['extensions']:
+ out += ['\t(godot_gdnative_api_struct *)&api_extension_' + name + '_struct,']
+
+ out += ['};\n']
+
+ out += [
+ '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_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')
@@ -101,18 +180,23 @@ def _build_gdnative_wrapper_code(api):
'#include <gdnative/gdnative.h>',
'#include <nativescript/godot_nativescript.h>',
'#include <pluginscript/godot_pluginscript.h>',
+ '#include <arvr/godot_arvr.h>',
'',
'#include <gdnative_api_struct.gen.h>',
'',
- 'godot_gdnative_api_struct *_gdnative_wrapper_api_struct = 0;',
- '',
'#ifdef __cplusplus',
'extern "C" {',
'#endif',
- ''
+ '',
+ 'godot_gdnative_core_api_struct *_gdnative_wrapper_api_struct = 0;',
]
- for funcdef in api['api']:
+ for name in api['extensions']:
+ out.append('godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct;')
+
+ out += ['']
+
+ for funcdef in api['core']['api']:
args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']])
out.append('%s%s(%s) {' % (_spaced(funcdef['return_type']), funcdef['name'], args))
@@ -125,6 +209,20 @@ def _build_gdnative_wrapper_code(api):
out.append('}')
out.append('')
+ for name in api['extensions']:
+ for funcdef in api['extensions'][name]['api']:
+ args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']])
+ out.append('%s%s(%s) {' % (_spaced(funcdef['return_type']), funcdef['name'], args))
+
+ args = ', '.join(['%s' % n for t, n in funcdef['arguments']])
+
+ return_line = '\treturn ' if funcdef['return_type'] != 'void' else '\t'
+ return_line += '_gdnative_wrapper_' + name + '_api_struct->' + funcdef['name'] + '(' + args + ');'
+
+ out.append(return_line)
+ out.append('}')
+ out.append('')
+
out += [
'#ifdef __cplusplus',
'}',