Added support to set functions for module

This commit is contained in:
Jin Hu 2017-08-13 02:26:44 +08:00
commit 3098a609fd
2 changed files with 95 additions and 3 deletions

View file

@ -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 {}