wasm/wasm-sharding-js/src/main.rs (53 lines of code) (raw):

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #![allow(dead_code, unused_imports, unused_must_use)] use std::borrow::{Borrow, BorrowMut}; use wasmedge_quickjs::*; fn args_parse() -> (String, Vec<String>) { use argparse::ArgumentParser; let mut file_path = String::new(); let mut res_args: Vec<String> = vec![]; { let mut ap = ArgumentParser::new(); ap.refer(&mut file_path) .add_argument("file", argparse::Store, "js file") .required(); ap.refer(&mut res_args) .add_argument("arg", argparse::List, "arg"); ap.parse_args_or_exit(); } (file_path, res_args) } fn main() { use wasmedge_quickjs as q; let mut rt = q::Runtime::new(); rt.run_with_context(|ctx| { let (file_path, mut rest_arg) = args_parse(); let code = std::fs::read_to_string(&file_path); match code { Ok(code) => { rest_arg.insert(0, file_path.clone()); ctx.put_args(rest_arg); ctx.eval_module_str(code, &file_path); } Err(e) => { eprintln!("{}", e.to_string()); } } ctx.js_loop().unwrap(); }); }