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/cscript/SCsub | 7 - modules/cscript/config.py | 8 - modules/cscript/godot_c.cpp | 29 - modules/cscript/godot_c.h | 567 -------------- modules/cscript/register_types.cpp | 34 - modules/cscript/register_types.h | 30 - modules/dlscript/SCsub | 14 + modules/dlscript/api_generator.cpp | 382 ++++++++++ modules/dlscript/api_generator.h | 9 + modules/dlscript/config.py | 8 + modules/dlscript/dl_script.cpp | 1048 ++++++++++++++++++++++++++ modules/dlscript/dl_script.h | 402 ++++++++++ modules/dlscript/godot.cpp | 193 +++++ modules/dlscript/godot.h | 389 ++++++++++ modules/dlscript/godot/godot_array.cpp | 271 +++++++ modules/dlscript/godot/godot_array.h | 88 +++ modules/dlscript/godot/godot_basis.cpp | 58 ++ modules/dlscript/godot/godot_basis.h | 34 + modules/dlscript/godot/godot_color.cpp | 34 + modules/dlscript/godot/godot_color.h | 29 + modules/dlscript/godot/godot_dictionary.cpp | 109 +++ modules/dlscript/godot/godot_dictionary.h | 51 ++ modules/dlscript/godot/godot_image.cpp | 85 +++ modules/dlscript/godot/godot_image.h | 95 +++ modules/dlscript/godot/godot_input_event.cpp | 280 +++++++ modules/dlscript/godot/godot_input_event.h | 206 +++++ modules/dlscript/godot/godot_node_path.cpp | 87 +++ modules/dlscript/godot/godot_node_path.h | 38 + modules/dlscript/godot/godot_plane.cpp | 48 ++ modules/dlscript/godot/godot_plane.h | 37 + modules/dlscript/godot/godot_pool_arrays.cpp | 558 ++++++++++++++ modules/dlscript/godot/godot_pool_arrays.h | 256 +++++++ modules/dlscript/godot/godot_quat.cpp | 79 ++ modules/dlscript/godot/godot_quat.h | 33 + modules/dlscript/godot/godot_rect2.cpp | 48 ++ modules/dlscript/godot/godot_rect2.h | 31 + modules/dlscript/godot/godot_rect3.cpp | 48 ++ modules/dlscript/godot/godot_rect3.h | 31 + modules/dlscript/godot/godot_rid.cpp | 36 + modules/dlscript/godot/godot_rid.h | 28 + modules/dlscript/godot/godot_string.cpp | 83 ++ modules/dlscript/godot/godot_string.h | 42 ++ modules/dlscript/godot/godot_transform.cpp | 44 ++ modules/dlscript/godot/godot_transform.h | 29 + modules/dlscript/godot/godot_transform2d.cpp | 59 ++ modules/dlscript/godot/godot_transform2d.h | 48 ++ modules/dlscript/godot/godot_variant.cpp | 466 ++++++++++++ modules/dlscript/godot/godot_variant.h | 148 ++++ modules/dlscript/godot/godot_vector2.cpp | 124 +++ modules/dlscript/godot/godot_vector2.h | 78 ++ modules/dlscript/godot/godot_vector3.cpp | 150 ++++ modules/dlscript/godot/godot_vector3.h | 82 ++ modules/dlscript/register_types.cpp | 69 ++ modules/dlscript/register_types.h | 30 + 54 files changed, 6595 insertions(+), 675 deletions(-) delete mode 100644 modules/cscript/SCsub delete mode 100644 modules/cscript/config.py delete mode 100644 modules/cscript/godot_c.cpp delete mode 100644 modules/cscript/godot_c.h delete mode 100644 modules/cscript/register_types.cpp delete mode 100644 modules/cscript/register_types.h create mode 100644 modules/dlscript/SCsub create mode 100644 modules/dlscript/api_generator.cpp create mode 100644 modules/dlscript/api_generator.h create mode 100644 modules/dlscript/config.py create mode 100644 modules/dlscript/dl_script.cpp create mode 100644 modules/dlscript/dl_script.h create mode 100644 modules/dlscript/godot.cpp create mode 100644 modules/dlscript/godot.h create mode 100644 modules/dlscript/godot/godot_array.cpp create mode 100644 modules/dlscript/godot/godot_array.h create mode 100644 modules/dlscript/godot/godot_basis.cpp create mode 100644 modules/dlscript/godot/godot_basis.h create mode 100644 modules/dlscript/godot/godot_color.cpp create mode 100644 modules/dlscript/godot/godot_color.h create mode 100644 modules/dlscript/godot/godot_dictionary.cpp create mode 100644 modules/dlscript/godot/godot_dictionary.h create mode 100644 modules/dlscript/godot/godot_image.cpp create mode 100644 modules/dlscript/godot/godot_image.h create mode 100644 modules/dlscript/godot/godot_input_event.cpp create mode 100644 modules/dlscript/godot/godot_input_event.h create mode 100644 modules/dlscript/godot/godot_node_path.cpp create mode 100644 modules/dlscript/godot/godot_node_path.h create mode 100644 modules/dlscript/godot/godot_plane.cpp create mode 100644 modules/dlscript/godot/godot_plane.h create mode 100644 modules/dlscript/godot/godot_pool_arrays.cpp create mode 100644 modules/dlscript/godot/godot_pool_arrays.h create mode 100644 modules/dlscript/godot/godot_quat.cpp create mode 100644 modules/dlscript/godot/godot_quat.h create mode 100644 modules/dlscript/godot/godot_rect2.cpp create mode 100644 modules/dlscript/godot/godot_rect2.h create mode 100644 modules/dlscript/godot/godot_rect3.cpp create mode 100644 modules/dlscript/godot/godot_rect3.h create mode 100644 modules/dlscript/godot/godot_rid.cpp create mode 100644 modules/dlscript/godot/godot_rid.h create mode 100644 modules/dlscript/godot/godot_string.cpp create mode 100644 modules/dlscript/godot/godot_string.h create mode 100644 modules/dlscript/godot/godot_transform.cpp create mode 100644 modules/dlscript/godot/godot_transform.h create mode 100644 modules/dlscript/godot/godot_transform2d.cpp create mode 100644 modules/dlscript/godot/godot_transform2d.h create mode 100644 modules/dlscript/godot/godot_variant.cpp create mode 100644 modules/dlscript/godot/godot_variant.h create mode 100644 modules/dlscript/godot/godot_vector2.cpp create mode 100644 modules/dlscript/godot/godot_vector2.h create mode 100644 modules/dlscript/godot/godot_vector3.cpp create mode 100644 modules/dlscript/godot/godot_vector3.h create mode 100644 modules/dlscript/register_types.cpp create mode 100644 modules/dlscript/register_types.h (limited to 'modules') diff --git a/modules/cscript/SCsub b/modules/cscript/SCsub deleted file mode 100644 index 0882406761..0000000000 --- a/modules/cscript/SCsub +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python - -Import('env') - -env.add_source_files(env.modules_sources, "*.cpp") - -Export('env') diff --git a/modules/cscript/config.py b/modules/cscript/config.py deleted file mode 100644 index 5698a37295..0000000000 --- a/modules/cscript/config.py +++ /dev/null @@ -1,8 +0,0 @@ - - -def can_build(platform): - return True - - -def configure(env): - pass diff --git a/modules/cscript/godot_c.cpp b/modules/cscript/godot_c.cpp deleted file mode 100644 index f754f2bb21..0000000000 --- a/modules/cscript/godot_c.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/*************************************************************************/ -/* godot_c.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 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. */ -/*************************************************************************/ -#include "godot_c.h" diff --git a/modules/cscript/godot_c.h b/modules/cscript/godot_c.h deleted file mode 100644 index 58acbf8bf9..0000000000 --- a/modules/cscript/godot_c.h +++ /dev/null @@ -1,567 +0,0 @@ -/*************************************************************************/ -/* godot_c.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 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 GODOT_C_H -#define GODOT_C_H - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(GDAPI_BUILT_IN) || !defined(WINDOWS_ENABLED) -#define GDAPI -#elif defined(GDAPI_EXPORTS) -#define GDAPI __declspec(dllexport) -#else -#define GDAPI __declspec(dllimport) -#endif - -#define GODOT_API_VERSION 1 - -typedef int godot_bool; - -#define GODOT_FALSE 0 -#define GODOT_TRUE 1 - -////// Image - -#define GODOT_IMAGE_FORMAT_GRAYSCALE 0 -#define GODOT_IMAGE_FORMAT_INTENSITY 1 -#define GODOT_IMAGE_FORMAT_GRAYSCALE_ALPHA 2 -#define GODOT_IMAGE_FORMAT_RGB 3 -#define GODOT_IMAGE_FORMAT_RGBA 4 -#define GODOT_IMAGE_FORMAT_INDEXED 5 -#define GODOT_IMAGE_FORMAT_INDEXED_ALPHA 6 -#define GODOT_IMAGE_FORMAT_YUV_422 7 -#define GODOT_IMAGE_FORMAT_YUV_444 8 -#define GODOT_IMAGE_FORMAT_BC1 9 -#define GODOT_IMAGE_FORMAT_BC2 10 -#define GODOT_IMAGE_FORMAT_BC3 11 -#define GODOT_IMAGE_FORMAT_BC4 12 -#define GODOT_IMAGE_FORMAT_BC5 13 -#define GODOT_IMAGE_FORMAT_PVRTC2 14 -#define GODOT_IMAGE_FORMAT_PVRTC2_ALPHA 15 -#define GODOT_IMAGE_FORMAT_PVRTC4 16 -#define GODOT_IMAGE_FORMAT_PVRTC4_ALPHA 17 -#define GODOT_IMAGE_FORMAT_ETC 18 -#define GODOT_IMAGE_FORMAT_ATC 19 -#define GODOT_IMAGE_FORMAT_ATC_ALPHA_EXPLICIT 20 -#define GODOT_IMAGE_FORMAT_ATC_ALPHA_INTERPOLATED 21 - -typedef void *godot_image; - -godot_image GDAPI godot_image_create_empty(); -godot_image GDAPI godot_image_create(int p_width, int p_height, int p_format, int p_use_mipmaps); -godot_image GDAPI godot_image_create_with_data(int p_width, int p_height, int p_format, int p_use_mipmaps, unsigned char *p_buffer); -int GDAPI godot_image_get_width(godot_image p_image); -int GDAPI godot_image_get_height(godot_image p_image); -int GDAPI godot_image_get_format(godot_image p_image); -int GDAPI godot_image_get_mipmap_count(godot_image p_image); -godot_image GDAPI godot_image_copy(godot_image p_image); -void GDAPI godot_image_free(godot_image p_image); - -////// RID - -typedef void *godot_rid; - -godot_rid GDAPI godot_rid_create(); -godot_rid GDAPI godot_rid_copy(godot_rid p_rid); -void GDAPI godot_rid_free(godot_rid p_rid); - -////// Variant (forward declared) - -typedef void *godot_variant; - -////// Dictionary - -typedef void *godot_dictionary; - -godot_dictionary GDAPI godot_dictionary_create(); -void GDAPI godot_dictionary_has(godot_dictionary p_dictionary, godot_variant p_key); -godot_variant GDAPI godot_dictionary_get(godot_dictionary p_dictionary, godot_variant p_key); -void GDAPI godot_dictionary_insert(godot_dictionary p_dictionary, godot_variant p_key, godot_variant p_value); -void GDAPI godot_dictionary_remove(godot_dictionary p_dictionary, godot_variant p_key); -void GDAPI godot_dictionary_clear(godot_dictionary p_dictionary); -int GDAPI godot_dictionary_get_size(godot_dictionary p_dictionary); -void GDAPI godot_dictionary_get_keys(godot_dictionary p_dictionary, godot_variant *p_keys); -godot_dictionary GDAPI godot_dictionary_copy(godot_dictionary p_dictionary); -void GDAPI godot_dictionary_free(godot_dictionary p_dictionary); - -////// Array - -typedef void *godot_array; - -godot_array GDAPI godot_array_create(); -godot_variant GDAPI godot_array_get(godot_array p_array, int p_index); -void GDAPI godot_array_set(godot_array p_array, int p_index, godot_variant p_value); -void GDAPI godot_array_resize(godot_array p_array, int p_size); -void GDAPI godot_array_insert(godot_array p_array, int p_position, godot_variant p_value); -void GDAPI godot_array_remove(godot_array p_array, int p_position); -void GDAPI godot_array_clear(godot_array p_array); -int GDAPI godot_array_get_size(godot_array p_array); -int GDAPI godot_array_find(godot_array p_array, godot_variant p_value, int p_from_pos = -1); -godot_array GDAPI godot_array_copy(godot_array p_array); -void GDAPI godot_array_free(godot_array p_array); - -////// InputEvent - -#define INPUT_EVENT_BUTTON_LEFT 1 -#define INPUT_EVENT_BUTTON_RIGHT 2 -#define INPUT_EVENT_BUTTON_MIDDLE 3 -#define INPUT_EVENT_BUTTON_WHEEL_UP 4 -#define INPUT_EVENT_BUTTON_WHEEL_DOWN 5 -#define INPUT_EVENT_BUTTON_WHEEL_LEFT 6 -#define INPUT_EVENT_BUTTON_WHEEL_RIGHT 7 -#define INPUT_EVENT_BUTTON_MASK_LEFT (1 << (INPUT_EVENT_BUTTON_LEFT - 1)) -#define INPUT_EVENT_BUTTON_MASK_RIGHT (1 << (INPUT_EVENT_BUTTON_RIGHT - 1)) -#define INPUT_EVENT_BUTTON_MASK_MIDDLE (1 << (INPUT_EVENT_BUTTON_MIDDLE - 1)) - -#define INPUT_EVENT_TYPE_NONE 0 -#define INPUT_EVENT_TYPE_KEY 1 -#define INPUT_EVENT_TYPE_MOUSE_MOTION 2 -#define INPUT_EVENT_TYPE_MOUSE_BUTTON 3 -#define INPUT_EVENT_TYPE_JOYPAD_MOTION 4 -#define INPUT_EVENT_TYPE_JOYPAD_BUTTON 5 -#define INPUT_EVENT_TYPE_SCREEN_TOUCH 6 -#define INPUT_EVENT_TYPE_SCREEN_DRAG 7 -#define INPUT_EVENT_TYPE_ACTION 8 - -typedef void *godot_input_event; - -godot_input_event GDAPI godot_input_event_create(); -godot_input_event GDAPI godot_input_event_copy(godot_input_event p_input_event); -void GDAPI godot_input_event_free(godot_input_event p_input_event); - -int GDAPI godot_input_event_get_type(godot_input_event p_event); -int GDAPI godot_input_event_get_device(godot_input_event p_event); - -godot_bool GDAPI godot_input_event_mod_has_alt(godot_input_event p_event); -godot_bool GDAPI godot_input_event_mod_has_ctrl(godot_input_event p_event); -godot_bool GDAPI godot_input_event_mod_has_command(godot_input_event p_event); -godot_bool GDAPI godot_input_event_mod_has_shift(godot_input_event p_event); -godot_bool GDAPI godot_input_event_mod_has_meta(godot_input_event p_event); - -int GDAPI godot_input_event_key_get_scancode(godot_input_event p_event); -int GDAPI godot_input_event_key_get_unicode(godot_input_event p_event); -godot_bool GDAPI godot_input_event_key_is_pressed(godot_input_event p_event); -godot_bool GDAPI godot_input_event_key_is_echo(godot_input_event p_event); - -int GDAPI godot_input_event_mouse_get_x(godot_input_event p_event); -int GDAPI godot_input_event_mouse_get_y(godot_input_event p_event); -int GDAPI godot_input_event_mouse_get_global_x(godot_input_event p_event); -int GDAPI godot_input_event_mouse_get_global_y(godot_input_event p_event); -int GDAPI godot_input_event_mouse_get_button_mask(godot_input_event p_event); - -int GDAPI godot_input_event_mouse_button_get_button_index(godot_input_event p_event); -godot_bool GDAPI godot_input_event_mouse_button_is_pressed(godot_input_event p_event); -godot_bool GDAPI godot_input_event_mouse_button_is_doubleclick(godot_input_event p_event); - -int GDAPI godot_input_event_mouse_motion_get_relative_x(godot_input_event p_event); -int GDAPI godot_input_event_mouse_motion_get_relative_y(godot_input_event p_event); - -int GDAPI godot_input_event_mouse_motion_get_speed_x(godot_input_event p_event); -int GDAPI godot_input_event_mouse_motion_get_speed_y(godot_input_event p_event); - -int GDAPI godot_input_event_joypad_motion_get_axis(godot_input_event p_event); -float GDAPI godot_input_event_joypad_motion_get_axis_value(godot_input_event p_event); - -int GDAPI godot_input_event_joypad_button_get_button_index(godot_input_event p_event); -godot_bool GDAPI godot_input_event_joypad_button_is_pressed(godot_input_event p_event); -float GDAPI godot_input_event_joypad_button_get_pressure(godot_input_event p_event); - -int GDAPI godot_input_event_screen_touch_get_index(godot_input_event p_event); -int GDAPI godot_input_event_screen_touch_get_x(godot_input_event p_event); -int GDAPI godot_input_event_screen_touch_get_y(godot_input_event p_event); -int GDAPI godot_input_event_screen_touch_is_pressed(godot_input_event p_event); - -int GDAPI godot_input_event_screen_drag_get_index(godot_input_event p_event); -int GDAPI godot_input_event_screen_drag_get_x(godot_input_event p_event); -int GDAPI godot_input_event_screen_drag_get_y(godot_input_event p_event); -int GDAPI godot_input_event_screen_drag_get_relative_x(godot_input_event p_event); -int GDAPI godot_input_event_screen_drag_get_relative_y(godot_input_event p_event); -int GDAPI godot_input_event_screen_drag_get_speed_x(godot_input_event p_event); -int GDAPI godot_input_event_screen_drag_get_speed_y(godot_input_event p_event); - -int GDAPI godot_input_event_is_action(godot_input_event p_event, char *p_action); -int GDAPI godot_input_event_is_action_pressed(godot_input_event p_event, char *p_action); - -////// ByteArray - -typedef void *godot_byte_array; - -godot_byte_array GDAPI godot_byte_array_create(); -godot_byte_array GDAPI godot_byte_array_copy(godot_byte_array p_byte_array); -void GDAPI godot_byte_array_free(godot_byte_array p_byte_array); - -int GDAPI godot_byte_array_get_size(godot_byte_array p_byte_array); -unsigned char GDAPI godot_byte_array_get(godot_byte_array p_byte_array, int p_index); -void GDAPI godot_byte_array_set(godot_byte_array p_byte_array, int p_index, unsigned char p_value); -void GDAPI godot_byte_array_remove(godot_byte_array p_byte_array, int p_index); -void GDAPI godot_byte_array_clear(godot_byte_array p_byte_array); - -typedef void *godot_byte_array_lock; - -godot_byte_array_lock GDAPI godot_byte_array_get_lock(godot_byte_array p_byte_array); -unsigned char GDAPI *godot_byte_array_lock_get_pointer(godot_byte_array_lock p_byte_array_lock); -void GDAPI godot_byte_array_lock_free(godot_byte_array_lock p_byte_array_lock); - -godot_image GDAPI godot_image_create_with_array(int p_width, int p_height, int p_format, int p_use_mipmaps, godot_array p_array); -godot_byte_array GDAPI godot_image_get_data(godot_image p_image); - -////// IntArray - -typedef void *godot_int_array; - -godot_int_array GDAPI godot_int_array_create(); -godot_int_array GDAPI godot_int_array_copy(godot_int_array p_int_array); -void GDAPI godot_int_array_free(godot_int_array p_int_array); - -int GDAPI godot_int_array_get_size(godot_int_array p_int_array); -int GDAPI godot_int_array_get(godot_int_array p_int_array, int p_index); -void GDAPI godot_int_array_set(godot_int_array p_int_array, int p_index, int p_value); -void GDAPI godot_int_array_remove(godot_int_array p_int_array, int p_index); -void GDAPI godot_int_array_clear(godot_int_array p_int_array); - -typedef void *godot_int_array_lock; - -godot_int_array_lock GDAPI godot_int_array_get_lock(godot_int_array p_int_array); -int GDAPI *godot_int_array_lock_get_pointer(godot_int_array_lock p_int_array_lock); -void GDAPI godot_int_array_lock_free(godot_int_array_lock p_int_array_lock); - -////// RealArray - -typedef void *godot_real_array; - -godot_real_array GDAPI godot_real_array_create(); -godot_real_array GDAPI godot_real_array_copy(godot_real_array p_real_array); -void GDAPI godot_real_array_free(godot_real_array p_real_array); - -int GDAPI godot_real_array_get_size(godot_real_array p_real_array); -float GDAPI godot_real_array_get(godot_real_array p_real_array, int p_index); -void GDAPI godot_real_array_set(godot_real_array p_real_array, int p_index, float p_value); -void GDAPI godot_real_array_remove(godot_real_array p_real_array, int p_index); -void GDAPI godot_real_array_clear(godot_real_array p_real_array); - -typedef void *godot_real_array_lock; - -godot_real_array_lock GDAPI godot_real_array_get_lock(godot_real_array p_real_array); -float GDAPI *godot_real_array_lock_get_pointer(godot_real_array_lock p_real_array_lock); -void GDAPI godot_real_array_lock_free(godot_real_array_lock p_real_array_lock); - -////// StringArray - -typedef void *godot_string_array; - -godot_string_array GDAPI godot_string_array_create(); -godot_string_array GDAPI godot_string_array_copy(godot_string_array p_string_array); -void GDAPI godot_string_array_free(godot_string_array p_string_array); - -int GDAPI godot_string_array_get_size(godot_string_array p_string_array); -int GDAPI godot_string_array_get(godot_string_array p_string_array, int p_index, unsigned char *p_string, int p_max_len); -void GDAPI godot_string_array_set(godot_string_array p_string_array, int p_index, unsigned char *p_string); -void GDAPI godot_string_array_remove(godot_string_array p_string_array, int p_index); -void GDAPI godot_string_array_clear(godot_string_array p_string_array); - -////// Vector2Array - -typedef void *godot_vector2_array; - -godot_vector2_array GDAPI godot_vector2_array_create(); -godot_vector2_array GDAPI godot_vector2_array_copy(godot_vector2_array p_vector2_array); -void GDAPI godot_vector2_array_free(godot_vector2_array p_vector2_array); - -int GDAPI godot_vector2_array_get_size(godot_vector2_array p_vector2_array); -int GDAPI godot_vector2_array_get_stride(godot_vector2_array p_vector2_array); -void GDAPI godot_vector2_array_get(godot_vector2_array p_vector2_array, int p_index, float *p_vector2); -void GDAPI godot_vector2_array_set(godot_vector2_array p_vector2_array, int p_index, float *p_vector2); -void GDAPI godot_vector2_array_remove(godot_vector2_array p_vector2_array, int p_index); -void GDAPI godot_vector2_array_clear(godot_vector2_array p_vector2_array); - -typedef void *godot_vector2_array_lock; - -godot_vector2_array_lock GDAPI godot_vector2_array_get_lock(godot_vector2_array p_vector2_array); -float GDAPI *godot_vector2_array_lock_get_pointer(godot_vector2_array_lock p_vector2_array_lock); -void GDAPI godot_vector2_array_lock_free(godot_vector2_array_lock p_vector2_array_lock); - -////// Vector3Array - -typedef void *godot_vector3_array; - -godot_vector3_array GDAPI godot_vector3_array_create(); -godot_vector3_array GDAPI godot_vector3_array_copy(godot_vector3_array p_vector3_array); -void GDAPI godot_vector3_array_free(godot_vector3_array p_vector3_array); - -int GDAPI godot_vector3_array_get_size(godot_vector3_array p_vector3_array); -int GDAPI godot_vector3_array_get_stride(godot_vector3_array p_vector3_array); -void GDAPI godot_vector3_array_get(godot_vector3_array p_vector3_array, int p_index, float *p_vector3); -void GDAPI godot_vector3_array_set(godot_vector3_array p_vector3_array, int p_index, float *p_vector3); -void GDAPI godot_vector3_array_remove(godot_vector3_array p_vector3_array, int p_index); -void GDAPI godot_vector3_array_clear(godot_vector3_array p_vector3_array); - -typedef void *godot_vector3_array_lock; - -godot_vector3_array_lock GDAPI godot_vector3_array_get_lock(godot_vector3_array p_vector3_array); -float GDAPI *godot_vector3_array_lock_get_pointer(godot_vector3_array_lock p_vector3_array_lock); -void GDAPI godot_vector3_array_lock_free(godot_vector3_array_lock p_vector3_array_lock); - -////// ColorArray - -typedef void *godot_color_array; - -godot_color_array GDAPI godot_color_array_create(); -godot_color_array GDAPI godot_color_array_copy(godot_color_array p_color_array); -void GDAPI godot_color_array_free(godot_color_array p_color_array); - -int GDAPI godot_color_array_get_size(godot_color_array p_color_array); -int GDAPI godot_color_array_get_stride(godot_color_array p_color_array); -void GDAPI godot_color_array_get(godot_color_array p_color_array, int p_index, float *p_color); -void GDAPI godot_color_array_set(godot_color_array p_color_array, int p_index, float *p_color); -void GDAPI godot_color_array_remove(godot_color_array p_color_array, int p_index); -void GDAPI godot_color_array_clear(godot_color_array p_color_array); - -typedef void *godot_color_array_lock; - -godot_color_array_lock GDAPI godot_color_array_get_lock(godot_color_array p_color_array); -float GDAPI *godot_color_array_lock_get_pointer(godot_color_array_lock p_color_array_lock); -void GDAPI godot_color_array_lock_free(godot_color_array_lock p_color_array_lock); - -////// Instance (forward declared) - -typedef void *godot_instance; - -////// Variant - -#define GODOT_VARIANT_NIL 0 -#define GODOT_VARIANT_BOOL 1 -#define GODOT_VARIANT_INT 2 -#define GODOT_VARIANT_REAL 3 -#define GODOT_VARIANT_STRING 4 -#define GODOT_VARIANT_VECTOR2 5 -#define GODOT_VARIANT_RECT2 6 -#define GODOT_VARIANT_VECTOR3 7 -#define GODOT_VARIANT_MATRIX32 8 -#define GODOT_VARIANT_PLANE 9 -#define GODOT_VARIANT_QUAT 10 -#define GODOT_VARIANT_AABB 11 -#define GODOT_VARIANT_MATRIX3 12 -#define GODOT_VARIANT_TRANSFORM 13 -#define GODOT_VARIANT_COLOR 14 -#define GODOT_VARIANT_IMAGE 15 -#define GODOT_VARIANT_NODE_PATH 16 -#define GODOT_VARIANT_RID 17 -#define GODOT_VARIANT_OBJECT 18 -#define GODOT_VARIANT_INPUT_EVENT 19 -#define GODOT_VARIANT_DICTIONARY 20 -#define GODOT_VARIANT_ARRAY 21 -#define GODOT_VARIANT_BYTE_ARRAY 22 -#define GODOT_VARIANT_INT_ARRAY 23 -#define GODOT_VARIANT_REAL_ARRAY 24 -#define GODOT_VARIANT_STRING_ARRAY 25 -#define GODOT_VARIANT_VECTOR2_ARRAY 26 -#define GODOT_VARIANT_VECTOR3_ARRAY 27 -#define GODOT_VARIANT_COLOR_ARRAY 28 -#define GODOT_VARIANT_MAX 29 - -godot_variant *godot_variant_new(); - -int GDAPI godot_variant_get_type(godot_variant p_variant); - -void GDAPI godot_variant_set_null(godot_variant p_variant); -void GDAPI godot_variant_set_bool(godot_variant p_variant, godot_bool p_bool); -void GDAPI godot_variant_set_int(godot_variant p_variant, int p_int); -void GDAPI godot_variant_set_float(godot_variant p_variant, int p_float); -void GDAPI godot_variant_set_string(godot_variant p_variant, char *p_string); -void GDAPI godot_variant_set_vector2(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_rect2(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_vector3(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_matrix32(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_plane(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_aabb(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_matrix3(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_transform(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_color(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_set_image(godot_variant p_variant, godot_image *p_image); -void GDAPI godot_variant_set_node_path(godot_variant p_variant, char *p_path); -void GDAPI godot_variant_set_rid(godot_variant p_variant, char *p_path); -void GDAPI godot_variant_set_instance(godot_variant p_variant, godot_instance p_instance); -void GDAPI godot_variant_set_input_event(godot_variant p_variant, godot_input_event p_instance); -void GDAPI godot_variant_set_dictionary(godot_variant p_variant, godot_dictionary p_dictionary); -void GDAPI godot_variant_set_array(godot_variant p_variant, godot_array p_array); -void GDAPI godot_variant_set_byte_array(godot_variant p_variant, godot_byte_array p_array); -void GDAPI godot_variant_set_int_array(godot_variant p_variant, godot_byte_array p_array); -void GDAPI godot_variant_set_string_array(godot_variant p_variant, godot_string_array p_array); -void GDAPI godot_variant_set_vector2_array(godot_variant p_variant, godot_vector2_array p_array); -void GDAPI godot_variant_set_vector3_array(godot_variant p_variant, godot_vector3_array p_array); -void GDAPI godot_variant_set_color_array(godot_variant p_variant, godot_color_array p_array); - -godot_bool GDAPI godot_variant_get_bool(godot_variant p_variant); -int GDAPI godot_variant_get_int(godot_variant p_variant); -float GDAPI godot_variant_get_float(godot_variant p_variant); -int GDAPI godot_variant_get_string(godot_variant p_variant, char *p_string, int p_bufsize); -void GDAPI godot_variant_get_vector2(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_rect2(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_vector3(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_matrix32(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_plane(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_aabb(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_matrix3(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_transform(godot_variant p_variant, float *p_elems); -void GDAPI godot_variant_get_color(godot_variant p_variant, float *p_elems); -godot_image GDAPI *godot_variant_get_image(godot_variant p_variant); -int GDAPI godot_variant_get_node_path(godot_variant p_variant, char *p_path, int p_bufsize); -godot_rid GDAPI godot_variant_get_rid(godot_variant p_variant); -godot_instance GDAPI godot_variant_get_instance(godot_variant p_variant); -void GDAPI godot_variant_get_input_event(godot_variant p_variant, godot_input_event); -void GDAPI godot_variant_get_dictionary(godot_variant p_variant, godot_dictionary); -godot_array GDAPI godot_variant_get_array(godot_variant p_variant); -godot_byte_array GDAPI godot_variant_get_byte_array(godot_variant p_variant); -godot_byte_array GDAPI godot_variant_get_int_array(godot_variant p_variant); -godot_string_array GDAPI godot_variant_get_string_array(godot_variant p_variant); -godot_vector2_array GDAPI godot_variant_get_vector2_array(godot_variant p_variant); -godot_vector3_array GDAPI godot_variant_get_vector3_array(godot_variant p_variant); -godot_color_array GDAPI godot_variant_get_color_array(godot_variant p_variant); - -void GDAPI godot_variant_delete(godot_variant p_variant); - -////// Class -/// - -char GDAPI **godot_class_get_list(); //get list of classes in array to array of strings, must be freed, use godot_list_free() - -int GDAPI godot_class_get_base(char *p_class, char *p_base, int p_max_len); -int GDAPI godot_class_get_name(char *p_class, char *p_base, int p_max_len); - -char GDAPI **godot_class_get_method_list(char *p_class); //free with godot_list_free() -int GDAPI godot_class_method_get_argument_count(char *p_class, char *p_method); -int GDAPI godot_class_method_get_argument_type(char *p_class, char *p_method, int p_argument); -godot_variant GDAPI godot_class_method_get_argument_default_value(char *p_class, char *p_method, int p_argument); - -char GDAPI **godot_class_get_constant_list(char *p_class); //free with godot_list_free() -int GDAPI godot_class_constant_get_value(char *p_class, char *p_constant); - -////// Instance - -typedef int godot_call_error; - -#define GODOT_CALL_OK -#define GODOT_CALL_ERROR_WRONG_ARGUMENTS -#define GODOT_CALL_ERROR_INVALID_INSTANCE - -godot_instance GDAPI godot_instance_new(char *p_class); -int GDAPI godot_instance_get_class(godot_instance p_instance, char *p_class, int p_max_len); - -typedef struct { - char *name; - int hint; - char *hint_string; - int usage; -} godot_property_info; - -godot_call_error GDAPI godot_instance_call(godot_instance p_instance, char *p_method, ...); -godot_call_error GDAPI godot_instance_call_ret(godot_instance p_instance, godot_variant r_return, char *p_method, ...); -godot_bool GDAPI godot_instance_set(godot_instance p_instance, char *p_prop, godot_variant p_value); -godot_variant GDAPI godot_instance_get(godot_instance p_instance, char *p_prop); - -#define GODOT_PROPERTY_HINT_NONE 0 ///< no hint provided. -#define GODOT_PROPERTY_HINT_RANGE 1 ///< hint_text = "min,max,step,slider; //slider is optional" -#define GODOT_PROPERTY_HINT_EXP_RANGE 2 ///< hint_text = "min,max,step", exponential edit -#define GODOT_PROPERTY_HINT_ENUM 3 ///< hint_text= "val1,val2,val3,etc" -#define GODOT_PROPERTY_HINT_EXP_EASING 4 /// exponential easing function (Math::ease) -#define GODOT_PROPERTY_HINT_LENGTH 5 ///< hint_text= "length" (as integer) -#define GODOT_PROPERTY_HINT_SPRITE_FRAME 6 -#define GODOT_PROPERTY_HINT_KEY_ACCEL 7 ///< hint_text= "length" (as integer) -#define GODOT_PROPERTY_HINT_FLAGS 8 ///< hint_text= "flag1,flag2,etc" (as bit flags) -#define GODOT_PROPERTY_HINT_ALL_FLAGS 9 -#define GODOT_PROPERTY_HINT_FILE 10 ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc," -#define GODOT_PROPERTY_HINT_DIR 11 ///< a directort path must be passed -#define GODOT_PROPERTY_HINT_GLOBAL_FILE 12 ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc," -#define GODOT_PROPERTY_HINT_GLOBAL_DIR 13 ///< a directort path must be passed -#define GODOT_PROPERTY_HINT_RESOURCE_TYPE 14 ///< a resource object type -#define GODOT_PROPERTY_HINT_MULTILINE_TEXT 15 ///< used for string properties that can contain multiple lines -#define GODOT_PROPERTY_HINT_COLOR_NO_ALPHA 16 ///< used for ignoring alpha component when editing a color -#define GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSY 17 -#define GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS 18 -#define GODOT_PROPERTY_HINT_OBJECT_ID 19 - -#define GODOT_PROPERTY_USAGE_STORAGE 1 -#define GODOT_PROPERTY_USAGE_EDITOR 2 -#define GODOT_PROPERTY_USAGE_NETWORK 4 -#define GODOT_PROPERTY_USAGE_EDITOR_HELPER 8 -#define GODOT_PROPERTY_USAGE_CHECKABLE 16 //used for editing global variables -#define GODOT_PROPERTY_USAGE_CHECKED 32 //used for editing global variables -#define GODOT_PROPERTY_USAGE_INTERNATIONALIZED 64 //hint for internationalized strings -#define GODOT_PROPERTY_USAGE_BUNDLE 128 //used for optimized bundles -#define GODOT_PROPERTY_USAGE_CATEGORY 256 -#define GODOT_PROPERTY_USAGE_STORE_IF_NONZERO 512 //only store if nonzero -#define GODOT_PROPERTY_USAGE_STORE_IF_NONONE 1024 //only store if false -#define GODOT_PROPERTY_USAGE_NO_INSTANCE_STATE 2048 -#define GODOT_PROPERTY_USAGE_RESTART_IF_CHANGED 4096 -#define GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE 8192 -#define GODOT_PROPERTY_USAGE_STORE_IF_NULL 16384 -#define GODOT_PROPERTY_USAGE_ANIMATE_AS_TRIGGER 32768 - -#define GODOT_PROPERTY_USAGE_DEFAULT GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_EDITOR | GODOT_PROPERTY_USAGE_NETWORK -#define GODOT_PROPERTY_USAGE_DEFAULT_INTL GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_EDITOR | GODOT_PROPERTY_USAGE_NETWORK | GODOT_PROPERTY_USAGE_INTERNATIONALIZED -#define GODOT_PROPERTY_USAGE_NOEDITOR GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_NETWORK - -godot_property_info GDAPI **godot_instance_get_property_list(godot_instance p_instance); -void GDAPI godot_instance_free_property_list(godot_instance p_instance, godot_property_info **p_list); - -void GDAPI godot_list_free(char **p_name); //helper to free all the class list - -////// Script API - -typedef void *(godot_script_instance_func)(godot_instance); //passed an instance, return a pointer to your userdata -typedef void(godot_script_free_func)(godot_instance, void *); //passed an instance, please free your userdata - -void GDAPI godot_script_register(char *p_base, char *p_name, godot_script_instance_func p_instance_func, godot_script_free_func p_free_func); -void GDAPI godot_script_unregister(char *p_name); - -typedef GDAPI godot_variant(godot_script_func)(godot_instance, void *, godot_variant *, int); //instance,userdata,arguments,argument count. Return something or NULL. Arguments must not be freed. - -void GDAPI godot_script_add_function(char *p_name, char *p_function_name, godot_script_func p_func); -void GDAPI godot_script_add_validated_function(char *p_name, char *p_function_name, godot_script_func p_func, int *p_arg_types, int p_arg_count, godot_variant *p_default_args, int p_default_arg_count); - -typedef void(godot_set_property_func)(godot_instance, void *, godot_variant); //instance,userdata,value. Value must not be freed. -typedef godot_variant(godot_get_property_func)(godot_instance, void *); //instance,userdata. Return a value or NULL. - -void GDAPI godot_script_add_property(char *p_name, char *p_path, godot_set_property_func p_set_func, godot_get_property_func p_get_func); -void GDAPI godot_script_add_listed_property(char *p_name, char *p_path, godot_set_property_func p_set_func, godot_get_property_func p_get_func, int p_type, int p_hint, char *p_hint_string, int p_usage); - -////// System Functions - -//using these will help Godot track how much memory is in use in debug mode -void GDAPI *godot_alloc(int p_bytes); -void GDAPI *godot_realloc(void *p_ptr, int p_bytes); -void GDAPI godot_free(void *p_ptr); - -#ifdef __cplusplus -} -#endif - -#endif // GODOT_C_H diff --git a/modules/cscript/register_types.cpp b/modules/cscript/register_types.cpp deleted file mode 100644 index 2477bc51e2..0000000000 --- a/modules/cscript/register_types.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/*************************************************************************/ -/* register_types.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 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. */ -/*************************************************************************/ -#include "register_types.h" - -void register_cscript_types() { -} -void unregister_cscript_types() { -} diff --git a/modules/cscript/register_types.h b/modules/cscript/register_types.h deleted file mode 100644 index 6614ee3a19..0000000000 --- a/modules/cscript/register_types.h +++ /dev/null @@ -1,30 +0,0 @@ -/*************************************************************************/ -/* register_types.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 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. */ -/*************************************************************************/ -void register_cscript_types(); -void unregister_cscript_types(); diff --git a/modules/dlscript/SCsub b/modules/dlscript/SCsub new file mode 100644 index 0000000000..ac13319a1d --- /dev/null +++ b/modules/dlscript/SCsub @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +Import('env') + +env.add_source_files(env.modules_sources, "*.cpp") +env.add_source_files(env.modules_sources, "godot/*.cpp") + +env.Append(CPPFLAGS=['-DGDAPI_BUILT_IN']) + +if "platform" in env and env["platform"] == "x11": # there has to be a better solution? + env.Append(LINKFLAGS=["-rdynamic"]) +env.use_ptrcall = True + +Export('env') diff --git a/modules/dlscript/api_generator.cpp b/modules/dlscript/api_generator.cpp new file mode 100644 index 0000000000..2c2497b5b1 --- /dev/null +++ b/modules/dlscript/api_generator.cpp @@ -0,0 +1,382 @@ +#include "api_generator.h" + +#include "class_db.h" +#include "core/global_config.h" +#include "os/file_access.h" + +// helper stuff + +static Error save_file(const String &p_path, const List &p_content) { + + FileAccessRef file = FileAccess::open(p_path, FileAccess::WRITE); + + ERR_FAIL_COND_V(!file, ERR_FILE_CANT_WRITE); + + for (const List::Element *e = p_content.front(); e != NULL; e = e->next()) { + file->store_string(e->get()); + } + + file->close(); + + return OK; +} + +// helper stuff end + +struct MethodAPI { + String method_name; + String return_type; + + List argument_types; + List argument_names; + + Map default_arguments; + + int argument_count; + bool has_varargs; + bool is_editor; + bool is_noscript; + bool is_const; + bool is_reverse; + bool is_virtual; + bool is_from_script; +}; + +struct PropertyAPI { + String name; + String getter; + String setter; + String type; +}; + +struct ConstantAPI { + String constant_name; + int constant_value; +}; + +struct SignalAPI { + String name; + List argument_types; + List argument_names; + Map default_arguments; +}; + +struct ClassAPI { + String class_name; + String super_class_name; + + ClassDB::APIType api_type; + + bool is_singleton; + bool is_instanciable; + // @Unclear + bool is_creatable; + // @Unclear + bool memory_own; + + List methods; + List properties; + List constants; + List signals_; +}; + +/* + * Reads the entire Godot API to a list + */ +List generate_c_api_classes() { + + List api; + + List classes; + ClassDB::get_class_list(&classes); + + for (List::Element *e = classes.front(); e != NULL; e = e->next()) { + StringName class_name = e->get(); + + 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); + { + String name = class_name; + if (name.begins_with("_")) { + name.remove(0); + } + class_api.is_singleton = GlobalConfig::get_singleton()->has_singleton(name); + } + class_api.is_instanciable = !class_api.is_singleton && ClassDB::can_instance(class_name); + + { + bool is_reference = false; + List inheriters; + ClassDB::get_inheriters_from_class("Reference", &inheriters); + is_reference = inheriters.find(class_name) < 0; + // @Unclear + class_api.memory_own = !class_api.is_singleton && is_reference; + } + + // constants + { + List constant; + ClassDB::get_integer_constant_list(class_name, &constant, true); + for (List::Element *c = constant.front(); c != NULL; 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 signals_; + ClassDB::get_signal_list(class_name, &signals_, true); + + 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.find(":") != -1) { + type = argument.name.get_slice(":", 1); + name = argument.name.get_slice(":", 0); + } else if (argument.hint == PROPERTY_HINT_RESOURCE_TYPE) { + type = argument.hint_string; + } else if (argument.type == Variant::NIL) { + type = "Variant"; + } else { + type = Variant::get_type_name(argument.type); + } + + signal.argument_names.push_back(name); + signal.argument_types.push_back(type); + } + + Vector 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 properties; + ClassDB::get_property_list(class_name, &properties, true); + + for (List::Element *p = properties.front(); p != NULL; 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.find(":") != -1) { + property_api.type = p->get().name.get_slice(":", 1); + property_api.name = p->get().name.get_slice(":", 0); + } else if (p->get().hint == PROPERTY_HINT_RESOURCE_TYPE) { + property_api.type = p->get().hint_string; + } else if (p->get().type == Variant::NIL) { + property_api.type = "Variant"; + } else { + property_api.type = Variant::get_type_name(p->get().type); + } + + if (!property_api.setter.empty() || !property_api.getter.empty()) { + class_api.properties.push_back(property_api); + } + } + } + + //methods + { + List methods; + ClassDB::get_method_list(class_name, &methods, true); + + for (List::Element *m = methods.front(); m != NULL; 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 = m->get().name; + //method return type + if (method_bind && method_bind->get_return_type() != StringName()) { + method_api.return_type = method_bind->get_return_type(); + } else if (method_api.method_name.find(":") != -1) { + method_api.return_type = method_api.method_name.get_slice(":", 1); + method_api.method_name = method_api.method_name.get_slice(":", 0); + } else if (m->get().return_val.type != Variant::NIL) { + method_api.return_type = m->get().return_val.hint == PROPERTY_HINT_RESOURCE_TYPE ? m->get().return_val.hint_string : Variant::get_type_name(m->get().return_val.type); + } else { + method_api.return_type = "void"; + } + + method_api.argument_count = method_info.arguments.size(); + method_api.has_varargs = method_bind && method_bind->is_vararg(); + + // Method flags + if (method_bind && method_bind->get_hint_flags()) { + const uint32_t flags = method_bind->get_hint_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 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.find(":") != -1) { + 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.hint_string; + } else if (arg_info.type == Variant::NIL) { + arg_type = "Variant"; + } else { + arg_type = Variant::get_type_name(arg_info.type); + } + + 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); + } + } + + api.push_back(class_api); + } + + return api; +} + +/* + * Generates the JSON source from the API in p_api + */ +static List generate_c_api_json(const List &p_api) { + + // I'm sorry for the \t mess + + List source; + + source.push_back("[\n"); + + for (const List::Element *c = p_api.front(); c != NULL; 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(String("\t\t\"instanciable\": ") + (api.is_instanciable ? "true" : "false") + ",\n"); + // @Unclear + // source.push_back(String("\t\t\"createable\": ") + (api.is_creatable ? "true" : "false") + ",\n"); + + source.push_back("\t\t\"constants\": {\n"); + for (List::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::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}") + (e->next() ? "," : "") + "\n"); + } + source.push_back("\t\t],\n"); + + source.push_back("\t\t\"signals\": [\n"); + for (List::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("\t\t\t\t\t\t\"default_value\": \"" + (e->get().default_arguments.has(i) ? (String)e->get().default_arguments[i] : "") + "\"\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::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\"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("\t\t\t\t\t\t\"default_value\": \"" + (e->get().default_arguments.has(i) ? (String)e->get().default_arguments[i] : "") + "\"\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(String("\t}") + (c->next() ? "," : "") + "\n"); + } + + source.push_back("]"); + + return source; +} + +// + +/* + * Saves the whole Godot API to a JSON file located at + * p_path + */ +Error generate_c_api(const String &p_path) { + + List api = generate_c_api_classes(); + + List json_source = generate_c_api_json(api); + + return save_file(p_path, json_source); +} diff --git a/modules/dlscript/api_generator.h b/modules/dlscript/api_generator.h new file mode 100644 index 0000000000..4a8354e9d6 --- /dev/null +++ b/modules/dlscript/api_generator.h @@ -0,0 +1,9 @@ +#ifndef API_GENERATOR_H +#define API_GENERATOR_H + +#include "core/ustring.h" +#include "typedefs.h" + +Error generate_c_api(const String &p_path); + +#endif // API_GENERATOR_H diff --git a/modules/dlscript/config.py b/modules/dlscript/config.py new file mode 100644 index 0000000000..9f57b9bb74 --- /dev/null +++ b/modules/dlscript/config.py @@ -0,0 +1,8 @@ + + +def can_build(platform): + return True + + +def configure(env): + env.use_ptrcall = True diff --git a/modules/dlscript/dl_script.cpp b/modules/dlscript/dl_script.cpp new file mode 100644 index 0000000000..9917018891 --- /dev/null +++ b/modules/dlscript/dl_script.cpp @@ -0,0 +1,1048 @@ +/*************************************************************************/ +/* dl_script.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 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. */ +/*************************************************************************/ +#include "dl_script.h" + +#include "global_config.h" +#include "global_constants.h" +#include "io/file_access_encrypted.h" +#include "os/file_access.h" +#include "os/os.h" + +#include "scene/resources/scene_format_text.h" + +#ifdef TOOLS_ENABLED +// #include "editor/editor_import_export.h" +#endif + +#if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED) +#include "api_generator.h" +#endif + +// Script + +bool DLScript::can_instance() const { +#ifdef DLSCRIPT_EDITOR_FEATURES + return script_data || (!is_tool() && !ScriptServer::is_scripting_enabled()); +#else + // allow defaultlibrary without editor features + if (!library.is_valid()) { + String path = GLOBAL_GET("dlscript/default_dllibrary"); + + RES lib = ResourceLoader::load(path); + + if (lib.is_valid() && lib->cast_to()) { + return true; + } + } + + return script_data; +#endif + //return script_data || (!tool && !ScriptServer::is_scripting_enabled()); + // change to true enable in editor stuff. +} + +Ref