Skip to content

Commit 44c0266

Browse files
author
梶塚太智
committed
Update main.rs
implement function `args-cmd` that get command-line arguments.
1 parent 1697e0f commit 44c0266

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,15 @@ impl Executor {
570570
}
571571
}
572572

573+
// Get command-line arguments
574+
"args-cmd" => self.stack.push(Type::List(
575+
env::args()
576+
.collect::<Vec<_>>()
577+
.iter()
578+
.map(|x| Type::String(x.to_string()))
579+
.collect::<Vec<Type>>(),
580+
)),
581+
573582
// Commands of control
574583

575584
// evaluate string as program
@@ -964,9 +973,10 @@ impl Executor {
964973
if let Some(value) = self.stack.pop() {
965974
value
966975
} else {
967-
self.log_print(format!(
976+
self.log_print(
968977
"Error! There are not enough values on the stack. returns default value\n"
969-
));
978+
.to_string(),
979+
);
970980
Type::String("".to_string())
971981
}
972982
}

0 commit comments

Comments
 (0)