Skip to main content

pipa/host/
func.rs

1use crate::runtime::context::JSContext;
2use crate::value::JSValue;
3
4pub type HostFunc = fn(&mut JSContext, &[JSValue]) -> JSValue;
5
6#[derive(Clone, Copy)]
7pub struct HostFunction {
8    pub func: HostFunc,
9    pub name: &'static str,
10    pub arity: u32,
11}
12
13impl HostFunction {
14    pub fn new(name: &'static str, arity: u32, func: HostFunc) -> Self {
15        HostFunction { name, arity, func }
16    }
17
18    pub fn call(&self, ctx: &mut JSContext, args: &[JSValue]) -> JSValue {
19        (self.func)(ctx, args)
20    }
21}