Skip to content

Commit 054ff48

Browse files
authored
Merge branch 'Stack-Programing-Community:main' into main
2 parents 307e843 + 9477838 commit 054ff48

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/main.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,6 @@ impl Executor {
10201020
// Generate a instance of object
10211021
"instance" => {
10221022
let data = self.pop_stack().get_list();
1023-
let mut methods = self.pop_stack().get_list();
10241023
let mut class = self.pop_stack().get_list();
10251024
let mut object: HashMap<String, Type> = HashMap::new();
10261025

@@ -1032,18 +1031,22 @@ impl Executor {
10321031
return;
10331032
};
10341033

1035-
for (name, element) in &mut class.to_owned()[1..class.len()].iter().zip(data) {
1036-
object.insert(name.to_owned().get_string(), element);
1037-
}
1038-
1039-
for item in &mut methods {
1040-
let item = item.get_list();
1041-
if item.len() >= 2 {
1034+
let mut index = 0;
1035+
for item in &mut class.to_owned()[1..class.len()].iter() {
1036+
let mut item = item.to_owned();
1037+
if item.get_list().len() == 1 {
1038+
let element = &data[index];
1039+
object.insert(
1040+
item.get_list()[0].to_owned().get_string(),
1041+
element.to_owned(),
1042+
);
1043+
index += 1;
1044+
} else if item.get_list().len() >= 2 {
1045+
let item = item.get_list();
10421046
object.insert(item[0].clone().get_string(), item[1].clone());
10431047
} else {
1044-
self.log_print("Error! the default data structure is wrong.".to_string());
1048+
self.log_print("Error! the class data structure is wrong.".to_string());
10451049
self.stack.push(Type::Error("instance-default".to_string()));
1046-
return;
10471050
}
10481051
}
10491052

@@ -1117,9 +1120,15 @@ impl Executor {
11171120
// Send the http request
11181121
"request" => {
11191122
let url = self.pop_stack().get_string();
1120-
self.stack.push(Type::String(
1121-
reqwest::blocking::get(url).unwrap().text().unwrap(),
1122-
));
1123+
match reqwest::blocking::get(url) {
1124+
Ok(i) => self
1125+
.stack
1126+
.push(Type::String(i.text().unwrap_or("".to_string()))),
1127+
Err(e) => {
1128+
self.log_print(format!("Error! {e}\n"));
1129+
self.stack.push(Type::Error("request".to_string()))
1130+
}
1131+
}
11231132
}
11241133

11251134
// Open the file or url

0 commit comments

Comments
 (0)