godot_nativescript.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*************************************************************************/
  2. /* godot_nativescript.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef GODOT_NATIVESCRIPT_H
  31. #define GODOT_NATIVESCRIPT_H
  32. #include <gdnative/gdnative.h>
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. typedef enum {
  37. GODOT_METHOD_RPC_MODE_DISABLED,
  38. GODOT_METHOD_RPC_MODE_ANY,
  39. GODOT_METHOD_RPC_MODE_AUTHORITY,
  40. } godot_nativescript_method_rpc_mode;
  41. typedef enum {
  42. GODOT_PROPERTY_HINT_NONE, ///< no hint provided.
  43. GODOT_PROPERTY_HINT_RANGE, ///< hint_text = "min,max,step,slider; //slider is optional"
  44. GODOT_PROPERTY_HINT_EXP_RANGE, ///< hint_text = "min,max,step", exponential edit
  45. GODOT_PROPERTY_HINT_ENUM, ///< hint_text= "val1,val2,val3,etc"
  46. GODOT_PROPERTY_HINT_EXP_EASING, /// exponential easing function (Math::ease)
  47. GODOT_PROPERTY_HINT_LENGTH, ///< hint_text= "length" (as integer)
  48. GODOT_PROPERTY_HINT_KEY_ACCEL, ///< hint_text= "length" (as integer)
  49. GODOT_PROPERTY_HINT_FLAGS, ///< hint_text= "flag1,flag2,etc" (as bit flags)
  50. GODOT_PROPERTY_HINT_LAYERS_2D_RENDER,
  51. GODOT_PROPERTY_HINT_LAYERS_2D_PHYSICS,
  52. GODOT_PROPERTY_HINT_LAYERS_2D_NAVIGATION,
  53. GODOT_PROPERTY_HINT_LAYERS_3D_RENDER,
  54. GODOT_PROPERTY_HINT_LAYERS_3D_PHYSICS,
  55. GODOT_PROPERTY_HINT_LAYERS_3D_NAVIGATION,
  56. GODOT_PROPERTY_HINT_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
  57. GODOT_PROPERTY_HINT_DIR, ///< a directory path must be passed
  58. GODOT_PROPERTY_HINT_GLOBAL_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
  59. GODOT_PROPERTY_HINT_GLOBAL_DIR, ///< a directory path must be passed
  60. GODOT_PROPERTY_HINT_RESOURCE_TYPE, ///< a resource object type
  61. GODOT_PROPERTY_HINT_MULTILINE_TEXT, ///< used for string properties that can contain multiple lines
  62. GODOT_PROPERTY_HINT_PLACEHOLDER_TEXT, ///< used to set a placeholder text for string properties
  63. GODOT_PROPERTY_HINT_COLOR_NO_ALPHA, ///< used for ignoring alpha component when editing a color
  64. GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSY,
  65. GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS,
  66. GODOT_PROPERTY_HINT_OBJECT_ID,
  67. GODOT_PROPERTY_HINT_TYPE_STRING, ///< a type string, the hint is the base type to choose
  68. GODOT_PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE, ///< so something else can provide this (used in scripts)
  69. GODOT_PROPERTY_HINT_METHOD_OF_VARIANT_TYPE, ///< a method of a type
  70. GODOT_PROPERTY_HINT_METHOD_OF_BASE_TYPE, ///< a method of a base type
  71. GODOT_PROPERTY_HINT_METHOD_OF_INSTANCE, ///< a method of an instance
  72. GODOT_PROPERTY_HINT_METHOD_OF_SCRIPT, ///< a method of a script & base
  73. GODOT_PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE, ///< a property of a type
  74. GODOT_PROPERTY_HINT_PROPERTY_OF_BASE_TYPE, ///< a property of a base type
  75. GODOT_PROPERTY_HINT_PROPERTY_OF_INSTANCE, ///< a property of an instance
  76. GODOT_PROPERTY_HINT_PROPERTY_OF_SCRIPT, ///< a property of a script & base
  77. GODOT_PROPERTY_HINT_MAX,
  78. } godot_nativescript_property_hint;
  79. typedef enum {
  80. GODOT_PROPERTY_USAGE_STORAGE = 1,
  81. GODOT_PROPERTY_USAGE_EDITOR = 2,
  82. GODOT_PROPERTY_USAGE_NETWORK = 4,
  83. GODOT_PROPERTY_USAGE_EDITOR_HELPER = 8,
  84. GODOT_PROPERTY_USAGE_CHECKABLE = 16, //used for editing global variables
  85. GODOT_PROPERTY_USAGE_CHECKED = 32, //used for editing global variables
  86. GODOT_PROPERTY_USAGE_INTERNATIONALIZED = 64, //hint for internationalized strings
  87. GODOT_PROPERTY_USAGE_GROUP = 128, //used for grouping props in the editor
  88. GODOT_PROPERTY_USAGE_CATEGORY = 256,
  89. GODOT_PROPERTY_USAGE_SUBGROUP = 512,
  90. GODOT_PROPERTY_USAGE_NO_INSTANCE_STATE = 2048,
  91. GODOT_PROPERTY_USAGE_RESTART_IF_CHANGED = 4096,
  92. GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE = 8192,
  93. GODOT_PROPERTY_USAGE_STORE_IF_NULL = 16384,
  94. GODOT_PROPERTY_USAGE_ANIMATE_AS_TRIGGER = 32768,
  95. GODOT_PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED = 65536,
  96. GODOT_PROPERTY_USAGE_DEFAULT = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_EDITOR | GODOT_PROPERTY_USAGE_NETWORK,
  97. GODOT_PROPERTY_USAGE_DEFAULT_INTL = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_EDITOR | GODOT_PROPERTY_USAGE_NETWORK | GODOT_PROPERTY_USAGE_INTERNATIONALIZED,
  98. GODOT_PROPERTY_USAGE_NOEDITOR = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_NETWORK,
  99. } godot_nativescript_property_usage_flags;
  100. typedef struct {
  101. godot_nativescript_method_rpc_mode rset_type;
  102. godot_int type;
  103. godot_nativescript_property_hint hint;
  104. godot_string hint_string;
  105. godot_nativescript_property_usage_flags usage;
  106. godot_variant default_value;
  107. } godot_nativescript_property_attributes;
  108. typedef struct {
  109. // instance pointer, method_data - return user data
  110. GDCALLINGCONV void *(*create_func)(godot_object *, void *);
  111. void *method_data;
  112. GDCALLINGCONV void (*free_func)(void *);
  113. } godot_nativescript_instance_create_func;
  114. typedef struct {
  115. // instance pointer, method data, user data
  116. GDCALLINGCONV void (*destroy_func)(godot_object *, void *, void *);
  117. void *method_data;
  118. GDCALLINGCONV void (*free_func)(void *);
  119. } godot_nativescript_instance_destroy_func;
  120. void GDAPI godot_nativescript_register_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_nativescript_instance_create_func p_create_func, godot_nativescript_instance_destroy_func p_destroy_func);
  121. void GDAPI godot_nativescript_register_tool_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_nativescript_instance_create_func p_create_func, godot_nativescript_instance_destroy_func p_destroy_func);
  122. typedef struct {
  123. godot_nativescript_method_rpc_mode rpc_type;
  124. } godot_nativescript_method_attributes;
  125. typedef struct {
  126. godot_string name;
  127. godot_variant_type type;
  128. godot_nativescript_property_hint hint;
  129. godot_string hint_string;
  130. } godot_nativescript_method_argument;
  131. typedef struct {
  132. // instance pointer, method data, user data, num args, args - return result as varaint
  133. GDCALLINGCONV godot_variant (*method)(godot_object *, void *, void *, int, godot_variant **);
  134. void *method_data;
  135. GDCALLINGCONV void (*free_func)(void *);
  136. } godot_nativescript_instance_method;
  137. void GDAPI godot_nativescript_register_method(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_nativescript_method_attributes p_attr, godot_nativescript_instance_method p_method);
  138. void GDAPI godot_nativescript_set_method_argument_information(void *p_gdnative_handle, const char *p_name, const char *p_function_name, int p_num_args, const godot_nativescript_method_argument *p_args);
  139. typedef struct {
  140. // instance pointer, method data, user data, value
  141. GDCALLINGCONV void (*set_func)(godot_object *, void *, void *, godot_variant *);
  142. void *method_data;
  143. GDCALLINGCONV void (*free_func)(void *);
  144. } godot_nativescript_property_set_func;
  145. typedef struct {
  146. // instance pointer, method data, user data, value
  147. GDCALLINGCONV godot_variant (*get_func)(godot_object *, void *, void *);
  148. void *method_data;
  149. GDCALLINGCONV void (*free_func)(void *);
  150. } godot_nativescript_property_get_func;
  151. void GDAPI godot_nativescript_register_property(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_nativescript_property_attributes *p_attr, godot_nativescript_property_set_func p_set_func, godot_nativescript_property_get_func p_get_func);
  152. typedef struct {
  153. godot_string name;
  154. godot_int type;
  155. godot_nativescript_property_hint hint;
  156. godot_string hint_string;
  157. godot_nativescript_property_usage_flags usage;
  158. godot_variant default_value;
  159. } godot_nativescript_signal_argument;
  160. typedef struct {
  161. godot_string name;
  162. int num_args;
  163. godot_nativescript_signal_argument *args;
  164. int num_default_args;
  165. godot_variant *default_args;
  166. } godot_nativescript_signal;
  167. void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const char *p_name, const godot_nativescript_signal *p_signal);
  168. void GDAPI *godot_nativescript_get_userdata(godot_object *p_instance);
  169. // documentation
  170. void GDAPI godot_nativescript_set_class_documentation(void *p_gdnative_handle, const char *p_name, godot_string p_documentation);
  171. void GDAPI godot_nativescript_set_method_documentation(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_string p_documentation);
  172. void GDAPI godot_nativescript_set_property_documentation(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_string p_documentation);
  173. void GDAPI godot_nativescript_set_signal_documentation(void *p_gdnative_handle, const char *p_name, const char *p_signal_name, godot_string p_documentation);
  174. // type tag API
  175. void GDAPI godot_nativescript_set_global_type_tag(int p_idx, const char *p_name, const void *p_type_tag);
  176. const void GDAPI *godot_nativescript_get_global_type_tag(int p_idx, const char *p_name);
  177. void GDAPI godot_nativescript_set_type_tag(void *p_gdnative_handle, const char *p_name, const void *p_type_tag);
  178. const void GDAPI *godot_nativescript_get_type_tag(const godot_object *p_object);
  179. // instance binding API
  180. typedef struct {
  181. GDCALLINGCONV void *(*alloc_instance_binding_data)(void *, const void *, godot_object *);
  182. GDCALLINGCONV void (*free_instance_binding_data)(void *, void *);
  183. GDCALLINGCONV void (*refcount_incremented_instance_binding)(void *, godot_object *);
  184. GDCALLINGCONV bool (*refcount_decremented_instance_binding)(void *, godot_object *);
  185. void *data;
  186. GDCALLINGCONV void (*free_func)(void *);
  187. } godot_nativescript_instance_binding_functions;
  188. int GDAPI godot_nativescript_register_instance_binding_data_functions(godot_nativescript_instance_binding_functions p_binding_functions);
  189. void GDAPI godot_nativescript_unregister_instance_binding_data_functions(int p_idx);
  190. void GDAPI *godot_nativescript_get_instance_binding_data(int p_idx, godot_object *p_object);
  191. void GDAPI godot_nativescript_profiling_add_data(const char *p_signature, uint64_t p_time);
  192. #ifdef __cplusplus
  193. }
  194. #endif
  195. #endif