gdnative_interface.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. /*************************************************************************/
  2. /* gdnative_interface.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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 "gdnative_interface.h"
  31. #include "core/config/engine.h"
  32. #include "core/object/class_db.h"
  33. #include "core/os/memory.h"
  34. #include "core/variant/variant.h"
  35. #include "core/version.h"
  36. // Memory Functions
  37. static void *gdnative_alloc(size_t p_size) {
  38. return memalloc(p_size);
  39. }
  40. static void *gdnative_realloc(void *p_mem, size_t p_size) {
  41. return memrealloc(p_mem, p_size);
  42. }
  43. static void gdnative_free(void *p_mem) {
  44. memfree(p_mem);
  45. }
  46. // Helper print functions.
  47. static void gdnative_print_error(const char *p_description, const char *p_function, const char *p_file, int32_t p_line) {
  48. _err_print_error(p_function, p_file, p_line, p_description, ERR_HANDLER_ERROR);
  49. }
  50. static void gdnative_print_warning(const char *p_description, const char *p_function, const char *p_file, int32_t p_line) {
  51. _err_print_error(p_function, p_file, p_line, p_description, ERR_HANDLER_WARNING);
  52. }
  53. static void gdnative_print_script_error(const char *p_description, const char *p_function, const char *p_file, int32_t p_line) {
  54. _err_print_error(p_function, p_file, p_line, p_description, ERR_HANDLER_SCRIPT);
  55. }
  56. // Variant functions
  57. static void gdnative_variant_new_copy(GDNativeVariantPtr r_dest, const GDNativeVariantPtr p_src) {
  58. memnew_placement(reinterpret_cast<Variant *>(r_dest), Variant(*reinterpret_cast<Variant *>(p_src)));
  59. }
  60. static void gdnative_variant_new_nil(GDNativeVariantPtr r_dest) {
  61. memnew_placement(reinterpret_cast<Variant *>(r_dest), Variant);
  62. }
  63. static void gdnative_variant_destroy(GDNativeVariantPtr p_self) {
  64. reinterpret_cast<Variant *>(p_self)->~Variant();
  65. }
  66. // variant type
  67. #define memnew_placement_custom(m_placement, m_class, m_constr) _post_initialize(new (m_placement, sizeof(m_class), "") m_constr)
  68. static void gdnative_variant_call(GDNativeVariantPtr p_self, const GDNativeStringNamePtr p_method, const GDNativeVariantPtr *p_args, const GDNativeInt p_argcount, GDNativeVariantPtr r_return, GDNativeCallError *r_error) {
  69. Variant *self = (Variant *)p_self;
  70. const StringName *method = (const StringName *)p_method;
  71. const Variant **args = (const Variant **)p_args;
  72. Variant ret;
  73. Callable::CallError error;
  74. self->call(*method, args, p_argcount, ret, error);
  75. memnew_placement_custom(r_return, Variant, Variant(ret));
  76. if (r_error) {
  77. r_error->error = (GDNativeCallErrorType)(error.error);
  78. r_error->argument = error.argument;
  79. r_error->expected = error.expected;
  80. }
  81. }
  82. static void gdnative_variant_call_static(GDNativeVariantType p_type, const GDNativeStringNamePtr p_method, const GDNativeVariantPtr *p_args, const GDNativeInt p_argcount, GDNativeVariantPtr r_return, GDNativeCallError *r_error) {
  83. Variant::Type type = (Variant::Type)p_type;
  84. const StringName *method = (const StringName *)p_method;
  85. const Variant **args = (const Variant **)p_args;
  86. Variant ret;
  87. Callable::CallError error;
  88. Variant::call_static(type, *method, args, p_argcount, ret, error);
  89. memnew_placement_custom(r_return, Variant, Variant(ret));
  90. if (r_error) {
  91. r_error->error = (GDNativeCallErrorType)error.error;
  92. r_error->argument = error.argument;
  93. r_error->expected = error.expected;
  94. }
  95. }
  96. static void gdnative_variant_evaluate(GDNativeVariantOperator p_op, const GDNativeVariantPtr p_a, const GDNativeVariantPtr p_b, GDNativeVariantPtr r_return, GDNativeBool *r_valid) {
  97. Variant::Operator op = (Variant::Operator)p_op;
  98. const Variant *a = (const Variant *)p_a;
  99. const Variant *b = (const Variant *)p_b;
  100. Variant *ret = (Variant *)r_return;
  101. bool valid;
  102. Variant::evaluate(op, *a, *b, *ret, valid);
  103. *r_valid = valid;
  104. }
  105. static void gdnative_variant_set(GDNativeVariantPtr p_self, const GDNativeVariantPtr p_key, const GDNativeVariantPtr p_value, GDNativeBool *r_valid) {
  106. Variant *self = (Variant *)p_self;
  107. const Variant *key = (const Variant *)p_key;
  108. const Variant *value = (const Variant *)p_value;
  109. bool valid;
  110. self->set(*key, *value, &valid);
  111. *r_valid = valid;
  112. }
  113. static void gdnative_variant_set_named(GDNativeVariantPtr p_self, const GDNativeStringNamePtr p_key, const GDNativeVariantPtr p_value, GDNativeBool *r_valid) {
  114. Variant *self = (Variant *)p_self;
  115. const StringName *key = (const StringName *)p_key;
  116. const Variant *value = (const Variant *)p_value;
  117. bool valid;
  118. self->set_named(*key, *value, valid);
  119. *r_valid = valid;
  120. }
  121. static void gdnative_variant_set_keyed(GDNativeVariantPtr p_self, const GDNativeVariantPtr p_key, const GDNativeVariantPtr p_value, GDNativeBool *r_valid) {
  122. Variant *self = (Variant *)p_self;
  123. const Variant *key = (const Variant *)p_key;
  124. const Variant *value = (const Variant *)p_value;
  125. bool valid;
  126. self->set_keyed(*key, *value, valid);
  127. *r_valid = valid;
  128. }
  129. static void gdnative_variant_set_indexed(GDNativeVariantPtr p_self, GDNativeInt p_index, const GDNativeVariantPtr p_value, GDNativeBool *r_valid, GDNativeBool *r_oob) {
  130. Variant *self = (Variant *)p_self;
  131. const Variant *value = (const Variant *)p_value;
  132. bool valid;
  133. bool oob;
  134. self->set_indexed(p_index, value, valid, oob);
  135. *r_valid = valid;
  136. *r_oob = oob;
  137. }
  138. static void gdnative_variant_get(const GDNativeVariantPtr p_self, const GDNativeVariantPtr p_key, GDNativeVariantPtr r_ret, GDNativeBool *r_valid) {
  139. const Variant *self = (const Variant *)p_self;
  140. const Variant *key = (const Variant *)p_key;
  141. bool valid;
  142. memnew_placement_custom(r_ret, Variant, Variant(self->get(*key, &valid)));
  143. *r_valid = valid;
  144. }
  145. static void gdnative_variant_get_named(const GDNativeVariantPtr p_self, const GDNativeStringNamePtr p_key, GDNativeVariantPtr r_ret, GDNativeBool *r_valid) {
  146. const Variant *self = (const Variant *)p_self;
  147. const StringName *key = (const StringName *)p_key;
  148. bool valid;
  149. memnew_placement_custom(r_ret, Variant, Variant(self->get_named(*key, valid)));
  150. *r_valid = valid;
  151. }
  152. static void gdnative_variant_get_keyed(const GDNativeVariantPtr p_self, const GDNativeVariantPtr p_key, GDNativeVariantPtr r_ret, GDNativeBool *r_valid) {
  153. const Variant *self = (const Variant *)p_self;
  154. const Variant *key = (const Variant *)p_key;
  155. bool valid;
  156. memnew_placement_custom(r_ret, Variant, Variant(self->get_keyed(*key, valid)));
  157. *r_valid = valid;
  158. }
  159. static void gdnative_variant_get_indexed(const GDNativeVariantPtr p_self, GDNativeInt p_index, GDNativeVariantPtr r_ret, GDNativeBool *r_valid, GDNativeBool *r_oob) {
  160. const Variant *self = (const Variant *)p_self;
  161. bool valid;
  162. bool oob;
  163. memnew_placement_custom(r_ret, Variant, Variant(self->get_indexed(p_index, valid, oob)));
  164. *r_valid = valid;
  165. *r_oob = oob;
  166. }
  167. /// Iteration.
  168. static GDNativeBool gdnative_variant_iter_init(const GDNativeVariantPtr p_self, GDNativeVariantPtr r_iter, GDNativeBool *r_valid) {
  169. const Variant *self = (const Variant *)p_self;
  170. Variant *iter = (Variant *)r_iter;
  171. bool valid;
  172. bool ret = self->iter_init(*iter, valid);
  173. *r_valid = valid;
  174. return ret;
  175. }
  176. static GDNativeBool gdnative_variant_iter_next(const GDNativeVariantPtr p_self, GDNativeVariantPtr r_iter, GDNativeBool *r_valid) {
  177. const Variant *self = (const Variant *)p_self;
  178. Variant *iter = (Variant *)r_iter;
  179. bool valid;
  180. bool ret = self->iter_next(*iter, valid);
  181. *r_valid = valid;
  182. return ret;
  183. }
  184. static void gdnative_variant_iter_get(const GDNativeVariantPtr p_self, GDNativeVariantPtr r_iter, GDNativeVariantPtr r_ret, GDNativeBool *r_valid) {
  185. const Variant *self = (const Variant *)p_self;
  186. Variant *iter = (Variant *)r_iter;
  187. bool valid;
  188. memnew_placement_custom(r_ret, Variant, Variant(self->iter_next(*iter, valid)));
  189. *r_valid = valid;
  190. }
  191. /// Variant functions.
  192. static GDNativeBool gdnative_variant_hash_compare(const GDNativeVariantPtr p_self, const GDNativeVariantPtr p_other) {
  193. const Variant *self = (const Variant *)p_self;
  194. const Variant *other = (const Variant *)p_other;
  195. return self->hash_compare(*other);
  196. }
  197. static GDNativeBool gdnative_variant_booleanize(const GDNativeVariantPtr p_self) {
  198. const Variant *self = (const Variant *)p_self;
  199. return self->booleanize();
  200. }
  201. static void gdnative_variant_blend(const GDNativeVariantPtr p_a, const GDNativeVariantPtr p_b, float p_c, GDNativeVariantPtr r_dst) {
  202. const Variant *a = (const Variant *)p_a;
  203. const Variant *b = (const Variant *)p_b;
  204. memnew_placement(r_dst, Variant);
  205. Variant::blend(*a, *b, p_c, *(Variant *)r_dst);
  206. }
  207. static void gdnative_variant_interpolate(const GDNativeVariantPtr p_a, const GDNativeVariantPtr p_b, float p_c, GDNativeVariantPtr r_dst) {
  208. const Variant *a = (const Variant *)p_a;
  209. const Variant *b = (const Variant *)p_b;
  210. memnew_placement(r_dst, Variant);
  211. Variant::interpolate(*a, *b, p_c, *(Variant *)r_dst);
  212. }
  213. static void gdnative_variant_duplicate(const GDNativeVariantPtr p_self, GDNativeVariantPtr r_ret, GDNativeBool p_deep) {
  214. const Variant *self = (const Variant *)p_self;
  215. memnew_placement_custom(r_ret, Variant, Variant(self->duplicate(p_deep)));
  216. }
  217. static void gdnative_variant_stringify(const GDNativeVariantPtr p_self, GDNativeStringPtr r_ret) {
  218. const Variant *self = (const Variant *)p_self;
  219. memnew_placement_custom(r_ret, String, String(*self));
  220. }
  221. static GDNativeVariantType gdnative_variant_get_type(const GDNativeVariantPtr p_self) {
  222. const Variant *self = (const Variant *)p_self;
  223. return (GDNativeVariantType)self->get_type();
  224. }
  225. static GDNativeBool gdnative_variant_has_method(const GDNativeVariantPtr p_self, const GDNativeStringNamePtr p_method) {
  226. const Variant *self = (const Variant *)p_self;
  227. const StringName *method = (const StringName *)p_method;
  228. return self->has_method(*method);
  229. }
  230. static GDNativeBool gdnative_variant_has_member(GDNativeVariantType p_type, const GDNativeStringNamePtr p_member) {
  231. return Variant::has_member((Variant::Type)p_type, *((const StringName *)p_member));
  232. }
  233. static GDNativeBool gdnative_variant_has_key(const GDNativeVariantPtr p_self, const GDNativeVariantPtr p_key, GDNativeBool *r_valid) {
  234. const Variant *self = (const Variant *)p_self;
  235. const Variant *key = (const Variant *)p_key;
  236. bool valid;
  237. bool ret = self->has_key(*key, valid);
  238. *r_valid = valid;
  239. return ret;
  240. }
  241. static void gdnative_variant_get_type_name(GDNativeVariantType p_type, GDNativeStringPtr r_ret) {
  242. String name = Variant::get_type_name((Variant::Type)p_type);
  243. memnew_placement_custom(r_ret, String, String(name));
  244. }
  245. static GDNativeBool gdnative_variant_can_convert(GDNativeVariantType p_from, GDNativeVariantType p_to) {
  246. return Variant::can_convert((Variant::Type)p_from, (Variant::Type)p_to);
  247. }
  248. static GDNativeBool gdnative_variant_can_convert_strict(GDNativeVariantType p_from, GDNativeVariantType p_to) {
  249. return Variant::can_convert_strict((Variant::Type)p_from, (Variant::Type)p_to);
  250. }
  251. // Variant interaction.
  252. static GDNativeVariantFromTypeConstructorFunc gdnative_get_variant_from_type_constructor(GDNativeVariantType p_type) {
  253. switch (p_type) {
  254. case GDNATIVE_VARIANT_TYPE_BOOL:
  255. return VariantTypeConstructor<bool>::variant_from_type;
  256. case GDNATIVE_VARIANT_TYPE_INT:
  257. return VariantTypeConstructor<int64_t>::variant_from_type;
  258. case GDNATIVE_VARIANT_TYPE_FLOAT:
  259. return VariantTypeConstructor<double>::variant_from_type;
  260. case GDNATIVE_VARIANT_TYPE_STRING:
  261. return VariantTypeConstructor<String>::variant_from_type;
  262. case GDNATIVE_VARIANT_TYPE_VECTOR2:
  263. return VariantTypeConstructor<Vector2>::variant_from_type;
  264. case GDNATIVE_VARIANT_TYPE_VECTOR2I:
  265. return VariantTypeConstructor<Vector2i>::variant_from_type;
  266. case GDNATIVE_VARIANT_TYPE_RECT2:
  267. return VariantTypeConstructor<Rect2>::variant_from_type;
  268. case GDNATIVE_VARIANT_TYPE_RECT2I:
  269. return VariantTypeConstructor<Rect2i>::variant_from_type;
  270. case GDNATIVE_VARIANT_TYPE_VECTOR3:
  271. return VariantTypeConstructor<Vector3>::variant_from_type;
  272. case GDNATIVE_VARIANT_TYPE_VECTOR3I:
  273. return VariantTypeConstructor<Vector3i>::variant_from_type;
  274. case GDNATIVE_VARIANT_TYPE_TRANSFORM2D:
  275. return VariantTypeConstructor<Transform2D>::variant_from_type;
  276. case GDNATIVE_VARIANT_TYPE_PLANE:
  277. return VariantTypeConstructor<Plane>::variant_from_type;
  278. case GDNATIVE_VARIANT_TYPE_QUATERNION:
  279. return VariantTypeConstructor<Quaternion>::variant_from_type;
  280. case GDNATIVE_VARIANT_TYPE_AABB:
  281. return VariantTypeConstructor<AABB>::variant_from_type;
  282. case GDNATIVE_VARIANT_TYPE_BASIS:
  283. return VariantTypeConstructor<Basis>::variant_from_type;
  284. case GDNATIVE_VARIANT_TYPE_TRANSFORM3D:
  285. return VariantTypeConstructor<Transform3D>::variant_from_type;
  286. case GDNATIVE_VARIANT_TYPE_COLOR:
  287. return VariantTypeConstructor<Color>::variant_from_type;
  288. case GDNATIVE_VARIANT_TYPE_STRING_NAME:
  289. return VariantTypeConstructor<StringName>::variant_from_type;
  290. case GDNATIVE_VARIANT_TYPE_NODE_PATH:
  291. return VariantTypeConstructor<NodePath>::variant_from_type;
  292. case GDNATIVE_VARIANT_TYPE_RID:
  293. return VariantTypeConstructor<RID>::variant_from_type;
  294. case GDNATIVE_VARIANT_TYPE_OBJECT:
  295. return VariantTypeConstructor<Object *>::variant_from_type;
  296. case GDNATIVE_VARIANT_TYPE_CALLABLE:
  297. return VariantTypeConstructor<Callable>::variant_from_type;
  298. case GDNATIVE_VARIANT_TYPE_SIGNAL:
  299. return VariantTypeConstructor<Signal>::variant_from_type;
  300. case GDNATIVE_VARIANT_TYPE_DICTIONARY:
  301. return VariantTypeConstructor<Dictionary>::variant_from_type;
  302. case GDNATIVE_VARIANT_TYPE_ARRAY:
  303. return VariantTypeConstructor<Array>::variant_from_type;
  304. case GDNATIVE_VARIANT_TYPE_PACKED_BYTE_ARRAY:
  305. return VariantTypeConstructor<PackedByteArray>::variant_from_type;
  306. case GDNATIVE_VARIANT_TYPE_PACKED_INT32_ARRAY:
  307. return VariantTypeConstructor<PackedInt32Array>::variant_from_type;
  308. case GDNATIVE_VARIANT_TYPE_PACKED_INT64_ARRAY:
  309. return VariantTypeConstructor<PackedInt64Array>::variant_from_type;
  310. case GDNATIVE_VARIANT_TYPE_PACKED_FLOAT32_ARRAY:
  311. return VariantTypeConstructor<PackedFloat32Array>::variant_from_type;
  312. case GDNATIVE_VARIANT_TYPE_PACKED_FLOAT64_ARRAY:
  313. return VariantTypeConstructor<PackedFloat64Array>::variant_from_type;
  314. case GDNATIVE_VARIANT_TYPE_PACKED_STRING_ARRAY:
  315. return VariantTypeConstructor<PackedStringArray>::variant_from_type;
  316. case GDNATIVE_VARIANT_TYPE_PACKED_VECTOR2_ARRAY:
  317. return VariantTypeConstructor<PackedVector2Array>::variant_from_type;
  318. case GDNATIVE_VARIANT_TYPE_PACKED_VECTOR3_ARRAY:
  319. return VariantTypeConstructor<PackedVector3Array>::variant_from_type;
  320. case GDNATIVE_VARIANT_TYPE_PACKED_COLOR_ARRAY:
  321. return VariantTypeConstructor<PackedColorArray>::variant_from_type;
  322. case GDNATIVE_VARIANT_TYPE_NIL:
  323. case GDNATIVE_VARIANT_TYPE_VARIANT_MAX:
  324. ERR_FAIL_V_MSG(nullptr, "Getting Variant conversion function with invalid type");
  325. }
  326. ERR_FAIL_V_MSG(nullptr, "Getting Variant conversion function with invalid type");
  327. }
  328. static GDNativeTypeFromVariantConstructorFunc gdnative_get_type_from_variant_constructor(GDNativeVariantType p_type) {
  329. switch (p_type) {
  330. case GDNATIVE_VARIANT_TYPE_BOOL:
  331. return VariantTypeConstructor<bool>::type_from_variant;
  332. case GDNATIVE_VARIANT_TYPE_INT:
  333. return VariantTypeConstructor<int64_t>::type_from_variant;
  334. case GDNATIVE_VARIANT_TYPE_FLOAT:
  335. return VariantTypeConstructor<double>::type_from_variant;
  336. case GDNATIVE_VARIANT_TYPE_STRING:
  337. return VariantTypeConstructor<String>::type_from_variant;
  338. case GDNATIVE_VARIANT_TYPE_VECTOR2:
  339. return VariantTypeConstructor<Vector2>::type_from_variant;
  340. case GDNATIVE_VARIANT_TYPE_VECTOR2I:
  341. return VariantTypeConstructor<Vector2i>::type_from_variant;
  342. case GDNATIVE_VARIANT_TYPE_RECT2:
  343. return VariantTypeConstructor<Rect2>::type_from_variant;
  344. case GDNATIVE_VARIANT_TYPE_RECT2I:
  345. return VariantTypeConstructor<Rect2i>::type_from_variant;
  346. case GDNATIVE_VARIANT_TYPE_VECTOR3:
  347. return VariantTypeConstructor<Vector3>::type_from_variant;
  348. case GDNATIVE_VARIANT_TYPE_VECTOR3I:
  349. return VariantTypeConstructor<Vector3i>::type_from_variant;
  350. case GDNATIVE_VARIANT_TYPE_TRANSFORM2D:
  351. return VariantTypeConstructor<Transform2D>::type_from_variant;
  352. case GDNATIVE_VARIANT_TYPE_PLANE:
  353. return VariantTypeConstructor<Plane>::type_from_variant;
  354. case GDNATIVE_VARIANT_TYPE_QUATERNION:
  355. return VariantTypeConstructor<Quaternion>::type_from_variant;
  356. case GDNATIVE_VARIANT_TYPE_AABB:
  357. return VariantTypeConstructor<AABB>::type_from_variant;
  358. case GDNATIVE_VARIANT_TYPE_BASIS:
  359. return VariantTypeConstructor<Basis>::type_from_variant;
  360. case GDNATIVE_VARIANT_TYPE_TRANSFORM3D:
  361. return VariantTypeConstructor<Transform3D>::type_from_variant;
  362. case GDNATIVE_VARIANT_TYPE_COLOR:
  363. return VariantTypeConstructor<Color>::type_from_variant;
  364. case GDNATIVE_VARIANT_TYPE_STRING_NAME:
  365. return VariantTypeConstructor<StringName>::type_from_variant;
  366. case GDNATIVE_VARIANT_TYPE_NODE_PATH:
  367. return VariantTypeConstructor<NodePath>::type_from_variant;
  368. case GDNATIVE_VARIANT_TYPE_RID:
  369. return VariantTypeConstructor<RID>::type_from_variant;
  370. case GDNATIVE_VARIANT_TYPE_OBJECT:
  371. return VariantTypeConstructor<Object *>::type_from_variant;
  372. case GDNATIVE_VARIANT_TYPE_CALLABLE:
  373. return VariantTypeConstructor<Callable>::type_from_variant;
  374. case GDNATIVE_VARIANT_TYPE_SIGNAL:
  375. return VariantTypeConstructor<Signal>::type_from_variant;
  376. case GDNATIVE_VARIANT_TYPE_DICTIONARY:
  377. return VariantTypeConstructor<Dictionary>::type_from_variant;
  378. case GDNATIVE_VARIANT_TYPE_ARRAY:
  379. return VariantTypeConstructor<Array>::type_from_variant;
  380. case GDNATIVE_VARIANT_TYPE_PACKED_BYTE_ARRAY:
  381. return VariantTypeConstructor<PackedByteArray>::type_from_variant;
  382. case GDNATIVE_VARIANT_TYPE_PACKED_INT32_ARRAY:
  383. return VariantTypeConstructor<PackedInt32Array>::type_from_variant;
  384. case GDNATIVE_VARIANT_TYPE_PACKED_INT64_ARRAY:
  385. return VariantTypeConstructor<PackedInt64Array>::type_from_variant;
  386. case GDNATIVE_VARIANT_TYPE_PACKED_FLOAT32_ARRAY:
  387. return VariantTypeConstructor<PackedFloat32Array>::type_from_variant;
  388. case GDNATIVE_VARIANT_TYPE_PACKED_FLOAT64_ARRAY:
  389. return VariantTypeConstructor<PackedFloat64Array>::type_from_variant;
  390. case GDNATIVE_VARIANT_TYPE_PACKED_STRING_ARRAY:
  391. return VariantTypeConstructor<PackedStringArray>::type_from_variant;
  392. case GDNATIVE_VARIANT_TYPE_PACKED_VECTOR2_ARRAY:
  393. return VariantTypeConstructor<PackedVector2Array>::type_from_variant;
  394. case GDNATIVE_VARIANT_TYPE_PACKED_VECTOR3_ARRAY:
  395. return VariantTypeConstructor<PackedVector3Array>::type_from_variant;
  396. case GDNATIVE_VARIANT_TYPE_PACKED_COLOR_ARRAY:
  397. return VariantTypeConstructor<PackedColorArray>::type_from_variant;
  398. case GDNATIVE_VARIANT_TYPE_NIL:
  399. case GDNATIVE_VARIANT_TYPE_VARIANT_MAX:
  400. ERR_FAIL_V_MSG(nullptr, "Getting Variant conversion function with invalid type");
  401. }
  402. ERR_FAIL_V_MSG(nullptr, "Getting Variant conversion function with invalid type");
  403. }
  404. // ptrcalls
  405. static GDNativePtrOperatorEvaluator gdnative_variant_get_ptr_operator_evaluator(GDNativeVariantOperator p_operator, GDNativeVariantType p_type_a, GDNativeVariantType p_type_b) {
  406. return (GDNativePtrOperatorEvaluator)Variant::get_ptr_operator_evaluator(Variant::Operator(p_operator), Variant::Type(p_type_a), Variant::Type(p_type_b));
  407. }
  408. static GDNativePtrBuiltInMethod gdnative_variant_get_ptr_builtin_method(GDNativeVariantType p_type, const char *p_method, GDNativeInt p_hash) {
  409. StringName method = p_method;
  410. uint32_t hash = Variant::get_builtin_method_hash(Variant::Type(p_type), method);
  411. if (hash != p_hash) {
  412. ERR_PRINT_ONCE("Error getting method " + String(method) + ", hash mismatch.");
  413. return nullptr;
  414. }
  415. return (GDNativePtrBuiltInMethod)Variant::get_ptr_builtin_method(Variant::Type(p_type), method);
  416. }
  417. static GDNativePtrConstructor gdnative_variant_get_ptr_constructor(GDNativeVariantType p_type, int32_t p_constructor) {
  418. return (GDNativePtrConstructor)Variant::get_ptr_constructor(Variant::Type(p_type), p_constructor);
  419. }
  420. static GDNativePtrDestructor gdnative_variant_get_ptr_destructor(GDNativeVariantType p_type) {
  421. return (GDNativePtrDestructor)Variant::get_ptr_destructor(Variant::Type(p_type));
  422. }
  423. static void gdnative_variant_construct(GDNativeVariantType p_type, GDNativeVariantPtr p_base, const GDNativeVariantPtr *p_args, int32_t p_argument_count, GDNativeCallError *r_error) {
  424. memnew_placement(p_base, Variant);
  425. Callable::CallError error;
  426. Variant::construct(Variant::Type(p_type), *(Variant *)p_base, (const Variant **)p_args, p_argument_count, error);
  427. if (r_error) {
  428. r_error->error = (GDNativeCallErrorType)(error.error);
  429. r_error->argument = error.argument;
  430. r_error->expected = error.expected;
  431. }
  432. }
  433. static GDNativePtrSetter gdnative_variant_get_ptr_setter(GDNativeVariantType p_type, const char *p_member) {
  434. return (GDNativePtrSetter)Variant::get_member_ptr_setter(Variant::Type(p_type), p_member);
  435. }
  436. static GDNativePtrGetter gdnative_variant_get_ptr_getter(GDNativeVariantType p_type, const char *p_member) {
  437. return (GDNativePtrGetter)Variant::get_member_ptr_getter(Variant::Type(p_type), p_member);
  438. }
  439. static GDNativePtrIndexedSetter gdnative_variant_get_ptr_indexed_setter(GDNativeVariantType p_type) {
  440. return (GDNativePtrIndexedSetter)Variant::get_member_ptr_indexed_setter(Variant::Type(p_type));
  441. }
  442. static GDNativePtrIndexedGetter gdnative_variant_get_ptr_indexed_getter(GDNativeVariantType p_type) {
  443. return (GDNativePtrIndexedGetter)Variant::get_member_ptr_indexed_getter(Variant::Type(p_type));
  444. }
  445. static GDNativePtrKeyedSetter gdnative_variant_get_ptr_keyed_setter(GDNativeVariantType p_type) {
  446. return (GDNativePtrKeyedSetter)Variant::get_member_ptr_keyed_setter(Variant::Type(p_type));
  447. }
  448. static GDNativePtrKeyedGetter gdnative_variant_get_ptr_keyed_getter(GDNativeVariantType p_type) {
  449. return (GDNativePtrKeyedGetter)Variant::get_member_ptr_keyed_getter(Variant::Type(p_type));
  450. }
  451. static GDNativePtrKeyedChecker gdnative_variant_get_ptr_keyed_checker(GDNativeVariantType p_type) {
  452. return (GDNativePtrKeyedChecker)Variant::get_member_ptr_keyed_checker(Variant::Type(p_type));
  453. }
  454. static void gdnative_variant_get_constant_value(GDNativeVariantType p_type, const char *p_constant, GDNativeVariantPtr r_ret) {
  455. memnew_placement_custom(r_ret, Variant, Variant(Variant::get_constant_value(Variant::Type(p_type), p_constant)));
  456. }
  457. static GDNativePtrUtilityFunction gdnative_variant_get_ptr_utility_function(const char *p_function, GDNativeInt p_hash) {
  458. StringName function = p_function;
  459. uint32_t hash = Variant::get_utility_function_hash(function);
  460. if (hash != p_hash) {
  461. ERR_PRINT_ONCE("Error getting utility function " + String(function) + ", hash mismatch.");
  462. return nullptr;
  463. }
  464. return (GDNativePtrUtilityFunction)Variant::get_ptr_utility_function(function);
  465. }
  466. //string helpers
  467. static void gdnative_string_new_with_latin1_chars(GDNativeStringPtr r_dest, const char *p_contents) {
  468. String *dest = (String *)r_dest;
  469. memnew_placement(dest, String);
  470. *dest = String(p_contents);
  471. }
  472. static void gdnative_string_new_with_utf8_chars(GDNativeStringPtr r_dest, const char *p_contents) {
  473. String *dest = (String *)r_dest;
  474. memnew_placement(dest, String);
  475. dest->parse_utf8(p_contents);
  476. }
  477. static void gdnative_string_new_with_utf16_chars(GDNativeStringPtr r_dest, const char16_t *p_contents) {
  478. String *dest = (String *)r_dest;
  479. memnew_placement(dest, String);
  480. dest->parse_utf16(p_contents);
  481. }
  482. static void gdnative_string_new_with_utf32_chars(GDNativeStringPtr r_dest, const char32_t *p_contents) {
  483. String *dest = (String *)r_dest;
  484. memnew_placement(dest, String);
  485. *dest = String((const char32_t *)p_contents);
  486. }
  487. static void gdnative_string_new_with_wide_chars(GDNativeStringPtr r_dest, const wchar_t *p_contents) {
  488. String *dest = (String *)r_dest;
  489. if (sizeof(wchar_t) == 2) {
  490. // wchar_t is 16 bit, parse.
  491. memnew_placement(dest, String);
  492. dest->parse_utf16((const char16_t *)p_contents);
  493. } else {
  494. // wchar_t is 32 bit, copy.
  495. memnew_placement(dest, String);
  496. *dest = String((const char32_t *)p_contents);
  497. }
  498. }
  499. static void gdnative_string_new_with_latin1_chars_and_len(GDNativeStringPtr r_dest, const char *p_contents, const GDNativeInt p_size) {
  500. String *dest = (String *)r_dest;
  501. memnew_placement(dest, String);
  502. *dest = String(p_contents, p_size);
  503. }
  504. static void gdnative_string_new_with_utf8_chars_and_len(GDNativeStringPtr r_dest, const char *p_contents, const GDNativeInt p_size) {
  505. String *dest = (String *)r_dest;
  506. memnew_placement(dest, String);
  507. dest->parse_utf8(p_contents, p_size);
  508. }
  509. static void gdnative_string_new_with_utf16_chars_and_len(GDNativeStringPtr r_dest, const char16_t *p_contents, const GDNativeInt p_size) {
  510. String *dest = (String *)r_dest;
  511. memnew_placement(dest, String);
  512. dest->parse_utf16(p_contents, p_size);
  513. }
  514. static void gdnative_string_new_with_utf32_chars_and_len(GDNativeStringPtr r_dest, const char32_t *p_contents, const GDNativeInt p_size) {
  515. String *dest = (String *)r_dest;
  516. memnew_placement(dest, String);
  517. *dest = String((const char32_t *)p_contents, p_size);
  518. }
  519. static void gdnative_string_new_with_wide_chars_and_len(GDNativeStringPtr r_dest, const wchar_t *p_contents, const GDNativeInt p_size) {
  520. String *dest = (String *)r_dest;
  521. if (sizeof(wchar_t) == 2) {
  522. // wchar_t is 16 bit, parse.
  523. memnew_placement(dest, String);
  524. dest->parse_utf16((const char16_t *)p_contents, p_size);
  525. } else {
  526. // wchar_t is 32 bit, copy.
  527. memnew_placement(dest, String);
  528. *dest = String((const char32_t *)p_contents, p_size);
  529. }
  530. }
  531. static GDNativeInt gdnative_string_to_latin1_chars(const GDNativeStringPtr p_self, char *r_text, GDNativeInt p_max_write_length) {
  532. String *self = (String *)p_self;
  533. CharString cs = self->ascii(true);
  534. GDNativeInt len = cs.length();
  535. if (r_text) {
  536. const char *s_text = cs.ptr();
  537. for (GDNativeInt i = 0; i < MIN(len, p_max_write_length); i++) {
  538. r_text[i] = s_text[i];
  539. }
  540. }
  541. return len;
  542. }
  543. static GDNativeInt gdnative_string_to_utf8_chars(const GDNativeStringPtr p_self, char *r_text, GDNativeInt p_max_write_length) {
  544. String *self = (String *)p_self;
  545. CharString cs = self->utf8();
  546. GDNativeInt len = cs.length();
  547. if (r_text) {
  548. const char *s_text = cs.ptr();
  549. for (GDNativeInt i = 0; i < MIN(len, p_max_write_length); i++) {
  550. r_text[i] = s_text[i];
  551. }
  552. }
  553. return len;
  554. }
  555. static GDNativeInt gdnative_string_to_utf16_chars(const GDNativeStringPtr p_self, char16_t *r_text, GDNativeInt p_max_write_length) {
  556. String *self = (String *)p_self;
  557. Char16String cs = self->utf16();
  558. GDNativeInt len = cs.length();
  559. if (r_text) {
  560. const char16_t *s_text = cs.ptr();
  561. for (GDNativeInt i = 0; i < MIN(len, p_max_write_length); i++) {
  562. r_text[i] = s_text[i];
  563. }
  564. }
  565. return len;
  566. }
  567. static GDNativeInt gdnative_string_to_utf32_chars(const GDNativeStringPtr p_self, char32_t *r_text, GDNativeInt p_max_write_length) {
  568. String *self = (String *)p_self;
  569. GDNativeInt len = self->length();
  570. if (r_text) {
  571. const char32_t *s_text = self->ptr();
  572. for (GDNativeInt i = 0; i < MIN(len, p_max_write_length); i++) {
  573. r_text[i] = s_text[i];
  574. }
  575. }
  576. return len;
  577. }
  578. static GDNativeInt gdnative_string_to_wide_chars(const GDNativeStringPtr p_self, wchar_t *r_text, GDNativeInt p_max_write_length) {
  579. if (sizeof(wchar_t) == 4) {
  580. return gdnative_string_to_utf32_chars(p_self, (char32_t *)r_text, p_max_write_length);
  581. } else {
  582. return gdnative_string_to_utf16_chars(p_self, (char16_t *)r_text, p_max_write_length);
  583. }
  584. }
  585. static char32_t *gdnative_string_operator_index(GDNativeStringPtr p_self, GDNativeInt p_index) {
  586. String *self = (String *)p_self;
  587. ERR_FAIL_INDEX_V(p_index, self->length() + 1, nullptr);
  588. return &self->ptrw()[p_index];
  589. }
  590. static const char32_t *gdnative_string_operator_index_const(const GDNativeStringPtr p_self, GDNativeInt p_index) {
  591. const String *self = (const String *)p_self;
  592. ERR_FAIL_INDEX_V(p_index, self->length() + 1, nullptr);
  593. return &self->ptr()[p_index];
  594. }
  595. /* OBJECT API */
  596. static void gdnative_object_method_bind_ptrcall(GDNativeMethodBindPtr p_method_bind, GDNativeObjectPtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr p_ret) {
  597. MethodBind *mb = (MethodBind *)p_method_bind;
  598. Object *o = (Object *)p_instance;
  599. mb->ptrcall(o, (const void **)p_args, p_ret);
  600. }
  601. static void gdnative_object_destroy(GDNativeObjectPtr p_o) {
  602. memdelete((Object *)p_o);
  603. }
  604. static GDNativeObjectPtr gdnative_global_get_singleton(const char *p_name) {
  605. return (GDNativeObjectPtr)Engine::get_singleton()->get_singleton_object(String(p_name));
  606. }
  607. static void *gdnative_object_get_instance_binding(GDNativeObjectPtr p_instance, void *p_token, const GDNativeInstanceBindingCallbacks *p_callbacks) {
  608. Object *o = (Object *)p_instance;
  609. return o->get_instance_binding(p_token, p_callbacks);
  610. }
  611. static void gdnative_object_set_instance_binding(GDNativeObjectPtr p_instance, void *p_token, void *p_binding, const GDNativeInstanceBindingCallbacks *p_callbacks) {
  612. Object *o = (Object *)p_instance;
  613. o->set_instance_binding(p_token, p_binding, p_callbacks);
  614. }
  615. static GDNativeObjectPtr gdnative_object_get_instance_from_id(GDObjectInstanceID p_instance_id) {
  616. return (GDNativeObjectPtr)ObjectDB::get_instance(ObjectID(p_instance_id));
  617. }
  618. static GDNativeObjectPtr gdnative_object_cast_to(const GDNativeObjectPtr p_object, void *p_class_tag) {
  619. if (!p_object) {
  620. return nullptr;
  621. }
  622. Object *o = (Object *)p_object;
  623. return o->is_class_ptr(p_class_tag) ? (GDNativeObjectPtr)o : (GDNativeObjectPtr) nullptr;
  624. }
  625. static GDObjectInstanceID gdnative_object_get_instance_id(const GDNativeObjectPtr p_object) {
  626. const Object *o = (const Object *)p_object;
  627. return (GDObjectInstanceID)o->get_instance_id();
  628. }
  629. static GDNativeMethodBindPtr gdnative_classdb_get_method_bind(const char *p_classname, const char *p_methodname, GDNativeInt p_hash) {
  630. MethodBind *mb = ClassDB::get_method(StringName(p_classname), StringName(p_methodname));
  631. ERR_FAIL_COND_V(!mb, nullptr);
  632. if (mb->get_hash() != p_hash) {
  633. ERR_PRINT_ONCE("Hash mismatch for method '" + String(p_classname) + "." + String(p_methodname) + "'.");
  634. return nullptr;
  635. }
  636. // MethodBind *mb = ClassDB::get_method("Node", "get_name");
  637. return (GDNativeMethodBindPtr)mb;
  638. }
  639. static GDNativeClassConstructor gdnative_classdb_get_constructor(const char *p_classname) {
  640. ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(StringName(p_classname));
  641. if (class_info) {
  642. return (GDNativeClassConstructor)class_info->creation_func;
  643. }
  644. return nullptr;
  645. }
  646. static void *gdnative_classdb_get_class_tag(const char *p_classname) {
  647. ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(p_classname);
  648. return class_info ? class_info->class_ptr : nullptr;
  649. }
  650. void gdnative_setup_interface(GDNativeInterface *p_interface) {
  651. GDNativeInterface &gdni = *p_interface;
  652. gdni.version_major = VERSION_MAJOR;
  653. gdni.version_minor = VERSION_MINOR;
  654. #if VERSION_PATCH
  655. gdni.version_patch = VERSION_PATCH;
  656. #else
  657. gdni.version_patch = 0;
  658. #endif
  659. gdni.version_string = VERSION_FULL_NAME;
  660. /* GODOT CORE */
  661. gdni.mem_alloc = gdnative_alloc;
  662. gdni.mem_realloc = gdnative_realloc;
  663. gdni.mem_free = gdnative_free;
  664. gdni.print_error = gdnative_print_error;
  665. gdni.print_warning = gdnative_print_warning;
  666. gdni.print_script_error = gdnative_print_script_error;
  667. /* GODOT VARIANT */
  668. // variant general
  669. gdni.variant_new_copy = gdnative_variant_new_copy;
  670. gdni.variant_new_nil = gdnative_variant_new_nil;
  671. gdni.variant_destroy = gdnative_variant_destroy;
  672. gdni.variant_call = gdnative_variant_call;
  673. gdni.variant_call_static = gdnative_variant_call_static;
  674. gdni.variant_evaluate = gdnative_variant_evaluate;
  675. gdni.variant_set = gdnative_variant_set;
  676. gdni.variant_set_named = gdnative_variant_set_named;
  677. gdni.variant_set_keyed = gdnative_variant_set_keyed;
  678. gdni.variant_set_indexed = gdnative_variant_set_indexed;
  679. gdni.variant_get = gdnative_variant_get;
  680. gdni.variant_get_named = gdnative_variant_get_named;
  681. gdni.variant_get_keyed = gdnative_variant_get_keyed;
  682. gdni.variant_get_indexed = gdnative_variant_get_indexed;
  683. gdni.variant_iter_init = gdnative_variant_iter_init;
  684. gdni.variant_iter_next = gdnative_variant_iter_next;
  685. gdni.variant_iter_get = gdnative_variant_iter_get;
  686. gdni.variant_hash_compare = gdnative_variant_hash_compare;
  687. gdni.variant_booleanize = gdnative_variant_booleanize;
  688. gdni.variant_blend = gdnative_variant_blend;
  689. gdni.variant_interpolate = gdnative_variant_interpolate;
  690. gdni.variant_duplicate = gdnative_variant_duplicate;
  691. gdni.variant_stringify = gdnative_variant_stringify;
  692. gdni.variant_get_type = gdnative_variant_get_type;
  693. gdni.variant_has_method = gdnative_variant_has_method;
  694. gdni.variant_has_member = gdnative_variant_has_member;
  695. gdni.variant_has_key = gdnative_variant_has_key;
  696. gdni.variant_get_type_name = gdnative_variant_get_type_name;
  697. gdni.variant_can_convert = gdnative_variant_can_convert;
  698. gdni.variant_can_convert_strict = gdnative_variant_can_convert_strict;
  699. gdni.get_variant_from_type_constructor = gdnative_get_variant_from_type_constructor;
  700. gdni.get_variant_to_type_constructor = gdnative_get_type_from_variant_constructor;
  701. // ptrcalls.
  702. gdni.variant_get_ptr_operator_evaluator = gdnative_variant_get_ptr_operator_evaluator;
  703. gdni.variant_get_ptr_builtin_method = gdnative_variant_get_ptr_builtin_method;
  704. gdni.variant_get_ptr_constructor = gdnative_variant_get_ptr_constructor;
  705. gdni.variant_get_ptr_destructor = gdnative_variant_get_ptr_destructor;
  706. gdni.variant_construct = gdnative_variant_construct;
  707. gdni.variant_get_ptr_setter = gdnative_variant_get_ptr_setter;
  708. gdni.variant_get_ptr_getter = gdnative_variant_get_ptr_getter;
  709. gdni.variant_get_ptr_indexed_setter = gdnative_variant_get_ptr_indexed_setter;
  710. gdni.variant_get_ptr_indexed_getter = gdnative_variant_get_ptr_indexed_getter;
  711. gdni.variant_get_ptr_keyed_setter = gdnative_variant_get_ptr_keyed_setter;
  712. gdni.variant_get_ptr_keyed_getter = gdnative_variant_get_ptr_keyed_getter;
  713. gdni.variant_get_ptr_keyed_checker = gdnative_variant_get_ptr_keyed_checker;
  714. gdni.variant_get_constant_value = gdnative_variant_get_constant_value;
  715. gdni.variant_get_ptr_utility_function = gdnative_variant_get_ptr_utility_function;
  716. // extra utilities
  717. gdni.string_new_with_latin1_chars = gdnative_string_new_with_latin1_chars;
  718. gdni.string_new_with_utf8_chars = gdnative_string_new_with_utf8_chars;
  719. gdni.string_new_with_utf16_chars = gdnative_string_new_with_utf16_chars;
  720. gdni.string_new_with_utf32_chars = gdnative_string_new_with_utf32_chars;
  721. gdni.string_new_with_wide_chars = gdnative_string_new_with_wide_chars;
  722. gdni.string_new_with_latin1_chars_and_len = gdnative_string_new_with_latin1_chars_and_len;
  723. gdni.string_new_with_utf8_chars_and_len = gdnative_string_new_with_utf8_chars_and_len;
  724. gdni.string_new_with_utf16_chars_and_len = gdnative_string_new_with_utf16_chars_and_len;
  725. gdni.string_new_with_utf32_chars_and_len = gdnative_string_new_with_utf32_chars_and_len;
  726. gdni.string_new_with_wide_chars_and_len = gdnative_string_new_with_wide_chars_and_len;
  727. gdni.string_to_latin1_chars = gdnative_string_to_latin1_chars;
  728. gdni.string_to_utf8_chars = gdnative_string_to_utf8_chars;
  729. gdni.string_to_utf16_chars = gdnative_string_to_utf16_chars;
  730. gdni.string_to_utf32_chars = gdnative_string_to_utf32_chars;
  731. gdni.string_to_wide_chars = gdnative_string_to_wide_chars;
  732. gdni.string_operator_index = gdnative_string_operator_index;
  733. gdni.string_operator_index_const = gdnative_string_operator_index_const;
  734. /* OBJECT */
  735. gdni.object_method_bind_ptrcall = gdnative_object_method_bind_ptrcall;
  736. gdni.object_destroy = gdnative_object_destroy;
  737. gdni.global_get_singleton = gdnative_global_get_singleton;
  738. gdni.object_get_instance_binding = gdnative_object_get_instance_binding;
  739. gdni.object_set_instance_binding = gdnative_object_set_instance_binding;
  740. gdni.object_cast_to = gdnative_object_cast_to;
  741. gdni.object_get_instance_from_id = gdnative_object_get_instance_from_id;
  742. gdni.object_get_instance_id = gdnative_object_get_instance_id;
  743. /* CLASSDB */
  744. gdni.classdb_get_constructor = gdnative_classdb_get_constructor;
  745. gdni.classdb_get_method_bind = gdnative_classdb_get_method_bind;
  746. gdni.classdb_get_class_tag = gdnative_classdb_get_class_tag;
  747. /* CLASSDB EXTENSION */
  748. //these are filled by implementation, since it will want to keep track of registered classes
  749. gdni.classdb_register_extension_class = nullptr;
  750. gdni.classdb_register_extension_class_method = nullptr;
  751. gdni.classdb_register_extension_class_integer_constant = nullptr;
  752. gdni.classdb_register_extension_class_property = nullptr;
  753. gdni.classdb_register_extension_class_signal = nullptr;
  754. gdni.classdb_unregister_extension_class = nullptr;
  755. }