Format array.__str__ output
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -29,7 +29,7 @@ thread_local! {
|
||||
0 => {
|
||||
let array = machine.stack_pop()?;
|
||||
let index = IntObj::new(0);
|
||||
let working = StrObj::new(String::new());
|
||||
let working = StrObj::new(String::from("{"));
|
||||
machine.stack_push(working)?;
|
||||
machine.stack_push(index)?;
|
||||
machine.stack_push(array)?;
|
||||
@@ -48,7 +48,12 @@ thread_local! {
|
||||
.ok_or_else(|| RuntimeError::WrongValue("int".to_string()))?;
|
||||
let index = index_int.value() as usize;
|
||||
if array.value().len() <= index {
|
||||
// done iterating, exit
|
||||
// done iterating, add closing brace and then exit
|
||||
let working_obj = machine.stack_pop()?;
|
||||
let working = working_obj.as_any().downcast_ref::<StrObj>()
|
||||
.ok_or_else(|| RuntimeError::WrongValue("string".to_string()))?;
|
||||
let str_final = StrObj::new(format!("{} }}", working.value()));
|
||||
machine.stack_push(str_final)?;
|
||||
return Ok(BuiltinExit::Return);
|
||||
}
|
||||
// get the current item from the array, push the index and
|
||||
@@ -82,7 +87,7 @@ thread_local! {
|
||||
let working = working_obj.as_any().downcast_ref::<StrObj>()
|
||||
.ok_or_else(|| RuntimeError::WrongValue("str".to_string()))?;
|
||||
|
||||
let new_str = StrObj::new(format!("{}{}", working.value(), returned.value()));
|
||||
let new_str = StrObj::new(format!("{} {}", working.value(), returned.value()));
|
||||
// index gets incremented here
|
||||
let new_index = IntObj::new(index.value() + 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user