MCPcopy Create free account
hub / github.com/aiscriptdev/aiscript / format

Function format

aiscript-vm/src/builtins/format.rs:6–21  ·  view source on GitHub ↗

Format function that implements Python-like string formatting

(
    state: &mut State<'gc>,
    args: Vec<Value<'gc>>,
)

Source from the content-addressed store, hash-verified

4
5/// Format function that implements Python-like string formatting
6pub(super) fn format<'gc>(
7 state: &mut State<'gc>,
8 args: Vec<Value<'gc>>,
9) -> Result<Value<'gc>, VmError> {
10 if args.is_empty() {
11 return Err(VmError::RuntimeError(
12 "format() missing required argument.".into(),
13 ));
14 }
15
16 let template = args[0].as_string()?.to_str().unwrap();
17 let format_args = &args[1..];
18
19 let result = format_string(template, format_args)?;
20 Ok(Value::IoString(Gc::new(state, result)))
21}
22
23#[derive(Debug, Default)]
24struct FormatSpec {

Callers

nothing calls this directly

Calls 4

RuntimeErrorClass · 0.85
format_stringFunction · 0.85
to_strMethod · 0.80
as_stringMethod · 0.80

Tested by

no test coverage detected