23 lines
429 B
Go
23 lines
429 B
Go
package builtins
|
|
|
|
import (
|
|
"fmt"
|
|
"monkey/internal/object"
|
|
"monkey/internal/typing"
|
|
"strconv"
|
|
)
|
|
|
|
// Hex ...
|
|
func Hex(args ...object.Object) object.Object {
|
|
if err := typing.Check(
|
|
"hex", args,
|
|
typing.ExactArgs(1),
|
|
typing.WithTypes(object.IntegerType),
|
|
); err != nil {
|
|
return newError(err.Error())
|
|
}
|
|
|
|
i := args[0].(object.Integer)
|
|
return object.String{Value: fmt.Sprintf("0x%s", strconv.FormatInt(i.Value, 16))}
|
|
}
|