godot_nativescript.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*************************************************************************/
  2. /* godot_nativescript.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_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_REMOTE,
  39. GODOT_METHOD_RPC_MODE_MASTER,
  40. GODOT_METHOD_RPC_MODE_PUPPET,
  41. GODOT_METHOD_RPC_MODE_SLAVE = GODOT_METHOD_RPC_MODE_PUPPET,
  42. GODOT_METHOD_RPC_MODE_REMOTESYNC,
  43. GODOT_METHOD_RPC_MODE_SYNC = GODOT_METHOD_RPC_MODE_REMOTESYNC,
  44. GODOT_METHOD_RPC_MODE_MASTERSYNC,
  45. GODOT_METHOD_RPC_MODE_PUPPETSYNC,
  46. } godot_method_rpc_mode;
  47. typedef enum {
  48. GODOT_PROPERTY_HINT_NONE, ///< no hint provided.
  49. GODOT_PROPERTY_HINT_RANGE, ///< hint_text = "min,max,step,slider; //slider is optional"
  50. GODOT_PROPERTY_HINT_EXP_RANGE, ///< hint_text = "min,max,step", exponential edit
  51. GODOT_PROPERTY_HINT_ENUM, ///< hint_text= "val1,val2,val3,etc"
  52. GODOT_PROPERTY_HINT_EXP_EASING, /// exponential easing function (Math::ease)
  53. GODOT_PROPERTY_HINT_LENGTH, ///< hint_text= "length" (as integer)
  54. GODOT_PROPERTY_HINT_SPRITE_FRAME, // FIXME: Obsolete: drop whenever we can break compat
  55. GODOT_PROPERTY_HINT_KEY_ACCEL, ///< hint_text= "length" (as integer)
  56. GODOT_PROPERTY_HINT_FLAGS, ///< hint_text= "flag1,flag2,etc" (as bit flags)
  57. GODOT_PROPERTY_HINT_LAYERS_2D_RENDER,
  58. GODOT_PROPERTY_HINT_LAYERS_2D_PHYSICS,
  59. GODOT_PROPERTY_HINT_LAYERS_3D_RENDER,
  60. GODOT_PROPERTY_HINT_LAYERS_3D_PHYSICS,
  61. GODOT_PROPERTY_HINT_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
  62. GODOT_PROPERTY_HINT_DIR, ///< a directory path must be passed
  63. GODOT_PROPERTY_HINT_GLOBAL_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
  64. GODOT_PROPERTY_HINT_GLOBAL_DIR, ///< a directory path must be passed
  65. GODOT_PROPERTY_HINT_RESOURCE_TYPE, ///< a resource object type
  66. GODOT_PROPERTY_HINT_MULTILINE_TEXT, ///< used for string properties that can contain multiple lines
  67. GODOT_PROPERTY_HINT_PLACEHOLDER_TEXT, ///< used to set a placeholder text for string properties
  68. GODOT_PROPERTY_HINT_COLOR_NO_ALPHA, ///< used for ignoring alpha component when editing a color
  69. GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSY,
  70. GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS,
  71. GODOT_PROPERTY_HINT_OBJECT_ID,
  72. GODOT_PROPERTY_HINT_TYPE_STRING, ///< a type string, the hint is the base type to choose
  73. GODOT_PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE, ///< so something else can provide this (used in scripts)
  74. GODOT_PROPERTY_HINT_METHOD_OF_VARIANT_TYPE, ///< a method of a type
  75. GODOT_PROPERTY_HINT_METHOD_OF_BASE_TYPE, ///< a method of a base type
  76. GODOT_PROPERTY_HINT_METHOD_OF_INSTANCE, ///< a method of an instance
  77. GODOT_PROPERTY_HINT_METHOD_OF_SCRIPT, ///< a method of a script & base
  78. GODOT_PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE, ///< a property of a type
  79. GODOT_PROPERTY_HINT_PROPERTY_OF_BASE_TYPE, ///< a property of a base type
  80. GODOT_PROPERTY_HINT_PROPERTY_OF_INSTANCE, ///< a property of an instance
  81. GODOT_PROPERTY_HINT_PROPERTY_OF_SCRIPT, ///< a property of a script & base
  82. GODOT_PROPERTY_HINT_MAX,
  83. } godot_property_hint;
  84. typedef enum {
  85. GODOT_PROPERTY_USAGE_STORAGE = 1,
  86. GODOT_PROPERTY_USAGE_EDITOR = 2,
  87. GODOT_PROPERTY_USAGE_NETWORK = 4,
  88. GODOT_PROPERTY_USAGE_EDITOR_HELPER = 8,
  89. GODOT_PROPERTY_USAGE_CHECKABLE = 16, //used for editing global variables
  90. GODOT_PROPERTY_USAGE_CHECKED = 32, //used for editing global variables
  91. GODOT_PROPERTY_USAGE_INTERNATIONALIZED = 64, //hint for internationalized strings
  92. GODOT_PROPERTY_USAGE_GROUP = 128, //used for grouping props in the editor
  93. GODOT_PROPERTY_USAGE_CATEGORY = 256,
  94. GODOT_PROPERTY_USAGE_STORE_IF_NONZERO = 512, // FIXME: Obsolete: drop whenever we can break compat
  95. GODOT_PROPERTY_USAGE_STORE_IF_NONONE = 1024, // FIXME: Obsolete: drop whenever we can break compat
  96. GODOT_PROPERTY_USAGE_NO_INSTANCE_STATE = 2048,
  97. GODOT_PROPERTY_USAGE_RESTART_IF_CHANGED = 4096,
  98. GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE = 8192,
  99. GODOT_PROPERTY_USAGE_STORE_IF_NULL = 16384,
  100. GODOT_PROPERTY_USAGE_ANIMATE_AS_TRIGGER = 32768,
  101. GODOT_PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED = 65536,
  102. GODOT_PROPERTY_USAGE_DEFAULT = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_EDITOR | GODOT_PROPERTY_USAGE_NETWORK,
  103. GODOT_PROPERTY_USAGE_DEFAULT_INTL = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_EDITOR | GODOT_PROPERTY_USAGE_NETWORK | GODOT_PROPERTY_USAGE_INTERNATIONALIZED,
  104. GODOT_PROPERTY_USAGE_NOEDITOR = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_NETWORK,
  105. } godot_property_usage_flags;
  106. typedef struct {
  107. godot_method_rpc_mode rset_type;
  108. godot_int type;
  109. godot_property_hint hint;
  110. godot_string hint_string;
  111. godot_property_usage_flags usage;
  112. godot_variant default_value;
  113. } godot_property_attributes;
  114. typedef struct {
  115. // instance pointer, method_data - return user data
  116. GDCALLINGCONV void *(*create_func)(godot_object *, void *);
  117. void *method_data;
  118. GDCALLINGCONV void (*free_func)(void *);
  119. } godot_instance_create_func;
  120. typedef struct {
  121. // instance pointer, method data, user data
  122. GDCALLINGCONV void (*destroy_func)(godot_object *, void *, void *);
  123. void *method_data;
  124. GDCALLINGCONV void (*free_func)(void *);
  125. } godot_instance_destroy_func;
  126. void GDAPI godot_nativescript_register_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func);
  127. void GDAPI godot_nativescript_register_tool_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func);
  128. typedef struct {
  129. godot_method_rpc_mode rpc_type;
  130. } godot_method_attributes;
  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_instance_method;
  137. void GDAPI godot_nativescript_register_method(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method);
  138. typedef struct {
  139. // instance pointer, method data, user data, value
  140. GDCALLINGCONV void (*set_func)(godot_object *, void *, void *, godot_variant *);
  141. void *method_data;
  142. GDCALLINGCONV void (*free_func)(void *);
  143. } godot_property_set_func;
  144. typedef struct {
  145. // instance pointer, method data, user data, value
  146. GDCALLINGCONV godot_variant (*get_func)(godot_object *, void *, void *);
  147. void *method_data;
  148. GDCALLINGCONV void (*free_func)(void *);
  149. } godot_property_get_func;
  150. void GDAPI godot_nativescript_register_property(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_property_attributes *p_attr, godot_property_set_func p_set_func, godot_property_get_func p_get_func);
  151. typedef struct {
  152. godot_string name;
  153. godot_int type;
  154. godot_property_hint hint;
  155. godot_string hint_string;
  156. godot_property_usage_flags usage;
  157. godot_variant default_value;
  158. } godot_signal_argument;
  159. typedef struct {
  160. godot_string name;
  161. int num_args;
  162. godot_signal_argument *args;
  163. int num_default_args;
  164. godot_variant *default_args;
  165. } godot_signal;
  166. void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const char *p_name, const godot_signal *p_signal);
  167. void GDAPI *godot_nativescript_get_userdata(godot_object *p_instance);
  168. /*
  169. *
  170. *
  171. * NativeScript 1.1
  172. *
  173. *
  174. */
  175. // method registering with argument names
  176. typedef struct {
  177. godot_string name;
  178. godot_variant_type type;
  179. godot_property_hint hint;
  180. godot_string hint_string;
  181. } godot_method_arg;
  182. 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_method_arg *p_args);
  183. // documentation
  184. void GDAPI godot_nativescript_set_class_documentation(void *p_gdnative_handle, const char *p_name, godot_string p_documentation);
  185. void GDAPI godot_nativescript_set_method_documentation(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_string p_documentation);
  186. void GDAPI godot_nativescript_set_property_documentation(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_string p_documentation);
  187. void GDAPI godot_nativescript_set_signal_documentation(void *p_gdnative_handle, const char *p_name, const char *p_signal_name, godot_string p_documentation);
  188. // type tag API
  189. void GDAPI godot_nativescript_set_global_type_tag(int p_idx, const char *p_name, const void *p_type_tag);
  190. const void GDAPI *godot_nativescript_get_global_type_tag(int p_idx, const char *p_name);
  191. void GDAPI godot_nativescript_set_type_tag(void *p_gdnative_handle, const char *p_name, const void *p_type_tag);
  192. const void GDAPI *godot_nativescript_get_type_tag(const godot_object *p_object);
  193. // instance binding API
  194. typedef struct {
  195. GDCALLINGCONV void *(*alloc_instance_binding_data)(void *, const void *, godot_object *);
  196. GDCALLINGCONV void (*free_instance_binding_data)(void *, void *);
  197. GDCALLINGCONV void (*refcount_incremented_instance_binding)(void *, godot_object *);
  198. GDCALLINGCONV bool (*refcount_decremented_instance_binding)(void *, godot_object *);
  199. void *data;
  200. GDCALLINGCONV void (*free_func)(void *);
  201. } godot_instance_binding_functions;
  202. int GDAPI godot_nativescript_register_instance_binding_data_functions(godot_instance_binding_functions p_binding_functions);
  203. void GDAPI godot_nativescript_unregister_instance_binding_data_functions(int p_idx);
  204. void GDAPI *godot_nativescript_get_instance_binding_data(int p_idx, godot_object *p_object);
  205. void GDAPI godot_nativescript_profiling_add_data(const char *p_signature, uint64_t p_time);
  206. #ifdef __cplusplus
  207. }
  208. #endif
  209. #endif