commit 577f56f43bea524dd55cc3f89016b4c0164d3a67
parent 0526690e1e9f310f8ca7869b6cde16a1bcb25a49
Author: lash <dev@holbrook.no>
Date: Sat, 14 Sep 2024 17:35:14 +0100
Refactor examples and dev exes on new engine interface
Diffstat:
17 files changed, 39 insertions(+), 22 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,3 +1,5 @@
+- 0.2.0
+ * Remove Init from engine interface, allowing input to be passed in all parts of engine execution.
- 0.1.0
* Data storage interface (db.Db) with implementations for memory (db.memDb), filesystem (db.fsDb), gdbm (db.gdbmDb) and Postgres (db.pgDb).
* Replace resource.FsResource and resource.MemResource with resource.DbResource using corresponding db.Db backend.
diff --git a/dev/interactive/main.go b/dev/interactive/main.go
@@ -54,7 +54,8 @@ func main() {
en = en.WithPersister(pe)
}
- cont, err := en.Init(ctx)
+ //cont, err := en.Init(ctx)
+ cont, err := en.Exec(ctx, []byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "engine init exited with error: %v\n", err)
os.Exit(1)
diff --git a/examples/db/main.go b/examples/db/main.go
@@ -139,7 +139,8 @@ func main() {
en := engine.NewEngine(cfg, rs)
en = en.WithPersister(pr)
- _, err = en.Init(ctx)
+ //_, err = en.Init(ctx)
+ _, err = en.Exec(ctx, []byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
diff --git a/examples/gdbm/main.go b/examples/gdbm/main.go
@@ -59,7 +59,8 @@ func main() {
}
en := engine.NewEngine(cfg, rs)
- _, err = en.Init(ctx)
+ //_, err = en.Init(ctx)
+ _, err = en.Exec(ctx, []byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
diff --git a/examples/http/main.go b/examples/http/main.go
@@ -151,11 +151,11 @@ func(f *DefaultSessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Reques
return
}
- if len(input) == 0 {
- r, err = en.Init(ctx)
- } else {
- r, err = en.Exec(ctx, input)
- }
+ //if len(input) == 0 {
+ // r, err = en.Init(ctx)
+ //} else {
+ r, err = en.Exec(ctx, input)
+ //}
if err != nil {
f.writeError(w, 500, "Engine exec fail", err)
return
diff --git a/examples/intro/main.go b/examples/intro/main.go
@@ -97,7 +97,8 @@ func main() {
en = en.WithState(st)
en = en.WithMemory(ca)
- _, err = en.Init(ctx)
+ //_, err = en.Init(ctx)
+ _, err = en.Exec(ctx, []byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
diff --git a/examples/languages/main.go b/examples/languages/main.go
@@ -98,7 +98,6 @@ func main() {
cfg := engine.Config{
Root: "root",
SessionId: "default",
- FlagCount: 1,
}
dp := path.Join(scriptDir, ".state")
@@ -109,18 +108,21 @@ func main() {
os.Exit(1)
}
pr := persist.NewPersister(store)
+ st := state.NewState(1)
en := engine.NewEngine(cfg, rs)
+ en = en.WithState(st)
en = en.WithPersister(pr)
aux := &langController{
- State: pr.State,
+ State: st,
}
rs.AddLocalFunc("swaplang", aux.lang)
rs.AddLocalFunc("msg", msg)
rs.AddLocalFunc("momsg", aux.moMsg)
rs.AddLocalFunc("empty", empty)
- _, err = en.Init(ctx)
+ //_, err = en.Init(ctx)
+ _, err = en.Exec(ctx, []byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
diff --git a/examples/longmenu/main.go b/examples/longmenu/main.go
@@ -37,7 +37,8 @@ func main() {
OutputSize: uint32(size),
}
en := engine.NewEngine(cfg, rs)
- cont, err := en.Init(ctx)
+ //cont, err := en.Init(ctx)
+ cont, err := en.Exec(ctx, []byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "engine init exited with error: %v\n", err)
os.Exit(1)
diff --git a/examples/pincheck/main.go b/examples/pincheck/main.go
@@ -94,7 +94,8 @@ func main() {
en := engine.NewEngine(cfg, rs)
en = en.WithState(st)
en = en.WithMemory(ca)
- _, err = en.Init(ctx)
+ //_, err = en.Init(ctx)
+ _, err = en.Exec(ctx, []byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
diff --git a/examples/preprocessor/main.go b/examples/preprocessor/main.go
@@ -96,7 +96,8 @@ func main() {
en = en.WithState(st)
en = en.WithMemory(ca)
- _, err = en.Init(ctx)
+ //_, err = en.Init(ctx)
+ _, err = en.Exec(ctx, []byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
diff --git a/examples/profile/main.go b/examples/profile/main.go
@@ -123,7 +123,8 @@ func main() {
en := engine.NewEngine(cfg, rs)
en = en.WithState(st)
en = en.WithMemory(ca)
- _, err = en.Init(ctx)
+ //_, err = en.Init(ctx)
+ _, err = en.Exec(ctx, []byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
diff --git a/examples/quit/main.go b/examples/quit/main.go
@@ -40,7 +40,8 @@ func main() {
en := engine.NewEngine(cfg, rs)
- _, err = en.Init(ctx)
+ //_, err = en.Init(ctx)
+ _, err = en.Exec(ctx, []byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
diff --git a/examples/reuse/main.go b/examples/reuse/main.go
@@ -44,7 +44,8 @@ func main() {
Root: "root",
}
en := engine.NewEngine(cfg, rs)
- _, err = en.Init(ctx)
+ //_, err = en.Init(ctx)
+ _, err = en.Exec(ctx, []byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
diff --git a/examples/session/main.go b/examples/session/main.go
@@ -77,7 +77,8 @@ func main() {
}
ctx = context.WithValue(ctx, "SessionId", sessionId)
en := engine.NewEngine(cfg, rs)
- _, err = en.Init(ctx)
+ //_, err = en.Init(ctx)
+ _, err = en.Exec(ctx, []byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
diff --git a/examples/state/main.go b/examples/state/main.go
@@ -97,7 +97,8 @@ func main() {
en = en.WithState(st)
en = en.WithDebug(nil)
- _, err = en.Init(ctx)
+ //_, err = en.Init(ctx)
+ _, err = en.Exec(ctx, []byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)
diff --git a/examples/state_passive/main.go b/examples/state_passive/main.go
@@ -120,7 +120,7 @@ func main() {
rs.AddLocalFunc("poke", aux.poke)
rs.AddLocalFunc("peek", aux.peek)
- cont, err := en.Init(ctx)
+ cont, err := en.Exec(ctx, []byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "engine init exited with error: %v\n", err)
os.Exit(1)
diff --git a/examples/validate/main.go b/examples/validate/main.go
@@ -78,7 +78,8 @@ func main() {
en := engine.NewEngine(cfg, rs)
en = en.WithState(st)
- _, err = en.Init(ctx)
+ //_, err = en.Init(ctx)
+ _, err = en.Exec(ctx, []byte{})
if err != nil {
fmt.Fprintf(os.Stderr, "engine init fail: %v\n", err)
os.Exit(1)