Skip to content

Commit 9f490f1

Browse files
committed
add command "index"
1 parent 7847e84 commit 9f490f1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,20 @@ impl Executor {
11091109
})
11101110
}
11111111

1112+
"index" => {
1113+
let findhint = self.pop_stack().get_string();
1114+
let findtarget = self.pop_stack().get_list();
1115+
1116+
for index in 0..(findtarget.len()) {
1117+
if findhint == findtarget[index].clone().get_string() {
1118+
self.stack.push(Type::Number(index as f64));
1119+
return;
1120+
}
1121+
}
1122+
self.log_print(String::from("Error! item not found in this list").as_str().to_owned() + "\n");
1123+
self.stack.push(Type::Error(String::from("item-not-found")));
1124+
}
1125+
11121126
// If it is not recognized as a command, use it as a string.
11131127
_ => self.stack.push(Type::String(command)),
11141128
}

0 commit comments

Comments
 (0)