diff options
Diffstat (limited to 'modules/gdnative/SCsub')
-rw-r--r-- | modules/gdnative/SCsub | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub index 4e5f155f45..6592d0ae1d 100644 --- a/modules/gdnative/SCsub +++ b/modules/gdnative/SCsub @@ -30,12 +30,14 @@ def _build_gdnative_api_struct_header(api): 'extern "C" {', '#endif', '', - 'typedef struct godot_gdnative_api_struct {' + 'typedef struct godot_gdnative_api_struct {', + '\tvoid *next;', + '\tconst char *version;', ] - for funcname, funcdef in api['api'].items(): + for funcdef in api['api']: args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']]) - out.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcname, args)) + out.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args)) out += [ '} godot_gdnative_api_struct;', @@ -55,11 +57,14 @@ def _build_gdnative_api_struct_source(api): '', '#include <gdnative_api_struct.gen.h>', '', - 'extern const godot_gdnative_api_struct api_struct = {' + 'const char *_gdnative_api_version = "%s";' % api['version'], + 'extern const godot_gdnative_api_struct api_struct = {', + '\tNULL,', + '\t_gdnative_api_version,', ] - for funcname in api['api'].keys(): - out.append('\t%s,' % funcname) + for funcdef in api['api']: + out.append('\t%s,' % funcdef['name']) out.append('};\n') return '\n'.join(out) @@ -69,8 +74,7 @@ def build_gdnative_api_struct(target, source, env): from collections import OrderedDict with open(source[0].path, 'r') as fd: - # Keep the json ordered - api = json.load(fd, object_pairs_hook=OrderedDict) + api = json.load(fd) header, source = target with open(header.path, 'w') as fd: @@ -102,14 +106,14 @@ def _build_gdnative_wrapper_code(api): '' ] - for funcname, funcdef in api['api'].items(): + for funcdef in api['api']: args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']]) - out.append('%s %s(%s) {' % (_spaced(funcdef['return_type']), funcname, args)) + 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_api_struct->' + funcname + '(' + args + ');' + return_line += '_gdnative_wrapper_api_struct->' + funcdef['name'] + '(' + args + ');' out.append(return_line) out.append('}') @@ -127,7 +131,6 @@ def _build_gdnative_wrapper_code(api): def build_gdnative_wrapper_code(target, source, env): import json with open(source[0].path, 'r') as fd: -#Keep the json ordered api = json.load(fd) wrapper_file = target[0] @@ -138,7 +141,7 @@ def build_gdnative_wrapper_code(target, source, env): if ARGUMENTS.get('gdnative_wrapper', False): #build wrapper code - gdn_env.Command('gdnative_wrapper_code.gen.cpp', 'gdnative_api.json', build_gdnative_wrapper_code) + gensource, = gdn_env.Command('gdnative_wrapper_code.gen.cpp', 'gdnative_api.json', build_gdnative_wrapper_code) gd_wrapper_env = env.Clone() gd_wrapper_env.Append(CPPPATH=['#modules/gdnative/include/']) @@ -146,4 +149,4 @@ if ARGUMENTS.get('gdnative_wrapper', False): # I think this doesn't work on MSVC yet... gd_wrapper_env.Append(CCFLAGS=['-fPIC']) - gd_wrapper_env.Library("#bin/gdnative_wrapper_code", ["#modules/gdnative/gdnative_wrapper_code.gen.cpp"]) + gd_wrapper_env.Library("#bin/gdnative_wrapper_code", [gensource]) |