feat: rm run_js
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
mod qjs;
|
mod qjs;
|
||||||
mod sig;
|
mod sig;
|
||||||
|
|
||||||
@@ -9,9 +7,6 @@ pub use sig::*; // TODO
|
|||||||
fn main() {
|
fn main() {
|
||||||
let context = QuickJSContext::new().unwrap();
|
let context = QuickJSContext::new().unwrap();
|
||||||
|
|
||||||
let mut map = HashMap::new();
|
|
||||||
map.insert("name", "hatter");
|
|
||||||
|
|
||||||
let script = r##"
|
let script = r##"
|
||||||
function __EXPORT(f) { eval('__PUBLIC_' + f + '=' + f); }
|
function __EXPORT(f) { eval('__PUBLIC_' + f + '=' + f); }
|
||||||
|
|
||||||
@@ -36,8 +31,10 @@ fn main() {
|
|||||||
"##;
|
"##;
|
||||||
|
|
||||||
context.init(script).unwrap();
|
context.init(script).unwrap();
|
||||||
let r = context.run_js(&map);
|
// let mut map = HashMap::new();
|
||||||
println!("{:?}", r);
|
// map.insert("name", "hatter");
|
||||||
|
// let r = context.run_js(&map);
|
||||||
|
// println!("{:?}", r);
|
||||||
let r = context.call_fn("getName", "[1, 'hatter', 'jiang']");
|
let r = context.call_fn("getName", "[1, 'hatter', 'jiang']");
|
||||||
println!("{:?}", r);
|
println!("{:?}", r);
|
||||||
let r = context.call_fn("helloAb", "['hatter', 'jiang']");
|
let r = context.call_fn("helloAb", "['hatter', 'jiang']");
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ impl QuickJSContext {
|
|||||||
self.context.eval(js).map_err(|e| e.into())
|
self.context.eval(js).map_err(|e| e.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_js<T>(&self, p: &T) -> XResult<JsValue> where T: ?Sized + Serialize {
|
// pub fn run_js<T>(&self, p: &T) -> XResult<JsValue> where T: ?Sized + Serialize {
|
||||||
let p_json = match serde_json::to_string(p) {
|
// let p_json = match serde_json::to_string(p) {
|
||||||
Err(e) => return Err(e.into()),
|
// Err(e) => return Err(e.into()),
|
||||||
Ok(p) => p,
|
// Ok(p) => p,
|
||||||
};
|
// };
|
||||||
self.context.eval(&format!("main({})", p_json)).map_err(|e| e.into())
|
// self.context.eval(&format!("main({})", p_json)).map_err(|e| e.into())
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn call_fn(&self, fun: &str, params: &str) -> XResult<JsValue> {
|
pub fn call_fn(&self, fun: &str, params: &str) -> XResult<JsValue> {
|
||||||
if !params.trim().starts_with("[") {
|
if !params.trim().starts_with("[") {
|
||||||
|
|||||||
Reference in New Issue
Block a user