Add file operations
Some checks failed
Build / build (push) Failing after 6m4s
Test / build (push) Has been cancelled

This commit is contained in:
Chuck Smith
2024-03-28 14:00:21 -04:00
parent 110152a139
commit 67c5b4cd66
7 changed files with 226 additions and 3 deletions

27
builtins/close.go Normal file
View File

@@ -0,0 +1,27 @@
package builtins
import (
"monkey/object"
"monkey/typing"
"syscall"
)
// Close ...
func Close(args ...object.Object) object.Object {
if err := typing.Check(
"close", args,
typing.ExactArgs(1),
typing.WithTypes(object.INTEGER_OBJ),
); err != nil {
return newError(err.Error())
}
fd := int(args[0].(*object.Integer).Value)
err := syscall.Close(syscall.Handle(fd))
if err != nil {
return newError("IOError: %s", err)
}
return &object.Null{}
}