mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
Fix using Indexer as Caller.
This commit is contained in:
parent
0fdf595633
commit
ed2855c595
11
eval/call.go
11
eval/call.go
|
@ -26,6 +26,17 @@ type Caller interface {
|
|||
Call(ec *EvalCtx, args []Value)
|
||||
}
|
||||
|
||||
func getCaller(v Value) Caller {
|
||||
if caller, ok := v.(Caller); ok {
|
||||
return caller
|
||||
}
|
||||
if indexer, ok := v.(Indexer); ok {
|
||||
return IndexerCaller{indexer}
|
||||
}
|
||||
throw(fmt.Errorf("a %s is not callable", v.Kind()))
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func (ec *EvalCtx) PCall(f Caller, args []Value) (ex error) {
|
||||
defer errutil.Catch(&ex)
|
||||
f.Call(ec, args)
|
||||
|
|
|
@ -237,10 +237,7 @@ func (cp *compiler) form(n *parse.Form) Op {
|
|||
headValues := headOp(ec)
|
||||
headMust := ec.must(headValues, "the head of command", p)
|
||||
headMust.mustLen(1)
|
||||
headCaller, ok := headValues[0].(Caller)
|
||||
if !ok {
|
||||
headMust.error("a callable", headValues[0].Kind())
|
||||
}
|
||||
headCaller := getCaller(headValues[0])
|
||||
|
||||
// args
|
||||
var args []Value
|
||||
|
|
|
@ -64,3 +64,17 @@ func intIndex(idx Value) int {
|
|||
}
|
||||
return i
|
||||
}
|
||||
|
||||
/*
|
||||
// CallerIndexer adapts a Caller to an Indexer.
|
||||
type CallerIndexer struct {
|
||||
Caller
|
||||
ec *EvalCtx
|
||||
}
|
||||
|
||||
func (ci CallerIndexer) Index(idx Value) Value {
|
||||
return captureOutput(ci.ec, func(ec *EvalCtx) {
|
||||
ci.Caller.Call(ec, []Value{idx})
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user