macro_rules! plug_args {
(@embedded, $ty:ty, $($wasm:ident),* $(,)?) => { ... };
(@dynamic, $state:expr, $($wasm:ident),* $(,)?) => { ... };
(@inner, @embedded, $ty:ty, $($wasm:ident),*) => { ... };
(@dynamic, $state:expr, $($wasm:ident),* $(,)?) => { ... };
(@inner, @embedded, $ty:ty, $($wasm:ident),*) => { ... };
(@inner, @dynamic, $state:expr, $($wasm:ident),*) => { ... };
}Expand description
@embedded or @dynamic Whether to import JavaScript runtime args from vfs, args is automatically imported even if you are not using it, so that you can block it
@embedded or @dynamic Whether to use embedded or dynamic args. @embedded if using embedded args. @dynamic if using dynamic args. @embedded is faster and small than @dynamic.
// @embedded
import_wasm!(test_wasm);
use const_struct::*;
use wasi_virt_layer::prelude::*;
#[const_struct]
const VIRTUAL_ARGS: VirtualArgsEmbeddedState = VirtualArgsEmbeddedState {
args: &["command", "arg1", "arg2"],
};
plug_args!(@embedded, VirtualArgsTy, test_wasm);// @dynamic
import_wasm!(test_wasm);
use std::sync::{LazyLock, Mutex};
use wasi_virt_layer::prelude::*;
struct VirtualArgsState {
args: Vec<String>,
}
impl<'a> VirtualArgs<'a> for VirtualArgsState {
type Str = String;
fn get_args(&mut self) -> &[Self::Str] {
&self.args
}
}
static VIRTUAL_ARGS: LazyLock<Mutex<VirtualArgsState>> = LazyLock::new(|| {
let mut args = Vec::<String>::new();
args.push("command".into());
args.push("arg1".into());
Mutex::new(VirtualArgsState { args })
});
plug_args!(@dynamic, &mut VIRTUAL_ARGS.lock().unwrap(), test_wasm);Plugs the command-line arguments ecosystem.