extension_api_dump.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  1. /*************************************************************************/
  2. /* extension_api_dump.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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 sizes.
  241. struct {
  242. Variant::Type type;
  243. const char *member;
  244. uint32_t offset_32_bits_real_float;
  245. uint32_t offset_64_bits_real_float;
  246. uint32_t offset_32_bits_real_double;
  247. uint32_t offset_64_bits_real_double;
  248. } member_offset_array[] = {
  249. { Variant::VECTOR2, "x", 0, 0, 0, 0 },
  250. { Variant::VECTOR2, "y", sizeof(float), sizeof(float), sizeof(double), sizeof(double) },
  251. { Variant::VECTOR2I, "x", 0, 0, 0, 0 },
  252. { Variant::VECTOR2I, "y", sizeof(int32_t), sizeof(int32_t), sizeof(int32_t), sizeof(int32_t) },
  253. { Variant::RECT2, "position", 0, 0, 0, 0 },
  254. { Variant::RECT2, "size", 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(double), 2 * sizeof(double) },
  255. { Variant::RECT2I, "position", 0, 0, 0, 0 },
  256. { Variant::RECT2I, "size", 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t) },
  257. { Variant::VECTOR3, "x", 0, 0, 0, 0 },
  258. { Variant::VECTOR3, "y", sizeof(float), sizeof(float), sizeof(double), sizeof(double) },
  259. { Variant::VECTOR3, "z", 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(double), 2 * sizeof(double) },
  260. { Variant::VECTOR3I, "x", 0, 0, 0, 0 },
  261. { Variant::VECTOR3I, "y", sizeof(int32_t), sizeof(int32_t), sizeof(int32_t), sizeof(int32_t) },
  262. { Variant::VECTOR3I, "z", 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t) },
  263. { Variant::TRANSFORM2D, "x", 0, 0, 0, 0 },
  264. { Variant::TRANSFORM2D, "y", 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(double), 2 * sizeof(double) },
  265. { Variant::TRANSFORM2D, "origin", 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(double), 4 * sizeof(double) },
  266. { Variant::VECTOR4, "x", 0, 0, 0, 0 },
  267. { Variant::VECTOR4, "y", sizeof(float), sizeof(float), sizeof(double), sizeof(double) },
  268. { Variant::VECTOR4, "z", 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(double), 2 * sizeof(double) },
  269. { Variant::VECTOR4, "w", 3 * sizeof(float), 3 * sizeof(float), 3 * sizeof(double), 3 * sizeof(double) },
  270. { Variant::VECTOR4I, "x", 0, 0, 0, 0 },
  271. { Variant::VECTOR4I, "y", sizeof(int32_t), sizeof(int32_t), sizeof(int32_t), sizeof(int32_t) },
  272. { Variant::VECTOR4I, "z", 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t) },
  273. { Variant::VECTOR4I, "w", 3 * sizeof(int32_t), 3 * sizeof(int32_t), 3 * sizeof(int32_t), 3 * sizeof(int32_t) },
  274. { Variant::PLANE, "normal", 0, 0, 0, 0 },
  275. { Variant::PLANE, "d", vec3_elems * sizeof(float), vec3_elems * sizeof(float), vec3_elems * sizeof(double), vec3_elems * sizeof(double) },
  276. { Variant::QUATERNION, "x", 0, 0, 0, 0 },
  277. { Variant::QUATERNION, "y", sizeof(float), sizeof(float), sizeof(double), sizeof(double) },
  278. { Variant::QUATERNION, "z", 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(double), 2 * sizeof(double) },
  279. { Variant::QUATERNION, "w", 3 * sizeof(float), 3 * sizeof(float), 3 * sizeof(double), 3 * sizeof(double) },
  280. { Variant::AABB, "position", 0, 0, 0, 0 },
  281. { Variant::AABB, "size", vec3_elems * sizeof(float), vec3_elems * sizeof(float), vec3_elems * sizeof(double), vec3_elems * sizeof(double) },
  282. // Remember that basis vectors are flipped!
  283. { Variant::BASIS, "x", 0, 0, 0, 0 },
  284. { Variant::BASIS, "y", vec3_elems * sizeof(float), vec3_elems * sizeof(float), vec3_elems * sizeof(double), vec3_elems * sizeof(double) },
  285. { Variant::BASIS, "z", vec3_elems * 2 * sizeof(float), vec3_elems * 2 * sizeof(float), vec3_elems * 2 * sizeof(double), vec3_elems * 2 * sizeof(double) },
  286. { Variant::TRANSFORM3D, "basis", 0, 0, 0, 0 },
  287. { Variant::TRANSFORM3D, "origin", (vec3_elems * 3) * sizeof(float), (vec3_elems * 3) * sizeof(float), (vec3_elems * 3) * sizeof(double), (vec3_elems * 3) * sizeof(double) },
  288. { Variant::PROJECTION, "x", 0, 0, 0, 0 },
  289. { Variant::PROJECTION, "y", vec4_elems * sizeof(float), vec4_elems * sizeof(float), vec4_elems * sizeof(double), vec4_elems * sizeof(double) },
  290. { Variant::PROJECTION, "z", vec4_elems * 2 * sizeof(float), vec4_elems * 2 * sizeof(float), vec4_elems * 2 * sizeof(double), vec4_elems * 2 * sizeof(double) },
  291. { Variant::PROJECTION, "w", vec4_elems * 3 * sizeof(float), vec4_elems * 3 * sizeof(float), vec4_elems * 3 * sizeof(double), vec4_elems * 3 * sizeof(double) },
  292. { Variant::COLOR, "r", 0, 0, 0, 0 },
  293. { Variant::COLOR, "g", sizeof(float), sizeof(float), sizeof(float), sizeof(float) },
  294. { Variant::COLOR, "b", 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(float) },
  295. { Variant::COLOR, "a", 3 * sizeof(float), 3 * sizeof(float), 3 * sizeof(float), 3 * sizeof(float) },
  296. { Variant::NIL, nullptr, 0, 0, 0, 0 },
  297. };
  298. Array core_type_member_offsets;
  299. for (int i = 0; i < 4; i++) {
  300. Dictionary d;
  301. d["build_configuration"] = build_config_name[i];
  302. Array type_offsets;
  303. uint32_t idx = 0;
  304. Variant::Type last_type = Variant::NIL;
  305. Dictionary d2;
  306. Array members;
  307. while (true) {
  308. Variant::Type t = member_offset_array[idx].type;
  309. if (t != last_type) {
  310. if (last_type != Variant::NIL) {
  311. d2["members"] = members;
  312. type_offsets.push_back(d2);
  313. }
  314. if (t == Variant::NIL) {
  315. break;
  316. }
  317. String name = t == Variant::VARIANT_MAX ? String("Variant") : Variant::get_type_name(t);
  318. d2 = Dictionary();
  319. members = Array();
  320. d2["name"] = name;
  321. last_type = t;
  322. }
  323. Dictionary d3;
  324. uint32_t offset = 0;
  325. switch (i) {
  326. case 0:
  327. offset = member_offset_array[idx].offset_32_bits_real_float;
  328. break;
  329. case 1:
  330. offset = member_offset_array[idx].offset_64_bits_real_float;
  331. break;
  332. case 2:
  333. offset = member_offset_array[idx].offset_32_bits_real_double;
  334. break;
  335. case 3:
  336. offset = member_offset_array[idx].offset_64_bits_real_double;
  337. break;
  338. }
  339. d3["member"] = member_offset_array[idx].member;
  340. d3["offset"] = offset;
  341. members.push_back(d3);
  342. idx++;
  343. }
  344. d["classes"] = type_offsets;
  345. core_type_member_offsets.push_back(d);
  346. }
  347. api_dump["builtin_class_member_offsets"] = core_type_member_offsets;
  348. }
  349. {
  350. // Global enums and constants.
  351. Array constants;
  352. HashMap<String, List<Pair<String, int64_t>>> enum_list;
  353. for (int i = 0; i < CoreConstants::get_global_constant_count(); i++) {
  354. int64_t value = CoreConstants::get_global_constant_value(i);
  355. String enum_name = CoreConstants::get_global_constant_enum(i);
  356. String name = CoreConstants::get_global_constant_name(i);
  357. if (!enum_name.is_empty()) {
  358. enum_list[enum_name].push_back(Pair<String, int64_t>(name, value));
  359. } else {
  360. Dictionary d;
  361. d["name"] = name;
  362. d["value"] = value;
  363. constants.push_back(d);
  364. }
  365. }
  366. api_dump["global_constants"] = constants;
  367. Array enums;
  368. for (const KeyValue<String, List<Pair<String, int64_t>>> &E : enum_list) {
  369. Dictionary d1;
  370. d1["name"] = E.key;
  371. Array values;
  372. for (const Pair<String, int64_t> &F : E.value) {
  373. Dictionary d2;
  374. d2["name"] = F.first;
  375. d2["value"] = F.second;
  376. values.push_back(d2);
  377. }
  378. d1["values"] = values;
  379. enums.push_back(d1);
  380. }
  381. api_dump["global_enums"] = enums;
  382. }
  383. {
  384. Array utility_funcs;
  385. List<StringName> utility_func_names;
  386. Variant::get_utility_function_list(&utility_func_names);
  387. for (const StringName &name : utility_func_names) {
  388. Dictionary func;
  389. func["name"] = String(name);
  390. if (Variant::has_utility_function_return_value(name)) {
  391. Variant::Type rt = Variant::get_utility_function_return_type(name);
  392. func["return_type"] = rt == Variant::NIL ? String("Variant") : Variant::get_type_name(rt);
  393. }
  394. switch (Variant::get_utility_function_type(name)) {
  395. case Variant::UTILITY_FUNC_TYPE_MATH:
  396. func["category"] = "math";
  397. break;
  398. case Variant::UTILITY_FUNC_TYPE_RANDOM:
  399. func["category"] = "random";
  400. break;
  401. case Variant::UTILITY_FUNC_TYPE_GENERAL:
  402. func["category"] = "general";
  403. break;
  404. }
  405. bool vararg = Variant::is_utility_function_vararg(name);
  406. func["is_vararg"] = Variant::is_utility_function_vararg(name);
  407. func["hash"] = Variant::get_utility_function_hash(name);
  408. Array arguments;
  409. int argcount = Variant::get_utility_function_argument_count(name);
  410. for (int i = 0; i < argcount; i++) {
  411. Dictionary arg;
  412. String argname = vararg ? "arg" + itos(i + 1) : Variant::get_utility_function_argument_name(name, i);
  413. arg["name"] = argname;
  414. arg["type"] = get_builtin_or_variant_type_name(Variant::get_utility_function_argument_type(name, i));
  415. //no default value support in utility functions
  416. arguments.push_back(arg);
  417. }
  418. if (arguments.size()) {
  419. func["arguments"] = arguments;
  420. }
  421. utility_funcs.push_back(func);
  422. }
  423. api_dump["utility_functions"] = utility_funcs;
  424. }
  425. {
  426. // builtin types
  427. Array builtins;
  428. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  429. if (i == Variant::OBJECT) {
  430. continue;
  431. }
  432. Variant::Type type = Variant::Type(i);
  433. Dictionary d;
  434. d["name"] = Variant::get_type_name(type);
  435. if (Variant::has_indexing(type)) {
  436. d["indexing_return_type"] = get_builtin_or_variant_type_name(Variant::get_indexed_element_type(type));
  437. }
  438. d["is_keyed"] = Variant::is_keyed(type);
  439. {
  440. //members
  441. Array members;
  442. List<StringName> member_names;
  443. Variant::get_member_list(type, &member_names);
  444. for (const StringName &member_name : member_names) {
  445. Dictionary d2;
  446. d2["name"] = String(member_name);
  447. d2["type"] = get_builtin_or_variant_type_name(Variant::get_member_type(type, member_name));
  448. members.push_back(d2);
  449. }
  450. if (members.size()) {
  451. d["members"] = members;
  452. }
  453. }
  454. {
  455. //constants
  456. Array constants;
  457. List<StringName> constant_names;
  458. Variant::get_constants_for_type(type, &constant_names);
  459. for (const StringName &constant_name : constant_names) {
  460. Dictionary d2;
  461. d2["name"] = String(constant_name);
  462. Variant constant = Variant::get_constant_value(type, constant_name);
  463. d2["type"] = get_builtin_or_variant_type_name(constant.get_type());
  464. d2["value"] = constant.get_construct_string();
  465. constants.push_back(d2);
  466. }
  467. if (constants.size()) {
  468. d["constants"] = constants;
  469. }
  470. }
  471. {
  472. //enums
  473. Array enums;
  474. List<StringName> enum_names;
  475. Variant::get_enums_for_type(type, &enum_names);
  476. for (const StringName &enum_name : enum_names) {
  477. Dictionary enum_dict;
  478. enum_dict["name"] = String(enum_name);
  479. List<StringName> enumeration_names;
  480. Variant::get_enumerations_for_enum(type, enum_name, &enumeration_names);
  481. Array values;
  482. for (const StringName &enumeration : enumeration_names) {
  483. Dictionary values_dict;
  484. values_dict["name"] = String(enumeration);
  485. values_dict["value"] = Variant::get_enum_value(type, enum_name, enumeration);
  486. values.push_back(values_dict);
  487. }
  488. if (values.size()) {
  489. enum_dict["values"] = values;
  490. }
  491. enums.push_back(enum_dict);
  492. }
  493. if (enums.size()) {
  494. d["enums"] = enums;
  495. }
  496. }
  497. {
  498. //operators
  499. Array operators;
  500. for (int j = 0; j < Variant::VARIANT_MAX; j++) {
  501. for (int k = 0; k < Variant::OP_MAX; k++) {
  502. Variant::Type rt = Variant::get_operator_return_type(Variant::Operator(k), type, Variant::Type(j));
  503. if (rt != Variant::NIL) {
  504. Dictionary d2;
  505. d2["name"] = Variant::get_operator_name(Variant::Operator(k));
  506. if (k != Variant::OP_NEGATE && k != Variant::OP_POSITIVE && k != Variant::OP_NOT && k != Variant::OP_BIT_NEGATE) {
  507. d2["right_type"] = get_builtin_or_variant_type_name(Variant::Type(j));
  508. }
  509. d2["return_type"] = get_builtin_or_variant_type_name(Variant::get_operator_return_type(Variant::Operator(k), type, Variant::Type(j)));
  510. operators.push_back(d2);
  511. }
  512. }
  513. }
  514. if (operators.size()) {
  515. d["operators"] = operators;
  516. }
  517. }
  518. {
  519. //methods
  520. Array methods;
  521. List<StringName> method_names;
  522. Variant::get_builtin_method_list(type, &method_names);
  523. for (const StringName &method_name : method_names) {
  524. Dictionary d2;
  525. d2["name"] = String(method_name);
  526. if (Variant::has_builtin_method_return_value(type, method_name)) {
  527. Variant::Type ret_type = Variant::get_builtin_method_return_type(type, method_name);
  528. d2["return_type"] = ret_type == Variant::NIL ? String("Variant") : Variant::get_type_name(ret_type);
  529. }
  530. d2["is_vararg"] = Variant::is_builtin_method_vararg(type, method_name);
  531. d2["is_const"] = Variant::is_builtin_method_const(type, method_name);
  532. d2["is_static"] = Variant::is_builtin_method_static(type, method_name);
  533. d2["hash"] = Variant::get_builtin_method_hash(type, method_name);
  534. Vector<Variant> default_args = Variant::get_builtin_method_default_arguments(type, method_name);
  535. Array arguments;
  536. int argcount = Variant::get_builtin_method_argument_count(type, method_name);
  537. for (int j = 0; j < argcount; j++) {
  538. Dictionary d3;
  539. d3["name"] = Variant::get_builtin_method_argument_name(type, method_name, j);
  540. d3["type"] = get_builtin_or_variant_type_name(Variant::get_builtin_method_argument_type(type, method_name, j));
  541. if (j >= (argcount - default_args.size())) {
  542. int dargidx = j - (argcount - default_args.size());
  543. d3["default_value"] = default_args[dargidx].get_construct_string();
  544. }
  545. arguments.push_back(d3);
  546. }
  547. if (arguments.size()) {
  548. d2["arguments"] = arguments;
  549. }
  550. methods.push_back(d2);
  551. }
  552. if (methods.size()) {
  553. d["methods"] = methods;
  554. }
  555. }
  556. {
  557. //constructors
  558. Array constructors;
  559. for (int j = 0; j < Variant::get_constructor_count(type); j++) {
  560. Dictionary d2;
  561. d2["index"] = j;
  562. Array arguments;
  563. int argcount = Variant::get_constructor_argument_count(type, j);
  564. for (int k = 0; k < argcount; k++) {
  565. Dictionary d3;
  566. d3["name"] = Variant::get_constructor_argument_name(type, j, k);
  567. d3["type"] = get_builtin_or_variant_type_name(Variant::get_constructor_argument_type(type, j, k));
  568. arguments.push_back(d3);
  569. }
  570. if (arguments.size()) {
  571. d2["arguments"] = arguments;
  572. }
  573. constructors.push_back(d2);
  574. }
  575. if (constructors.size()) {
  576. d["constructors"] = constructors;
  577. }
  578. }
  579. {
  580. //destructor
  581. d["has_destructor"] = Variant::has_destructor(type);
  582. }
  583. builtins.push_back(d);
  584. }
  585. api_dump["builtin_classes"] = builtins;
  586. }
  587. {
  588. // classes
  589. Array classes;
  590. List<StringName> class_list;
  591. ClassDB::get_class_list(&class_list);
  592. class_list.sort_custom<StringName::AlphCompare>();
  593. for (const StringName &class_name : class_list) {
  594. Dictionary d;
  595. d["name"] = String(class_name);
  596. d["is_refcounted"] = ClassDB::is_parent_class(class_name, "RefCounted");
  597. d["is_instantiable"] = ClassDB::can_instantiate(class_name);
  598. StringName parent_class = ClassDB::get_parent_class(class_name);
  599. if (parent_class != StringName()) {
  600. d["inherits"] = String(parent_class);
  601. }
  602. {
  603. ClassDB::APIType api = ClassDB::get_api_type(class_name);
  604. static const char *api_type[5] = { "core", "editor", "extension", "editor_extension" };
  605. d["api_type"] = api_type[api];
  606. }
  607. {
  608. //constants
  609. Array constants;
  610. List<String> constant_list;
  611. ClassDB::get_integer_constant_list(class_name, &constant_list, true);
  612. for (const String &F : constant_list) {
  613. StringName enum_name = ClassDB::get_integer_constant_enum(class_name, F);
  614. if (enum_name != StringName()) {
  615. continue; //enums will be handled on their own
  616. }
  617. Dictionary d2;
  618. d2["name"] = String(F);
  619. d2["value"] = ClassDB::get_integer_constant(class_name, F);
  620. constants.push_back(d2);
  621. }
  622. if (constants.size()) {
  623. d["constants"] = constants;
  624. }
  625. }
  626. {
  627. //enum
  628. Array enums;
  629. List<StringName> enum_list;
  630. ClassDB::get_enum_list(class_name, &enum_list, true);
  631. for (const StringName &F : enum_list) {
  632. Dictionary d2;
  633. d2["name"] = String(F);
  634. d2["is_bitfield"] = ClassDB::is_enum_bitfield(class_name, F);
  635. Array values;
  636. List<StringName> enum_constant_list;
  637. ClassDB::get_enum_constants(class_name, F, &enum_constant_list, true);
  638. for (List<StringName>::Element *G = enum_constant_list.front(); G; G = G->next()) {
  639. Dictionary d3;
  640. d3["name"] = String(G->get());
  641. d3["value"] = ClassDB::get_integer_constant(class_name, G->get());
  642. values.push_back(d3);
  643. }
  644. d2["values"] = values;
  645. enums.push_back(d2);
  646. }
  647. if (enums.size()) {
  648. d["enums"] = enums;
  649. }
  650. }
  651. {
  652. //methods
  653. Array methods;
  654. List<MethodInfo> method_list;
  655. ClassDB::get_method_list(class_name, &method_list, true);
  656. for (const MethodInfo &F : method_list) {
  657. StringName method_name = F.name;
  658. if ((F.flags & METHOD_FLAG_VIRTUAL) && !(F.flags & METHOD_FLAG_OBJECT_CORE)) {
  659. //virtual method
  660. const MethodInfo &mi = F;
  661. Dictionary d2;
  662. d2["name"] = String(method_name);
  663. d2["is_const"] = (F.flags & METHOD_FLAG_CONST) ? true : false;
  664. d2["is_static"] = (F.flags & METHOD_FLAG_STATIC) ? true : false;
  665. d2["is_vararg"] = false;
  666. d2["is_virtual"] = true;
  667. // virtual functions have no hash since no MethodBind is involved
  668. bool has_return = mi.return_val.type != Variant::NIL || (mi.return_val.usage & PROPERTY_USAGE_NIL_IS_VARIANT);
  669. Array arguments;
  670. for (int i = (has_return ? -1 : 0); i < mi.arguments.size(); i++) {
  671. PropertyInfo pinfo = i == -1 ? mi.return_val : mi.arguments[i];
  672. Dictionary d3;
  673. if (i >= 0) {
  674. d3["name"] = pinfo.name;
  675. }
  676. d3["type"] = get_property_info_type_name(pinfo);
  677. if (i == -1) {
  678. d2["return_value"] = d3;
  679. } else {
  680. arguments.push_back(d3);
  681. }
  682. }
  683. if (arguments.size()) {
  684. d2["arguments"] = arguments;
  685. }
  686. methods.push_back(d2);
  687. } else if (F.name.begins_with("_")) {
  688. //hidden method, ignore
  689. } else {
  690. Dictionary d2;
  691. d2["name"] = String(method_name);
  692. MethodBind *method = ClassDB::get_method(class_name, method_name);
  693. if (!method) {
  694. continue;
  695. }
  696. d2["is_const"] = method->is_const();
  697. d2["is_vararg"] = method->is_vararg();
  698. d2["is_static"] = method->is_static();
  699. d2["is_virtual"] = false;
  700. d2["hash"] = method->get_hash();
  701. Vector<Variant> default_args = method->get_default_arguments();
  702. Array arguments;
  703. for (int i = (method->has_return() ? -1 : 0); i < method->get_argument_count(); i++) {
  704. PropertyInfo pinfo = i == -1 ? method->get_return_info() : method->get_argument_info(i);
  705. Dictionary d3;
  706. if (i >= 0) {
  707. d3["name"] = pinfo.name;
  708. }
  709. d3["type"] = get_property_info_type_name(pinfo);
  710. if (method->get_argument_meta(i) > 0) {
  711. static const char *argmeta[11] = { "none", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float", "double" };
  712. d3["meta"] = argmeta[method->get_argument_meta(i)];
  713. }
  714. if (i >= 0 && i >= (method->get_argument_count() - default_args.size())) {
  715. int dargidx = i - (method->get_argument_count() - default_args.size());
  716. d3["default_value"] = default_args[dargidx].get_construct_string();
  717. }
  718. if (i == -1) {
  719. d2["return_value"] = d3;
  720. } else {
  721. arguments.push_back(d3);
  722. }
  723. }
  724. if (arguments.size()) {
  725. d2["arguments"] = arguments;
  726. }
  727. methods.push_back(d2);
  728. }
  729. }
  730. if (methods.size()) {
  731. d["methods"] = methods;
  732. }
  733. }
  734. {
  735. //signals
  736. Array signals;
  737. List<MethodInfo> signal_list;
  738. ClassDB::get_signal_list(class_name, &signal_list, true);
  739. for (const MethodInfo &F : signal_list) {
  740. StringName signal_name = F.name;
  741. Dictionary d2;
  742. d2["name"] = String(signal_name);
  743. Array arguments;
  744. for (int i = 0; i < F.arguments.size(); i++) {
  745. Dictionary d3;
  746. d3["name"] = F.arguments[i].name;
  747. d3["type"] = get_property_info_type_name(F.arguments[i]);
  748. arguments.push_back(d3);
  749. }
  750. if (arguments.size()) {
  751. d2["arguments"] = arguments;
  752. }
  753. signals.push_back(d2);
  754. }
  755. if (signals.size()) {
  756. d["signals"] = signals;
  757. }
  758. }
  759. {
  760. //properties
  761. Array properties;
  762. List<PropertyInfo> property_list;
  763. ClassDB::get_property_list(class_name, &property_list, true);
  764. for (const PropertyInfo &F : property_list) {
  765. 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)) {
  766. continue; //not real properties
  767. }
  768. if (F.name.begins_with("_")) {
  769. continue; //hidden property
  770. }
  771. if (F.name.find("/") >= 0) {
  772. // Ignore properties with '/' (slash) in the name. These are only meant for use in the inspector.
  773. continue;
  774. }
  775. StringName property_name = F.name;
  776. Dictionary d2;
  777. d2["type"] = get_property_info_type_name(F);
  778. d2["name"] = String(property_name);
  779. StringName setter = ClassDB::get_property_setter(class_name, F.name);
  780. if (!(setter == "")) {
  781. d2["setter"] = setter;
  782. }
  783. StringName getter = ClassDB::get_property_getter(class_name, F.name);
  784. if (!(getter == "")) {
  785. d2["getter"] = getter;
  786. }
  787. int index = ClassDB::get_property_index(class_name, F.name);
  788. if (index != -1) {
  789. d2["index"] = index;
  790. }
  791. properties.push_back(d2);
  792. }
  793. if (properties.size()) {
  794. d["properties"] = properties;
  795. }
  796. }
  797. classes.push_back(d);
  798. }
  799. api_dump["classes"] = classes;
  800. }
  801. {
  802. // singletons
  803. Array singletons;
  804. List<Engine::Singleton> singleton_list;
  805. Engine::get_singleton()->get_singletons(&singleton_list);
  806. for (const Engine::Singleton &s : singleton_list) {
  807. Dictionary d;
  808. d["name"] = s.name;
  809. if (s.class_name != StringName()) {
  810. d["type"] = String(s.class_name);
  811. } else {
  812. d["type"] = String(s.ptr->get_class());
  813. }
  814. singletons.push_back(d);
  815. }
  816. if (singletons.size()) {
  817. api_dump["singletons"] = singletons;
  818. }
  819. }
  820. {
  821. Array native_structures;
  822. List<StringName> native_structs;
  823. ClassDB::get_native_struct_list(&native_structs);
  824. native_structs.sort_custom<StringName::AlphCompare>();
  825. for (const StringName &E : native_structs) {
  826. String code = ClassDB::get_native_struct_code(E);
  827. Dictionary d;
  828. d["name"] = String(E);
  829. d["format"] = code;
  830. native_structures.push_back(d);
  831. }
  832. api_dump["native_structures"] = native_structures;
  833. }
  834. return api_dump;
  835. }
  836. void GDExtensionAPIDump::generate_extension_json_file(const String &p_path) {
  837. Dictionary api = generate_extension_api();
  838. Ref<JSON> json;
  839. json.instantiate();
  840. String text = json->stringify(api, "\t", false) + "\n";
  841. Ref<FileAccess> fa = FileAccess::open(p_path, FileAccess::WRITE);
  842. fa->store_string(text);
  843. }
  844. #endif // TOOLS_ENABLED