mirror of
https://github.com/icewind1991/ivory.git
synced 2026-06-03 18:54:07 +02:00
Added support to set functions for module
This commit is contained in:
parent
872ca624fb
commit
3098a609fd
2 changed files with 95 additions and 3 deletions
|
|
@ -8,11 +8,79 @@ type InfoFunc = extern fn () ;
|
|||
type GlobalsCtorFunc = extern fn (global: *const c_void) -> c_void;
|
||||
type GlobalsDtorFunc = extern fn (global: *const c_void) -> c_void;
|
||||
type PostDeactivateFunc = extern fn () -> c_int;
|
||||
type HandlerFunc = extern fn (execute_data: &ExecuteData, retval: &Value);
|
||||
|
||||
|
||||
|
||||
pub struct ExecuteData {}
|
||||
pub struct Value {}
|
||||
pub struct ModuleDep {}
|
||||
pub struct Function {}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct ArgInfo {
|
||||
name: *const c_char,
|
||||
class_name: *const c_char,
|
||||
type_hint: c_uchar,
|
||||
pass_by_reference: c_uchar,
|
||||
allow_null: c_uchar,
|
||||
is_variadic: c_uchar,
|
||||
}
|
||||
|
||||
impl ArgInfo {
|
||||
pub fn new(name: *const c_char, allow_null: c_uchar, is_variadic: c_uchar, by_reference: c_uchar) -> ArgInfo {
|
||||
ArgInfo {
|
||||
name: name,
|
||||
class_name: std::ptr::null(),
|
||||
type_hint: 0,
|
||||
pass_by_reference: by_reference,
|
||||
allow_null: allow_null,
|
||||
is_variadic: is_variadic,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Function {
|
||||
fname: *const c_char,
|
||||
handler: Option<HandlerFunc>,
|
||||
arg_info: *const ArgInfo,
|
||||
num_args: u32,
|
||||
flags: u32,
|
||||
}
|
||||
|
||||
impl Function {
|
||||
pub fn new(name: *const c_char, handler: HandlerFunc) -> Function {
|
||||
Function {
|
||||
fname: name,
|
||||
handler: Some(handler),
|
||||
arg_info: std::ptr::null(),
|
||||
num_args: 0,
|
||||
flags: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_args(name: *const c_char, handler: HandlerFunc, args: Box<[ArgInfo]>) -> Function {
|
||||
let num_args = args.len() as u32;
|
||||
|
||||
Function {
|
||||
fname: name,
|
||||
handler: Some(handler),
|
||||
arg_info: Box::into_raw(args) as *const ArgInfo,
|
||||
num_args: num_args - 1,
|
||||
flags: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn end() -> Function {
|
||||
Function {
|
||||
fname: std::ptr::null(),
|
||||
handler: None,
|
||||
arg_info: std::ptr::null(),
|
||||
num_args: 0,
|
||||
flags: 0,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct INI {}
|
||||
|
||||
#[repr(C)]
|
||||
|
|
@ -84,6 +152,10 @@ impl Module {
|
|||
pub fn set_info_func(&mut self, func: InfoFunc) {
|
||||
self.info_func = Some(func);
|
||||
}
|
||||
|
||||
pub fn set_functions(&mut self, funcs: Box<[Function]>) {
|
||||
self.functions = Box::into_raw(funcs) as *const Function;
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sync for Module {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue