Skip to content

Instantly share code, notes, and snippets.

@emk
Created December 12, 2014 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emk/88b6b2149e8d767bc537 to your computer and use it in GitHub Desktop.
Save emk/88b6b2149e8d767bc537 to your computer and use it in GitHub Desktop.
Can't call through trait
/// Call the global JavaScript function named `fn_name` with `args`, and
/// return the result.
pub fn call<'a>(&mut self, fn_name: &str,
args: &[&Encodable<Encoder<'a>, DuktapeError>]) ->
DuktapeResult<Value<'static>>
{
unsafe {
assert_stack_height_unchanged!(self, {
duk_push_global_object(self.ptr);
fn_name.with_c_str(|c_str| {
duk_get_prop_string(self.ptr, -1, c_str);
});
{
let mut encoder = Encoder::new(self);
for arg in args.iter() {
arg.encode(&mut encoder).unwrap();
}
}
let status = duk_pcall(self.ptr, args.len() as i32);
let result = self.pop_result(status);
duk_pop(self.ptr); // Remove global object.
result
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment