mirror of
https://github.com/hymkor/lispect.git
synced 2026-08-28 04:46:59 -04:00
Implement (getenv)
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/hymkor/gmnlisp"
|
||||
@@ -138,3 +139,15 @@ func (g *Global) expectX(ctx context.Context, w *gmnlisp.World, node gmnlisp.Nod
|
||||
return gmnlisp.Progn(ctx, w, timeoutAct)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Global) getenv(ctx context.Context, w *gmnlisp.World, arg gmnlisp.Node) (gmnlisp.Node, error) {
|
||||
name, err := gmnlisp.ExpectClass[gmnlisp.String](ctx, w, arg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
value, ok := os.LookupEnv(string(name))
|
||||
if !ok {
|
||||
return gmnlisp.Null, nil
|
||||
}
|
||||
return gmnlisp.String(value), nil
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ func mains(args []string) error {
|
||||
gmnlisp.NewSymbol("spawn"): &gmnlisp.Function{Min: 1, F: g.spawn},
|
||||
gmnlisp.NewSymbol("expect*"): gmnlisp.SpecialF(g.expectX),
|
||||
gmnlisp.NewSymbol("expect"): gmnlisp.SpecialF(g.expect),
|
||||
gmnlisp.NewSymbol("getenv"): gmnlisp.Function1(g.getenv),
|
||||
})
|
||||
|
||||
if len(args) <= 0 {
|
||||
|
||||
Reference in New Issue
Block a user