godot_nativescript.h 11 KB

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