|
#ifndef RAVA_LOADER_H
|
|
#define RAVA_LOADER_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#define RAVA_MAX_NATIVE_METHODS 256
|
|
#define RAVA_MAX_NATIVE_LIBRARIES 32
|
|
#define RAVA_MAX_METHOD_PARAMS 16
|
|
|
|
typedef enum {
|
|
RAVA_NATIVE_VOID,
|
|
RAVA_NATIVE_INT,
|
|
RAVA_NATIVE_LONG,
|
|
RAVA_NATIVE_DOUBLE,
|
|
RAVA_NATIVE_BOOLEAN,
|
|
RAVA_NATIVE_STRING,
|
|
RAVA_NATIVE_OBJECT,
|
|
RAVA_NATIVE_ARRAY
|
|
} RavaNativeType_e;
|
|
|
|
typedef struct {
|
|
RavaNativeType_e type;
|
|
union {
|
|
int32_t int_val;
|
|
int64_t long_val;
|
|
double double_val;
|
|
bool bool_val;
|
|
char *string_val;
|
|
void *object_val;
|
|
void *array_val;
|
|
} data;
|
|
} RavaNativeValue_t;
|
|
|
|
typedef RavaNativeValue_t (*RavaNativeFunction_fn)(RavaNativeValue_t *args, size_t arg_count, void *user_data);
|
|
|
|
typedef struct {
|
|
char *class_name;
|
|
char *method_name;
|
|
RavaNativeType_e return_type;
|
|
RavaNativeType_e param_types[RAVA_MAX_METHOD_PARAMS];
|
|
size_t param_count;
|
|
RavaNativeFunction_fn function;
|
|
void *user_data;
|
|
} RavaNativeMethod_t;
|
|
|
|
typedef struct {
|
|
char *name;
|
|
char *path;
|
|
void *handle;
|
|
RavaNativeMethod_t *methods;
|
|
size_t method_count;
|
|
size_t method_capacity;
|
|
} RavaNativeLibrary_t;
|
|
|
|
typedef struct {
|
|
RavaNativeLibrary_t *libraries[RAVA_MAX_NATIVE_LIBRARIES];
|
|
size_t library_count;
|
|
RavaNativeMethod_t *method_cache[RAVA_MAX_NATIVE_METHODS];
|
|
size_t cache_count;
|
|
} RavaNativeRegistry_t;
|
|
|
|
RavaNativeRegistry_t* rava_native_registry_create(void);
|
|
void rava_native_registry_destroy(RavaNativeRegistry_t *registry);
|
|
|
|
RavaNativeLibrary_t* rava_native_library_load(RavaNativeRegistry_t *registry, const char *path);
|
|
void rava_native_library_unload(RavaNativeRegistry_t *registry, RavaNativeLibrary_t *lib);
|
|
|
|
bool rava_native_register_method(RavaNativeRegistry_t *registry,
|
|
const char *class_name,
|
|
const char *method_name,
|
|
RavaNativeType_e return_type,
|
|
RavaNativeType_e *param_types,
|
|
size_t param_count,
|
|
RavaNativeFunction_fn function,
|
|
void *user_data);
|
|
|
|
RavaNativeMethod_t* rava_native_find_method(RavaNativeRegistry_t *registry,
|
|
const char *class_name,
|
|
const char *method_name);
|
|
|
|
RavaNativeValue_t rava_native_invoke(RavaNativeMethod_t *method,
|
|
RavaNativeValue_t *args,
|
|
size_t arg_count);
|
|
|
|
|
|
RavaNativeValue_t rava_native_int(int32_t val);
|
|
RavaNativeValue_t rava_native_long(int64_t val);
|
|
RavaNativeValue_t rava_native_double(double val);
|
|
RavaNativeValue_t rava_native_boolean(bool val);
|
|
RavaNativeValue_t rava_native_string(const char *val);
|
|
RavaNativeValue_t rava_native_void(void);
|
|
RavaNativeValue_t rava_native_null(void);
|
|
|
|
typedef void (*RavaLibraryRegisterFn)(RavaNativeRegistry_t *registry);
|
|
#define RAVA_LIBRARY_REGISTER_SYMBOL "rava_library_register"
|
|
|
|
#endif
|