[][src]Attribute Macro decorator::hana_function

#[hana_function]

Generates a native function callable from haru's virtual machine.

Note that the file containing your native function must contain the imports for Vm and Value:

extern crate haru;
use haru::vmbindings::value::Value;
use haru::vmbindings::vm::Vm;

Example:

#[hana_function()]
fn fopen(path: Value::String, mode: Value::String) {
    [body of fopen]
}

should generate a function like this (semi pseudocode):

pub extern "C" fn fopen(cvm : *mut Vm, nargs : u16) {
    if nargs != [nargs] { [raise vm error] }
    fn fopen() -> Value {
        let Value::String(path) = vm.stack.pop().unwrap() ||
                panic!("expected path to be string");
        let Value::String(mode) = vm.stack.pop().unwrap() ||
                panic!("expected mode to be string");
        [body of fopen]
    }
    let vm = unsafe { &mut *cvm };
    let result : Value = #name(vm);
    vm.stack.push(result.wrap());
}