From ed382bec55be25039e4dcf020d1512139855c9bb Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 9 Nov 2022 08:38:50 -0600 Subject: cleanup of the example commands. more plugin work add a button in two plugins at the same time! added a button in andlabs/ui & gocui attempt a common widget struct between wit/gui & the plugins start handling missing plugins rename Makefile command examples remote examples used for testing filename improvements golang src code uses lowercase and _ in filenames fix crash when button click function == nil fix wrong name 'gocli' -> 'gocui' keep fighting with goreadme generated README.md Signed-off-by: Jeff Carr --- plugin.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'plugin.go') diff --git a/plugin.go b/plugin.go index 5c10e03..58e6dbe 100644 --- a/plugin.go +++ b/plugin.go @@ -1,5 +1,10 @@ package gui +// This is based off of the excellent example and documentation here: +// https://github.com/vladimirvivien/go-plugin-example +// There truly are great people in this world. +// It's a pleasure to be here with all of you + import ( "log" "os" @@ -8,6 +13,7 @@ import ( "github.com/davecgh/go-spew/spew" ) +// TODO: could a protobuf work here? type Greeter interface { Greet() JcarrButton() @@ -15,6 +21,7 @@ type Greeter interface { } var PlugGocli *plugin.Plugin +var PlugGocliOk bool var PlugHello *plugin.Plugin // var gBut plugin.Symbol @@ -23,6 +30,9 @@ var symGreeter plugin.Symbol var greeter Greeter var ok bool +var typeToolkit plugin.Symbol +var typeToolkitCast Greeter + func LoadPlugin(name string) *plugin.Plugin { scs := spew.ConfigState{MaxDepth: 1} @@ -33,12 +43,19 @@ func LoadPlugin(name string) *plugin.Plugin { log.Println(scs.Sdump(plug)) if err != nil { log.Println(err) - os.Exit(1) + return nil } - PlugGocli = plug // 2. look up a symbol (an exported function or variable) // in this case, variable Greeter + typeToolkit, err = plug.Lookup("Toolkit") + log.Println("plugin.Toolkit", typeToolkit) + log.Println(scs.Sdump(typeToolkit)) + if err != nil { + log.Println(err) + os.Exit(1) + } + symGreeter, err = plug.Lookup("Greeter") log.Println("symGreater", symGreeter) log.Println(scs.Sdump(symGreeter)) @@ -57,6 +74,14 @@ func LoadPlugin(name string) *plugin.Plugin { log.Println("unexpected type from module symbol") os.Exit(1) } + + /* + typeToolkitCast, ok = typeToolkit.(Greeter) + if !ok { + log.Println("unexpected cast of Toolkit to Greeter") + os.Exit(1) + } + */ return plug } @@ -66,6 +91,7 @@ func RunGreet() { log.Println("wit/gui gocui plugin didn't load") return } + PlugGocliOk = true greeter.Greet() } -- cgit v1.2.3