Print objects to the text stream file, separated by sep and followed by end. Args: objects: Objects to print. sep (str): String inserted between values. Default: ' ' end (str): String appended after the last value. Default: '\n' file: A file-like object (stream). Defaults to the current stdout flush (bool): Whether to forcibly flush the stream. Default: False fn print(*objects, sep=" ", end="\n"
(
_state: &mut State<'gc>,
args: Vec<Value<'gc>>,
)
| 12 | /// |
| 13 | /// fn print(*objects, sep=" ", end="\n", file=nil, flush=false) {} |
| 14 | pub(super) fn print<'gc>( |
| 15 | _state: &mut State<'gc>, |
| 16 | args: Vec<Value<'gc>>, |
| 17 | ) -> Result<Value<'gc>, VmError> { |
| 18 | // Extract keyword arguments with defaults |
| 19 | let mut sep = " "; |
| 20 | let mut end = "\n"; |
| 21 | // let mut file = None; |
| 22 | let mut flush = false; |
| 23 | |
| 24 | // Build arguments iterator to handle both positional and keyword args |
| 25 | let mut i = 0; |
| 26 | let mut positional = Vec::new(); |
| 27 | |
| 28 | while i < args.len() { |
| 29 | match args[i] { |
| 30 | Value::String(key) if i + 1 < args.len() => { |
| 31 | match key.to_str().unwrap() { |
| 32 | "sep" => { |
| 33 | sep = args[i + 1].as_string()?.to_str().unwrap(); |
| 34 | i += 2; |
| 35 | } |
| 36 | "end" => { |
| 37 | end = args[i + 1].as_string()?.to_str().unwrap(); |
| 38 | i += 2; |
| 39 | } |
| 40 | "file" => { |
| 41 | // For now, just ignore file argument since we only support stdout |
| 42 | i += 2; |
| 43 | } |
| 44 | "flush" => { |
| 45 | flush = args[i + 1].as_boolean(); |
| 46 | i += 2; |
| 47 | } |
| 48 | _ => { |
| 49 | // Not a keyword arg, treat as positional |
| 50 | positional.push(&args[i]); |
| 51 | i += 1; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | _ => { |
| 56 | positional.push(&args[i]); |
| 57 | i += 1; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // Build the output string |
| 63 | let mut output = String::new(); |
| 64 | |
| 65 | for (i, arg) in positional.iter().enumerate() { |
| 66 | if i > 0 { |
| 67 | output.push_str(sep); |
| 68 | } |
| 69 | write!(output, "{}", arg).unwrap(); |
| 70 | } |
| 71 | output.push_str(end); |
nothing calls this directly
no test coverage detected