summaryrefslogtreecommitdiff
path: root/plugin.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2022-11-09 08:38:50 -0600
committerJeff Carr <[email protected]>2022-11-09 08:38:50 -0600
commited382bec55be25039e4dcf020d1512139855c9bb (patch)
treefb3a671fd07c03a75cedb8d56b2241108cd792ff /plugin.go
parentb410d0fd083ee89eed410cda2123a22cddcd3f44 (diff)
cleanup of the example commands. more plugin workv0.4.6
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 <[email protected]>
Diffstat (limited to 'plugin.go')
-rw-r--r--plugin.go30
1 files changed, 28 insertions, 2 deletions
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()
}