mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
Add builtin resolve
; change Repr of BuiltinFn.
This commit is contained in:
parent
713b98fd0d
commit
425f19165f
|
@ -36,7 +36,7 @@ func (*BuiltinFn) Kind() string {
|
|||
}
|
||||
|
||||
func (b *BuiltinFn) Repr(int) string {
|
||||
return "$" + FnPrefix + b.Name
|
||||
return "<builtin " + b.Name + ">"
|
||||
}
|
||||
|
||||
// Call calls a builtin function.
|
||||
|
@ -103,6 +103,8 @@ func init() {
|
|||
&BuiltinFn{"!=", WrapFn(noteq)},
|
||||
&BuiltinFn{"deepeq", deepeq},
|
||||
|
||||
&BuiltinFn{"resolve", WrapFn(resolveFn)},
|
||||
|
||||
&BuiltinFn{"take", WrapFn(take)},
|
||||
|
||||
&BuiltinFn{"count", count},
|
||||
|
@ -713,6 +715,11 @@ func deepeq(ec *EvalCtx, args []Value) {
|
|||
out <- Bool(true)
|
||||
}
|
||||
|
||||
func resolveFn(ec *EvalCtx, cmd String) {
|
||||
out := ec.ports[1].Chan
|
||||
out <- resolve(string(cmd), ec)
|
||||
}
|
||||
|
||||
func take(ec *EvalCtx, n int, iterate func(func(Value))) {
|
||||
out := ec.ports[1].Chan
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"os"
|
||||
"syscall"
|
||||
|
||||
"github.com/elves/elvish/parse"
|
||||
"github.com/elves/elvish/util"
|
||||
)
|
||||
|
||||
|
@ -25,7 +26,7 @@ func (ExternalCmd) Kind() string {
|
|||
}
|
||||
|
||||
func (e ExternalCmd) Repr(int) string {
|
||||
return "<external " + e.Name + " >"
|
||||
return "<external " + parse.Quote(e.Name) + ">"
|
||||
}
|
||||
|
||||
// Call calls an external command.
|
||||
|
|
|
@ -27,12 +27,12 @@ func (s String) Call(ec *EvalCtx, args []Value) {
|
|||
resolve(string(s), ec).Call(ec, args)
|
||||
}
|
||||
|
||||
func resolve(s string, ec *EvalCtx) Fn {
|
||||
func resolve(s string, ec *EvalCtx) FnValue {
|
||||
// Try variable
|
||||
splice, ns, name := ParseVariable(string(s))
|
||||
if !splice {
|
||||
if v := ec.ResolveVar(ns, FnPrefix+name); v != nil {
|
||||
if caller, ok := v.Get().(Fn); ok {
|
||||
if caller, ok := v.Get().(FnValue); ok {
|
||||
return caller
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user