Files
monkey/internal/builtins/exit.go
Chuck Smith fc6ceee02c
Some checks failed
Build / build (push) Failing after 5m21s
Publish Image / publish (push) Failing after 32s
Test / build (push) Failing after 5m8s
restructure project
2024-03-28 16:20:09 -04:00

27 lines
437 B
Go

package builtins
import (
"monkey/internal/object"
"monkey/internal/typing"
)
// Exit ...
func Exit(args ...object.Object) object.Object {
if err := typing.Check(
"exit", args,
typing.RangeOfArgs(0, 1),
typing.WithTypes(object.INTEGER_OBJ),
); err != nil {
return newError(err.Error())
}
var status int
if len(args) == 1 {
status = int(args[0].(*object.Integer).Value)
}
object.ExitFunction(status)
return nil
}