fx.reflection: implement dynamic function calling
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
#ifndef FX_REFLECTION_FUNCTION_H_
|
||||
#define FX_REFLECTION_FUNCTION_H_
|
||||
|
||||
#include <fx/macros.h>
|
||||
#include <fx/status.h>
|
||||
#include <fx/value.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
#define FX_REFLECTION_TYPE_FUNCTION (fx_function_get_type())
|
||||
#define FX_REFLECTION_TYPE_FUNCTION_CONTEXT (fx_function_context_get_type())
|
||||
|
||||
typedef enum fx_function_flags {
|
||||
FX_FUNCTION_F_NONE = 0x00u,
|
||||
FX_FUNCTION_F_STATIC = 0x01u,
|
||||
FX_FUNCTION_F_VIRTUAL = 0x02u,
|
||||
FX_FUNCTION_F_VARARG = 0x04u,
|
||||
} fx_function_flags;
|
||||
|
||||
#if 0
|
||||
#define FX_FUNCTION_VALUE(type) \
|
||||
((fx_function_value) { \
|
||||
.v_type = FX_FUNCTION_V_PRIMITIVE, \
|
||||
.v_primitive = (type), \
|
||||
})
|
||||
|
||||
typedef enum fx_function_value_type {
|
||||
FX_FUNCTION_V_NONE = 0,
|
||||
FX_FUNCTION_V_PRIMITIVE,
|
||||
FX_FUNCTION_V_OBJECT,
|
||||
} fx_function_value_type;
|
||||
|
||||
typedef struct fx_function_value {
|
||||
fx_function_value_type v_type;
|
||||
union {
|
||||
fx_value_type v_primitive;
|
||||
fx_type v_object;
|
||||
};
|
||||
} fx_function_value;
|
||||
#endif
|
||||
|
||||
typedef void (*fx_function_impl)();
|
||||
|
||||
FX_DECLARE_TYPE(fx_function);
|
||||
FX_DECLARE_TYPE(fx_function_context);
|
||||
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_function)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_function)
|
||||
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_function_context)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_function_context)
|
||||
|
||||
FX_API fx_type fx_function_get_type();
|
||||
FX_API fx_type fx_function_context_get_type();
|
||||
|
||||
FX_API fx_function_context *fx_function_context_create(void);
|
||||
FX_API void fx_function_context_reset(fx_function_context *ctx);
|
||||
FX_API void fx_function_context_push_arg(
|
||||
fx_function_context *ctx,
|
||||
const fx_value *value);
|
||||
|
||||
FX_API fx_function *fx_function_create(
|
||||
const char *name,
|
||||
fx_function_flags flags,
|
||||
fx_function_impl impl,
|
||||
const fx_value_type *args,
|
||||
size_t nr_args,
|
||||
fx_value_type return_type);
|
||||
FX_API fx_status
|
||||
fx_function_bind(const fx_function *func, const fx_value *args, size_t nr_args);
|
||||
FX_API fx_status fx_function_invoke(
|
||||
const fx_function *func,
|
||||
const fx_value *args,
|
||||
size_t nr_args,
|
||||
fx_value *return_value);
|
||||
FX_API fx_status fx_function_invoke_with_context(
|
||||
const fx_function *func,
|
||||
const fx_function_context *ctx,
|
||||
fx_value *return_value);
|
||||
|
||||
FX_DECLS_END;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user