High level GDNative
Single header GDNative high level API for C/C++
Loading...
Searching...
No Matches
hgdn.h
Go to the documentation of this file.
1
39#ifndef __HGDN_H__
40#define __HGDN_H__
41
42#include <stdint.h>
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48
49#ifndef HGDN_DECL
50 #ifdef HGDN_STATIC
51 #define HGDN_DECL static
52 #else
53 #define HGDN_DECL extern
54 #endif
55#endif
56
57#ifndef HGDN_STRING_FORMAT_BUFFER_SIZE
58 #define HGDN_STRING_FORMAT_BUFFER_SIZE 1024
59#endif
60
61#if defined(__cplusplus) && __cplusplus >= 201103L // `constexpr` is a C++11 feature
62 #define HGDN_CONSTEXPR constexpr
63#else
64 #define HGDN_CONSTEXPR
65#endif
66
67#ifndef HGDN_METHOD_ARGUMENTS_INFO_MAX
68 #define HGDN_METHOD_ARGUMENTS_INFO_MAX 16
69#endif
70
71// Macro magic to get the number of variable arguments
72// Ref: https://groups.google.com/g/comp.std.c/c/d-6Mj5Lko_s
73#define HGDN__NARG(...) HGDN__NARG_(__VA_ARGS__, HGDN__NARG_RSEQ_N())
74#define HGDN__NARG_(...) HGDN__NARG_N(__VA_ARGS__)
75#define HGDN__NARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,_21,_22,_23,_24,_25,_26,_27,_28,_29,_30,_31,_32,_33,_34,_35,_36,_37,_38,_39,_40,_41,_42,_43,_44,_45,_46,_47,_48,_49,_50,_51,_52,_53,_54,_55,_56,_57,_58,_59,_60,_61,_62,_63,N,...) N
76#define HGDN__NARG_RSEQ_N() 63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
77
78// Macro magic to apply a function macro to variadic arguments
79// Ref: https://stackoverflow.com/questions/6707148/foreach-macro-on-macros-arguments/13459454#13459454
80#define HGDN__EVAL0(...) __VA_ARGS__
81#define HGDN__EVAL1(...) HGDN__EVAL0(HGDN__EVAL0(HGDN__EVAL0(__VA_ARGS__)))
82#define HGDN__EVAL2(...) HGDN__EVAL1(HGDN__EVAL1(HGDN__EVAL1(__VA_ARGS__)))
83#define HGDN__EVAL3(...) HGDN__EVAL2(HGDN__EVAL2(HGDN__EVAL2(__VA_ARGS__)))
84#define HGDN__EVAL4(...) HGDN__EVAL3(HGDN__EVAL3(HGDN__EVAL3(__VA_ARGS__)))
85#define HGDN__EVAL(...) HGDN__EVAL4(HGDN__EVAL4(HGDN__EVAL4(__VA_ARGS__)))
86#define HGDN__MAP_END(...)
87#define HGDN__MAP_OUT
88#define HGDN__MAP_COMMA ,
89#define HGDN__MAP_GET_END() 0, HGDN__MAP_END
90#define HGDN__MAP_NEXT0(item, next, ...) next HGDN__MAP_OUT
91#define HGDN__MAP_NEXT1(item, next) HGDN__MAP_NEXT0(item, HGDN__MAP_COMMA next, 0)
92#define HGDN__MAP_NEXT(item, next) HGDN__MAP_NEXT1(HGDN__MAP_GET_END item, next)
93#define HGDN__MAP0(f, x, peek, ...) f(x) HGDN__MAP_NEXT(peek, HGDN__MAP1)(f, peek, __VA_ARGS__)
94#define HGDN__MAP1(f, x, peek, ...) f(x) HGDN__MAP_NEXT(peek, HGDN__MAP0)(f, peek, __VA_ARGS__)
95#define HGDN__MAP(f, ...) HGDN__EVAL(HGDN__MAP1(f, __VA_ARGS__, (), 0))
96
97
98
102typedef union hgdn_vector2 {
103 // raw data, must be the first field for guaranteeing ABI compatibility with Godot
104 uint8_t data[sizeof(float[2])];
105 // float elements
106 float elements[2];
107 // xy
108 struct { float x, y; };
109 // rg
110 struct { float r, g; };
111 // st
112 struct { float s, t; };
113 // uv
114 struct { float u, v; };
115 // Size: width/height
116 struct { float width, height; };
118
119#ifndef GODOT_CORE_API_GODOT_VECTOR2_TYPE_DEFINED
121#define GODOT_CORE_API_GODOT_VECTOR2_TYPE_DEFINED
122#endif
123
124typedef union hgdn_vector3 {
125 // raw data, must be the first field for guaranteeing ABI compatibility with Godot
126 uint8_t data[sizeof(float[3])];
127 // float elements
128 float elements[3];
129 // xyz
130 struct { float x, y, z; };
131 struct { hgdn_vector2 xy; float _0; };
132 struct { float _1; hgdn_vector2 yz; };
133 // rgb
134 struct { float r, g, b; };
135 struct { hgdn_vector2 rg; float _2; };
136 struct { float _3; hgdn_vector2 gb; };
137 // stp
138 struct { float s, t, p; };
139 struct { hgdn_vector2 st; float _6; };
140 struct { float _7; hgdn_vector2 tp; };
141 // uv
142 struct { float u, v, _4; };
143 struct { hgdn_vector2 uv; float _5; };
144 // 3D Size: width/height/depth
145 struct { float width, height, depth; };
147
148#ifndef GODOT_CORE_API_GODOT_VECTOR3_TYPE_DEFINED
150#define GODOT_CORE_API_GODOT_VECTOR3_TYPE_DEFINED
151#endif
152
153typedef union hgdn_vector4 {
154 // raw data, must be the first field for guaranteeing ABI compatibility with Godot
155 uint8_t data[sizeof(float[4])];
156 // float elements
157 float elements[4];
158 // xyzw
159 struct { float x, y, z, w; };
160 struct { hgdn_vector2 xy; hgdn_vector2 zw; };
161 struct { float _0; hgdn_vector2 yz; float _1; };
162 struct { hgdn_vector3 xyz; float _2; };
163 struct { float _3; hgdn_vector3 yzw; };
164 // rgba
165 struct { float r, g, b, a; };
166 struct { hgdn_vector2 rg; hgdn_vector2 ba; };
167 struct { float _4; hgdn_vector2 gb; float _5; };
168 struct { hgdn_vector3 rgb; float _6; };
169 struct { float _7; hgdn_vector3 gba; };
170 // stpq
171 struct { float s, t, p, q; };
172 struct { hgdn_vector2 st; hgdn_vector2 pq; };
173 struct { float _8; hgdn_vector2 tp; float _9; };
174 struct { hgdn_vector3 stp; float _10; };
175 struct { float _11; hgdn_vector3 tpq; };
176 // uv
177 struct { float u, v; float _12[2]; };
178 struct { hgdn_vector2 uv; float _13[2]; };
180
181#ifndef GODOT_CORE_API_GODOT_COLOR_TYPE_DEFINED
184#define GODOT_CORE_API_GODOT_COLOR_TYPE_DEFINED
185#endif
186
187typedef union hgdn_rect2 {
188 // raw data, must be the first field for guaranteeing ABI compatibility with Godot
189 uint8_t data[sizeof(float[4])];
190 float elements[4];
191 struct { float x, y, width, height; };
192 struct { hgdn_vector2 position; hgdn_vector2 size; };
193} hgdn_rect2;
194
195#ifndef GODOT_CORE_API_GODOT_RECT2_TYPE_DEFINED
196typedef hgdn_rect2 godot_rect2;
197#define GODOT_CORE_API_GODOT_RECT2_TYPE_DEFINED
198#endif
199
200typedef union hgdn_plane {
201 // raw data, must be the first field for guaranteeing ABI compatibility with Godot
202 uint8_t data[sizeof(float[4])];
203 float elements[4];
204 struct { hgdn_vector3 normal; float d; };
205} hgdn_plane;
206
207#ifndef GODOT_CORE_API_GODOT_PLANE_TYPE_DEFINED
208typedef hgdn_plane godot_plane;
209#define GODOT_CORE_API_GODOT_PLANE_TYPE_DEFINED
210#endif
211
212typedef union hgdn_quat {
213 // raw data, must be the first field for guaranteeing ABI compatibility with Godot
214 uint8_t data[sizeof(float[4])];
215 float elements[4];
216 struct { float x, y, z, w; };
217 struct { hgdn_vector2 xy; hgdn_vector2 zw; };
218 struct { float _0; hgdn_vector2 yz; float _1; };
219 struct { hgdn_vector3 xyz; float _2; };
220 struct { float _3; hgdn_vector3 yzw; };
221} hgdn_quat;
222#define HGDN_QUAT_IDENTITY ((hgdn_quat){ .elements = {0, 0, 0, 1} })
223
224#ifndef GODOT_CORE_API_GODOT_QUAT_TYPE_DEFINED
225typedef hgdn_quat godot_quat;
226#define GODOT_CORE_API_GODOT_QUAT_TYPE_DEFINED
227#endif
228
229typedef union hgdn_basis {
230 // raw data, must be the first field for guaranteeing ABI compatibility with Godot
231 uint8_t data[sizeof(float[9])];
232 float elements[9];
233 hgdn_vector3 rows[3];
234} hgdn_basis;
235#define HGDN_BASIS_IDENTITY ((hgdn_basis){ .elements = {1, 0, 0, 0, 1, 0, 0, 0, 1} })
236
237#ifndef GODOT_CORE_API_GODOT_BASIS_TYPE_DEFINED
238typedef hgdn_basis godot_basis;
239#define GODOT_CORE_API_GODOT_BASIS_TYPE_DEFINED
240#endif
241
242typedef union hgdn_aabb {
243 // raw data, must be the first field for guaranteeing ABI compatibility with Godot
244 uint8_t data[sizeof(float[6])];
245 float elements[6];
246 struct { hgdn_vector3 position, size; };
247} hgdn_aabb;
248
249#ifndef GODOT_CORE_API_GODOT_AABB_TYPE_DEFINED
250typedef hgdn_aabb godot_aabb;
251#define GODOT_CORE_API_GODOT_AABB_TYPE_DEFINED
252#endif
253
254typedef union hgdn_transform2d {
255 // raw data, must be the first field for guaranteeing ABI compatibility with Godot
256 uint8_t data[sizeof(float[6])];
257 float elements[6];
258 hgdn_vector2 columns[3];
259 struct { hgdn_vector2 x, y, origin; };
261#define HGDN_TRANSFORM2D_IDENTITY ((hgdn_transform2d){ .elements = {1, 0, 0, 1, 0, 0} })
262
263#ifndef GODOT_CORE_API_GODOT_TRANSFORM2D_TYPE_DEFINED
265#define GODOT_CORE_API_GODOT_TRANSFORM2D_TYPE_DEFINED
266#endif
267
268typedef union hgdn_transform {
269 // raw data, must be the first field for guaranteeing ABI compatibility with Godot
270 uint8_t data[sizeof(float[12])];
271 float elements[12];
272 struct { hgdn_basis basis; hgdn_vector3 origin; };
274#define HGDN_TRANSFORM3D_IDENTITY ((hgdn_transform){ .elements = {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0} })
275
276#ifndef GODOT_CORE_API_GODOT_TRANSFORM_TYPE_DEFINED
278#define GODOT_CORE_API_GODOT_TRANSFORM_TYPE_DEFINED
279#endif
281
282#include "gdnative_api_struct.gen.h"
283
287extern const godot_gdnative_core_api_struct *hgdn_core_api;
288#ifndef HGDN_NO_CORE_1_1
289extern const godot_gdnative_core_1_1_api_struct *hgdn_core_1_1_api;
290#endif
291#ifndef HGDN_NO_CORE_1_2
292extern const godot_gdnative_core_1_2_api_struct *hgdn_core_1_2_api;
293#endif
294#ifndef HGDN_NO_CORE_1_3
295extern const godot_gdnative_core_1_3_api_struct *hgdn_core_1_3_api;
296#endif
297#ifndef HGDN_NO_EXT_NATIVESCRIPT
298extern const godot_gdnative_ext_nativescript_api_struct *hgdn_nativescript_api;
299extern const godot_gdnative_ext_nativescript_1_1_api_struct *hgdn_nativescript_1_1_api;
300#endif
301#ifndef HGDN_NO_EXT_PLUGINSCRIPT
302extern const godot_gdnative_ext_pluginscript_api_struct *hgdn_pluginscript_api;
303#endif
304#ifndef HGDN_NO_EXT_ANDROID
305extern const godot_gdnative_ext_android_api_struct *hgdn_android_api;
306#endif
307#ifndef HGDN_NO_EXT_ARVR
308extern const godot_gdnative_ext_arvr_api_struct *hgdn_arvr_api;
309extern const godot_gdnative_ext_arvr_1_2_api_struct *hgdn_arvr_1_2_api;
310#endif
311#ifndef HGDN_NO_EXT_VIDEOCODER
312extern const godot_gdnative_ext_videodecoder_api_struct *hgdn_videodecoder_api;
313#endif
314#ifndef HGDN_NO_EXT_NET
315extern const godot_gdnative_ext_net_api_struct *hgdn_net_api;
316extern const godot_gdnative_ext_net_3_2_api_struct *hgdn_net_3_2_api;
317#endif
318extern godot_object *hgdn_library;
319extern godot_method_bind *hgdn_method_Object_callv;
321
322
326HGDN_DECL void hgdn_gdnative_init(const godot_gdnative_init_options *options);
327HGDN_DECL void hgdn_gdnative_terminate(const godot_gdnative_terminate_options *options);
329
330
334HGDN_DECL void *hgdn_alloc(size_t size);
335HGDN_DECL void *hgdn_realloc(void *ptr, size_t size);
337HGDN_DECL void hgdn_free(void *ptr);
339
340
344HGDN_DECL void hgdn_print(const char *fmt, ...);
345HGDN_DECL void hgdn_print_warning(const char *funcname, const char *filename, int line, const char *fmt, ...);
346HGDN_DECL void hgdn_print_error(const char *funcname, const char *filename, int line, const char *fmt, ...);
347#ifdef _MSC_VER
348#define HGDN_PRINT_WARNING(fmt, ...) (hgdn_print_warning(__FUNCTION__, __FILE__, __LINE__, fmt, ##__VA_ARGS__))
349#define HGDN_PRINT_ERROR(fmt, ...) (hgdn_print_error(__FUNCTION__, __FILE__, __LINE__, fmt, ##__VA_ARGS__))
350#else
351#define HGDN_PRINT_WARNING(fmt, ...) (hgdn_print_warning(__PRETTY_FUNCTION__, __FILE__, __LINE__, fmt, ##__VA_ARGS__))
352#define HGDN_PRINT_ERROR(fmt, ...) (hgdn_print_error(__PRETTY_FUNCTION__, __FILE__, __LINE__, fmt, ##__VA_ARGS__))
353#endif
355
363#define HGDN_ASSERT(cond) HGDN_ASSERT_MSG((cond), "Assertion error: !(" #cond ")")
365#define HGDN_ASSERT_MSG(cond, fmt, ...) if(!(cond)){ HGDN_PRINT_ERROR(fmt, ##__VA_ARGS__); return hgdn_new_nil_variant(); }
367#define HGDN_ASSERT_ARRAY_SIZE(arr, min_size) HGDN_ASSERT_MSG(hgdn_core_api->godot_array_size((arr)) >= (min_size), "Error: array should have size of at least " #min_size ", got %d", hgdn_core_api->godot_array_size((arr)))
369#define HGDN_ASSERT_ARGS_SIZE(argc, min_size) HGDN_ASSERT_MSG((argc) >= (min_size), "Error: expected at least " #min_size " arguments, got %d", argc)
371
375typedef struct hgdn_string {
376 godot_char_string gd_char_string;
377 const char *ptr;
378 godot_int length;
380HGDN_DECL hgdn_string hgdn_string_get(const godot_string *str);
381HGDN_DECL hgdn_string hgdn_string_get_own(godot_string str);
382HGDN_DECL void hgdn_string_destroy(hgdn_string *str);
383
384typedef struct hgdn_wide_string {
385 godot_string gd_string;
386 const wchar_t *ptr;
387 godot_int length;
389HGDN_DECL hgdn_wide_string hgdn_wide_string_get(const godot_string *str);
390HGDN_DECL hgdn_wide_string hgdn_wide_string_get_own(godot_string str);
391HGDN_DECL void hgdn_wide_string_destroy(hgdn_wide_string *str);
393
394
398typedef struct hgdn_byte_array {
399 godot_pool_byte_array_read_access *gd_read_access;
400 const uint8_t *ptr;
401 godot_int size;
403HGDN_DECL hgdn_byte_array hgdn_byte_array_get(const godot_pool_byte_array *array);
404HGDN_DECL hgdn_byte_array hgdn_byte_array_get_own(godot_pool_byte_array array);
405HGDN_DECL void hgdn_byte_array_destroy(hgdn_byte_array *array);
406
407typedef struct hgdn_int_array {
408 godot_pool_int_array_read_access *gd_read_access;
409 const godot_int *ptr;
410 godot_int size;
412HGDN_DECL hgdn_int_array hgdn_int_array_get(const godot_pool_int_array *array);
413HGDN_DECL hgdn_int_array hgdn_int_array_get_own(godot_pool_int_array array);
414HGDN_DECL void hgdn_int_array_destroy(hgdn_int_array *array);
415
416typedef struct hgdn_real_array {
417 godot_pool_real_array_read_access *gd_read_access;
418 const godot_real *ptr;
419 godot_int size;
421HGDN_DECL hgdn_real_array hgdn_real_array_get(const godot_pool_real_array *array);
422HGDN_DECL hgdn_real_array hgdn_real_array_get_own(godot_pool_real_array array);
423HGDN_DECL void hgdn_real_array_destroy(hgdn_real_array *array);
424
425typedef struct hgdn_vector2_array {
426 godot_pool_vector2_array_read_access *gd_read_access;
427 const godot_vector2 *ptr;
428 godot_int size;
430HGDN_DECL hgdn_vector2_array hgdn_vector2_array_get(const godot_pool_vector2_array *array);
431HGDN_DECL hgdn_vector2_array hgdn_vector2_array_get_own(godot_pool_vector2_array array);
432HGDN_DECL void hgdn_vector2_array_destroy(hgdn_vector2_array *array);
433
434typedef struct hgdn_vector3_array {
435 godot_pool_vector3_array_read_access *gd_read_access;
436 const godot_vector3 *ptr;
437 godot_int size;
439HGDN_DECL hgdn_vector3_array hgdn_vector3_array_get(const godot_pool_vector3_array *array);
440HGDN_DECL hgdn_vector3_array hgdn_vector3_array_get_own(godot_pool_vector3_array array);
441HGDN_DECL void hgdn_vector3_array_destroy(hgdn_vector3_array *array);
442
443typedef struct hgdn_color_array {
444 godot_pool_color_array_read_access *gd_read_access;
445 const godot_color *ptr;
446 godot_int size;
448HGDN_DECL hgdn_color_array hgdn_color_array_get(const godot_pool_color_array *array);
449HGDN_DECL hgdn_color_array hgdn_color_array_get_own(godot_pool_color_array array);
450HGDN_DECL void hgdn_color_array_destroy(hgdn_color_array *array);
451
452typedef struct hgdn_string_array {
453 hgdn_string *strings;
454 const char **ptr;
455 godot_int size;
457HGDN_DECL hgdn_string_array hgdn_string_array_get(const godot_pool_string_array *array);
458HGDN_DECL hgdn_string_array hgdn_string_array_get_own(godot_pool_string_array array);
459HGDN_DECL void hgdn_string_array_destroy(hgdn_string_array *array);
461
462
468HGDN_DECL godot_bool hgdn_variant_get_bool(const godot_variant *var);
469HGDN_DECL uint64_t hgdn_variant_get_uint(const godot_variant *var);
470HGDN_DECL int64_t hgdn_variant_get_int(const godot_variant *var);
471HGDN_DECL double hgdn_variant_get_real(const godot_variant *var);
472HGDN_DECL godot_vector2 hgdn_variant_get_vector2(const godot_variant *var);
473HGDN_DECL godot_vector3 hgdn_variant_get_vector3(const godot_variant *var);
474HGDN_DECL godot_rect2 hgdn_variant_get_rect2(const godot_variant *var);
475HGDN_DECL godot_plane hgdn_variant_get_plane(const godot_variant *var);
476HGDN_DECL godot_quat hgdn_variant_get_quat(const godot_variant *var);
477HGDN_DECL godot_aabb hgdn_variant_get_aabb(const godot_variant *var);
478HGDN_DECL godot_basis hgdn_variant_get_basis(const godot_variant *var);
479HGDN_DECL godot_transform2d hgdn_variant_get_transform2d(const godot_variant *var);
480HGDN_DECL godot_transform hgdn_variant_get_transform(const godot_variant *var);
481HGDN_DECL godot_color hgdn_variant_get_color(const godot_variant *var);
482HGDN_DECL godot_node_path hgdn_variant_get_node_path(const godot_variant *var);
483HGDN_DECL godot_rid hgdn_variant_get_rid(const godot_variant *var);
484HGDN_DECL godot_object *hgdn_variant_get_object(const godot_variant *var);
485HGDN_DECL godot_dictionary hgdn_variant_get_dictionary(const godot_variant *var);
486HGDN_DECL godot_array hgdn_variant_get_array(const godot_variant *var);
487
488HGDN_DECL hgdn_string hgdn_variant_get_string(const godot_variant *var);
489HGDN_DECL hgdn_wide_string hgdn_variant_get_wide_string(const godot_variant *var);
490HGDN_DECL hgdn_byte_array hgdn_variant_get_byte_array(const godot_variant *var);
491HGDN_DECL hgdn_int_array hgdn_variant_get_int_array(const godot_variant *var);
492HGDN_DECL hgdn_real_array hgdn_variant_get_real_array(const godot_variant *var);
493HGDN_DECL hgdn_vector2_array hgdn_variant_get_vector2_array(const godot_variant *var);
494HGDN_DECL hgdn_vector3_array hgdn_variant_get_vector3_array(const godot_variant *var);
495HGDN_DECL hgdn_color_array hgdn_variant_get_color_array(const godot_variant *var);
496HGDN_DECL hgdn_string_array hgdn_variant_get_string_array(const godot_variant *var);
497
498HGDN_DECL godot_bool hgdn_variant_get_bool_own(godot_variant var);
499HGDN_DECL uint64_t hgdn_variant_get_uint_own(godot_variant var);
500HGDN_DECL int64_t hgdn_variant_get_int_own(godot_variant var);
501HGDN_DECL double hgdn_variant_get_real_own(godot_variant var);
502HGDN_DECL godot_vector2 hgdn_variant_get_vector2_own(godot_variant var);
503HGDN_DECL godot_vector3 hgdn_variant_get_vector3_own(godot_variant var);
504HGDN_DECL godot_rect2 hgdn_variant_get_rect2_own(godot_variant var);
505HGDN_DECL godot_plane hgdn_variant_get_plane_own(godot_variant var);
506HGDN_DECL godot_quat hgdn_variant_get_quat_own(godot_variant var);
507HGDN_DECL godot_aabb hgdn_variant_get_aabb_own(godot_variant var);
508HGDN_DECL godot_basis hgdn_variant_get_basis_own(godot_variant var);
509HGDN_DECL godot_transform2d hgdn_variant_get_transform2d_own(godot_variant var);
510HGDN_DECL godot_transform hgdn_variant_get_transform_own(godot_variant var);
511HGDN_DECL godot_color hgdn_variant_get_color_own(godot_variant var);
512HGDN_DECL godot_node_path hgdn_variant_get_node_path_own(godot_variant var);
513HGDN_DECL godot_rid hgdn_variant_get_rid_own(godot_variant var);
514HGDN_DECL godot_object *hgdn_variant_get_object_own(godot_variant var);
515HGDN_DECL godot_dictionary hgdn_variant_get_dictionary_own(godot_variant var);
516HGDN_DECL godot_array hgdn_variant_get_array_own(godot_variant var);
517
518HGDN_DECL hgdn_string hgdn_variant_get_string_own(godot_variant var);
519HGDN_DECL hgdn_wide_string hgdn_variant_get_wide_string_own(godot_variant var);
520HGDN_DECL hgdn_byte_array hgdn_variant_get_byte_array_own(godot_variant var);
521HGDN_DECL hgdn_int_array hgdn_variant_get_int_array_own(godot_variant var);
522HGDN_DECL hgdn_real_array hgdn_variant_get_real_array_own(godot_variant var);
523HGDN_DECL hgdn_vector2_array hgdn_variant_get_vector2_array_own(godot_variant var);
524HGDN_DECL hgdn_vector3_array hgdn_variant_get_vector3_array_own(godot_variant var);
525HGDN_DECL hgdn_color_array hgdn_variant_get_color_array_own(godot_variant var);
526HGDN_DECL hgdn_string_array hgdn_variant_get_string_array_own(godot_variant var);
528
529
533HGDN_DECL godot_bool hgdn_array_get_bool(const godot_array *array, const godot_int index);
534HGDN_DECL uint64_t hgdn_array_get_uint(const godot_array *array, const godot_int index);
535HGDN_DECL int64_t hgdn_array_get_int(const godot_array *array, const godot_int index);
536HGDN_DECL double hgdn_array_get_real(const godot_array *array, const godot_int index);
537HGDN_DECL godot_vector2 hgdn_array_get_vector2(const godot_array *array, const godot_int index);
538HGDN_DECL godot_vector3 hgdn_array_get_vector3(const godot_array *array, const godot_int index);
539HGDN_DECL godot_rect2 hgdn_array_get_rect2(const godot_array *array, const godot_int index);
540HGDN_DECL godot_plane hgdn_array_get_plane(const godot_array *array, const godot_int index);
541HGDN_DECL godot_quat hgdn_array_get_quat(const godot_array *array, const godot_int index);
542HGDN_DECL godot_aabb hgdn_array_get_aabb(const godot_array *array, const godot_int index);
543HGDN_DECL godot_basis hgdn_array_get_basis(const godot_array *array, const godot_int index);
544HGDN_DECL godot_transform2d hgdn_array_get_transform2d(const godot_array *array, const godot_int index);
545HGDN_DECL godot_transform hgdn_array_get_transform(const godot_array *array, const godot_int index);
546HGDN_DECL godot_color hgdn_array_get_color(const godot_array *array, const godot_int index);
547HGDN_DECL godot_node_path hgdn_array_get_node_path(const godot_array *array, const godot_int index);
548HGDN_DECL godot_rid hgdn_array_get_rid(const godot_array *array, const godot_int index);
549HGDN_DECL godot_object *hgdn_array_get_object(const godot_array *array, const godot_int index);
550HGDN_DECL godot_dictionary hgdn_array_get_dictionary(const godot_array *array, const godot_int index);
551HGDN_DECL godot_array hgdn_array_get_array(const godot_array *array, const godot_int index);
552
553HGDN_DECL hgdn_string hgdn_array_get_string(const godot_array *array, const godot_int index);
554HGDN_DECL hgdn_wide_string hgdn_array_get_wide_string(const godot_array *array, const godot_int index);
555HGDN_DECL hgdn_byte_array hgdn_array_get_byte_array(const godot_array *array, const godot_int index);
556HGDN_DECL hgdn_int_array hgdn_array_get_int_array(const godot_array *array, const godot_int index);
557HGDN_DECL hgdn_real_array hgdn_array_get_real_array(const godot_array *array, const godot_int index);
558HGDN_DECL hgdn_vector2_array hgdn_array_get_vector2_array(const godot_array *array, const godot_int index);
559HGDN_DECL hgdn_vector3_array hgdn_array_get_vector3_array(const godot_array *array, const godot_int index);
560HGDN_DECL hgdn_color_array hgdn_array_get_color_array(const godot_array *array, const godot_int index);
561HGDN_DECL hgdn_string_array hgdn_array_get_string_array(const godot_array *array, const godot_int index);
563
564
568HGDN_DECL godot_bool hgdn_args_get_bool(godot_variant **args, const godot_int index);
569HGDN_DECL uint64_t hgdn_args_get_uint(godot_variant **args, const godot_int index);
570HGDN_DECL int64_t hgdn_args_get_int(godot_variant **args, const godot_int index);
571HGDN_DECL double hgdn_args_get_real(godot_variant **args, const godot_int index);
572HGDN_DECL godot_vector2 hgdn_args_get_vector2(godot_variant **args, const godot_int index);
573HGDN_DECL godot_vector3 hgdn_args_get_vector3(godot_variant **args, const godot_int index);
574HGDN_DECL godot_rect2 hgdn_args_get_rect2(godot_variant **args, const godot_int index);
575HGDN_DECL godot_plane hgdn_args_get_plane(godot_variant **args, const godot_int index);
576HGDN_DECL godot_quat hgdn_args_get_quat(godot_variant **args, const godot_int index);
577HGDN_DECL godot_aabb hgdn_args_get_aabb(godot_variant **args, const godot_int index);
578HGDN_DECL godot_basis hgdn_args_get_basis(godot_variant **args, const godot_int index);
579HGDN_DECL godot_transform2d hgdn_args_get_transform2d(godot_variant **args, const godot_int index);
580HGDN_DECL godot_transform hgdn_args_get_transform(godot_variant **args, const godot_int index);
581HGDN_DECL godot_color hgdn_args_get_color(godot_variant **args, const godot_int index);
582HGDN_DECL godot_node_path hgdn_args_get_node_path(godot_variant **args, const godot_int index);
583HGDN_DECL godot_rid hgdn_args_get_rid(godot_variant **args, const godot_int index);
584HGDN_DECL godot_object *hgdn_args_get_object(godot_variant **args, const godot_int index);
585HGDN_DECL godot_dictionary hgdn_args_get_dictionary(godot_variant **args, const godot_int index);
586HGDN_DECL godot_array hgdn_args_get_array(godot_variant **args, const godot_int index);
587
588HGDN_DECL hgdn_string hgdn_args_get_string(godot_variant **args, const godot_int index);
589HGDN_DECL hgdn_wide_string hgdn_args_get_wide_string(godot_variant **args, const godot_int index);
590HGDN_DECL hgdn_byte_array hgdn_args_get_byte_array(godot_variant **args, const godot_int index);
591HGDN_DECL hgdn_int_array hgdn_args_get_int_array(godot_variant **args, const godot_int index);
592HGDN_DECL hgdn_real_array hgdn_args_get_real_array(godot_variant **args, const godot_int index);
593HGDN_DECL hgdn_vector2_array hgdn_args_get_vector2_array(godot_variant **args, const godot_int index);
594HGDN_DECL hgdn_vector3_array hgdn_args_get_vector3_array(godot_variant **args, const godot_int index);
595HGDN_DECL hgdn_color_array hgdn_args_get_color_array(godot_variant **args, const godot_int index);
596HGDN_DECL hgdn_string_array hgdn_args_get_string_array(godot_variant **args, const godot_int index);
598
599
603HGDN_DECL godot_bool hgdn_dictionary_get_bool(const godot_dictionary *dict, const godot_variant *key);
604HGDN_DECL uint64_t hgdn_dictionary_get_uint(const godot_dictionary *dict, const godot_variant *key);
605HGDN_DECL int64_t hgdn_dictionary_get_int(const godot_dictionary *dict, const godot_variant *key);
606HGDN_DECL double hgdn_dictionary_get_real(const godot_dictionary *dict, const godot_variant *key);
607HGDN_DECL godot_vector2 hgdn_dictionary_get_vector2(const godot_dictionary *dict, const godot_variant *key);
608HGDN_DECL godot_vector3 hgdn_dictionary_get_vector3(const godot_dictionary *dict, const godot_variant *key);
609HGDN_DECL godot_rect2 hgdn_dictionary_get_rect2(const godot_dictionary *dict, const godot_variant *key);
610HGDN_DECL godot_plane hgdn_dictionary_get_plane(const godot_dictionary *dict, const godot_variant *key);
611HGDN_DECL godot_quat hgdn_dictionary_get_quat(const godot_dictionary *dict, const godot_variant *key);
612HGDN_DECL godot_aabb hgdn_dictionary_get_aabb(const godot_dictionary *dict, const godot_variant *key);
613HGDN_DECL godot_basis hgdn_dictionary_get_basis(const godot_dictionary *dict, const godot_variant *key);
614HGDN_DECL godot_transform2d hgdn_dictionary_get_transform2d(const godot_dictionary *dict, const godot_variant *key);
615HGDN_DECL godot_transform hgdn_dictionary_get_transform(const godot_dictionary *dict, const godot_variant *key);
616HGDN_DECL godot_color hgdn_dictionary_get_color(const godot_dictionary *dict, const godot_variant *key);
617HGDN_DECL godot_node_path hgdn_dictionary_get_node_path(const godot_dictionary *dict, const godot_variant *key);
618HGDN_DECL godot_rid hgdn_dictionary_get_rid(const godot_dictionary *dict, const godot_variant *key);
619HGDN_DECL godot_object *hgdn_dictionary_get_object(const godot_dictionary *dict, const godot_variant *key);
620HGDN_DECL godot_dictionary hgdn_dictionary_get_dictionary(const godot_dictionary *dict, const godot_variant *key);
621HGDN_DECL godot_array hgdn_dictionary_get_array(const godot_dictionary *dict, const godot_variant *key);
622
623HGDN_DECL hgdn_string hgdn_dictionary_get_string(const godot_dictionary *dict, const godot_variant *key);
624HGDN_DECL hgdn_wide_string hgdn_dictionary_get_wide_string(const godot_dictionary *dict, const godot_variant *key);
625HGDN_DECL hgdn_byte_array hgdn_dictionary_get_byte_array(const godot_dictionary *dict, const godot_variant *key);
626HGDN_DECL hgdn_int_array hgdn_dictionary_get_int_array(const godot_dictionary *dict, const godot_variant *key);
627HGDN_DECL hgdn_real_array hgdn_dictionary_get_real_array(const godot_dictionary *dict, const godot_variant *key);
628HGDN_DECL hgdn_vector2_array hgdn_dictionary_get_vector2_array(const godot_dictionary *dict, const godot_variant *key);
629HGDN_DECL hgdn_vector3_array hgdn_dictionary_get_vector3_array(const godot_dictionary *dict, const godot_variant *key);
630HGDN_DECL hgdn_color_array hgdn_dictionary_get_color_array(const godot_dictionary *dict, const godot_variant *key);
631HGDN_DECL hgdn_string_array hgdn_dictionary_get_string_array(const godot_dictionary *dict, const godot_variant *key);
632
633HGDN_DECL godot_bool hgdn_dictionary_string_get_bool(const godot_dictionary *dict, const char *key);
634HGDN_DECL uint64_t hgdn_dictionary_string_get_uint(const godot_dictionary *dict, const char *key);
635HGDN_DECL int64_t hgdn_dictionary_string_get_int(const godot_dictionary *dict, const char *key);
636HGDN_DECL double hgdn_dictionary_string_get_real(const godot_dictionary *dict, const char *key);
637HGDN_DECL godot_vector2 hgdn_dictionary_string_get_vector2(const godot_dictionary *dict, const char *key);
638HGDN_DECL godot_vector3 hgdn_dictionary_string_get_vector3(const godot_dictionary *dict, const char *key);
639HGDN_DECL godot_rect2 hgdn_dictionary_string_get_rect2(const godot_dictionary *dict, const char *key);
640HGDN_DECL godot_plane hgdn_dictionary_string_get_plane(const godot_dictionary *dict, const char *key);
641HGDN_DECL godot_quat hgdn_dictionary_string_get_quat(const godot_dictionary *dict, const char *key);
642HGDN_DECL godot_aabb hgdn_dictionary_string_get_aabb(const godot_dictionary *dict, const char *key);
643HGDN_DECL godot_basis hgdn_dictionary_string_get_basis(const godot_dictionary *dict, const char *key);
644HGDN_DECL godot_transform2d hgdn_dictionary_string_get_transform2d(const godot_dictionary *dict, const char *key);
645HGDN_DECL godot_transform hgdn_dictionary_string_get_transform(const godot_dictionary *dict, const char *key);
646HGDN_DECL godot_color hgdn_dictionary_string_get_color(const godot_dictionary *dict, const char *key);
647HGDN_DECL godot_node_path hgdn_dictionary_string_get_node_path(const godot_dictionary *dict, const char *key);
648HGDN_DECL godot_rid hgdn_dictionary_string_get_rid(const godot_dictionary *dict, const char *key);
649HGDN_DECL godot_object *hgdn_dictionary_string_get_object(const godot_dictionary *dict, const char *key);
650HGDN_DECL godot_dictionary hgdn_dictionary_string_get_dictionary(const godot_dictionary *dict, const char *key);
651HGDN_DECL godot_array hgdn_dictionary_string_get_array(const godot_dictionary *dict, const char *key);
652
653HGDN_DECL hgdn_string hgdn_dictionary_string_get_string(const godot_dictionary *dict, const char *key);
654HGDN_DECL hgdn_wide_string hgdn_dictionary_string_get_wide_string(const godot_dictionary *dict, const char *key);
655HGDN_DECL hgdn_byte_array hgdn_dictionary_string_get_byte_array(const godot_dictionary *dict, const char *key);
656HGDN_DECL hgdn_int_array hgdn_dictionary_string_get_int_array(const godot_dictionary *dict, const char *key);
657HGDN_DECL hgdn_real_array hgdn_dictionary_string_get_real_array(const godot_dictionary *dict, const char *key);
658HGDN_DECL hgdn_vector2_array hgdn_dictionary_string_get_vector2_array(const godot_dictionary *dict, const char *key);
659HGDN_DECL hgdn_vector3_array hgdn_dictionary_string_get_vector3_array(const godot_dictionary *dict, const char *key);
660HGDN_DECL hgdn_color_array hgdn_dictionary_string_get_color_array(const godot_dictionary *dict, const char *key);
661HGDN_DECL hgdn_string_array hgdn_dictionary_string_get_string_array(const godot_dictionary *dict, const char *key);
663
664
672HGDN_DECL godot_variant hgdn_new_variant_copy(const godot_variant *value);
673HGDN_DECL godot_variant hgdn_new_nil_variant();
674HGDN_DECL godot_variant hgdn_new_bool_variant(const godot_bool value);
675HGDN_DECL godot_variant hgdn_new_uint_variant(const uint64_t value);
676HGDN_DECL godot_variant hgdn_new_int_variant(const int64_t value);
677HGDN_DECL godot_variant hgdn_new_real_variant(const double value);
678HGDN_DECL godot_variant hgdn_new_string_variant(const godot_string *value);
679HGDN_DECL godot_variant hgdn_new_cstring_variant(const char *value);
680HGDN_DECL godot_variant hgdn_new_wide_string_variant(const wchar_t *value);
681HGDN_DECL godot_variant hgdn_new_vector2_variant(const godot_vector2 value);
682HGDN_DECL godot_variant hgdn_new_vector3_variant(const godot_vector3 value);
683HGDN_DECL godot_variant hgdn_new_rect2_variant(const godot_rect2 value);
684HGDN_DECL godot_variant hgdn_new_plane_variant(const godot_plane value);
685HGDN_DECL godot_variant hgdn_new_quat_variant(const godot_quat value);
686HGDN_DECL godot_variant hgdn_new_aabb_variant(const godot_aabb value);
687HGDN_DECL godot_variant hgdn_new_basis_variant(const godot_basis value);
688HGDN_DECL godot_variant hgdn_new_transform2d_variant(const godot_transform2d value);
689HGDN_DECL godot_variant hgdn_new_transform_variant(const godot_transform value);
690HGDN_DECL godot_variant hgdn_new_color_variant(const godot_color value);
691HGDN_DECL godot_variant hgdn_new_node_path_variant(const godot_node_path *value);
692HGDN_DECL godot_variant hgdn_new_rid_variant(const godot_rid *value);
693HGDN_DECL godot_variant hgdn_new_object_variant(const godot_object *value);
694HGDN_DECL godot_variant hgdn_new_dictionary_variant(const godot_dictionary *value);
695HGDN_DECL godot_variant hgdn_new_array_variant(const godot_array *value);
696HGDN_DECL godot_variant hgdn_new_pool_byte_array_variant(const godot_pool_byte_array *value);
697HGDN_DECL godot_variant hgdn_new_pool_int_array_variant(const godot_pool_int_array *value);
698HGDN_DECL godot_variant hgdn_new_pool_real_array_variant(const godot_pool_real_array *value);
699HGDN_DECL godot_variant hgdn_new_pool_vector2_array_variant(const godot_pool_vector2_array *value);
700HGDN_DECL godot_variant hgdn_new_pool_vector3_array_variant(const godot_pool_vector3_array *value);
701HGDN_DECL godot_variant hgdn_new_pool_color_array_variant(const godot_pool_color_array *value);
702HGDN_DECL godot_variant hgdn_new_pool_string_array_variant(const godot_pool_string_array *value);
703
704HGDN_DECL godot_variant hgdn_new_string_variant_own(godot_string value);
705HGDN_DECL godot_variant hgdn_new_node_path_variant_own(godot_node_path value);
706HGDN_DECL godot_variant hgdn_new_dictionary_variant_own(godot_dictionary value);
707HGDN_DECL godot_variant hgdn_new_array_variant_own(godot_array value);
708HGDN_DECL godot_variant hgdn_new_pool_byte_array_variant_own(godot_pool_byte_array value);
709HGDN_DECL godot_variant hgdn_new_pool_int_array_variant_own(godot_pool_int_array value);
710HGDN_DECL godot_variant hgdn_new_pool_real_array_variant_own(godot_pool_real_array value);
711HGDN_DECL godot_variant hgdn_new_pool_vector2_array_variant_own(godot_pool_vector2_array value);
712HGDN_DECL godot_variant hgdn_new_pool_vector3_array_variant_own(godot_pool_vector3_array value);
713HGDN_DECL godot_variant hgdn_new_pool_color_array_variant_own(godot_pool_color_array value);
714HGDN_DECL godot_variant hgdn_new_pool_string_array_variant_own(godot_pool_string_array value);
715
716#ifdef __cplusplus
717extern "C++" {
718 HGDN_DECL godot_variant hgdn_new_variant(const godot_bool value);
719 HGDN_DECL godot_variant hgdn_new_variant(const unsigned int value);
720 HGDN_DECL godot_variant hgdn_new_variant(const uint64_t value);
721 HGDN_DECL godot_variant hgdn_new_variant(const int value);
722 HGDN_DECL godot_variant hgdn_new_variant(const int64_t value);
723 HGDN_DECL godot_variant hgdn_new_variant(const double value);
724 HGDN_DECL godot_variant hgdn_new_variant(const godot_string *value);
725 HGDN_DECL godot_variant hgdn_new_variant(const char *value);
726 HGDN_DECL godot_variant hgdn_new_variant(const wchar_t *value);
727 HGDN_DECL godot_variant hgdn_new_variant(const godot_vector2 value);
728 HGDN_DECL godot_variant hgdn_new_variant(const godot_vector3 value);
729 HGDN_DECL godot_variant hgdn_new_variant(const godot_rect2 value);
730 HGDN_DECL godot_variant hgdn_new_variant(const godot_plane value);
731 HGDN_DECL godot_variant hgdn_new_variant(const godot_quat value);
732 HGDN_DECL godot_variant hgdn_new_variant(const godot_aabb value);
733 HGDN_DECL godot_variant hgdn_new_variant(const godot_basis value);
734 HGDN_DECL godot_variant hgdn_new_variant(const godot_transform2d value);
735 HGDN_DECL godot_variant hgdn_new_variant(const godot_transform value);
736 HGDN_DECL godot_variant hgdn_new_variant(const godot_color value);
737 HGDN_DECL godot_variant hgdn_new_variant(const godot_node_path *value);
738 HGDN_DECL godot_variant hgdn_new_variant(const godot_rid *value);
739 HGDN_DECL godot_variant hgdn_new_variant(const godot_object *value);
740 HGDN_DECL godot_variant hgdn_new_variant(const godot_dictionary *value);
741 HGDN_DECL godot_variant hgdn_new_variant(const godot_array *value);
742 HGDN_DECL godot_variant hgdn_new_variant(const godot_pool_byte_array *value);
743 HGDN_DECL godot_variant hgdn_new_variant(const godot_pool_int_array *value);
744 HGDN_DECL godot_variant hgdn_new_variant(const godot_pool_real_array *value);
745 HGDN_DECL godot_variant hgdn_new_variant(const godot_pool_vector2_array *value);
746 HGDN_DECL godot_variant hgdn_new_variant(const godot_pool_vector3_array *value);
747 HGDN_DECL godot_variant hgdn_new_variant(const godot_pool_color_array *value);
748 HGDN_DECL godot_variant hgdn_new_variant(const godot_pool_string_array *value);
749 HGDN_DECL godot_variant hgdn_new_variant(godot_string value);
750 HGDN_DECL godot_variant hgdn_new_variant(godot_node_path value);
751 HGDN_DECL godot_variant hgdn_new_variant(godot_dictionary value);
752 HGDN_DECL godot_variant hgdn_new_variant(godot_array value);
753 HGDN_DECL godot_variant hgdn_new_variant(godot_pool_byte_array value);
754 HGDN_DECL godot_variant hgdn_new_variant(godot_pool_int_array value);
755 HGDN_DECL godot_variant hgdn_new_variant(godot_pool_real_array value);
756 HGDN_DECL godot_variant hgdn_new_variant(godot_pool_vector2_array value);
757 HGDN_DECL godot_variant hgdn_new_variant(godot_pool_vector3_array value);
758 HGDN_DECL godot_variant hgdn_new_variant(godot_pool_color_array value);
759 HGDN_DECL godot_variant hgdn_new_variant(godot_pool_string_array value);
760 HGDN_DECL godot_variant hgdn_new_variant(const godot_variant *value);
761 HGDN_DECL HGDN_CONSTEXPR godot_variant hgdn_new_variant(godot_variant value);
762}
763#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L // C11
765#define hgdn_new_variant(value) \
766 (_Generic((value), \
767 godot_bool: hgdn_new_bool_variant, \
768 unsigned int: hgdn_new_uint_variant, \
769 uint64_t: hgdn_new_uint_variant, \
770 int: hgdn_new_int_variant, \
771 int64_t: hgdn_new_int_variant, \
772 float: hgdn_new_real_variant, \
773 double: hgdn_new_real_variant, \
774 godot_string*: hgdn_new_string_variant, const godot_string*: hgdn_new_string_variant, \
775 char*: hgdn_new_cstring_variant, const char*: hgdn_new_cstring_variant, \
776 wchar_t*: hgdn_new_wide_string_variant, const wchar_t*: hgdn_new_wide_string_variant, \
777 godot_vector2: hgdn_new_vector2_variant, \
778 godot_vector3: hgdn_new_vector3_variant, \
779 godot_rect2: hgdn_new_rect2_variant, \
780 godot_plane: hgdn_new_plane_variant, \
781 godot_quat: hgdn_new_quat_variant, \
782 godot_aabb: hgdn_new_aabb_variant, \
783 godot_basis: hgdn_new_basis_variant, \
784 godot_transform2d: hgdn_new_transform2d_variant, \
785 godot_transform: hgdn_new_transform_variant, \
786 godot_color: hgdn_new_color_variant, \
787 godot_node_path*: hgdn_new_node_path_variant, const godot_node_path*: hgdn_new_node_path_variant, \
788 godot_rid*: hgdn_new_rid_variant, const godot_rid*: hgdn_new_rid_variant, \
789 godot_object*: hgdn_new_object_variant, const godot_object*: hgdn_new_object_variant, \
790 godot_dictionary*: hgdn_new_dictionary_variant, const godot_dictionary*: hgdn_new_dictionary_variant, \
791 godot_array*: hgdn_new_array_variant, const godot_array*: hgdn_new_array_variant, \
792 godot_pool_byte_array*: hgdn_new_pool_byte_array_variant, const godot_pool_byte_array*: hgdn_new_pool_byte_array_variant, \
793 godot_pool_int_array*: hgdn_new_pool_int_array_variant, const godot_pool_int_array*: hgdn_new_pool_int_array_variant, \
794 godot_pool_real_array*: hgdn_new_pool_real_array_variant, const godot_pool_real_array*: hgdn_new_pool_real_array_variant, \
795 godot_pool_vector2_array*: hgdn_new_pool_vector2_array_variant, const godot_pool_vector2_array*: hgdn_new_pool_vector2_array_variant, \
796 godot_pool_vector3_array*: hgdn_new_pool_vector3_array_variant, const godot_pool_vector3_array*: hgdn_new_pool_vector3_array_variant, \
797 godot_pool_color_array*: hgdn_new_pool_color_array_variant, const godot_pool_color_array*: hgdn_new_pool_color_array_variant, \
798 godot_pool_string_array*: hgdn_new_pool_string_array_variant, const godot_pool_string_array*: hgdn_new_pool_string_array_variant, \
799 godot_string: hgdn_new_string_variant_own, \
800 godot_node_path: hgdn_new_node_path_variant_own, \
801 godot_dictionary: hgdn_new_dictionary_variant_own, \
802 godot_array: hgdn_new_array_variant_own, \
803 godot_pool_byte_array: hgdn_new_pool_byte_array_variant_own, \
804 godot_pool_int_array: hgdn_new_pool_int_array_variant_own, \
805 godot_pool_real_array: hgdn_new_pool_real_array_variant_own, \
806 godot_pool_vector2_array: hgdn_new_pool_vector2_array_variant_own, \
807 godot_pool_vector3_array: hgdn_new_pool_vector3_array_variant_own, \
808 godot_pool_color_array: hgdn_new_pool_color_array_variant_own, \
809 godot_pool_string_array: hgdn_new_pool_string_array_variant_own, \
810 godot_variant*: hgdn_new_variant_copy, const godot_variant*: hgdn_new_variant_copy, \
811 godot_variant: hgdn__variant_return \
812 )(value))
813HGDN_DECL godot_variant hgdn__variant_return(godot_variant value);
814#else
815#define hgdn_new_variant(value) (value) // No transformations in C without C11 support
816#endif
818
819
823HGDN_DECL godot_string hgdn_new_string(const char *cstr);
824HGDN_DECL godot_string hgdn_new_string_with_len(const char *cstr, const godot_int len);
826HGDN_DECL godot_string hgdn_new_formatted_string(const char *fmt, ...);
827
828HGDN_DECL godot_string hgdn_new_wide_string(const wchar_t *wstr);
829HGDN_DECL godot_string hgdn_new_wide_string_with_len(const wchar_t *wstr, const godot_int len);
831
832
839HGDN_DECL godot_pool_byte_array hgdn_new_byte_array(const uint8_t *buffer, const godot_int size);
840HGDN_DECL godot_pool_int_array hgdn_new_int_array(const godot_int *buffer, const godot_int size);
841HGDN_DECL godot_pool_real_array hgdn_new_real_array(const godot_real *buffer, const godot_int size);
842HGDN_DECL godot_pool_vector2_array hgdn_new_vector2_array(const godot_vector2 *buffer, const godot_int size);
843HGDN_DECL godot_pool_vector3_array hgdn_new_vector3_array(const godot_vector3 *buffer, const godot_int size);
844HGDN_DECL godot_pool_color_array hgdn_new_color_array(const godot_color *buffer, const godot_int size);
846HGDN_DECL godot_pool_string_array hgdn_new_string_array(const char *const *buffer, const godot_int size);
847HGDN_DECL godot_array hgdn_new_array(const godot_variant *const *buffer, const godot_int size);
849HGDN_DECL godot_array hgdn_new_array_own(godot_variant *buffer, const godot_int size);
850
851#if defined(__cplusplus) && __cplusplus >= 201103L // Parameter pack is a C++11 feature
852extern "C++" {
853 template<typename... Args> godot_pool_byte_array hgdn_new_byte_array_args(Args... args) {
854 uint8_t buffer[] = { args... };
855 return hgdn_new_byte_array(buffer, sizeof...(args));
856 }
857 template<typename... Args> godot_pool_int_array hgdn_new_int_array_args(Args... args) {
858 godot_int buffer[] = { args... };
859 return hgdn_new_int_array(buffer, sizeof...(args));
860 }
861 template<typename... Args> godot_pool_real_array hgdn_new_real_array_args(Args... args) {
862 godot_real buffer[] = { args... };
863 return hgdn_new_real_array(buffer, sizeof...(args));
864 }
865 template<typename... Args> godot_pool_vector2_array hgdn_new_vector2_array_args(Args... args) {
866 godot_vector2 buffer[] = { args... };
867 return hgdn_new_vector2_array(buffer, sizeof...(args));
868 }
869 template<typename... Args> godot_pool_vector3_array hgdn_new_vector3_array_args(Args... args) {
870 godot_vector3 buffer[] = { args... };
871 return hgdn_new_vector3_array(buffer, sizeof...(args));
872 }
873 template<typename... Args> godot_pool_color_array hgdn_new_color_array_args(Args... args) {
874 godot_color buffer[] = { args... };
875 return hgdn_new_color_array(buffer, sizeof...(args));
876 }
877 template<typename... Args> godot_pool_string_array hgdn_new_string_array_args(Args... args) {
878 const char *const buffer[] = { args... };
879 return hgdn_new_string_array(buffer, sizeof...(args));
880 }
881 template<typename... Args> godot_array hgdn_new_array_args(Args... args) {
882 godot_variant buffer[] = { hgdn_new_variant(args)... };
883 return hgdn_new_array_own(buffer, sizeof...(args));
884 }
885}
886#else
887 #define hgdn_new_byte_array_args(...) (hgdn_new_byte_array((const uint8_t[]){ __VA_ARGS__ }, HGDN__NARG(__VA_ARGS__)))
888 #define hgdn_new_int_array_args(...) (hgdn_new_int_array((const godot_int[]){ __VA_ARGS__ }, HGDN__NARG(__VA_ARGS__)))
889 #define hgdn_new_real_array_args(...) (hgdn_new_real_array((const godot_real[]){ __VA_ARGS__ }, HGDN__NARG(__VA_ARGS__)))
890 #define hgdn_new_vector2_array_args(...) (hgdn_new_vector2_array((const godot_vector2[]){ __VA_ARGS__ }, HGDN__NARG(__VA_ARGS__)))
891 #define hgdn_new_vector3_array_args(...) (hgdn_new_vector3_array((const godot_vector3[]){ __VA_ARGS__ }, HGDN__NARG(__VA_ARGS__)))
892 #define hgdn_new_color_array_args(...) (hgdn_new_color_array((const godot_color[]){ __VA_ARGS__ }, HGDN__NARG(__VA_ARGS__)))
893 #define hgdn_new_string_array_args(...) (hgdn_new_string_array((const char *const []){ __VA_ARGS__ }, HGDN__NARG(__VA_ARGS__)))
895 #define hgdn_new_array_args(...) (hgdn_new_array_own((godot_variant[]){ HGDN__MAP(hgdn_new_variant, __VA_ARGS__) }, HGDN__NARG(__VA_ARGS__)))
896#endif
898
899
906typedef struct hgdn_dictionary_entry {
907 godot_variant *key, *value;
909
911 godot_variant key, value;
913
915 const char *key;
916 godot_variant *value;
918
920 const char *key;
921 godot_variant value;
923
925 const char *key, *value;
927
929 const char *key;
930 godot_int value;
932
933HGDN_DECL godot_dictionary hgdn_new_dictionary(const hgdn_dictionary_entry *buffer, const godot_int size);
934HGDN_DECL godot_dictionary hgdn_new_dictionary_string(const hgdn_dictionary_entry_string *buffer, const godot_int size);
935HGDN_DECL godot_dictionary hgdn_new_dictionary_string_int(const hgdn_dictionary_entry_string_int *buffer, const godot_int size);
936HGDN_DECL godot_dictionary hgdn_new_dictionary_string_string(const hgdn_dictionary_entry_string_string *buffer, const godot_int size);
937HGDN_DECL godot_dictionary hgdn_new_dictionary_own(hgdn_dictionary_entry_own *buffer, const godot_int size);
938HGDN_DECL godot_dictionary hgdn_new_dictionary_string_own(hgdn_dictionary_entry_string_own *buffer, const godot_int size);
939
940#define hgdn_new_dictionary_args(...) (hgdn_new_dictionary((const hgdn_dictionary_entry[]){ __VA_ARGS__ }, HGDN__NARG(__VA_ARGS__)))
941#define hgdn_new_dictionary_string_args(...) (hgdn_new_dictionary_string((const hgdn_dictionary_entry_string[]){ __VA_ARGS__ }, HGDN__NARG(__VA_ARGS__)))
942#define hgdn_new_dictionary_string_int_args(...) (hgdn_new_dictionary_string_int((const hgdn_dictionary_entry_string_int[]){ __VA_ARGS__ }, HGDN__NARG(__VA_ARGS__)))
943#define hgdn_new_dictionary_string_string_args(...) (hgdn_new_dictionary_string_string((const hgdn_dictionary_entry_string_string[]){ __VA_ARGS__ }, HGDN__NARG(__VA_ARGS__)))
944#define hgdn_new_dictionary_own_args(...) (hgdn_new_dictionary_own((hgdn_dictionary_entry_own[]){ __VA_ARGS__ }, HGDN__NARG(__VA_ARGS__)))
945#define hgdn_new_dictionary_string_own_args(...) (hgdn_new_dictionary_string_own((hgdn_dictionary_entry_string_own[]){ __VA_ARGS__ }, HGDN__NARG(__VA_ARGS__)))
947
948
952HGDN_DECL godot_variant hgdn_object_callv(godot_object *instance, const char *method, const godot_array *args);
953HGDN_DECL godot_variant hgdn_object_callv_own(godot_object *instance, const char *method, godot_array args);
954#define hgdn_object_get(instance, property) (hgdn_object_call(instance, "get", property))
955#define hgdn_object_set(instance, property, value) (hgdn_object_call(instance, "set", property, value))
956
957#if defined(__cplusplus) && __cplusplus >= 201103L // Parameter pack is a C++11 feature
958extern "C++" template<typename... Args> godot_variant hgdn_object_call(godot_object *instance, const char *method, Args... args) {
959 godot_array args_array = hgdn_new_array_args(args...);
960 return hgdn_object_callv_own(instance, method, args_array);
961}
962#else
964#define hgdn_object_call(instance, method, ...) (hgdn_object_callv_own((instance), (method), hgdn_new_array_args(__VA_ARGS__)))
965#endif
967
968
972#ifndef HGDN_NO_EXT_NATIVESCRIPT
973typedef struct hgdn_property_info {
974 const char *path;
975 godot_property_set_func setter;
976 godot_property_get_func getter;
977 // godot_property_attributes
978 godot_int type;
979 godot_property_hint hint;
980 const char *hint_string;
981 godot_property_usage_flags usage;
982 godot_variant default_value;
983 godot_method_rpc_mode rset_type;
985 const char *documentation;
987
989 const char *name;
990 godot_variant_type type;
991 godot_property_hint hint;
992 const char *hint_string;
994
995typedef struct hgdn_method_info {
996 const char *name;
997 godot_instance_method method;
998 // godot_method_attributes
999 godot_method_rpc_mode rpc_type;
1001 const char *documentation;
1007
1009 const char *name;
1010 godot_int type;
1011 godot_property_hint hint;
1012 const char *hint_string;
1013 godot_variant default_value;
1015
1016typedef struct hgdn_signal_info {
1017 const char *name;
1018 hgdn_signal_argument_info *arguments_info;
1019 int num_default_args;
1021 const char *documentation;
1023
1024typedef struct hgdn_class_info {
1025 const char *name;
1026 const char *base;
1027 godot_instance_create_func create;
1028 godot_instance_destroy_func destroy;
1041 godot_bool tool;
1043 const char *documentation;
1045
1047#define hgdn_properties(...) ((hgdn_property_info[]){ __VA_ARGS__, {} })
1049#define hgdn_methods(...) ((hgdn_method_info[]){ __VA_ARGS__, {} })
1051#define hgdn_method_arguments(...) ((hgdn_method_argument_info[]){ __VA_ARGS__, {} })
1053#define hgdn_signals(...) ((hgdn_signal_info[]){ __VA_ARGS__, {} })
1055#define hgdn_signal_arguments(...) ((hgdn_signal_argument_info[]){ __VA_ARGS__, {} })
1056
1057HGDN_DECL void hgdn_register_class(void *gdnative_handle, const hgdn_class_info *class_info);
1058
1060HGDN_DECL void *hgdn_instance_alloc(godot_object *instance, void *alloc_size);
1062#define hgdn_instance_create_func_alloc(ctype) ((const godot_instance_create_func){ &hgdn_instance_alloc, (void *) sizeof(ctype) })
1064HGDN_DECL void hgdn_instance_free(godot_object *instance, void *method_data, void *data);
1066#define hgdn_instance_destroy_func_free() ((const godot_instance_destroy_func){ &hgdn_instance_free })
1067
1068HGDN_DECL godot_variant *hgdn_property_constant_alloc(godot_variant value);
1069HGDN_DECL void hgdn_property_constant_free(void *value);
1070HGDN_DECL godot_variant hgdn_property_constant_get(godot_object *instance, void *value, void *data);
1072#define hgdn_property_constant(value) ((const godot_property_get_func){ &hgdn_property_constant_get, (void *) hgdn_property_constant_alloc(hgdn_new_variant((value))), &hgdn_property_constant_free })
1073#endif // HGDN_NO_EXT_NATIVESCRIPT
1075
1076#ifdef __cplusplus
1077}
1078#endif
1079
1080#endif // __HGDN_H__
1081
1083
1084#ifdef HGDN_IMPLEMENTATION
1085
1086#include <stdarg.h>
1087#include <stdio.h>
1088#include <string.h>
1089
1090const godot_gdnative_core_api_struct *hgdn_core_api;
1091#ifndef HGDN_NO_CORE_1_1
1092const godot_gdnative_core_1_1_api_struct *hgdn_core_1_1_api;
1093#endif
1094#ifndef HGDN_NO_CORE_1_2
1095const godot_gdnative_core_1_2_api_struct *hgdn_core_1_2_api;
1096#endif
1097#ifndef HGDN_NO_CORE_1_3
1098const godot_gdnative_core_1_3_api_struct *hgdn_core_1_3_api;
1099#endif
1100#ifndef HGDN_NO_EXT_NATIVESCRIPT
1101const godot_gdnative_ext_nativescript_api_struct *hgdn_nativescript_api;
1102const godot_gdnative_ext_nativescript_1_1_api_struct *hgdn_nativescript_1_1_api;
1103#endif
1104#ifndef HGDN_NO_EXT_PLUGINSCRIPT
1105const godot_gdnative_ext_pluginscript_api_struct *hgdn_pluginscript_api;
1106#endif
1107#ifndef HGDN_NO_EXT_ANDROID
1108const godot_gdnative_ext_android_api_struct *hgdn_android_api;
1109#endif
1110#ifndef HGDN_NO_EXT_ARVR
1111const godot_gdnative_ext_arvr_api_struct *hgdn_arvr_api;
1112const godot_gdnative_ext_arvr_1_2_api_struct *hgdn_arvr_1_2_api;
1113#endif
1114#ifndef HGDN_NO_EXT_VIDEOCODER
1115const godot_gdnative_ext_videodecoder_api_struct *hgdn_videodecoder_api;
1116#endif
1117#ifndef HGDN_NO_EXT_NET
1118const godot_gdnative_ext_net_api_struct *hgdn_net_api;
1119const godot_gdnative_ext_net_3_2_api_struct *hgdn_net_3_2_api;
1120#endif
1121godot_object *hgdn_library;
1122godot_method_bind *hgdn_method_Object_callv;
1123
1124static char hgdn__format_string_buffer[HGDN_STRING_FORMAT_BUFFER_SIZE];
1125#define HGDN__FILL_FORMAT_BUFFER(fmt, ...) \
1126 va_list args; \
1127 va_start(args, fmt); \
1128 godot_int size = vsnprintf(hgdn__format_string_buffer, HGDN_STRING_FORMAT_BUFFER_SIZE, fmt, args); \
1129 if (size > HGDN_STRING_FORMAT_BUFFER_SIZE) { \
1130 size = HGDN_STRING_FORMAT_BUFFER_SIZE; \
1131 } \
1132 va_end(args)
1133
1134static godot_array hgdn__empty_array;
1135
1136// Init and terminate
1137void hgdn_gdnative_init(const godot_gdnative_init_options *options) {
1138 hgdn_library = options->gd_native_library;
1139 hgdn_core_api = options->api_struct;
1140 for (const godot_gdnative_api_struct *ext = hgdn_core_api->next; ext; ext = ext->next) {
1141#ifndef HGDN_NO_CORE_1_1
1142 if (ext->version.major == 1 && ext->version.minor == 1) {
1143 hgdn_core_1_1_api = (const godot_gdnative_core_1_1_api_struct *) ext;
1144 }
1145#endif
1146#ifndef HGDN_NO_CORE_1_2
1147 if (ext->version.major == 1 && ext->version.minor == 2) {
1148 hgdn_core_1_2_api = (const godot_gdnative_core_1_2_api_struct *) ext;
1149 }
1150#endif
1151#ifndef HGDN_NO_CORE_1_3
1152 if (ext->version.major == 1 && ext->version.minor == 3) {
1153 hgdn_core_1_3_api = (const godot_gdnative_core_1_3_api_struct *) ext;
1154 }
1155#endif
1156 }
1157
1158 for (unsigned int i = 0; i < hgdn_core_api->num_extensions; i++) {
1159 switch(hgdn_core_api->extensions[i]->type) {
1160#ifndef HGDN_NO_EXT_NATIVESCRIPT
1161 case GDNATIVE_EXT_NATIVESCRIPT:
1162 hgdn_nativescript_api = (const godot_gdnative_ext_nativescript_api_struct *) hgdn_core_api->extensions[i];
1163 for (const godot_gdnative_api_struct *ext = hgdn_nativescript_api->next; ext; ext = ext->next) {
1164 if (ext->version.major == 1 && ext->version.minor == 1) {
1165 hgdn_nativescript_1_1_api = (const godot_gdnative_ext_nativescript_1_1_api_struct *) ext;
1166 }
1167 }
1168 break;
1169#endif
1170#ifndef HGDN_NO_EXT_PLUGINSCRIPT
1171 case GDNATIVE_EXT_PLUGINSCRIPT:
1172 hgdn_pluginscript_api = (const godot_gdnative_ext_pluginscript_api_struct *) hgdn_core_api->extensions[i];
1173 break;
1174#endif
1175#ifndef HGDN_NO_EXT_ANDROID
1176 case GDNATIVE_EXT_ANDROID:
1177 hgdn_android_api = (const godot_gdnative_ext_android_api_struct *) hgdn_core_api->extensions[i];
1178 break;
1179#endif
1180#ifndef HGDN_NO_EXT_ARVR
1181 case GDNATIVE_EXT_ARVR:
1182 hgdn_arvr_api = (const godot_gdnative_ext_arvr_api_struct *) hgdn_core_api->extensions[i];
1183 for (const godot_gdnative_api_struct *ext = hgdn_arvr_api->next; ext; ext = ext->next) {
1184 if (ext->version.major == 1 && ext->version.minor == 2) {
1185 hgdn_arvr_1_2_api = (const godot_gdnative_ext_arvr_1_2_api_struct *) ext;
1186 }
1187 }
1188 break;
1189#endif
1190#ifndef HGDN_NO_EXT_VIDEOCODER
1191 case GDNATIVE_EXT_VIDEODECODER:
1192 hgdn_videodecoder_api = (const godot_gdnative_ext_videodecoder_api_struct *) hgdn_core_api->extensions[i];
1193 break;
1194#endif
1195#ifndef HGDN_NO_EXT_NET
1196 case GDNATIVE_EXT_NET:
1197 hgdn_net_api = (const godot_gdnative_ext_net_api_struct *) hgdn_core_api->extensions[i];
1198 for (const godot_gdnative_api_struct *ext = hgdn_net_api->next; ext; ext = ext->next) {
1199 if (ext->version.major == 3 && ext->version.minor == 2) {
1200 hgdn_net_3_2_api = (const godot_gdnative_ext_net_3_2_api_struct *) ext;
1201 }
1202 }
1203 break;
1204#endif
1205 default:
1206 break;
1207 }
1208 }
1209
1210 hgdn_method_Object_callv = hgdn_core_api->godot_method_bind_get_method("Object", "callv");
1211 hgdn_core_api->godot_array_new(&hgdn__empty_array);
1212}
1213
1214void hgdn_gdnative_terminate(const godot_gdnative_terminate_options *options) {
1215 hgdn_core_api->godot_array_destroy(&hgdn__empty_array);
1216}
1217
1218// Memory API
1219void *hgdn_alloc(size_t size) {
1220 return hgdn_core_api->godot_alloc(size);
1221}
1222
1223void *hgdn_realloc(void *ptr, size_t size) {
1224 return hgdn_core_api->godot_realloc(ptr, size);
1225}
1226
1227void hgdn_free(void *ptr) {
1228 if (ptr) {
1229 hgdn_core_api->godot_free(ptr);
1230 }
1231}
1232
1233// Print functions
1234void hgdn_print(const char *fmt, ...) {
1235 HGDN__FILL_FORMAT_BUFFER(fmt, ...);
1236 godot_string str = hgdn_new_string_with_len(hgdn__format_string_buffer, size);
1237 hgdn_core_api->godot_print(&str);
1238 hgdn_core_api->godot_string_destroy(&str);
1239}
1240
1241void hgdn_print_warning(const char *funcname, const char *filename, int line, const char *fmt, ...) {
1242 HGDN__FILL_FORMAT_BUFFER(fmt, ...);
1243 hgdn_core_api->godot_print_warning(hgdn__format_string_buffer, funcname, filename, line);
1244}
1245
1246void hgdn_print_error(const char *funcname, const char *filename, int line, const char *fmt, ...) {
1247 HGDN__FILL_FORMAT_BUFFER(fmt, ...);
1248 hgdn_core_api->godot_print_error(hgdn__format_string_buffer, funcname, filename, line);
1249}
1250
1251// String creation API
1252godot_string hgdn_new_wide_string(const wchar_t *wstr) {
1253 godot_string str;
1254 hgdn_core_api->godot_string_new_with_wide_string(&str, wstr, -1);
1255 return str;
1256}
1257
1258godot_string hgdn_new_wide_string_with_len(const wchar_t *wstr, const godot_int len) {
1259 godot_string str;
1260 hgdn_core_api->godot_string_new_with_wide_string(&str, wstr, len);
1261 return str;
1262}
1263
1264godot_string hgdn_new_string(const char *cstr) {
1265 return hgdn_core_api->godot_string_chars_to_utf8(cstr);
1266}
1267
1268godot_string hgdn_new_string_with_len(const char *cstr, const godot_int len) {
1269 return hgdn_core_api->godot_string_chars_to_utf8_with_len(cstr, len);
1270}
1271
1272godot_string hgdn_new_formatted_string(const char *fmt, ...) {
1273 HGDN__FILL_FORMAT_BUFFER(fmt, ...);
1274 return hgdn_new_string_with_len(hgdn__format_string_buffer, size);
1275}
1276
1277// Array creation API
1278#define HGDN_DECLARE_NEW_POOL_ARRAY_FUNC(kind, ctype) \
1279 godot_pool_##kind##_array hgdn_new_##kind##_array(const ctype *buffer, const godot_int size) { \
1280 godot_pool_##kind##_array array; \
1281 hgdn_core_api->godot_pool_##kind##_array_new(&array); \
1282 hgdn_core_api->godot_pool_##kind##_array_resize(&array, size); \
1283 godot_pool_##kind##_array_write_access *write = hgdn_core_api->godot_pool_##kind##_array_write(&array); \
1284 memcpy(hgdn_core_api->godot_pool_##kind##_array_write_access_ptr(write), buffer, size * sizeof(ctype)); \
1285 hgdn_core_api->godot_pool_##kind##_array_write_access_destroy(write); \
1286 return array; \
1287 }
1288
1289HGDN_DECLARE_NEW_POOL_ARRAY_FUNC(byte, uint8_t) // hgdn_new_byte_array
1290HGDN_DECLARE_NEW_POOL_ARRAY_FUNC(int, godot_int) // hgdn_new_int_array
1291HGDN_DECLARE_NEW_POOL_ARRAY_FUNC(real, godot_real) // hgdn_new_real_array
1292HGDN_DECLARE_NEW_POOL_ARRAY_FUNC(vector2, godot_vector2) // hgdn_new_vector2_array
1293HGDN_DECLARE_NEW_POOL_ARRAY_FUNC(vector3, godot_vector3) // hgdn_new_vector3_array
1294HGDN_DECLARE_NEW_POOL_ARRAY_FUNC(color, godot_color) // hgdn_new_color_array
1295
1296godot_pool_string_array hgdn_new_string_array(const char *const *buffer, const godot_int size) {
1297 godot_pool_string_array array;
1298 hgdn_core_api->godot_pool_string_array_new(&array);
1299 hgdn_core_api->godot_pool_string_array_resize(&array, size);
1300 for (godot_int i = 0; i < size; i++) {
1301 godot_string str = hgdn_core_api->godot_string_chars_to_utf8(buffer[i]);
1302 hgdn_core_api->godot_pool_string_array_set(&array, i, &str);
1303 hgdn_core_api->godot_string_destroy(&str);
1304 }
1305 return array;
1306}
1307
1308#undef HGDN_DECLARE_NEW_POOL_ARRAY_FUNC
1309
1310godot_array hgdn_new_array(const godot_variant *const *buffer, const godot_int size) {
1311 godot_array array;
1312 hgdn_core_api->godot_array_new(&array);
1313 hgdn_core_api->godot_array_resize(&array, size);
1314 for (godot_int i = 0; i < size; i++) {
1315 hgdn_core_api->godot_array_set(&array, i, buffer[i]);
1316 }
1317 return array;
1318}
1319
1320godot_array hgdn_new_array_own(godot_variant *buffer, const godot_int size) {
1321 godot_array array;
1322 hgdn_core_api->godot_array_new(&array);
1323 hgdn_core_api->godot_array_resize(&array, size);
1324 for (godot_int i = 0; i < size; i++) {
1325 godot_variant *var = &buffer[i];
1326 hgdn_core_api->godot_array_set(&array, i, var);
1327 hgdn_core_api->godot_variant_destroy(var);
1328 }
1329 return array;
1330}
1331
1332// Dictionary creation API
1333godot_dictionary hgdn_new_dictionary(const hgdn_dictionary_entry *buffer, const godot_int size) {
1334 godot_dictionary dict;
1335 hgdn_core_api->godot_dictionary_new(&dict);
1336 for (godot_int i = 0; i < size; i++) {
1337 hgdn_core_api->godot_dictionary_set(&dict, buffer[i].key, buffer[i].value);
1338 }
1339 return dict;
1340}
1341
1342godot_dictionary hgdn_new_dictionary_string(const hgdn_dictionary_entry_string *buffer, const godot_int size) {
1343 godot_dictionary dict;
1344 hgdn_core_api->godot_dictionary_new(&dict);
1345 for (godot_int i = 0; i < size; i++) {
1346 godot_variant key = hgdn_new_string_variant_own(hgdn_new_string(buffer[i].key));
1347 hgdn_core_api->godot_dictionary_set(&dict, &key, buffer[i].value);
1348 hgdn_core_api->godot_variant_destroy(&key);
1349 }
1350 return dict;
1351}
1352
1353godot_dictionary hgdn_new_dictionary_string_int(const hgdn_dictionary_entry_string_int *buffer, const godot_int size) {
1354 godot_dictionary dict;
1355 hgdn_core_api->godot_dictionary_new(&dict);
1356 for (godot_int i = 0; i < size; i++) {
1357 godot_variant key = hgdn_new_string_variant_own(hgdn_new_string(buffer[i].key));
1358 godot_variant value = hgdn_new_int_variant(buffer[i].value);
1359 hgdn_core_api->godot_dictionary_set(&dict, &key, &value);
1360 hgdn_core_api->godot_variant_destroy(&key);
1361 hgdn_core_api->godot_variant_destroy(&value);
1362 }
1363 return dict;
1364}
1365
1366godot_dictionary hgdn_new_dictionary_string_string(const hgdn_dictionary_entry_string_string *buffer, const godot_int size) {
1367 godot_dictionary dict;
1368 hgdn_core_api->godot_dictionary_new(&dict);
1369 for (godot_int i = 0; i < size; i++) {
1370 godot_variant key = hgdn_new_string_variant_own(hgdn_new_string(buffer[i].key));
1371 godot_variant value = hgdn_new_string_variant_own(hgdn_new_string(buffer[i].value));
1372 hgdn_core_api->godot_dictionary_set(&dict, &key, &value);
1373 hgdn_core_api->godot_variant_destroy(&key);
1374 hgdn_core_api->godot_variant_destroy(&value);
1375 }
1376 return dict;
1377}
1378
1379godot_dictionary hgdn_new_dictionary_own(hgdn_dictionary_entry_own *buffer, const godot_int size) {
1380 godot_dictionary dict;
1381 hgdn_core_api->godot_dictionary_new(&dict);
1382 for (godot_int i = 0; i < size; i++) {
1383 hgdn_core_api->godot_dictionary_set(&dict, &buffer[i].key, &buffer[i].value);
1384 hgdn_core_api->godot_variant_destroy(&buffer[i].key);
1385 hgdn_core_api->godot_variant_destroy(&buffer[i].value);
1386 }
1387 return dict;
1388}
1389
1390godot_dictionary hgdn_new_dictionary_string_own(hgdn_dictionary_entry_string_own *buffer, const godot_int size) {
1391 godot_dictionary dict;
1392 hgdn_core_api->godot_dictionary_new(&dict);
1393 for (godot_int i = 0; i < size; i++) {
1394 godot_variant key = hgdn_new_string_variant_own(hgdn_new_string(buffer[i].key));
1395 hgdn_core_api->godot_dictionary_set(&dict, &key, &buffer[i].value);
1396 hgdn_core_api->godot_variant_destroy(&key);
1397 hgdn_core_api->godot_variant_destroy(&buffer[i].value);
1398 }
1399 return dict;
1400}
1401
1402// String helpers
1403hgdn_wide_string hgdn_wide_string_get(const godot_string *str) {
1404 godot_string new_str;
1405 hgdn_core_api->godot_string_new_copy(&new_str, str);
1406 return hgdn_wide_string_get_own(new_str);
1407}
1408
1409hgdn_wide_string hgdn_wide_string_get_own(godot_string str) {
1410 hgdn_wide_string wrapper = {
1411 str,
1412 hgdn_core_api->godot_string_wide_str(&str),
1413 hgdn_core_api->godot_string_length(&str),
1414 };
1415 return wrapper;
1416}
1417
1418void hgdn_wide_string_destroy(hgdn_wide_string *str) {
1419 hgdn_core_api->godot_string_destroy(&str->gd_string);
1420}
1421
1422hgdn_string hgdn_string_get(const godot_string *str) {
1423 godot_char_string char_string = hgdn_core_api->godot_string_utf8(str);
1424 hgdn_string wrapper = {
1425 char_string,
1426 hgdn_core_api->godot_char_string_get_data(&char_string),
1427 hgdn_core_api->godot_char_string_length(&char_string),
1428 };
1429 return wrapper;
1430}
1431
1432hgdn_string hgdn_string_get_own(godot_string str) {
1433 hgdn_string wrapper = hgdn_string_get(&str);
1434 hgdn_core_api->godot_string_destroy(&str);
1435 return wrapper;
1436}
1437
1438void hgdn_string_destroy(hgdn_string *str) {
1439 hgdn_core_api->godot_char_string_destroy(&str->gd_char_string);
1440}
1441
1442// Pool String helpers
1443#define HGDN_DECLARE_POOL_ARRAY_API(kind, ctype) \
1444 hgdn_##kind##_array hgdn_##kind##_array_get(const godot_pool_##kind##_array *array) { \
1445 godot_pool_##kind##_array_read_access *access = hgdn_core_api->godot_pool_##kind##_array_read(array); \
1446 hgdn_##kind##_array wrapper = { \
1447 access, \
1448 hgdn_core_api->godot_pool_##kind##_array_read_access_ptr(access), \
1449 hgdn_core_api->godot_pool_##kind##_array_size(array), \
1450 }; \
1451 return wrapper; \
1452 } \
1453 hgdn_##kind##_array hgdn_##kind##_array_get_own(godot_pool_##kind##_array array) { \
1454 hgdn_##kind##_array result = hgdn_##kind##_array_get(&array); \
1455 hgdn_core_api->godot_pool_##kind##_array_destroy(&array); \
1456 return result; \
1457 } \
1458 void hgdn_##kind##_array_destroy(hgdn_##kind##_array *array) { \
1459 hgdn_core_api->godot_pool_##kind##_array_read_access_destroy(array->gd_read_access); \
1460 }
1461
1462HGDN_DECLARE_POOL_ARRAY_API(byte, uint8_t) // hgdn_byte_array_get, hgdn_byte_array_get_own, hgdn_byte_array_destroy
1463HGDN_DECLARE_POOL_ARRAY_API(int, godot_int) // hgdn_int_array_get, hgdn_int_array_get_own, hgdn_int_array_destroy
1464HGDN_DECLARE_POOL_ARRAY_API(real, godot_real) // hgdn_real_array_get, hgdn_real_array_get_own, hgdn_real_array_destroy
1465HGDN_DECLARE_POOL_ARRAY_API(vector2, godot_vector2) // hgdn_vector2_array_get, hgdn_vector2_array_get_own, hgdn_vector2_array_destroy
1466HGDN_DECLARE_POOL_ARRAY_API(vector3, godot_vector3) // hgdn_vector3_array_get, hgdn_vector3_array_get_own, hgdn_vector3_array_destroy
1467HGDN_DECLARE_POOL_ARRAY_API(color, godot_color) // hgdn_color_array_get, hgdn_color_array_get_own, hgdn_color_array_destroy
1468
1469#undef HGDN_DECLARE_POOL_ARRAY_API
1470
1471hgdn_string_array hgdn_string_array_get(const godot_pool_string_array *array) {
1472 godot_int size = hgdn_core_api->godot_pool_string_array_size(array);
1473 godot_pool_string_array_read_access *access = hgdn_core_api->godot_pool_string_array_read(array);
1474 hgdn_string_array wrapper = {0};
1475 if ((wrapper.strings = (hgdn_string *) hgdn_alloc(size * sizeof(hgdn_string))) == NULL) {
1476 return wrapper;
1477 }
1478 if ((wrapper.ptr = (const char **) hgdn_alloc(size * sizeof(char *))) == NULL) {
1479 hgdn_free(wrapper.strings);
1480 return wrapper;
1481 }
1482 wrapper.size = size;
1483 const godot_string *gd_strings = hgdn_core_api->godot_pool_string_array_read_access_ptr(access);
1484 for (godot_int i = 0; i < size; i++) {
1485 hgdn_string str = hgdn_string_get(&gd_strings[i]);
1486 wrapper.strings[i] = str;
1487 wrapper.ptr[i] = str.ptr;
1488 }
1489 hgdn_core_api->godot_pool_string_array_read_access_destroy(access);
1490 return wrapper;
1491}
1492
1493hgdn_string_array hgdn_string_array_get_own(godot_pool_string_array array) {
1494 hgdn_string_array result = hgdn_string_array_get(&array);
1495 hgdn_core_api->godot_pool_string_array_destroy(&array);
1496 return result;
1497}
1498
1499void hgdn_string_array_destroy(hgdn_string_array *array) {
1500 for (godot_int i = 0; i < array->size; i++) {
1501 hgdn_string_destroy(&array->strings[i]);
1502 }
1503 hgdn_free(array->strings);
1504 hgdn_free((void *) array->ptr);
1505}
1506
1507// Get values from Variant, Array, Dictionary and method arguments helpers
1508#define HGDN_DECLARE_VARIANT_GET(kind, ctype) \
1509 ctype hgdn_variant_get_##kind(const godot_variant *var) { \
1510 return hgdn_core_api->godot_variant_as_##kind(var); \
1511 }
1512#define HGDN_DECLARE_VARIANT_GET_OWN(kind, ctype) \
1513 ctype hgdn_variant_get_##kind##_own(godot_variant var) { \
1514 ctype result = hgdn_variant_get_##kind(&var); \
1515 hgdn_core_api->godot_variant_destroy(&var); \
1516 return result; \
1517 }
1518#define HGDN_DECLARE_ARRAY_GET(kind, ctype) \
1519 ctype hgdn_array_get_##kind(const godot_array *array, const godot_int index) { \
1520 return hgdn_variant_get_##kind(hgdn_core_api->godot_array_operator_index_const(array, index)); \
1521 }
1522#define HGDN_DECLARE_ARGS_GET(kind, ctype) \
1523 ctype hgdn_args_get_##kind(godot_variant **args, const godot_int index) { \
1524 return hgdn_variant_get_##kind(args[index]); \
1525 }
1526#define HGDN_DECLARE_DICTIONARY_GET(kind, ctype) \
1527 ctype hgdn_dictionary_get_##kind(const godot_dictionary *dict, const godot_variant *key) { \
1528 return hgdn_variant_get_##kind(hgdn_core_api->godot_dictionary_operator_index_const(dict, key)); \
1529 } \
1530 ctype hgdn_dictionary_string_get_##kind(const godot_dictionary *dict, const char *key) { \
1531 godot_variant key_var = hgdn_new_cstring_variant(key); \
1532 ctype value = hgdn_dictionary_get_##kind(dict, &key_var); \
1533 hgdn_core_api->godot_variant_destroy(&key_var); \
1534 return value; \
1535 }
1536
1537HGDN_DECLARE_VARIANT_GET(bool, godot_bool) // hgdn_variant_get_bool
1538HGDN_DECLARE_VARIANT_GET_OWN(bool, godot_bool) // hgdn_variant_get_bool_own
1539HGDN_DECLARE_ARRAY_GET(bool, godot_bool) // hgdn_array_get_bool
1540HGDN_DECLARE_ARGS_GET(bool, godot_bool) // hgdn_args_get_bool
1541HGDN_DECLARE_DICTIONARY_GET(bool, godot_bool) // hgdn_dictionary_get_bool, hgdn_dictionary_string_get_bool
1542
1543#define HGDN_DECLARE_VARIANT_API(kind, ctype) \
1544 HGDN_DECLARE_VARIANT_GET(kind, ctype) \
1545 HGDN_DECLARE_VARIANT_GET_OWN(kind, ctype) \
1546 HGDN_DECLARE_ARRAY_GET(kind, ctype) \
1547 HGDN_DECLARE_ARGS_GET(kind, ctype) \
1548 HGDN_DECLARE_DICTIONARY_GET(kind, ctype)
1549
1550HGDN_DECLARE_VARIANT_API(uint, uint64_t) // hgdn_variant_get_uint, hgdn_variant_get_uint_own, hgdn_array_get_uint, hgdn_args_get_uint, hgdn_dictionary_get_uint, hgdn_dictionary_string_get_uint
1551HGDN_DECLARE_VARIANT_API(int, int64_t) // hgdn_variant_get_int, hgdn_variant_get_int_own, hgdn_array_get_int, hgdn_args_get_int, hgdn_dictionary_get_int, hgdn_dictionary_string_get_int
1552HGDN_DECLARE_VARIANT_API(real, double) // hgdn_variant_get_real, hgdn_variant_get_real_own, hgdn_array_get_real, hgdn_args_get_real, hgdn_dictionary_get_real, hgdn_dictionary_string_get_real
1553HGDN_DECLARE_VARIANT_API(vector2, godot_vector2) // hgdn_variant_get_vector2, hgdn_variant_get_vector2_own, hgdn_array_get_vector2, hgdn_args_get_vector2, hgdn_dictionary_get_vector2, hgdn_dictionary_string_get_vector2
1554HGDN_DECLARE_VARIANT_API(vector3, godot_vector3) // hgdn_variant_get_vector3, hgdn_variant_get_vector3_own, hgdn_array_get_vector3, hgdn_args_get_vector3, hgdn_dictionary_get_vector3, hgdn_dictionary_string_get_vector3
1555HGDN_DECLARE_VARIANT_API(rect2, godot_rect2) // hgdn_variant_get_rect2, hgdn_variant_get_rect2_own, hgdn_array_get_rect2, hgdn_args_get_rect2, hgdn_dictionary_get_rect2, hgdn_dictionary_string_get_rect2
1556HGDN_DECLARE_VARIANT_API(plane, godot_plane) // hgdn_variant_get_plane, hgdn_variant_get_plane_own, hgdn_array_get_plane, hgdn_args_get_plane, hgdn_dictionary_get_plane, hgdn_dictionary_string_get_plane
1557HGDN_DECLARE_VARIANT_API(quat, godot_quat) // hgdn_variant_get_quat, hgdn_variant_get_quat_own, hgdn_array_get_quat, hgdn_args_get_quat, hgdn_dictionary_get_quat, hgdn_dictionary_string_get_quat
1558HGDN_DECLARE_VARIANT_API(aabb, godot_aabb) // hgdn_variant_get_aabb, hgdn_variant_get_aabb_own, hgdn_array_get_aabb, hgdn_args_get_aabb, hgdn_dictionary_get_aabb, hgdn_dictionary_string_get_aabb
1559HGDN_DECLARE_VARIANT_API(basis, godot_basis) // hgdn_variant_get_basis, hgdn_variant_get_basis_own, hgdn_array_get_basis, hgdn_args_get_basis, hgdn_dictionary_get_basis, hgdn_dictionary_string_get_basis
1560HGDN_DECLARE_VARIANT_API(transform2d, godot_transform2d) // hgdn_variant_get_transform2d, hgdn_variant_get_transform2d_own, hgdn_array_get_transform2d, hgdn_args_get_transform2d, hgdn_dictionary_get_transform2d, hgdn_dictionary_string_get_transform2d
1561HGDN_DECLARE_VARIANT_API(transform, godot_transform) // hgdn_variant_get_transform, hgdn_variant_get_transform_own, hgdn_array_get_transform, hgdn_args_get_transform, hgdn_dictionary_get_transform, hgdn_dictionary_string_get_transform
1562HGDN_DECLARE_VARIANT_API(color, godot_color) // hgdn_variant_get_color, hgdn_variant_get_color_own, hgdn_array_get_color, hgdn_args_get_color, hgdn_dictionary_get_color, hgdn_dictionary_string_get_color
1563HGDN_DECLARE_VARIANT_API(node_path, godot_node_path) // hgdn_variant_get_node_path, hgdn_variant_get_node_path_own, hgdn_array_get_node_path, hgdn_args_get_node_path, hgdn_dictionary_get_node_path, hgdn_dictionary_string_get_node_path
1564HGDN_DECLARE_VARIANT_API(rid, godot_rid) // hgdn_variant_get_rid, hgdn_variant_get_rid_own, hgdn_array_get_rid, hgdn_args_get_rid, hgdn_dictionary_get_rid, hgdn_dictionary_string_get_rid
1565HGDN_DECLARE_VARIANT_API(object, godot_object *) // hgdn_variant_get_object, hgdn_variant_get_object_own, hgdn_array_get_object, hgdn_args_get_object, hgdn_dictionary_get_object, hgdn_dictionary_string_get_object
1566HGDN_DECLARE_VARIANT_API(dictionary, godot_dictionary) // hgdn_variant_get_dictionary, hgdn_variant_get_dictionary_own, hgdn_array_get_dictionary, hgdn_args_get_dictionary, hgdn_dictionary_get_dictionary, hgdn_dictionary_string_get_dictionary
1567HGDN_DECLARE_VARIANT_API(array, godot_array) // hgdn_variant_get_array, hgdn_variant_get_array_own, hgdn_array_get_array, hgdn_args_get_array, hgdn_dictionary_get_array, hgdn_dictionary_string_get_array
1568
1569#undef HGDN_DECLARE_VARIANT_GET
1570
1571hgdn_string hgdn_variant_get_string(const godot_variant *var) {
1572 return hgdn_string_get_own(hgdn_core_api->godot_variant_as_string(var));
1573}
1574HGDN_DECLARE_VARIANT_GET_OWN(string, hgdn_string) // hgdn_variant_get_string_own
1575HGDN_DECLARE_ARRAY_GET(string, hgdn_string) // hgdn_array_get_string
1576HGDN_DECLARE_ARGS_GET(string, hgdn_string) // hgdn_args_get_string
1577HGDN_DECLARE_DICTIONARY_GET(string, hgdn_string) // hgdn_dictionary_get_string
1578
1579hgdn_wide_string hgdn_variant_get_wide_string(const godot_variant *var) {
1580 return hgdn_wide_string_get_own(hgdn_core_api->godot_variant_as_string(var));
1581}
1582HGDN_DECLARE_VARIANT_GET_OWN(wide_string, hgdn_wide_string) // hgdn_variant_get_wide_string_own
1583HGDN_DECLARE_ARRAY_GET(wide_string, hgdn_wide_string) // hgdn_array_get_wide_string
1584HGDN_DECLARE_ARGS_GET(wide_string, hgdn_wide_string) // hgdn_args_get_wide_string
1585HGDN_DECLARE_DICTIONARY_GET(wide_string, hgdn_wide_string) // hgdn_dictionary_get_wide_string
1586
1587#define HGDN_DECLARE_VARIANT_GET_POOL_ARRAY(kind, ctype) \
1588 ctype hgdn_variant_get_##kind(const godot_variant *var) { \
1589 return hgdn_##kind##_get_own(hgdn_core_api->godot_variant_as_pool_##kind(var)); \
1590 } \
1591 HGDN_DECLARE_VARIANT_GET_OWN(kind, ctype) \
1592 HGDN_DECLARE_ARRAY_GET(kind, ctype) \
1593 HGDN_DECLARE_ARGS_GET(kind, ctype) \
1594 HGDN_DECLARE_DICTIONARY_GET(kind, ctype)
1595
1596HGDN_DECLARE_VARIANT_GET_POOL_ARRAY(byte_array, hgdn_byte_array) // hgdn_variant_get_byte_array, hgdn_variant_get_byte_array_own, hgdn_array_get_byte_array, hgdn_args_get_byte_array, hgdn_dictionary_get_byte_array, hgdn_dictionary_string_get_byte_array
1597HGDN_DECLARE_VARIANT_GET_POOL_ARRAY(int_array, hgdn_int_array) // hgdn_variant_get_int_array, hgdn_variant_get_int_array_own, hgdn_array_get_int_array, hgdn_args_get_int_array, hgdn_dictionary_get_int_array, hgdn_dictionary_string_get_int_array
1598HGDN_DECLARE_VARIANT_GET_POOL_ARRAY(real_array, hgdn_real_array) // hgdn_variant_get_real_array, hgdn_variant_get_real_array_own, hgdn_array_get_real_array, hgdn_args_get_real_array, hgdn_dictionary_get_real_array, hgdn_dictionary_string_get_real_array
1599HGDN_DECLARE_VARIANT_GET_POOL_ARRAY(string_array, hgdn_string_array) // hgdn_variant_get_string_array, hgdn_variant_get_string_array_own, hgdn_array_get_string_array, hgdn_args_get_string_array, hgdn_dictionary_get_string_array, hgdn_dictionary_string_get_string_array
1600HGDN_DECLARE_VARIANT_GET_POOL_ARRAY(vector2_array, hgdn_vector2_array) // hgdn_variant_get_vector2_array, hgdn_variant_get_vector2_array_own, hgdn_array_get_vector2_array, hgdn_args_get_vector2_array, hgdn_dictionary_get_vector2_array, hgdn_dictionary_string_get_vector2_array
1601HGDN_DECLARE_VARIANT_GET_POOL_ARRAY(vector3_array, hgdn_vector3_array) // hgdn_variant_get_vector3_array, hgdn_variant_get_vector3_array_own, hgdn_array_get_vector3_array, hgdn_args_get_vector3_array, hgdn_dictionary_get_vector3_array, hgdn_dictionary_string_get_vector3_array
1602HGDN_DECLARE_VARIANT_GET_POOL_ARRAY(color_array, hgdn_color_array) // hgdn_variant_get_color_array, hgdn_variant_get_color_array_own, hgdn_array_get_color_array, hgdn_args_get_color_array, hgdn_dictionary_get_color_array, hgdn_dictionary_string_get_color_array
1603
1604#undef HGDN_DECLARE_VARIANT_GET_POOL_ARRAY
1605
1606#undef HGDN_DECLARE_DICTIONARY_GET
1607#undef HGDN_DECLARE_ARGS_GET
1608#undef HGDN_DECLARE_ARRAY_GET
1609#undef HGDN_DECLARE_VARIANT_GET_OWN
1610
1611// Object helpers
1612godot_variant hgdn_object_callv(godot_object *instance, const char *method, const godot_array *args_array) {
1613 if (!args_array) {
1614 args_array = &hgdn__empty_array;
1615 }
1616 godot_variant result;
1617 godot_string method_str = hgdn_new_string(method);
1618 const void *args[] = { &method_str, args_array };
1619 hgdn_core_api->godot_method_bind_ptrcall(hgdn_method_Object_callv, instance, args, &result);
1620 hgdn_core_api->godot_string_destroy(&method_str);
1621 return result;
1622}
1623
1624godot_variant hgdn_object_callv_own(godot_object *instance, const char *method, godot_array args) {
1625 godot_variant result = hgdn_object_callv(instance, method, &args);
1626 hgdn_core_api->godot_array_destroy(&args);
1627 return result;
1628}
1629
1630// Create variants
1631godot_variant hgdn_new_variant_copy(const godot_variant *value) {
1632 godot_variant var;
1633 hgdn_core_api->godot_variant_new_copy(&var, value);
1634 return var;
1635}
1636
1637godot_variant hgdn_new_nil_variant() {
1638 godot_variant var;
1639 hgdn_core_api->godot_variant_new_nil(&var);
1640 return var;
1641}
1642
1643#define HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(kind, ctype) \
1644 godot_variant hgdn_new_##kind##_variant(const ctype value) { \
1645 godot_variant var; \
1646 hgdn_core_api->godot_variant_new_##kind(&var, value); \
1647 return var; \
1648 }
1649
1650HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(bool, godot_bool) // hgdn_new_bool_variant
1651HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(uint, uint64_t) // hgdn_new_uint_variant
1652HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(int, int64_t) // hgdn_new_int_variant
1653HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(real, double) // hgdn_new_real_variant
1654HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(string, godot_string *) // hgdn_new_string_variant
1655HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(dictionary, godot_dictionary *) // hgdn_new_dictionary_variant
1656HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(array, godot_array *) // hgdn_new_array_variant
1657HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(pool_byte_array, godot_pool_byte_array *) // hgdn_new_pool_byte_array_variant
1658HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(pool_int_array, godot_pool_int_array *) // hgdn_new_pool_int_array_variant
1659HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(pool_real_array, godot_pool_real_array *) // hgdn_new_pool_real_array_variant
1660HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(pool_vector2_array, godot_pool_vector2_array *) // hgdn_new_pool_vector2_array_variant
1661HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(pool_vector3_array, godot_pool_vector3_array *) // hgdn_new_pool_vector3_array_variant
1662HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(pool_color_array, godot_pool_color_array *) // hgdn_new_pool_color_array_variant
1663HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(pool_string_array, godot_pool_string_array *) // hgdn_new_pool_string_array_variant
1664HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(node_path, godot_node_path *) // hgdn_new_node_path_variant
1665HGDN_DECLARE_NEW_PRIMITIVE_VARIANT(rid, godot_rid *) // hgdn_new_rid_variant
1666
1667#undef HGDN_DECLARE_NEW_PRIMITIVE_VARIANT
1668
1669godot_variant hgdn_new_object_variant(const godot_object *value) {
1670 godot_variant var;
1671 if (value) {
1672 hgdn_core_api->godot_variant_new_object(&var, value);
1673 }
1674 else {
1675 hgdn_core_api->godot_variant_new_nil(&var);
1676 }
1677 return var;
1678}
1679
1680godot_variant hgdn_new_cstring_variant(const char *value) {
1681 return hgdn_new_string_variant_own(hgdn_new_string(value));
1682}
1683
1684godot_variant hgdn_new_wide_string_variant(const wchar_t *value) {
1685 return hgdn_new_string_variant_own(hgdn_new_wide_string(value));
1686}
1687
1688#define HGDN_DECLARE_NEW_COMPOUND_VARIANT(kind, ctype) \
1689 godot_variant hgdn_new_##kind##_variant(const ctype value) { \
1690 godot_variant var; \
1691 hgdn_core_api->godot_variant_new_##kind(&var, &value); \
1692 return var; \
1693 }
1694
1695HGDN_DECLARE_NEW_COMPOUND_VARIANT(vector2, godot_vector2) // hgdn_new_vector2_variant
1696HGDN_DECLARE_NEW_COMPOUND_VARIANT(vector3, godot_vector3) // hgdn_new_vector3_variant
1697HGDN_DECLARE_NEW_COMPOUND_VARIANT(rect2, godot_rect2) // hgdn_new_rect2_variant
1698HGDN_DECLARE_NEW_COMPOUND_VARIANT(plane, godot_plane) // hgdn_new_plane_variant
1699HGDN_DECLARE_NEW_COMPOUND_VARIANT(quat, godot_quat) // hgdn_new_quat_variant
1700HGDN_DECLARE_NEW_COMPOUND_VARIANT(aabb, godot_aabb) // hgdn_new_aabb_variant
1701HGDN_DECLARE_NEW_COMPOUND_VARIANT(basis, godot_basis) // hgdn_new_basis_variant
1702HGDN_DECLARE_NEW_COMPOUND_VARIANT(transform2d, godot_transform2d) // hgdn_new_transform2d_variant
1703HGDN_DECLARE_NEW_COMPOUND_VARIANT(transform, godot_transform) // hgdn_new_transform_variant
1704HGDN_DECLARE_NEW_COMPOUND_VARIANT(color, godot_color) // hgdn_new_color_variant
1705
1706#undef HGDN_DECLARE_NEW_COMPOUND_VARIANT
1707
1708#define HGDN_DECLARE_NEW_OWNED_VARIANT(kind, ctype) \
1709 godot_variant hgdn_new_##kind##_variant_own(ctype value) { \
1710 godot_variant var; \
1711 hgdn_core_api->godot_variant_new_##kind(&var, &value); \
1712 hgdn_core_api->ctype##_destroy(&value); \
1713 return var; \
1714 }
1715
1716HGDN_DECLARE_NEW_OWNED_VARIANT(string, godot_string) // hgdn_new_string_variant_own
1717HGDN_DECLARE_NEW_OWNED_VARIANT(dictionary, godot_dictionary) // hgdn_new_dictionary_variant_own
1718HGDN_DECLARE_NEW_OWNED_VARIANT(array, godot_array) // hgdn_new_array_variant_own
1719HGDN_DECLARE_NEW_OWNED_VARIANT(pool_byte_array, godot_pool_byte_array) // hgdn_new_pool_byte_array_variant_own
1720HGDN_DECLARE_NEW_OWNED_VARIANT(pool_int_array, godot_pool_int_array) // hgdn_new_pool_int_array_variant_own
1721HGDN_DECLARE_NEW_OWNED_VARIANT(pool_real_array, godot_pool_real_array) // hgdn_new_pool_real_array_variant_own
1722HGDN_DECLARE_NEW_OWNED_VARIANT(pool_vector2_array, godot_pool_vector2_array) // hgdn_new_pool_vector2_array_variant_own
1723HGDN_DECLARE_NEW_OWNED_VARIANT(pool_vector3_array, godot_pool_vector3_array) // hgdn_new_pool_vector3_array_variant_own
1724HGDN_DECLARE_NEW_OWNED_VARIANT(pool_color_array, godot_pool_color_array) // hgdn_new_pool_color_array_variant_own
1725HGDN_DECLARE_NEW_OWNED_VARIANT(pool_string_array, godot_pool_string_array) // hgdn_new_pool_string_array_variant_own
1726HGDN_DECLARE_NEW_OWNED_VARIANT(node_path, godot_node_path) // hgdn_new_node_path_variant_own
1727
1728#undef HGDN_DECLARE_NEW_OWNED_VARIANT
1729
1730#ifdef __cplusplus
1731godot_variant hgdn_new_variant(const godot_bool value) { return hgdn_new_bool_variant(value); }
1732godot_variant hgdn_new_variant(const unsigned int value) { return hgdn_new_uint_variant(value); }
1733godot_variant hgdn_new_variant(const uint64_t value) { return hgdn_new_uint_variant(value); }
1734godot_variant hgdn_new_variant(const int value) { return hgdn_new_int_variant(value); }
1735godot_variant hgdn_new_variant(const int64_t value) { return hgdn_new_int_variant(value); }
1736godot_variant hgdn_new_variant(const double value) { return hgdn_new_real_variant(value); }
1737godot_variant hgdn_new_variant(const godot_string *value) { return hgdn_new_string_variant(value); }
1738godot_variant hgdn_new_variant(const char *value) { return hgdn_new_cstring_variant(value); }
1739godot_variant hgdn_new_variant(const wchar_t *value) { return hgdn_new_wide_string_variant(value); }
1740godot_variant hgdn_new_variant(const godot_vector2 value) { return hgdn_new_vector2_variant(value); }
1741godot_variant hgdn_new_variant(const godot_vector3 value) { return hgdn_new_vector3_variant(value); }
1742godot_variant hgdn_new_variant(const godot_rect2 value) { return hgdn_new_rect2_variant(value); }
1743godot_variant hgdn_new_variant(const godot_plane value) { return hgdn_new_plane_variant(value); }
1744godot_variant hgdn_new_variant(const godot_quat value) { return hgdn_new_quat_variant(value); }
1745godot_variant hgdn_new_variant(const godot_aabb value) { return hgdn_new_aabb_variant(value); }
1746godot_variant hgdn_new_variant(const godot_basis value) { return hgdn_new_basis_variant(value); }
1747godot_variant hgdn_new_variant(const godot_transform2d value) { return hgdn_new_transform2d_variant(value); }
1748godot_variant hgdn_new_variant(const godot_transform value) { return hgdn_new_transform_variant(value); }
1749godot_variant hgdn_new_variant(const godot_color value) { return hgdn_new_color_variant(value); }
1750godot_variant hgdn_new_variant(const godot_node_path *value) { return hgdn_new_node_path_variant(value); }
1751godot_variant hgdn_new_variant(const godot_rid *value) { return hgdn_new_rid_variant(value); }
1752godot_variant hgdn_new_variant(const godot_object *value) { return hgdn_new_object_variant(value); }
1753godot_variant hgdn_new_variant(const godot_dictionary *value) { return hgdn_new_dictionary_variant(value); }
1754godot_variant hgdn_new_variant(const godot_array *value) { return hgdn_new_array_variant(value); }
1755godot_variant hgdn_new_variant(const godot_pool_byte_array *value) { return hgdn_new_pool_byte_array_variant(value); }
1756godot_variant hgdn_new_variant(const godot_pool_int_array *value) { return hgdn_new_pool_int_array_variant(value); }
1757godot_variant hgdn_new_variant(const godot_pool_real_array *value) { return hgdn_new_pool_real_array_variant(value); }
1758godot_variant hgdn_new_variant(const godot_pool_vector2_array *value) { return hgdn_new_pool_vector2_array_variant(value); }
1759godot_variant hgdn_new_variant(const godot_pool_vector3_array *value) { return hgdn_new_pool_vector3_array_variant(value); }
1760godot_variant hgdn_new_variant(const godot_pool_color_array *value) { return hgdn_new_pool_color_array_variant(value); }
1761godot_variant hgdn_new_variant(const godot_pool_string_array *value) { return hgdn_new_pool_string_array_variant(value); }
1762godot_variant hgdn_new_variant(godot_string value) { return hgdn_new_string_variant_own(value); }
1763godot_variant hgdn_new_variant(godot_node_path value) { return hgdn_new_node_path_variant_own(value); }
1764godot_variant hgdn_new_variant(godot_dictionary value) { return hgdn_new_dictionary_variant_own(value); }
1765godot_variant hgdn_new_variant(godot_array value) { return hgdn_new_array_variant_own(value); }
1766godot_variant hgdn_new_variant(godot_pool_byte_array value) { return hgdn_new_pool_byte_array_variant_own(value); }
1767godot_variant hgdn_new_variant(godot_pool_int_array value) { return hgdn_new_pool_int_array_variant_own(value); }
1768godot_variant hgdn_new_variant(godot_pool_real_array value) { return hgdn_new_pool_real_array_variant_own(value); }
1769godot_variant hgdn_new_variant(godot_pool_vector2_array value) { return hgdn_new_pool_vector2_array_variant_own(value); }
1770godot_variant hgdn_new_variant(godot_pool_vector3_array value) { return hgdn_new_pool_vector3_array_variant_own(value); }
1771godot_variant hgdn_new_variant(godot_pool_color_array value) { return hgdn_new_pool_color_array_variant_own(value); }
1772godot_variant hgdn_new_variant(godot_pool_string_array value) { return hgdn_new_pool_string_array_variant_own(value); }
1773godot_variant hgdn_new_variant(const godot_variant *value) { return hgdn_new_variant_copy(value); }
1774HGDN_CONSTEXPR godot_variant hgdn_new_variant(godot_variant value) { return value; }
1775#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L // C11
1776godot_variant hgdn__variant_return(godot_variant value) { return value; }
1777#endif // __cplusplus
1778
1779// NativeScript
1780#ifndef HGDN_NO_EXT_NATIVESCRIPT
1781void hgdn_register_class(void *handle, const hgdn_class_info *class_info) {
1782 if (class_info->tool) {
1783 hgdn_nativescript_api->godot_nativescript_register_tool_class(handle, class_info->name, class_info->base, class_info->create, class_info->destroy);
1784 }
1785 else {
1786 hgdn_nativescript_api->godot_nativescript_register_class(handle, class_info->name, class_info->base, class_info->create, class_info->destroy);
1787 }
1788
1789 if (hgdn_nativescript_1_1_api && class_info->documentation) {
1790 godot_string documentation = hgdn_new_string(class_info->documentation);
1791 hgdn_nativescript_1_1_api->godot_nativescript_set_class_documentation(handle, class_info->name, documentation);
1792 hgdn_core_api->godot_string_destroy(&documentation);
1793 }
1794
1795 if (class_info->properties) {
1796 for (hgdn_property_info *property = class_info->properties; property->path; property++) {
1797 godot_property_attributes attr = {
1798 property->rset_type,
1799 property->type,
1800 property->hint,
1801 hgdn_new_string(property->hint_string),
1802 property->usage,
1803 property->default_value,
1804 };
1805 hgdn_nativescript_api->godot_nativescript_register_property(handle, class_info->name, property->path, &attr, property->setter, property->getter);
1806 hgdn_core_api->godot_string_destroy(&attr.hint_string);
1807 if (hgdn_nativescript_1_1_api && property->documentation) {
1808 godot_string documentation = hgdn_new_string(property->documentation);
1809 hgdn_nativescript_1_1_api->godot_nativescript_set_property_documentation(handle, class_info->name, property->path, documentation);
1810 hgdn_core_api->godot_string_destroy(&documentation);
1811 }
1812 }
1813 }
1814
1815 if (class_info->methods) {
1816 for (hgdn_method_info *method = class_info->methods; method->name; method++) {
1817 godot_method_attributes attr = { method->rpc_type };
1818 hgdn_nativescript_api->godot_nativescript_register_method(handle, class_info->name, method->name, attr, method->method);
1819 if (hgdn_nativescript_1_1_api) {
1820 if (method->documentation) {
1821 godot_string documentation = hgdn_new_string(method->documentation);
1822 hgdn_nativescript_1_1_api->godot_nativescript_set_method_documentation(handle, class_info->name, method->name, documentation);
1823 hgdn_core_api->godot_string_destroy(&documentation);
1824 }
1825 if (method->arguments_info) {
1826 godot_method_arg gd_args[HGDN_METHOD_ARGUMENTS_INFO_MAX];
1827 int num_args = 0;
1828 for (hgdn_method_argument_info *argument = method->arguments_info; argument->name; argument++) {
1829 gd_args[num_args] = (godot_method_arg){
1830 hgdn_new_string(argument->name),
1831 argument->type,
1832 argument->hint,
1833 hgdn_new_string(argument->hint_string),
1834 };
1835 num_args++;
1836 }
1837 hgdn_nativescript_1_1_api->godot_nativescript_set_method_argument_information(handle, class_info->name, method->name, num_args, gd_args);
1838 for (int i = 0; i < num_args; i++) {
1839 hgdn_core_api->godot_string_destroy(&gd_args[i].name);
1840 hgdn_core_api->godot_string_destroy(&gd_args[i].hint_string);
1841 }
1842 }
1843 }
1844 }
1845 }
1846
1847 if (class_info->signals) {
1848 for (hgdn_signal_info *signal = class_info->signals; signal->name; signal++) {
1849 godot_signal_argument gd_args[HGDN_METHOD_ARGUMENTS_INFO_MAX];
1850 int num_args = 0;
1851 for (hgdn_signal_argument_info *argument = signal->arguments_info; argument->name; argument++) {
1852 gd_args[num_args] = (godot_signal_argument){
1853 hgdn_new_string(argument->name),
1854 argument->type,
1855 argument->hint,
1856 hgdn_new_string(argument->hint_string),
1857 (godot_property_usage_flags) 0,
1858 argument->default_value,
1859 };
1860 num_args++;
1861 }
1862 godot_string signal_name = hgdn_new_string(signal->name);
1863 godot_signal gd_signal = {
1864 signal_name,
1865 num_args,
1866 gd_args,
1867 signal->num_default_args,
1868 NULL,
1869 };
1870 hgdn_nativescript_api->godot_nativescript_register_signal(handle, class_info->name, &gd_signal);
1871 hgdn_core_api->godot_string_destroy(&signal_name);
1872 for (int i = 0; i < num_args; i++) {
1873 hgdn_core_api->godot_string_destroy(&gd_args[i].name);
1874 hgdn_core_api->godot_string_destroy(&gd_args[i].hint_string);
1875 }
1876 if (hgdn_nativescript_1_1_api && signal->documentation) {
1877 godot_string documentation = hgdn_new_string(signal->documentation);
1878 hgdn_nativescript_1_1_api->godot_nativescript_set_signal_documentation(handle, class_info->name, signal->name, documentation);
1879 hgdn_core_api->godot_string_destroy(&documentation);
1880 }
1881 }
1882 }
1883}
1884
1885void *hgdn_instance_alloc(godot_object *instance, void *alloc_size) {
1886 void *buffer = hgdn_alloc((uintptr_t) alloc_size);
1887 if (buffer) {
1888 memset(buffer, 0, (uintptr_t) alloc_size);
1889 }
1890 return buffer;
1891}
1892
1893void hgdn_instance_free(godot_object *instance, void *method_data, void *data) {
1894 hgdn_free(data);
1895}
1896
1897godot_variant *hgdn_property_constant_alloc(godot_variant value) {
1898 godot_variant *buffer = (godot_variant *) hgdn_alloc(sizeof(godot_variant));
1899 if (buffer) {
1900 *buffer = value;
1901 }
1902 return buffer;
1903}
1904
1905void hgdn_property_constant_free(void *value) {
1906 if (value) {
1907 hgdn_core_api->godot_variant_destroy((godot_variant *) value);
1908 hgdn_core_api->godot_free(value);
1909 }
1910}
1911
1912godot_variant hgdn_property_constant_get(godot_object *instance, void *value, void *data) {
1913 return hgdn_new_variant_copy((const godot_variant *) value);
1914}
1915#endif // HGDN_NO_EXT_NATIVESCRIPT
1916
1917#undef HGDN__FILL_FORMAT_BUFFER
1918
1919#endif // HGDN_IMPLEMENTATION
#define hgdn_new_array_args(...)
Definition: hgdn.h:895
HGDN_DECL godot_pool_string_array hgdn_new_string_array(const char *const *buffer, const godot_int size)
HGDN_DECL godot_array hgdn_new_array_own(godot_variant *buffer, const godot_int size)
hgdn_vector4 godot_color
Color is present on Pool Arrays and as MultiMesh instance data, so it's convenient having a full vect...
Definition: hgdn.h:183
godot_object * hgdn_library
GDNativeLibrary object being initialized.
HGDN_DECL void hgdn_free(void *ptr)
Compatible with free. It is safe to pass NULL without triggering an error message.
HGDN_DECL void * hgdn_alloc(size_t size)
Compatible with malloc
HGDN_DECL void * hgdn_realloc(void *ptr, size_t size)
Compatible with realloc
HGDN_DECL void * hgdn_instance_alloc(godot_object *instance, void *alloc_size)
Function that allocates and returns zero-initialized alloc_size bytes, to be used as instance create ...
HGDN_DECL void hgdn_instance_free(godot_object *instance, void *method_data, void *data)
Function that frees data with hgdn_free, to be used as instance destroy function.
#define hgdn_new_variant(value)
Overloaded function/macro for creating Variants from any values. Available in C++ and C11.
Definition: hgdn.h:765
#define hgdn_object_call(instance, method,...)
Definition: hgdn.h:964
HGDN_DECL godot_string hgdn_new_formatted_string(const char *fmt,...)
Definition: hgdn.h:398
Definition: hgdn.h:1024
hgdn_method_info * methods
NULL-terminated array of methods.
Definition: hgdn.h:1036
hgdn_property_info * properties
NULL-terminated array of properties.
Definition: hgdn.h:1032
const char * documentation
NativeScript 1.1 documentation.
Definition: hgdn.h:1043
hgdn_signal_info * signals
NULL-terminated array of signals.
Definition: hgdn.h:1040
Definition: hgdn.h:443
Definition: hgdn.h:910
Definition: hgdn.h:928
Definition: hgdn.h:919
Definition: hgdn.h:924
Definition: hgdn.h:914
Definition: hgdn.h:906
Definition: hgdn.h:407
Definition: hgdn.h:988
Definition: hgdn.h:995
hgdn_method_argument_info * arguments_info
NULL-terminated array of argument info.
Definition: hgdn.h:1005
const char * documentation
NativeScript 1.1 documentation.
Definition: hgdn.h:1001
Definition: hgdn.h:973
const char * documentation
NativeScript 1.1 documentation.
Definition: hgdn.h:985
Definition: hgdn.h:416
Definition: hgdn.h:1008
Definition: hgdn.h:1016
const char * documentation
NativeScript 1.1 documentation.
Definition: hgdn.h:1021
Definition: hgdn.h:452
Definition: hgdn.h:375
Definition: hgdn.h:425
Definition: hgdn.h:434
Definition: hgdn.h:384
Definition: hgdn.h:242
Definition: hgdn.h:229
Definition: hgdn.h:200
Definition: hgdn.h:212
Definition: hgdn.h:187
Definition: hgdn.h:254
Definition: hgdn.h:268
Definition: hgdn.h:102
Definition: hgdn.h:124
Definition: hgdn.h:153