Files
monkey/builtins/hex.go
2024-03-24 16:03:08 -04:00

21 lines
436 B
Go

package builtins
import (
"fmt"
"monkey/object"
"strconv"
)
// Hex ...
func Hex(args ...object.Object) object.Object {
if len(args) != 1 {
return newError("wrong number of arguments. got=%d, want=1",
len(args))
}
if i, ok := args[0].(*object.Integer); ok {
return &object.String{Value: fmt.Sprintf("0x%s", strconv.FormatInt(i.Value, 16))}
}
return newError("argument to `hex` not supported, got %s", args[0].Type())
}