From 534d62d2f4ea1ff4be11b50bc79684b5780e4615 Mon Sep 17 00:00:00 2001 From: Karroffel Date: Fri, 14 Jul 2017 01:44:14 +0200 Subject: [GDNative] new GDNative API This adds GDNative as a separate class type. It can be used to interface with native libraries by using "native calls", which can be registered by modules (and in future other GDNative libraries?). It also reworks the currently called "GDNativeScript" into a "NativeScript" that just makes use of the new GDNative instead of it being the component that implements that functionality. --- modules/nativescript/nativescript.h | 281 ++++++++++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) create mode 100644 modules/nativescript/nativescript.h (limited to 'modules/nativescript/nativescript.h') diff --git a/modules/nativescript/nativescript.h b/modules/nativescript/nativescript.h new file mode 100644 index 0000000000..0578ffb680 --- /dev/null +++ b/modules/nativescript/nativescript.h @@ -0,0 +1,281 @@ +/*************************************************************************/ +/* nativescript.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 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 "io/resource_loader.h" +#include "io/resource_saver.h" +#include "os/thread_safe.h" +#include "resource.h" +#include "scene/main/node.h" +#include "script_language.h" +#include "self_list.h" + +#include "godot_nativescript.h" +#include "modules/gdnative/gdnative.h" + +struct NativeScriptDesc { + + struct Method { + godot_instance_method method; + MethodInfo info; + int rpc_mode; + }; + struct Property { + godot_property_set_func setter; + godot_property_get_func getter; + PropertyInfo info; + Variant default_value; + int rset_mode; + }; + + struct Signal { + MethodInfo signal; + }; + + Map methods; + Map properties; + Map signals_; // QtCreator doesn't like the name signals + StringName base; + StringName base_native_type; + NativeScriptDesc *base_data; + godot_instance_create_func create_func; + godot_instance_destroy_func destroy_func; + + bool is_tool; + + inline NativeScriptDesc() + : methods(), + properties(), + signals_(), + base(), + base_native_type() { + zeromem(&create_func, sizeof(godot_instance_create_func)); + zeromem(&destroy_func, sizeof(godot_instance_destroy_func)); + } +}; + +class NativeScript : public Script { + GDCLASS(NativeScript, Script) + +#ifdef TOOLS_ENABLED + Set placeholders; + void _update_placeholder(PlaceHolderScriptInstance *p_placeholder); + virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder); +#endif + + friend class NativeScriptInstance; + friend class NativeScriptLanguage; + friend class NativeReloadNode; + friend class GDNativeLibrary; + + Ref library; + + String lib_path; + + String class_name; + + Set instance_owners; + +protected: + static void _bind_methods(); + +public: + inline NativeScriptDesc *get_script_desc() const; + + void set_class_name(String p_class_name); + String get_class_name() const; + + void set_library(Ref library); + Ref get_library() const; + + virtual bool can_instance() const; + + virtual Ref