Add New function to construct and initialize Env instances

The `New` function creates a new `Env` that embeds a `gmnlisp.World` and sets up the necessary pseudoterminal and inter-goroutine communication channels. This allows users to execute Lisp code with flexible argument control and custom Go function integration, offering more control compared to `RunString` or `RunFile`.
This commit is contained in:
HAYAMA_Kaoru
2025-05-04 16:59:17 +09:00
parent 3c40d37843
commit fe2080ba9a
2 changed files with 31 additions and 14 deletions
+7 -2
View File
@@ -20,8 +20,9 @@ var (
var ErrCtrlC = errors.New("^C")
type Env struct {
w *Watcher
term *Term
w *Watcher
term *Term
*gmnlisp.World
closer []func()
}
@@ -30,6 +31,10 @@ func (env *Env) Close() {
env.closer[i]()
}
env.closer = nil
if env.term != nil {
env.term.Close()
env.term = nil
}
}
func (env *Env) send(ctx context.Context, w *gmnlisp.World, args []gmnlisp.Node) (gmnlisp.Node, error) {