mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
eval: Add an AddBuiltinFns utility.
This commit is contained in:
parent
cfc473fcfe
commit
fb0fe70b8a
|
@ -121,7 +121,9 @@ func installModules(modules map[string]eval.Namespace, ed *Editor) {
|
|||
}
|
||||
|
||||
// Utility functions.
|
||||
ns[eval.FnPrefix+"styled"] = eval.NewRoVariable(&eval.BuiltinFn{"le:&styled", styled})
|
||||
eval.AddBuiltinFns(ns,
|
||||
&eval.BuiltinFn{"le:styled", styled},
|
||||
)
|
||||
|
||||
modules["le"] = ns
|
||||
// Install other modules.
|
||||
|
|
|
@ -2,6 +2,7 @@ package eval
|
|||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/elves/elvish/daemon/api"
|
||||
|
@ -16,8 +17,17 @@ func makeBuiltinNamespace(daemon *api.Client) Namespace {
|
|||
"paths": &EnvPathList{envName: "PATH"},
|
||||
"pwd": PwdVariable{daemon},
|
||||
}
|
||||
for _, b := range builtinFns {
|
||||
ns[FnPrefix+b.Name] = NewRoVariable(b)
|
||||
}
|
||||
AddBuiltinFns(ns, builtinFns...)
|
||||
return ns
|
||||
}
|
||||
|
||||
// AddBuiltinFns adds builtin functions to a namespace.
|
||||
func AddBuiltinFns(ns Namespace, fns ...*BuiltinFn) {
|
||||
for _, b := range fns {
|
||||
name := b.Name
|
||||
if i := strings.IndexRune(b.Name, ':'); i != -1 {
|
||||
name = b.Name[i+1:]
|
||||
}
|
||||
ns[FnPrefix+name] = NewRoVariable(b)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user