pluginwrap

command
v1.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2020 License: MIT Imports: 12 Imported by: 0

README

20190419-2 update pluginwrap: delete InitxxxFuncs , add func GetxxxFuncs(p *pluginloader.PluginLoader) *xxxFuncs ,avoid namespace conflict. 修改 pluginwrap ,删除生成的文件中的 InitxxxFuncs,改为:func GetxxxFuncs(p *pluginloader.PluginLoader) *xxxFuncs, 函数都被包含在 xxxFuncs结构体中避免命名冲突。

说明

本程序用于从源代码生成plugin中的导出结构体的接口(interface),以便用于类型断言,以及对函数和方法进行包装。 函数、方法的返回值、参数类型不能是用户自定义类型。 pluginwrap几乎已经完美了! 现在除了用户自定义类型,已经可以使用所有被导入库的类型。

如果必须使用自定义类型,有两种办法:

  1. 请使用 pluginloader.Callpluginloader.CallValue 调用。
  2. 把需要导出的复杂类型做成第三方库(import "your/package"),不要在plugin源代码中定义。

Use this program convert export structs to interface, in order to type assert. Wrap funcs and methods. pluginwrap is almost perfect now! It can deal with all types import from packages, except User Defined types in main.

If you must export self defined type, please put the code in a package can be imported by others.

安装(install):

go get github.com/rocket049/pluginloader/cmd/pluginwrap

用法(usage):

pluginwrap path/to/plugin/dir

生成的文件(generate):

dirWrap.go

调用

使用对象(struct)

	p, err := pluginloader.NewPluginLoader("foo.so")
	if err != nil {
		panic(err)
	}
	iface, err := p.Call("NewFoo",arg...)
	if err != nil {
		panic(err)
	}
	foo := iface.(IFoo)
	// use foo.Method

使用func

	//2090419 new
	p, err := pluginloader.NewPluginLoader("foo.so")
	if err != nil {
		panic(err)
	}
	
	// MUST call GetxxxFuncs(p) before call funcs, xxx = plugin名字
	funcs := GetfooFuncs(p)
	
	// call methods in plugin foo
	funcs.Method(arg)
	

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL