diff options
Diffstat (limited to 'modules/gdnative/nativescript')
-rw-r--r-- | modules/gdnative/nativescript/SCsub | 9 | ||||
-rw-r--r-- | modules/gdnative/nativescript/api_generator.cpp | 948 | ||||
-rw-r--r-- | modules/gdnative/nativescript/api_generator.h | 40 | ||||
-rw-r--r-- | modules/gdnative/nativescript/godot_nativescript.cpp | 344 | ||||
-rw-r--r-- | modules/gdnative/nativescript/nativescript.cpp | 1777 | ||||
-rw-r--r-- | modules/gdnative/nativescript/nativescript.h | 393 | ||||
-rw-r--r-- | modules/gdnative/nativescript/register_types.cpp | 71 | ||||
-rw-r--r-- | modules/gdnative/nativescript/register_types.h | 37 |
8 files changed, 0 insertions, 3619 deletions
diff --git a/modules/gdnative/nativescript/SCsub b/modules/gdnative/nativescript/SCsub deleted file mode 100644 index 4212e87a87..0000000000 --- a/modules/gdnative/nativescript/SCsub +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python - -Import("env") -Import("env_gdnative") - -env_gdnative.add_source_files(env.modules_sources, "*.cpp") - -if "platform" in env and env["platform"] in ["linuxbsd", "iphone"]: - env.Append(LINKFLAGS=["-rdynamic"]) diff --git a/modules/gdnative/nativescript/api_generator.cpp b/modules/gdnative/nativescript/api_generator.cpp deleted file mode 100644 index 0309d1d9c7..0000000000 --- a/modules/gdnative/nativescript/api_generator.cpp +++ /dev/null @@ -1,948 +0,0 @@ -/*************************************************************************/ -/* api_generator.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "api_generator.h" - -#ifdef TOOLS_ENABLED - -#include "core/config/engine.h" -#include "core/core_constants.h" -#include "core/io/file_access.h" -#include "core/object/class_db.h" -#include "core/string/string_builder.h" -#include "core/templates/pair.h" -#include "core/variant/variant_parser.h" - -// 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); - - for (const List<String>::Element *e = p_content.front(); e != nullptr; e = e->next()) { - file->store_string(e->get()); - } - - file->close(); - - return OK; -} - -// helper stuff end - -struct MethodAPI { - String method_name; - String return_type; - - List<String> argument_types; - List<String> argument_names; - - Map<int, Variant> default_arguments; - - int argument_count = 0; - bool has_varargs = false; - bool is_editor = false; - bool is_noscript = false; - bool is_const = false; - bool is_static = false; // For builtin types. - bool is_reverse = false; - bool is_virtual = false; - bool is_from_script = false; -}; - -struct PropertyAPI { - String name; - String getter; - String setter; - String type; - int index = 0; -}; - -struct ConstantAPI { - String constant_name; - int constant_value = 0; - Variant builtin_constant_value; // For builtin types; - String builtin_constant_type; // For builtin types; -}; - -struct SignalAPI { - String name; - List<String> argument_types; - List<String> argument_names; - Map<int, Variant> default_arguments; -}; - -struct EnumAPI { - String name; - List<Pair<int, String>> values; -}; - -struct OperatorAPI { // For builtin types; - String name; - int oper = Variant::OP_MAX; - String other_type; - String return_type; -}; - -struct ClassAPI { - String class_name; - String super_class_name; - - ClassDB::APIType api_type = ClassDB::API_NONE; - - bool is_singleton = false; - String singleton_name; - bool is_instantiable = false; - // @Unclear - bool is_ref_counted = false; - bool has_indexing = false; // For builtin types. - String indexed_type; // For builtin types. - bool is_keyed = false; // For builtin types. - - List<MethodAPI> methods; - List<MethodAPI> constructors; // For builtin types. - List<PropertyAPI> properties; - List<ConstantAPI> constants; - List<SignalAPI> signals_; - List<EnumAPI> enums; - List<OperatorAPI> operators; // For builtin types. -}; - -static String get_type_name(const PropertyInfo &info) { - if (info.type == Variant::INT && (info.usage & PROPERTY_USAGE_CLASS_IS_ENUM)) { - return String("enum.") + String(info.class_name).replace(".", "::"); - } - if (info.class_name != StringName()) { - return info.class_name; - } - if (info.hint == PROPERTY_HINT_RESOURCE_TYPE) { - return info.class_name; - } - if (info.type == Variant::NIL && (info.usage & PROPERTY_USAGE_NIL_IS_VARIANT)) { - return "Variant"; - } - if (info.type == Variant::NIL) { - return "void"; - } - return Variant::get_type_name(info.type); -} - -/* - * Some comparison helper functions we need - */ - -struct MethodInfoComparator { - StringName::AlphCompare compare; - bool operator()(const MethodInfo &p_a, const MethodInfo &p_b) const { - return compare(p_a.name, p_b.name); - } -}; - -struct PropertyInfoComparator { - StringName::AlphCompare compare; - bool operator()(const PropertyInfo &p_a, const PropertyInfo &p_b) const { - return compare(p_a.name, p_b.name); - } -}; - -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); - } -}; - -/* - * Reads the entire Godot API to a list - */ -List<ClassAPI> generate_c_api_classes() { - List<ClassAPI> api; - - List<StringName> classes; - ClassDB::get_class_list(&classes); - classes.sort_custom<StringName::AlphCompare>(); - - // Register global constants as a fake CoreConstants singleton class - { - ClassAPI global_constants_api; - global_constants_api.class_name = "CoreConstants"; - global_constants_api.api_type = ClassDB::API_CORE; - global_constants_api.is_singleton = true; - global_constants_api.singleton_name = "CoreConstants"; - global_constants_api.is_instantiable = false; - const int constants_count = CoreConstants::get_global_constant_count(); - - Map<StringName, EnumAPI> enum_api_map; - for (int i = 0; i < constants_count; ++i) { - StringName enum_name = CoreConstants::get_global_constant_enum(i); - String name = String(CoreConstants::get_global_constant_name(i)); - int value = CoreConstants::get_global_constant_value(i); - - if (enum_name == StringName()) { - ConstantAPI constant_api; - constant_api.constant_name = name; - constant_api.constant_value = value; - global_constants_api.constants.push_back(constant_api); - } else { - EnumAPI enum_api; - if (enum_api_map.has(enum_name)) { - enum_api = enum_api_map[enum_name]; - } else { - enum_api.name = String(enum_name); - } - enum_api.values.push_back(Pair(value, name)); - - enum_api_map[enum_name] = enum_api; - } - } - for (const KeyValue<StringName, EnumAPI> &E : enum_api_map) { - global_constants_api.enums.push_back(E.value); - } - global_constants_api.constants.sort_custom<ConstantAPIComparator>(); - api.push_back(global_constants_api); - } - - for (List<StringName>::Element *e = classes.front(); e != nullptr; e = e->next()) { - StringName class_name = e->get(); - - if (!ClassDB::is_class_exposed(class_name)) { - continue; - } - - ClassAPI class_api; - class_api.api_type = ClassDB::get_api_type(e->get()); - class_api.class_name = class_name; - class_api.super_class_name = ClassDB::get_parent_class(class_name); - { - class_api.is_singleton = Engine::get_singleton()->has_singleton(class_name); - if (class_api.is_singleton) { - class_api.singleton_name = class_name; - } - } - class_api.is_instantiable = !class_api.is_singleton && ClassDB::can_instantiate(class_name); - - { - List<StringName> inheriters; - ClassDB::get_inheriters_from_class("RefCounted", &inheriters); - bool is_ref_counted = !!inheriters.find(class_name) || class_name == "RefCounted"; - // @Unclear - class_api.is_ref_counted = !class_api.is_singleton && is_ref_counted; - } - - // constants - { - List<String> constant; - ClassDB::get_integer_constant_list(class_name, &constant, true); - constant.sort_custom<NoCaseComparator>(); - for (List<String>::Element *c = constant.front(); c != nullptr; c = c->next()) { - ConstantAPI constant_api; - constant_api.constant_name = c->get(); - constant_api.constant_value = ClassDB::get_integer_constant(class_name, c->get()); - - class_api.constants.push_back(constant_api); - } - } - - // signals - { - List<MethodInfo> signals_; - ClassDB::get_signal_list(class_name, &signals_, true); - signals_.sort_custom<MethodInfoComparator>(); - - for (int i = 0; i < signals_.size(); i++) { - SignalAPI signal; - - MethodInfo method_info = signals_[i]; - signal.name = method_info.name; - - for (int j = 0; j < method_info.arguments.size(); j++) { - PropertyInfo argument = method_info.arguments[j]; - String type; - String name = argument.name; - - if (argument.name.contains(":")) { - type = argument.name.get_slice(":", 1); - name = argument.name.get_slice(":", 0); - } else { - type = get_type_name(argument); - } - - signal.argument_names.push_back(name); - signal.argument_types.push_back(type); - } - - Vector<Variant> default_arguments = method_info.default_arguments; - - int default_start = signal.argument_names.size() - default_arguments.size(); - - for (int j = 0; j < default_arguments.size(); j++) { - signal.default_arguments[default_start + j] = default_arguments[j]; - } - - class_api.signals_.push_back(signal); - } - } - - //properties - { - List<PropertyInfo> properties; - ClassDB::get_property_list(class_name, &properties, true); - properties.sort_custom<PropertyInfoComparator>(); - - for (List<PropertyInfo>::Element *p = properties.front(); p != nullptr; p = p->next()) { - PropertyAPI property_api; - - property_api.name = p->get().name; - property_api.getter = ClassDB::get_property_getter(class_name, p->get().name); - property_api.setter = ClassDB::get_property_setter(class_name, p->get().name); - - if (p->get().name.contains(":")) { - property_api.type = p->get().name.get_slice(":", 1); - property_api.name = p->get().name.get_slice(":", 0); - } else { - MethodInfo minfo; - ClassDB::get_method_info(class_name, property_api.getter, &minfo, true, false); - property_api.type = get_type_name(minfo.return_val); - } - - property_api.index = ClassDB::get_property_index(class_name, p->get().name); - - if (!property_api.setter.is_empty() || !property_api.getter.is_empty()) { - class_api.properties.push_back(property_api); - } - } - } - - //methods - { - List<MethodInfo> methods; - ClassDB::get_method_list(class_name, &methods, true); - methods.sort_custom<MethodInfoComparator>(); - - for (List<MethodInfo>::Element *m = methods.front(); m != nullptr; m = m->next()) { - MethodAPI method_api; - MethodBind *method_bind = ClassDB::get_method(class_name, m->get().name); - MethodInfo &method_info = m->get(); - - //method name - method_api.method_name = method_info.name; - //method return type - if (method_api.method_name.contains(":")) { - method_api.return_type = method_api.method_name.get_slice(":", 1); - method_api.method_name = method_api.method_name.get_slice(":", 0); - } else { - method_api.return_type = get_type_name(m->get().return_val); - } - - method_api.argument_count = method_info.arguments.size(); - method_api.has_varargs = method_bind && method_bind->is_vararg(); - - // Method flags - method_api.is_virtual = false; - if (method_info.flags) { - const uint32_t flags = method_info.flags; - method_api.is_editor = flags & METHOD_FLAG_EDITOR; - method_api.is_noscript = flags & METHOD_FLAG_NOSCRIPT; - method_api.is_const = flags & METHOD_FLAG_CONST; - method_api.is_reverse = flags & METHOD_FLAG_REVERSE; - method_api.is_virtual = flags & METHOD_FLAG_VIRTUAL; - method_api.is_from_script = flags & METHOD_FLAG_FROM_SCRIPT; - } - - method_api.is_virtual = method_api.is_virtual || method_api.method_name[0] == '_'; - - // method argument name and type - - for (int i = 0; i < method_api.argument_count; i++) { - String arg_name; - String arg_type; - PropertyInfo arg_info = method_info.arguments[i]; - - arg_name = arg_info.name; - - if (arg_info.name.contains(":")) { - arg_type = arg_info.name.get_slice(":", 1); - arg_name = arg_info.name.get_slice(":", 0); - } else if (arg_info.hint == PROPERTY_HINT_RESOURCE_TYPE) { - arg_type = arg_info.class_name; - } else if (arg_info.type == Variant::NIL) { - arg_type = "Variant"; - } else if (arg_info.type == Variant::OBJECT) { - arg_type = arg_info.class_name; - if (arg_type.is_empty()) { - arg_type = Variant::get_type_name(arg_info.type); - } - } else { - arg_type = get_type_name(arg_info); - } - - method_api.argument_names.push_back(arg_name); - method_api.argument_types.push_back(arg_type); - - if (method_bind && method_bind->has_default_argument(i)) { - method_api.default_arguments[i] = method_bind->get_default_argument(i); - } - } - - class_api.methods.push_back(method_api); - } - } - - // enums - { - List<EnumAPI> enums; - List<StringName> enum_names; - ClassDB::get_enum_list(class_name, &enum_names, true); - for (const StringName &E : enum_names) { - List<StringName> value_names; - EnumAPI enum_api; - enum_api.name = E; - ClassDB::get_enum_constants(class_name, E, &value_names, true); - for (List<StringName>::Element *val_e = value_names.front(); val_e; val_e = val_e->next()) { - int int_val = ClassDB::get_integer_constant(class_name, val_e->get(), nullptr); - enum_api.values.push_back(Pair<int, String>(int_val, val_e->get())); - } - enum_api.values.sort_custom<PairSort<int, String>>(); - class_api.enums.push_back(enum_api); - } - } - - api.push_back(class_api); - } - - return api; -} - -/* - * Reads the builtin Variant API to a list - */ -List<ClassAPI> generate_c_builtin_api_types() { - List<ClassAPI> api; - - // Special class for the utility methods. - { - ClassAPI utility_api; - utility_api.class_name = "Utilities"; - utility_api.is_instantiable = false; - - List<StringName> utility_functions; - Variant::get_utility_function_list(&utility_functions); - for (const StringName &E : utility_functions) { - const StringName &function_name = E; - - MethodAPI function_api; - function_api.method_name = function_name; - function_api.has_varargs = Variant::is_utility_function_vararg(function_name); - function_api.argument_count = function_api.has_varargs ? 0 : Variant::get_utility_function_argument_count(function_name); - function_api.is_const = Variant::get_utility_function_type(function_name) == Variant::UTILITY_FUNC_TYPE_MATH; - - for (int i = 0; i < function_api.argument_count; i++) { - function_api.argument_names.push_back(Variant::get_utility_function_argument_name(function_name, i)); - Variant::Type arg_type = Variant::get_utility_function_argument_type(function_name, i); - function_api.argument_types.push_back(arg_type == Variant::NIL ? "Variant" : Variant::get_type_name(arg_type)); - } - - if (Variant::has_utility_function_return_value(function_name)) { - Variant::Type ret_type = Variant::get_utility_function_return_type(function_name); - function_api.return_type = ret_type == Variant::NIL ? "Variant" : Variant::get_type_name(ret_type); - } else { - function_api.return_type = "void"; - } - - utility_api.methods.push_back(function_api); - } - - api.push_back(utility_api); - } - - for (int t = 0; t < Variant::VARIANT_MAX; t++) { - Variant::Type type = (Variant::Type)t; - - ClassAPI class_api; - class_api.class_name = Variant::get_type_name(type); - class_api.is_instantiable = true; - class_api.has_indexing = Variant::has_indexing(type); - class_api.indexed_type = Variant::get_type_name(Variant::get_indexed_element_type(type)); - class_api.is_keyed = Variant::is_keyed(type); - // Types that are passed by reference. - switch (type) { - case Variant::OBJECT: - case Variant::DICTIONARY: - case Variant::ARRAY: - case Variant::PACKED_BYTE_ARRAY: - case Variant::PACKED_INT32_ARRAY: - case Variant::PACKED_INT64_ARRAY: - case Variant::PACKED_FLOAT32_ARRAY: - case Variant::PACKED_FLOAT64_ARRAY: - case Variant::PACKED_STRING_ARRAY: - case Variant::PACKED_VECTOR2_ARRAY: - case Variant::PACKED_VECTOR3_ARRAY: - case Variant::PACKED_COLOR_ARRAY: - class_api.is_ref_counted = true; - break; - default: - class_api.is_ref_counted = false; - break; - } - - // Methods. - - List<StringName> methods; - Variant::get_builtin_method_list(type, &methods); - for (const StringName &E : methods) { - const StringName &method_name = E; - - MethodAPI method_api; - - method_api.method_name = method_name; - method_api.argument_count = Variant::get_builtin_method_argument_count(type, method_name); - method_api.has_varargs = Variant::is_builtin_method_vararg(type, method_name); - method_api.is_const = Variant::is_builtin_method_const(type, method_name); - method_api.is_static = Variant::is_builtin_method_static(type, method_name); - - for (int i = 0; i < method_api.argument_count; i++) { - method_api.argument_names.push_back(Variant::get_builtin_method_argument_name(type, method_name, i)); - Variant::Type arg_type = Variant::get_builtin_method_argument_type(type, method_name, i); - method_api.argument_types.push_back(arg_type == Variant::NIL ? "Variant" : Variant::get_type_name(arg_type)); - } - - Vector<Variant> default_arguments = Variant::get_builtin_method_default_arguments(type, method_name); - - int default_start = method_api.argument_names.size() - default_arguments.size(); - - for (int i = 0; i < default_arguments.size(); i++) { - method_api.default_arguments[default_start + i] = default_arguments[i]; - } - - if (Variant::has_builtin_method_return_value(type, method_name)) { - Variant::Type ret_type = Variant::get_builtin_method_return_type(type, method_name); - method_api.return_type = ret_type == Variant::NIL ? "Variant" : Variant::get_type_name(ret_type); - } else { - method_api.return_type = "void"; - } - - class_api.methods.push_back(method_api); - } - - // Constructors. - - for (int c = 0; c < Variant::get_constructor_count(type); c++) { - MethodAPI constructor_api; - - constructor_api.method_name = Variant::get_type_name(type); - constructor_api.argument_count = Variant::get_constructor_argument_count(type, c); - constructor_api.return_type = Variant::get_type_name(type); - - for (int i = 0; i < constructor_api.argument_count; i++) { - constructor_api.argument_names.push_back(Variant::get_constructor_argument_name(type, c, i)); - Variant::Type arg_type = Variant::get_constructor_argument_type(type, c, i); - constructor_api.argument_types.push_back(arg_type == Variant::NIL ? "Variant" : Variant::get_type_name(arg_type)); - } - - class_api.constructors.push_back(constructor_api); - } - - // Constants. - - List<StringName> constants; - Variant::get_constants_for_type(type, &constants); - for (const StringName &E : constants) { - const StringName &constant_name = E; - ConstantAPI constant_api; - - constant_api.constant_name = constant_name; - constant_api.builtin_constant_value = Variant::get_constant_value(type, constant_name); - constant_api.builtin_constant_type = Variant::get_type_name(constant_api.builtin_constant_value.get_type()); - - class_api.constants.push_back(constant_api); - } - - // Members. - - List<StringName> members; - Variant::get_member_list(type, &members); - for (const StringName &E : members) { - const StringName &member_name = E; - - PropertyAPI member_api; - member_api.name = member_name; - Variant::Type member_type = Variant::get_member_type(type, member_name); - member_api.type = member_type == Variant::NIL ? "Variant" : Variant::get_type_name(member_type); - - class_api.properties.push_back(member_api); - } - - // Operators. - - for (int op = 0; op < Variant::OP_MAX; op++) { - Variant::Operator oper = (Variant::Operator)op; - - for (int ot = 0; ot < Variant::VARIANT_MAX; ot++) { - Variant::Type other_type = (Variant::Type)ot; - - if (!Variant::get_validated_operator_evaluator(oper, type, other_type)) { - continue; - } - - OperatorAPI oper_api; - oper_api.name = Variant::get_operator_name(oper); - oper_api.oper = oper; - oper_api.other_type = Variant::get_type_name(other_type); - oper_api.return_type = Variant::get_type_name(Variant::get_operator_return_type(oper, type, other_type)); - - class_api.operators.push_back(oper_api); - } - } - - api.push_back(class_api); - } - - return api; -} - -/* - * 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; - VariantWriter writer; - - source.push_back("[\n"); - - for (const List<ClassAPI>::Element *c = p_api.front(); c != nullptr; c = c->next()) { - ClassAPI api = c->get(); - - source.push_back("\t{\n"); - - source.push_back("\t\t\"name\": \"" + api.class_name + "\",\n"); - source.push_back("\t\t\"base_class\": \"" + api.super_class_name + "\",\n"); - source.push_back(String("\t\t\"api_type\": \"") + (api.api_type == ClassDB::API_CORE ? "core" : (api.api_type == ClassDB::API_EDITOR ? "tools" : "none")) + "\",\n"); - source.push_back(String("\t\t\"singleton\": ") + (api.is_singleton ? "true" : "false") + ",\n"); - source.push_back("\t\t\"singleton_name\": \"" + api.singleton_name + "\",\n"); - source.push_back(String("\t\t\"instantiable\": ") + (api.is_instantiable ? "true" : "false") + ",\n"); - source.push_back(String("\t\t\"is_ref_counted\": ") + (api.is_ref_counted ? "true" : "false") + ",\n"); - - source.push_back("\t\t\"constants\": {\n"); - for (List<ConstantAPI>::Element *e = api.constants.front(); e; e = e->next()) { - source.push_back("\t\t\t\"" + e->get().constant_name + "\": " + String::num_int64(e->get().constant_value) + (e->next() ? "," : "") + "\n"); - } - source.push_back("\t\t},\n"); - - source.push_back("\t\t\"properties\": [\n"); - for (List<PropertyAPI>::Element *e = api.properties.front(); e; e = e->next()) { - source.push_back("\t\t\t{\n"); - source.push_back("\t\t\t\t\"name\": \"" + e->get().name + "\",\n"); - source.push_back("\t\t\t\t\"type\": \"" + e->get().type + "\",\n"); - source.push_back("\t\t\t\t\"getter\": \"" + e->get().getter + "\",\n"); - source.push_back("\t\t\t\t\"setter\": \"" + e->get().setter + "\",\n"); - source.push_back(String("\t\t\t\t\"index\": ") + itos(e->get().index) + "\n"); - source.push_back(String("\t\t\t}") + (e->next() ? "," : "") + "\n"); - } - source.push_back("\t\t],\n"); - - source.push_back("\t\t\"signals\": [\n"); - for (List<SignalAPI>::Element *e = api.signals_.front(); e; e = e->next()) { - source.push_back("\t\t\t{\n"); - source.push_back("\t\t\t\t\"name\": \"" + e->get().name + "\",\n"); - source.push_back("\t\t\t\t\"arguments\": [\n"); - for (int i = 0; i < e->get().argument_names.size(); i++) { - source.push_back("\t\t\t\t\t{\n"); - source.push_back("\t\t\t\t\t\t\"name\": \"" + e->get().argument_names[i] + "\",\n"); - source.push_back("\t\t\t\t\t\t\"type\": \"" + e->get().argument_types[i] + "\",\n"); - source.push_back(String("\t\t\t\t\t\t\"has_default_value\": ") + (e->get().default_arguments.has(i) ? "true" : "false") + ",\n"); - String default_value; - if (e->get().default_arguments.has(i)) { - writer.write_to_string(e->get().default_arguments[i], default_value); - default_value = default_value.replace("\n", "").json_escape(); - } - source.push_back("\t\t\t\t\t\t\"default_value\": \"" + default_value + "\"\n"); - source.push_back(String("\t\t\t\t\t}") + ((i < e->get().argument_names.size() - 1) ? "," : "") + "\n"); - } - source.push_back("\t\t\t\t]\n"); - source.push_back(String("\t\t\t}") + (e->next() ? "," : "") + "\n"); - } - source.push_back("\t\t],\n"); - - source.push_back("\t\t\"methods\": [\n"); - for (List<MethodAPI>::Element *e = api.methods.front(); e; e = e->next()) { - source.push_back("\t\t\t{\n"); - source.push_back("\t\t\t\t\"name\": \"" + e->get().method_name + "\",\n"); - source.push_back("\t\t\t\t\"return_type\": \"" + e->get().return_type + "\",\n"); - source.push_back(String("\t\t\t\t\"is_editor\": ") + (e->get().is_editor ? "true" : "false") + ",\n"); - source.push_back(String("\t\t\t\t\"is_noscript\": ") + (e->get().is_noscript ? "true" : "false") + ",\n"); - source.push_back(String("\t\t\t\t\"is_const\": ") + (e->get().is_const ? "true" : "false") + ",\n"); - source.push_back(String("\t\t\t\t\"is_reverse\": ") + (e->get().is_reverse ? "true" : "false") + ",\n"); - source.push_back(String("\t\t\t\t\"is_virtual\": ") + (e->get().is_virtual ? "true" : "false") + ",\n"); - source.push_back(String("\t\t\t\t\"has_varargs\": ") + (e->get().has_varargs ? "true" : "false") + ",\n"); - source.push_back(String("\t\t\t\t\"is_from_script\": ") + (e->get().is_from_script ? "true" : "false") + ",\n"); - source.push_back("\t\t\t\t\"arguments\": [\n"); - for (int i = 0; i < e->get().argument_names.size(); i++) { - source.push_back("\t\t\t\t\t{\n"); - source.push_back("\t\t\t\t\t\t\"name\": \"" + e->get().argument_names[i] + "\",\n"); - source.push_back("\t\t\t\t\t\t\"type\": \"" + e->get().argument_types[i] + "\",\n"); - source.push_back(String("\t\t\t\t\t\t\"has_default_value\": ") + (e->get().default_arguments.has(i) ? "true" : "false") + ",\n"); - String default_value; - if (e->get().default_arguments.has(i)) { - writer.write_to_string(e->get().default_arguments[i], default_value); - default_value = default_value.replace("\n", "").json_escape(); - } - source.push_back("\t\t\t\t\t\t\"default_value\": \"" + default_value + "\"\n"); - source.push_back(String("\t\t\t\t\t}") + ((i < e->get().argument_names.size() - 1) ? "," : "") + "\n"); - } - source.push_back("\t\t\t\t]\n"); - source.push_back(String("\t\t\t}") + (e->next() ? "," : "") + "\n"); - } - source.push_back("\t\t],\n"); - - source.push_back("\t\t\"enums\": [\n"); - for (List<EnumAPI>::Element *e = api.enums.front(); e; e = e->next()) { - source.push_back("\t\t\t{\n"); - source.push_back("\t\t\t\t\"name\": \"" + e->get().name + "\",\n"); - source.push_back("\t\t\t\t\"values\": {\n"); - for (List<Pair<int, String>>::Element *val_e = e->get().values.front(); val_e; val_e = val_e->next()) { - source.push_back("\t\t\t\t\t\"" + val_e->get().second + "\": " + itos(val_e->get().first)); - source.push_back(String((val_e->next() ? "," : "")) + "\n"); - } - source.push_back("\t\t\t\t}\n"); - source.push_back(String("\t\t\t}") + (e->next() ? "," : "") + "\n"); - } - source.push_back("\t\t]\n"); - - source.push_back(String("\t}") + (c->next() ? "," : "") + "\n"); - } - source.push_back("]"); - - return source; -} - -static int indent_level = 0; - -static void append_indented(StringBuilder &p_source, const String &p_text) { - for (int i = 0; i < indent_level; i++) { - p_source.append("\t"); - } - p_source.append(p_text); - p_source.append("\n"); -} - -static void append_indented(StringBuilder &p_source, const char *p_text) { - for (int i = 0; i < indent_level; i++) { - p_source.append("\t"); - } - p_source.append(p_text); - p_source.append("\n"); -} - -static void write_builtin_method(StringBuilder &p_source, const MethodAPI &p_method) { - VariantWriter writer; - - append_indented(p_source, vformat(R"("name": "%s",)", p_method.method_name)); - append_indented(p_source, vformat(R"("return_type": "%s",)", p_method.return_type)); - append_indented(p_source, vformat(R"("is_const": %s,)", p_method.is_const ? "true" : "false")); - append_indented(p_source, vformat(R"("is_static": %s,)", p_method.is_static ? "true" : "false")); - append_indented(p_source, vformat(R"("has_varargs": %s,)", p_method.has_varargs ? "true" : "false")); - - append_indented(p_source, R"("arguments": [)"); - indent_level++; - for (int i = 0; i < p_method.argument_count; i++) { - append_indented(p_source, "{"); - indent_level++; - - append_indented(p_source, vformat(R"("name": "%s",)", p_method.argument_names[i])); - append_indented(p_source, vformat(R"("type": "%s",)", p_method.argument_types[i])); - append_indented(p_source, vformat(R"("has_default_value": %s,)", p_method.default_arguments.has(i) ? "true" : "false")); - String default_value; - if (p_method.default_arguments.has(i)) { - writer.write_to_string(p_method.default_arguments[i], default_value); - default_value = default_value.replace("\n", "").json_escape(); - } - append_indented(p_source, vformat(R"("default_value": "%s")", default_value)); - - indent_level--; - append_indented(p_source, i < p_method.argument_count - 1 ? "}," : "}"); - } - indent_level--; - append_indented(p_source, "]"); -} - -static List<String> generate_c_builtin_api_json(const List<ClassAPI> &p_api) { - StringBuilder source; - - source.append("[\n"); - - indent_level = 1; - - for (const List<ClassAPI>::Element *C = p_api.front(); C; C = C->next()) { - const ClassAPI &class_api = C->get(); - append_indented(source, "{"); - indent_level++; - - append_indented(source, vformat(R"("name": "%s",)", class_api.class_name)); - append_indented(source, vformat(R"("is_instantiable": %s,)", class_api.is_instantiable ? "true" : "false")); - append_indented(source, vformat(R"("is_ref_counted": %s,)", class_api.is_ref_counted ? "true" : "false")); - append_indented(source, vformat(R"("has_indexing": %s,)", class_api.has_indexing ? "true" : "false")); - append_indented(source, vformat(R"("indexed_type": "%s",)", class_api.has_indexing && class_api.indexed_type == "Nil" ? "Variant" : class_api.indexed_type)); - append_indented(source, vformat(R"("is_keyed": %s,)", class_api.is_keyed ? "true" : "false")); - - // Constructors. - append_indented(source, R"("constructors": [)"); - indent_level++; - for (const List<MethodAPI>::Element *E = class_api.constructors.front(); E; E = E->next()) { - const MethodAPI &constructor = E->get(); - append_indented(source, "{"); - indent_level++; - - write_builtin_method(source, constructor); - - indent_level--; - append_indented(source, E->next() ? "}," : "}"); - } - indent_level--; - append_indented(source, "],"); - - // Constants. - append_indented(source, R"("constants": [)"); - indent_level++; - for (const List<ConstantAPI>::Element *E = class_api.constants.front(); E; E = E->next()) { - const ConstantAPI &constant = E->get(); - append_indented(source, "{"); - indent_level++; - - append_indented(source, vformat(R"("name": "%s",)", constant.constant_name)); - append_indented(source, vformat(R"("type": "%s",)", constant.builtin_constant_type)); - append_indented(source, vformat(R"("value": "%s")", constant.builtin_constant_value.operator String())); - - indent_level--; - append_indented(source, E->next() ? "}," : "}"); - } - indent_level--; - append_indented(source, "],"); - - // Methods. - append_indented(source, R"("methods": [)"); - indent_level++; - for (const List<MethodAPI>::Element *E = class_api.methods.front(); E; E = E->next()) { - const MethodAPI &method = E->get(); - append_indented(source, "{"); - indent_level++; - - write_builtin_method(source, method); - - indent_level--; - append_indented(source, E->next() ? "}," : "}"); - } - indent_level--; - append_indented(source, "],"); - - // Members. - append_indented(source, R"("members": [)"); - indent_level++; - for (const List<PropertyAPI>::Element *E = class_api.properties.front(); E; E = E->next()) { - const PropertyAPI &member = E->get(); - append_indented(source, "{"); - indent_level++; - - append_indented(source, vformat(R"("name": "%s",)", member.name)); - append_indented(source, vformat(R"("type": "%s")", member.type)); - - indent_level--; - append_indented(source, E->next() ? "}," : "}"); - } - indent_level--; - append_indented(source, "],"); - - // Operators. - append_indented(source, R"("operators": [)"); - indent_level++; - for (const List<OperatorAPI>::Element *E = class_api.operators.front(); E; E = E->next()) { - const OperatorAPI &oper = E->get(); - append_indented(source, "{"); - indent_level++; - - append_indented(source, vformat(R"("name": "%s",)", oper.name)); - append_indented(source, vformat(R"("operator": %d,)", oper.oper)); - append_indented(source, vformat(R"("other_type": "%s",)", oper.other_type)); - append_indented(source, vformat(R"("return_type": "%s")", oper.return_type)); - - indent_level--; - append_indented(source, E->next() ? "}," : "}"); - } - indent_level--; - append_indented(source, "]"); - - indent_level--; - append_indented(source, C->next() ? "}," : "}"); - } - - indent_level--; - source.append("]\n"); - - List<String> result; - result.push_back(source.as_string()); - return result; -} - -#endif - -/* - * Saves the whole Godot API to a JSON file located at - * p_path - */ -Error generate_c_api(const String &p_path) { -#ifndef TOOLS_ENABLED - return ERR_BUG; -#else - - List<ClassAPI> api = generate_c_api_classes(); - - List<String> json_source = generate_c_api_json(api); - - return save_file(p_path, json_source); -#endif -} -/* - * Saves the builtin Godot API to a JSON file located at - * p_path - */ -Error generate_c_builtin_api(const String &p_path) { -#ifndef TOOLS_ENABLED - return ERR_BUG; -#else - - List<ClassAPI> api = generate_c_builtin_api_types(); - - List<String> json_source = generate_c_builtin_api_json(api); - - return save_file(p_path, json_source); -#endif -} diff --git a/modules/gdnative/nativescript/api_generator.h b/modules/gdnative/nativescript/api_generator.h deleted file mode 100644 index 58e141f07e..0000000000 --- a/modules/gdnative/nativescript/api_generator.h +++ /dev/null @@ -1,40 +0,0 @@ -/*************************************************************************/ -/* api_generator.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef API_GENERATOR_H -#define API_GENERATOR_H - -#include "core/string/ustring.h" -#include "core/typedefs.h" - -Error generate_c_api(const String &p_path); -Error generate_c_builtin_api(const String &p_path); - -#endif // API_GENERATOR_H diff --git a/modules/gdnative/nativescript/godot_nativescript.cpp b/modules/gdnative/nativescript/godot_nativescript.cpp deleted file mode 100644 index 992eeba8f4..0000000000 --- a/modules/gdnative/nativescript/godot_nativescript.cpp +++ /dev/null @@ -1,344 +0,0 @@ -/*************************************************************************/ -/* godot_nativescript.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "nativescript/godot_nativescript.h" - -#include "core/config/project_settings.h" -#include "core/core_constants.h" -#include "core/error/error_macros.h" -#include "core/object/class_db.h" -#include "core/variant/variant.h" -#include "gdnative/gdnative.h" -#include <stdint.h> - -#include "nativescript.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern "C" void _native_script_hook() { -} - -#define NSL NativeScriptLanguage::get_singleton() - -// Script API - -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]; - - NativeScriptDesc desc; - - desc.create_func = p_create_func; - desc.destroy_func = p_destroy_func; - desc.is_tool = false; - - desc.base = p_base; - - if (classes->has(p_base)) { - desc.base_data = &(*classes)[p_base]; - desc.base_native_type = desc.base_data->base_native_type; - - const NativeScriptDesc *b = desc.base_data; - while (b) { - desc.rpc_methods.append_array(b->rpc_methods); - b = b->base_data; - } - - } else { - desc.base_data = nullptr; - desc.base_native_type = p_base; - } - - 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_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]; - - NativeScriptDesc desc; - - desc.create_func = p_create_func; - desc.destroy_func = p_destroy_func; - desc.is_tool = true; - desc.base = p_base; - - if (classes->has(p_base)) { - desc.base_data = &(*classes)[p_base]; - desc.base_native_type = desc.base_data->base_native_type; - - const NativeScriptDesc *b = desc.base_data; - while (b) { - desc.rpc_methods.append_array(b->rpc_methods); - b = b->base_data; - } - - } else { - desc.base_data = nullptr; - desc.base_native_type = p_base; - } - - 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_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); - ERR_FAIL_COND_MSG(!E, "Attempted to register method on non-existent class."); - - NativeScriptDesc::Method method; - method.method = p_method; - method.rpc_mode = p_attr.rpc_type; - method.rpc_method_id = UINT16_MAX; - method.info = MethodInfo(p_function_name); - - E->get().methods.insert(p_function_name, method); - - if (p_attr.rpc_type != GODOT_METHOD_RPC_MODE_DISABLED) { - Multiplayer::RPCConfig nd; - nd.name = String(p_name); - nd.rpc_mode = Multiplayer::RPCMode(p_attr.rpc_type); - E->get().rpc_methods.push_back(nd); - } -} - -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); - ERR_FAIL_COND_MSG(!E, "Attempted to register method on non-existent class."); - - NativeScriptDesc::Property property; - property.default_value = *(Variant *)&p_attr->default_value; - property.getter = p_get_func; - property.setter = p_set_func; - property.info = PropertyInfo((Variant::Type)p_attr->type, - p_path, - (PropertyHint)p_attr->hint, - *(String *)&p_attr->hint_string, - (PropertyUsageFlags)p_attr->usage); - - E->get().properties.insert(p_path, property); -} - -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); - ERR_FAIL_COND_MSG(!E, "Attempted to register method on non-existent class."); - - List<PropertyInfo> args; - Vector<Variant> default_args; - - for (int i = 0; i < p_signal->num_args; i++) { - PropertyInfo info; - - godot_nativescript_signal_argument arg = p_signal->args[i]; - - info.hint = (PropertyHint)arg.hint; - info.hint_string = *(String *)&arg.hint_string; - info.name = *(String *)&arg.name; - info.type = (Variant::Type)arg.type; - info.usage = (PropertyUsageFlags)arg.usage; - - args.push_back(info); - } - - for (int i = 0; i < p_signal->num_default_args; i++) { - Variant *v; - godot_nativescript_signal_argument attrib = p_signal->args[i]; - - v = (Variant *)&attrib.default_value; - - default_args.push_back(*v); - } - - MethodInfo method_info; - method_info.name = *(String *)&p_signal->name; - method_info.arguments = args; - method_info.default_arguments = default_args; - - NativeScriptDesc::Signal signal; - signal.signal = method_info; - - E->get().signals_.insert(*(String *)&p_signal->name, signal); -} - -void GDAPI *godot_nativescript_get_userdata(godot_object *p_instance) { - Object *instance = (Object *)p_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; - } - return nullptr; -} - -/* - * - * - * NativeScript 1.1 - * - * - */ - -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); - ERR_FAIL_COND_MSG(!E, "Attempted to add argument information for a method on a non-existent class."); - - Map<StringName, NativeScriptDesc::Method>::Element *method = E->get().methods.find(p_function_name); - ERR_FAIL_COND_MSG(!method, "Attempted to add argument information to non-existent method."); - - MethodInfo *method_information = &method->get().info; - - List<PropertyInfo> args; - - for (int i = 0; i < p_num_args; i++) { - godot_nativescript_method_argument arg = p_args[i]; - String name = *(String *)&arg.name; - String hint_string = *(String *)&arg.hint_string; - - Variant::Type type = (Variant::Type)arg.type; - PropertyHint hint = (PropertyHint)arg.hint; - - args.push_back(PropertyInfo(type, p_name, hint, hint_string)); - } - - method_information->arguments = args; -} - -void GDAPI godot_nativescript_set_class_documentation(void *p_gdnative_handle, const char *p_name, godot_string p_documentation) { - String *s = (String *)p_gdnative_handle; - - Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a non-existent class."); - - E->get().documentation = *(String *)&p_documentation; -} - -void GDAPI godot_nativescript_set_method_documentation(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_string p_documentation) { - String *s = (String *)p_gdnative_handle; - - Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a method on a non-existent class."); - - Map<StringName, NativeScriptDesc::Method>::Element *method = E->get().methods.find(p_function_name); - ERR_FAIL_COND_MSG(!method, "Attempted to add documentation to non-existent method."); - - method->get().documentation = *(String *)&p_documentation; -} - -void GDAPI godot_nativescript_set_property_documentation(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_string p_documentation) { - String *s = (String *)p_gdnative_handle; - - Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a property on a non-existent class."); - - OrderedHashMap<StringName, NativeScriptDesc::Property>::Element property = E->get().properties.find(p_path); - ERR_FAIL_COND_MSG(!property, "Attempted to add documentation to non-existent property."); - - property.get().documentation = *(String *)&p_documentation; -} - -void GDAPI godot_nativescript_set_signal_documentation(void *p_gdnative_handle, const char *p_name, const char *p_signal_name, godot_string p_documentation) { - String *s = (String *)p_gdnative_handle; - - Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a signal on a non-existent class."); - - Map<StringName, NativeScriptDesc::Signal>::Element *signal = E->get().signals_.find(p_signal_name); - ERR_FAIL_COND_MSG(!signal, "Attempted to add documentation to non-existent signal."); - - signal->get().documentation = *(String *)&p_documentation; -} - -void GDAPI godot_nativescript_set_global_type_tag(int p_idx, const char *p_name, const void *p_type_tag) { - NativeScriptLanguage::get_singleton()->set_global_type_tag(p_idx, StringName(p_name), p_type_tag); -} - -const void GDAPI *godot_nativescript_get_global_type_tag(int p_idx, const char *p_name) { - return NativeScriptLanguage::get_singleton()->get_global_type_tag(p_idx, StringName(p_name)); -} - -void GDAPI godot_nativescript_set_type_tag(void *p_gdnative_handle, const char *p_name, const void *p_type_tag) { - String *s = (String *)p_gdnative_handle; - - Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - ERR_FAIL_COND_MSG(!E, "Attempted to set type tag on a non-existent class."); - - E->get().type_tag = p_type_tag; -} - -const void GDAPI *godot_nativescript_get_type_tag(const godot_object *p_object) { - const Object *o = (Object *)p_object; - - if (!o->get_script_instance()) { - return nullptr; - } else { - NativeScript *script = Object::cast_to<NativeScript>(o->get_script_instance()->get_script().ptr()); - if (!script) { - return nullptr; - } - - if (script->get_script_desc()) { - return script->get_script_desc()->type_tag; - } - } - - return nullptr; -} - -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); -} - -void GDAPI godot_nativescript_unregister_instance_binding_data_functions(int p_idx) { - NativeScriptLanguage::get_singleton()->unregister_binding_functions(p_idx); -} - -void GDAPI *godot_nativescript_get_instance_binding_data(int p_idx, godot_object *p_object) { - return nullptr; -} - -void GDAPI godot_nativescript_profiling_add_data(const char *p_signature, uint64_t p_time) { - NativeScriptLanguage::get_singleton()->profiling_add_data(StringName(p_signature), p_time); -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp deleted file mode 100644 index 95976a8827..0000000000 --- a/modules/gdnative/nativescript/nativescript.cpp +++ /dev/null @@ -1,1777 +0,0 @@ -/*************************************************************************/ -/* nativescript.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "nativescript.h" - -#include <stdint.h> - -#include "gdnative/gdnative.h" - -#include "core/config/project_settings.h" -#include "core/core_constants.h" -#include "core/core_string_names.h" -#include "core/io/file_access.h" -#include "core/io/file_access_encrypted.h" -#include "core/os/os.h" - -#include "main/main.h" - -#include "scene/main/scene_tree.h" -#include "scene/resources/resource_format_text.h" - -#include <stdlib.h> - -#ifndef NO_THREADS -#include "core/os/thread.h" -#endif - -#if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED) -#include "api_generator.h" -#endif - -#ifdef TOOLS_ENABLED -#include "editor/editor_node.h" -#endif - -void NativeScript::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_class_name", "class_name"), &NativeScript::set_class_name); - ClassDB::bind_method(D_METHOD("get_class_name"), &NativeScript::get_class_name); - - ClassDB::bind_method(D_METHOD("set_library", "library"), &NativeScript::set_library); - ClassDB::bind_method(D_METHOD("get_library"), &NativeScript::get_library); - - ClassDB::bind_method(D_METHOD("set_script_class_name", "class_name"), &NativeScript::set_script_class_name); - ClassDB::bind_method(D_METHOD("get_script_class_name"), &NativeScript::get_script_class_name); - ClassDB::bind_method(D_METHOD("set_script_class_icon_path", "icon_path"), &NativeScript::set_script_class_icon_path); - ClassDB::bind_method(D_METHOD("get_script_class_icon_path"), &NativeScript::get_script_class_icon_path); - - ClassDB::bind_method(D_METHOD("get_class_documentation"), &NativeScript::get_class_documentation); - ClassDB::bind_method(D_METHOD("get_method_documentation", "method"), &NativeScript::get_method_documentation); - ClassDB::bind_method(D_METHOD("get_signal_documentation", "signal_name"), &NativeScript::get_signal_documentation); - ClassDB::bind_method(D_METHOD("get_property_documentation", "path"), &NativeScript::get_property_documentation); - - ADD_PROPERTY(PropertyInfo(Variant::STRING, "class_name"), "set_class_name", "get_class_name"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "GDNativeLibrary"), "set_library", "get_library"); - ADD_GROUP("Script Class", "script_class_"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "script_class_name"), "set_script_class_name", "get_script_class_name"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "script_class_icon_path", PROPERTY_HINT_FILE), "set_script_class_icon_path", "get_script_class_icon_path"); - - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &NativeScript::_new, MethodInfo("new")); -} - -#define NSL NativeScriptLanguage::get_singleton() - -#ifdef TOOLS_ENABLED - -void NativeScript::_update_placeholder(PlaceHolderScriptInstance *p_placeholder) { - NativeScriptDesc *script_data = get_script_desc(); - - ERR_FAIL_COND(!script_data); - - List<PropertyInfo> info; - get_script_property_list(&info); - Map<StringName, Variant> values; - for (const PropertyInfo &E : info) { - Variant value; - get_property_default_value(E.name, value); - values[E.name] = value; - } - - p_placeholder->update(info, values); -} - -void NativeScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) { - placeholders.erase(p_placeholder); -} - -#endif - -bool NativeScript::inherits_script(const Ref<Script> &p_script) const { - Ref<NativeScript> ns = p_script; - if (ns.is_null()) { - return false; - } - - const NativeScriptDesc *other_s = ns->get_script_desc(); - if (!other_s) { - return false; - } - - const NativeScriptDesc *s = get_script_desc(); - - while (s) { - if (s == other_s) { - return true; - } - s = s->base_data; - } - - return false; -} - -void NativeScript::set_class_name(String p_class_name) { - class_name = p_class_name; -} - -String NativeScript::get_class_name() const { - return class_name; -} - -void NativeScript::set_library(Ref<GDNativeLibrary> p_library) { - if (!library.is_null()) { - WARN_PRINT("Library in NativeScript already set. Do nothing."); - return; - } - if (p_library.is_null()) { - return; - } - library = p_library; - lib_path = library->get_current_library_path(); - -#ifndef NO_THREADS - if (Thread::get_caller_id() != Thread::get_main_id()) { - NSL->defer_init_library(p_library, this); - } else -#endif - { - NSL->init_library(p_library); - NSL->register_script(this); - } -} - -Ref<GDNativeLibrary> NativeScript::get_library() const { - return library; -} - -void NativeScript::set_script_class_name(String p_type) { - script_class_name = p_type; -} - -String NativeScript::get_script_class_name() const { - return script_class_name; -} - -void NativeScript::set_script_class_icon_path(String p_icon_path) { - script_class_icon_path = p_icon_path; -} - -String NativeScript::get_script_class_icon_path() const { - return script_class_icon_path; -} - -bool NativeScript::can_instantiate() const { - NativeScriptDesc *script_data = get_script_desc(); - -#ifdef TOOLS_ENABLED - // Only valid if this is either a tool script or a "regular" script. - // (so, an environment where scripting is disabled (and not the editor) would not - // create objects). - return script_data && (is_tool() || ScriptServer::is_scripting_enabled()); -#else - return script_data; -#endif -} - -Ref<Script> NativeScript::get_base_script() const { - NativeScriptDesc *script_data = get_script_desc(); - - if (!script_data) { - return Ref<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; -} - -StringName NativeScript::get_instance_base_type() const { - NativeScriptDesc *script_data = get_script_desc(); - - 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) { - return nullptr; - } - - NativeScriptInstance *nsi = memnew(NativeScriptInstance); - - nsi->owner = p_this; - nsi->script = Ref<NativeScript>(this); - -#ifndef TOOLS_ENABLED - if (!ScriptServer::is_scripting_enabled()) { - nsi->userdata = nullptr; - } else { - nsi->userdata = script_data->create_func.create_func((godot_object *)p_this, script_data->create_func.method_data); - } -#else - nsi->userdata = script_data->create_func.create_func((godot_object *)p_this, script_data->create_func.method_data); -#endif - - { - MutexLock lock(owners_lock); - - instance_owners.insert(p_this); - } - - return nsi; -} - -PlaceHolderScriptInstance *NativeScript::placeholder_instance_create(Object *p_this) { -#ifdef TOOLS_ENABLED - PlaceHolderScriptInstance *sins = memnew(PlaceHolderScriptInstance(NSL, Ref<Script>(this), p_this)); - placeholders.insert(sins); - - _update_placeholder(sins); - - return sins; -#else - return nullptr; -#endif -} - -bool NativeScript::instance_has(const Object *p_this) const { - return instance_owners.has((Object *)p_this); -} - -bool NativeScript::has_source_code() const { - return false; -} - -String NativeScript::get_source_code() const { - return ""; -} - -void NativeScript::set_source_code(const String &p_code) { -} - -Error NativeScript::reload(bool p_keep_state) { - return FAILED; -} - -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)) { - return true; - } - - script_data = script_data->base_data; - } - return false; -} - -MethodInfo NativeScript::get_method_info(const StringName &p_method) const { - NativeScriptDesc *script_data = get_script_desc(); - - if (!script_data) { - return MethodInfo(); - } - - while (script_data) { - Map<StringName, NativeScriptDesc::Method>::Element *M = script_data->methods.find(p_method); - - if (M) { - return M->get().info; - } - - script_data = script_data->base_data; - } - return MethodInfo(); -} - -bool NativeScript::is_valid() const { - return true; -} - -bool NativeScript::is_tool() const { - NativeScriptDesc *script_data = get_script_desc(); - - if (script_data) { - return script_data->is_tool; - } - - return false; -} - -ScriptLanguage *NativeScript::get_language() const { - return NativeScriptLanguage::get_singleton(); -} - -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)) { - return true; - } - script_data = script_data->base_data; - } - return false; -} - -void NativeScript::get_script_signal_list(List<MethodInfo> *r_signals) const { - NativeScriptDesc *script_data = get_script_desc(); - - if (!script_data) { - return; - } - - Set<MethodInfo> signals_; - - while (script_data) { - for (const KeyValue<StringName, NativeScriptDesc::Signal> &S : script_data->signals_) { - signals_.insert(S.value.signal); - } - - script_data = script_data->base_data; - } - - for (Set<MethodInfo>::Element *E = signals_.front(); E; E = E->next()) { - r_signals->push_back(E->get()); - } -} - -bool NativeScript::get_property_default_value(const StringName &p_property, Variant &r_value) const { - NativeScriptDesc *script_data = get_script_desc(); - - OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P; - while (!P && script_data) { - P = script_data->properties.find(p_property); - script_data = script_data->base_data; - } - if (!P) { - return false; - } - - r_value = P.get().default_value; - return true; -} - -void NativeScript::update_exports() { -} - -void NativeScript::get_script_method_list(List<MethodInfo> *p_list) const { - NativeScriptDesc *script_data = get_script_desc(); - - if (!script_data) { - return; - } - - Set<MethodInfo> methods; - - while (script_data) { - for (const KeyValue<StringName, NativeScriptDesc::Method> &E : script_data->methods) { - methods.insert(E.value.info); - } - - script_data = script_data->base_data; - } - - for (Set<MethodInfo>::Element *E = methods.front(); E; E = E->next()) { - p_list->push_back(E->get()); - } -} - -void NativeScript::get_script_property_list(List<PropertyInfo> *p_list) const { - NativeScriptDesc *script_data = get_script_desc(); - - Set<StringName> existing_properties; - List<PropertyInfo>::Element *original_back = p_list->back(); - while (script_data) { - List<PropertyInfo>::Element *insert_position = original_back; - - for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.front(); E; E = E.next()) { - if (!existing_properties.has(E.key())) { - insert_position = p_list->insert_after(insert_position, E.get().info); - existing_properties.insert(E.key()); - } - } - script_data = script_data->base_data; - } -} - -const Vector<Multiplayer::RPCConfig> NativeScript::get_rpc_methods() const { - NativeScriptDesc *script_data = get_script_desc(); - ERR_FAIL_COND_V(!script_data, Vector<Multiplayer::RPCConfig>()); - - return script_data->rpc_methods; -} - -String NativeScript::get_class_documentation() const { - NativeScriptDesc *script_data = get_script_desc(); - - ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get class documentation on invalid NativeScript."); - - return script_data->documentation; -} - -String NativeScript::get_method_documentation(const StringName &p_method) const { - NativeScriptDesc *script_data = get_script_desc(); - - 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) { - return method->get().documentation; - } - - script_data = script_data->base_data; - } - - ERR_FAIL_V_MSG("", "Attempt to get method documentation for non-existent method."); -} - -String NativeScript::get_signal_documentation(const StringName &p_signal_name) const { - NativeScriptDesc *script_data = get_script_desc(); - - 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) { - return signal->get().documentation; - } - - script_data = script_data->base_data; - } - - ERR_FAIL_V_MSG("", "Attempt to get signal documentation for non-existent signal."); -} - -String NativeScript::get_property_documentation(const StringName &p_path) const { - NativeScriptDesc *script_data = get_script_desc(); - - 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) { - return property.get().documentation; - } - - script_data = script_data->base_data; - } - - ERR_FAIL_V_MSG("", "Attempt to get property documentation for non-existent signal."); -} - -Variant NativeScript::_new(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (lib_path.is_empty() || class_name.is_empty() || library.is_null()) { - r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL; - return Variant(); - } - - NativeScriptDesc *script_data = get_script_desc(); - - if (!script_data) { - r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL; - return Variant(); - } - - r_error.error = Callable::CallError::CALL_OK; - - REF ref; - Object *owner = nullptr; - - if (!(script_data->base_native_type == "")) { - owner = ClassDB::instantiate(script_data->base_native_type); - } else { - owner = memnew(RefCounted); - } - - if (!owner) { - r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL; - return Variant(); - } - - RefCounted *r = Object::cast_to<RefCounted>(owner); - if (r) { - ref = REF(r); - } - - NativeScriptInstance *instance = (NativeScriptInstance *)instance_create(owner); - - owner->set_script_instance(instance); - - if (!instance) { - if (ref.is_null()) { - memdelete(owner); //no owner, sorry - } - return Variant(); - } - - if (ref.is_valid()) { - return ref; - } else { - return owner; - } -} - -NativeScript::NativeScript() { - library = Ref<GDNative>(); - lib_path = ""; - class_name = ""; -} - -NativeScript::~NativeScript() { - NSL->unregister_script(this); -} - -#define GET_SCRIPT_DESC() script->get_script_desc() - -void NativeScriptInstance::_ml_call_reversed(NativeScriptDesc *script_data, const StringName &p_method, const Variant **p_args, int p_argcount) { - if (script_data->base_data) { - _ml_call_reversed(script_data->base_data, p_method, p_args, p_argcount); - } - - Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method); - if (E) { - godot_variant res = E->get().method.method((godot_object *)owner, E->get().method.method_data, userdata, p_argcount, (godot_variant **)p_args); - godot_variant_destroy(&res); - } -} - -bool NativeScriptInstance::set(const StringName &p_name, const Variant &p_value) { - NativeScriptDesc *script_data = GET_SCRIPT_DESC(); - - while (script_data) { - OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = script_data->properties.find(p_name); - if (P) { - P.get().setter.set_func((godot_object *)owner, - P.get().setter.method_data, - userdata, - (godot_variant *)&p_value); - return true; - } - - Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find("_set"); - if (E) { - Variant name = p_name; - const Variant *args[2] = { &name, &p_value }; - - godot_variant result; - result = E->get().method.method((godot_object *)owner, - E->get().method.method_data, - userdata, - 2, - (godot_variant **)args); - bool handled = *(Variant *)&result; - godot_variant_destroy(&result); - if (handled) { - return true; - } - } - - script_data = script_data->base_data; - } - return false; -} - -bool NativeScriptInstance::get(const StringName &p_name, Variant &r_ret) const { - NativeScriptDesc *script_data = GET_SCRIPT_DESC(); - - while (script_data) { - OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = script_data->properties.find(p_name); - if (P) { - godot_variant value; - value = P.get().getter.get_func((godot_object *)owner, - P.get().getter.method_data, - userdata); - r_ret = *(Variant *)&value; - godot_variant_destroy(&value); - return true; - } - - Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find("_get"); - if (E) { - Variant name = p_name; - const Variant *args[1] = { &name }; - - godot_variant result; - result = E->get().method.method((godot_object *)owner, - E->get().method.method_data, - userdata, - 1, - (godot_variant **)args); - r_ret = *(Variant *)&result; - godot_variant_destroy(&result); - if (r_ret.get_type() != Variant::NIL) { - return true; - } - } - - script_data = script_data->base_data; - } - return false; -} - -void NativeScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const { - script->get_script_property_list(p_properties); - - 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, - userdata, - 0, - nullptr); - Variant res = *(Variant *)&result; - godot_variant_destroy(&result); - - ERR_FAIL_COND_MSG(res.get_type() != Variant::ARRAY, "_get_property_list must return an array of dictionaries."); - - Array arr = res; - for (int i = 0; i < arr.size(); i++) { - Dictionary d = arr[i]; - - ERR_CONTINUE(!d.has("name")); - ERR_CONTINUE(!d.has("type")); - - PropertyInfo info; - - info.type = Variant::Type(d["type"].operator int64_t()); - ERR_CONTINUE(info.type < 0 || info.type >= Variant::VARIANT_MAX); - - info.name = d["name"]; - ERR_CONTINUE(info.name.is_empty()); - - if (d.has("hint")) { - info.hint = PropertyHint(d["hint"].operator int64_t()); - } - - if (d.has("hint_string")) { - info.hint_string = d["hint_string"]; - } - - if (d.has("usage")) { - info.usage = d["usage"]; - } - - p_properties->push_back(info); - } - } - - script_data = script_data->base_data; - } - return; -} - -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; - return P.get().info.type; - } - - script_data = script_data->base_data; - } - return Variant::NIL; -} - -void NativeScriptInstance::get_method_list(List<MethodInfo> *p_list) const { - script->get_script_method_list(p_list); -} - -bool NativeScriptInstance::has_method(const StringName &p_method) const { - return script->has_method(p_method); -} - -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) { - Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method); - if (E) { - godot_variant result; - -#ifdef DEBUG_ENABLED - current_method_call = p_method; -#endif - - result = E->get().method.method((godot_object *)owner, - E->get().method.method_data, - userdata, - p_argcount, - (godot_variant **)p_args); - -#ifdef DEBUG_ENABLED - current_method_call = ""; -#endif - - Variant res = *(Variant *)&result; - godot_variant_destroy(&result); - r_error.error = Callable::CallError::CALL_OK; - return res; - } - - script_data = script_data->base_data; - } - - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; - return Variant(); -} - -void NativeScriptInstance::notification(int p_what) { -#ifdef DEBUG_ENABLED - switch (p_what) { - case MainLoop::NOTIFICATION_CRASH: { - if (current_method_call != StringName()) { - ERR_PRINT("NativeScriptInstance detected crash on method: " + current_method_call); - current_method_call = ""; - } - } break; - } -#endif - - Variant value = p_what; - const Variant *args[1] = { &value }; - Callable::CallError error; - call("_notification", args, 1, error); -} - -String NativeScriptInstance::to_string(bool *r_valid) { - if (has_method(CoreStringNames::get_singleton()->_to_string)) { - Callable::CallError ce; - 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) { - *r_valid = false; - } - ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); - } - if (r_valid) { - *r_valid = true; - } - return ret.operator String(); - } - } - if (r_valid) { - *r_valid = false; - } - return String(); -} - -void NativeScriptInstance::refcount_incremented() { - Callable::CallError err; - call("_refcount_incremented", nullptr, 0, err); - if (err.error != Callable::CallError::CALL_OK && err.error != Callable::CallError::CALL_ERROR_INVALID_METHOD) { - ERR_PRINT("Failed to invoke _refcount_incremented - should not happen"); - } -} - -bool NativeScriptInstance::refcount_decremented() { - Callable::CallError err; - Variant ret = call("_refcount_decremented", nullptr, 0, err); - if (err.error != Callable::CallError::CALL_OK && err.error != Callable::CallError::CALL_ERROR_INVALID_METHOD) { - ERR_PRINT("Failed to invoke _refcount_decremented - should not happen"); - return true; // assume we can destroy the object - } - if (err.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) { - // the method does not exist, default is true - return true; - } - return ret; -} - -Ref<Script> NativeScriptInstance::get_script() const { - return script; -} - -const Vector<Multiplayer::RPCConfig> NativeScriptInstance::get_rpc_methods() const { - return script->get_rpc_methods(); -} - -ScriptLanguage *NativeScriptInstance::get_language() { - return NativeScriptLanguage::get_singleton(); -} - -NativeScriptInstance::~NativeScriptInstance() { - NativeScriptDesc *script_data = GET_SCRIPT_DESC(); - - if (!script_data) { - return; - } - - script_data->destroy_func.destroy_func((godot_object *)owner, script_data->destroy_func.method_data, userdata); - - if (owner) { - MutexLock lock(script->owners_lock); - - script->instance_owners.erase(owner); - } -} - -NativeScriptLanguage *NativeScriptLanguage::singleton; - -void NativeScriptLanguage::_unload_stuff(bool p_reload) { - Map<String, Ref<GDNative>> erase_and_unload; - - for (KeyValue<String, Map<StringName, NativeScriptDesc>> &L : library_classes) { - String lib_path = L.key; - Map<StringName, NativeScriptDesc> classes = L.value; - - if (p_reload) { - Map<String, Ref<GDNative>>::Element *E = library_gdnatives.find(lib_path); - Ref<GDNative> gdn; - - if (E) { - gdn = E->get(); - } - - bool should_reload = false; - - if (gdn.is_valid()) { - Ref<GDNativeLibrary> lib = gdn->get_library(); - if (lib.is_valid()) { - should_reload = lib->is_reloadable(); - } - } - - if (!should_reload) { - continue; - } - } - - Map<String, Ref<GDNative>>::Element *E = library_gdnatives.find(lib_path); - Ref<GDNative> gdn; - - if (E) { - gdn = E->get(); - } - - for (KeyValue<StringName, NativeScriptDesc> &C : classes) { - // free property stuff first - for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = C.value.properties.front(); P; P = P.next()) { - if (P.get().getter.free_func) { - P.get().getter.free_func(P.get().getter.method_data); - } - - if (P.get().setter.free_func) { - P.get().setter.free_func(P.get().setter.method_data); - } - } - - // free method stuff - for (const KeyValue<StringName, NativeScriptDesc::Method> &M : C.value.methods) { - if (M.value.method.free_func) { - M.value.method.free_func(M.value.method.method_data); - } - } - - // free constructor/destructor - if (C.value.create_func.free_func) { - C.value.create_func.free_func(C.value.create_func.method_data); - } - - if (C.value.destroy_func.free_func) { - C.value.destroy_func.free_func(C.value.destroy_func.method_data); - } - } - - erase_and_unload.insert(lib_path, gdn); - } - - for (KeyValue<String, Ref<GDNative>> &E : erase_and_unload) { - String lib_path = E.key; - Ref<GDNative> gdn = E.value; - - library_classes.erase(lib_path); - - if (gdn.is_valid() && gdn->get_library().is_valid()) { - Ref<GDNativeLibrary> lib = gdn->get_library(); - void *terminate_fn; - Error err = gdn->get_symbol(lib->get_symbol_prefix() + _terminate_call_name, terminate_fn, true); - - if (err == OK) { - void (*terminate)(void *) = (void (*)(void *))terminate_fn; - - terminate((void *)&lib_path); - } - } - } -} - -NativeScriptLanguage::NativeScriptLanguage() { - NativeScriptLanguage::singleton = this; - - _init_call_type = "nativescript_init"; - _init_call_name = "nativescript_init"; - _terminate_call_name = "nativescript_terminate"; - _noarg_call_type = "nativescript_no_arg"; - _frame_call_name = "nativescript_frame"; -#ifndef NO_THREADS - _thread_enter_call_name = "nativescript_thread_enter"; - _thread_exit_call_name = "nativescript_thread_exit"; -#endif -} - -NativeScriptLanguage::~NativeScriptLanguage() { - for (KeyValue<String, Ref<GDNative>> &L : NSL->library_gdnatives) { - Ref<GDNative> lib = L.value; - // 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()) { - lib->terminate(); - } - } - } - - NSL->library_classes.clear(); - NSL->library_gdnatives.clear(); - NSL->library_script_users.clear(); -} - -String NativeScriptLanguage::get_name() const { - return "NativeScript"; -} - -void _add_reload_node() { -#ifdef TOOLS_ENABLED - NativeReloadNode *rn = memnew(NativeReloadNode); - EditorNode::get_singleton()->add_child(rn); -#endif -} - -void NativeScriptLanguage::init() { -#if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED) - - List<String> args = OS::get_singleton()->get_cmdline_args(); - - List<String>::Element *E = args.find("--gdnative-generate-json-api"); - - if (E && E->next()) { - if (generate_c_api(E->next()->get()) != OK) { - ERR_PRINT("Failed to generate C API\n"); - } - Main::cleanup(true); - exit(0); - } - - E = args.find("--gdnative-generate-json-builtin-api"); - - if (E && E->next()) { - if (generate_c_builtin_api(E->next()->get()) != OK) { - ERR_PRINT("Failed to generate C builtin API\n"); - } - Main::cleanup(true); - exit(0); - } -#endif - -#ifdef TOOLS_ENABLED - 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 { -} - -bool NativeScriptLanguage::is_control_flow_keyword(String p_keyword) const { - return false; -} - -void NativeScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const { -} - -void NativeScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const { -} - -Ref<Script> NativeScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const { - NativeScript *s = memnew(NativeScript); - s->set_class_name(p_class_name); - return Ref<NativeScript>(s); -} - -bool NativeScriptLanguage::validate(const String &p_script, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const { - return true; -} - -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) { -} - -// Debugging stuff here. Not used for now. -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() { -} - -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"); -} - -void NativeScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const { -} - -void NativeScriptLanguage::get_public_constants(List<Pair<String, Variant>> *p_constants) const { -} - -void NativeScriptLanguage::profiling_start() { -#ifdef DEBUG_ENABLED - MutexLock lock(mutex); - - profile_data.clear(); -#endif -} - -void NativeScriptLanguage::profiling_stop() { -#ifdef DEBUG_ENABLED - MutexLock lock(mutex); -#endif -} - -int NativeScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) { -#ifdef DEBUG_ENABLED - MutexLock lock(mutex); - - int current = 0; - - for (const KeyValue<StringName, ProfileData> &d : profile_data) { - if (current >= p_info_max) { - break; - } - - p_info_arr[current].call_count = d.value.call_count; - p_info_arr[current].self_time = d.value.self_time; - p_info_arr[current].total_time = d.value.total_time; - p_info_arr[current].signature = d.value.signature; - current++; - } - - return current; -#else - return 0; -#endif -} - -int NativeScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) { -#ifdef DEBUG_ENABLED - MutexLock lock(mutex); - - int current = 0; - - for (const KeyValue<StringName, ProfileData> &d : profile_data) { - if (current >= p_info_max) { - break; - } - - if (d.value.last_frame_call_count) { - p_info_arr[current].call_count = d.value.last_frame_call_count; - p_info_arr[current].self_time = d.value.last_frame_self_time; - p_info_arr[current].total_time = d.value.last_frame_total_time; - p_info_arr[current].signature = d.value.signature; - current++; - } - } - - return current; -#else - return 0; -#endif -} - -void NativeScriptLanguage::profiling_add_data(StringName p_signature, uint64_t p_time) { -#ifdef DEBUG_ENABLED - MutexLock lock(mutex); - - Map<StringName, ProfileData>::Element *d = profile_data.find(p_signature); - if (d) { - d->get().call_count += 1; - d->get().total_time += p_time; - d->get().frame_call_count += 1; - d->get().frame_total_time += p_time; - } else { - ProfileData data; - - data.signature = p_signature; - data.call_count = 1; - data.self_time = 0; - data.total_time = p_time; - data.frame_call_count = 1; - data.frame_self_time = 0; - data.frame_total_time = p_time; - data.last_frame_call_count = 0; - data.last_frame_self_time = 0; - data.last_frame_total_time = 0; - - profile_data.insert(p_signature, data); - } -#endif -} - -int NativeScriptLanguage::register_binding_functions(godot_nativescript_instance_binding_functions p_binding_functions) { - // find index - - int idx = -1; - - for (int i = 0; i < binding_functions.size(); i++) { - if (!binding_functions[i].first) { - // free, we'll take it - idx = i; - break; - } - } - - if (idx == -1) { - idx = binding_functions.size(); - binding_functions.resize(idx + 1); - } - - // set the functions - binding_functions.write[idx].first = true; - binding_functions.write[idx].second = p_binding_functions; - - return idx; -} - -void NativeScriptLanguage::unregister_binding_functions(int p_idx) { - ERR_FAIL_INDEX(p_idx, binding_functions.size()); - - 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) { - 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) { - 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) { - return nullptr; -#if 0 - ERR_FAIL_INDEX_V(p_idx, binding_functions.size(), nullptr); - - ERR_FAIL_COND_V_MSG(!binding_functions[p_idx].first, nullptr, "Tried to get binding data for a nativescript binding that does not exist."); - - Vector<void *> *binding_data = (Vector<void *> *)p_object->get_script_instance_binding(lang_idx); - - if (!binding_data) { - return nullptr; // should never happen. - } - - if (binding_data->size() <= p_idx) { - // okay, add new elements here. - int old_size = binding_data->size(); - - binding_data->resize(p_idx + 1); - - for (int i = old_size; i <= p_idx; i++) { - (*binding_data).write[i] = nullptr; - } - } - - 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/ - (*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]; -#endif -} - -void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) { - return nullptr; -#if 0 - Vector<void *> *binding_data = new Vector<void *>; - - binding_data->resize(binding_functions.size()); - - for (int i = 0; i < binding_functions.size(); i++) { - (*binding_data).write[i] = nullptr; - } - - binding_instances.insert(binding_data); - - return (void *)binding_data; -#endif -} - -void NativeScriptLanguage::free_instance_binding_data(void *p_data) { -#if 0 - 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]) { - 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]); - } - } - - binding_instances.erase(&binding_data); - - delete &binding_data; -#endif -} - -void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_object) { -#if 0 - void *data = p_object->get_script_instance_binding(lang_idx); - - if (!data) { - return; - } - - Vector<void *> &binding_data = *(Vector<void *> *)data; - - for (int i = 0; i < binding_data.size(); i++) { - if (!binding_data[i]) { - continue; - } - - 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); - } - } -#endif -} - -bool NativeScriptLanguage::refcount_decremented_instance_binding(Object *p_object) { -#if 0 - void *data = p_object->get_script_instance_binding(lang_idx); - - 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]) { - continue; - } - - 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); - } - } - - return can_die; -#endif - return false; -} - -void NativeScriptLanguage::set_global_type_tag(int p_idx, StringName p_class_name, const void *p_type_tag) { - if (!global_type_tags.has(p_idx)) { - global_type_tags.insert(p_idx, HashMap<StringName, const void *>()); - } - - HashMap<StringName, const void *> &tags = global_type_tags[p_idx]; - - tags.set(p_class_name, p_type_tag); -} - -const void *NativeScriptLanguage::get_global_type_tag(int p_idx, StringName p_class_name) const { - 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)) { - return nullptr; - } - - const void *tag = tags.get(p_class_name); - - return tag; -} - -#ifndef NO_THREADS -void NativeScriptLanguage::defer_init_library(Ref<GDNativeLibrary> lib, NativeScript *script) { - MutexLock lock(mutex); - libs_to_init.insert(lib); - scripts_to_register.insert(script); - has_objects_to_register.set(); -} -#endif - -void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) { - MutexLock lock(mutex); - - // See if this library was "registered" already. - const String &lib_path = lib->get_current_library_path(); - ERR_FAIL_COND_MSG(lib_path.length() == 0, lib->get_name() + " does not have a library for the current platform."); - Map<String, Ref<GDNative>>::Element *E = library_gdnatives.find(lib_path); - - if (!E) { - Ref<GDNative> gdn; - gdn.instantiate(); - gdn->set_library(lib); - - // TODO check the return value? - gdn->initialize(); - - library_gdnatives.insert(lib_path, gdn); - - library_classes.insert(lib_path, Map<StringName, NativeScriptDesc>()); - - if (!library_script_users.has(lib_path)) { - library_script_users.insert(lib_path, Set<NativeScript *>()); - } - - void *proc_ptr; - - Error err = gdn->get_symbol(lib->get_symbol_prefix() + _init_call_name, proc_ptr); - - if (err != OK) { - ERR_PRINT(String("No " + _init_call_name + " in \"" + lib_path + "\" found").utf8().get_data()); - } else { - ((void (*)(godot_string *))proc_ptr)((godot_string *)&lib_path); - } - } else { - // already initialized. Nice. - } -} - -void NativeScriptLanguage::register_script(NativeScript *script) { - MutexLock lock(mutex); - - library_script_users[script->lib_path].insert(script); -} - -void NativeScriptLanguage::unregister_script(NativeScript *script) { - MutexLock lock(mutex); - - Map<String, Set<NativeScript *>>::Element *S = library_script_users.find(script->lib_path); - if (S) { - S->get().erase(script); - if (S->get().size() == 0) { - library_script_users.erase(S); - - Map<String, Ref<GDNative>>::Element *G = library_gdnatives.find(script->lib_path); - if (G && G->get()->get_library()->is_reloadable()) { - // ONLY if the library is marked as reloadable, and no more instances of its scripts exist do we unload the library - - // First remove meta data related to the library - Map<String, Map<StringName, NativeScriptDesc>>::Element *L = library_classes.find(script->lib_path); - if (L) { - Map<StringName, NativeScriptDesc> classes = L->get(); - - for (KeyValue<StringName, NativeScriptDesc> &C : classes) { - // free property stuff first - for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = C.value.properties.front(); P; P = P.next()) { - if (P.get().getter.free_func) { - P.get().getter.free_func(P.get().getter.method_data); - } - - if (P.get().setter.free_func) { - P.get().setter.free_func(P.get().setter.method_data); - } - } - - // free method stuff - for (const KeyValue<StringName, NativeScriptDesc::Method> &M : C.value.methods) { - if (M.value.method.free_func) { - M.value.method.free_func(M.value.method.method_data); - } - } - - // free constructor/destructor - if (C.value.create_func.free_func) { - C.value.create_func.free_func(C.value.create_func.method_data); - } - - if (C.value.destroy_func.free_func) { - C.value.destroy_func.free_func(C.value.destroy_func.method_data); - } - } - - library_classes.erase(script->lib_path); - } - - // now unload the library - G->get()->terminate(); - library_gdnatives.erase(G); - } - } - } -#ifndef NO_THREADS - scripts_to_register.erase(script); -#endif -} - -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 (KeyValue<String, Ref<GDNative>> &L : library_gdnatives) { - if (L.value.is_null()) { - continue; - } - - if (L.value->is_initialized()) { - void *proc_ptr; - Error err = L.value->get_symbol(L.value->get_library()->get_symbol_prefix() + name, proc_ptr); - - if (!err) { - ((void (*)())proc_ptr)(); - } - } - } -} - -void NativeScriptLanguage::frame() { -#ifndef NO_THREADS - if (has_objects_to_register.is_set()) { - MutexLock lock(mutex); - for (Set<Ref<GDNativeLibrary>>::Element *L = libs_to_init.front(); L; L = L->next()) { - init_library(L->get()); - } - libs_to_init.clear(); - for (Set<NativeScript *>::Element *S = scripts_to_register.front(); S; S = S->next()) { - register_script(S->get()); - } - scripts_to_register.clear(); - has_objects_to_register.clear(); - } -#endif - -#ifdef DEBUG_ENABLED - { - MutexLock lock(mutex); - - for (KeyValue<StringName, ProfileData> &d : profile_data) { - d.value.last_frame_call_count = d.value.frame_call_count; - d.value.last_frame_self_time = d.value.frame_self_time; - d.value.last_frame_total_time = d.value.frame_total_time; - d.value.frame_call_count = 0; - d.value.frame_self_time = 0; - d.value.frame_total_time = 0; - } - } -#endif - - call_libraries_cb(_frame_call_name); -} - -#ifndef NO_THREADS - -void NativeScriptLanguage::thread_enter() { - call_libraries_cb(_thread_enter_call_name); -} - -void NativeScriptLanguage::thread_exit() { - call_libraries_cb(_thread_exit_call_name); -} - -#endif // NO_THREADS - -bool NativeScriptLanguage::handles_global_class_type(const String &p_type) const { - return p_type == "NativeScript"; -} - -String NativeScriptLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const { - if (!p_path.is_empty()) { - Ref<NativeScript> script = ResourceLoader::load(p_path, "NativeScript"); - if (script.is_valid()) { - if (r_base_type) { - *r_base_type = script->get_instance_base_type(); - } - if (r_icon_path) { - *r_icon_path = script->get_script_class_icon_path(); - } - return script->get_script_class_name(); - } - if (r_base_type) { - *r_base_type = String(); - } - if (r_icon_path) { - *r_icon_path = String(); - } - } - return String(); -} - -void NativeReloadNode::_bind_methods() { - ClassDB::bind_method(D_METHOD("_notification"), &NativeReloadNode::_notification); -} - -void NativeReloadNode::_notification(int p_what) { -#ifdef TOOLS_ENABLED - switch (p_what) { - case NOTIFICATION_APPLICATION_FOCUS_OUT: { - if (unloaded) { - break; - } - MutexLock lock(NSL->mutex); - NSL->_unload_stuff(true); - - for (KeyValue<String, Ref<GDNative>> &L : NSL->library_gdnatives) { - Ref<GDNative> gdn = L.value; - - if (gdn.is_null()) { - continue; - } - - // Don't unload what should not be reloaded! - if (!gdn->get_library()->is_reloadable()) { - continue; - } - - // singleton libraries might have alive pointers living inside the - // editor. Also reloading a singleton library would mean that - // the singleton entry will not be called again, as this only - // happens at engine startup. - if (gdn->get_library()->is_singleton()) { - continue; - } - - gdn->terminate(); - } - - unloaded = true; - } break; - - case NOTIFICATION_APPLICATION_FOCUS_IN: { - if (!unloaded) { - break; - } - MutexLock lock(NSL->mutex); - - Set<StringName> libs_to_remove; - for (KeyValue<String, Ref<GDNative>> &L : NSL->library_gdnatives) { - Ref<GDNative> gdn = L.value; - - if (gdn.is_null()) { - continue; - } - - if (!gdn->get_library()->is_reloadable()) { - continue; - } - - // since singleton libraries are not unloaded there is no point - // in loading them again. - if (gdn->get_library()->is_singleton()) { - continue; - } - - if (!gdn->initialize()) { - libs_to_remove.insert(L.key); - continue; - } - - NSL->library_classes.insert(L.key, Map<StringName, NativeScriptDesc>()); - - // here the library registers all the classes and stuff. - - void *proc_ptr; - Error err = gdn->get_symbol(gdn->get_library()->get_symbol_prefix() + "nativescript_init", proc_ptr); - if (err != OK) { - ERR_PRINT(String("No godot_nativescript_init in \"" + L.key + "\" found").utf8().get_data()); - } else { - ((void (*)(void *))proc_ptr)((void *)&L.key); - } - - for (KeyValue<String, Set<NativeScript *>> &U : NSL->library_script_users) { - for (Set<NativeScript *>::Element *S = U.value.front(); S; S = S->next()) { - NativeScript *script = S->get(); - - if (script->placeholders.size() == 0) { - continue; - } - - for (Set<PlaceHolderScriptInstance *>::Element *P = script->placeholders.front(); P; P = P->next()) { - script->_update_placeholder(P->get()); - } - } - } - } - - unloaded = false; - - for (Set<StringName>::Element *R = libs_to_remove.front(); R; R = R->next()) { - NSL->library_gdnatives.erase(R->get()); - } - } break; - } -#endif -} - -RES ResourceFormatLoaderNativeScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_no_cache) { - return ResourceFormatLoaderText::singleton->load(p_path, p_original_path, r_error); -} - -void ResourceFormatLoaderNativeScript::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("gdns"); -} - -bool ResourceFormatLoaderNativeScript::handles_type(const String &p_type) const { - return (p_type == "Script" || p_type == "NativeScript"); -} - -String ResourceFormatLoaderNativeScript::get_resource_type(const String &p_path) const { - String el = p_path.get_extension().to_lower(); - if (el == "gdns") { - return "NativeScript"; - } - return ""; -} - -Error ResourceFormatSaverNativeScript::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - ResourceFormatSaverText rfst; - return rfst.save(p_path, p_resource, p_flags); -} - -bool ResourceFormatSaverNativeScript::recognize(const RES &p_resource) const { - return Object::cast_to<NativeScript>(*p_resource) != nullptr; -} - -void ResourceFormatSaverNativeScript::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - if (Object::cast_to<NativeScript>(*p_resource)) { - p_extensions->push_back("gdns"); - } -} diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h deleted file mode 100644 index 2d01de5832..0000000000 --- a/modules/gdnative/nativescript/nativescript.h +++ /dev/null @@ -1,393 +0,0 @@ -/*************************************************************************/ -/* nativescript.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef NATIVE_SCRIPT_H -#define NATIVE_SCRIPT_H - -#include "core/doc_data.h" -#include "core/io/resource.h" -#include "core/io/resource_loader.h" -#include "core/io/resource_saver.h" -#include "core/object/script_language.h" -#include "core/os/mutex.h" -#include "core/os/thread_safe.h" -#include "core/templates/oa_hash_map.h" -#include "core/templates/ordered_hash_map.h" -#include "core/templates/safe_refcount.h" -#include "core/templates/self_list.h" -#include "scene/main/node.h" - -#include "modules/gdnative/gdnative.h" - -#include <nativescript/godot_nativescript.h> - -struct NativeScriptDesc { - struct Method { - godot_nativescript_instance_method method; - MethodInfo info; - int rpc_mode = 0; - uint16_t rpc_method_id = 0; - String documentation; - }; - - struct Property { - godot_nativescript_property_set_func setter; - godot_nativescript_property_get_func getter; - PropertyInfo info; - Variant default_value; - String documentation; - }; - - struct Signal { - MethodInfo signal; - String documentation; - }; - - Map<StringName, Method> methods; - Vector<Multiplayer::RPCConfig> rpc_methods; - OrderedHashMap<StringName, Property> properties; - Map<StringName, Signal> signals_; // QtCreator doesn't like the name signals - StringName base; - StringName base_native_type; - NativeScriptDesc *base_data = nullptr; - godot_nativescript_instance_create_func create_func; - godot_nativescript_instance_destroy_func destroy_func; - - String documentation; - - const void *type_tag = nullptr; - - bool is_tool = false; - - inline NativeScriptDesc() { - memset(&create_func, 0, sizeof(godot_nativescript_instance_create_func)); - memset(&destroy_func, 0, sizeof(godot_nativescript_instance_destroy_func)); - } -}; - -class NativeScript : public Script { - GDCLASS(NativeScript, Script); - -#ifdef TOOLS_ENABLED - Set<PlaceHolderScriptInstance *> placeholders; - void _update_placeholder(PlaceHolderScriptInstance *p_placeholder); - virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override; -#endif - - friend class NativeScriptInstance; - friend class NativeScriptLanguage; - friend class NativeReloadNode; - friend class GDNativeLibrary; - - Ref<GDNativeLibrary> library; - - String lib_path; - - String class_name; - - String script_class_name; - String script_class_icon_path; - - Mutex owners_lock; - Set<Object *> instance_owners; - -protected: - static void _bind_methods(); - -public: - inline NativeScriptDesc *get_script_desc() const; - - bool inherits_script(const Ref<Script> &p_script) const override; - - void set_class_name(String p_class_name); - String get_class_name() const; - - void set_library(Ref<GDNativeLibrary> p_library); - Ref<GDNativeLibrary> get_library() const; - - void set_script_class_name(String p_type); - String get_script_class_name() const; - void set_script_class_icon_path(String p_icon_path); - String get_script_class_icon_path() const; - - virtual bool can_instantiate() const override; - - virtual Ref<Script> get_base_script() const override; //for script inheritance - - virtual StringName get_instance_base_type() const override; // this may not work in all scripts, will return empty if so - virtual ScriptInstance *instance_create(Object *p_this) override; - virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) override; - virtual bool instance_has(const Object *p_this) const override; - - virtual bool has_source_code() const override; - virtual String get_source_code() const override; - virtual void set_source_code(const String &p_code) override; - virtual Error reload(bool p_keep_state = false) override; - -#ifdef TOOLS_ENABLED - virtual const Vector<DocData::ClassDoc> &get_documentation() const override { - static Vector<DocData::ClassDoc> docs; - return docs; - } -#endif // TOOLS_ENABLED - - virtual bool has_method(const StringName &p_method) const override; - virtual MethodInfo get_method_info(const StringName &p_method) const override; - - virtual bool is_tool() const override; - virtual bool is_valid() const override; - - virtual ScriptLanguage *get_language() const override; - - virtual bool has_script_signal(const StringName &p_signal) const override; - virtual void get_script_signal_list(List<MethodInfo> *r_signals) const override; - - virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const override; - - virtual void update_exports() override; //editor tool - virtual void get_script_method_list(List<MethodInfo> *p_list) const override; - virtual void get_script_property_list(List<PropertyInfo> *p_list) const override; - - virtual const Vector<Multiplayer::RPCConfig> get_rpc_methods() const override; - - String get_class_documentation() const; - String get_method_documentation(const StringName &p_method) const; - String get_signal_documentation(const StringName &p_signal_name) const; - String get_property_documentation(const StringName &p_path) const; - - Variant _new(const Variant **p_args, int p_argcount, Callable::CallError &r_error); - - NativeScript(); - ~NativeScript(); -}; - -class NativeScriptInstance : public ScriptInstance { - friend class NativeScript; - - Object *owner; - Ref<NativeScript> script; -#ifdef DEBUG_ENABLED - StringName current_method_call; -#endif - - void _ml_call_reversed(NativeScriptDesc *script_data, const StringName &p_method, const Variant **p_args, int p_argcount); - -public: - void *userdata; - - virtual bool set(const StringName &p_name, const Variant &p_value); - virtual bool get(const StringName &p_name, Variant &r_ret) const; - virtual void get_property_list(List<PropertyInfo> *p_properties) const; - virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid) const; - virtual void get_method_list(List<MethodInfo> *p_list) const; - virtual bool has_method(const StringName &p_method) const; - virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error); - virtual void notification(int p_what); - String to_string(bool *r_valid); - virtual Ref<Script> get_script() const; - - virtual const Vector<Multiplayer::RPCConfig> get_rpc_methods() const; - - virtual ScriptLanguage *get_language(); - - virtual void refcount_incremented(); - virtual bool refcount_decremented(); - - ~NativeScriptInstance(); -}; - -class NativeReloadNode; - -class NativeScriptLanguage : public ScriptLanguage { - friend class NativeScript; - friend class NativeScriptInstance; - friend class NativeReloadNode; - -private: - static NativeScriptLanguage *singleton; - int lang_idx = 0; - - void _unload_stuff(bool p_reload = false); - - Mutex mutex; -#ifndef NO_THREADS - Set<Ref<GDNativeLibrary>> libs_to_init; - Set<NativeScript *> scripts_to_register; - SafeFlag has_objects_to_register; // so that we don't lock mutex every frame - it's rarely needed - void defer_init_library(Ref<GDNativeLibrary> lib, NativeScript *script); -#endif - - void init_library(const Ref<GDNativeLibrary> &lib); - void register_script(NativeScript *script); - void unregister_script(NativeScript *script); - - void call_libraries_cb(const StringName &name); - - Vector<Pair<bool, godot_nativescript_instance_binding_functions>> binding_functions; - Set<Vector<void *> *> binding_instances; - - Map<int, HashMap<StringName, const void *>> global_type_tags; - - struct ProfileData { - StringName signature; - uint64_t call_count = 0; - uint64_t self_time = 0; - uint64_t total_time = 0; - uint64_t frame_call_count = 0; - uint64_t frame_self_time = 0; - uint64_t frame_total_time = 0; - uint64_t last_frame_call_count = 0; - uint64_t last_frame_self_time = 0; - uint64_t last_frame_total_time = 0; - }; - - Map<StringName, ProfileData> profile_data; - -public: - // These two maps must only be touched on the main thread - Map<String, Map<StringName, NativeScriptDesc>> library_classes; - Map<String, Ref<GDNative>> library_gdnatives; - - Map<String, Set<NativeScript *>> library_script_users; - - StringName _init_call_type; - StringName _init_call_name; - StringName _terminate_call_name; - StringName _noarg_call_type; - StringName _frame_call_name; -#ifndef NO_THREADS - StringName _thread_enter_call_name; - StringName _thread_exit_call_name; -#endif - - NativeScriptLanguage(); - ~NativeScriptLanguage(); - - inline static NativeScriptLanguage *get_singleton() { - return singleton; - } - - _FORCE_INLINE_ void set_language_index(int p_idx) { lang_idx = p_idx; } - -#ifndef NO_THREADS - virtual void thread_enter(); - virtual void thread_exit(); -#endif - - virtual void frame(); - - virtual String get_name() const; - virtual void init(); - virtual String get_type() const; - virtual String get_extension() const; - virtual Error execute_file(const String &p_path); - virtual void finish(); - virtual void get_reserved_words(List<String> *p_words) const; - virtual bool is_control_flow_keyword(String p_keyword) const; - 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, const String &p_path, List<String> *r_functions, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const; - virtual Script *create_script() const; - virtual bool has_named_classes() const; - virtual bool supports_builtin_mode() const; - virtual int find_function(const String &p_function, const String &p_code) const; - virtual String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const; - virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const; - virtual void add_global_constant(const StringName &p_variable, const Variant &p_value); - virtual String debug_get_error() const; - virtual int debug_get_stack_level_count() const; - virtual int debug_get_stack_level_line(int p_level) const; - virtual String debug_get_stack_level_function(int p_level) const; - virtual String debug_get_stack_level_source(int p_level) const; - virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth); - virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth); - virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth); - virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth); - virtual void reload_all_scripts(); - virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload); - virtual void get_recognized_extensions(List<String> *p_extensions) const; - virtual void get_public_functions(List<MethodInfo> *p_functions) const; - virtual void get_public_constants(List<Pair<String, Variant>> *p_constants) const; - virtual void profiling_start(); - virtual void profiling_stop(); - 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_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); - - virtual void *alloc_instance_binding_data(Object *p_object); - virtual void free_instance_binding_data(void *p_data); - virtual void refcount_incremented_instance_binding(Object *p_object); - virtual bool refcount_decremented_instance_binding(Object *p_object); - - void set_global_type_tag(int p_idx, StringName p_class_name, const void *p_type_tag); - const void *get_global_type_tag(int p_idx, StringName p_class_name) const; - - virtual bool handles_global_class_type(const String &p_type) const; - virtual String get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const; - - void profiling_add_data(StringName p_signature, uint64_t p_time); -}; - -inline NativeScriptDesc *NativeScript::get_script_desc() const { - Map<StringName, NativeScriptDesc>::Element *E = NativeScriptLanguage::singleton->library_classes[lib_path].find(class_name); - return E ? &E->get() : nullptr; -} - -class NativeReloadNode : public Node { - GDCLASS(NativeReloadNode, Node); - bool unloaded = false; - -public: - static void _bind_methods(); - void _notification(int p_what); - - NativeReloadNode() {} -}; - -class ResourceFormatLoaderNativeScript : public ResourceFormatLoader { -public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); - virtual void get_recognized_extensions(List<String> *p_extensions) const; - virtual bool handles_type(const String &p_type) const; - virtual String get_resource_type(const String &p_path) const; -}; - -class ResourceFormatSaverNativeScript : public ResourceFormatSaver { - virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0); - virtual bool recognize(const RES &p_resource) const; - virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const; -}; - -#endif // GDNATIVE_H diff --git a/modules/gdnative/nativescript/register_types.cpp b/modules/gdnative/nativescript/register_types.cpp deleted file mode 100644 index ee63dca9a3..0000000000 --- a/modules/gdnative/nativescript/register_types.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/*************************************************************************/ -/* register_types.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "register_types.h" - -#include "core/io/resource_loader.h" -#include "core/io/resource_saver.h" - -#include "nativescript.h" - -#include "core/os/os.h" - -NativeScriptLanguage *native_script_language; - -Ref<ResourceFormatLoaderNativeScript> resource_loader_gdns; -Ref<ResourceFormatSaverNativeScript> resource_saver_gdns; - -void register_nativescript_types() { - native_script_language = memnew(NativeScriptLanguage); - - GDREGISTER_CLASS(NativeScript); - - native_script_language->set_language_index(ScriptServer::get_language_count()); - ScriptServer::register_language(native_script_language); - - resource_saver_gdns.instantiate(); - ResourceSaver::add_resource_format_saver(resource_saver_gdns); - - resource_loader_gdns.instantiate(); - ResourceLoader::add_resource_format_loader(resource_loader_gdns); -} - -void unregister_nativescript_types() { - ResourceLoader::remove_resource_format_loader(resource_loader_gdns); - resource_loader_gdns.unref(); - - ResourceSaver::remove_resource_format_saver(resource_saver_gdns); - resource_saver_gdns.unref(); - - if (native_script_language) { - ScriptServer::unregister_language(native_script_language); - memdelete(native_script_language); - } -} diff --git a/modules/gdnative/nativescript/register_types.h b/modules/gdnative/nativescript/register_types.h deleted file mode 100644 index ce6085f62a..0000000000 --- a/modules/gdnative/nativescript/register_types.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************/ -/* register_types.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef NATIVESCRIPT_REGISTER_TYPES_H -#define NATIVESCRIPT_REGISTER_TYPES_H - -void register_nativescript_types(); -void unregister_nativescript_types(); - -#endif // NATIVESCRIPT_REGISTER_TYPES_H |