variant.go 988 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package gdnative
  2. /*
  3. #include <gdnative/string.h>
  4. #include <gdnative/variant.h>
  5. #include "gdnative.gen.h"
  6. #include "variant.h"
  7. */
  8. import "C"
  9. // NewVariantWithString creates a new Variant initialized with the given string
  10. func NewVariantWithString(str String) Variant {
  11. var variant C.godot_variant
  12. C.go_godot_variant_new_string(GDNative.api, &variant, str.getBase())
  13. return Variant{base: &variant}
  14. }
  15. // GetType returns back the VaraintType for this Variant
  16. func (gdt *Variant) GetType() VariantType {
  17. variantType := C.go_godot_variant_get_type(GDNative.api, gdt.getBase())
  18. return VariantType(variantType)
  19. }
  20. // VariantArray is a wrapper around Godot C **godot_variant
  21. type VariantArray struct {
  22. array []Variant
  23. }
  24. func (gdt *VariantArray) getBase() **C.godot_variant {
  25. variantArray := C.go_godot_variant_build_array(C.int(len(gdt.array)))
  26. for i, variant := range gdt.array {
  27. C.go_godot_variant_add_element(variantArray, variant.getBase(), C.int(i))
  28. }
  29. return variantArray
  30. }