data-cursor.go: now supports the 'index' command
This commit is contained in:
parent
e6174aca82
commit
d9fbe6f36d
@ -15,6 +15,7 @@ const (
|
||||
resetName = "reset"
|
||||
nextName = "next"
|
||||
currentName = "current"
|
||||
indexName = "index"
|
||||
)
|
||||
|
||||
type dataCursor struct {
|
||||
@ -66,23 +67,27 @@ func (dc *dataCursor) String() string {
|
||||
}
|
||||
|
||||
func (dc *dataCursor) HasOperation(name string) (exists bool) {
|
||||
exists = name == indexName
|
||||
if !exists {
|
||||
f, ok := dc.ds[name]
|
||||
exists = ok && isFunctor(f)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (dc *dataCursor) CallOperation(name string, args []any) (value any, err error) {
|
||||
if functor, ok := dc.ds[name]; ok && isFunctor(functor) {
|
||||
if name == indexName {
|
||||
value = dc.Index()
|
||||
} else if functor, ok := dc.ds[name]; ok && isFunctor(functor) {
|
||||
if functor == dc.cleanFunc {
|
||||
return dc.Clean()
|
||||
value, err = dc.Clean()
|
||||
} else if functor == dc.resetFunc {
|
||||
return dc.Reset()
|
||||
value, err = dc.Reset()
|
||||
} else {
|
||||
ctx := cloneContext(dc.ctx)
|
||||
value, err = functor.Invoke(ctx, name, []any{})
|
||||
exportObjects(dc.ctx, ctx)
|
||||
}
|
||||
|
||||
} else {
|
||||
err = errNoOperation(name)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user