| 158 | |
| 159 | impl<'gc> From<Value<'gc>> for ReturnValue { |
| 160 | fn from(value: Value<'gc>) -> Self { |
| 161 | match value { |
| 162 | Value::Number(value) => ReturnValue::Number(value), |
| 163 | Value::Boolean(value) => ReturnValue::Boolean(value), |
| 164 | Value::String(value) => ReturnValue::String(value.to_string()), |
| 165 | Value::IoString(value) => ReturnValue::String(value.to_string()), |
| 166 | Value::List(value) => ReturnValue::Array( |
| 167 | value |
| 168 | .borrow() |
| 169 | .data |
| 170 | .iter() |
| 171 | .map(|item| item.to_serde_value()) |
| 172 | .collect::<Vec<_>>(), |
| 173 | ), |
| 174 | Value::Instance(instance) => { |
| 175 | if instance.borrow().class.borrow().name.to_str().unwrap() == "Response" { |
| 176 | return ReturnValue::Response( |
| 177 | instance |
| 178 | .borrow() |
| 179 | .fields |
| 180 | .iter() |
| 181 | .map(|(key, value)| (key.to_string(), value.to_serde_value())) |
| 182 | .collect(), |
| 183 | ); |
| 184 | } else { |
| 185 | ReturnValue::Object( |
| 186 | instance |
| 187 | .borrow() |
| 188 | .fields |
| 189 | .iter() |
| 190 | .map(|(key, value)| (key.to_string(), value.to_serde_value())) |
| 191 | .collect(), |
| 192 | ) |
| 193 | } |
| 194 | } |
| 195 | Value::Object(obj) => ReturnValue::Object( |
| 196 | obj.borrow() |
| 197 | .fields |
| 198 | .iter() |
| 199 | .map(|(key, value)| (key.to_string(), value.to_serde_value())) |
| 200 | .collect(), |
| 201 | ), |
| 202 | Value::Agent(agent) => ReturnValue::Agent(agent.name.to_string()), |
| 203 | _ => ReturnValue::Nil, |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | pub fn eval(source: &'static str) -> Result<ReturnValue, VmError> { |