如何在 SWIG 生成的 Go 包装器中添加导入语句
How to add an import statement in a Go wrapper generated by SWIG
我有一个由 SWIG
为 Go
语言生成的包装器。在这个包装器中,我插入了一些需要包 reflect
的 Go
代码。因此,我需要在此包装器中添加 import "reflect"
行。在 SWIG
?
中是否有说明如何执行此操作的示例
我想你想要的是 section 23.4.10 Adding additional go code 即关于
的部分
If you need to import other go packages, you can do this with %go_import. For example...
%go_import("fmt", _ "unusedPackage", rp "renamed/package")
%insert(go_wrapper) %{
func foo() {
fmt.Println("Some string:", rp.GetString())
}
// Importing the same package twice is permitted,
// Go code will be generated with only the first instance of the import.
%go_import("fmt")
%insert(go_wrapper) %{
func bar() {
fmt.Println("Hello world!")
}
%}
我有一个由 SWIG
为 Go
语言生成的包装器。在这个包装器中,我插入了一些需要包 reflect
的 Go
代码。因此,我需要在此包装器中添加 import "reflect"
行。在 SWIG
?
我想你想要的是 section 23.4.10 Adding additional go code 即关于
的部分If you need to import other go packages, you can do this with %go_import. For example...
%go_import("fmt", _ "unusedPackage", rp "renamed/package")
%insert(go_wrapper) %{
func foo() {
fmt.Println("Some string:", rp.GetString())
}
// Importing the same package twice is permitted,
// Go code will be generated with only the first instance of the import.
%go_import("fmt")
%insert(go_wrapper) %{
func bar() {
fmt.Println("Hello world!")
}
%}