gdnative/include/gdn/gdnative.h

330 lines
11 KiB
C
Raw Normal View History

2023-05-23 18:02:01 +02:00
/**************************************************************************/
/* gdnative.h */
/**************************************************************************/
/* This file is part of: */
2023-05-26 10:58:14 +02:00
/* PANDEMONIUM ENGINE */
/* https://pandemoniumengine.org */
2023-05-23 18:02:01 +02:00
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GDNATIVE_GDNATIVE_H
#define GDNATIVE_GDNATIVE_H
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_WIN32) || defined(__ANDROID__)
#define GDCALLINGCONV
#define GDAPI GDCALLINGCONV
#elif defined(__APPLE__)
#include "TargetConditionals.h"
#if TARGET_OS_IPHONE
#define GDCALLINGCONV __attribute__((visibility("default")))
#define GDAPI GDCALLINGCONV
#elif TARGET_OS_MAC
#define GDCALLINGCONV __attribute__((sysv_abi))
#define GDAPI GDCALLINGCONV
#endif
#else // !_WIN32 && !__APPLE__
#define GDCALLINGCONV __attribute__((sysv_abi))
#define GDAPI GDCALLINGCONV
#endif
2023-05-26 10:58:14 +02:00
// This is for libraries *using* the header, NOT PANDEMONIUM EXPOSING STUFF!!
2023-05-23 18:02:01 +02:00
#if !defined(GDN_EXPORT)
#if defined(_WIN32)
#define GDN_EXPORT __declspec(dllexport)
#elif defined(__GNUC__)
#define GDN_EXPORT __attribute__((visibility("default")))
#else
#define GDN_EXPORT
#endif
#endif
#include <stdbool.h>
#include <stdint.h>
2023-05-26 10:58:14 +02:00
#define PANDEMONIUM_API_VERSION 1
2023-05-23 18:02:01 +02:00
////// Error
typedef enum {
2023-05-26 10:58:14 +02:00
PANDEMONIUM_OK, // (0)
PANDEMONIUM_FAILED, ///< Generic fail error
PANDEMONIUM_ERR_UNAVAILABLE, ///< What is requested is unsupported/unavailable
PANDEMONIUM_ERR_UNCONFIGURED, ///< The object being used hasn't been properly set up yet
PANDEMONIUM_ERR_UNAUTHORIZED, ///< Missing credentials for requested resource
PANDEMONIUM_ERR_PARAMETER_RANGE_ERROR, ///< Parameter given out of range (5)
PANDEMONIUM_ERR_OUT_OF_MEMORY, ///< Out of memory
PANDEMONIUM_ERR_FILE_NOT_FOUND,
PANDEMONIUM_ERR_FILE_BAD_DRIVE,
PANDEMONIUM_ERR_FILE_BAD_PATH,
PANDEMONIUM_ERR_FILE_NO_PERMISSION, // (10)
PANDEMONIUM_ERR_FILE_ALREADY_IN_USE,
PANDEMONIUM_ERR_FILE_CANT_OPEN,
PANDEMONIUM_ERR_FILE_CANT_WRITE,
PANDEMONIUM_ERR_FILE_CANT_READ,
PANDEMONIUM_ERR_FILE_UNRECOGNIZED, // (15)
PANDEMONIUM_ERR_FILE_CORRUPT,
PANDEMONIUM_ERR_FILE_MISSING_DEPENDENCIES,
PANDEMONIUM_ERR_FILE_EOF,
PANDEMONIUM_ERR_CANT_OPEN, ///< Can't open a resource/socket/file
PANDEMONIUM_ERR_CANT_CREATE, // (20)
PANDEMONIUM_ERR_QUERY_FAILED,
PANDEMONIUM_ERR_ALREADY_IN_USE,
PANDEMONIUM_ERR_LOCKED, ///< resource is locked
PANDEMONIUM_ERR_TIMEOUT,
PANDEMONIUM_ERR_CANT_CONNECT, // (25)
PANDEMONIUM_ERR_CANT_RESOLVE,
PANDEMONIUM_ERR_CONNECTION_ERROR,
PANDEMONIUM_ERR_CANT_ACQUIRE_RESOURCE,
PANDEMONIUM_ERR_CANT_FORK,
PANDEMONIUM_ERR_INVALID_DATA, ///< Data passed is invalid (30)
PANDEMONIUM_ERR_INVALID_PARAMETER, ///< Parameter passed is invalid
PANDEMONIUM_ERR_ALREADY_EXISTS, ///< When adding, item already exists
PANDEMONIUM_ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist
PANDEMONIUM_ERR_DATABASE_CANT_READ, ///< database is full
PANDEMONIUM_ERR_DATABASE_CANT_WRITE, ///< database is full (35)
PANDEMONIUM_ERR_COMPILATION_FAILED,
PANDEMONIUM_ERR_METHOD_NOT_FOUND,
PANDEMONIUM_ERR_LINK_FAILED,
PANDEMONIUM_ERR_SCRIPT_FAILED,
PANDEMONIUM_ERR_CYCLIC_LINK, // (40)
PANDEMONIUM_ERR_INVALID_DECLARATION,
PANDEMONIUM_ERR_DUPLICATE_SYMBOL,
PANDEMONIUM_ERR_PARSE_ERROR,
PANDEMONIUM_ERR_BUSY,
PANDEMONIUM_ERR_SKIP, // (45)
PANDEMONIUM_ERR_HELP, ///< user requested help!!
PANDEMONIUM_ERR_BUG, ///< a bug in the software certainly happened, due to a double check failing or unexpected behavior.
PANDEMONIUM_ERR_PRINTER_ON_FIRE, /// the parallel port printer is engulfed in flames
} pandemonium_error;
2023-05-23 18:02:01 +02:00
////// bool
2023-05-26 10:58:14 +02:00
typedef bool pandemonium_bool;
2023-05-23 18:02:01 +02:00
2023-05-26 10:58:14 +02:00
#define PANDEMONIUM_TRUE 1
#define PANDEMONIUM_FALSE 0
2023-05-23 18:02:01 +02:00
/////// int
2023-05-26 10:58:14 +02:00
typedef int pandemonium_int;
2023-05-23 18:02:01 +02:00
/////// real
// TODO add real_t -> float/double support!
// If the engine is built with doubles as real_t this won't work, as the structs won't line up!
2023-05-26 10:58:14 +02:00
typedef float pandemonium_real;
2023-05-23 18:02:01 +02:00
/////// Object (forward declared)
2023-05-26 10:58:14 +02:00
typedef void pandemonium_object;
2023-05-23 18:02:01 +02:00
/////// String
2023-05-25 21:54:24 +02:00
#include <gdn/string.h>
2023-05-23 18:02:01 +02:00
/////// String name
2023-05-25 21:54:24 +02:00
#include <gdn/string_name.h>
2023-05-23 18:02:01 +02:00
////// Vector2
2023-05-25 21:54:24 +02:00
#include <gdn/vector2.h>
2023-05-23 18:02:01 +02:00
2023-05-26 21:32:06 +02:00
////// Vector2i
#include <gdn/vector2i.h>
2023-05-23 18:02:01 +02:00
////// Rect2
2023-05-25 21:54:24 +02:00
#include <gdn/rect2.h>
2023-05-23 18:02:01 +02:00
2023-05-30 19:37:02 +02:00
////// Rect2i
#include <gdn/rect2i.h>
2023-05-23 18:02:01 +02:00
////// Vector3
2023-05-25 21:54:24 +02:00
#include <gdn/vector3.h>
2023-05-23 18:02:01 +02:00
2023-05-27 13:36:49 +02:00
////// Vector3i
#include <gdn/vector3i.h>
////// Vector4
#include <gdn/vector4.h>
////// Vector4i
#include <gdn/vector4i.h>
2023-05-23 18:02:01 +02:00
////// Transform2D
2023-05-25 21:54:24 +02:00
#include <gdn/transform2d.h>
2023-05-23 18:02:01 +02:00
/////// Plane
2023-05-25 21:54:24 +02:00
#include <gdn/plane.h>
2023-05-23 18:02:01 +02:00
2023-05-25 20:26:36 +02:00
/////// Quaternion
2023-05-23 18:02:01 +02:00
2023-05-25 21:54:24 +02:00
#include <gdn/quaternion.h>
2023-05-23 18:02:01 +02:00
/////// AABB
2023-05-25 21:54:24 +02:00
#include <gdn/aabb.h>
2023-05-23 18:02:01 +02:00
/////// Basis
2023-05-25 21:54:24 +02:00
#include <gdn/basis.h>
2023-05-23 18:02:01 +02:00
/////// Transform
2023-05-25 21:54:24 +02:00
#include <gdn/transform.h>
2023-05-23 18:02:01 +02:00
2023-05-30 22:36:09 +02:00
/////// Projection
#include <gdn/projection.h>
2023-05-23 18:02:01 +02:00
/////// Color
2023-05-25 21:54:24 +02:00
#include <gdn/color.h>
2023-05-23 18:02:01 +02:00
/////// NodePath
2023-05-25 21:54:24 +02:00
#include <gdn/node_path.h>
2023-05-23 18:02:01 +02:00
/////// RID
2023-05-25 21:54:24 +02:00
#include <gdn/rid.h>
2023-05-23 18:02:01 +02:00
/////// Dictionary
2023-05-25 21:54:24 +02:00
#include <gdn/dictionary.h>
2023-05-23 18:02:01 +02:00
/////// Array
2023-05-25 21:54:24 +02:00
#include <gdn/array.h>
2023-05-23 18:02:01 +02:00
// single API file for Pool*Array
2023-05-25 21:54:24 +02:00
#include <gdn/pool_arrays.h>
2023-05-23 18:02:01 +02:00
2023-05-26 10:58:14 +02:00
void GDAPI pandemonium_object_destroy(pandemonium_object *p_o);
2023-05-23 18:02:01 +02:00
////// Variant
2023-05-25 21:54:24 +02:00
#include <gdn/variant.h>
2023-05-23 18:02:01 +02:00
////// Singleton API
2023-05-26 10:58:14 +02:00
pandemonium_object GDAPI *pandemonium_global_get_singleton(char *p_name); // result shouldn't be freed
2023-05-23 18:02:01 +02:00
////// MethodBind API
typedef struct {
uint8_t _dont_touch_that[1]; // TODO
2023-05-26 10:58:14 +02:00
} pandemonium_method_bind;
2023-05-23 18:02:01 +02:00
2023-05-26 10:58:14 +02:00
pandemonium_method_bind GDAPI *pandemonium_method_bind_get_method(const char *p_classname, const char *p_methodname);
void GDAPI pandemonium_method_bind_ptrcall(pandemonium_method_bind *p_method_bind, pandemonium_object *p_instance, const void **p_args, void *p_ret);
pandemonium_variant GDAPI pandemonium_method_bind_call(pandemonium_method_bind *p_method_bind, pandemonium_object *p_instance, const pandemonium_variant **p_args, const int p_arg_count, pandemonium_variant_call_error *p_call_error);
2023-05-23 18:02:01 +02:00
////// Script API
2023-05-26 10:58:14 +02:00
typedef struct pandemonium_gdnative_api_version {
2023-05-23 18:02:01 +02:00
unsigned int major;
unsigned int minor;
2023-05-26 10:58:14 +02:00
} pandemonium_gdnative_api_version;
2023-05-23 18:02:01 +02:00
2023-05-26 10:58:14 +02:00
typedef struct pandemonium_gdnative_api_struct pandemonium_gdnative_api_struct;
2023-05-23 18:02:01 +02:00
2023-05-26 10:58:14 +02:00
struct pandemonium_gdnative_api_struct {
2023-05-23 18:02:01 +02:00
unsigned int type;
2023-05-26 10:58:14 +02:00
pandemonium_gdnative_api_version version;
const pandemonium_gdnative_api_struct *next;
2023-05-23 18:02:01 +02:00
};
#define GDNATIVE_VERSION_COMPATIBLE(want, have) (want.major == have.major && want.minor <= have.minor)
typedef struct {
2023-05-26 10:58:14 +02:00
pandemonium_bool in_editor;
2023-05-23 18:02:01 +02:00
uint64_t core_api_hash;
uint64_t editor_api_hash;
uint64_t no_api_hash;
2023-05-26 10:58:14 +02:00
void (*report_version_mismatch)(const pandemonium_object *p_library, const char *p_what, pandemonium_gdnative_api_version p_want, pandemonium_gdnative_api_version p_have);
void (*report_loading_error)(const pandemonium_object *p_library, const char *p_what);
pandemonium_object *gd_native_library; // pointer to GDNativeLibrary that is being initialized
const struct pandemonium_gdnative_core_api_struct *api_struct;
const pandemonium_string *active_library_path;
} pandemonium_gdnative_init_options;
2023-05-23 18:02:01 +02:00
typedef struct {
2023-05-26 10:58:14 +02:00
pandemonium_bool in_editor;
} pandemonium_gdnative_terminate_options;
2023-05-23 18:02:01 +02:00
// Calling convention?
2023-05-26 10:58:14 +02:00
typedef pandemonium_object *(*pandemonium_class_constructor)();
2023-05-23 18:02:01 +02:00
2023-05-26 10:58:14 +02:00
pandemonium_class_constructor GDAPI pandemonium_get_class_constructor(const char *p_classname);
2023-05-23 18:02:01 +02:00
2023-05-26 10:58:14 +02:00
pandemonium_dictionary GDAPI pandemonium_get_global_constants();
2023-05-23 18:02:01 +02:00
////// GDNative procedure types
2023-05-26 10:58:14 +02:00
typedef void (*pandemonium_gdnative_init_fn)(pandemonium_gdnative_init_options *);
typedef void (*pandemonium_gdnative_terminate_fn)(pandemonium_gdnative_terminate_options *);
typedef pandemonium_variant (*pandemonium_gdnative_procedure_fn)(pandemonium_array *);
2023-05-23 18:02:01 +02:00
////// System Functions
2023-05-26 10:58:14 +02:00
typedef pandemonium_variant (*native_call_cb)(void *, pandemonium_array *);
void GDAPI pandemonium_register_native_call_type(const char *p_call_type, native_call_cb p_callback);
2023-05-23 18:02:01 +02:00
2023-05-26 10:58:14 +02:00
//using these will help Pandemonium track how much memory is in use in debug mode
void GDAPI *pandemonium_alloc(int p_bytes);
void GDAPI *pandemonium_realloc(void *p_ptr, int p_bytes);
void GDAPI pandemonium_free(void *p_ptr);
2023-05-23 18:02:01 +02:00
2023-05-26 10:58:14 +02:00
//print using Pandemonium's error handler list
void GDAPI pandemonium_print_error(const char *p_description, const char *p_function, const char *p_file, int p_line);
void GDAPI pandemonium_print_warning(const char *p_description, const char *p_function, const char *p_file, int p_line);
void GDAPI pandemonium_print(const pandemonium_string *p_message);
2023-05-23 18:02:01 +02:00
2023-05-26 10:58:14 +02:00
bool GDAPI pandemonium_is_instance_valid(const pandemonium_object *p_object);
2023-05-23 18:02:01 +02:00
//tags used for safe dynamic casting
2023-05-26 10:58:14 +02:00
void GDAPI *pandemonium_get_class_tag(const pandemonium_string_name *p_class);
pandemonium_object GDAPI *pandemonium_object_cast_to(const pandemonium_object *p_object, void *p_class_tag);
2023-05-23 18:02:01 +02:00
// equivalent of GDScript's instance_from_id
2023-05-26 10:58:14 +02:00
pandemonium_object GDAPI *pandemonium_instance_from_id(pandemonium_int p_instance_id);
2023-05-23 18:02:01 +02:00
#ifdef __cplusplus
}
#endif
#endif // GDNATIVE_GDNATIVE_H