Created
December 12, 2014 11:09
-
-
Save emk/88b6b2149e8d767bc537 to your computer and use it in GitHub Desktop.
Revisions
-
emk created this gist
Dec 12, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ /// 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 }) } }