seperated builtins
Some checks failed
Build / build (push) Successful in 10m0s
Test / build (push) Failing after 16m20s

This commit is contained in:
Chuck Smith
2024-03-20 17:01:45 -04:00
parent f735215c28
commit 43362475f9
13 changed files with 345 additions and 204 deletions

30
object/builtin_input.go Normal file
View File

@@ -0,0 +1,30 @@
package object
import (
"bufio"
"fmt"
"io"
"os"
)
// Input ...
func Input(args ...Object) Object {
if len(args) > 0 {
obj, ok := args[0].(*String)
if !ok {
return newError(
"argument to `input` not supported, got %s",
args[0].Type(),
)
}
fmt.Fprintf(os.Stdout, obj.Value)
}
buffer := bufio.NewReader(os.Stdin)
line, _, err := buffer.ReadLine()
if err != nil && err != io.EOF {
return newError(fmt.Sprintf("error reading input from stdin: %s", err))
}
return &String{Value: string(line)}
}