Created
December 12, 2014 11:09
-
-
Save emk/88b6b2149e8d767bc537 to your computer and use it in GitHub Desktop.
Can't call through trait
This file contains 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 characters
/// 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