Browse Source

embedding shell commands

Signed-off-by: Erik Hollensbe <github@hollensbe.org>
master
Erik Hollensbe 12 months ago
parent
commit
2992cc83d9
3 changed files with 23 additions and 11 deletions
  1. +1
    -1
      Cargo.toml
  2. +5
    -3
      src/bundle.js
  3. +17
    -7
      src/main.rs

+ 1
- 1
Cargo.toml View File

@ -8,4 +8,4 @@ edition = "2018"
[dependencies]
deno_core = "^0.45.2"
tokio = { version = "0.2.20", features = ["rt-core"] }
tokio = "^0"

+ 5
- 3
src/bundle.js View File

@ -1,7 +1,9 @@
function main() {
ops = Deno.core.ops();
u8 = new Uint8Array("echo hi >/tmp/foo");
Deno.core.print(Deno.core.dispatch(ops["runShell"], u8, null));
const ops = Deno.core.ops();
const u8 = Deno.core.encode("echo hi");
Deno.core.print(
Deno.core.decode(Deno.core.dispatch(ops["runShell"], u8, null))
);
}
main();

+ 17
- 7
src/main.rs View File

@ -1,5 +1,6 @@
use deno_core::CoreIsolate;
use deno_core::Op;
use deno_core::Script;
use deno_core::StartupData;
use deno_core::ZeroCopyBuf;
use std::process::Command;
@ -11,9 +12,12 @@ struct CmdArgs {
impl From<&[u8]> for CmdArgs {
fn from(buf: &[u8]) -> Self {
return CmdArgs {
cmdline: String::from_utf8_lossy(buf).to_string(),
};
let str = String::from_utf8_lossy(buf)
.trim_end_matches(char::from(0))
.to_string();
println!("{:?}", str);
return CmdArgs { cmdline: str };
}
}
@ -29,9 +33,15 @@ fn op_run_shell(_isolate: &mut CoreIsolate, control_buf: &[u8], _zcb: Option<Zer
}
fn main() {
let mut isolate = CoreIsolate::new(StartupData::None {}, false);
let mut isolate = CoreIsolate::new(
StartupData::Script(Script {
filename: "bundle.js",
source: include_str!("bundle.js"),
}),
false,
);
isolate.register_op("runShell", op_run_shell);
isolate
.execute("main.js", include_str!("bundle.js"))
.unwrap();
let mut runtime = tokio::runtime::Builder::new().enable_all().build().unwrap();
runtime.block_on(isolate).unwrap()
}

Loading…
Cancel
Save