class_db.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. /**************************************************************************/
  2. /* class_db.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #include "core/object/method_bind.h"
  32. #include "core/object/object.h"
  33. #include "core/os/rw_lock.h"
  34. #include "core/string/print_string.h"
  35. // Makes callable_mp readily available in all classes connecting signals.
  36. // Needs to come after method_bind and object have been included.
  37. #include "core/object/callable_method_pointer.h"
  38. #include "core/templates/hash_set.h"
  39. #include <type_traits>
  40. template <typename T, typename = void>
  41. struct is_class_enabled;
  42. template <>
  43. struct is_class_enabled<Object> : std::true_type {};
  44. template <typename T>
  45. struct is_class_enabled<T, std::enable_if_t<std::is_base_of_v<Object, T>>> {
  46. static constexpr bool value = is_class_enabled<typename T::super_type>::value;
  47. };
  48. template <typename T>
  49. inline constexpr bool is_class_enabled_v = is_class_enabled<T>::value;
  50. #define GD_IS_CLASS_ENABLED(m_class) is_class_enabled_v<m_class>
  51. #include "core/disabled_classes.gen.h"
  52. #define DEFVAL(m_defval) (m_defval)
  53. #define DEFVAL_ARRAY DEFVAL(ClassDB::default_array_arg)
  54. #ifdef DEBUG_ENABLED
  55. struct MethodDefinition {
  56. StringName name;
  57. Vector<StringName> args;
  58. MethodDefinition() {}
  59. MethodDefinition(const char *p_name) :
  60. name(p_name) {}
  61. MethodDefinition(const StringName &p_name) :
  62. name(p_name) {}
  63. };
  64. MethodDefinition D_METHODP(const char *p_name, const char *const **p_args, uint32_t p_argcount);
  65. template <typename... VarArgs>
  66. MethodDefinition D_METHOD(const char *p_name, const VarArgs... p_args) {
  67. const char *args[sizeof...(p_args) + 1] = { p_args..., nullptr }; // +1 makes sure zero sized arrays are also supported.
  68. const char *const *argptrs[sizeof...(p_args) + 1];
  69. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  70. argptrs[i] = &args[i];
  71. }
  72. return D_METHODP(p_name, sizeof...(p_args) == 0 ? nullptr : (const char *const **)argptrs, sizeof...(p_args));
  73. }
  74. #else
  75. // When DEBUG_ENABLED is set this will let the engine know
  76. // the argument names for easier debugging.
  77. #define D_METHOD(m_c, ...) m_c
  78. #endif // DEBUG_ENABLED
  79. class ClassDB {
  80. friend class Object;
  81. public:
  82. enum APIType {
  83. API_CORE,
  84. API_EDITOR,
  85. API_EXTENSION,
  86. API_EDITOR_EXTENSION,
  87. API_NONE
  88. };
  89. public:
  90. struct PropertySetGet {
  91. int index;
  92. StringName setter;
  93. StringName getter;
  94. MethodBind *_setptr = nullptr;
  95. MethodBind *_getptr = nullptr;
  96. Variant::Type type;
  97. };
  98. struct ClassInfo {
  99. APIType api = API_NONE;
  100. ClassInfo *inherits_ptr = nullptr;
  101. void *class_ptr = nullptr;
  102. ObjectGDExtension *gdextension = nullptr;
  103. HashMap<StringName, MethodBind *> method_map;
  104. HashMap<StringName, LocalVector<MethodBind *>> method_map_compatibility;
  105. HashMap<StringName, int64_t> constant_map;
  106. struct EnumInfo {
  107. List<StringName> constants;
  108. bool is_bitfield = false;
  109. };
  110. HashMap<StringName, EnumInfo> enum_map;
  111. HashMap<StringName, MethodInfo> signal_map;
  112. List<PropertyInfo> property_list;
  113. HashMap<StringName, PropertyInfo> property_map;
  114. #ifdef DEBUG_ENABLED
  115. List<StringName> constant_order;
  116. List<StringName> method_order;
  117. HashSet<StringName> methods_in_properties;
  118. List<MethodInfo> virtual_methods;
  119. HashMap<StringName, MethodInfo> virtual_methods_map;
  120. HashMap<StringName, Vector<Error>> method_error_values;
  121. HashMap<StringName, List<StringName>> linked_properties;
  122. #endif // DEBUG_ENABLED
  123. #ifdef TOOLS_ENABLED
  124. List<StringName> dependency_list;
  125. #endif
  126. HashMap<StringName, PropertySetGet> property_setget;
  127. HashMap<StringName, Vector<uint32_t>> virtual_methods_compat;
  128. StringName inherits;
  129. StringName name;
  130. bool disabled = false;
  131. bool exposed = false;
  132. bool reloadable = false;
  133. bool is_virtual = false;
  134. bool is_runtime = false;
  135. // The bool argument indicates the need to postinitialize.
  136. Object *(*creation_func)(bool) = nullptr;
  137. ClassInfo() {}
  138. ~ClassInfo() {}
  139. };
  140. template <typename T>
  141. static Object *creator(bool p_notify_postinitialize) {
  142. Object *ret = new ("") T;
  143. ret->_initialize();
  144. if (p_notify_postinitialize) {
  145. ret->_postinitialize();
  146. }
  147. return ret;
  148. }
  149. // We need a recursive r/w lock because there are various code paths
  150. // that may in turn invoke other entry points with require locking.
  151. class Locker {
  152. public:
  153. enum State {
  154. STATE_UNLOCKED,
  155. STATE_READ,
  156. STATE_WRITE,
  157. };
  158. private:
  159. inline static RWLock lock;
  160. inline thread_local static State thread_state = STATE_UNLOCKED;
  161. public:
  162. class Lock {
  163. State state = STATE_UNLOCKED;
  164. public:
  165. explicit Lock(State p_state);
  166. ~Lock();
  167. };
  168. };
  169. static HashMap<StringName, ClassInfo> classes;
  170. static HashMap<StringName, StringName> resource_base_extensions;
  171. static HashMap<StringName, StringName> compat_classes;
  172. #ifdef TOOLS_ENABLED
  173. static HashMap<StringName, ObjectGDExtension> placeholder_extensions;
  174. #endif
  175. #ifdef DEBUG_ENABLED
  176. static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, bool p_compatibility, const MethodDefinition &method_name, const Variant **p_defs, int p_defcount);
  177. #else
  178. static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, bool p_compatibility, const char *method_name, const Variant **p_defs, int p_defcount);
  179. #endif // DEBUG_ENABLED
  180. static APIType current_api;
  181. static HashMap<APIType, uint32_t> api_hashes_cache;
  182. static void _add_class(const StringName &p_class, const StringName &p_inherits);
  183. static HashMap<StringName, HashMap<StringName, Variant>> default_values;
  184. static HashSet<StringName> default_values_cached;
  185. // Native structs, used by binder
  186. struct NativeStruct {
  187. String ccode; // C code to create the native struct, fields separated by ; Arrays accepted (even containing other structs), also function pointers. All types must be Godot types.
  188. uint64_t struct_size; // local size of struct, for comparison
  189. };
  190. static HashMap<StringName, NativeStruct> native_structs;
  191. static Array default_array_arg;
  192. static bool is_default_array_arg(const Array &p_array);
  193. private:
  194. // Non-locking variants of get_parent_class and is_parent_class.
  195. static StringName _get_parent_class(const StringName &p_class);
  196. static bool _is_parent_class(const StringName &p_class, const StringName &p_inherits);
  197. static void _bind_compatibility(ClassInfo *type, MethodBind *p_method);
  198. static MethodBind *_bind_vararg_method(MethodBind *p_bind, const StringName &p_name, const Vector<Variant> &p_default_args, bool p_compatibility);
  199. static void _bind_method_custom(const StringName &p_class, MethodBind *p_method, bool p_compatibility);
  200. static Object *_instantiate_internal(const StringName &p_class, bool p_require_real_class = false, bool p_notify_postinitialize = true, bool p_exposed_only = true);
  201. static bool _can_instantiate(ClassInfo *p_class_info, bool p_exposed_only = true);
  202. public:
  203. template <typename T>
  204. static void register_class(bool p_virtual = false) {
  205. Locker::Lock lock(Locker::STATE_WRITE);
  206. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  207. T::initialize_class();
  208. ClassInfo *t = classes.getptr(T::get_class_static());
  209. ERR_FAIL_NULL(t);
  210. t->creation_func = &creator<T>;
  211. t->exposed = true;
  212. t->is_virtual = p_virtual;
  213. t->class_ptr = T::get_class_ptr_static();
  214. t->api = current_api;
  215. T::register_custom_data_to_otdb();
  216. }
  217. template <typename T>
  218. static void register_abstract_class() {
  219. Locker::Lock lock(Locker::STATE_WRITE);
  220. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  221. T::initialize_class();
  222. ClassInfo *t = classes.getptr(T::get_class_static());
  223. ERR_FAIL_NULL(t);
  224. t->exposed = true;
  225. t->class_ptr = T::get_class_ptr_static();
  226. t->api = current_api;
  227. //nothing
  228. }
  229. template <typename T>
  230. static void register_internal_class() {
  231. Locker::Lock lock(Locker::STATE_WRITE);
  232. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  233. T::initialize_class();
  234. ClassInfo *t = classes.getptr(T::get_class_static());
  235. ERR_FAIL_NULL(t);
  236. t->creation_func = &creator<T>;
  237. t->exposed = false;
  238. t->is_virtual = false;
  239. t->class_ptr = T::get_class_ptr_static();
  240. t->api = current_api;
  241. T::register_custom_data_to_otdb();
  242. }
  243. template <typename T>
  244. static void register_runtime_class() {
  245. Locker::Lock lock(Locker::STATE_WRITE);
  246. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  247. T::initialize_class();
  248. ClassInfo *t = classes.getptr(T::get_class_static());
  249. ERR_FAIL_NULL(t);
  250. ERR_FAIL_COND_MSG(t->inherits_ptr && !t->inherits_ptr->creation_func, vformat("Cannot register runtime class '%s' that descends from an abstract parent class.", T::get_class_static()));
  251. t->creation_func = &creator<T>;
  252. t->exposed = true;
  253. t->is_virtual = false;
  254. t->is_runtime = true;
  255. t->class_ptr = T::get_class_ptr_static();
  256. t->api = current_api;
  257. T::register_custom_data_to_otdb();
  258. }
  259. static void register_extension_class(ObjectGDExtension *p_extension);
  260. static void unregister_extension_class(const StringName &p_class, bool p_free_method_binds = true);
  261. template <typename T>
  262. static Object *_create_ptr_func(bool p_notify_postinitialize) {
  263. return T::create(p_notify_postinitialize);
  264. }
  265. template <typename T>
  266. static void register_custom_instance_class() {
  267. Locker::Lock lock(Locker::STATE_WRITE);
  268. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  269. T::initialize_class();
  270. ClassInfo *t = classes.getptr(T::get_class_static());
  271. ERR_FAIL_NULL(t);
  272. t->creation_func = &_create_ptr_func<T>;
  273. t->exposed = true;
  274. t->class_ptr = T::get_class_ptr_static();
  275. t->api = current_api;
  276. T::register_custom_data_to_otdb();
  277. }
  278. static void get_class_list(LocalVector<StringName> &p_classes);
  279. #ifdef TOOLS_ENABLED
  280. static void get_extensions_class_list(LocalVector<StringName> &p_classes);
  281. static void get_extension_class_list(const Ref<GDExtension> &p_extension, List<StringName> *p_classes);
  282. static ObjectGDExtension *get_placeholder_extension(const StringName &p_class);
  283. #endif
  284. static void get_inheriters_from_class(const StringName &p_class, LocalVector<StringName> &p_classes);
  285. static void get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
  286. static StringName get_parent_class_nocheck(const StringName &p_class);
  287. static bool get_inheritance_chain_nocheck(const StringName &p_class, Vector<StringName> &r_result);
  288. static StringName get_parent_class(const StringName &p_class);
  289. static StringName get_compatibility_remapped_class(const StringName &p_class);
  290. static bool class_exists(const StringName &p_class);
  291. static bool is_parent_class(const StringName &p_class, const StringName &p_inherits);
  292. static bool can_instantiate(const StringName &p_class);
  293. static bool is_abstract(const StringName &p_class);
  294. static bool is_virtual(const StringName &p_class);
  295. static Object *instantiate(const StringName &p_class);
  296. static Object *instantiate_no_placeholders(const StringName &p_class);
  297. static Object *instantiate_without_postinitialization(const StringName &p_class);
  298. static void set_object_extension_instance(Object *p_object, const StringName &p_class, GDExtensionClassInstancePtr p_instance);
  299. static APIType get_api_type(const StringName &p_class);
  300. static uint32_t get_api_hash(APIType p_api);
  301. template <typename>
  302. struct member_function_traits;
  303. template <typename R, typename T, typename... Args>
  304. struct member_function_traits<R (T::*)(Args...)> {
  305. using return_type = R;
  306. };
  307. template <typename R, typename T, typename... Args>
  308. struct member_function_traits<R (T::*)(Args...) const> {
  309. using return_type = R;
  310. };
  311. template <typename R, typename... Args>
  312. struct member_function_traits<R (*)(Args...)> {
  313. using return_type = R;
  314. };
  315. template <typename N, typename M, typename... VarArgs>
  316. static MethodBind *bind_method(N p_method_name, M p_method, VarArgs... p_args) {
  317. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  318. const Variant *argptrs[sizeof...(p_args) + 1];
  319. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  320. argptrs[i] = &args[i];
  321. }
  322. MethodBind *bind = create_method_bind(p_method);
  323. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  324. bind->set_return_type_is_raw_object_ptr(true);
  325. }
  326. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, false, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  327. }
  328. template <typename N, typename M, typename... VarArgs>
  329. static MethodBind *bind_static_method(const StringName &p_class, N p_method_name, M p_method, VarArgs... p_args) {
  330. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  331. const Variant *argptrs[sizeof...(p_args) + 1];
  332. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  333. argptrs[i] = &args[i];
  334. }
  335. MethodBind *bind = create_static_method_bind(p_method);
  336. bind->set_instance_class(p_class);
  337. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  338. bind->set_return_type_is_raw_object_ptr(true);
  339. }
  340. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, false, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  341. }
  342. template <typename N, typename M, typename... VarArgs>
  343. static MethodBind *bind_compatibility_method(N p_method_name, M p_method, VarArgs... p_args) {
  344. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  345. const Variant *argptrs[sizeof...(p_args) + 1];
  346. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  347. argptrs[i] = &args[i];
  348. }
  349. MethodBind *bind = create_method_bind(p_method);
  350. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  351. bind->set_return_type_is_raw_object_ptr(true);
  352. }
  353. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, true, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  354. }
  355. template <typename N, typename M, typename... VarArgs>
  356. static MethodBind *bind_compatibility_static_method(const StringName &p_class, N p_method_name, M p_method, VarArgs... p_args) {
  357. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  358. const Variant *argptrs[sizeof...(p_args) + 1];
  359. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  360. argptrs[i] = &args[i];
  361. }
  362. MethodBind *bind = create_static_method_bind(p_method);
  363. bind->set_instance_class(p_class);
  364. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  365. bind->set_return_type_is_raw_object_ptr(true);
  366. }
  367. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, true, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  368. }
  369. template <typename M>
  370. static MethodBind *bind_vararg_method(uint32_t p_flags, const StringName &p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector<Variant> &p_default_args = Vector<Variant>(), bool p_return_nil_is_variant = true) {
  371. Locker::Lock lock(Locker::STATE_WRITE);
  372. MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
  373. ERR_FAIL_NULL_V(bind, nullptr);
  374. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  375. bind->set_return_type_is_raw_object_ptr(true);
  376. }
  377. return _bind_vararg_method(bind, p_name, p_default_args, false);
  378. }
  379. template <typename M>
  380. static MethodBind *bind_compatibility_vararg_method(uint32_t p_flags, const StringName &p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector<Variant> &p_default_args = Vector<Variant>(), bool p_return_nil_is_variant = true) {
  381. Locker::Lock lock(Locker::STATE_WRITE);
  382. MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
  383. ERR_FAIL_NULL_V(bind, nullptr);
  384. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  385. bind->set_return_type_is_raw_object_ptr(true);
  386. }
  387. return _bind_vararg_method(bind, p_name, p_default_args, true);
  388. }
  389. static void bind_method_custom(const StringName &p_class, MethodBind *p_method);
  390. static void bind_compatibility_method_custom(const StringName &p_class, MethodBind *p_method);
  391. static void add_signal(const StringName &p_class, const MethodInfo &p_signal);
  392. static bool has_signal(const StringName &p_class, const StringName &p_signal, bool p_no_inheritance = false);
  393. static bool get_signal(const StringName &p_class, const StringName &p_signal, MethodInfo *r_signal);
  394. static void get_signal_list(const StringName &p_class, List<MethodInfo> *p_signals, bool p_no_inheritance = false);
  395. static void add_property_group(const StringName &p_class, const String &p_name, const String &p_prefix = "", int p_indent_depth = 0);
  396. static void add_property_subgroup(const StringName &p_class, const String &p_name, const String &p_prefix = "", int p_indent_depth = 0);
  397. static void add_property_array_count(const StringName &p_class, const String &p_label, const StringName &p_count_property, const StringName &p_count_setter, const StringName &p_count_getter, const String &p_array_element_prefix, uint32_t p_count_usage = PROPERTY_USAGE_DEFAULT);
  398. static void add_property_array(const StringName &p_class, const StringName &p_path, const String &p_array_element_prefix);
  399. static void add_property(const StringName &p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index = -1);
  400. static void set_property_default_value(const StringName &p_class, const StringName &p_name, const Variant &p_default);
  401. static void add_linked_property(const StringName &p_class, const String &p_property, const String &p_linked_property);
  402. static void get_property_list(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance = false, const Object *p_validator = nullptr);
  403. static bool get_property_info(const StringName &p_class, const StringName &p_property, PropertyInfo *r_info, bool p_no_inheritance = false, const Object *p_validator = nullptr);
  404. static void get_linked_properties_info(const StringName &p_class, const StringName &p_property, List<StringName> *r_properties, bool p_no_inheritance = false);
  405. static bool set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid = nullptr);
  406. static bool get_property(Object *p_object, const StringName &p_property, Variant &r_value);
  407. static bool has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance = false);
  408. static int get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
  409. static Variant::Type get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
  410. static StringName get_property_setter(const StringName &p_class, const StringName &p_property);
  411. static StringName get_property_getter(const StringName &p_class, const StringName &p_property);
  412. static bool has_method(const StringName &p_class, const StringName &p_method, bool p_no_inheritance = false);
  413. static void set_method_flags(const StringName &p_class, const StringName &p_method, int p_flags);
  414. static void get_method_list(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false, bool p_exclude_from_properties = false);
  415. static void get_method_list_with_compatibility(const StringName &p_class, List<Pair<MethodInfo, uint32_t>> *p_methods_with_hash, bool p_no_inheritance = false, bool p_exclude_from_properties = false);
  416. static bool get_method_info(const StringName &p_class, const StringName &p_method, MethodInfo *r_info, bool p_no_inheritance = false, bool p_exclude_from_properties = false);
  417. static int get_method_argument_count(const StringName &p_class, const StringName &p_method, bool *r_is_valid = nullptr, bool p_no_inheritance = false);
  418. static MethodBind *get_method(const StringName &p_class, const StringName &p_name);
  419. static MethodBind *get_method_with_compatibility(const StringName &p_class, const StringName &p_name, uint64_t p_hash, bool *r_method_exists = nullptr, bool *r_is_deprecated = nullptr);
  420. static Vector<uint32_t> get_method_compatibility_hashes(const StringName &p_class, const StringName &p_name);
  421. static void add_virtual_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual = true, const Vector<String> &p_arg_names = Vector<String>(), bool p_object_core = false);
  422. static void add_virtual_compatibility_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual = true, const Vector<String> &p_arg_names = Vector<String>(), bool p_object_core = false);
  423. static void get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false);
  424. static void add_extension_class_virtual_method(const StringName &p_class, const GDExtensionClassVirtualMethodInfo *p_method_info);
  425. static Vector<uint32_t> get_virtual_method_compatibility_hashes(const StringName &p_class, const StringName &p_name);
  426. static void bind_integer_constant(const StringName &p_class, const StringName &p_enum, const StringName &p_name, int64_t p_constant, bool p_is_bitfield = false);
  427. static void get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance = false);
  428. static int64_t get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success = nullptr);
  429. static bool has_integer_constant(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  430. static StringName get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  431. static StringName get_integer_constant_bitfield(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  432. static void get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance = false);
  433. static void get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance = false);
  434. static bool has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  435. static bool is_enum_bitfield(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  436. static void set_method_error_return_values(const StringName &p_class, const StringName &p_method, const Vector<Error> &p_values);
  437. static Vector<Error> get_method_error_return_values(const StringName &p_class, const StringName &p_method);
  438. static Variant class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid = nullptr);
  439. static void set_class_enabled(const StringName &p_class, bool p_enable);
  440. static bool is_class_enabled(const StringName &p_class);
  441. static bool is_class_exposed(const StringName &p_class);
  442. static bool is_class_reloadable(const StringName &p_class);
  443. static bool is_class_runtime(const StringName &p_class);
  444. #ifdef TOOLS_ENABLED
  445. static void add_class_dependency(const StringName &p_class, const StringName &p_dependency);
  446. static void get_class_dependencies(const StringName &p_class, List<StringName> *r_rependencies);
  447. #endif
  448. static void add_resource_base_extension(const StringName &p_extension, const StringName &p_class);
  449. static void get_resource_base_extensions(List<String> *p_extensions);
  450. static void get_extensions_for_type(const StringName &p_class, List<String> *p_extensions);
  451. static bool is_resource_extension(const StringName &p_extension);
  452. static void add_compatibility_class(const StringName &p_class, const StringName &p_fallback);
  453. static StringName get_compatibility_class(const StringName &p_class);
  454. static void set_current_api(APIType p_api);
  455. static APIType get_current_api();
  456. static void cleanup_defaults();
  457. static void cleanup();
  458. static void register_native_struct(const StringName &p_name, const String &p_code, uint64_t p_current_size);
  459. static void get_native_struct_list(List<StringName> *r_names);
  460. static String get_native_struct_code(const StringName &p_name);
  461. static uint64_t get_native_struct_size(const StringName &p_name); // Used for asserting
  462. static Object *_instantiate_allow_unexposed(const StringName &p_class); // Used to create unexposed classes from GDExtension, typically for unexposed EditorPlugin.
  463. };
  464. #define BIND_ENUM_CONSTANT(m_constant) \
  465. ::ClassDB::bind_integer_constant(get_class_static(), __constant_get_enum_name(m_constant), #m_constant, m_constant);
  466. #define BIND_BITFIELD_FLAG(m_constant) \
  467. ::ClassDB::bind_integer_constant(get_class_static(), __constant_get_bitfield_name(m_constant), #m_constant, m_constant, true);
  468. #define BIND_CONSTANT(m_constant) \
  469. ::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
  470. #ifdef DEBUG_ENABLED
  471. #define BIND_METHOD_ERR_RETURN_DOC(m_method, ...) \
  472. ::ClassDB::set_method_error_return_values(get_class_static(), m_method, Vector<Error>{ __VA_ARGS__ });
  473. #else
  474. #define BIND_METHOD_ERR_RETURN_DOC(m_method, ...)
  475. #endif // DEBUG_ENABLED
  476. #define GDREGISTER_CLASS(m_class) \
  477. if constexpr (GD_IS_CLASS_ENABLED(m_class)) { \
  478. ::ClassDB::register_class<m_class>(); \
  479. }
  480. #define GDREGISTER_VIRTUAL_CLASS(m_class) \
  481. if constexpr (GD_IS_CLASS_ENABLED(m_class)) { \
  482. ::ClassDB::register_class<m_class>(true); \
  483. }
  484. #define GDREGISTER_ABSTRACT_CLASS(m_class) \
  485. if constexpr (GD_IS_CLASS_ENABLED(m_class)) { \
  486. ::ClassDB::register_abstract_class<m_class>(); \
  487. }
  488. #define GDREGISTER_INTERNAL_CLASS(m_class) \
  489. if constexpr (GD_IS_CLASS_ENABLED(m_class)) { \
  490. ::ClassDB::register_internal_class<m_class>(); \
  491. }
  492. #define GDREGISTER_RUNTIME_CLASS(m_class) \
  493. if constexpr (GD_IS_CLASS_ENABLED(m_class)) { \
  494. ::ClassDB::register_runtime_class<m_class>(); \
  495. }
  496. #define GDREGISTER_NATIVE_STRUCT(m_class, m_code) ClassDB::register_native_struct(#m_class, m_code, sizeof(m_class))