5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-30 10:51:35 +00:00
matterbridge/vendor/github.com/d5/tengo/objects/builtin_format.go

28 lines
537 B
Go
Raw Normal View History

2019-06-16 21:33:25 +00:00
package objects
func builtinFormat(args ...Object) (Object, error) {
numArgs := len(args)
if numArgs == 0 {
return nil, ErrWrongNumArguments
}
format, ok := args[0].(*String)
if !ok {
return nil, ErrInvalidArgumentType{
Name: "format",
Expected: "string",
Found: args[0].TypeName(),
}
}
if numArgs == 1 {
return format, nil // okay to return 'format' directly as String is immutable
}
s, err := Format(format.Value, args[1:]...)
if err != nil {
return nil, err
}
return &String{Value: s}, nil
}