1 /*************************************************************************/ 2 /* gdnative.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2020 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 31 #ifndef GODOT_GDNATIVE_H 32 #define GODOT_GDNATIVE_H 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 #if defined(_WIN32) || defined(__ANDROID__) 39 #define GDCALLINGCONV 40 #define GDAPI GDCALLINGCONV 41 #elif defined(__APPLE__) 42 #include "TargetConditionals.h" 43 #if TARGET_OS_IPHONE 44 #define GDCALLINGCONV __attribute__((visibility("default"))) 45 #define GDAPI GDCALLINGCONV 46 #elif TARGET_OS_MAC 47 #define GDCALLINGCONV __attribute__((sysv_abi)) 48 #define GDAPI GDCALLINGCONV 49 #endif 50 #else // !_WIN32 && !__APPLE__ 51 #define GDCALLINGCONV __attribute__((sysv_abi)) 52 #define GDAPI GDCALLINGCONV 53 #endif 54 55 // This is for libraries *using* the header, NOT GODOT EXPOSING STUFF!! 56 #ifdef _WIN32 57 #define GDN_EXPORT __declspec(dllexport) 58 #else 59 #define GDN_EXPORT 60 #endif 61 62 #include <stdbool.h> 63 #include <stdint.h> 64 65 #define GODOT_API_VERSION 1 66 67 ////// Error 68 69 typedef enum { 70 GODOT_OK, // (0) 71 GODOT_FAILED, ///< Generic fail error 72 GODOT_ERR_UNAVAILABLE, ///< What is requested is unsupported/unavailable 73 GODOT_ERR_UNCONFIGURED, ///< The object being used hasn't been properly set up yet 74 GODOT_ERR_UNAUTHORIZED, ///< Missing credentials for requested resource 75 GODOT_ERR_PARAMETER_RANGE_ERROR, ///< Parameter given out of range (5) 76 GODOT_ERR_OUT_OF_MEMORY, ///< Out of memory 77 GODOT_ERR_FILE_NOT_FOUND, 78 GODOT_ERR_FILE_BAD_DRIVE, 79 GODOT_ERR_FILE_BAD_PATH, 80 GODOT_ERR_FILE_NO_PERMISSION, // (10) 81 GODOT_ERR_FILE_ALREADY_IN_USE, 82 GODOT_ERR_FILE_CANT_OPEN, 83 GODOT_ERR_FILE_CANT_WRITE, 84 GODOT_ERR_FILE_CANT_READ, 85 GODOT_ERR_FILE_UNRECOGNIZED, // (15) 86 GODOT_ERR_FILE_CORRUPT, 87 GODOT_ERR_FILE_MISSING_DEPENDENCIES, 88 GODOT_ERR_FILE_EOF, 89 GODOT_ERR_CANT_OPEN, ///< Can't open a resource/socket/file 90 GODOT_ERR_CANT_CREATE, // (20) 91 GODOT_ERR_QUERY_FAILED, 92 GODOT_ERR_ALREADY_IN_USE, 93 GODOT_ERR_LOCKED, ///< resource is locked 94 GODOT_ERR_TIMEOUT, 95 GODOT_ERR_CANT_CONNECT, // (25) 96 GODOT_ERR_CANT_RESOLVE, 97 GODOT_ERR_CONNECTION_ERROR, 98 GODOT_ERR_CANT_ACQUIRE_RESOURCE, 99 GODOT_ERR_CANT_FORK, 100 GODOT_ERR_INVALID_DATA, ///< Data passed is invalid (30) 101 GODOT_ERR_INVALID_PARAMETER, ///< Parameter passed is invalid 102 GODOT_ERR_ALREADY_EXISTS, ///< When adding, item already exists 103 GODOT_ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist 104 GODOT_ERR_DATABASE_CANT_READ, ///< database is full 105 GODOT_ERR_DATABASE_CANT_WRITE, ///< database is full (35) 106 GODOT_ERR_COMPILATION_FAILED, 107 GODOT_ERR_METHOD_NOT_FOUND, 108 GODOT_ERR_LINK_FAILED, 109 GODOT_ERR_SCRIPT_FAILED, 110 GODOT_ERR_CYCLIC_LINK, // (40) 111 GODOT_ERR_INVALID_DECLARATION, 112 GODOT_ERR_DUPLICATE_SYMBOL, 113 GODOT_ERR_PARSE_ERROR, 114 GODOT_ERR_BUSY, 115 GODOT_ERR_SKIP, // (45) 116 GODOT_ERR_HELP, ///< user requested help!! 117 GODOT_ERR_BUG, ///< a bug in the software certainly happened, due to a double check failing or unexpected behavior. 118 GODOT_ERR_PRINTER_ON_FIRE, /// the parallel port printer is engulfed in flames 119 } godot_error; 120 121 ////// bool 122 123 typedef bool godot_bool; 124 125 #define GODOT_TRUE 1 126 #define GODOT_FALSE 0 127 128 /////// int 129 130 typedef int godot_int; 131 132 /////// real 133 134 typedef float godot_real; 135 136 /////// Object (forward declared) 137 typedef void godot_object; 138 139 /////// String 140 141 #include <gdnative/string.h> 142 143 /////// String name 144 145 #include <gdnative/string_name.h> 146 147 ////// Vector2 148 149 #include <gdnative/vector2.h> 150 151 ////// Rect2 152 153 #include <gdnative/rect2.h> 154 155 ////// Vector3 156 157 #include <gdnative/vector3.h> 158 159 ////// Transform2D 160 161 #include <gdnative/transform2d.h> 162 163 /////// Plane 164 165 #include <gdnative/plane.h> 166 167 /////// Quat 168 169 #include <gdnative/quat.h> 170 171 /////// AABB 172 173 #include <gdnative/aabb.h> 174 175 /////// Basis 176 177 #include <gdnative/basis.h> 178 179 /////// Transform 180 181 #include <gdnative/transform.h> 182 183 /////// Color 184 185 #include <gdnative/color.h> 186 187 /////// NodePath 188 189 #include <gdnative/node_path.h> 190 191 /////// RID 192 193 #include <gdnative/rid.h> 194 195 /////// Dictionary 196 197 #include <gdnative/dictionary.h> 198 199 /////// Array 200 201 #include <gdnative/array.h> 202 203 // single API file for Pool*Array 204 #include <gdnative/pool_arrays.h> 205 206 void GDAPI godot_object_destroy(godot_object *p_o); 207 208 ////// Variant 209 210 #include <gdnative/variant.h> 211 212 ////// Singleton API 213 214 godot_object GDAPI *godot_global_get_singleton(char *p_name); // result shouldn't be freed 215 216 ////// MethodBind API 217 218 typedef struct { 219 uint8_t _dont_touch_that[1]; // TODO 220 } godot_method_bind; 221 222 godot_method_bind GDAPI *godot_method_bind_get_method(const char *p_classname, const char *p_methodname); 223 void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_object *p_instance, const void **p_args, void *p_ret); 224 godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, godot_object *p_instance, const godot_variant **p_args, const int p_arg_count, godot_variant_call_error *p_call_error); 225 ////// Script API 226 227 typedef struct godot_gdnative_api_version { 228 unsigned int major; 229 unsigned int minor; 230 } godot_gdnative_api_version; 231 232 typedef struct godot_gdnative_api_struct godot_gdnative_api_struct; 233 234 struct godot_gdnative_api_struct { 235 unsigned int type; 236 godot_gdnative_api_version version; 237 const godot_gdnative_api_struct *next; 238 }; 239 240 #define GDNATIVE_VERSION_COMPATIBLE(want, have) (want.major == have.major && want.minor <= have.minor) 241 242 typedef struct { 243 godot_bool in_editor; 244 uint64_t core_api_hash; 245 uint64_t editor_api_hash; 246 uint64_t no_api_hash; 247 void (*report_version_mismatch)(const godot_object *p_library, const char *p_what, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have); 248 void (*report_loading_error)(const godot_object *p_library, const char *p_what); 249 godot_object *gd_native_library; // pointer to GDNativeLibrary that is being initialized 250 const struct godot_gdnative_core_api_struct *api_struct; 251 const godot_string *active_library_path; 252 } godot_gdnative_init_options; 253 254 typedef struct { 255 godot_bool in_editor; 256 } godot_gdnative_terminate_options; 257 258 // Calling convention? 259 typedef godot_object *(*godot_class_constructor)(); 260 261 godot_class_constructor GDAPI godot_get_class_constructor(const char *p_classname); 262 263 godot_dictionary GDAPI godot_get_global_constants(); 264 265 ////// GDNative procedure types 266 typedef void (*godot_gdnative_init_fn)(godot_gdnative_init_options *); 267 typedef void (*godot_gdnative_terminate_fn)(godot_gdnative_terminate_options *); 268 typedef godot_variant (*godot_gdnative_procedure_fn)(godot_array *); 269 270 ////// System Functions 271 272 typedef godot_variant (*native_call_cb)(void *, godot_array *); 273 void GDAPI godot_register_native_call_type(const char *p_call_type, native_call_cb p_callback); 274 275 //using these will help Godot track how much memory is in use in debug mode 276 void GDAPI *godot_alloc(int p_bytes); 277 void GDAPI *godot_realloc(void *p_ptr, int p_bytes); 278 void GDAPI godot_free(void *p_ptr); 279 280 //print using Godot's error handler list 281 void GDAPI godot_print_error(const char *p_description, const char *p_function, const char *p_file, int p_line); 282 void GDAPI godot_print_warning(const char *p_description, const char *p_function, const char *p_file, int p_line); 283 void GDAPI godot_print(const godot_string *p_message); 284 285 // GDNATIVE CORE 1.0.1 286 287 bool GDAPI godot_is_instance_valid(const godot_object *p_object); 288 289 //tags used for safe dynamic casting 290 void GDAPI *godot_get_class_tag(const godot_string_name *p_class); 291 godot_object GDAPI *godot_object_cast_to(const godot_object *p_object, void *p_class_tag); 292 293 // equivalent of GDScript's instance_from_id 294 godot_object GDAPI *godot_instance_from_id(godot_int p_instance_id); 295 296 #ifdef __cplusplus 297 } 298 #endif 299 300 #endif // GODOT_C_H 301