How to add an import statement in a Go wrapper generated by SWIG

huangapple go评论87阅读模式
英文:

How to add an import statement in a Go wrapper generated by SWIG

问题

我有一个由SWIGGo语言生成的包装器。在这个包装器中,我插入了一些需要使用reflect包的Go代码。因此,我需要在这个包装器中添加import "reflect"这一行。是否有一个示例可以说明如何在SWIG中实现这个功能?

英文:

I have a wrapper generated by SWIG for the Go language. In this wrapper, I inserted some Go code that needs the package reflect. Consequently, I need to add the line import "reflect" in this wrapper. Is there an example that illustrates how to do this in SWIG?

答案1

得分: 0

我认为你想要的内容在第23.4.10节中的添加额外的Go代码部分,特别是关于:

> 如果你需要导入其他的Go包,你可以使用%go_import。例如...

%go_import("fmt", _ "unusedPackage", rp "renamed/package")

%insert(go_wrapper) %{

func foo() {
  fmt.Println("Some string:", rp.GetString())
}

// 允许导入同一个包两次,生成的Go代码只会包含第一次导入的实例。
%go_import("fmt")

%insert(go_wrapper) %{

func bar() {
  fmt.Println("Hello world!")
}

%}
英文:

I think what you want is in section 23.4.10 Adding additional go code namely the part about

> 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!")
}

%}

huangapple
  • 本文由 发表于 2021年9月15日 15:12:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/69188570.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定