From fd553087867187220d4f6b8217854dd8e9be2667 Mon Sep 17 00:00:00 2001 From: Karroffel Date: Mon, 3 Apr 2017 16:11:38 +0200 Subject: added dlscript module This module was written by bojidar-bg and me, with the help of ClikCode and touilleMan. This adds a module to Godot that enables the use of dynamic libraries as a source for scripts. That also allows third party libraries to be linked to Godot more easily and without creating modules. For a readme see https://github.com/GodotNativeTools/godot_headers/blob/master/README.md --- modules/dlscript/dl_script.h | 402 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 402 insertions(+) create mode 100644 modules/dlscript/dl_script.h (limited to 'modules/dlscript/dl_script.h') diff --git a/modules/dlscript/dl_script.h b/modules/dlscript/dl_script.h new file mode 100644 index 000000000..18af85382 --- /dev/null +++ b/modules/dlscript/dl_script.h @@ -0,0 +1,402 @@ +/*************************************************************************/ +/* dl_script.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 DL_SCRIPT_H +#define DL_SCRIPT_H + +#include "io/resource_loader.h" +#include "io/resource_saver.h" +#include "os/thread_safe.h" +#include "resource.h" +#include "script_language.h" +#include "self_list.h" + +#include "godot.h" + +#ifdef TOOLS_ENABLED +// #define DLSCRIPT_EDITOR_FEATURES +#endif + +struct DLScriptData { + /* typedef void* (InstanceFunc)(godot_object* instance); + typedef void (DestroyFunc)(godot_object* instance,void* userdata); + typedef godot_variant (MethodFunc)(godot_object *instance, void *userdata, void *method_data, int arg_count,godot_variant **args); + typedef void (MethodDataFreeFunc)(void *method_data); + typedef void (SetterFunc)(godot_object* instance,void* userdata,godot_variant value); + typedef godot_variant (GetterFunc)(godot_object* instance,void* userdata);*/ + + struct Method { + godot_instance_method method; + MethodInfo info; + int rpc_mode; + + Method() { + } + Method(godot_instance_method p_method, MethodInfo p_info, int p_rpc_mode) { + method = p_method; + info = p_info; + rpc_mode = p_rpc_mode; + } + }; + struct Property { + godot_property_set_func setter; + godot_property_get_func getter; + PropertyInfo info; + Variant default_value; + int rset_mode; + + Property() { + } + Property(godot_property_set_func p_setter, godot_property_get_func p_getter) { + setter = p_setter; + getter = p_getter; + } + Property(godot_property_set_func p_setter, godot_property_get_func p_getter, PropertyInfo p_info, Variant p_default_value, int p_rset_mode) { + setter = p_setter; + getter = p_getter; + info = p_info; + default_value = p_default_value; + rset_mode = p_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; + DLScriptData *base_data; + godot_instance_create_func create_func; + godot_instance_destroy_func destroy_func; + + bool is_tool; + + DLScriptData() { + base = StringName(); + base_data = NULL; + is_tool = false; + } + DLScriptData(StringName p_base, godot_instance_create_func p_instance, godot_instance_destroy_func p_free) { + base = p_base; + base_data = NULL; + create_func = p_instance; + destroy_func = p_free; + is_tool = false; + } +}; + +class DLLibrary; + +class DLScript : public Script { + + GDCLASS(DLScript, Script); + + Ref library; + StringName script_name; + StringName base_native_type; + Set instances; + DLScriptData *script_data; + +#ifdef TOOLS_ENABLED + Set placeholders; +// void _update_placeholder(PlaceHolderScriptInstance *p_placeholder); +// virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder); +#endif + + friend class DLInstance; + friend class DLScriptLanguage; + +protected: + static void _bind_methods(); + +public: + virtual bool can_instance() const; + + virtual Ref