godot_nativescript.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /**************************************************************************/
  2. /* godot_nativescript.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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_2D_NAVIGATION,
  60. GODOT_PROPERTY_HINT_LAYERS_3D_RENDER,
  61. GODOT_PROPERTY_HINT_LAYERS_3D_PHYSICS,
  62. GODOT_PROPERTY_HINT_LAYERS_3D_NAVIGATION,
  63. GODOT_PROPERTY_HINT_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
  64. GODOT_PROPERTY_HINT_DIR, ///< a directory path must be passed
  65. GODOT_PROPERTY_HINT_GLOBAL_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
  66. GODOT_PROPERTY_HINT_GLOBAL_DIR, ///< a directory path must be passed
  67. GODOT_PROPERTY_HINT_RESOURCE_TYPE, ///< a resource object type
  68. GODOT_PROPERTY_HINT_MULTILINE_TEXT, ///< used for string properties that can contain multiple lines
  69. GODOT_PROPERTY_HINT_PLACEHOLDER_TEXT, ///< used to set a placeholder text for string properties
  70. GODOT_PROPERTY_HINT_COLOR_NO_ALPHA, ///< used for ignoring alpha component when editing a color
  71. GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSY,
  72. GODOT_PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS,
  73. GODOT_PROPERTY_HINT_OBJECT_ID,
  74. GODOT_PROPERTY_HINT_TYPE_STRING, ///< a type string, the hint is the base type to choose
  75. GODOT_PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE, ///< so something else can provide this (used in scripts)
  76. GODOT_PROPERTY_HINT_METHOD_OF_VARIANT_TYPE, ///< a method of a type
  77. GODOT_PROPERTY_HINT_METHOD_OF_BASE_TYPE, ///< a method of a base type
  78. GODOT_PROPERTY_HINT_METHOD_OF_INSTANCE, ///< a method of an instance
  79. GODOT_PROPERTY_HINT_METHOD_OF_SCRIPT, ///< a method of a script & base
  80. GODOT_PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE, ///< a property of a type
  81. GODOT_PROPERTY_HINT_PROPERTY_OF_BASE_TYPE, ///< a property of a base type
  82. GODOT_PROPERTY_HINT_PROPERTY_OF_INSTANCE, ///< a property of an instance
  83. GODOT_PROPERTY_HINT_PROPERTY_OF_SCRIPT, ///< a property of a script & base
  84. GODOT_PROPERTY_HINT_OBJECT_TOO_BIG, ///< object is too big to send
  85. GODOT_PROPERTY_HINT_NODE_PATH_VALID_TYPES,
  86. GODOT_PROPERTY_HINT_SAVE_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,". This opens a save dialog
  87. GODOT_PROPERTY_HINT_ENUM_SUGGESTION, ///< hint_text= "val1,val2,val3,etc"
  88. GODOT_PROPERTY_HINT_LOCALE_ID,
  89. GODOT_PROPERTY_HINT_MAX,
  90. } godot_property_hint;
  91. typedef enum {
  92. GODOT_PROPERTY_USAGE_STORAGE = 1,
  93. GODOT_PROPERTY_USAGE_EDITOR = 2,
  94. GODOT_PROPERTY_USAGE_NETWORK = 4,
  95. GODOT_PROPERTY_USAGE_EDITOR_HELPER = 8,
  96. GODOT_PROPERTY_USAGE_CHECKABLE = 16, //used for editing global variables
  97. GODOT_PROPERTY_USAGE_CHECKED = 32, //used for editing global variables
  98. GODOT_PROPERTY_USAGE_INTERNATIONALIZED = 64, //hint for internationalized strings
  99. GODOT_PROPERTY_USAGE_GROUP = 128, //used for grouping props in the editor
  100. GODOT_PROPERTY_USAGE_CATEGORY = 256,
  101. GODOT_PROPERTY_USAGE_STORE_IF_NONZERO = 512, // FIXME: Obsolete: drop whenever we can break compat
  102. GODOT_PROPERTY_USAGE_STORE_IF_NONONE = 1024, // FIXME: Obsolete: drop whenever we can break compat
  103. GODOT_PROPERTY_USAGE_NO_INSTANCE_STATE = 2048,
  104. GODOT_PROPERTY_USAGE_RESTART_IF_CHANGED = 4096,
  105. GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE = 8192,
  106. GODOT_PROPERTY_USAGE_STORE_IF_NULL = 16384,
  107. GODOT_PROPERTY_USAGE_ANIMATE_AS_TRIGGER = 32768,
  108. GODOT_PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED = 65536,
  109. GODOT_PROPERTY_USAGE_DEFAULT = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_EDITOR | GODOT_PROPERTY_USAGE_NETWORK,
  110. GODOT_PROPERTY_USAGE_DEFAULT_INTL = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_EDITOR | GODOT_PROPERTY_USAGE_NETWORK | GODOT_PROPERTY_USAGE_INTERNATIONALIZED,
  111. GODOT_PROPERTY_USAGE_NOEDITOR = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_NETWORK,
  112. } godot_property_usage_flags;
  113. typedef struct {
  114. godot_method_rpc_mode rset_type;
  115. godot_int type;
  116. godot_property_hint hint;
  117. godot_string hint_string;
  118. godot_property_usage_flags usage;
  119. godot_variant default_value;
  120. } godot_property_attributes;
  121. typedef struct {
  122. // instance pointer, method_data - return user data
  123. GDCALLINGCONV void *(*create_func)(godot_object *, void *);
  124. void *method_data;
  125. GDCALLINGCONV void (*free_func)(void *);
  126. } godot_instance_create_func;
  127. typedef struct {
  128. // instance pointer, method data, user data
  129. GDCALLINGCONV void (*destroy_func)(godot_object *, void *, void *);
  130. void *method_data;
  131. GDCALLINGCONV void (*free_func)(void *);
  132. } godot_instance_destroy_func;
  133. 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);
  134. 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);
  135. typedef struct {
  136. godot_method_rpc_mode rpc_type;
  137. } godot_method_attributes;
  138. typedef struct {
  139. // instance pointer, method data, user data, num args, args - return result as variant
  140. GDCALLINGCONV godot_variant (*method)(godot_object *, void *, void *, int, godot_variant **);
  141. void *method_data;
  142. GDCALLINGCONV void (*free_func)(void *);
  143. } godot_instance_method;
  144. 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);
  145. typedef struct {
  146. // instance pointer, method data, user data, value
  147. GDCALLINGCONV void (*set_func)(godot_object *, void *, void *, godot_variant *);
  148. void *method_data;
  149. GDCALLINGCONV void (*free_func)(void *);
  150. } godot_property_set_func;
  151. typedef struct {
  152. // instance pointer, method data, user data, value
  153. GDCALLINGCONV godot_variant (*get_func)(godot_object *, void *, void *);
  154. void *method_data;
  155. GDCALLINGCONV void (*free_func)(void *);
  156. } godot_property_get_func;
  157. 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);
  158. typedef struct {
  159. godot_string name;
  160. godot_int type;
  161. godot_property_hint hint;
  162. godot_string hint_string;
  163. godot_property_usage_flags usage;
  164. godot_variant default_value;
  165. } godot_signal_argument;
  166. typedef struct {
  167. godot_string name;
  168. int num_args;
  169. godot_signal_argument *args;
  170. int num_default_args;
  171. godot_variant *default_args;
  172. } godot_signal;
  173. void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const char *p_name, const godot_signal *p_signal);
  174. void GDAPI *godot_nativescript_get_userdata(godot_object *p_instance);
  175. /*
  176. *
  177. *
  178. * NativeScript 1.1
  179. *
  180. *
  181. */
  182. // method registering with argument names
  183. typedef struct {
  184. godot_string name;
  185. godot_variant_type type;
  186. godot_property_hint hint;
  187. godot_string hint_string;
  188. } godot_method_arg;
  189. 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);
  190. // documentation
  191. void GDAPI godot_nativescript_set_class_documentation(void *p_gdnative_handle, const char *p_name, godot_string p_documentation);
  192. void GDAPI godot_nativescript_set_method_documentation(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_string p_documentation);
  193. void GDAPI godot_nativescript_set_property_documentation(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_string p_documentation);
  194. void GDAPI godot_nativescript_set_signal_documentation(void *p_gdnative_handle, const char *p_name, const char *p_signal_name, godot_string p_documentation);
  195. // type tag API
  196. void GDAPI godot_nativescript_set_global_type_tag(int p_idx, const char *p_name, const void *p_type_tag);
  197. const void GDAPI *godot_nativescript_get_global_type_tag(int p_idx, const char *p_name);
  198. void GDAPI godot_nativescript_set_type_tag(void *p_gdnative_handle, const char *p_name, const void *p_type_tag);
  199. const void GDAPI *godot_nativescript_get_type_tag(const godot_object *p_object);
  200. // instance binding API
  201. typedef struct {
  202. GDCALLINGCONV void *(*alloc_instance_binding_data)(void *, const void *, godot_object *);
  203. GDCALLINGCONV void (*free_instance_binding_data)(void *, void *);
  204. GDCALLINGCONV void (*refcount_incremented_instance_binding)(void *, godot_object *);
  205. GDCALLINGCONV bool (*refcount_decremented_instance_binding)(void *, godot_object *);
  206. void *data;
  207. GDCALLINGCONV void (*free_func)(void *);
  208. } godot_instance_binding_functions;
  209. int GDAPI godot_nativescript_register_instance_binding_data_functions(godot_instance_binding_functions p_binding_functions);
  210. void GDAPI godot_nativescript_unregister_instance_binding_data_functions(int p_idx);
  211. void GDAPI *godot_nativescript_get_instance_binding_data(int p_idx, godot_object *p_object);
  212. void GDAPI godot_nativescript_profiling_add_data(const char *p_signature, uint64_t p_time);
  213. #ifdef __cplusplus
  214. }
  215. #endif
  216. #endif // GODOT_NATIVESCRIPT_H