summaryrefslogtreecommitdiff
path: root/modules/gdnative/nativescript
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdnative/nativescript')
-rw-r--r--modules/gdnative/nativescript/api_generator.cpp7
-rw-r--r--modules/gdnative/nativescript/godot_nativescript.cpp32
-rw-r--r--modules/gdnative/nativescript/nativescript.cpp209
-rw-r--r--modules/gdnative/nativescript/nativescript.h45
-rw-r--r--modules/gdnative/nativescript/register_types.cpp1
5 files changed, 145 insertions, 149 deletions
diff --git a/modules/gdnative/nativescript/api_generator.cpp b/modules/gdnative/nativescript/api_generator.cpp
index 3c0cfd0484..62f2ec5024 100644
--- a/modules/gdnative/nativescript/api_generator.cpp
+++ b/modules/gdnative/nativescript/api_generator.cpp
@@ -41,7 +41,6 @@
// helper stuff
static Error save_file(const String &p_path, const List<String> &p_content) {
-
FileAccessRef file = FileAccess::open(p_path, FileAccess::WRITE);
ERR_FAIL_COND_V(!file, ERR_FILE_CANT_WRITE);
@@ -146,7 +145,6 @@ static String get_type_name(const PropertyInfo &info) {
struct MethodInfoComparator {
StringName::AlphCompare compare;
bool operator()(const MethodInfo &p_a, const MethodInfo &p_b) const {
-
return compare(p_a.name, p_b.name);
}
};
@@ -154,7 +152,6 @@ struct MethodInfoComparator {
struct PropertyInfoComparator {
StringName::AlphCompare compare;
bool operator()(const PropertyInfo &p_a, const PropertyInfo &p_b) const {
-
return compare(p_a.name, p_b.name);
}
};
@@ -162,7 +159,6 @@ struct PropertyInfoComparator {
struct ConstantAPIComparator {
NoCaseComparator compare;
bool operator()(const ConstantAPI &p_a, const ConstantAPI &p_b) const {
-
return compare(p_a.constant_name, p_b.constant_name);
}
};
@@ -171,7 +167,6 @@ struct ConstantAPIComparator {
* Reads the entire Godot API to a list
*/
List<ClassAPI> generate_c_api_classes() {
-
List<ClassAPI> api;
List<StringName> classes;
@@ -410,7 +405,6 @@ List<ClassAPI> generate_c_api_classes() {
* Generates the JSON source from the API in p_api
*/
static List<String> generate_c_api_json(const List<ClassAPI> &p_api) {
-
// I'm sorry for the \t mess
List<String> source;
@@ -520,7 +514,6 @@ static List<String> generate_c_api_json(const List<ClassAPI> &p_api) {
* p_path
*/
Error generate_c_api(const String &p_path) {
-
#ifndef TOOLS_ENABLED
return ERR_BUG;
#else
diff --git a/modules/gdnative/nativescript/godot_nativescript.cpp b/modules/gdnative/nativescript/godot_nativescript.cpp
index 0502458b4f..e47548f3e9 100644
--- a/modules/gdnative/nativescript/godot_nativescript.cpp
+++ b/modules/gdnative/nativescript/godot_nativescript.cpp
@@ -51,8 +51,7 @@ extern "C" void _native_script_hook() {
// Script API
-void GDAPI godot_nativescript_register_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func) {
-
+void GDAPI godot_nativescript_register_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_nativescript_instance_create_func p_create_func, godot_nativescript_instance_destroy_func p_destroy_func) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc> *classes = &NSL->library_classes[*s];
@@ -84,8 +83,7 @@ void GDAPI godot_nativescript_register_class(void *p_gdnative_handle, const char
classes->insert(p_name, desc);
}
-void GDAPI godot_nativescript_register_tool_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func) {
-
+void GDAPI godot_nativescript_register_tool_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_nativescript_instance_create_func p_create_func, godot_nativescript_instance_destroy_func p_destroy_func) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc> *classes = &NSL->library_classes[*s];
@@ -118,8 +116,7 @@ void GDAPI godot_nativescript_register_tool_class(void *p_gdnative_handle, const
classes->insert(p_name, desc);
}
-void GDAPI godot_nativescript_register_method(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method) {
-
+void GDAPI godot_nativescript_register_method(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_nativescript_method_attributes p_attr, godot_nativescript_instance_method p_method) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
@@ -138,8 +135,7 @@ void GDAPI godot_nativescript_register_method(void *p_gdnative_handle, const cha
E->get().methods.insert(p_function_name, method);
}
-void GDAPI godot_nativescript_register_property(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_property_attributes *p_attr, godot_property_set_func p_set_func, godot_property_get_func p_get_func) {
-
+void GDAPI godot_nativescript_register_property(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_nativescript_property_attributes *p_attr, godot_nativescript_property_set_func p_set_func, godot_nativescript_property_get_func p_get_func) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
@@ -163,8 +159,7 @@ void GDAPI godot_nativescript_register_property(void *p_gdnative_handle, const c
E->get().properties.insert(p_path, property);
}
-void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const char *p_name, const godot_signal *p_signal) {
-
+void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const char *p_name, const godot_nativescript_signal *p_signal) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
@@ -176,7 +171,7 @@ void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const cha
for (int i = 0; i < p_signal->num_args; i++) {
PropertyInfo info;
- godot_signal_argument arg = p_signal->args[i];
+ godot_nativescript_signal_argument arg = p_signal->args[i];
info.hint = (PropertyHint)arg.hint;
info.hint_string = *(String *)&arg.hint_string;
@@ -189,7 +184,7 @@ void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const cha
for (int i = 0; i < p_signal->num_default_args; i++) {
Variant *v;
- godot_signal_argument attrib = p_signal->args[i];
+ godot_nativescript_signal_argument attrib = p_signal->args[i];
v = (Variant *)&attrib.default_value;
@@ -209,8 +204,9 @@ void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const cha
void GDAPI *godot_nativescript_get_userdata(godot_object *p_instance) {
Object *instance = (Object *)p_instance;
- if (!instance)
+ if (!instance) {
return nullptr;
+ }
if (instance->get_script_instance() && instance->get_script_instance()->get_language() == NativeScriptLanguage::get_singleton()) {
return ((NativeScriptInstance *)instance->get_script_instance())->userdata;
}
@@ -225,7 +221,7 @@ void GDAPI *godot_nativescript_get_userdata(godot_object *p_instance) {
*
*/
-void GDAPI godot_nativescript_set_method_argument_information(void *p_gdnative_handle, const char *p_name, const char *p_function_name, int p_num_args, const godot_method_arg *p_args) {
+void GDAPI godot_nativescript_set_method_argument_information(void *p_gdnative_handle, const char *p_name, const char *p_function_name, int p_num_args, const godot_nativescript_method_argument *p_args) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
@@ -239,7 +235,7 @@ void GDAPI godot_nativescript_set_method_argument_information(void *p_gdnative_h
List<PropertyInfo> args;
for (int i = 0; i < p_num_args; i++) {
- godot_method_arg arg = p_args[i];
+ godot_nativescript_method_argument arg = p_args[i];
String name = *(String *)&arg.name;
String hint_string = *(String *)&arg.hint_string;
@@ -315,7 +311,6 @@ void GDAPI godot_nativescript_set_type_tag(void *p_gdnative_handle, const char *
}
const void GDAPI *godot_nativescript_get_type_tag(const godot_object *p_object) {
-
const Object *o = (Object *)p_object;
if (!o->get_script_instance()) {
@@ -326,14 +321,15 @@ const void GDAPI *godot_nativescript_get_type_tag(const godot_object *p_object)
return nullptr;
}
- if (script->get_script_desc())
+ if (script->get_script_desc()) {
return script->get_script_desc()->type_tag;
+ }
}
return nullptr;
}
-int GDAPI godot_nativescript_register_instance_binding_data_functions(godot_instance_binding_functions p_binding_functions) {
+int GDAPI godot_nativescript_register_instance_binding_data_functions(godot_nativescript_instance_binding_functions p_binding_functions) {
return NativeScriptLanguage::get_singleton()->register_binding_functions(p_binding_functions);
}
diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp
index ed3ec44bf7..94aa2125c2 100644
--- a/modules/gdnative/nativescript/nativescript.cpp
+++ b/modules/gdnative/nativescript/nativescript.cpp
@@ -169,7 +169,6 @@ String NativeScript::get_script_class_icon_path() const {
}
bool NativeScript::can_instance() const {
-
NativeScriptDesc *script_data = get_script_desc();
#ifdef TOOLS_ENABLED
@@ -185,8 +184,9 @@ bool NativeScript::can_instance() const {
Ref<Script> NativeScript::get_base_script() const {
NativeScriptDesc *script_data = get_script_desc();
- if (!script_data)
+ if (!script_data) {
return Ref<Script>();
+ }
NativeScript *script = (NativeScript *)NSL->create_script();
Ref<NativeScript> ns = Ref<NativeScript>(script);
@@ -200,14 +200,14 @@ Ref<Script> NativeScript::get_base_script() const {
StringName NativeScript::get_instance_base_type() const {
NativeScriptDesc *script_data = get_script_desc();
- if (!script_data)
+ if (!script_data) {
return "";
+ }
return script_data->base_native_type;
}
ScriptInstance *NativeScript::instance_create(Object *p_this) {
-
NativeScriptDesc *script_data = get_script_desc();
if (!script_data) {
@@ -274,8 +274,9 @@ bool NativeScript::has_method(const StringName &p_method) const {
NativeScriptDesc *script_data = get_script_desc();
while (script_data) {
- if (script_data->methods.has(p_method))
+ if (script_data->methods.has(p_method)) {
return true;
+ }
script_data = script_data->base_data;
}
@@ -285,14 +286,16 @@ bool NativeScript::has_method(const StringName &p_method) const {
MethodInfo NativeScript::get_method_info(const StringName &p_method) const {
NativeScriptDesc *script_data = get_script_desc();
- if (!script_data)
+ if (!script_data) {
return MethodInfo();
+ }
while (script_data) {
Map<StringName, NativeScriptDesc::Method>::Element *M = script_data->methods.find(p_method);
- if (M)
+ if (M) {
return M->get().info;
+ }
script_data = script_data->base_data;
}
@@ -306,8 +309,9 @@ bool NativeScript::is_valid() const {
bool NativeScript::is_tool() const {
NativeScriptDesc *script_data = get_script_desc();
- if (script_data)
+ if (script_data) {
return script_data->is_tool;
+ }
return false;
}
@@ -320,8 +324,9 @@ bool NativeScript::has_script_signal(const StringName &p_signal) const {
NativeScriptDesc *script_data = get_script_desc();
while (script_data) {
- if (script_data->signals_.has(p_signal))
+ if (script_data->signals_.has(p_signal)) {
return true;
+ }
script_data = script_data->base_data;
}
return false;
@@ -330,13 +335,13 @@ bool NativeScript::has_script_signal(const StringName &p_signal) const {
void NativeScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
NativeScriptDesc *script_data = get_script_desc();
- if (!script_data)
+ if (!script_data) {
return;
+ }
Set<MethodInfo> signals_;
while (script_data) {
-
for (Map<StringName, NativeScriptDesc::Signal>::Element *S = script_data->signals_.front(); S; S = S->next()) {
signals_.insert(S->get().signal);
}
@@ -357,8 +362,9 @@ bool NativeScript::get_property_default_value(const StringName &p_property, Vari
P = script_data->properties.find(p_property);
script_data = script_data->base_data;
}
- if (!P)
+ if (!P) {
return false;
+ }
r_value = P.get().default_value;
return true;
@@ -370,13 +376,13 @@ void NativeScript::update_exports() {
void NativeScript::get_script_method_list(List<MethodInfo> *p_list) const {
NativeScriptDesc *script_data = get_script_desc();
- if (!script_data)
+ if (!script_data) {
return;
+ }
Set<MethodInfo> methods;
while (script_data) {
-
for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) {
methods.insert(E->get().info);
}
@@ -408,13 +414,11 @@ void NativeScript::get_script_property_list(List<PropertyInfo> *p_list) const {
}
Vector<ScriptNetData> NativeScript::get_rpc_methods() const {
-
Vector<ScriptNetData> v;
NativeScriptDesc *script_data = get_script_desc();
while (script_data) {
-
for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) {
if (E->get().rpc_mode != GODOT_METHOD_RPC_MODE_DISABLED) {
ScriptNetData nd;
@@ -434,7 +438,6 @@ uint16_t NativeScript::get_rpc_method_id(const StringName &p_method) const {
NativeScriptDesc *script_data = get_script_desc();
while (script_data) {
-
Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method);
if (E) {
return E->get().rpc_method_id;
@@ -452,7 +455,6 @@ StringName NativeScript::get_rpc_method(uint16_t p_id) const {
NativeScriptDesc *script_data = get_script_desc();
while (script_data) {
-
for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) {
if (E->get().rpc_method_id == p_id) {
return E->key();
@@ -466,13 +468,11 @@ StringName NativeScript::get_rpc_method(uint16_t p_id) const {
}
MultiplayerAPI::RPCMode NativeScript::get_rpc_mode_by_id(uint16_t p_id) const {
-
ERR_FAIL_COND_V(p_id == UINT16_MAX, MultiplayerAPI::RPC_MODE_DISABLED);
NativeScriptDesc *script_data = get_script_desc();
while (script_data) {
-
for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) {
if (E->get().rpc_method_id == p_id) {
switch (E->get().rpc_mode) {
@@ -503,11 +503,9 @@ MultiplayerAPI::RPCMode NativeScript::get_rpc_mode_by_id(uint16_t p_id) const {
}
MultiplayerAPI::RPCMode NativeScript::get_rpc_mode(const StringName &p_method) const {
-
NativeScriptDesc *script_data = get_script_desc();
while (script_data) {
-
Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method);
if (E) {
switch (E->get().rpc_mode) {
@@ -542,7 +540,6 @@ Vector<ScriptNetData> NativeScript::get_rset_properties() const {
NativeScriptDesc *script_data = get_script_desc();
while (script_data) {
-
for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.front(); E; E = E.next()) {
if (E.get().rset_mode != GODOT_METHOD_RPC_MODE_DISABLED) {
ScriptNetData nd;
@@ -561,7 +558,6 @@ uint16_t NativeScript::get_rset_property_id(const StringName &p_variable) const
NativeScriptDesc *script_data = get_script_desc();
while (script_data) {
-
OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.find(p_variable);
if (E) {
return E.get().rset_property_id;
@@ -579,7 +575,6 @@ StringName NativeScript::get_rset_property(uint16_t p_id) const {
NativeScriptDesc *script_data = get_script_desc();
while (script_data) {
-
for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.front(); E; E = E.next()) {
if (E.get().rset_property_id == p_id) {
return E.key();
@@ -593,13 +588,11 @@ StringName NativeScript::get_rset_property(uint16_t p_id) const {
}
MultiplayerAPI::RPCMode NativeScript::get_rset_mode_by_id(uint16_t p_id) const {
-
ERR_FAIL_COND_V(p_id == UINT16_MAX, MultiplayerAPI::RPC_MODE_DISABLED);
NativeScriptDesc *script_data = get_script_desc();
while (script_data) {
-
for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.front(); E; E = E.next()) {
if (E.get().rset_property_id == p_id) {
switch (E.get().rset_mode) {
@@ -630,11 +623,9 @@ MultiplayerAPI::RPCMode NativeScript::get_rset_mode_by_id(uint16_t p_id) const {
}
MultiplayerAPI::RPCMode NativeScript::get_rset_mode(const StringName &p_variable) const {
-
NativeScriptDesc *script_data = get_script_desc();
while (script_data) {
-
OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.find(p_variable);
if (E) {
switch (E.get().rset_mode) {
@@ -677,7 +668,6 @@ String NativeScript::get_method_documentation(const StringName &p_method) const
ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get method documentation on invalid NativeScript.");
while (script_data) {
-
Map<StringName, NativeScriptDesc::Method>::Element *method = script_data->methods.find(p_method);
if (method) {
@@ -696,7 +686,6 @@ String NativeScript::get_signal_documentation(const StringName &p_signal_name) c
ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get signal documentation on invalid NativeScript.");
while (script_data) {
-
Map<StringName, NativeScriptDesc::Signal>::Element *signal = script_data->signals_.find(p_signal_name);
if (signal) {
@@ -715,7 +704,6 @@ String NativeScript::get_property_documentation(const StringName &p_path) const
ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get property documentation on invalid NativeScript.");
while (script_data) {
-
OrderedHashMap<StringName, NativeScriptDesc::Property>::Element property = script_data->properties.find(p_path);
if (property) {
@@ -729,7 +717,6 @@ String NativeScript::get_property_documentation(const StringName &p_path) const
}
Variant NativeScript::_new(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
-
if (lib_path.empty() || class_name.empty() || library.is_null()) {
r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL;
return Variant();
@@ -840,6 +827,7 @@ bool NativeScriptInstance::set(const StringName &p_name, const Variant &p_value)
}
return false;
}
+
bool NativeScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
NativeScriptDesc *script_data = GET_SCRIPT_DESC();
@@ -884,10 +872,8 @@ void NativeScriptInstance::get_property_list(List<PropertyInfo> *p_properties) c
NativeScriptDesc *script_data = GET_SCRIPT_DESC();
while (script_data) {
-
Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find("_get_property_list");
if (E) {
-
godot_variant result;
result = E->get().method.method((godot_object *)owner,
E->get().method.method_data,
@@ -936,11 +922,9 @@ void NativeScriptInstance::get_property_list(List<PropertyInfo> *p_properties) c
}
Variant::Type NativeScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const {
-
NativeScriptDesc *script_data = GET_SCRIPT_DESC();
while (script_data) {
-
OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = script_data->properties.find(p_name);
if (P) {
*r_is_valid = true;
@@ -961,7 +945,6 @@ bool NativeScriptInstance::has_method(const StringName &p_method) const {
}
Variant NativeScriptInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
-
NativeScriptDesc *script_data = GET_SCRIPT_DESC();
while (script_data) {
@@ -1017,17 +1000,20 @@ String NativeScriptInstance::to_string(bool *r_valid) {
Variant ret = call(CoreStringNames::get_singleton()->_to_string, nullptr, 0, ce);
if (ce.error == Callable::CallError::CALL_OK) {
if (ret.get_type() != Variant::STRING) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String.");
}
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret.operator String();
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return String();
}
@@ -1127,11 +1113,11 @@ void NativeScriptInstance::call_multilevel_reversed(const StringName &p_method,
}
NativeScriptInstance::~NativeScriptInstance() {
-
NativeScriptDesc *script_data = GET_SCRIPT_DESC();
- if (!script_data)
+ if (!script_data) {
return;
+ }
script_data->destroy_func.destroy_func((godot_object *)owner, script_data->destroy_func.method_data, userdata);
@@ -1145,16 +1131,13 @@ NativeScriptInstance::~NativeScriptInstance() {
NativeScriptLanguage *NativeScriptLanguage::singleton;
void NativeScriptLanguage::_unload_stuff(bool p_reload) {
-
Map<String, Ref<GDNative>> erase_and_unload;
for (Map<String, Map<StringName, NativeScriptDesc>>::Element *L = library_classes.front(); L; L = L->next()) {
-
String lib_path = L->key();
Map<StringName, NativeScriptDesc> classes = L->get();
if (p_reload) {
-
Map<String, Ref<GDNative>>::Element *E = library_gdnatives.find(lib_path);
Ref<GDNative> gdn;
@@ -1184,28 +1167,32 @@ void NativeScriptLanguage::_unload_stuff(bool p_reload) {
}
for (Map<StringName, NativeScriptDesc>::Element *C = classes.front(); C; C = C->next()) {
-
// free property stuff first
for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = C->get().properties.front(); P; P = P.next()) {
- if (P.get().getter.free_func)
+ if (P.get().getter.free_func) {
P.get().getter.free_func(P.get().getter.method_data);
+ }
- if (P.get().setter.free_func)
+ if (P.get().setter.free_func) {
P.get().setter.free_func(P.get().setter.method_data);
+ }
}
// free method stuff
for (Map<StringName, NativeScriptDesc::Method>::Element *M = C->get().methods.front(); M; M = M->next()) {
- if (M->get().method.free_func)
+ if (M->get().method.free_func) {
M->get().method.free_func(M->get().method.method_data);
+ }
}
// free constructor/destructor
- if (C->get().create_func.free_func)
+ if (C->get().create_func.free_func) {
C->get().create_func.free_func(C->get().create_func.method_data);
+ }
- if (C->get().destroy_func.free_func)
+ if (C->get().destroy_func.free_func) {
C->get().destroy_func.free_func(C->get().destroy_func.method_data);
+ }
}
erase_and_unload.insert(lib_path, gdn);
@@ -1253,13 +1240,10 @@ NativeScriptLanguage::NativeScriptLanguage() {
}
NativeScriptLanguage::~NativeScriptLanguage() {
-
for (Map<String, Ref<GDNative>>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) {
-
Ref<GDNative> lib = L->get();
// only shut down valid libs, duh!
if (lib.is_valid()) {
-
// If it's a singleton-library then the gdnative module
// manages the destruction at engine shutdown, not NativeScript.
if (!lib->get_library()->is_singleton()) {
@@ -1285,7 +1269,6 @@ void _add_reload_node() {
}
void NativeScriptLanguage::init() {
-
#if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED)
List<String> args = OS::get_singleton()->get_cmdline_args();
@@ -1304,22 +1287,29 @@ void NativeScriptLanguage::init() {
EditorNode::add_init_callback(&_add_reload_node);
#endif
}
+
String NativeScriptLanguage::get_type() const {
return "NativeScript";
}
+
String NativeScriptLanguage::get_extension() const {
return "gdns";
}
+
Error NativeScriptLanguage::execute_file(const String &p_path) {
return OK; // Qué?
}
+
void NativeScriptLanguage::finish() {
_unload_stuff();
}
+
void NativeScriptLanguage::get_reserved_words(List<String> *p_words) const {
}
+
void NativeScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const {
}
+
void NativeScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const {
}
@@ -1328,6 +1318,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, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const {
return true;
}
@@ -1336,20 +1327,26 @@ Script *NativeScriptLanguage::create_script() const {
NativeScript *script = memnew(NativeScript);
return script;
}
+
bool NativeScriptLanguage::has_named_classes() const {
return true;
}
+
bool NativeScriptLanguage::supports_builtin_mode() const {
return true;
}
+
int NativeScriptLanguage::find_function(const String &p_function, const String &p_code) const {
return -1;
}
+
String NativeScriptLanguage::make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const {
return "";
}
+
void NativeScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const {
}
+
void NativeScriptLanguage::add_global_constant(const StringName &p_variable, const Variant &p_value) {
}
@@ -1357,27 +1354,36 @@ void NativeScriptLanguage::add_global_constant(const StringName &p_variable, con
String NativeScriptLanguage::debug_get_error() const {
return "";
}
+
int NativeScriptLanguage::debug_get_stack_level_count() const {
return -1;
}
+
int NativeScriptLanguage::debug_get_stack_level_line(int p_level) const {
return -1;
}
+
String NativeScriptLanguage::debug_get_stack_level_function(int p_level) const {
return "";
}
+
String NativeScriptLanguage::debug_get_stack_level_source(int p_level) const {
return "";
}
+
void NativeScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
}
+
void NativeScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
}
+
void NativeScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
}
+
String NativeScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) {
return "";
}
+
// Debugging stuff end.
void NativeScriptLanguage::reload_all_scripts() {
@@ -1385,6 +1391,7 @@ void NativeScriptLanguage::reload_all_scripts() {
void NativeScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) {
}
+
void NativeScriptLanguage::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("gdns");
}
@@ -1419,8 +1426,9 @@ int NativeScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_a
int current = 0;
for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) {
- if (current >= p_info_max)
+ if (current >= p_info_max) {
break;
+ }
p_info_arr[current].call_count = d->get().call_count;
p_info_arr[current].self_time = d->get().self_time;
@@ -1442,8 +1450,9 @@ int NativeScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, in
int current = 0;
for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) {
- if (current >= p_info_max)
+ if (current >= p_info_max) {
break;
+ }
if (d->get().last_frame_call_count) {
p_info_arr[current].call_count = d->get().last_frame_call_count;
@@ -1489,8 +1498,7 @@ void NativeScriptLanguage::profiling_add_data(StringName p_signature, uint64_t p
#endif
}
-int NativeScriptLanguage::register_binding_functions(godot_instance_binding_functions p_binding_functions) {
-
+int NativeScriptLanguage::register_binding_functions(godot_nativescript_instance_binding_functions p_binding_functions) {
// find index
int idx = -1;
@@ -1521,14 +1529,16 @@ void NativeScriptLanguage::unregister_binding_functions(int p_idx) {
for (Set<Vector<void *> *>::Element *E = binding_instances.front(); E; E = E->next()) {
Vector<void *> &binding_data = *E->get();
- if (p_idx < binding_data.size() && binding_data[p_idx] && binding_functions[p_idx].second.free_instance_binding_data)
+ if (p_idx < binding_data.size() && binding_data[p_idx] && binding_functions[p_idx].second.free_instance_binding_data) {
binding_functions[p_idx].second.free_instance_binding_data(binding_functions[p_idx].second.data, binding_data[p_idx]);
+ }
}
binding_functions.write[p_idx].first = false;
- if (binding_functions[p_idx].second.free_func)
+ if (binding_functions[p_idx].second.free_func) {
binding_functions[p_idx].second.free_func(binding_functions[p_idx].second.data);
+ }
}
void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_object) {
@@ -1538,8 +1548,9 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec
Vector<void *> *binding_data = (Vector<void *> *)p_object->get_script_instance_binding(lang_idx);
- if (!binding_data)
+ if (!binding_data) {
return nullptr; // should never happen.
+ }
if (binding_data->size() <= p_idx) {
// okay, add new elements here.
@@ -1553,7 +1564,6 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec
}
if (!(*binding_data)[p_idx]) {
-
const void *global_type_tag = get_global_type_tag(p_idx, p_object->get_class_name());
// no binding data yet, soooooo alloc new one \o/
@@ -1564,7 +1574,6 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec
}
void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) {
-
Vector<void *> *binding_data = new Vector<void *>;
binding_data->resize(binding_functions.size());
@@ -1579,15 +1588,16 @@ void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) {
}
void NativeScriptLanguage::free_instance_binding_data(void *p_data) {
-
- if (!p_data)
+ if (!p_data) {
return;
+ }
Vector<void *> &binding_data = *(Vector<void *> *)p_data;
for (int i = 0; i < binding_data.size(); i++) {
- if (!binding_data[i])
+ if (!binding_data[i]) {
continue;
+ }
if (binding_functions[i].first && binding_functions[i].second.free_instance_binding_data) {
binding_functions[i].second.free_instance_binding_data(binding_functions[i].second.data, binding_data[i]);
@@ -1600,20 +1610,22 @@ void NativeScriptLanguage::free_instance_binding_data(void *p_data) {
}
void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_object) {
-
void *data = p_object->get_script_instance_binding(lang_idx);
- if (!data)
+ if (!data) {
return;
+ }
Vector<void *> &binding_data = *(Vector<void *> *)data;
for (int i = 0; i < binding_data.size(); i++) {
- if (!binding_data[i])
+ if (!binding_data[i]) {
continue;
+ }
- if (!binding_functions[i].first)
+ if (!binding_functions[i].first) {
continue;
+ }
if (binding_functions[i].second.refcount_incremented_instance_binding) {
binding_functions[i].second.refcount_incremented_instance_binding(binding_data[i], p_object);
@@ -1622,22 +1634,24 @@ void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_objec
}
bool NativeScriptLanguage::refcount_decremented_instance_binding(Object *p_object) {
-
void *data = p_object->get_script_instance_binding(lang_idx);
- if (!data)
+ if (!data) {
return true;
+ }
Vector<void *> &binding_data = *(Vector<void *> *)data;
bool can_die = true;
for (int i = 0; i < binding_data.size(); i++) {
- if (!binding_data[i])
+ if (!binding_data[i]) {
continue;
+ }
- if (!binding_functions[i].first)
+ if (!binding_functions[i].first) {
continue;
+ }
if (binding_functions[i].second.refcount_decremented_instance_binding) {
can_die = can_die && binding_functions[i].second.refcount_decremented_instance_binding(binding_data[i], p_object);
@@ -1658,13 +1672,15 @@ void NativeScriptLanguage::set_global_type_tag(int p_idx, StringName p_class_nam
}
const void *NativeScriptLanguage::get_global_type_tag(int p_idx, StringName p_class_name) const {
- if (!global_type_tags.has(p_idx))
+ if (!global_type_tags.has(p_idx)) {
return nullptr;
+ }
const HashMap<StringName, const void *> &tags = global_type_tags[p_idx];
- if (!tags.has(p_class_name))
+ if (!tags.has(p_class_name)) {
return nullptr;
+ }
const void *tag = tags.get(p_class_name);
@@ -1700,8 +1716,9 @@ void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) {
library_classes.insert(lib_path, Map<StringName, NativeScriptDesc>());
- if (!library_script_users.has(lib_path))
+ if (!library_script_users.has(lib_path)) {
library_script_users.insert(lib_path, Set<NativeScript *>());
+ }
void *proc_ptr;
@@ -1741,13 +1758,11 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) {
void NativeScriptLanguage::call_libraries_cb(const StringName &name) {
// library_gdnatives is modified only from the main thread, so it's safe not to use mutex here
for (Map<String, Ref<GDNative>>::Element *L = library_gdnatives.front(); L; L = L->next()) {
-
if (L->get().is_null()) {
continue;
}
if (L->get()->is_initialized()) {
-
void *proc_ptr;
Error err = L->get()->get_symbol(L->get()->get_library()->get_symbol_prefix() + name, proc_ptr);
@@ -1812,16 +1827,20 @@ String NativeScriptLanguage::get_global_class_name(const String &p_path, String
if (!p_path.empty()) {
Ref<NativeScript> script = ResourceLoader::load(p_path, "NativeScript");
if (script.is_valid()) {
- if (r_base_type)
+ if (r_base_type) {
*r_base_type = script->get_instance_base_type();
- if (r_icon_path)
+ }
+ if (r_icon_path) {
*r_icon_path = script->get_script_class_icon_path();
+ }
return script->get_script_class_name();
}
- if (r_base_type)
+ if (r_base_type) {
*r_base_type = String();
- if (r_icon_path)
+ }
+ if (r_icon_path) {
*r_icon_path = String();
+ }
}
return String();
}
@@ -1834,15 +1853,14 @@ void NativeReloadNode::_notification(int p_what) {
#ifdef TOOLS_ENABLED
switch (p_what) {
- case NOTIFICATION_WM_FOCUS_OUT: {
-
- if (unloaded)
+ case NOTIFICATION_APPLICATION_FOCUS_OUT: {
+ if (unloaded) {
break;
+ }
MutexLock lock(NSL->mutex);
NSL->_unload_stuff(true);
for (Map<String, Ref<GDNative>>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) {
-
Ref<GDNative> gdn = L->get();
if (gdn.is_null()) {
@@ -1869,15 +1887,14 @@ void NativeReloadNode::_notification(int p_what) {
} break;
- case NOTIFICATION_WM_FOCUS_IN: {
-
- if (!unloaded)
+ case NOTIFICATION_APPLICATION_FOCUS_IN: {
+ if (!unloaded) {
break;
+ }
MutexLock lock(NSL->mutex);
Set<StringName> libs_to_remove;
for (Map<String, Ref<GDNative>>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) {
-
Ref<GDNative> gdn = L->get();
if (gdn.is_null()) {
@@ -1915,8 +1932,9 @@ void NativeReloadNode::_notification(int p_what) {
for (Set<NativeScript *>::Element *S = U->get().front(); S; S = S->next()) {
NativeScript *script = S->get();
- if (script->placeholders.size() == 0)
+ if (script->placeholders.size() == 0) {
continue;
+ }
for (Set<PlaceHolderScriptInstance *>::Element *P = script->placeholders.front(); P; P = P->next()) {
script->_update_placeholder(P->get());
@@ -1952,8 +1970,9 @@ bool ResourceFormatLoaderNativeScript::handles_type(const String &p_type) const
String ResourceFormatLoaderNativeScript::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
- if (el == "gdns")
+ if (el == "gdns") {
return "NativeScript";
+ }
return "";
}
diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h
index 7e7598e06c..fabf4bb87e 100644
--- a/modules/gdnative/nativescript/nativescript.h
+++ b/modules/gdnative/nativescript/nativescript.h
@@ -43,20 +43,21 @@
#include "scene/main/node.h"
#include "modules/gdnative/gdnative.h"
+
#include <nativescript/godot_nativescript.h>
struct NativeScriptDesc {
-
struct Method {
- godot_instance_method method;
+ godot_nativescript_instance_method method;
MethodInfo info;
int rpc_mode;
uint16_t rpc_method_id;
String documentation;
};
+
struct Property {
- godot_property_set_func setter;
- godot_property_get_func getter;
+ godot_nativescript_property_set_func setter;
+ godot_nativescript_property_get_func getter;
PropertyInfo info;
Variant default_value;
int rset_mode;
@@ -69,35 +70,26 @@ struct NativeScriptDesc {
String documentation;
};
- uint16_t rpc_count;
+ uint16_t rpc_count = 0;
Map<StringName, Method> methods;
- uint16_t rset_count;
+ uint16_t rset_count = 0;
OrderedHashMap<StringName, Property> properties;
Map<StringName, Signal> signals_; // QtCreator doesn't like the name signals
StringName base;
StringName base_native_type;
NativeScriptDesc *base_data;
- godot_instance_create_func create_func;
- godot_instance_destroy_func destroy_func;
+ godot_nativescript_instance_create_func create_func;
+ godot_nativescript_instance_destroy_func destroy_func;
String documentation;
- const void *type_tag;
+ const void *type_tag = nullptr;
bool is_tool;
- inline NativeScriptDesc() :
- rpc_count(0),
- methods(),
- rset_count(0),
- properties(),
- signals_(),
- base(),
- base_native_type(),
- documentation(),
- type_tag(nullptr) {
- zeromem(&create_func, sizeof(godot_instance_create_func));
- zeromem(&destroy_func, sizeof(godot_instance_destroy_func));
+ inline NativeScriptDesc() {
+ zeromem(&create_func, sizeof(godot_nativescript_instance_create_func));
+ zeromem(&destroy_func, sizeof(godot_nativescript_instance_destroy_func));
}
};
@@ -201,7 +193,6 @@ public:
};
class NativeScriptInstance : public ScriptInstance {
-
friend class NativeScript;
Object *owner;
@@ -252,7 +243,6 @@ public:
class NativeReloadNode;
class NativeScriptLanguage : public ScriptLanguage {
-
friend class NativeScript;
friend class NativeScriptInstance;
friend class NativeReloadNode;
@@ -277,7 +267,7 @@ private:
void call_libraries_cb(const StringName &name);
- Vector<Pair<bool, godot_instance_binding_functions>> binding_functions;
+ Vector<Pair<bool, godot_nativescript_instance_binding_functions>> binding_functions;
Set<Vector<void *> *> binding_instances;
Map<int, HashMap<StringName, const void *>> global_type_tags;
@@ -370,7 +360,7 @@ public:
virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max);
virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max);
- int register_binding_functions(godot_instance_binding_functions p_binding_functions);
+ int register_binding_functions(godot_nativescript_instance_binding_functions p_binding_functions);
void unregister_binding_functions(int p_idx);
void *get_instance_binding_data(int p_idx, Object *p_object);
@@ -396,14 +386,13 @@ inline NativeScriptDesc *NativeScript::get_script_desc() const {
class NativeReloadNode : public Node {
GDCLASS(NativeReloadNode, Node);
- bool unloaded;
+ bool unloaded = false;
public:
static void _bind_methods();
void _notification(int p_what);
- NativeReloadNode() :
- unloaded(false) {}
+ NativeReloadNode() {}
};
class ResourceFormatLoaderNativeScript : public ResourceFormatLoader {
diff --git a/modules/gdnative/nativescript/register_types.cpp b/modules/gdnative/nativescript/register_types.cpp
index b5e8174e43..ac8c7ab2fd 100644
--- a/modules/gdnative/nativescript/register_types.cpp
+++ b/modules/gdnative/nativescript/register_types.cpp
@@ -58,7 +58,6 @@ void register_nativescript_types() {
}
void unregister_nativescript_types() {
-
ResourceLoader::remove_resource_format_loader(resource_loader_gdns);
resource_loader_gdns.unref();