summaryrefslogtreecommitdiff
path: root/modules/gdnative
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdnative')
-rw-r--r--modules/gdnative/SCsub257
-rw-r--r--modules/gdnative/arvr/arvr_interface_gdnative.cpp2
-rw-r--r--modules/gdnative/arvr/arvr_interface_gdnative.h2
-rw-r--r--modules/gdnative/config.py2
-rw-r--r--modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml15
-rw-r--r--modules/gdnative/doc_classes/PacketPeerGDNative.xml15
-rw-r--r--modules/gdnative/doc_classes/StreamPeerGDNative.xml15
-rw-r--r--modules/gdnative/gdnative.cpp10
-rw-r--r--modules/gdnative/gdnative.h6
-rw-r--r--modules/gdnative/gdnative/string.cpp14
-rw-r--r--modules/gdnative/gdnative_builders.py261
-rw-r--r--modules/gdnative/nativescript/api_generator.cpp2
-rw-r--r--modules/gdnative/nativescript/nativescript.cpp33
-rw-r--r--modules/gdnative/nativescript/nativescript.h2
-rw-r--r--modules/gdnative/pluginscript/pluginscript_language.cpp2
-rw-r--r--modules/gdnative/pluginscript/pluginscript_language.h2
-rw-r--r--modules/gdnative/register_types.cpp8
17 files changed, 356 insertions, 292 deletions
diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub
index 116a86b27b..46b2a832f1 100644
--- a/modules/gdnative/SCsub
+++ b/modules/gdnative/SCsub
@@ -17,268 +17,19 @@ SConscript("net/SCsub")
SConscript("arvr/SCsub")
SConscript("pluginscript/SCsub")
-def _spaced(e):
- return e if e[-1] == '*' else e + ' '
+from platform_methods import run_in_subprocess
+import gdnative_builders
-def _build_gdnative_api_struct_header(api):
- gdnative_api_init_macro = [
- '\textern const godot_gdnative_core_api_struct *_gdnative_wrapper_api_struct;'
- ]
-
- for ext in api['extensions']:
- name = ext['name']
- gdnative_api_init_macro.append(
- '\textern const godot_gdnative_ext_{0}_api_struct *_gdnative_wrapper_{0}_api_struct;'.format(name))
-
- gdnative_api_init_macro.append('\t_gdnative_wrapper_api_struct = options->api_struct;')
- gdnative_api_init_macro.append('\tfor (unsigned int i = 0; i < _gdnative_wrapper_api_struct->num_extensions; i++) { ')
- gdnative_api_init_macro.append('\t\tswitch (_gdnative_wrapper_api_struct->extensions[i]->type) {')
-
- for ext in api['extensions']:
- name = ext['name']
- gdnative_api_init_macro.append(
- '\t\t\tcase GDNATIVE_EXT_%s:' % ext['type'])
- gdnative_api_init_macro.append(
- '\t\t\t\t_gdnative_wrapper_{0}_api_struct = (godot_gdnative_ext_{0}_api_struct *)'
- ' _gdnative_wrapper_api_struct->extensions[i];'.format(name))
- gdnative_api_init_macro.append('\t\t\t\tbreak;')
- gdnative_api_init_macro.append('\t\t}')
- gdnative_api_init_macro.append('\t}')
-
- 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 <android/godot_android.h>',
- '#include <arvr/godot_arvr.h>',
- '#include <nativescript/godot_nativescript.h>',
- '#include <pluginscript/godot_pluginscript.h>',
- '',
- '#define GDNATIVE_API_INIT(options) do { \\\n' + ' \\\n'.join(gdnative_api_init_macro) + ' \\\n } while (0)',
- '',
- '#ifdef __cplusplus',
- 'extern "C" {',
- '#endif',
- '',
- 'enum GDNATIVE_API_TYPES {',
- '\tGDNATIVE_' + api['core']['type'] + ','
- ]
-
- for ext in api['extensions']:
- out += ['\tGDNATIVE_EXT_' + ext['type'] + ',']
-
- out += ['};', '']
-
-
- def generate_extension_struct(name, ext, include_version=True):
- ret_val = []
- if ext['next']:
- ret_val += generate_extension_struct(name, ext['next'])
-
- ret_val += [
- 'typedef struct godot_gdnative_ext_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_api_struct {',
- '\tunsigned int type;',
- '\tgodot_gdnative_api_version version;',
- '\tconst godot_gdnative_api_struct *next;'
- ]
-
- for funcdef in ext['api']:
- args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']])
- ret_val.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args))
-
- ret_val += ['} godot_gdnative_ext_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_api_struct;', '']
-
- return ret_val
-
-
- for ext in api['extensions']:
- name = ext['name']
- out += generate_extension_struct(name, ext, False)
-
- 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['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_core_api_struct;',
- '',
- '#ifdef __cplusplus',
- '}',
- '#endif',
- '',
- '#endif // GODOT_GDNATIVE_API_STRUCT_H',
- ''
- ]
- return '\n'.join(out)
-
-def _build_gdnative_api_struct_source(api):
- out = [
- '/* THIS FILE IS GENERATED DO NOT EDIT */',
- '',
- '#include <gdnative_api_struct.gen.h>',
- ''
- ]
-
- def get_extension_struct_name(name, ext, include_version=True):
- return 'godot_gdnative_ext_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_api_struct'
-
- def get_extension_struct_instance_name(name, ext, include_version=True):
- return 'api_extension_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_struct'
-
- def get_extension_struct_definition(name, ext, include_version=True):
-
- ret_val = []
-
- if ext['next']:
- ret_val += get_extension_struct_definition(name, ext['next'])
-
- ret_val += [
- 'extern const ' + get_extension_struct_name(name, ext, include_version) + ' ' + get_extension_struct_instance_name(name, ext, include_version) + ' = {',
- '\tGDNATIVE_EXT_' + ext['type'] + ',',
- '\t{' + str(ext['version']['major']) + ', ' + str(ext['version']['minor']) + '},',
- '\t' + ('NULL' if not ext['next'] else ('(const godot_gdnative_api_struct *)&' + get_extension_struct_instance_name(name, ext['next']))) + ','
- ]
-
- for funcdef in ext['api']:
- ret_val.append('\t%s,' % funcdef['name'])
-
- ret_val += ['};\n']
-
- return ret_val
-
- for ext in api['extensions']:
- name = ext['name']
- out += get_extension_struct_definition(name, ext, False)
-
- out += ['', 'const godot_gdnative_api_struct *gdnative_extensions_pointers[] = {']
-
- for ext in api['extensions']:
- name = ext['name']
- 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' + str(len(api['extensions'])) + ',',
- '\tgdnative_extensions_pointers,',
- ]
-
- for funcdef in api['core']['api']:
- out.append('\t%s,' % funcdef['name'])
- out.append('};\n')
-
- return '\n'.join(out)
-
-def build_gdnative_api_struct(target, source, env):
- import json
- from collections import OrderedDict
-
- with open(source[0].path, 'r') as fd:
- api = json.load(fd)
-
- header, source = target
- with open(header.path, 'w') as fd:
- fd.write(_build_gdnative_api_struct_header(api))
- with open(source.path, 'w') as fd:
- fd.write(_build_gdnative_api_struct_source(api))
_, gensource = gdn_env.CommandNoCache(['include/gdnative_api_struct.gen.h', 'gdnative_api_struct.gen.cpp'],
- 'gdnative_api.json', build_gdnative_api_struct)
+ 'gdnative_api.json', run_in_subprocess(gdnative_builders.build_gdnative_api_struct))
gdn_env.add_source_files(env.modules_sources, [gensource])
env.use_ptrcall = True
-def _build_gdnative_wrapper_code(api):
- out = [
- '/* THIS FILE IS GENERATED DO NOT EDIT */',
- '',
- '#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>',
- '',
- '#ifdef __cplusplus',
- 'extern "C" {',
- '#endif',
- '',
- 'godot_gdnative_core_api_struct *_gdnative_wrapper_api_struct = 0;',
- ]
-
- for ext in api['extensions']:
- name = ext['name']
- out.append('godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct = 0;')
-
- 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))
-
- 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->' + funcdef['name'] + '(' + args + ');'
-
- out.append(return_line)
- out.append('}')
- out.append('')
-
- for ext in api['extensions']:
- name = ext['name']
- for funcdef in ext['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',
- '}',
- '#endif'
- ]
-
- return '\n'.join(out)
-
-
-def build_gdnative_wrapper_code(target, source, env):
- import json
- with open(source[0].path, 'r') as fd:
- api = json.load(fd)
-
- wrapper_file = target[0]
- with open(wrapper_file.path, 'w') as fd:
- fd.write(_build_gdnative_wrapper_code(api))
-
-
-
if ARGUMENTS.get('gdnative_wrapper', False):
-#build wrapper code
- gensource, = gdn_env.CommandNoCache('gdnative_wrapper_code.gen.cpp', 'gdnative_api.json', build_gdnative_wrapper_code)
+ gensource, = gdn_env.CommandNoCache('gdnative_wrapper_code.gen.cpp', 'gdnative_api.json', run_in_subprocess(gdnative_builders.build_gdnative_wrapper_code))
gd_wrapper_env = env.Clone()
gd_wrapper_env.Append(CPPPATH=['#modules/gdnative/include/'])
diff --git a/modules/gdnative/arvr/arvr_interface_gdnative.cpp b/modules/gdnative/arvr/arvr_interface_gdnative.cpp
index 385c020a78..b525725107 100644
--- a/modules/gdnative/arvr/arvr_interface_gdnative.cpp
+++ b/modules/gdnative/arvr/arvr_interface_gdnative.cpp
@@ -125,7 +125,7 @@ bool ARVRInterfaceGDNative::is_stereo() {
return stereo;
}
-bool ARVRInterfaceGDNative::is_initialized() {
+bool ARVRInterfaceGDNative::is_initialized() const {
bool initialized;
ERR_FAIL_COND_V(interface == NULL, false);
diff --git a/modules/gdnative/arvr/arvr_interface_gdnative.h b/modules/gdnative/arvr/arvr_interface_gdnative.h
index e50be6e196..26d0cdf9f4 100644
--- a/modules/gdnative/arvr/arvr_interface_gdnative.h
+++ b/modules/gdnative/arvr/arvr_interface_gdnative.h
@@ -59,7 +59,7 @@ public:
virtual StringName get_name() const;
virtual int get_capabilities() const;
- virtual bool is_initialized();
+ virtual bool is_initialized() const;
virtual bool initialize();
virtual void uninitialize();
diff --git a/modules/gdnative/config.py b/modules/gdnative/config.py
index c5b37d35b4..701a13d32f 100644
--- a/modules/gdnative/config.py
+++ b/modules/gdnative/config.py
@@ -9,9 +9,11 @@ def get_doc_classes():
"ARVRInterfaceGDNative",
"GDNative",
"GDNativeLibrary",
+ "MultiplayerPeerGDNative",
"NativeScript",
"PacketPeerGDNative",
"PluginScript",
+ "StreamPeerGDNative",
]
def get_doc_path():
diff --git a/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml b/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml
new file mode 100644
index 0000000000..4433179726
--- /dev/null
+++ b/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="MultiplayerPeerGDNative" inherits="NetworkedMultiplayerPeer" category="Core" version="3.1">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <demos>
+ </demos>
+ <methods>
+ </methods>
+ <constants>
+ </constants>
+</class>
diff --git a/modules/gdnative/doc_classes/PacketPeerGDNative.xml b/modules/gdnative/doc_classes/PacketPeerGDNative.xml
new file mode 100644
index 0000000000..0ae54bc9c7
--- /dev/null
+++ b/modules/gdnative/doc_classes/PacketPeerGDNative.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="PacketPeerGDNative" inherits="PacketPeer" category="Core" version="3.1">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <demos>
+ </demos>
+ <methods>
+ </methods>
+ <constants>
+ </constants>
+</class>
diff --git a/modules/gdnative/doc_classes/StreamPeerGDNative.xml b/modules/gdnative/doc_classes/StreamPeerGDNative.xml
new file mode 100644
index 0000000000..d86cd2c25a
--- /dev/null
+++ b/modules/gdnative/doc_classes/StreamPeerGDNative.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<class name="StreamPeerGDNative" inherits="StreamPeer" category="Core" version="3.1">
+ <brief_description>
+ </brief_description>
+ <description>
+ </description>
+ <tutorials>
+ </tutorials>
+ <demos>
+ </demos>
+ <methods>
+ </methods>
+ <constants>
+ </constants>
+</class>
diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp
index e7ebcc73af..0acd6c27d8 100644
--- a/modules/gdnative/gdnative.cpp
+++ b/modules/gdnative/gdnative.cpp
@@ -277,7 +277,7 @@ void GDNative::set_library(Ref<GDNativeLibrary> p_library) {
library = p_library;
}
-Ref<GDNativeLibrary> GDNative::get_library() {
+Ref<GDNativeLibrary> GDNative::get_library() const {
return library;
}
@@ -373,7 +373,7 @@ bool GDNative::initialize() {
if (library->should_load_once() && !GDNativeLibrary::loaded_libraries->has(lib_path)) {
Vector<Ref<GDNative> > gdnatives;
gdnatives.resize(1);
- gdnatives[0] = Ref<GDNative>(this);
+ gdnatives.write[0] = Ref<GDNative>(this);
GDNativeLibrary::loaded_libraries->insert(lib_path, gdnatives);
}
@@ -428,7 +428,7 @@ bool GDNative::terminate() {
return true;
}
-bool GDNative::is_initialized() {
+bool GDNative::is_initialized() const {
return initialized;
}
@@ -442,7 +442,7 @@ Vector<StringName> GDNativeCallRegistry::get_native_call_types() {
size_t idx = 0;
for (Map<StringName, native_call_cb>::Element *E = native_calls.front(); E; E = E->next(), idx++) {
- call_types[idx] = E->key();
+ call_types.write[idx] = E->key();
}
return call_types;
@@ -474,7 +474,7 @@ Variant GDNative::call_native(StringName p_native_call_type, StringName p_proced
return res;
}
-Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle, bool p_optional) {
+Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle, bool p_optional) const {
if (!initialized) {
ERR_PRINT("No valid library handle, can't get symbol from GDNative object");
diff --git a/modules/gdnative/gdnative.h b/modules/gdnative/gdnative.h
index b17bb94f1c..148f85723e 100644
--- a/modules/gdnative/gdnative.h
+++ b/modules/gdnative/gdnative.h
@@ -148,16 +148,16 @@ public:
static void _bind_methods();
void set_library(Ref<GDNativeLibrary> p_library);
- Ref<GDNativeLibrary> get_library();
+ Ref<GDNativeLibrary> get_library() const;
- bool is_initialized();
+ bool is_initialized() const;
bool initialize();
bool terminate();
Variant call_native(StringName p_native_call_type, StringName p_procedure_name, Array p_arguments = Array());
- Error get_symbol(StringName p_procedure_name, void *&r_handle, bool p_optional = true);
+ Error get_symbol(StringName p_procedure_name, void *&r_handle, bool p_optional = true) const;
};
class GDNativeLibraryResourceLoader : public ResourceFormatLoader {
diff --git a/modules/gdnative/gdnative/string.cpp b/modules/gdnative/gdnative/string.cpp
index 7f5dbc12be..8ca57392a3 100644
--- a/modules/gdnative/gdnative/string.cpp
+++ b/modules/gdnative/gdnative/string.cpp
@@ -207,7 +207,7 @@ godot_int GDAPI godot_string_findmk(const godot_string *p_self, const godot_arra
Array *keys_proxy = (Array *)p_keys;
keys.resize(keys_proxy->size());
for (int i = 0; i < keys_proxy->size(); i++) {
- keys[i] = (*keys_proxy)[i];
+ keys.write[i] = (*keys_proxy)[i];
}
return self->findmk(keys);
@@ -220,7 +220,7 @@ godot_int GDAPI godot_string_findmk_from(const godot_string *p_self, const godot
Array *keys_proxy = (Array *)p_keys;
keys.resize(keys_proxy->size());
for (int i = 0; i < keys_proxy->size(); i++) {
- keys[i] = (*keys_proxy)[i];
+ keys.write[i] = (*keys_proxy)[i];
}
return self->findmk(keys, p_from);
@@ -233,7 +233,7 @@ godot_int GDAPI godot_string_findmk_from_in_place(const godot_string *p_self, co
Array *keys_proxy = (Array *)p_keys;
keys.resize(keys_proxy->size());
for (int i = 0; i < keys_proxy->size(); i++) {
- keys[i] = (*keys_proxy)[i];
+ keys.write[i] = (*keys_proxy)[i];
}
return self->findmk(keys, p_from, r_key);
@@ -696,7 +696,7 @@ godot_array GDAPI godot_string_split_floats_mk(const godot_string *p_self, const
Array *splitter_proxy = (Array *)p_splitters;
splitters.resize(splitter_proxy->size());
for (int i = 0; i < splitter_proxy->size(); i++) {
- splitters[i] = (*splitter_proxy)[i];
+ splitters.write[i] = (*splitter_proxy)[i];
}
godot_array result;
@@ -719,7 +719,7 @@ godot_array GDAPI godot_string_split_floats_mk_allows_empty(const godot_string *
Array *splitter_proxy = (Array *)p_splitters;
splitters.resize(splitter_proxy->size());
for (int i = 0; i < splitter_proxy->size(); i++) {
- splitters[i] = (*splitter_proxy)[i];
+ splitters.write[i] = (*splitter_proxy)[i];
}
godot_array result;
@@ -774,7 +774,7 @@ godot_array GDAPI godot_string_split_ints_mk(const godot_string *p_self, const g
Array *splitter_proxy = (Array *)p_splitters;
splitters.resize(splitter_proxy->size());
for (int i = 0; i < splitter_proxy->size(); i++) {
- splitters[i] = (*splitter_proxy)[i];
+ splitters.write[i] = (*splitter_proxy)[i];
}
godot_array result;
@@ -797,7 +797,7 @@ godot_array GDAPI godot_string_split_ints_mk_allows_empty(const godot_string *p_
Array *splitter_proxy = (Array *)p_splitters;
splitters.resize(splitter_proxy->size());
for (int i = 0; i < splitter_proxy->size(); i++) {
- splitters[i] = (*splitter_proxy)[i];
+ splitters.write[i] = (*splitter_proxy)[i];
}
godot_array result;
diff --git a/modules/gdnative/gdnative_builders.py b/modules/gdnative/gdnative_builders.py
new file mode 100644
index 0000000000..8a1cd049af
--- /dev/null
+++ b/modules/gdnative/gdnative_builders.py
@@ -0,0 +1,261 @@
+"""Functions used to generate source files during build time
+
+All such functions are invoked in a subprocess on Windows to prevent build flakiness.
+
+"""
+import json
+from platform_methods import subprocess_main
+
+
+def _spaced(e):
+ return e if e[-1] == '*' else e + ' '
+
+
+def _build_gdnative_api_struct_header(api):
+ gdnative_api_init_macro = [
+ '\textern const godot_gdnative_core_api_struct *_gdnative_wrapper_api_struct;'
+ ]
+
+ for ext in api['extensions']:
+ name = ext['name']
+ gdnative_api_init_macro.append(
+ '\textern const godot_gdnative_ext_{0}_api_struct *_gdnative_wrapper_{0}_api_struct;'.format(name))
+
+ gdnative_api_init_macro.append('\t_gdnative_wrapper_api_struct = options->api_struct;')
+ gdnative_api_init_macro.append('\tfor (unsigned int i = 0; i < _gdnative_wrapper_api_struct->num_extensions; i++) { ')
+ gdnative_api_init_macro.append('\t\tswitch (_gdnative_wrapper_api_struct->extensions[i]->type) {')
+
+ for ext in api['extensions']:
+ name = ext['name']
+ gdnative_api_init_macro.append(
+ '\t\t\tcase GDNATIVE_EXT_%s:' % ext['type'])
+ gdnative_api_init_macro.append(
+ '\t\t\t\t_gdnative_wrapper_{0}_api_struct = (godot_gdnative_ext_{0}_api_struct *)'
+ ' _gdnative_wrapper_api_struct->extensions[i];'.format(name))
+ gdnative_api_init_macro.append('\t\t\t\tbreak;')
+ gdnative_api_init_macro.append('\t\t}')
+ gdnative_api_init_macro.append('\t}')
+
+ 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 <android/godot_android.h>',
+ '#include <arvr/godot_arvr.h>',
+ '#include <nativescript/godot_nativescript.h>',
+ '#include <pluginscript/godot_pluginscript.h>',
+ '',
+ '#define GDNATIVE_API_INIT(options) do { \\\n' + ' \\\n'.join(gdnative_api_init_macro) + ' \\\n } while (0)',
+ '',
+ '#ifdef __cplusplus',
+ 'extern "C" {',
+ '#endif',
+ '',
+ 'enum GDNATIVE_API_TYPES {',
+ '\tGDNATIVE_' + api['core']['type'] + ','
+ ]
+
+ for ext in api['extensions']:
+ out += ['\tGDNATIVE_EXT_' + ext['type'] + ',']
+
+ out += ['};', '']
+
+ def generate_extension_struct(name, ext, include_version=True):
+ ret_val = []
+ if ext['next']:
+ ret_val += generate_extension_struct(name, ext['next'])
+
+ ret_val += [
+ 'typedef struct godot_gdnative_ext_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_api_struct {',
+ '\tunsigned int type;',
+ '\tgodot_gdnative_api_version version;',
+ '\tconst godot_gdnative_api_struct *next;'
+ ]
+
+ for funcdef in ext['api']:
+ args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']])
+ ret_val.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args))
+
+ ret_val += ['} godot_gdnative_ext_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_api_struct;', '']
+
+ return ret_val
+
+ for ext in api['extensions']:
+ name = ext['name']
+ out += generate_extension_struct(name, ext, False)
+
+ 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['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_core_api_struct;',
+ '',
+ '#ifdef __cplusplus',
+ '}',
+ '#endif',
+ '',
+ '#endif // GODOT_GDNATIVE_API_STRUCT_H',
+ ''
+ ]
+ return '\n'.join(out)
+
+
+def _build_gdnative_api_struct_source(api):
+ out = [
+ '/* THIS FILE IS GENERATED DO NOT EDIT */',
+ '',
+ '#include <gdnative_api_struct.gen.h>',
+ ''
+ ]
+
+ def get_extension_struct_name(name, ext, include_version=True):
+ return 'godot_gdnative_ext_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_api_struct'
+
+ def get_extension_struct_instance_name(name, ext, include_version=True):
+ return 'api_extension_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_struct'
+
+ def get_extension_struct_definition(name, ext, include_version=True):
+
+ ret_val = []
+
+ if ext['next']:
+ ret_val += get_extension_struct_definition(name, ext['next'])
+
+ ret_val += [
+ 'extern const ' + get_extension_struct_name(name, ext, include_version) + ' ' + get_extension_struct_instance_name(name, ext, include_version) + ' = {',
+ '\tGDNATIVE_EXT_' + ext['type'] + ',',
+ '\t{' + str(ext['version']['major']) + ', ' + str(ext['version']['minor']) + '},',
+ '\t' + ('NULL' if not ext['next'] else ('(const godot_gdnative_api_struct *)&' + get_extension_struct_instance_name(name, ext['next']))) + ','
+ ]
+
+ for funcdef in ext['api']:
+ ret_val.append('\t%s,' % funcdef['name'])
+
+ ret_val += ['};\n']
+
+ return ret_val
+
+ for ext in api['extensions']:
+ name = ext['name']
+ out += get_extension_struct_definition(name, ext, False)
+
+ out += ['', 'const godot_gdnative_api_struct *gdnative_extensions_pointers[] = {']
+
+ for ext in api['extensions']:
+ name = ext['name']
+ 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' + str(len(api['extensions'])) + ',',
+ '\tgdnative_extensions_pointers,',
+ ]
+
+ for funcdef in api['core']['api']:
+ out.append('\t%s,' % funcdef['name'])
+ out.append('};\n')
+
+ return '\n'.join(out)
+
+
+def build_gdnative_api_struct(target, source, env):
+
+ with open(source[0], 'r') as fd:
+ api = json.load(fd)
+
+ header, source = target
+ with open(header, 'w') as fd:
+ fd.write(_build_gdnative_api_struct_header(api))
+ with open(source, 'w') as fd:
+ fd.write(_build_gdnative_api_struct_source(api))
+
+
+def _build_gdnative_wrapper_code(api):
+ out = [
+ '/* THIS FILE IS GENERATED DO NOT EDIT */',
+ '',
+ '#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>',
+ '',
+ '#ifdef __cplusplus',
+ 'extern "C" {',
+ '#endif',
+ '',
+ 'godot_gdnative_core_api_struct *_gdnative_wrapper_api_struct = 0;',
+ ]
+
+ for ext in api['extensions']:
+ name = ext['name']
+ out.append('godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct = 0;')
+
+ 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))
+
+ 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->' + funcdef['name'] + '(' + args + ');'
+
+ out.append(return_line)
+ out.append('}')
+ out.append('')
+
+ for ext in api['extensions']:
+ name = ext['name']
+ for funcdef in ext['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',
+ '}',
+ '#endif'
+ ]
+
+ return '\n'.join(out)
+
+
+def build_gdnative_wrapper_code(target, source, env):
+ with open(source[0], 'r') as fd:
+ api = json.load(fd)
+
+ wrapper_file = target[0]
+ with open(wrapper_file, 'w') as fd:
+ fd.write(_build_gdnative_wrapper_code(api))
+
+
+if __name__ == '__main__':
+ subprocess_main(globals())
diff --git a/modules/gdnative/nativescript/api_generator.cpp b/modules/gdnative/nativescript/api_generator.cpp
index 4012e821bb..70ca8d68b8 100644
--- a/modules/gdnative/nativescript/api_generator.cpp
+++ b/modules/gdnative/nativescript/api_generator.cpp
@@ -110,7 +110,6 @@ struct ClassAPI {
bool is_singleton;
bool is_instanciable;
// @Unclear
- bool is_creatable;
bool is_reference;
List<MethodAPI> methods;
@@ -385,7 +384,6 @@ static List<String> generate_c_api_json(const List<ClassAPI> &p_api) {
source.push_back(String("\t\t\"instanciable\": ") + (api.is_instanciable ? "true" : "false") + ",\n");
source.push_back(String("\t\t\"is_reference\": ") + (api.is_reference ? "true" : "false") + ",\n");
// @Unclear
- // source.push_back(String("\t\t\"createable\": ") + (api.is_creatable ? "true" : "false") + ",\n");
source.push_back("\t\t\"constants\": {\n");
for (List<ConstantAPI>::Element *e = api.constants.front(); e; e = e->next()) {
diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp
index 7bab718b81..0f3b497c94 100644
--- a/modules/gdnative/nativescript/nativescript.cpp
+++ b/modules/gdnative/nativescript/nativescript.cpp
@@ -149,7 +149,10 @@ Ref<Script> NativeScript::get_base_script() const {
if (!script_data)
return Ref<Script>();
- Ref<NativeScript> ns = Ref<NativeScript>(NSL->create_script());
+ NativeScript *script = (NativeScript *)NSL->create_script();
+ Ref<NativeScript> ns = Ref<NativeScript>(script);
+ ERR_FAIL_COND_V(!ns.is_valid(), Ref<Script>());
+
ns->set_class_name(script_data->base);
ns->set_library(get_library());
return ns;
@@ -553,12 +556,17 @@ bool NativeScriptInstance::set(const StringName &p_name, const Variant &p_value)
Variant name = p_name;
const Variant *args[2] = { &name, &p_value };
- E->get().method.method((godot_object *)owner,
+ godot_variant result;
+ result = E->get().method.method((godot_object *)owner,
E->get().method.method_data,
userdata,
2,
(godot_variant **)args);
- return true;
+ bool handled = *(Variant *)&result;
+ godot_variant_destroy(&result);
+ if (handled) {
+ return true;
+ }
}
script_data = script_data->base_data;
@@ -593,10 +601,9 @@ bool NativeScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
(godot_variant **)args);
r_ret = *(Variant *)&result;
godot_variant_destroy(&result);
- if (r_ret.get_type() == Variant::NIL) {
- return false;
+ if (r_ret.get_type() != Variant::NIL) {
+ return true;
}
- return true;
}
script_data = script_data->base_data;
@@ -1053,7 +1060,7 @@ Ref<Script> NativeScriptLanguage::get_template(const String &p_class_name, const
s->set_class_name(p_class_name);
return Ref<NativeScript>(s);
}
-bool NativeScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions) const {
+bool NativeScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const {
return true;
}
@@ -1154,8 +1161,8 @@ int NativeScriptLanguage::register_binding_functions(godot_instance_binding_func
}
// set the functions
- binding_functions[idx].first = true;
- binding_functions[idx].second = p_binding_functions;
+ binding_functions.write[idx].first = true;
+ binding_functions.write[idx].second = p_binding_functions;
return idx;
}
@@ -1170,7 +1177,7 @@ void NativeScriptLanguage::unregister_binding_functions(int p_idx) {
binding_functions[p_idx].second.free_instance_binding_data(binding_functions[p_idx].second.data, binding_data[p_idx]);
}
- binding_functions[p_idx].first = false;
+ binding_functions.write[p_idx].first = false;
if (binding_functions[p_idx].second.free_func)
binding_functions[p_idx].second.free_func(binding_functions[p_idx].second.data);
@@ -1196,7 +1203,7 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec
binding_data->resize(p_idx + 1);
for (int i = old_size; i <= p_idx; i++) {
- (*binding_data)[i] = NULL;
+ (*binding_data).write[i] = NULL;
}
}
@@ -1205,7 +1212,7 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec
const void *global_type_tag = global_type_tags[p_idx].get(p_object->get_class_name());
// no binding data yet, soooooo alloc new one \o/
- (*binding_data)[p_idx] = binding_functions[p_idx].second.alloc_instance_binding_data(binding_functions[p_idx].second.data, global_type_tag, (godot_object *)p_object);
+ (*binding_data).write[p_idx] = binding_functions[p_idx].second.alloc_instance_binding_data(binding_functions[p_idx].second.data, global_type_tag, (godot_object *)p_object);
}
return (*binding_data)[p_idx];
@@ -1218,7 +1225,7 @@ void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) {
binding_data->resize(binding_functions.size());
for (int i = 0; i < binding_functions.size(); i++) {
- (*binding_data)[i] = NULL;
+ (*binding_data).write[i] = NULL;
}
binding_instances.insert(binding_data);
diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h
index be093dde4b..688ed295db 100644
--- a/modules/gdnative/nativescript/nativescript.h
+++ b/modules/gdnative/nativescript/nativescript.h
@@ -295,7 +295,7 @@ public:
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
virtual void get_string_delimiters(List<String> *p_delimiters) const;
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
- virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions) const;
+ virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings = NULL, Set<int> *r_safe_lines = NULL) const;
virtual Script *create_script() const;
virtual bool has_named_classes() const;
virtual bool supports_builtin_mode() const;
diff --git a/modules/gdnative/pluginscript/pluginscript_language.cpp b/modules/gdnative/pluginscript/pluginscript_language.cpp
index 8018178bd5..2b538c4a36 100644
--- a/modules/gdnative/pluginscript/pluginscript_language.cpp
+++ b/modules/gdnative/pluginscript/pluginscript_language.cpp
@@ -108,7 +108,7 @@ Ref<Script> PluginScriptLanguage::get_template(const String &p_class_name, const
return script;
}
-bool PluginScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions) const {
+bool PluginScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const {
PoolStringArray functions;
if (_desc.validate) {
bool ret = _desc.validate(
diff --git a/modules/gdnative/pluginscript/pluginscript_language.h b/modules/gdnative/pluginscript/pluginscript_language.h
index 709345885b..c4df6f3a33 100644
--- a/modules/gdnative/pluginscript/pluginscript_language.h
+++ b/modules/gdnative/pluginscript/pluginscript_language.h
@@ -74,7 +74,7 @@ public:
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
virtual void get_string_delimiters(List<String> *p_delimiters) const;
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
- virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL) const;
+ virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL, List<ScriptLanguage::Warning> *r_warnings = NULL, Set<int> *r_safe_lines = NULL) const;
virtual Script *create_script() const;
virtual bool has_named_classes() const;
virtual bool supports_builtin_mode() const;
diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp
index d18297f2f8..ae1a218392 100644
--- a/modules/gdnative/register_types.cpp
+++ b/modules/gdnative/register_types.cpp
@@ -341,10 +341,10 @@ void register_gdnative_types() {
Ref<GDNativeLibrary> lib = ResourceLoader::load(path);
- singleton_gdnatives[i].instance();
- singleton_gdnatives[i]->set_library(lib);
+ singleton_gdnatives.write[i].instance();
+ singleton_gdnatives.write[i]->set_library(lib);
- if (!singleton_gdnatives[i]->initialize()) {
+ if (!singleton_gdnatives.write[i]->initialize()) {
// Can't initialize. Don't make a native_call then
continue;
}
@@ -374,7 +374,7 @@ void unregister_gdnative_types() {
continue;
}
- singleton_gdnatives[i]->terminate();
+ singleton_gdnatives.write[i]->terminate();
}
singleton_gdnatives.clear();