Skip to content

Commit 0522886

Browse files
committed
String indexing
1 parent 72906cd commit 0522886

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

.github/workflows/rustdoc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ on:
1717
- 'Cargo.toml'
1818
- 'Cargo.lock'
1919
- '.github/**'
20-
20+
2121
env:
2222
CARGO_TERM_COLOR: always
2323

zenlang/src/vm/vm_opcode.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ impl VM {
175175
return;
176176
}
177177
}
178+
Value::String(string) => {
179+
if let Value::Number(index) = index {
180+
if let Some(ch) = string.chars().nth(index as usize) {
181+
self.stack.push(Value::String(String::from(ch)));
182+
} else {
183+
self.stack.push(Value::Null());
184+
}
185+
return;
186+
}
187+
}
178188
_ => {}
179189
}
180190
self.error = format!("iafs failed: invalid operand types");

0 commit comments

Comments
 (0)