variant.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*************************************************************************/
  2. /* variant.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef GODOT_VARIANT_H
  31. #define GODOT_VARIANT_H
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. #include <stdint.h>
  36. #define GODOT_VARIANT_SIZE (16 + sizeof(void *))
  37. #ifndef GODOT_CORE_API_GODOT_VARIANT_TYPE_DEFINED
  38. #define GODOT_CORE_API_GODOT_VARIANT_TYPE_DEFINED
  39. typedef struct {
  40. uint8_t _dont_touch_that[GODOT_VARIANT_SIZE];
  41. } godot_variant;
  42. #endif
  43. typedef enum godot_variant_type {
  44. GODOT_VARIANT_TYPE_NIL,
  45. // atomic types
  46. GODOT_VARIANT_TYPE_BOOL,
  47. GODOT_VARIANT_TYPE_INT,
  48. GODOT_VARIANT_TYPE_REAL,
  49. GODOT_VARIANT_TYPE_STRING,
  50. // math types
  51. GODOT_VARIANT_TYPE_VECTOR2, // 5
  52. GODOT_VARIANT_TYPE_RECT2,
  53. GODOT_VARIANT_TYPE_VECTOR3,
  54. GODOT_VARIANT_TYPE_TRANSFORM2D,
  55. GODOT_VARIANT_TYPE_PLANE,
  56. GODOT_VARIANT_TYPE_QUAT, // 10
  57. GODOT_VARIANT_TYPE_AABB,
  58. GODOT_VARIANT_TYPE_BASIS,
  59. GODOT_VARIANT_TYPE_TRANSFORM,
  60. // misc types
  61. GODOT_VARIANT_TYPE_COLOR,
  62. GODOT_VARIANT_TYPE_NODE_PATH, // 15
  63. GODOT_VARIANT_TYPE_RID,
  64. GODOT_VARIANT_TYPE_OBJECT,
  65. GODOT_VARIANT_TYPE_DICTIONARY,
  66. GODOT_VARIANT_TYPE_ARRAY, // 20
  67. // arrays
  68. GODOT_VARIANT_TYPE_POOL_BYTE_ARRAY,
  69. GODOT_VARIANT_TYPE_POOL_INT_ARRAY,
  70. GODOT_VARIANT_TYPE_POOL_REAL_ARRAY,
  71. GODOT_VARIANT_TYPE_POOL_STRING_ARRAY,
  72. GODOT_VARIANT_TYPE_POOL_VECTOR2_ARRAY, // 25
  73. GODOT_VARIANT_TYPE_POOL_VECTOR3_ARRAY,
  74. GODOT_VARIANT_TYPE_POOL_COLOR_ARRAY,
  75. } godot_variant_type;
  76. typedef enum godot_variant_call_error_error {
  77. GODOT_CALL_ERROR_CALL_OK,
  78. GODOT_CALL_ERROR_CALL_ERROR_INVALID_METHOD,
  79. GODOT_CALL_ERROR_CALL_ERROR_INVALID_ARGUMENT,
  80. GODOT_CALL_ERROR_CALL_ERROR_TOO_MANY_ARGUMENTS,
  81. GODOT_CALL_ERROR_CALL_ERROR_TOO_FEW_ARGUMENTS,
  82. GODOT_CALL_ERROR_CALL_ERROR_INSTANCE_IS_NULL,
  83. } godot_variant_call_error_error;
  84. typedef struct godot_variant_call_error {
  85. godot_variant_call_error_error error;
  86. int argument;
  87. godot_variant_type expected;
  88. } godot_variant_call_error;
  89. typedef enum godot_variant_operator {
  90. // comparison
  91. GODOT_VARIANT_OP_EQUAL,
  92. GODOT_VARIANT_OP_NOT_EQUAL,
  93. GODOT_VARIANT_OP_LESS,
  94. GODOT_VARIANT_OP_LESS_EQUAL,
  95. GODOT_VARIANT_OP_GREATER,
  96. GODOT_VARIANT_OP_GREATER_EQUAL,
  97. // mathematic
  98. GODOT_VARIANT_OP_ADD,
  99. GODOT_VARIANT_OP_SUBTRACT,
  100. GODOT_VARIANT_OP_MULTIPLY,
  101. GODOT_VARIANT_OP_DIVIDE,
  102. GODOT_VARIANT_OP_NEGATE,
  103. GODOT_VARIANT_OP_POSITIVE,
  104. GODOT_VARIANT_OP_MODULE,
  105. GODOT_VARIANT_OP_STRING_CONCAT,
  106. // bitwise
  107. GODOT_VARIANT_OP_SHIFT_LEFT,
  108. GODOT_VARIANT_OP_SHIFT_RIGHT,
  109. GODOT_VARIANT_OP_BIT_AND,
  110. GODOT_VARIANT_OP_BIT_OR,
  111. GODOT_VARIANT_OP_BIT_XOR,
  112. GODOT_VARIANT_OP_BIT_NEGATE,
  113. // logic
  114. GODOT_VARIANT_OP_AND,
  115. GODOT_VARIANT_OP_OR,
  116. GODOT_VARIANT_OP_XOR,
  117. GODOT_VARIANT_OP_NOT,
  118. // containment
  119. GODOT_VARIANT_OP_IN,
  120. GODOT_VARIANT_OP_MAX,
  121. } godot_variant_operator;
  122. // reduce extern "C" nesting for VS2013
  123. #ifdef __cplusplus
  124. }
  125. #endif
  126. #include <gdnative/aabb.h>
  127. #include <gdnative/array.h>
  128. #include <gdnative/basis.h>
  129. #include <gdnative/color.h>
  130. #include <gdnative/dictionary.h>
  131. #include <gdnative/node_path.h>
  132. #include <gdnative/plane.h>
  133. #include <gdnative/pool_arrays.h>
  134. #include <gdnative/quat.h>
  135. #include <gdnative/rect2.h>
  136. #include <gdnative/rid.h>
  137. #include <gdnative/string.h>
  138. #include <gdnative/transform.h>
  139. #include <gdnative/transform2d.h>
  140. #include <gdnative/variant.h>
  141. #include <gdnative/vector2.h>
  142. #include <gdnative/vector3.h>
  143. #include <gdnative/gdnative.h>
  144. #ifdef __cplusplus
  145. extern "C" {
  146. #endif
  147. godot_variant_type GDAPI godot_variant_get_type(const godot_variant *p_v);
  148. void GDAPI godot_variant_new_copy(godot_variant *r_dest, const godot_variant *p_src);
  149. void GDAPI godot_variant_new_nil(godot_variant *r_dest);
  150. void GDAPI godot_variant_new_bool(godot_variant *r_dest, const godot_bool p_b);
  151. void GDAPI godot_variant_new_uint(godot_variant *r_dest, const uint64_t p_i);
  152. void GDAPI godot_variant_new_int(godot_variant *r_dest, const int64_t p_i);
  153. void GDAPI godot_variant_new_real(godot_variant *r_dest, const double p_r);
  154. void GDAPI godot_variant_new_string(godot_variant *r_dest, const godot_string *p_s);
  155. void GDAPI godot_variant_new_vector2(godot_variant *r_dest, const godot_vector2 *p_v2);
  156. void GDAPI godot_variant_new_rect2(godot_variant *r_dest, const godot_rect2 *p_rect2);
  157. void GDAPI godot_variant_new_vector3(godot_variant *r_dest, const godot_vector3 *p_v3);
  158. void GDAPI godot_variant_new_transform2d(godot_variant *r_dest, const godot_transform2d *p_t2d);
  159. void GDAPI godot_variant_new_plane(godot_variant *r_dest, const godot_plane *p_plane);
  160. void GDAPI godot_variant_new_quat(godot_variant *r_dest, const godot_quat *p_quat);
  161. void GDAPI godot_variant_new_aabb(godot_variant *r_dest, const godot_aabb *p_aabb);
  162. void GDAPI godot_variant_new_basis(godot_variant *r_dest, const godot_basis *p_basis);
  163. void GDAPI godot_variant_new_transform(godot_variant *r_dest, const godot_transform *p_trans);
  164. void GDAPI godot_variant_new_color(godot_variant *r_dest, const godot_color *p_color);
  165. void GDAPI godot_variant_new_node_path(godot_variant *r_dest, const godot_node_path *p_np);
  166. void GDAPI godot_variant_new_rid(godot_variant *r_dest, const godot_rid *p_rid);
  167. void GDAPI godot_variant_new_object(godot_variant *r_dest, const godot_object *p_obj);
  168. void GDAPI godot_variant_new_dictionary(godot_variant *r_dest, const godot_dictionary *p_dict);
  169. void GDAPI godot_variant_new_array(godot_variant *r_dest, const godot_array *p_arr);
  170. void GDAPI godot_variant_new_pool_byte_array(godot_variant *r_dest, const godot_pool_byte_array *p_pba);
  171. void GDAPI godot_variant_new_pool_int_array(godot_variant *r_dest, const godot_pool_int_array *p_pia);
  172. void GDAPI godot_variant_new_pool_real_array(godot_variant *r_dest, const godot_pool_real_array *p_pra);
  173. void GDAPI godot_variant_new_pool_string_array(godot_variant *r_dest, const godot_pool_string_array *p_psa);
  174. void GDAPI godot_variant_new_pool_vector2_array(godot_variant *r_dest, const godot_pool_vector2_array *p_pv2a);
  175. void GDAPI godot_variant_new_pool_vector3_array(godot_variant *r_dest, const godot_pool_vector3_array *p_pv3a);
  176. void GDAPI godot_variant_new_pool_color_array(godot_variant *r_dest, const godot_pool_color_array *p_pca);
  177. godot_bool GDAPI godot_variant_as_bool(const godot_variant *p_self);
  178. uint64_t GDAPI godot_variant_as_uint(const godot_variant *p_self);
  179. int64_t GDAPI godot_variant_as_int(const godot_variant *p_self);
  180. double GDAPI godot_variant_as_real(const godot_variant *p_self);
  181. godot_string GDAPI godot_variant_as_string(const godot_variant *p_self);
  182. godot_vector2 GDAPI godot_variant_as_vector2(const godot_variant *p_self);
  183. godot_rect2 GDAPI godot_variant_as_rect2(const godot_variant *p_self);
  184. godot_vector3 GDAPI godot_variant_as_vector3(const godot_variant *p_self);
  185. godot_transform2d GDAPI godot_variant_as_transform2d(const godot_variant *p_self);
  186. godot_plane GDAPI godot_variant_as_plane(const godot_variant *p_self);
  187. godot_quat GDAPI godot_variant_as_quat(const godot_variant *p_self);
  188. godot_aabb GDAPI godot_variant_as_aabb(const godot_variant *p_self);
  189. godot_basis GDAPI godot_variant_as_basis(const godot_variant *p_self);
  190. godot_transform GDAPI godot_variant_as_transform(const godot_variant *p_self);
  191. godot_color GDAPI godot_variant_as_color(const godot_variant *p_self);
  192. godot_node_path GDAPI godot_variant_as_node_path(const godot_variant *p_self);
  193. godot_rid GDAPI godot_variant_as_rid(const godot_variant *p_self);
  194. godot_object GDAPI *godot_variant_as_object(const godot_variant *p_self);
  195. godot_dictionary GDAPI godot_variant_as_dictionary(const godot_variant *p_self);
  196. godot_array GDAPI godot_variant_as_array(const godot_variant *p_self);
  197. godot_pool_byte_array GDAPI godot_variant_as_pool_byte_array(const godot_variant *p_self);
  198. godot_pool_int_array GDAPI godot_variant_as_pool_int_array(const godot_variant *p_self);
  199. godot_pool_real_array GDAPI godot_variant_as_pool_real_array(const godot_variant *p_self);
  200. godot_pool_string_array GDAPI godot_variant_as_pool_string_array(const godot_variant *p_self);
  201. godot_pool_vector2_array GDAPI godot_variant_as_pool_vector2_array(const godot_variant *p_self);
  202. godot_pool_vector3_array GDAPI godot_variant_as_pool_vector3_array(const godot_variant *p_self);
  203. godot_pool_color_array GDAPI godot_variant_as_pool_color_array(const godot_variant *p_self);
  204. godot_variant GDAPI godot_variant_call(godot_variant *p_self, const godot_string *p_method, const godot_variant **p_args, const godot_int p_argcount, godot_variant_call_error *r_error);
  205. godot_bool GDAPI godot_variant_has_method(const godot_variant *p_self, const godot_string *p_method);
  206. godot_bool GDAPI godot_variant_operator_equal(const godot_variant *p_self, const godot_variant *p_other);
  207. godot_bool GDAPI godot_variant_operator_less(const godot_variant *p_self, const godot_variant *p_other);
  208. godot_bool GDAPI godot_variant_hash_compare(const godot_variant *p_self, const godot_variant *p_other);
  209. godot_bool GDAPI godot_variant_booleanize(const godot_variant *p_self);
  210. void GDAPI godot_variant_destroy(godot_variant *p_self);
  211. // GDNative core 1.1
  212. godot_string GDAPI godot_variant_get_operator_name(godot_variant_operator p_op);
  213. void GDAPI godot_variant_evaluate(godot_variant_operator p_op, const godot_variant *p_a, const godot_variant *p_b, godot_variant *r_ret, godot_bool *r_valid);
  214. #ifdef __cplusplus
  215. }
  216. #endif
  217. #endif