Skip to content

Commit

Permalink
Merge pull request #492 from moonbitlang/polish_cli_args_passing
Browse files Browse the repository at this point in the history
internal: polish cli args passing
  • Loading branch information
Young-Flash authored Nov 26, 2024
2 parents 6fe6396 + 6ccf2d1 commit fa46488
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub fn get_args() -> Array[String] {

extern "js" fn get_cli_args_internal() -> Array[String] =
#| function() {
#| return process.argv.slice(2);
#| return process.argv;
#| }

fn main {
Expand Down
4 changes: 3 additions & 1 deletion crates/moonrun/src/sys_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ fn construct_args_list<'s>(
args: &[String],
scope: &mut v8::HandleScope<'s>,
) -> v8::Local<'s, v8::Array> {
// align with node's behavior
// use this concat instead of std::env::args(), to ignore the possible --
let cli_args: Vec<String> = std::env::args()
// path of moonrun and the path of the wasm file
.take(2)
.chain(args.iter().cloned())
.collect();

let arr = v8::Array::new(scope, args.len() as i32);
let arr = v8::Array::new(scope, cli_args.len() as i32);
for (i, arg) in cli_args.iter().enumerate() {
let arg = v8::String::new(scope, arg).unwrap();
arr.set_index(scope, i as u32, arg.into());
Expand Down

0 comments on commit fa46488

Please sign in to comment.