extension_api_dump.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. /**************************************************************************/
  2. /* extension_api_dump.cpp */
  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. #include "extension_api_dump.h"
  31. #include "core/config/engine.h"
  32. #include "core/core_constants.h"
  33. #include "core/io/file_access.h"
  34. #include "core/io/json.h"
  35. #include "core/templates/pair.h"
  36. #include "core/version.h"
  37. #ifdef TOOLS_ENABLED
  38. static String get_builtin_or_variant_type_name(const Variant::Type p_type) {
  39. if (p_type == Variant::NIL) {
  40. return "Variant";
  41. } else {
  42. return Variant::get_type_name(p_type);
  43. }
  44. }
  45. static String get_property_info_type_name(const PropertyInfo &p_info) {
  46. if (p_info.type == Variant::INT && (p_info.hint == PROPERTY_HINT_INT_IS_POINTER)) {
  47. if (p_info.hint_string.is_empty()) {
  48. return "void*";
  49. } else {
  50. return p_info.hint_string + "*";
  51. }
  52. }
  53. if (p_info.type == Variant::ARRAY && (p_info.hint == PROPERTY_HINT_ARRAY_TYPE)) {
  54. return String("typedarray::") + p_info.hint_string;
  55. }
  56. if (p_info.type == Variant::INT && (p_info.usage & (PROPERTY_USAGE_CLASS_IS_ENUM))) {
  57. return String("enum::") + String(p_info.class_name);
  58. }
  59. if (p_info.type == Variant::INT && (p_info.usage & (PROPERTY_USAGE_CLASS_IS_BITFIELD))) {
  60. return String("bitfield::") + String(p_info.class_name);
  61. }
  62. if (p_info.type == Variant::INT && (p_info.usage & PROPERTY_USAGE_ARRAY)) {
  63. return "int";
  64. }
  65. if (p_info.class_name != StringName()) {
  66. return p_info.class_name;
  67. }
  68. if (p_info.hint == PROPERTY_HINT_RESOURCE_TYPE) {
  69. return p_info.hint_string;
  70. }
  71. if (p_info.type == Variant::NIL && (p_info.usage & PROPERTY_USAGE_NIL_IS_VARIANT)) {
  72. return "Variant";
  73. }
  74. if (p_info.type == Variant::NIL) {
  75. return "void";
  76. }
  77. return get_builtin_or_variant_type_name(p_info.type);
  78. }
  79. Dictionary GDExtensionAPIDump::generate_extension_api() {
  80. Dictionary api_dump;
  81. {
  82. //header
  83. Dictionary header;
  84. header["version_major"] = VERSION_MAJOR;
  85. header["version_minor"] = VERSION_MINOR;
  86. #if VERSION_PATCH
  87. header["version_patch"] = VERSION_PATCH;
  88. #else
  89. header["version_patch"] = 0;
  90. #endif
  91. header["version_status"] = VERSION_STATUS;
  92. header["version_build"] = VERSION_BUILD;
  93. header["version_full_name"] = VERSION_FULL_NAME;
  94. api_dump["header"] = header;
  95. }
  96. const uint32_t vec3_elems = 3;
  97. const uint32_t vec4_elems = 4;
  98. const uint32_t ptrsize_32 = 4;
  99. const uint32_t ptrsize_64 = 8;
  100. static const char *build_config_name[4] = { "float_32", "float_64", "double_32", "double_64" };
  101. {
  102. //type sizes
  103. constexpr struct {
  104. Variant::Type type;
  105. uint32_t size_32_bits_real_float;
  106. uint32_t size_64_bits_real_float;
  107. uint32_t size_32_bits_real_double;
  108. uint32_t size_64_bits_real_double;
  109. // For compile-time size check.
  110. constexpr uint32_t operator[](int index) const {
  111. switch (index) {
  112. #ifndef REAL_T_IS_DOUBLE
  113. case sizeof(uint32_t):
  114. return size_32_bits_real_float;
  115. case sizeof(uint64_t):
  116. return size_64_bits_real_float;
  117. #else // REAL_T_IS_DOUBLE
  118. case sizeof(uint32_t):
  119. return size_32_bits_real_double;
  120. case sizeof(uint64_t):
  121. return size_64_bits_real_double;
  122. #endif
  123. }
  124. return -1;
  125. }
  126. } type_size_array[Variant::VARIANT_MAX + 1] = {
  127. { Variant::NIL, 0, 0, 0, 0 },
  128. { Variant::BOOL, sizeof(uint8_t), sizeof(uint8_t), sizeof(uint8_t), sizeof(uint8_t) },
  129. { Variant::INT, sizeof(int64_t), sizeof(int64_t), sizeof(int64_t), sizeof(int64_t) },
  130. { Variant::FLOAT, sizeof(double), sizeof(double), sizeof(double), sizeof(double) },
  131. { Variant::STRING, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 },
  132. { Variant::VECTOR2, 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(double), 2 * sizeof(double) },
  133. { Variant::VECTOR2I, 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t) },
  134. { Variant::RECT2, 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(double), 4 * sizeof(double) },
  135. { Variant::RECT2I, 4 * sizeof(int32_t), 4 * sizeof(int32_t), 4 * sizeof(int32_t), 4 * sizeof(int32_t) },
  136. { Variant::VECTOR3, vec3_elems * sizeof(float), vec3_elems * sizeof(float), vec3_elems * sizeof(double), vec3_elems * sizeof(double) },
  137. { Variant::VECTOR3I, 3 * sizeof(int32_t), 3 * sizeof(int32_t), 3 * sizeof(int32_t), 3 * sizeof(int32_t) },
  138. { Variant::TRANSFORM2D, 6 * sizeof(float), 6 * sizeof(float), 6 * sizeof(double), 6 * sizeof(double) },
  139. { Variant::VECTOR4, 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(double), 4 * sizeof(double) },
  140. { Variant::VECTOR4I, 4 * sizeof(int32_t), 4 * sizeof(int32_t), 4 * sizeof(int32_t), 4 * sizeof(int32_t) },
  141. { Variant::PLANE, (vec3_elems + 1) * sizeof(float), (vec3_elems + 1) * sizeof(float), (vec3_elems + 1) * sizeof(double), (vec3_elems + 1) * sizeof(double) },
  142. { Variant::QUATERNION, 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(double), 4 * sizeof(double) },
  143. { Variant::AABB, (vec3_elems * 2) * sizeof(float), (vec3_elems * 2) * sizeof(float), (vec3_elems * 2) * sizeof(double), (vec3_elems * 2) * sizeof(double) },
  144. { Variant::BASIS, (vec3_elems * 3) * sizeof(float), (vec3_elems * 3) * sizeof(float), (vec3_elems * 3) * sizeof(double), (vec3_elems * 3) * sizeof(double) },
  145. { Variant::TRANSFORM3D, (vec3_elems * 4) * sizeof(float), (vec3_elems * 4) * sizeof(float), (vec3_elems * 4) * sizeof(double), (vec3_elems * 4) * sizeof(double) },
  146. { Variant::PROJECTION, (vec4_elems * 4) * sizeof(float), (vec4_elems * 4) * sizeof(float), (vec4_elems * 4) * sizeof(double), (vec4_elems * 4) * sizeof(double) },
  147. { Variant::COLOR, 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(float) },
  148. { Variant::STRING_NAME, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 },
  149. { Variant::NODE_PATH, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 },
  150. { Variant::RID, sizeof(uint64_t), sizeof(uint64_t), sizeof(uint64_t), sizeof(uint64_t) },
  151. { Variant::OBJECT, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 },
  152. { Variant::CALLABLE, sizeof(Callable), sizeof(Callable), sizeof(Callable), sizeof(Callable) }, // Hardcoded align.
  153. { Variant::SIGNAL, sizeof(Signal), sizeof(Signal), sizeof(Signal), sizeof(Signal) }, // Hardcoded align.
  154. { Variant::DICTIONARY, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 },
  155. { Variant::ARRAY, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 },
  156. { Variant::PACKED_BYTE_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  157. { Variant::PACKED_INT32_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  158. { Variant::PACKED_INT64_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  159. { Variant::PACKED_FLOAT32_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  160. { Variant::PACKED_FLOAT64_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  161. { Variant::PACKED_STRING_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  162. { Variant::PACKED_VECTOR2_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  163. { Variant::PACKED_VECTOR3_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  164. { Variant::PACKED_COLOR_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  165. { Variant::VARIANT_MAX, sizeof(uint64_t) + sizeof(float) * 4, sizeof(uint64_t) + sizeof(float) * 4, sizeof(uint64_t) + sizeof(double) * 4, sizeof(uint64_t) + sizeof(double) * 4 },
  166. };
  167. // Validate sizes at compile time for the current build configuration.
  168. static_assert(type_size_array[Variant::BOOL][sizeof(void *)] == sizeof(GDExtensionBool), "Size of bool mismatch");
  169. static_assert(type_size_array[Variant::INT][sizeof(void *)] == sizeof(GDExtensionInt), "Size of int mismatch");
  170. static_assert(type_size_array[Variant::FLOAT][sizeof(void *)] == sizeof(double), "Size of float mismatch");
  171. static_assert(type_size_array[Variant::STRING][sizeof(void *)] == sizeof(String), "Size of String mismatch");
  172. static_assert(type_size_array[Variant::VECTOR2][sizeof(void *)] == sizeof(Vector2), "Size of Vector2 mismatch");
  173. static_assert(type_size_array[Variant::VECTOR2I][sizeof(void *)] == sizeof(Vector2i), "Size of Vector2i mismatch");
  174. static_assert(type_size_array[Variant::RECT2][sizeof(void *)] == sizeof(Rect2), "Size of Rect2 mismatch");
  175. static_assert(type_size_array[Variant::RECT2I][sizeof(void *)] == sizeof(Rect2i), "Size of Rect2i mismatch");
  176. static_assert(type_size_array[Variant::VECTOR3][sizeof(void *)] == sizeof(Vector3), "Size of Vector3 mismatch");
  177. static_assert(type_size_array[Variant::VECTOR3I][sizeof(void *)] == sizeof(Vector3i), "Size of Vector3i mismatch");
  178. static_assert(type_size_array[Variant::TRANSFORM2D][sizeof(void *)] == sizeof(Transform2D), "Size of Transform2D mismatch");
  179. static_assert(type_size_array[Variant::VECTOR4][sizeof(void *)] == sizeof(Vector4), "Size of Vector4 mismatch");
  180. static_assert(type_size_array[Variant::VECTOR4I][sizeof(void *)] == sizeof(Vector4i), "Size of Vector4i mismatch");
  181. static_assert(type_size_array[Variant::PLANE][sizeof(void *)] == sizeof(Plane), "Size of Plane mismatch");
  182. static_assert(type_size_array[Variant::QUATERNION][sizeof(void *)] == sizeof(Quaternion), "Size of Quaternion mismatch");
  183. static_assert(type_size_array[Variant::AABB][sizeof(void *)] == sizeof(AABB), "Size of AABB mismatch");
  184. static_assert(type_size_array[Variant::BASIS][sizeof(void *)] == sizeof(Basis), "Size of Basis mismatch");
  185. static_assert(type_size_array[Variant::TRANSFORM3D][sizeof(void *)] == sizeof(Transform3D), "Size of Transform3D mismatch");
  186. static_assert(type_size_array[Variant::PROJECTION][sizeof(void *)] == sizeof(Projection), "Size of Projection mismatch");
  187. static_assert(type_size_array[Variant::COLOR][sizeof(void *)] == sizeof(Color), "Size of Color mismatch");
  188. static_assert(type_size_array[Variant::STRING_NAME][sizeof(void *)] == sizeof(StringName), "Size of StringName mismatch");
  189. static_assert(type_size_array[Variant::NODE_PATH][sizeof(void *)] == sizeof(NodePath), "Size of NodePath mismatch");
  190. static_assert(type_size_array[Variant::RID][sizeof(void *)] == sizeof(RID), "Size of RID mismatch");
  191. static_assert(type_size_array[Variant::OBJECT][sizeof(void *)] == sizeof(Object *), "Size of Object mismatch");
  192. static_assert(type_size_array[Variant::CALLABLE][sizeof(void *)] == sizeof(Callable), "Size of Callable mismatch");
  193. static_assert(type_size_array[Variant::SIGNAL][sizeof(void *)] == sizeof(Signal), "Size of Signal mismatch");
  194. static_assert(type_size_array[Variant::DICTIONARY][sizeof(void *)] == sizeof(Dictionary), "Size of Dictionary mismatch");
  195. static_assert(type_size_array[Variant::ARRAY][sizeof(void *)] == sizeof(Array), "Size of Array mismatch");
  196. static_assert(type_size_array[Variant::PACKED_BYTE_ARRAY][sizeof(void *)] == sizeof(PackedByteArray), "Size of PackedByteArray mismatch");
  197. static_assert(type_size_array[Variant::PACKED_INT32_ARRAY][sizeof(void *)] == sizeof(PackedInt32Array), "Size of PackedInt32Array mismatch");
  198. static_assert(type_size_array[Variant::PACKED_INT64_ARRAY][sizeof(void *)] == sizeof(PackedInt64Array), "Size of PackedInt64Array mismatch");
  199. static_assert(type_size_array[Variant::PACKED_FLOAT32_ARRAY][sizeof(void *)] == sizeof(PackedFloat32Array), "Size of PackedFloat32Array mismatch");
  200. static_assert(type_size_array[Variant::PACKED_FLOAT64_ARRAY][sizeof(void *)] == sizeof(PackedFloat64Array), "Size of PackedFloat64Array mismatch");
  201. static_assert(type_size_array[Variant::PACKED_STRING_ARRAY][sizeof(void *)] == sizeof(PackedStringArray), "Size of PackedStringArray mismatch");
  202. static_assert(type_size_array[Variant::PACKED_VECTOR2_ARRAY][sizeof(void *)] == sizeof(PackedVector2Array), "Size of PackedVector2Array mismatch");
  203. static_assert(type_size_array[Variant::PACKED_VECTOR3_ARRAY][sizeof(void *)] == sizeof(PackedVector3Array), "Size of PackedVector3Array mismatch");
  204. static_assert(type_size_array[Variant::PACKED_COLOR_ARRAY][sizeof(void *)] == sizeof(PackedColorArray), "Size of PackedColorArray mismatch");
  205. static_assert(type_size_array[Variant::VARIANT_MAX][sizeof(void *)] == sizeof(Variant), "Size of Variant mismatch");
  206. Array core_type_sizes;
  207. for (int i = 0; i < 4; i++) {
  208. Dictionary d;
  209. d["build_configuration"] = build_config_name[i];
  210. Array sizes;
  211. for (int j = 0; j <= Variant::VARIANT_MAX; j++) {
  212. Variant::Type t = type_size_array[j].type;
  213. String name = t == Variant::VARIANT_MAX ? String("Variant") : Variant::get_type_name(t);
  214. Dictionary d2;
  215. d2["name"] = name;
  216. uint32_t size = 0;
  217. switch (i) {
  218. case 0:
  219. size = type_size_array[j].size_32_bits_real_float;
  220. break;
  221. case 1:
  222. size = type_size_array[j].size_64_bits_real_float;
  223. break;
  224. case 2:
  225. size = type_size_array[j].size_32_bits_real_double;
  226. break;
  227. case 3:
  228. size = type_size_array[j].size_64_bits_real_double;
  229. break;
  230. }
  231. d2["size"] = size;
  232. sizes.push_back(d2);
  233. }
  234. d["sizes"] = sizes;
  235. core_type_sizes.push_back(d);
  236. }
  237. api_dump["builtin_class_sizes"] = core_type_sizes;
  238. }
  239. {
  240. // Member offsets, meta types and sizes.
  241. #define REAL_MEMBER_OFFSET(type, member) \
  242. { \
  243. type, \
  244. member, \
  245. "float", \
  246. sizeof(float), \
  247. "float", \
  248. sizeof(float), \
  249. "double", \
  250. sizeof(double), \
  251. "double", \
  252. sizeof(double), \
  253. }
  254. #define INT32_MEMBER_OFFSET(type, member) \
  255. { \
  256. type, \
  257. member, \
  258. "int32", \
  259. sizeof(int32_t), \
  260. "int32", \
  261. sizeof(int32_t), \
  262. "int32", \
  263. sizeof(int32_t), \
  264. "int32", \
  265. sizeof(int32_t), \
  266. }
  267. #define INT32_BASED_BUILTIN_MEMBER_OFFSET(type, member, member_type, member_elems) \
  268. { \
  269. type, \
  270. member, \
  271. member_type, \
  272. sizeof(int32_t) * member_elems, \
  273. member_type, \
  274. sizeof(int32_t) * member_elems, \
  275. member_type, \
  276. sizeof(int32_t) * member_elems, \
  277. member_type, \
  278. sizeof(int32_t) * member_elems, \
  279. }
  280. #define REAL_BASED_BUILTIN_MEMBER_OFFSET(type, member, member_type, member_elems) \
  281. { \
  282. type, \
  283. member, \
  284. member_type, \
  285. sizeof(float) * member_elems, \
  286. member_type, \
  287. sizeof(float) * member_elems, \
  288. member_type, \
  289. sizeof(double) * member_elems, \
  290. member_type, \
  291. sizeof(double) * member_elems, \
  292. }
  293. struct {
  294. Variant::Type type;
  295. const char *member;
  296. const char *member_meta_32_bits_real_float;
  297. const uint32_t member_size_32_bits_real_float;
  298. const char *member_meta_64_bits_real_float;
  299. const uint32_t member_size_64_bits_real_float;
  300. const char *member_meta_32_bits_real_double;
  301. const uint32_t member_size_32_bits_real_double;
  302. const char *member_meta_64_bits_real_double;
  303. const uint32_t member_size_64_bits_real_double;
  304. } member_offset_array[] = {
  305. // Vector2
  306. REAL_MEMBER_OFFSET(Variant::VECTOR2, "x"),
  307. REAL_MEMBER_OFFSET(Variant::VECTOR2, "y"),
  308. // Vector2i
  309. INT32_MEMBER_OFFSET(Variant::VECTOR2I, "x"),
  310. INT32_MEMBER_OFFSET(Variant::VECTOR2I, "y"),
  311. // Rect2
  312. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::RECT2, "position", "Vector2", 2),
  313. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::RECT2, "size", "Vector2", 2),
  314. // Rect2i
  315. INT32_BASED_BUILTIN_MEMBER_OFFSET(Variant::RECT2I, "position", "Vector2i", 2),
  316. INT32_BASED_BUILTIN_MEMBER_OFFSET(Variant::RECT2I, "size", "Vector2i", 2),
  317. // Vector3
  318. REAL_MEMBER_OFFSET(Variant::VECTOR3, "x"),
  319. REAL_MEMBER_OFFSET(Variant::VECTOR3, "y"),
  320. REAL_MEMBER_OFFSET(Variant::VECTOR3, "z"),
  321. // Vector3i
  322. INT32_MEMBER_OFFSET(Variant::VECTOR3I, "x"),
  323. INT32_MEMBER_OFFSET(Variant::VECTOR3I, "y"),
  324. INT32_MEMBER_OFFSET(Variant::VECTOR3I, "z"),
  325. // Transform2D
  326. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::TRANSFORM2D, "x", "Vector2", 2),
  327. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::TRANSFORM2D, "y", "Vector2", 2),
  328. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::TRANSFORM2D, "origin", "Vector2", 2),
  329. // Vector4
  330. REAL_MEMBER_OFFSET(Variant::VECTOR4, "x"),
  331. REAL_MEMBER_OFFSET(Variant::VECTOR4, "y"),
  332. REAL_MEMBER_OFFSET(Variant::VECTOR4, "z"),
  333. REAL_MEMBER_OFFSET(Variant::VECTOR4, "w"),
  334. // Vector4i
  335. INT32_MEMBER_OFFSET(Variant::VECTOR4I, "x"),
  336. INT32_MEMBER_OFFSET(Variant::VECTOR4I, "y"),
  337. INT32_MEMBER_OFFSET(Variant::VECTOR4I, "z"),
  338. INT32_MEMBER_OFFSET(Variant::VECTOR4I, "w"),
  339. // Plane
  340. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::PLANE, "normal", "Vector3", vec3_elems),
  341. REAL_MEMBER_OFFSET(Variant::PLANE, "d"),
  342. // Quaternion
  343. REAL_MEMBER_OFFSET(Variant::QUATERNION, "x"),
  344. REAL_MEMBER_OFFSET(Variant::QUATERNION, "y"),
  345. REAL_MEMBER_OFFSET(Variant::QUATERNION, "z"),
  346. REAL_MEMBER_OFFSET(Variant::QUATERNION, "w"),
  347. // AABB
  348. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::AABB, "position", "Vector3", vec3_elems),
  349. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::AABB, "size", "Vector3", vec3_elems),
  350. // Basis (remember that basis vectors are flipped!)
  351. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::BASIS, "x", "Vector3", vec3_elems),
  352. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::BASIS, "y", "Vector3", vec3_elems),
  353. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::BASIS, "z", "Vector3", vec3_elems),
  354. // Transform3D
  355. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::TRANSFORM3D, "basis", "Basis", vec3_elems * 3),
  356. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::TRANSFORM3D, "origin", "Vector3", vec3_elems),
  357. // Projection
  358. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::PROJECTION, "x", "Vector4", vec4_elems),
  359. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::PROJECTION, "y", "Vector4", vec4_elems),
  360. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::PROJECTION, "z", "Vector4", vec4_elems),
  361. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::PROJECTION, "w", "Vector4", vec4_elems),
  362. // Color (always composed of 4bytes floats)
  363. { Variant::COLOR, "r", "float", sizeof(float), "float", sizeof(float), "float", sizeof(float), "float", sizeof(float) },
  364. { Variant::COLOR, "g", "float", sizeof(float), "float", sizeof(float), "float", sizeof(float), "float", sizeof(float) },
  365. { Variant::COLOR, "b", "float", sizeof(float), "float", sizeof(float), "float", sizeof(float), "float", sizeof(float) },
  366. { Variant::COLOR, "a", "float", sizeof(float), "float", sizeof(float), "float", sizeof(float), "float", sizeof(float) },
  367. // End marker, must stay last
  368. { Variant::NIL, nullptr, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0 },
  369. };
  370. Array core_type_member_offsets;
  371. for (int i = 0; i < 4; i++) {
  372. Dictionary d;
  373. d["build_configuration"] = build_config_name[i];
  374. Array type_offsets;
  375. uint32_t idx = 0;
  376. Variant::Type previous_type = Variant::NIL;
  377. Dictionary d2;
  378. Array members;
  379. uint32_t offset = 0;
  380. while (true) {
  381. Variant::Type t = member_offset_array[idx].type;
  382. if (t != previous_type) {
  383. if (previous_type != Variant::NIL) {
  384. d2["members"] = members;
  385. type_offsets.push_back(d2);
  386. }
  387. if (t == Variant::NIL) {
  388. break;
  389. }
  390. String name = t == Variant::VARIANT_MAX ? String("Variant") : Variant::get_type_name(t);
  391. d2 = Dictionary();
  392. members = Array();
  393. offset = 0;
  394. d2["name"] = name;
  395. previous_type = t;
  396. }
  397. Dictionary d3;
  398. const char *member_meta = nullptr;
  399. uint32_t member_size = 0;
  400. switch (i) {
  401. case 0:
  402. member_meta = member_offset_array[idx].member_meta_32_bits_real_float;
  403. member_size = member_offset_array[idx].member_size_32_bits_real_float;
  404. break;
  405. case 1:
  406. member_meta = member_offset_array[idx].member_meta_64_bits_real_float;
  407. member_size = member_offset_array[idx].member_size_64_bits_real_float;
  408. break;
  409. case 2:
  410. member_meta = member_offset_array[idx].member_meta_32_bits_real_double;
  411. member_size = member_offset_array[idx].member_size_32_bits_real_double;
  412. break;
  413. case 3:
  414. member_meta = member_offset_array[idx].member_meta_64_bits_real_double;
  415. member_size = member_offset_array[idx].member_size_64_bits_real_double;
  416. break;
  417. }
  418. d3["member"] = member_offset_array[idx].member;
  419. d3["offset"] = offset;
  420. d3["meta"] = member_meta;
  421. offset += member_size;
  422. members.push_back(d3);
  423. idx++;
  424. }
  425. d["classes"] = type_offsets;
  426. core_type_member_offsets.push_back(d);
  427. }
  428. api_dump["builtin_class_member_offsets"] = core_type_member_offsets;
  429. }
  430. {
  431. // Global enums and constants.
  432. Array constants;
  433. HashMap<String, List<Pair<String, int64_t>>> enum_list;
  434. HashMap<String, bool> enum_is_bitfield;
  435. for (int i = 0; i < CoreConstants::get_global_constant_count(); i++) {
  436. int64_t value = CoreConstants::get_global_constant_value(i);
  437. String enum_name = CoreConstants::get_global_constant_enum(i);
  438. String name = CoreConstants::get_global_constant_name(i);
  439. bool bitfield = CoreConstants::is_global_constant_bitfield(i);
  440. if (!enum_name.is_empty()) {
  441. enum_list[enum_name].push_back(Pair<String, int64_t>(name, value));
  442. enum_is_bitfield[enum_name] = bitfield;
  443. } else {
  444. Dictionary d;
  445. d["name"] = name;
  446. d["value"] = value;
  447. d["is_bitfield"] = bitfield;
  448. constants.push_back(d);
  449. }
  450. }
  451. api_dump["global_constants"] = constants;
  452. Array enums;
  453. for (const KeyValue<String, List<Pair<String, int64_t>>> &E : enum_list) {
  454. Dictionary d1;
  455. d1["name"] = E.key;
  456. d1["is_bitfield"] = enum_is_bitfield[E.key];
  457. Array values;
  458. for (const Pair<String, int64_t> &F : E.value) {
  459. Dictionary d2;
  460. d2["name"] = F.first;
  461. d2["value"] = F.second;
  462. values.push_back(d2);
  463. }
  464. d1["values"] = values;
  465. enums.push_back(d1);
  466. }
  467. api_dump["global_enums"] = enums;
  468. }
  469. {
  470. Array utility_funcs;
  471. List<StringName> utility_func_names;
  472. Variant::get_utility_function_list(&utility_func_names);
  473. for (const StringName &name : utility_func_names) {
  474. Dictionary func;
  475. func["name"] = String(name);
  476. if (Variant::has_utility_function_return_value(name)) {
  477. Variant::Type rt = Variant::get_utility_function_return_type(name);
  478. func["return_type"] = rt == Variant::NIL ? String("Variant") : Variant::get_type_name(rt);
  479. }
  480. switch (Variant::get_utility_function_type(name)) {
  481. case Variant::UTILITY_FUNC_TYPE_MATH:
  482. func["category"] = "math";
  483. break;
  484. case Variant::UTILITY_FUNC_TYPE_RANDOM:
  485. func["category"] = "random";
  486. break;
  487. case Variant::UTILITY_FUNC_TYPE_GENERAL:
  488. func["category"] = "general";
  489. break;
  490. }
  491. bool vararg = Variant::is_utility_function_vararg(name);
  492. func["is_vararg"] = Variant::is_utility_function_vararg(name);
  493. func["hash"] = Variant::get_utility_function_hash(name);
  494. Array arguments;
  495. int argcount = Variant::get_utility_function_argument_count(name);
  496. for (int i = 0; i < argcount; i++) {
  497. Dictionary arg;
  498. String argname = vararg ? "arg" + itos(i + 1) : Variant::get_utility_function_argument_name(name, i);
  499. arg["name"] = argname;
  500. arg["type"] = get_builtin_or_variant_type_name(Variant::get_utility_function_argument_type(name, i));
  501. //no default value support in utility functions
  502. arguments.push_back(arg);
  503. }
  504. if (arguments.size()) {
  505. func["arguments"] = arguments;
  506. }
  507. utility_funcs.push_back(func);
  508. }
  509. api_dump["utility_functions"] = utility_funcs;
  510. }
  511. {
  512. // builtin types
  513. Array builtins;
  514. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  515. if (i == Variant::OBJECT) {
  516. continue;
  517. }
  518. Variant::Type type = Variant::Type(i);
  519. Dictionary d;
  520. d["name"] = Variant::get_type_name(type);
  521. if (Variant::has_indexing(type)) {
  522. d["indexing_return_type"] = get_builtin_or_variant_type_name(Variant::get_indexed_element_type(type));
  523. }
  524. d["is_keyed"] = Variant::is_keyed(type);
  525. {
  526. //members
  527. Array members;
  528. List<StringName> member_names;
  529. Variant::get_member_list(type, &member_names);
  530. for (const StringName &member_name : member_names) {
  531. Dictionary d2;
  532. d2["name"] = String(member_name);
  533. d2["type"] = get_builtin_or_variant_type_name(Variant::get_member_type(type, member_name));
  534. members.push_back(d2);
  535. }
  536. if (members.size()) {
  537. d["members"] = members;
  538. }
  539. }
  540. {
  541. //constants
  542. Array constants;
  543. List<StringName> constant_names;
  544. Variant::get_constants_for_type(type, &constant_names);
  545. for (const StringName &constant_name : constant_names) {
  546. Dictionary d2;
  547. d2["name"] = String(constant_name);
  548. Variant constant = Variant::get_constant_value(type, constant_name);
  549. d2["type"] = get_builtin_or_variant_type_name(constant.get_type());
  550. d2["value"] = constant.get_construct_string();
  551. constants.push_back(d2);
  552. }
  553. if (constants.size()) {
  554. d["constants"] = constants;
  555. }
  556. }
  557. {
  558. //enums
  559. Array enums;
  560. List<StringName> enum_names;
  561. Variant::get_enums_for_type(type, &enum_names);
  562. for (const StringName &enum_name : enum_names) {
  563. Dictionary enum_dict;
  564. enum_dict["name"] = String(enum_name);
  565. List<StringName> enumeration_names;
  566. Variant::get_enumerations_for_enum(type, enum_name, &enumeration_names);
  567. Array values;
  568. for (const StringName &enumeration : enumeration_names) {
  569. Dictionary values_dict;
  570. values_dict["name"] = String(enumeration);
  571. values_dict["value"] = Variant::get_enum_value(type, enum_name, enumeration);
  572. values.push_back(values_dict);
  573. }
  574. if (values.size()) {
  575. enum_dict["values"] = values;
  576. }
  577. enums.push_back(enum_dict);
  578. }
  579. if (enums.size()) {
  580. d["enums"] = enums;
  581. }
  582. }
  583. {
  584. //operators
  585. Array operators;
  586. for (int j = 0; j < Variant::VARIANT_MAX; j++) {
  587. for (int k = 0; k < Variant::OP_MAX; k++) {
  588. Variant::Type rt = Variant::get_operator_return_type(Variant::Operator(k), type, Variant::Type(j));
  589. if (rt != Variant::NIL) {
  590. Dictionary d2;
  591. d2["name"] = Variant::get_operator_name(Variant::Operator(k));
  592. if (k != Variant::OP_NEGATE && k != Variant::OP_POSITIVE && k != Variant::OP_NOT && k != Variant::OP_BIT_NEGATE) {
  593. d2["right_type"] = get_builtin_or_variant_type_name(Variant::Type(j));
  594. }
  595. d2["return_type"] = get_builtin_or_variant_type_name(Variant::get_operator_return_type(Variant::Operator(k), type, Variant::Type(j)));
  596. operators.push_back(d2);
  597. }
  598. }
  599. }
  600. if (operators.size()) {
  601. d["operators"] = operators;
  602. }
  603. }
  604. {
  605. //methods
  606. Array methods;
  607. List<StringName> method_names;
  608. Variant::get_builtin_method_list(type, &method_names);
  609. for (const StringName &method_name : method_names) {
  610. Dictionary d2;
  611. d2["name"] = String(method_name);
  612. if (Variant::has_builtin_method_return_value(type, method_name)) {
  613. Variant::Type ret_type = Variant::get_builtin_method_return_type(type, method_name);
  614. d2["return_type"] = ret_type == Variant::NIL ? String("Variant") : Variant::get_type_name(ret_type);
  615. }
  616. d2["is_vararg"] = Variant::is_builtin_method_vararg(type, method_name);
  617. d2["is_const"] = Variant::is_builtin_method_const(type, method_name);
  618. d2["is_static"] = Variant::is_builtin_method_static(type, method_name);
  619. d2["hash"] = Variant::get_builtin_method_hash(type, method_name);
  620. Vector<Variant> default_args = Variant::get_builtin_method_default_arguments(type, method_name);
  621. Array arguments;
  622. int argcount = Variant::get_builtin_method_argument_count(type, method_name);
  623. for (int j = 0; j < argcount; j++) {
  624. Dictionary d3;
  625. d3["name"] = Variant::get_builtin_method_argument_name(type, method_name, j);
  626. d3["type"] = get_builtin_or_variant_type_name(Variant::get_builtin_method_argument_type(type, method_name, j));
  627. if (j >= (argcount - default_args.size())) {
  628. int dargidx = j - (argcount - default_args.size());
  629. d3["default_value"] = default_args[dargidx].get_construct_string();
  630. }
  631. arguments.push_back(d3);
  632. }
  633. if (arguments.size()) {
  634. d2["arguments"] = arguments;
  635. }
  636. methods.push_back(d2);
  637. }
  638. if (methods.size()) {
  639. d["methods"] = methods;
  640. }
  641. }
  642. {
  643. //constructors
  644. Array constructors;
  645. for (int j = 0; j < Variant::get_constructor_count(type); j++) {
  646. Dictionary d2;
  647. d2["index"] = j;
  648. Array arguments;
  649. int argcount = Variant::get_constructor_argument_count(type, j);
  650. for (int k = 0; k < argcount; k++) {
  651. Dictionary d3;
  652. d3["name"] = Variant::get_constructor_argument_name(type, j, k);
  653. d3["type"] = get_builtin_or_variant_type_name(Variant::get_constructor_argument_type(type, j, k));
  654. arguments.push_back(d3);
  655. }
  656. if (arguments.size()) {
  657. d2["arguments"] = arguments;
  658. }
  659. constructors.push_back(d2);
  660. }
  661. if (constructors.size()) {
  662. d["constructors"] = constructors;
  663. }
  664. }
  665. {
  666. //destructor
  667. d["has_destructor"] = Variant::has_destructor(type);
  668. }
  669. builtins.push_back(d);
  670. }
  671. api_dump["builtin_classes"] = builtins;
  672. }
  673. {
  674. // classes
  675. Array classes;
  676. List<StringName> class_list;
  677. ClassDB::get_class_list(&class_list);
  678. class_list.sort_custom<StringName::AlphCompare>();
  679. for (const StringName &class_name : class_list) {
  680. Dictionary d;
  681. d["name"] = String(class_name);
  682. d["is_refcounted"] = ClassDB::is_parent_class(class_name, "RefCounted");
  683. d["is_instantiable"] = ClassDB::can_instantiate(class_name);
  684. StringName parent_class = ClassDB::get_parent_class(class_name);
  685. if (parent_class != StringName()) {
  686. d["inherits"] = String(parent_class);
  687. }
  688. {
  689. ClassDB::APIType api = ClassDB::get_api_type(class_name);
  690. static const char *api_type[5] = { "core", "editor", "extension", "editor_extension" };
  691. d["api_type"] = api_type[api];
  692. }
  693. {
  694. //constants
  695. Array constants;
  696. List<String> constant_list;
  697. ClassDB::get_integer_constant_list(class_name, &constant_list, true);
  698. for (const String &F : constant_list) {
  699. StringName enum_name = ClassDB::get_integer_constant_enum(class_name, F);
  700. if (enum_name != StringName()) {
  701. continue; //enums will be handled on their own
  702. }
  703. Dictionary d2;
  704. d2["name"] = String(F);
  705. d2["value"] = ClassDB::get_integer_constant(class_name, F);
  706. constants.push_back(d2);
  707. }
  708. if (constants.size()) {
  709. d["constants"] = constants;
  710. }
  711. }
  712. {
  713. //enum
  714. Array enums;
  715. List<StringName> enum_list;
  716. ClassDB::get_enum_list(class_name, &enum_list, true);
  717. for (const StringName &F : enum_list) {
  718. Dictionary d2;
  719. d2["name"] = String(F);
  720. d2["is_bitfield"] = ClassDB::is_enum_bitfield(class_name, F);
  721. Array values;
  722. List<StringName> enum_constant_list;
  723. ClassDB::get_enum_constants(class_name, F, &enum_constant_list, true);
  724. for (List<StringName>::Element *G = enum_constant_list.front(); G; G = G->next()) {
  725. Dictionary d3;
  726. d3["name"] = String(G->get());
  727. d3["value"] = ClassDB::get_integer_constant(class_name, G->get());
  728. values.push_back(d3);
  729. }
  730. d2["values"] = values;
  731. enums.push_back(d2);
  732. }
  733. if (enums.size()) {
  734. d["enums"] = enums;
  735. }
  736. }
  737. {
  738. //methods
  739. Array methods;
  740. List<MethodInfo> method_list;
  741. ClassDB::get_method_list(class_name, &method_list, true);
  742. for (const MethodInfo &F : method_list) {
  743. StringName method_name = F.name;
  744. if ((F.flags & METHOD_FLAG_VIRTUAL) && !(F.flags & METHOD_FLAG_OBJECT_CORE)) {
  745. //virtual method
  746. const MethodInfo &mi = F;
  747. Dictionary d2;
  748. d2["name"] = String(method_name);
  749. d2["is_const"] = (F.flags & METHOD_FLAG_CONST) ? true : false;
  750. d2["is_static"] = (F.flags & METHOD_FLAG_STATIC) ? true : false;
  751. d2["is_vararg"] = false;
  752. d2["is_virtual"] = true;
  753. // virtual functions have no hash since no MethodBind is involved
  754. bool has_return = mi.return_val.type != Variant::NIL || (mi.return_val.usage & PROPERTY_USAGE_NIL_IS_VARIANT);
  755. Array arguments;
  756. for (int i = (has_return ? -1 : 0); i < mi.arguments.size(); i++) {
  757. PropertyInfo pinfo = i == -1 ? mi.return_val : mi.arguments[i];
  758. Dictionary d3;
  759. if (i >= 0) {
  760. d3["name"] = pinfo.name;
  761. }
  762. d3["type"] = get_property_info_type_name(pinfo);
  763. if (i == -1) {
  764. d2["return_value"] = d3;
  765. } else {
  766. arguments.push_back(d3);
  767. }
  768. }
  769. if (arguments.size()) {
  770. d2["arguments"] = arguments;
  771. }
  772. methods.push_back(d2);
  773. } else if (F.name.begins_with("_")) {
  774. //hidden method, ignore
  775. } else {
  776. Dictionary d2;
  777. d2["name"] = String(method_name);
  778. MethodBind *method = ClassDB::get_method(class_name, method_name);
  779. if (!method) {
  780. continue;
  781. }
  782. d2["is_const"] = method->is_const();
  783. d2["is_vararg"] = method->is_vararg();
  784. d2["is_static"] = method->is_static();
  785. d2["is_virtual"] = false;
  786. d2["hash"] = method->get_hash();
  787. Vector<Variant> default_args = method->get_default_arguments();
  788. Array arguments;
  789. for (int i = (method->has_return() ? -1 : 0); i < method->get_argument_count(); i++) {
  790. PropertyInfo pinfo = i == -1 ? method->get_return_info() : method->get_argument_info(i);
  791. Dictionary d3;
  792. if (i >= 0) {
  793. d3["name"] = pinfo.name;
  794. }
  795. d3["type"] = get_property_info_type_name(pinfo);
  796. if (method->get_argument_meta(i) > 0) {
  797. static const char *argmeta[11] = { "none", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float", "double" };
  798. d3["meta"] = argmeta[method->get_argument_meta(i)];
  799. }
  800. if (i >= 0 && i >= (method->get_argument_count() - default_args.size())) {
  801. int dargidx = i - (method->get_argument_count() - default_args.size());
  802. d3["default_value"] = default_args[dargidx].get_construct_string();
  803. }
  804. if (i == -1) {
  805. d2["return_value"] = d3;
  806. } else {
  807. arguments.push_back(d3);
  808. }
  809. }
  810. if (arguments.size()) {
  811. d2["arguments"] = arguments;
  812. }
  813. methods.push_back(d2);
  814. }
  815. }
  816. if (methods.size()) {
  817. d["methods"] = methods;
  818. }
  819. }
  820. {
  821. //signals
  822. Array signals;
  823. List<MethodInfo> signal_list;
  824. ClassDB::get_signal_list(class_name, &signal_list, true);
  825. for (const MethodInfo &F : signal_list) {
  826. StringName signal_name = F.name;
  827. Dictionary d2;
  828. d2["name"] = String(signal_name);
  829. Array arguments;
  830. for (int i = 0; i < F.arguments.size(); i++) {
  831. Dictionary d3;
  832. d3["name"] = F.arguments[i].name;
  833. d3["type"] = get_property_info_type_name(F.arguments[i]);
  834. arguments.push_back(d3);
  835. }
  836. if (arguments.size()) {
  837. d2["arguments"] = arguments;
  838. }
  839. signals.push_back(d2);
  840. }
  841. if (signals.size()) {
  842. d["signals"] = signals;
  843. }
  844. }
  845. {
  846. //properties
  847. Array properties;
  848. List<PropertyInfo> property_list;
  849. ClassDB::get_property_list(class_name, &property_list, true);
  850. for (const PropertyInfo &F : property_list) {
  851. if (F.usage & PROPERTY_USAGE_CATEGORY || F.usage & PROPERTY_USAGE_GROUP || F.usage & PROPERTY_USAGE_SUBGROUP || (F.type == Variant::NIL && F.usage & PROPERTY_USAGE_ARRAY)) {
  852. continue; //not real properties
  853. }
  854. if (F.name.begins_with("_")) {
  855. continue; //hidden property
  856. }
  857. if (F.name.find("/") >= 0) {
  858. // Ignore properties with '/' (slash) in the name. These are only meant for use in the inspector.
  859. continue;
  860. }
  861. StringName property_name = F.name;
  862. Dictionary d2;
  863. d2["type"] = get_property_info_type_name(F);
  864. d2["name"] = String(property_name);
  865. StringName setter = ClassDB::get_property_setter(class_name, F.name);
  866. if (!(setter == "")) {
  867. d2["setter"] = setter;
  868. }
  869. StringName getter = ClassDB::get_property_getter(class_name, F.name);
  870. if (!(getter == "")) {
  871. d2["getter"] = getter;
  872. }
  873. int index = ClassDB::get_property_index(class_name, F.name);
  874. if (index != -1) {
  875. d2["index"] = index;
  876. }
  877. properties.push_back(d2);
  878. }
  879. if (properties.size()) {
  880. d["properties"] = properties;
  881. }
  882. }
  883. classes.push_back(d);
  884. }
  885. api_dump["classes"] = classes;
  886. }
  887. {
  888. // singletons
  889. Array singletons;
  890. List<Engine::Singleton> singleton_list;
  891. Engine::get_singleton()->get_singletons(&singleton_list);
  892. for (const Engine::Singleton &s : singleton_list) {
  893. Dictionary d;
  894. d["name"] = s.name;
  895. if (s.class_name != StringName()) {
  896. d["type"] = String(s.class_name);
  897. } else {
  898. d["type"] = String(s.ptr->get_class());
  899. }
  900. singletons.push_back(d);
  901. }
  902. if (singletons.size()) {
  903. api_dump["singletons"] = singletons;
  904. }
  905. }
  906. {
  907. Array native_structures;
  908. List<StringName> native_structs;
  909. ClassDB::get_native_struct_list(&native_structs);
  910. native_structs.sort_custom<StringName::AlphCompare>();
  911. for (const StringName &E : native_structs) {
  912. String code = ClassDB::get_native_struct_code(E);
  913. Dictionary d;
  914. d["name"] = String(E);
  915. d["format"] = code;
  916. native_structures.push_back(d);
  917. }
  918. api_dump["native_structures"] = native_structures;
  919. }
  920. return api_dump;
  921. }
  922. void GDExtensionAPIDump::generate_extension_json_file(const String &p_path) {
  923. Dictionary api = generate_extension_api();
  924. Ref<JSON> json;
  925. json.instantiate();
  926. String text = json->stringify(api, "\t", false) + "\n";
  927. Ref<FileAccess> fa = FileAccess::open(p_path, FileAccess::WRITE);
  928. fa->store_string(text);
  929. }
  930. #endif // TOOLS_ENABLED