Hi,

Assume I have a plugin:
package main

func Add(x, y int) int {
return x + y
}

func main() {}

I'd like to make sure that plugin functions are from certain type. So I 
wrote (ignore panics, they are for brevity):
Enter code here...package main

import (
"fmt"
"plugin"
)

type MathFunc func(int, int) int

func main() {
p, err := plugin.Open("./plugin.so")
if err != nil {
panic(err)
}
sym, err := p.Lookup("Add")
if err != nil {
panic(err)
}


// fn := sym.(MathFunc)
fn := sym.(func(int, int) int)
fmt.Println(fn(1, 2))
}

The commented out line causes a panic.

The other way I see is to expose MathFunc to plugins but then plugin 
writers will have to write something like:
var Add = MathFunc(func(x, y int) int {
return x + y
})

Which is ugly :)

Any way around this? (I saw that http.HandleFunc gets the function 
signature like I do now - so I guess this is the best way, but worth 
checking).

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to