(state: &mut State<'gc>, args: Vec<Value<'gc>>)
| 48 | } |
| 49 | |
| 50 | fn serde_to_str<'gc>(state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> { |
| 51 | let (positional, keyword) = extract_keyword_args(&args)?; |
| 52 | |
| 53 | if positional.len() != 1 { |
| 54 | return Err(VmError::RuntimeError( |
| 55 | "to_str() requires value argument".into(), |
| 56 | )); |
| 57 | } |
| 58 | |
| 59 | let pretty = if let Some(pretty_val) = keyword.get("pretty") { |
| 60 | match pretty_val { |
| 61 | Value::Boolean(b) => *b, |
| 62 | _ => { |
| 63 | return Err(VmError::RuntimeError( |
| 64 | "pretty argument must be a boolean".into(), |
| 65 | )); |
| 66 | } |
| 67 | } |
| 68 | } else { |
| 69 | false |
| 70 | }; |
| 71 | |
| 72 | // Convert AIScript Value to JSON value |
| 73 | let json_value = to_json_value(&positional[0])?; |
| 74 | |
| 75 | // Convert to string with appropriate formatting |
| 76 | let result = if pretty { |
| 77 | serde_json::to_string_pretty(&json_value) |
| 78 | } else { |
| 79 | serde_json::to_string(&json_value) |
| 80 | } |
| 81 | .map_err(|e| VmError::RuntimeError(format!("Failed to serialize to JSON: {}", e)))?; |
| 82 | |
| 83 | Ok(Value::IoString(Gc::new(state, result))) |
| 84 | } |
| 85 | |
| 86 | fn serde_from_file<'gc>( |
| 87 | state: &mut State<'gc>, |
nothing calls this directly
no test coverage detected