(
mc: &'gc Mutation<'gc>,
receiver: Value<'gc>,
args: Vec<Value<'gc>>,
)
| 277 | } |
| 278 | |
| 279 | fn join<'gc>( |
| 280 | mc: &'gc Mutation<'gc>, |
| 281 | receiver: Value<'gc>, |
| 282 | args: Vec<Value<'gc>>, |
| 283 | ) -> Result<Value<'gc>, VmError> { |
| 284 | let receiver = receiver.as_string_value()?; |
| 285 | let separator = receiver.as_str(); |
| 286 | |
| 287 | if args.len() != 1 { |
| 288 | return Err(VmError::RuntimeError( |
| 289 | "join: expected exactly one array argument".into(), |
| 290 | )); |
| 291 | } |
| 292 | |
| 293 | // Get the array from args[0] |
| 294 | let vec = match &args[0] { |
| 295 | Value::List(list) => &list.borrow().data, |
| 296 | _ => { |
| 297 | return Err(VmError::RuntimeError( |
| 298 | "join: argument must be an array".into(), |
| 299 | )); |
| 300 | } |
| 301 | }; |
| 302 | |
| 303 | let mut result = String::new(); |
| 304 | for (i, value) in vec.iter().enumerate() { |
| 305 | if i > 0 { |
| 306 | result.push_str(separator); |
| 307 | } |
| 308 | match value { |
| 309 | Value::String(s) => result.push_str(s.to_str().unwrap()), |
| 310 | Value::IoString(s) => result.push_str(s), |
| 311 | _ => { |
| 312 | return Err(VmError::RuntimeError(format!( |
| 313 | "join: array element {} must be a string", |
| 314 | i |
| 315 | ))); |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | Ok(Value::IoString(Gc::new(mc, result))) |
| 321 | } |
| 322 | |
| 323 | // Regex operations |
| 324 | fn regex_match<'gc>( |
nothing calls this directly
no test coverage detected