feat: can run qjs

This commit is contained in:
2020-11-07 16:12:21 +08:00
parent 5110732561
commit 56b44d1a8f
60 changed files with 91718 additions and 16 deletions

View File

@@ -1,5 +1,46 @@
use std::collections::HashMap;
mod qjs;
mod sig;
pub use qjs::*;
pub use sig::*; // TODO
fn main() {
println!("Hello, world!");
let context = QuickJSContext::new().unwrap();
let mut map = HashMap::new();
map.insert("name", "hatter");
let script = r##"
function __EXPORT(f) { eval('__PUBLIC_' + f + '=' + f); }
function getName() {
console.info("=========================");
for (var i = 0; i < arguments.length; i++) {
console.info(i, ' ----> ', arguments[i]);
}
return 'hatter';
}
function helloAb(a, b) {
console.info("Hello: ", a);
console.info("Hello: ", b);
}
function main(p) {
console.log(p);
return 1;
}
__EXPORT('getName');
__EXPORT('helloAb');
"##;
context.init(script).unwrap();
let r = context.run_js(&map);
println!("{:?}", r);
let r = context.call_fn("getName", "[1, 'hatter', 'jiang']");
println!("{:?}", r);
let r = context.call_fn("helloAb", "['hatter', 'jiang']");
println!("{:?}", r);
}