Make client input available for LOAD instruction execution
This commit is contained in:
parent
a2d947e106
commit
46288b240b
@ -32,16 +32,16 @@ func NewFsWrapper(path string, st *state.State) FsWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
func(fs FsWrapper) one(sym string, ctx context.Context) (string, error) {
|
||||
func(fs FsWrapper) one(sym string, input []byte, ctx context.Context) (string, error) {
|
||||
return "one", nil
|
||||
}
|
||||
|
||||
func(fs FsWrapper) inky(sym string, ctx context.Context) (string, error) {
|
||||
func(fs FsWrapper) inky(sym string, input []byte, ctx context.Context) (string, error) {
|
||||
return "tinkywinky", nil
|
||||
}
|
||||
|
||||
func(fs FsWrapper) pinky(sym string, ctx context.Context) (string, error) {
|
||||
return "xyzzy", nil
|
||||
func(fs FsWrapper) pinky(sym string, input []byte, ctx context.Context) (string, error) {
|
||||
return fmt.Sprintf("xyzzy: %x", input), nil
|
||||
}
|
||||
|
||||
func(fs FsWrapper) FuncFor(sym string) (resource.EntryFunc, error) {
|
||||
|
@ -41,19 +41,19 @@ func funcFor(sym string) (resource.EntryFunc, error) {
|
||||
return nil, fmt.Errorf("unknown func: %s", sym)
|
||||
}
|
||||
|
||||
func getFoo(sym string, ctx context.Context) (string, error) {
|
||||
func getFoo(sym string, input []byte, ctx context.Context) (string, error) {
|
||||
return "inky", nil
|
||||
}
|
||||
|
||||
func getBar(sym string, ctx context.Context) (string, error) {
|
||||
func getBar(sym string, input []byte, ctx context.Context) (string, error) {
|
||||
return "pinky", nil
|
||||
}
|
||||
|
||||
func getBaz(sym string, ctx context.Context) (string, error) {
|
||||
func getBaz(sym string, input []byte, ctx context.Context) (string, error) {
|
||||
return "blinky", nil
|
||||
}
|
||||
|
||||
func getXyzzy(sym string, ctx context.Context) (string, error) {
|
||||
func getXyzzy(sym string, input []byte, ctx context.Context) (string, error) {
|
||||
return "inky pinky\nblinky clyde sue\ntinkywinky dipsy\nlala poo\none two three four five six seven\neight nine ten\neleven twelve", nil
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ func(fs FsResource) FuncFor(sym string) (EntryFunc, error) {
|
||||
if ok {
|
||||
return fn, nil
|
||||
}
|
||||
_, err := fs.getFuncNoCtx(sym)
|
||||
_, err := fs.getFuncNoCtx(sym, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unknown sym: %s", sym)
|
||||
}
|
||||
@ -55,11 +55,11 @@ func(fs FsResource) String() string {
|
||||
return fmt.Sprintf("fs resource at path: %s", fs.Path)
|
||||
}
|
||||
|
||||
func(fs FsResource) getFunc(sym string, ctx context.Context) (string, error) {
|
||||
return fs.getFuncNoCtx(sym)
|
||||
func(fs FsResource) getFunc(sym string, input []byte, ctx context.Context) (string, error) {
|
||||
return fs.getFuncNoCtx(sym, input)
|
||||
}
|
||||
|
||||
func(fs FsResource) getFuncNoCtx(sym string) (string, error) {
|
||||
func(fs FsResource) getFuncNoCtx(sym string, input []byte) (string, error) {
|
||||
fb := sym + ".txt"
|
||||
fp := path.Join(fs.Path, fb)
|
||||
log.Printf("getfunc search dir %s %s for %s", fs.Path, fp, sym)
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
// EntryFunc is a function signature for retrieving value for a key
|
||||
type EntryFunc func(sym string, ctx context.Context) (string, error)
|
||||
type EntryFunc func(sym string, input []byte, ctx context.Context) (string, error)
|
||||
type CodeFunc func(sym string) ([]byte, error)
|
||||
type TemplateFunc func(sym string) (string, error)
|
||||
type FuncForFunc func(sym string) (EntryFunc, error)
|
||||
|
@ -37,7 +37,7 @@ func funcFor(sym string) (EntryFunc, error) {
|
||||
return nil, fmt.Errorf("unknown func: %s", sym)
|
||||
}
|
||||
|
||||
func get(sym string, ctx context.Context) (string, error) {
|
||||
func get(sym string, input []byte, ctx context.Context) (string, error) {
|
||||
switch sym {
|
||||
case "foo":
|
||||
return "inky", nil
|
||||
@ -49,6 +49,6 @@ func get(sym string, ctx context.Context) (string, error) {
|
||||
return "", fmt.Errorf("unknown sym: %s", sym)
|
||||
}
|
||||
|
||||
func getXyzzy(sym string, ctx context.Context) (string, error) {
|
||||
func getXyzzy(sym string, input []byte, ctx context.Context) (string, error) {
|
||||
return "inky pinky\nblinky clyde sue\ntinkywinky dipsy\nlala poo\none two three four five six seven\neight nine ten\neleven twelve", nil
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ func(vm *Vm) RunLoad(b []byte, ctx context.Context) ([]byte, error) {
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
r, err := refresh(sym, vm.rs, ctx)
|
||||
r, err := vm.refresh(sym, vm.rs, ctx)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
@ -226,7 +226,7 @@ func(vm *Vm) RunReload(b []byte, ctx context.Context) ([]byte, error) {
|
||||
return b, err
|
||||
}
|
||||
|
||||
r, err := refresh(sym, vm.rs, ctx)
|
||||
r, err := vm.refresh(sym, vm.rs, ctx)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
@ -421,7 +421,7 @@ func(vm *Vm) Render(ctx context.Context) (string, error) {
|
||||
}
|
||||
|
||||
// retrieve data for key
|
||||
func refresh(key string, rs resource.Resource, ctx context.Context) (string, error) {
|
||||
func(vm *Vm) refresh(key string, rs resource.Resource, ctx context.Context) (string, error) {
|
||||
fn, err := rs.FuncFor(key)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@ -429,6 +429,7 @@ func refresh(key string, rs resource.Resource, ctx context.Context) (string, err
|
||||
if fn == nil {
|
||||
return "", fmt.Errorf("no retrieve function for external symbol %v", key)
|
||||
}
|
||||
return fn(key, ctx)
|
||||
input, _ := vm.st.GetInput()
|
||||
return fn(key, input, ctx)
|
||||
}
|
||||
|
||||
|
@ -20,15 +20,15 @@ type TestResource struct {
|
||||
state *state.State
|
||||
}
|
||||
|
||||
func getOne(sym string, ctx context.Context) (string, error) {
|
||||
func getOne(sym string, input []byte, ctx context.Context) (string, error) {
|
||||
return "one", nil
|
||||
}
|
||||
|
||||
func getTwo(sym string, ctx context.Context) (string, error) {
|
||||
func getTwo(sym string, input []byte, ctx context.Context) (string, error) {
|
||||
return "two", nil
|
||||
}
|
||||
|
||||
func getDyn(sym string, ctx context.Context) (string, error) {
|
||||
func getDyn(sym string, input []byte, ctx context.Context) (string, error) {
|
||||
return dynVal, nil
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ func (r TestResource) FuncFor(sym string) (resource.EntryFunc, error) {
|
||||
return nil, fmt.Errorf("invalid function: '%s'", sym)
|
||||
}
|
||||
|
||||
func(r TestResource) getInput(sym string, ctx context.Context) (string, error) {
|
||||
func(r TestResource) getInput(sym string, input []byte, ctx context.Context) (string, error) {
|
||||
v, err := r.state.GetInput()
|
||||
return string(v), err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user