@@ -1020,7 +1020,6 @@ impl Executor {
1020
1020
// Generate a instance of object
1021
1021
"instance" => {
1022
1022
let data = self . pop_stack ( ) . get_list ( ) ;
1023
- let mut methods = self . pop_stack ( ) . get_list ( ) ;
1024
1023
let mut class = self . pop_stack ( ) . get_list ( ) ;
1025
1024
let mut object: HashMap < String , Type > = HashMap :: new ( ) ;
1026
1025
@@ -1032,18 +1031,22 @@ impl Executor {
1032
1031
return ;
1033
1032
} ;
1034
1033
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 ( ) ;
1042
1046
object. insert ( item[ 0 ] . clone ( ) . get_string ( ) , item[ 1 ] . clone ( ) ) ;
1043
1047
} 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 ( ) ) ;
1045
1049
self . stack . push ( Type :: Error ( "instance-default" . to_string ( ) ) ) ;
1046
- return ;
1047
1050
}
1048
1051
}
1049
1052
@@ -1117,9 +1120,15 @@ impl Executor {
1117
1120
// Send the http request
1118
1121
"request" => {
1119
1122
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
+ }
1123
1132
}
1124
1133
1125
1134
// Open the file or url
0 commit comments