-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathgd.c
More file actions
2116 lines (2101 loc) · 131 KB
/
Copy pathgd.c
File metadata and controls
2116 lines (2101 loc) · 131 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifdef __EMSCRIPTEN__
// The generated interface header is the authoritative one in the engine
// tree (the plain gdextension_interface.h there is a stale snapshot).
#include "core/extension/gdextension_interface.gen.h"
#include <emscripten/bind.h>
#include <bit>
#else
#include "gdextension_interface.h"
#endif
#include "gd.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
// emscripten can only expose std::string to JS, not char *
// we want emscripten to be able to deal with 64bit values without resorting to slow big ints.
#ifdef __EMSCRIPTEN__
#define UINT64(n) uint32_t n##_1, uint32_t n##_2
#define UINT64_FROM(v) ((uint64_t)(v##_1) << 32) | ((uint64_t)(v##_2))
#define UINT64_MAKE(v) (uint32_t)(v >> 32), (uint32_t)(v & 0xFFFFFFFF)
#define INT64(n) uint32_t n##_1, uint32_t n##_2
#define INT64_FROM(v) std::__bit_cast<int64_t>(((uint64_t)(v##_1) << 32) | ((uint64_t)(v##_2)))
#define INT int32_t
#define STRING std::string
#define STRING_POINTER(s) (s).c_str()
#define BUFFER uint32_t
#define BUFFER_POINTER(s) (char*)(s)
#define ANY uint32_t
#define UINT uint32_t
#else
#define UINT64(n) uint64_t n
#define UINT64_FROM(v) (v)
#define UINT64_MAKE(v) (v)
#define INT64 int64_t
#define INT64_FROM(v) (v)
#define INT int64_t
#define STRING const char*
#define STRING_POINTER(s) (s)
#define BUFFER char*
#define BUFFER_POINTER(s) (s)
#define ANY void*
#define UINT uint64_t
#endif
#ifdef _WIN32
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
#define LOAD_PROC_ADDRESS(m_name, m_type) gdextension_##m_name = (m_type)p_get_proc_address(#m_name);
static GDExtensionClassLibraryPtr gd_library = NULL;
static GDExtensionGodotVersion2 gd_godot_version_cached = {};
typedef struct { uint64_t part[2]; } result_16;
typedef struct { uint64_t part[3]; } result_24;
typedef struct { uint64_t part[4]; } result_32;
typedef struct { uint64_t part[8]; } result_64;
static void engine_exit(void *ignore, GDExtensionInitializationLevel level) {
gd_on_engine_exit(level);
}
static void callable_call(void *callable_userdata, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionVariantPtr r_return, GDExtensionCallError *r_error) {
gd_on_callable_call((uintptr_t)callable_userdata, r_return, p_argument_count, (void *)p_args, (CallError*)r_error);
}
static GDExtensionBool callable_validation(void *callable_userdata) {
return gd_on_callable_validation((uintptr_t)callable_userdata);
}
static void callable_free(void *callable_userdata) {
gd_on_callable_free((uintptr_t)callable_userdata);
}
static uint32_t callable_hash(void *callable_userdata) {
return gd_on_callable_hash((uintptr_t)callable_userdata);
}
static GDExtensionBool callable_compare(void *callable_userdata, void *other_userdata) {
return gd_on_callable_compare((uintptr_t)callable_userdata, (uintptr_t)other_userdata);
}
static GDExtensionBool callable_less_than(void *callable_userdata, void *other_userdata) {
return gd_on_callable_less_than((uintptr_t)callable_userdata, (uintptr_t)other_userdata);
}
static void callable_stringify(void *callable_userdata, GDExtensionBool *r_is_valid, GDExtensionStringPtr r_out) {
uint64_t invalid = 0;
uintptr_t s = gd_on_callable_stringify((uintptr_t)callable_userdata, (CallError*)&invalid);
*r_is_valid = !(GDExtensionBool)invalid;
if (invalid) {
*((uintptr_t*)r_out) = 0;
} else {
*((uintptr_t*)r_out) = s;
}
}
static GDExtensionInt callable_get_argument_count(void *callable_userdata, GDExtensionBool *r_is_valid) {
uint64_t invalid = 0;
int64_t count = gd_on_callable_get_argument_count((uintptr_t)callable_userdata, (CallError*)&invalid);
*r_is_valid = !(GDExtensionBool)invalid;
if (invalid) return -1;
return (GDExtensionInt)count;
}
static void extension_instance_dynamic_call(void *method_userdata, GDExtensionClassInstancePtr p_instance, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionVariantPtr r_return, GDExtensionCallError *r_error) {
gd_on_extension_instance_dynamic_call((uintptr_t)p_instance, (uintptr_t)method_userdata, r_return, p_argument_count, (void *)p_args, (CallError*)r_error);
}
static void extension_instance_checked_call(void *method_userdata, GDExtensionClassInstancePtr p_instance, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_ret) {
gd_on_extension_instance_checked_call((uintptr_t)p_instance, (uintptr_t)method_userdata, r_ret, (void *)p_args);
}
static void *extension_binding_created(void *p_token, void *p_instance) {
return (void *)gd_on_extension_binding_created((uintptr_t)p_instance);
}
static void extension_binding_removed(void *p_token, void *p_instance, void *p_binding) {
gd_on_extension_binding_removed((uintptr_t)p_instance, (uintptr_t)p_binding);
}
static GDExtensionBool extension_binding_reference(void *p_token, void *p_binding, GDExtensionBool p_reference) {
return gd_on_extension_binding_reference((uintptr_t)p_binding, p_reference);
}
GDExtensionInstanceBindingCallbacks instance_binding_callbacks = {
.create_callback = extension_binding_created,
.free_callback = extension_binding_removed,
// .reference_callback = extension_binding_reference
};
GDExtensionTypeFromVariantConstructorFunc type_from_variant_constructors[GDEXTENSION_VARIANT_TYPE_VARIANT_MAX];
GDExtensionVariantFromTypeConstructorFunc variant_from_type_constructors[GDEXTENSION_VARIANT_TYPE_VARIANT_MAX];
GDExtensionPtrDestructor variant_ptr_destructors[GDEXTENSION_VARIANT_TYPE_VARIANT_MAX];
GDExtensionVariantGetInternalPtrFunc variant_internal_ptr_funcs[GDEXTENSION_VARIANT_TYPE_VARIANT_MAX];
GDExtensionPtrIndexedSetter variant_ptr_indexed_setters[GDEXTENSION_VARIANT_TYPE_VARIANT_MAX];
GDExtensionPtrIndexedGetter variant_ptr_indexed_getters[GDEXTENSION_VARIANT_TYPE_VARIANT_MAX];
GDExtensionPtrKeyedSetter variant_ptr_keyed_setters[GDEXTENSION_VARIANT_TYPE_VARIANT_MAX];
GDExtensionPtrKeyedGetter variant_ptr_keyed_getters[GDEXTENSION_VARIANT_TYPE_VARIANT_MAX];
GDExtensionInterfaceMemAlloc gdextension_mem_alloc = NULL;
GDExtensionInterfaceMemRealloc gdextension_mem_realloc = NULL;
GDExtensionInterfaceMemFree gdextension_mem_free = NULL;
GDExtensionInterfacePrintError gdextension_print_error = NULL;
GDExtensionInterfacePrintErrorWithMessage gdextension_print_error_with_message = NULL;
GDExtensionInterfacePrintWarning gdextension_print_warning = NULL;
GDExtensionInterfacePrintWarningWithMessage gdextension_print_warning_with_message = NULL;
GDExtensionInterfacePrintScriptError gdextension_print_script_error = NULL;
GDExtensionInterfacePrintScriptErrorWithMessage gdextension_print_script_error_with_message = NULL;
GDExtensionInterfaceGetNativeStructSize gdextension_get_native_struct_size = NULL;
GDExtensionInterfaceVariantNewCopy gdextension_variant_new_copy = NULL;
GDExtensionInterfaceVariantNewNil gdextension_variant_new_nil = NULL;
GDExtensionInterfaceVariantDestroy gdextension_variant_destroy = NULL;
GDExtensionInterfaceVariantCall gdextension_variant_call = NULL;
GDExtensionInterfaceVariantCallStatic gdextension_variant_call_static = NULL;
GDExtensionInterfaceVariantEvaluate gdextension_variant_evaluate = NULL;
GDExtensionInterfaceVariantSet gdextension_variant_set = NULL;
GDExtensionInterfaceVariantSetNamed gdextension_variant_set_named = NULL;
GDExtensionInterfaceVariantSetKeyed gdextension_variant_set_keyed = NULL;
GDExtensionInterfaceVariantSetIndexed gdextension_variant_set_indexed = NULL;
GDExtensionInterfaceVariantGet gdextension_variant_get = NULL;
GDExtensionInterfaceVariantGetNamed gdextension_variant_get_named = NULL;
GDExtensionInterfaceVariantGetKeyed gdextension_variant_get_keyed = NULL;
GDExtensionInterfaceVariantGetIndexed gdextension_variant_get_indexed = NULL;
GDExtensionInterfaceVariantIterInit gdextension_variant_iter_init = NULL;
GDExtensionInterfaceVariantIterNext gdextension_variant_iter_next = NULL;
GDExtensionInterfaceVariantIterGet gdextension_variant_iter_get = NULL;
GDExtensionInterfaceVariantHash gdextension_variant_hash = NULL;
GDExtensionInterfaceVariantRecursiveHash gdextension_variant_recursive_hash = NULL;
GDExtensionInterfaceVariantHashCompare gdextension_variant_hash_compare = NULL;
GDExtensionInterfaceVariantBooleanize gdextension_variant_booleanize = NULL;
GDExtensionInterfaceVariantDuplicate gdextension_variant_duplicate = NULL;
GDExtensionInterfaceVariantStringify gdextension_variant_stringify = NULL;
GDExtensionInterfaceVariantGetType gdextension_variant_get_type = NULL;
GDExtensionInterfaceVariantHasMethod gdextension_variant_has_method = NULL;
GDExtensionInterfaceVariantHasMember gdextension_variant_has_member = NULL;
GDExtensionInterfaceVariantHasKey gdextension_variant_has_key = NULL;
GDExtensionInterfaceVariantGetObjectInstanceId gdextension_variant_get_object_instance_id = NULL;
GDExtensionInterfaceVariantGetTypeName gdextension_variant_get_type_name = NULL;
GDExtensionInterfaceVariantCanConvert gdextension_variant_can_convert = NULL;
GDExtensionInterfaceVariantCanConvertStrict gdextension_variant_can_convert_strict = NULL;
GDExtensionInterfaceGetVariantFromTypeConstructor gdextension_get_variant_from_type_constructor = NULL;
GDExtensionInterfaceGetVariantToTypeConstructor gdextension_get_variant_to_type_constructor = NULL;
GDExtensionInterfaceVariantGetPtrInternalGetter gdextension_variant_get_ptr_internal_getter = NULL;
GDExtensionInterfaceVariantGetPtrOperatorEvaluator gdextension_variant_get_ptr_operator_evaluator = NULL;
GDExtensionInterfaceVariantGetPtrBuiltinMethod gdextension_variant_get_ptr_builtin_method = NULL;
GDExtensionInterfaceVariantGetPtrConstructor gdextension_variant_get_ptr_constructor = NULL;
GDExtensionInterfaceVariantGetPtrDestructor gdextension_variant_get_ptr_destructor = NULL;
GDExtensionInterfaceVariantConstruct gdextension_variant_construct = NULL;
GDExtensionInterfaceVariantGetPtrSetter gdextension_variant_get_ptr_setter = NULL;
GDExtensionInterfaceVariantGetPtrGetter gdextension_variant_get_ptr_getter = NULL;
GDExtensionInterfaceVariantGetPtrIndexedSetter gdextension_variant_get_ptr_indexed_setter = NULL;
GDExtensionInterfaceVariantGetPtrIndexedGetter gdextension_variant_get_ptr_indexed_getter = NULL;
GDExtensionInterfaceVariantGetPtrKeyedSetter gdextension_variant_get_ptr_keyed_setter = NULL;
GDExtensionInterfaceVariantGetPtrKeyedGetter gdextension_variant_get_ptr_keyed_getter = NULL;
GDExtensionInterfaceVariantGetPtrKeyedChecker gdextension_variant_get_ptr_keyed_checker = NULL;
GDExtensionInterfaceVariantGetConstantValue gdextension_variant_get_constant_value = NULL;
GDExtensionInterfaceVariantGetPtrUtilityFunction gdextension_variant_get_ptr_utility_function = NULL;
GDExtensionInterfaceStringNewWithLatin1Chars gdextension_string_new_with_latin1_chars = NULL;
GDExtensionInterfaceStringNewWithUtf8Chars gdextension_string_new_with_utf8_chars = NULL;
GDExtensionInterfaceStringNewWithUtf16Chars gdextension_string_new_with_utf16_chars = NULL;
GDExtensionInterfaceStringNewWithUtf32Chars gdextension_string_new_with_utf32_chars = NULL;
GDExtensionInterfaceStringNewWithWideChars gdextension_string_new_with_wide_chars = NULL;
GDExtensionInterfaceStringNewWithLatin1CharsAndLen gdextension_string_new_with_latin1_chars_and_len = NULL;
GDExtensionInterfaceStringNewWithUtf8CharsAndLen gdextension_string_new_with_utf8_chars_and_len = NULL;
GDExtensionInterfaceStringNewWithUtf8CharsAndLen2 gdextension_string_new_with_utf8_chars_and_len2 = NULL;
GDExtensionInterfaceStringNewWithUtf16CharsAndLen gdextension_string_new_with_utf16_chars_and_len = NULL;
GDExtensionInterfaceStringNewWithUtf16CharsAndLen2 gdextension_string_new_with_utf16_chars_and_len2 = NULL;
GDExtensionInterfaceStringNewWithUtf32CharsAndLen gdextension_string_new_with_utf32_chars_and_len = NULL;
GDExtensionInterfaceStringNewWithWideCharsAndLen gdextension_string_new_with_wide_chars_and_len = NULL;
GDExtensionInterfaceStringToLatin1Chars gdextension_string_to_latin1_chars = NULL;
GDExtensionInterfaceStringToUtf8Chars gdextension_string_to_utf8_chars = NULL;
GDExtensionInterfaceStringToUtf16Chars gdextension_string_to_utf16_chars = NULL;
GDExtensionInterfaceStringToUtf32Chars gdextension_string_to_utf32_chars = NULL;
GDExtensionInterfaceStringToWideChars gdextension_string_to_wide_chars = NULL;
GDExtensionInterfaceStringOperatorIndex gdextension_string_operator_index = NULL;
GDExtensionInterfaceStringOperatorIndexConst gdextension_string_operator_index_const = NULL;
GDExtensionInterfaceStringOperatorPlusEqString gdextension_string_operator_plus_eq_string = NULL;
GDExtensionInterfaceStringOperatorPlusEqChar gdextension_string_operator_plus_eq_char = NULL;
GDExtensionInterfaceStringOperatorPlusEqCstr gdextension_string_operator_plus_eq_cstr = NULL;
GDExtensionInterfaceStringOperatorPlusEqWcstr gdextension_string_operator_plus_eq_wcstr = NULL;
GDExtensionInterfaceStringOperatorPlusEqC32str gdextension_string_operator_plus_eq_c32str = NULL;
GDExtensionInterfaceStringResize gdextension_string_resize = NULL;
GDExtensionInterfaceStringNameNewWithLatin1Chars gdextension_string_name_new_with_latin1_chars = NULL;
GDExtensionInterfaceStringNameNewWithUtf8CharsAndLen gdextension_string_name_new_with_utf8_chars_and_len = NULL;
GDExtensionInterfaceXmlParserOpenBuffer gdextension_xml_parser_open_buffer = NULL;
GDExtensionInterfaceFileAccessStoreBuffer gdextension_file_access_store_buffer = NULL;
GDExtensionInterfaceFileAccessGetBuffer gdextension_file_access_get_buffer = NULL;
GDExtensionInterfaceWorkerThreadPoolAddNativeGroupTask gdextension_worker_thread_pool_add_native_group_task = NULL;
GDExtensionInterfaceWorkerThreadPoolAddNativeTask gdextension_worker_thread_pool_add_native_task = NULL;
GDExtensionInterfacePackedByteArrayOperatorIndex gdextension_packed_byte_array_operator_index = NULL;
GDExtensionInterfacePackedByteArrayOperatorIndexConst gdextension_packed_byte_array_operator_index_const = NULL;
GDExtensionInterfacePackedColorArrayOperatorIndex gdextension_packed_color_array_operator_index = NULL;
GDExtensionInterfacePackedColorArrayOperatorIndexConst gdextension_packed_color_array_operator_index_const = NULL;
GDExtensionInterfacePackedFloat32ArrayOperatorIndex gdextension_packed_float32_array_operator_index = NULL;
GDExtensionInterfacePackedFloat32ArrayOperatorIndexConst gdextension_packed_float32_array_operator_index_const = NULL;
GDExtensionInterfacePackedFloat64ArrayOperatorIndex gdextension_packed_float64_array_operator_index = NULL;
GDExtensionInterfacePackedFloat64ArrayOperatorIndexConst gdextension_packed_float64_array_operator_index_const = NULL;
GDExtensionInterfacePackedInt32ArrayOperatorIndex gdextension_packed_int32_array_operator_index = NULL;
GDExtensionInterfacePackedInt32ArrayOperatorIndexConst gdextension_packed_int32_array_operator_index_const = NULL;
GDExtensionInterfacePackedInt64ArrayOperatorIndex gdextension_packed_int64_array_operator_index = NULL;
GDExtensionInterfacePackedInt64ArrayOperatorIndexConst gdextension_packed_int64_array_operator_index_const = NULL;
GDExtensionInterfacePackedStringArrayOperatorIndex gdextension_packed_string_array_operator_index = NULL;
GDExtensionInterfacePackedStringArrayOperatorIndexConst gdextension_packed_string_array_operator_index_const = NULL;
GDExtensionInterfacePackedVector2ArrayOperatorIndex gdextension_packed_vector2_array_operator_index = NULL;
GDExtensionInterfacePackedVector2ArrayOperatorIndexConst gdextension_packed_vector2_array_operator_index_const = NULL;
GDExtensionInterfacePackedVector3ArrayOperatorIndex gdextension_packed_vector3_array_operator_index = NULL;
GDExtensionInterfacePackedVector3ArrayOperatorIndexConst gdextension_packed_vector3_array_operator_index_const = NULL;
GDExtensionInterfacePackedVector4ArrayOperatorIndex gdextension_packed_vector4_array_operator_index = NULL;
GDExtensionInterfacePackedVector4ArrayOperatorIndexConst gdextension_packed_vector4_array_operator_index_const = NULL;
GDExtensionInterfaceArrayOperatorIndex gdextension_array_operator_index = NULL;
GDExtensionInterfaceArrayOperatorIndexConst gdextension_array_operator_index_const = NULL;
GDExtensionInterfaceArraySetTyped gdextension_array_set_typed = NULL;
GDExtensionInterfaceDictionaryOperatorIndex gdextension_dictionary_operator_index = NULL;
GDExtensionInterfaceDictionaryOperatorIndexConst gdextension_dictionary_operator_index_const = NULL;
GDExtensionInterfaceDictionarySetTyped gdextension_dictionary_set_typed = NULL;
GDExtensionInterfaceObjectMethodBindCall gdextension_object_method_bind_call = NULL;
GDExtensionInterfaceObjectMethodBindPtrcall gdextension_object_method_bind_ptrcall = NULL;
GDExtensionInterfaceObjectDestroy gdextension_object_destroy = NULL;
GDExtensionInterfaceGlobalGetSingleton gdextension_global_get_singleton = NULL;
GDExtensionInterfaceObjectGetInstanceBinding gdextension_object_get_instance_binding = NULL;
GDExtensionInterfaceObjectSetInstanceBinding gdextension_object_set_instance_binding = NULL;
GDExtensionInterfaceObjectFreeInstanceBinding gdextension_object_free_instance_binding = NULL;
GDExtensionInterfaceObjectSetInstance gdextension_object_set_instance = NULL;
GDExtensionInterfaceObjectGetClassName gdextension_object_get_class_name = NULL;
GDExtensionInterfaceObjectCastTo gdextension_object_cast_to = NULL;
GDExtensionInterfaceObjectGetInstanceFromId gdextension_object_get_instance_from_id = NULL;
GDExtensionInterfaceObjectGetInstanceId gdextension_object_get_instance_id = NULL;
GDExtensionInterfaceObjectHasScriptMethod gdextension_object_has_script_method = NULL;
GDExtensionInterfaceObjectCallScriptMethod gdextension_object_call_script_method = NULL;
GDExtensionInterfaceCallableCustomCreate2 gdextension_callable_custom_create2 = NULL;
GDExtensionInterfaceCallableCustomGetUserdata gdextension_callable_custom_get_userdata = NULL;
GDExtensionInterfaceRefGetObject gdextension_ref_get_object = NULL;
GDExtensionInterfaceRefSetObject gdextension_ref_set_object = NULL;
GDExtensionInterfaceScriptInstanceCreate3 gdextension_script_instance_create3 = NULL;
GDExtensionInterfacePlaceholderScriptInstanceCreate gdextension_placeholder_script_instance_create = NULL;
GDExtensionInterfacePlaceholderScriptInstanceUpdate gdextension_placeholder_script_instance_update = NULL;
GDExtensionInterfaceObjectGetScriptInstance gdextension_object_get_script_instance = NULL;
GDExtensionInterfaceObjectSetScriptInstance gdextension_object_set_script_instance = NULL;
GDExtensionInterfaceClassdbConstructObject3 gdextension_classdb_construct_object3 = NULL;
GDExtensionInterfaceClassdbGetMethodBind gdextension_classdb_get_method_bind = NULL;
GDExtensionInterfaceClassdbGetClassTag gdextension_classdb_get_class_tag = NULL;
GDExtensionInterfaceClassdbRegisterExtensionClass6 gdextension_classdb_register_extension_class6 = NULL;
GDExtensionInterfaceClassdbRegisterExtensionClassMethod gdextension_classdb_register_extension_class_method = NULL;
GDExtensionInterfaceClassdbRegisterExtensionClassVirtualMethod gdextension_classdb_register_extension_class_virtual_method = NULL;
GDExtensionInterfaceClassdbRegisterExtensionClassIntegerConstant gdextension_classdb_register_extension_class_integer_constant = NULL;
GDExtensionInterfaceClassdbRegisterExtensionClassProperty gdextension_classdb_register_extension_class_property = NULL;
GDExtensionInterfaceClassdbRegisterExtensionClassPropertyIndexed gdextension_classdb_register_extension_class_property_indexed = NULL;
GDExtensionInterfaceClassdbRegisterExtensionClassPropertyGroup gdextension_classdb_register_extension_class_property_group = NULL;
GDExtensionInterfaceClassdbRegisterExtensionClassPropertySubgroup gdextension_classdb_register_extension_class_property_subgroup = NULL;
GDExtensionInterfaceClassdbRegisterExtensionClassSignal gdextension_classdb_register_extension_class_signal = NULL;
GDExtensionInterfaceClassdbUnregisterExtensionClass gdextension_classdb_unregister_extension_class = NULL;
GDExtensionInterfaceGetLibraryPath gdextension_get_library_path = NULL;
GDExtensionInterfaceEditorAddPlugin gdextension_editor_add_plugin = NULL;
GDExtensionInterfaceEditorRemovePlugin gdextension_editor_remove_plugin = NULL;
GDExtensionInterfaceEditorRegisterGetClassesUsedCallback gdextension_editor_register_get_classes_used_callback = NULL;
GDExtensionInterfaceEditorHelpLoadXmlFromUtf8Chars gdextension_editor_help_load_xml_from_utf8_chars = NULL;
GDExtensionInterfaceEditorHelpLoadXmlFromUtf8CharsAndLen gdextension_editor_help_load_xml_from_utf8_chars_and_len = NULL;
GDExtensionInterfaceImagePtrw gdextension_image_ptrw = NULL;
GDExtensionInterfaceImagePtr gdextension_image_ptr = NULL;
GDExtensionInterfaceRegisterMainLoopCallbacks gdextension_register_main_loop_callbacks = NULL;
GDExtensionInterfaceGetGodotVersion2 gdextension_get_godot_version2 = NULL;
GDExtensionObjectPtr OS = NULL;
GDExtensionMethodBindPtr OS_get_thread_caller_id = NULL;
GDExtensionMethodBindPtr OS_get_main_thread_id = NULL;
uint64_t main_thread_id = 0;
uint64_t get_thread_caller_id() {
uint64_t thread_id = 0;
gdextension_object_method_bind_ptrcall(OS_get_thread_caller_id, OS, NULL, &thread_id);
return thread_id;
}
static void engine_init(void *ignore, GDExtensionInitializationLevel level) {
if (level == GDEXTENSION_INITIALIZATION_CORE) {
uintptr_t string_name_OS;
gdextension_string_name_new_with_latin1_chars(&string_name_OS, "OS", true);
OS = gdextension_global_get_singleton(&string_name_OS);
uintptr_t string_name_get_thread_caller_id;
gdextension_string_name_new_with_latin1_chars(&string_name_get_thread_caller_id, "get_thread_caller_id", true);
OS_get_thread_caller_id = gdextension_classdb_get_method_bind(&string_name_OS, &string_name_get_thread_caller_id, 3905245786);
uintptr_t string_name_get_main_thread_id;
gdextension_string_name_new_with_latin1_chars(&string_name_get_main_thread_id, "get_main_thread_id", true);
OS_get_main_thread_id = gdextension_classdb_get_method_bind(&string_name_OS, &string_name_get_main_thread_id, 3905245786);
gdextension_object_method_bind_ptrcall(OS_get_main_thread_id, OS, NULL, &main_thread_id);
}
gd_on_engine_init(level);
}
bool gd_thread_is_main() {
return get_thread_caller_id() == main_thread_id;
}
EXPORT GDExtensionBool gd_extension_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
LOAD_PROC_ADDRESS(mem_alloc, GDExtensionInterfaceMemAlloc);
LOAD_PROC_ADDRESS(mem_realloc, GDExtensionInterfaceMemRealloc);
LOAD_PROC_ADDRESS(mem_free, GDExtensionInterfaceMemFree);
LOAD_PROC_ADDRESS(print_error_with_message, GDExtensionInterfacePrintErrorWithMessage);
LOAD_PROC_ADDRESS(print_warning, GDExtensionInterfacePrintWarning);
LOAD_PROC_ADDRESS(print_warning_with_message, GDExtensionInterfacePrintWarningWithMessage);
LOAD_PROC_ADDRESS(print_script_error, GDExtensionInterfacePrintScriptError);
LOAD_PROC_ADDRESS(print_script_error_with_message, GDExtensionInterfacePrintScriptErrorWithMessage);
LOAD_PROC_ADDRESS(get_native_struct_size, GDExtensionInterfaceGetNativeStructSize);
LOAD_PROC_ADDRESS(get_godot_version2, GDExtensionInterfaceGetGodotVersion2);
LOAD_PROC_ADDRESS(variant_new_copy, GDExtensionInterfaceVariantNewCopy);
LOAD_PROC_ADDRESS(variant_new_nil, GDExtensionInterfaceVariantNewNil);
LOAD_PROC_ADDRESS(variant_destroy, GDExtensionInterfaceVariantDestroy);
LOAD_PROC_ADDRESS(variant_call, GDExtensionInterfaceVariantCall);
LOAD_PROC_ADDRESS(variant_call_static, GDExtensionInterfaceVariantCallStatic);
LOAD_PROC_ADDRESS(variant_evaluate, GDExtensionInterfaceVariantEvaluate);
LOAD_PROC_ADDRESS(variant_set, GDExtensionInterfaceVariantSet);
LOAD_PROC_ADDRESS(variant_set_named, GDExtensionInterfaceVariantSetNamed);
LOAD_PROC_ADDRESS(variant_set_keyed, GDExtensionInterfaceVariantSetKeyed);
LOAD_PROC_ADDRESS(variant_set_indexed, GDExtensionInterfaceVariantSetIndexed);
LOAD_PROC_ADDRESS(variant_get, GDExtensionInterfaceVariantGet);
LOAD_PROC_ADDRESS(variant_get_named, GDExtensionInterfaceVariantGetNamed);
LOAD_PROC_ADDRESS(variant_get_keyed, GDExtensionInterfaceVariantGetKeyed);
LOAD_PROC_ADDRESS(variant_get_indexed, GDExtensionInterfaceVariantGetIndexed);
LOAD_PROC_ADDRESS(variant_iter_init, GDExtensionInterfaceVariantIterInit);
LOAD_PROC_ADDRESS(variant_iter_next, GDExtensionInterfaceVariantIterNext);
LOAD_PROC_ADDRESS(variant_iter_get, GDExtensionInterfaceVariantIterGet);
LOAD_PROC_ADDRESS(variant_hash, GDExtensionInterfaceVariantHash);
LOAD_PROC_ADDRESS(variant_recursive_hash, GDExtensionInterfaceVariantRecursiveHash);
LOAD_PROC_ADDRESS(variant_hash_compare, GDExtensionInterfaceVariantHashCompare);
LOAD_PROC_ADDRESS(variant_booleanize, GDExtensionInterfaceVariantBooleanize);
LOAD_PROC_ADDRESS(variant_duplicate, GDExtensionInterfaceVariantDuplicate);
LOAD_PROC_ADDRESS(variant_stringify, GDExtensionInterfaceVariantStringify);
LOAD_PROC_ADDRESS(variant_get_type, GDExtensionInterfaceVariantGetType);
LOAD_PROC_ADDRESS(variant_has_method, GDExtensionInterfaceVariantHasMethod);
LOAD_PROC_ADDRESS(variant_has_member, GDExtensionInterfaceVariantHasMember);
LOAD_PROC_ADDRESS(variant_has_key, GDExtensionInterfaceVariantHasKey);
LOAD_PROC_ADDRESS(variant_get_object_instance_id, GDExtensionInterfaceVariantGetObjectInstanceId);
LOAD_PROC_ADDRESS(variant_get_type_name, GDExtensionInterfaceVariantGetTypeName);
LOAD_PROC_ADDRESS(variant_can_convert, GDExtensionInterfaceVariantCanConvert);
LOAD_PROC_ADDRESS(variant_can_convert_strict, GDExtensionInterfaceVariantCanConvertStrict);
LOAD_PROC_ADDRESS(get_variant_from_type_constructor, GDExtensionInterfaceGetVariantFromTypeConstructor);
LOAD_PROC_ADDRESS(get_variant_to_type_constructor, GDExtensionInterfaceGetVariantToTypeConstructor);
LOAD_PROC_ADDRESS(variant_get_ptr_internal_getter, GDExtensionInterfaceVariantGetPtrInternalGetter);
LOAD_PROC_ADDRESS(variant_get_ptr_operator_evaluator, GDExtensionInterfaceVariantGetPtrOperatorEvaluator);
LOAD_PROC_ADDRESS(variant_get_ptr_builtin_method, GDExtensionInterfaceVariantGetPtrBuiltinMethod);
LOAD_PROC_ADDRESS(variant_get_ptr_constructor, GDExtensionInterfaceVariantGetPtrConstructor);
LOAD_PROC_ADDRESS(variant_get_ptr_destructor, GDExtensionInterfaceVariantGetPtrDestructor);
LOAD_PROC_ADDRESS(variant_construct, GDExtensionInterfaceVariantConstruct);
LOAD_PROC_ADDRESS(variant_get_ptr_setter, GDExtensionInterfaceVariantGetPtrSetter);
LOAD_PROC_ADDRESS(variant_get_ptr_getter, GDExtensionInterfaceVariantGetPtrGetter);
LOAD_PROC_ADDRESS(variant_get_ptr_indexed_setter, GDExtensionInterfaceVariantGetPtrIndexedSetter);
LOAD_PROC_ADDRESS(variant_get_ptr_indexed_getter, GDExtensionInterfaceVariantGetPtrIndexedGetter);
LOAD_PROC_ADDRESS(variant_get_ptr_keyed_setter, GDExtensionInterfaceVariantGetPtrKeyedSetter);
LOAD_PROC_ADDRESS(variant_get_ptr_keyed_getter, GDExtensionInterfaceVariantGetPtrKeyedGetter);
LOAD_PROC_ADDRESS(variant_get_ptr_keyed_checker, GDExtensionInterfaceVariantGetPtrKeyedChecker);
LOAD_PROC_ADDRESS(variant_get_constant_value, GDExtensionInterfaceVariantGetConstantValue);
LOAD_PROC_ADDRESS(variant_get_ptr_utility_function, GDExtensionInterfaceVariantGetPtrUtilityFunction);
LOAD_PROC_ADDRESS(string_new_with_latin1_chars, GDExtensionInterfaceStringNewWithLatin1Chars);
LOAD_PROC_ADDRESS(string_new_with_utf8_chars, GDExtensionInterfaceStringNewWithUtf8Chars);
LOAD_PROC_ADDRESS(string_new_with_utf16_chars, GDExtensionInterfaceStringNewWithUtf16Chars);
LOAD_PROC_ADDRESS(string_new_with_utf32_chars, GDExtensionInterfaceStringNewWithUtf32Chars);
LOAD_PROC_ADDRESS(string_new_with_wide_chars, GDExtensionInterfaceStringNewWithWideChars);
LOAD_PROC_ADDRESS(string_new_with_latin1_chars_and_len, GDExtensionInterfaceStringNewWithLatin1CharsAndLen);
LOAD_PROC_ADDRESS(string_new_with_utf8_chars_and_len, GDExtensionInterfaceStringNewWithUtf8CharsAndLen);
LOAD_PROC_ADDRESS(string_new_with_utf8_chars_and_len2, GDExtensionInterfaceStringNewWithUtf8CharsAndLen2);
LOAD_PROC_ADDRESS(string_new_with_utf16_chars_and_len, GDExtensionInterfaceStringNewWithUtf16CharsAndLen);
LOAD_PROC_ADDRESS(string_new_with_utf16_chars_and_len2, GDExtensionInterfaceStringNewWithUtf16CharsAndLen2);
LOAD_PROC_ADDRESS(string_new_with_utf32_chars_and_len, GDExtensionInterfaceStringNewWithUtf32CharsAndLen);
LOAD_PROC_ADDRESS(string_new_with_wide_chars_and_len, GDExtensionInterfaceStringNewWithWideCharsAndLen);
LOAD_PROC_ADDRESS(string_to_latin1_chars, GDExtensionInterfaceStringToLatin1Chars);
LOAD_PROC_ADDRESS(string_to_utf8_chars, GDExtensionInterfaceStringToUtf8Chars);
LOAD_PROC_ADDRESS(string_to_utf16_chars, GDExtensionInterfaceStringToUtf16Chars);
LOAD_PROC_ADDRESS(string_to_utf32_chars, GDExtensionInterfaceStringToUtf32Chars);
LOAD_PROC_ADDRESS(string_to_wide_chars, GDExtensionInterfaceStringToWideChars);
LOAD_PROC_ADDRESS(string_operator_index, GDExtensionInterfaceStringOperatorIndex);
LOAD_PROC_ADDRESS(string_operator_index_const, GDExtensionInterfaceStringOperatorIndexConst);
LOAD_PROC_ADDRESS(string_operator_plus_eq_string, GDExtensionInterfaceStringOperatorPlusEqString);
LOAD_PROC_ADDRESS(string_operator_plus_eq_char, GDExtensionInterfaceStringOperatorPlusEqChar);
LOAD_PROC_ADDRESS(string_operator_plus_eq_cstr, GDExtensionInterfaceStringOperatorPlusEqCstr);
LOAD_PROC_ADDRESS(string_operator_plus_eq_wcstr, GDExtensionInterfaceStringOperatorPlusEqWcstr);
LOAD_PROC_ADDRESS(string_operator_plus_eq_c32str, GDExtensionInterfaceStringOperatorPlusEqC32str);
LOAD_PROC_ADDRESS(string_resize, GDExtensionInterfaceStringResize);
LOAD_PROC_ADDRESS(string_name_new_with_latin1_chars, GDExtensionInterfaceStringNameNewWithLatin1Chars);
LOAD_PROC_ADDRESS(string_name_new_with_utf8_chars_and_len, GDExtensionInterfaceStringNameNewWithUtf8CharsAndLen);
LOAD_PROC_ADDRESS(xml_parser_open_buffer, GDExtensionInterfaceXmlParserOpenBuffer);
LOAD_PROC_ADDRESS(file_access_store_buffer, GDExtensionInterfaceFileAccessStoreBuffer);
LOAD_PROC_ADDRESS(file_access_get_buffer, GDExtensionInterfaceFileAccessGetBuffer);
LOAD_PROC_ADDRESS(worker_thread_pool_add_native_group_task, GDExtensionInterfaceWorkerThreadPoolAddNativeGroupTask);
LOAD_PROC_ADDRESS(worker_thread_pool_add_native_task, GDExtensionInterfaceWorkerThreadPoolAddNativeTask);
LOAD_PROC_ADDRESS(packed_byte_array_operator_index, GDExtensionInterfacePackedByteArrayOperatorIndex);
LOAD_PROC_ADDRESS(packed_byte_array_operator_index_const, GDExtensionInterfacePackedByteArrayOperatorIndexConst);
LOAD_PROC_ADDRESS(packed_color_array_operator_index, GDExtensionInterfacePackedColorArrayOperatorIndex);
LOAD_PROC_ADDRESS(packed_color_array_operator_index_const, GDExtensionInterfacePackedColorArrayOperatorIndexConst);
LOAD_PROC_ADDRESS(packed_float32_array_operator_index, GDExtensionInterfacePackedFloat32ArrayOperatorIndex);
LOAD_PROC_ADDRESS(packed_float32_array_operator_index_const, GDExtensionInterfacePackedFloat32ArrayOperatorIndexConst);
LOAD_PROC_ADDRESS(packed_float64_array_operator_index, GDExtensionInterfacePackedFloat64ArrayOperatorIndex);
LOAD_PROC_ADDRESS(packed_float64_array_operator_index_const, GDExtensionInterfacePackedFloat64ArrayOperatorIndexConst);
LOAD_PROC_ADDRESS(packed_int32_array_operator_index, GDExtensionInterfacePackedInt32ArrayOperatorIndex);
LOAD_PROC_ADDRESS(packed_int32_array_operator_index_const, GDExtensionInterfacePackedInt32ArrayOperatorIndexConst);
LOAD_PROC_ADDRESS(packed_int64_array_operator_index, GDExtensionInterfacePackedInt64ArrayOperatorIndex);
LOAD_PROC_ADDRESS(packed_int64_array_operator_index_const, GDExtensionInterfacePackedInt64ArrayOperatorIndexConst);
LOAD_PROC_ADDRESS(packed_string_array_operator_index, GDExtensionInterfacePackedStringArrayOperatorIndex);
LOAD_PROC_ADDRESS(packed_string_array_operator_index_const, GDExtensionInterfacePackedStringArrayOperatorIndexConst);
LOAD_PROC_ADDRESS(packed_vector2_array_operator_index, GDExtensionInterfacePackedVector2ArrayOperatorIndex);
LOAD_PROC_ADDRESS(packed_vector2_array_operator_index_const, GDExtensionInterfacePackedVector2ArrayOperatorIndexConst);
LOAD_PROC_ADDRESS(packed_vector3_array_operator_index, GDExtensionInterfacePackedVector3ArrayOperatorIndex);
LOAD_PROC_ADDRESS(packed_vector3_array_operator_index_const, GDExtensionInterfacePackedVector3ArrayOperatorIndexConst);
LOAD_PROC_ADDRESS(packed_vector4_array_operator_index, GDExtensionInterfacePackedVector4ArrayOperatorIndex);
LOAD_PROC_ADDRESS(packed_vector4_array_operator_index_const, GDExtensionInterfacePackedVector4ArrayOperatorIndexConst);
LOAD_PROC_ADDRESS(array_operator_index, GDExtensionInterfaceArrayOperatorIndex);
LOAD_PROC_ADDRESS(array_operator_index_const, GDExtensionInterfaceArrayOperatorIndexConst);
LOAD_PROC_ADDRESS(array_set_typed, GDExtensionInterfaceArraySetTyped);
LOAD_PROC_ADDRESS(dictionary_operator_index, GDExtensionInterfaceDictionaryOperatorIndex);
LOAD_PROC_ADDRESS(dictionary_operator_index_const, GDExtensionInterfaceDictionaryOperatorIndexConst);
LOAD_PROC_ADDRESS(dictionary_set_typed, GDExtensionInterfaceDictionarySetTyped);
LOAD_PROC_ADDRESS(object_method_bind_call, GDExtensionInterfaceObjectMethodBindCall);
LOAD_PROC_ADDRESS(object_method_bind_ptrcall, GDExtensionInterfaceObjectMethodBindPtrcall);
LOAD_PROC_ADDRESS(object_destroy, GDExtensionInterfaceObjectDestroy);
LOAD_PROC_ADDRESS(global_get_singleton, GDExtensionInterfaceGlobalGetSingleton);
LOAD_PROC_ADDRESS(object_get_instance_binding, GDExtensionInterfaceObjectGetInstanceBinding);
LOAD_PROC_ADDRESS(object_set_instance_binding, GDExtensionInterfaceObjectSetInstanceBinding);
LOAD_PROC_ADDRESS(object_free_instance_binding, GDExtensionInterfaceObjectFreeInstanceBinding);
LOAD_PROC_ADDRESS(object_set_instance, GDExtensionInterfaceObjectSetInstance);
LOAD_PROC_ADDRESS(object_get_class_name, GDExtensionInterfaceObjectGetClassName);
LOAD_PROC_ADDRESS(object_cast_to, GDExtensionInterfaceObjectCastTo);
LOAD_PROC_ADDRESS(object_get_instance_from_id, GDExtensionInterfaceObjectGetInstanceFromId);
LOAD_PROC_ADDRESS(object_get_instance_id, GDExtensionInterfaceObjectGetInstanceId);
LOAD_PROC_ADDRESS(object_has_script_method, GDExtensionInterfaceObjectHasScriptMethod);
LOAD_PROC_ADDRESS(object_call_script_method, GDExtensionInterfaceObjectCallScriptMethod);
LOAD_PROC_ADDRESS(callable_custom_create2, GDExtensionInterfaceCallableCustomCreate2);
LOAD_PROC_ADDRESS(callable_custom_get_userdata, GDExtensionInterfaceCallableCustomGetUserdata);
LOAD_PROC_ADDRESS(ref_get_object, GDExtensionInterfaceRefGetObject);
LOAD_PROC_ADDRESS(ref_set_object, GDExtensionInterfaceRefSetObject);
LOAD_PROC_ADDRESS(script_instance_create3, GDExtensionInterfaceScriptInstanceCreate3);
LOAD_PROC_ADDRESS(placeholder_script_instance_create, GDExtensionInterfacePlaceholderScriptInstanceCreate);
LOAD_PROC_ADDRESS(placeholder_script_instance_update, GDExtensionInterfacePlaceholderScriptInstanceUpdate);
LOAD_PROC_ADDRESS(object_get_script_instance, GDExtensionInterfaceObjectGetScriptInstance);
LOAD_PROC_ADDRESS(object_set_script_instance, GDExtensionInterfaceObjectSetScriptInstance);
LOAD_PROC_ADDRESS(classdb_construct_object3, GDExtensionInterfaceClassdbConstructObject3);
LOAD_PROC_ADDRESS(classdb_get_method_bind, GDExtensionInterfaceClassdbGetMethodBind);
LOAD_PROC_ADDRESS(classdb_get_class_tag, GDExtensionInterfaceClassdbGetClassTag);
LOAD_PROC_ADDRESS(classdb_register_extension_class6, GDExtensionInterfaceClassdbRegisterExtensionClass6);
LOAD_PROC_ADDRESS(classdb_register_extension_class_method, GDExtensionInterfaceClassdbRegisterExtensionClassMethod);
LOAD_PROC_ADDRESS(classdb_register_extension_class_virtual_method, GDExtensionInterfaceClassdbRegisterExtensionClassVirtualMethod);
LOAD_PROC_ADDRESS(classdb_register_extension_class_integer_constant, GDExtensionInterfaceClassdbRegisterExtensionClassIntegerConstant);
LOAD_PROC_ADDRESS(classdb_register_extension_class_property, GDExtensionInterfaceClassdbRegisterExtensionClassProperty);
LOAD_PROC_ADDRESS(classdb_register_extension_class_property_indexed, GDExtensionInterfaceClassdbRegisterExtensionClassPropertyIndexed);
LOAD_PROC_ADDRESS(classdb_register_extension_class_property_group, GDExtensionInterfaceClassdbRegisterExtensionClassPropertyGroup);
LOAD_PROC_ADDRESS(classdb_register_extension_class_property_subgroup, GDExtensionInterfaceClassdbRegisterExtensionClassPropertySubgroup);
LOAD_PROC_ADDRESS(classdb_register_extension_class_signal, GDExtensionInterfaceClassdbRegisterExtensionClassSignal);
LOAD_PROC_ADDRESS(classdb_unregister_extension_class, GDExtensionInterfaceClassdbUnregisterExtensionClass);
LOAD_PROC_ADDRESS(get_library_path, GDExtensionInterfaceGetLibraryPath);
LOAD_PROC_ADDRESS(editor_add_plugin, GDExtensionInterfaceEditorAddPlugin);
LOAD_PROC_ADDRESS(editor_remove_plugin, GDExtensionInterfaceEditorRemovePlugin);
LOAD_PROC_ADDRESS(editor_register_get_classes_used_callback, GDExtensionInterfaceEditorRegisterGetClassesUsedCallback);
LOAD_PROC_ADDRESS(editor_help_load_xml_from_utf8_chars, GDExtensionInterfaceEditorHelpLoadXmlFromUtf8Chars);
LOAD_PROC_ADDRESS(editor_help_load_xml_from_utf8_chars_and_len, GDExtensionInterfaceEditorHelpLoadXmlFromUtf8CharsAndLen);
LOAD_PROC_ADDRESS(image_ptrw, GDExtensionInterfaceImagePtrw);
LOAD_PROC_ADDRESS(image_ptr, GDExtensionInterfaceImagePtr);
LOAD_PROC_ADDRESS(register_main_loop_callbacks, GDExtensionInterfaceRegisterMainLoopCallbacks);
gd_library = p_library;
r_initialization->userdata = 0;
r_initialization->minimum_initialization_level = GDEXTENSION_INITIALIZATION_CORE;
r_initialization->initialize = engine_init;
r_initialization->deinitialize = engine_exit;
gdextension_get_godot_version2(&gd_godot_version_cached);
GDExtensionMainLoopCallbacks callbacks = {
.startup_func = gd_on_first_frame,
.shutdown_func = gd_on_final_frame,
.frame_func = gd_on_every_frame,
};
gdextension_register_main_loop_callbacks(p_library, &callbacks);
for (int i = 1; i < GDEXTENSION_VARIANT_TYPE_VARIANT_MAX; i++) {
GDExtensionVariantType v = (GDExtensionVariantType)i;
variant_from_type_constructors[i] = gdextension_get_variant_from_type_constructor(v);
type_from_variant_constructors[i] = gdextension_get_variant_to_type_constructor(v);
variant_ptr_destructors[i] = gdextension_variant_get_ptr_destructor(v);
variant_internal_ptr_funcs[i] = gdextension_variant_get_ptr_internal_getter(v);
variant_ptr_indexed_setters[i] = gdextension_variant_get_ptr_indexed_setter(v);
variant_ptr_indexed_getters[i] = gdextension_variant_get_ptr_indexed_getter(v);
variant_ptr_keyed_setters[i] = gdextension_variant_get_ptr_keyed_setter(v);
variant_ptr_keyed_getters[i] = gdextension_variant_get_ptr_keyed_getter(v);
}
return true;
}
void prepare_variants(void **frame, uint32_t argc, ANY args) {
uint8_t *head = (uint8_t*)args;
for (int i = 0; i < argc; i++) {
frame[i] = head;
head += 24;
}
}
// Helper macro to align a value to the next multiple of 'align'
#define ALIGN_UP(value, align) (((value) + ((align) - 1)) & ~((align) - 1))
// Packed size and alignment of each shape nibble code, mirroring the Go
// side's shapeSizes/shapeAlignMasks (gdextension.SizeArguments).
static const uint8_t gd_shape_sizes[16] = {0, 1, 2, 4, 8, 8, 12, 16, 16, 24, 24, 36, 48, 64, 0, 0};
static const uint8_t gd_shape_aligns[16] = {1, 1, 2, 4, 8, 4, 4, 8, 4, 8, 4, 4, 4, 4, 1, 1};
uint8_t prepare_callframe(int skip, void **frame, uint64_t shape, ANY args) {
uint8_t *head = (uint8_t *)args;
ptrdiff_t offset = 0; // Track current offset in the frame
int i = 0;
// Nibbles are contiguous with all higher nibbles zero, so the walk can
// stop when the remaining bits run out.
for (uint64_t s = shape >> (skip * 4); s; s >>= 4, i++) {
Shape code = (Shape)(s & 0xF);
offset = ALIGN_UP(offset, gd_shape_aligns[code]);
frame[i] = head + offset;
offset += gd_shape_sizes[code];
}
if (i < 16 - skip) frame[i] = NULL;
return i;
}
uintptr_t gd_builtin_name(uintptr_t name, INT64(hash)) { return (uintptr_t)gdextension_variant_get_ptr_utility_function((GDExtensionConstStringNamePtr)&name, INT64_FROM(hash));}
void gd_builtin_call(uintptr_t fn, ANY result, UINT64(shape), ANY args) {
void *points[16]; uint8_t argc = prepare_callframe(1, &points[0], UINT64_FROM(shape), args);
((GDExtensionPtrUtilityFunction)fn)((GDExtensionTypePtr)result, (GDExtensionConstTypePtr*)&points[0], argc);
}
void gd_callable_create(uintptr_t id, UINT64(object), ANY result) {
GDExtensionCallableCustomInfo2 info = {
.callable_userdata = (void *)id,
.token = gd_library,
.object_id = UINT64_FROM(object),
.call_func = callable_call,
.is_valid_func = callable_validation,
.free_func = callable_free,
.hash_func = callable_hash,
.equal_func = callable_compare,
.less_than_func = callable_less_than,
.to_string_func = callable_stringify,
.get_argument_count_func = callable_get_argument_count,
};
gdextension_callable_custom_create2((uint64_t *)result, &info);
}
uintptr_t gd_library_location() {
uintptr_t s;
gdextension_get_library_path(gd_library, &s);
return s;
}
uintptr_t gd_callable_lookup(UINT64(a), UINT64(b)) {
uint64_t callable[2] = {UINT64_FROM(a), UINT64_FROM(b)};
return (uintptr_t)gdextension_callable_custom_get_userdata(&callable, gd_library);
};
void gd_classdb_FileAccess_write(uintptr_t FileAccess, BUFFER buf, INT len) {
gdextension_file_access_store_buffer((GDExtensionObjectPtr)FileAccess, (const uint8_t *)BUFFER_POINTER(buf), len);
};
INT gd_classdb_FileAccess_read(uintptr_t FileAccess, BUFFER buf, INT len) {
return gdextension_file_access_get_buffer((GDExtensionObjectPtr)FileAccess, (uint8_t *)BUFFER_POINTER(buf), len);
};
uintptr_t gd_classdb_Image_unsafe(uintptr_t Image) {
return (uintptr_t)gdextension_image_ptrw((GDExtensionObjectPtr)Image);
};
uint8_t gd_classdb_Image_access(uintptr_t Image, INT offset) {
return gdextension_image_ptr((GDExtensionObjectPtr)Image)[offset];
};
typedef struct {
int32_t push;
int32_t size;
GDExtensionClassMethodInfo *info;
} method_list;
typedef struct {
int32_t push;
int32_t size;
GDExtensionPropertyInfo *info;
GDExtensionClassMethodArgumentMetadata *meta;
} property_list;
uintptr_t gd_method_list_make(INT length) {
method_list *list = (method_list *)gdextension_mem_alloc(sizeof(method_list));
list->push = 0;
list->size = length;
list->info = (GDExtensionClassMethodInfo*)gdextension_mem_alloc(sizeof(GDExtensionClassMethodInfo) * length);
return (uintptr_t)list;
};
void gd_method_list_push(uintptr_t list_p, uintptr_t name, uintptr_t method, uint32_t method_flags, uintptr_t return_value_info, uintptr_t arguments_info, INT default_argument_count, ANY default_arguments) {
method_list *list = (method_list *)list_p;
if (list->push >= list->size) return;
GDExtensionClassMethodInfo *info = &list->info[list->push++];
property_list *return_value = (property_list *)return_value_info;
property_list *arguments = (property_list *)arguments_info;
uintptr_t *name_allocated = (uintptr_t *)gdextension_mem_alloc(sizeof(uintptr_t));
*name_allocated = name;
info->name = (GDExtensionStringNamePtr)name_allocated;
info->method_userdata = (void *)method;
info->call_func = extension_instance_dynamic_call;
info->ptrcall_func = extension_instance_checked_call;
info->method_flags = method_flags;
if (return_value && return_value->push > 0) {
info->has_return_value = true;
info->return_value_info = return_value->info;
info->return_value_metadata = *return_value->meta;
} else {
info->has_return_value = false;
info->return_value_info = NULL;
info->return_value_metadata = (GDExtensionClassMethodArgumentMetadata)0;
}
if (arguments && arguments->push > 0) {
info->argument_count = arguments->push;
info->arguments_info = arguments->info;
info->arguments_metadata = arguments->meta;
} else {
info->argument_count = 0;
info->arguments_info = NULL;
info->arguments_metadata = NULL;
}
void **points = (void **)gdextension_mem_alloc(sizeof(void*) * default_argument_count);
prepare_variants(&points[0], default_argument_count, default_arguments);
info->default_argument_count = default_argument_count;
info->default_arguments = points;
};
void gd_method_list_free(uintptr_t list_p) {
method_list *list = (method_list *)list_p;
for (int i = 0; i < list->push; i++) {
gdextension_mem_free(list->info[i].name);
if (list->info[i].default_arguments) {
gdextension_mem_free(list->info[i].default_arguments);
}
}
gdextension_mem_free(list->info); gdextension_mem_free(list);
};
uintptr_t gd_property_list_make(INT length) {
property_list *list = (property_list*)gdextension_mem_alloc(sizeof(property_list));
list->push = 0;
list->size = length;
list->info = (GDExtensionPropertyInfo*)gdextension_mem_alloc(sizeof(GDExtensionPropertyInfo) * length);
list->meta = (GDExtensionClassMethodArgumentMetadata*)gdextension_mem_alloc(sizeof(GDExtensionClassMethodArgumentMetadata) * length);
return (uintptr_t)list;
};
void gd_property_list_push(uintptr_t list_p, uint32_t vtype, uintptr_t name, uintptr_t class_name, uint32_t hint, uintptr_t hint_string, uint32_t usage, uint32_t meta) {
property_list *list = (property_list *)list_p;
if (list->push >= list->size) return;
GDExtensionPropertyInfo *info = &list->info[list->push++];
GDExtensionClassMethodArgumentMetadata *meta_info = &list->meta[list->push - 1];
uintptr_t *name_allocated = (uintptr_t *)gdextension_mem_alloc(sizeof(uintptr_t));
*name_allocated = name;
uintptr_t *class_name_allocated = (uintptr_t *)gdextension_mem_alloc(sizeof(uintptr_t));
*class_name_allocated = class_name;
uintptr_t *hint_string_allocated = (uintptr_t *)gdextension_mem_alloc(sizeof(uintptr_t));
*hint_string_allocated = hint_string;
info->type = (GDExtensionVariantType)vtype;
info->name = (GDExtensionStringNamePtr)name_allocated;
info->class_name = (GDExtensionStringNamePtr)class_name_allocated;
info->hint = hint;
info->hint_string = (GDExtensionStringPtr)hint_string_allocated;
info->usage = usage;
*meta_info = (GDExtensionClassMethodArgumentMetadata)meta;
};
void gd_property_list_free(uintptr_t list_p) {
property_list *list = (property_list *)list_p;
for (int i = 0; i < list->push; i++) {
gdextension_mem_free(list->info[i].name);
gdextension_mem_free(list->info[i].class_name);
gdextension_mem_free(list->info[i].hint_string);
}
gdextension_mem_free(list->info);
gdextension_mem_free(list->meta);
gdextension_mem_free(list);
};
uint32_t gd_property_info_type(uintptr_t list_p) {
property_list *list = (property_list *)list_p;
return list->info[list->push-1].type;
};
uintptr_t gd_property_info_name(uintptr_t list_p) {
property_list *list = (property_list *)list_p;
return (uintptr_t)list->info[list->push-1].name;
};
uintptr_t gd_property_info_class_name(uintptr_t list_p) {
property_list *list = (property_list *)list_p;
return (uintptr_t)list->info[list->push-1].class_name;
};
uint32_t gd_property_info_hint(uintptr_t list_p) {
property_list *list = (property_list *)list_p;
return list->info[list->push-1].hint;
};
uintptr_t gd_property_info_hint_string(uintptr_t list_p) {
property_list *list = (property_list *)list_p;
return (uintptr_t)list->info[list->push-1].hint_string;
};
uint32_t gd_property_info_usage(uintptr_t list_p) {
property_list *list = (property_list *)list_p;
return list->info[list->push-1].usage;
};
static GDExtensionBool extension_instance_set(GDExtensionClassInstancePtr instance, GDExtensionConstStringNamePtr field, GDExtensionConstVariantPtr value) {
uint64_t *v = (uint64_t *)value;
return gd_on_extension_instance_set((uintptr_t)instance, *(uintptr_t*)field, UINT64_MAKE(v[0]), UINT64_MAKE(v[1]), UINT64_MAKE(v[2]));
}
static GDExtensionBool extension_instance_get(GDExtensionClassInstancePtr instance, GDExtensionConstStringNamePtr field, GDExtensionVariantPtr value) {
return gd_on_extension_instance_get((uintptr_t)instance, *(uintptr_t*)field, value);
}
static GDExtensionBool extension_instance_property_has_default(GDExtensionClassInstancePtr instance, GDExtensionConstStringNamePtr field) {
return gd_on_extension_instance_property_has_default((uintptr_t)instance, *(uintptr_t*)field);
}
static GDExtensionBool extension_instance_property_get_default(GDExtensionClassInstancePtr instance, GDExtensionConstStringNamePtr field, GDExtensionVariantPtr value) {
return gd_on_extension_instance_property_get_default((uintptr_t)instance, *(uintptr_t*)field, value);
}
static const GDExtensionPropertyInfo *extension_instance_property_list(GDExtensionClassInstancePtr instance, uint32_t *count) {
property_list *list = (property_list*)gd_on_extension_instance_property_list((uintptr_t)instance);
GDExtensionPropertyInfo *info = list ? list->info : NULL;
*count = list ? list->push : 0;
if (list && list->meta) {
gdextension_mem_free(list->meta);
}
return info;
}
static void class_free_property_list_func(GDExtensionClassInstancePtr instance, const GDExtensionPropertyInfo *list, uint32_t count) {
if (list) gdextension_mem_free((void*)list);
}
static GDExtensionBool extension_instance_property_validation(GDExtensionClassInstancePtr instance, GDExtensionPropertyInfo *field) {
property_list list = {
.push = 1,
.size = 1,
.info = field,
.meta = NULL
};
return gd_on_extension_instance_property_validation((uintptr_t)instance, (uintptr_t)&list);
}
static void extension_instance_stringify(GDExtensionClassInstancePtr instance, GDExtensionBool *ok, GDExtensionStringPtr s) {
uint32_t result = gd_on_extension_instance_stringify((uintptr_t)instance);
if (result) {
*(uint32_t*)s = result;
*ok = true;
} else {
gdextension_string_new_with_latin1_chars(s, ""); // FIXME/TODO remove in 4.5 (where my PR to fix this has been merged https://github.com/godotengine/godot/pull/105546)
*ok = false;
}
}
static void extension_instance_reference(GDExtensionClassInstancePtr instance) {
gd_on_extension_instance_reference((uintptr_t)instance, true);
}
static GDExtensionBool extension_instance_unreference(GDExtensionClassInstancePtr instance) {
return gd_on_extension_instance_reference((uintptr_t)instance, false);
}
static GDExtensionObjectPtr extension_class_create(void *user_data, GDExtensionBool notify_postinitialize) {
return (GDExtensionObjectPtr)gd_on_extension_class_create((uintptr_t)user_data, notify_postinitialize);
}
static void *extension_class_caller(void *user_data, GDExtensionConstStringNamePtr name, uint32_t hash) {
return (void*)gd_on_extension_class_caller((uintptr_t)user_data, *(uintptr_t*)name, hash);
}
static void extension_instance_called(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name, void *p_virtual_call_userdata, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_ret) {
gd_on_extension_instance_called((uintptr_t)p_instance, (uintptr_t)p_virtual_call_userdata, r_ret, (void *)p_args);
}
// gd_stock_virtual_entry exposes the stock entry above so Go can register it
// as the fallback target of a fast-path thunk (compiler.gd's runtime
// fastcbentry tail-jumps to it, arguments untouched, whenever the resident
// fast path's preconditions do not hold).
void *gd_stock_virtual_entry(void) { return (void*)extension_instance_called; }
// gd_ring_drain (defined with the ring machinery next to gd_ring_flush)
// drains the main thread's call ring in C when an engine->Go callback returns,
// so buffered outbound calls execute without a Go->C crossing to pay for the
// flush.
static void gd_ring_drain(void);
// gd_sticky_call_virtual, when set by Go (internal/sticky.EntryAddr), is a
// System V C-ABI thunk that runs the virtual dispatch WITHOUT a cgocallback
// transition (the sticky-P fast path). gd_call_virtual_dispatch routes each
// virtual call to it when armed, else to the stock cgocallback path.
void *gd_sticky_call_virtual = 0;
// gd_frame_active is set by Go (via asmcgocall around the engine Iteration) for
// the duration of a frame during which the P is HELD — the only window in which
// the no-transition fast path is safe (m.p valid, so the dispatch can allocate).
// Outside it, virtual calls take the stock cgocallback path.
int gd_frame_active = 0;
// gd_sticky_generic is the ONE generic fast entry (void(uintptr tag, void*frame))
// for every non-virtual engine->Go callback during a held frame. Set by Go.
void *gd_sticky_generic = 0;
static inline void gd_generic(uintptr_t tag, void *frame) {
((void(*)(uintptr_t, void*))gd_sticky_generic)(tag, frame);
}
// Callback tags — must match internal/startup genericDispatch.
enum {
GD_TAG_NOTIFICATION = 1,
GD_TAG_CHECKED_CALL = 2,
GD_TAG_EVERY_FRAME = 3,
GD_TAG_FIRST_FRAME = 4,
GD_TAG_FINAL_FRAME = 5,
};
static void gd_call_virtual_dispatch(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name, void *p_virtual_call_userdata, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_ret) {
if (gd_sticky_call_virtual) {
((void(*)(GDExtensionClassInstancePtr, GDExtensionConstStringNamePtr, void *, const GDExtensionConstTypePtr *, GDExtensionTypePtr))gd_sticky_call_virtual)(p_instance, p_name, p_virtual_call_userdata, p_args, r_ret);
} else {
extension_instance_called(p_instance, p_name, p_virtual_call_userdata, p_args, r_ret);
}
gd_ring_drain();
}
static void extension_instance_free(void *p_class_userdata, GDExtensionClassInstancePtr p_instance) {
gd_on_extension_instance_free((uintptr_t)p_instance);
}
// gd_go_handles_notifications is flipped on by Go (classdb) when a registered
// class implements a Notification handler. Until then the per-frame process
// tick notifications (NOTIFICATION_PHYSICS_PROCESS=16, NOTIFICATION_PROCESS=17,
// NOTIFICATION_INTERNAL_PROCESS=25, NOTIFICATION_INTERNAL_PHYSICS_PROCESS=26)
// are dropped here, engine-side: they arrive once per processing node per frame
// and would otherwise pay a full C->Go crossing just to hit a no-op.
bool gd_go_handles_notifications = false;
static void extension_instance_notification(GDExtensionClassInstancePtr p_instance, int32_t p_what, GDExtensionBool p_reversed) {
switch (p_what) {
case 16: case 17: case 25: case 26:
if (!gd_go_handles_notifications) return;
}
gd_on_extension_instance_notification((uintptr_t)p_instance, p_what, p_reversed);
gd_ring_drain();
}
void gd_classdb_register(uintptr_t class_name, uintptr_t parent, uintptr_t id, bool is_virtual, bool abstract, bool exposed, bool runtime, uintptr_t icon_path) {
GDExtensionClassCreationInfo6 info = {
.is_virtual = is_virtual,
.is_abstract = abstract,
.is_exposed = exposed,
.is_runtime = runtime,
.icon_path = (GDExtensionConstStringNamePtr)&icon_path,
.set_func = extension_instance_set,
.get_func = extension_instance_get,
.get_property_list_func = extension_instance_property_list,
.free_property_list_func = class_free_property_list_func,
.property_can_revert_func = extension_instance_property_has_default,
.property_get_revert_func = extension_instance_property_get_default,
.validate_property_func = extension_instance_property_validation,
.notification_func = (GDExtensionClassNotification2)extension_instance_notification,
.to_string_func = extension_instance_stringify,
//.reference_func = (GDExtensionClassReference)class_reference, // FIXME JavaScript error: null function or function signature mismatch
//.unreference_func = (GDExtensionClassUnreference)class_unreference, // FIXME JavaScript error: null function or function signature mismatch
.create_instance_func = extension_class_create,
.free_instance_func = extension_instance_free,
.get_virtual_call_data_func = extension_class_caller,
.call_virtual_with_data_func = gd_call_virtual_dispatch,
.class_userdata = (void *)id,
};
gdextension_classdb_register_extension_class6(gd_library, (GDExtensionConstStringNamePtr)&class_name, (GDExtensionConstStringNamePtr)&parent, &info);
};
void gd_classdb_register_methods(uintptr_t class_name, uintptr_t methods) {
method_list *list = (method_list *)methods;
for (int i = 0; i < list->push; i++) {
GDExtensionClassMethodInfo *info = &list->info[i];
gdextension_classdb_register_extension_class_method(gd_library, (GDExtensionConstStringNamePtr)&class_name, info);
}
};
void gd_classdb_register_constant(uintptr_t class_name, uintptr_t enum_name, uintptr_t name, INT64(value), bool bitfield) {
gdextension_classdb_register_extension_class_integer_constant(gd_library, (GDExtensionConstStringNamePtr)&class_name, (GDExtensionConstStringNamePtr)&enum_name, (GDExtensionConstStringNamePtr)&name, INT64_FROM(value), bitfield);
};
void gd_classdb_register_property(uintptr_t class_name, uintptr_t info, uintptr_t setter, uintptr_t getter) {
property_list *list = (property_list *)info;
gdextension_classdb_register_extension_class_property(gd_library, (GDExtensionConstStringNamePtr)&class_name, list->info, (GDExtensionConstStringNamePtr)&setter, (GDExtensionConstStringNamePtr)&getter);
};
// The Go side passes the index as a single (32-bit safe) integer; INT keeps
// int64_t natively and a single int32 on the web (INT64 would demand a
// hi/lo pair the callers never sent).
void gd_classdb_register_property_indexed(uintptr_t class_name, uintptr_t info, uintptr_t setter, uintptr_t getter, INT index) {
property_list *list = (property_list *)info;
gdextension_classdb_register_extension_class_property_indexed(gd_library, (GDExtensionConstStringNamePtr)&class_name, list->info, (GDExtensionConstStringNamePtr)&setter, (GDExtensionConstStringNamePtr)&getter, index);
};
void gd_classdb_register_property_group(uintptr_t class_name, uintptr_t group, uintptr_t prefix) {
gdextension_classdb_register_extension_class_property_group(gd_library, (GDExtensionConstStringNamePtr)&class_name, (GDExtensionConstStringNamePtr)&group, (GDExtensionConstStringPtr)&prefix);
};
void gd_classdb_register_property_sub_group(uintptr_t class_name, uintptr_t subgroup, uintptr_t prefix) {
gdextension_classdb_register_extension_class_property_subgroup(gd_library, (GDExtensionConstStringNamePtr)&class_name, (GDExtensionConstStringNamePtr)&subgroup, (GDExtensionConstStringPtr)&prefix);
};
void gd_classdb_register_signal(uintptr_t class_name, uintptr_t name, uintptr_t args) {
property_list *list = (property_list *)args;
gdextension_classdb_register_extension_class_signal(gd_library, (GDExtensionConstStringNamePtr)&class_name, (GDExtensionConstStringNamePtr)&name, list->info, list->push);
};
void gd_classdb_register_removal(uintptr_t class_name) {
gdextension_classdb_unregister_extension_class(gd_library, (GDExtensionConstStringNamePtr)&class_name);
};
void gd_classdb_WorkerThreadPool_add_task(uintptr_t WorkerPool, uintptr_t task_id, bool priority, uintptr_t description) {
gdextension_worker_thread_pool_add_native_task((GDExtensionObjectPtr)WorkerPool, (GDExtensionWorkerThreadPoolTask)gd_on_worker_thread_pool_task, (void *)task_id, priority, (GDExtensionConstStringNamePtr)&description);
};
void gd_classdb_WorkerThreadPool_add_group_task(uintptr_t WorkerPool, uintptr_t task_id, int32_t elements, int32_t tasks, bool priority, uintptr_t description) {
gdextension_worker_thread_pool_add_native_group_task((GDExtensionObjectPtr)WorkerPool, (GDExtensionWorkerThreadPoolGroupTask)gd_on_worker_thread_pool_group_task, (void *)task_id, elements, tasks, priority, (GDExtensionConstStringNamePtr)&description);
};
INT gd_classdb_XMLParser_load(uintptr_t XMLParser, BUFFER buf, INT len) {
return gdextension_xml_parser_open_buffer((GDExtensionObjectPtr)XMLParser, (const uint8_t *)BUFFER_POINTER(buf), len);
};
void gd_packed_dictionary_access(uintptr_t dict, UINT64(k1), UINT64(k2), UINT64(k3), ANY args) {
uint64_t key[3] = {UINT64_FROM(k1), UINT64_FROM(k2), UINT64_FROM(k3)};
uint64_t *value = (uint64_t*)gdextension_dictionary_operator_index_const((GDExtensionTypePtr)&dict, &key[0]);
if (!value) return;
// Shallow header copy — callers must Variants.Copy before Free (see gd_array_get).
uint64_t * result = (uint64_t*)args;
result[0] = value[0];
result[1] = value[1];
result[2] = value[2];
};
void gd_packed_dictionary_modify(uintptr_t dict, UINT64(k1), UINT64(k2), UINT64(k3), UINT64(v1), UINT64(v2), UINT64(v3)) {
uint64_t key[3] = {UINT64_FROM(k1), UINT64_FROM(k2), UINT64_FROM(k3)};
uint64_t *value = (uint64_t*)gdextension_dictionary_operator_index((GDExtensionTypePtr)&dict, (GDExtensionVariantPtr)&key[0]);
value[0] = UINT64_FROM(v1);
value[1] = UINT64_FROM(v2);
value[2] = UINT64_FROM(v3);
};
void gd_editor_add_documentation(STRING xml, INT len) {
gdextension_editor_help_load_xml_from_utf8_chars_and_len(STRING_POINTER(xml), len);
};
void gd_editor_add_plugin(uintptr_t class_name) {
gdextension_editor_add_plugin((GDExtensionConstStringNamePtr)&class_name);
};
void gd_editor_end_plugin(uintptr_t class_name) {
gdextension_editor_remove_plugin((GDExtensionConstStringNamePtr)&class_name);
};
void gd_iterator_make(UINT64(v1), UINT64(v2), UINT64(v3), ANY result, ANY err) {
uint64_t self[3] = {UINT64_FROM(v1), UINT64_FROM(v2), UINT64_FROM(v3)};
GDExtensionBool valid = true;
valid = valid && gdextension_variant_iter_init(&self, (void*)result, &valid);
if (valid) return;
((GDExtensionCallError*)err)->error = GDEXTENSION_CALL_ERROR_INVALID_ARGUMENT;
};
bool gd_iterator_next(UINT64(v1), UINT64(v2), UINT64(v3), ANY iter, ANY err) {
uint64_t self[3] = {UINT64_FROM(v1), UINT64_FROM(v2), UINT64_FROM(v3)};
GDExtensionBool valid = false;
GDExtensionBool ok = gdextension_variant_iter_next(&self, (GDExtensionVariantPtr)iter, &valid);
if (ok) {
return true;
}
((GDExtensionCallError*)err)->error = GDEXTENSION_CALL_ERROR_INVALID_ARGUMENT;
return false;
};
void gd_iterator_load(UINT64(v1), UINT64(v2), UINT64(v3), UINT64(i1), UINT64(i2), UINT64(i3), ANY result, ANY err) {
uint64_t self[3] = {UINT64_FROM(v1), UINT64_FROM(v2), UINT64_FROM(v3)};
uint64_t iter[3] = {UINT64_FROM(i1), UINT64_FROM(i2), UINT64_FROM(i3)};
void *points[16]; prepare_variants(&points[0], 1, result);
GDExtensionBool ok = false;
gdextension_variant_iter_get(&self, &iter, (GDExtensionUninitializedVariantPtr)points[0], &ok);
if (ok) return;
((GDExtensionCallError*)err)->error = GDEXTENSION_CALL_ERROR_INVALID_ARGUMENT;
};
const char *fit_string(const char *str, uint64_t len, char *buf, size_t buf_size) {
if (len == 0 || str == NULL) {
return NULL;
}
if (len >= buf_size) {
buf = (char *)gdextension_mem_alloc(len + 1); // +1 for null-terminator
}
memcpy(buf, str, len);
buf[len] = '\0'; // null-terminate the string
return buf;
}
void gd_log_error(
STRING text, INT text_len,
STRING code, INT code_len,
STRING func, INT func_len,
STRING file, INT file_len,
int32_t line, bool notify_editor
) {
char text_buf[256]; const char *text_ptr = fit_string(STRING_POINTER(text), text_len, &text_buf[0], 256);
char code_buf[100]; const char *code_ptr = fit_string(STRING_POINTER(code), code_len, &code_buf[0], 100);
char func_buf[100]; const char *func_ptr = fit_string(STRING_POINTER(func), func_len, &func_buf[0], 100);
char file_buf[100]; const char *file_ptr = fit_string(STRING_POINTER(file), file_len, &file_buf[0], 100);
gdextension_print_error_with_message(code_ptr, text_ptr, func_ptr, file_ptr, line, notify_editor);
if (text_ptr && text_ptr != text_buf) gdextension_mem_free((void *)text_ptr);
if (code_ptr && code_ptr != code_buf) gdextension_mem_free((void *)code_ptr);
if (func_ptr && func_ptr != func_buf) gdextension_mem_free((void *)func_ptr);
if (file_ptr && file_ptr != file_buf) gdextension_mem_free((void *)file_ptr);
};
void gd_log_warning(
STRING text, INT text_len,
STRING code, INT code_len,
STRING func, INT func_len,
STRING file, INT file_len,
int32_t line, bool notify_editor
) {
char text_buf[256]; const char *text_ptr = fit_string(STRING_POINTER(text), text_len, &text_buf[0], 256);
char code_buf[100]; const char *code_ptr = fit_string(STRING_POINTER(code), code_len, &code_buf[0], 100);
char func_buf[100]; const char *func_ptr = fit_string(STRING_POINTER(func), func_len, &func_buf[0], 100);
char file_buf[100]; const char *file_ptr = fit_string(STRING_POINTER(file), file_len, &file_buf[0], 100);
gdextension_print_warning_with_message(code_ptr, text_ptr, func_ptr, file_ptr, line, notify_editor);
if (text_ptr && text_ptr != text_buf) gdextension_mem_free((void *)text_ptr);
if (code_ptr && code_ptr != code_buf) gdextension_mem_free((void *)code_ptr);
if (func_ptr && func_ptr != func_buf) gdextension_mem_free((void *)func_ptr);
if (file_ptr && file_ptr != file_buf) gdextension_mem_free((void *)file_ptr);
};
uintptr_t gd_memory_malloc(INT size) {
return (uintptr_t)gdextension_mem_alloc(size);
};
INT gd_memory_sizeof(uintptr_t name) {
return gdextension_get_native_struct_size((GDExtensionConstStringNamePtr)&name);
};
uintptr_t gd_memory_resize(uintptr_t addr, INT size) {
return (uintptr_t)gdextension_mem_realloc((void *)addr, size);
};
void gd_memory_free(uintptr_t addr) {
gdextension_mem_free((void *)addr);