From f2dc3a9c1f1e2ef5242be594c5cee6502b3e2547 Mon Sep 17 00:00:00 2001
From: Ian Lance Taylor
Date: Tue, 21 Jan 2014 11:27:09 -0800
Subject: [PATCH] [Go] Add %go_import directive.
---
CHANGES.current | 3 +++
Doc/Manual/Go.html | 30 +++++++++++++++++++++++++----
Lib/go/go.swg | 3 +++
Lib/go/goruntime.swg | 22 +++++++++------------
Source/Modules/go.cxx | 45 +++++++++++++++++++++++++++++++++++++++++--
5 files changed, 84 insertions(+), 19 deletions(-)
diff --git a/CHANGES.current b/CHANGES.current
index 1945e9292..ca7503d41 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.0 (in progress)
============================
+2014-01-21: ianlancetaylor
+ [Go] Add %go_import directive.
+
2014-01-21: ianlancetaylor
[Go] Add support for Go 1.3, not yet released.
diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html
index 43bfc6971..240db2b61 100644
--- a/Doc/Manual/Go.html
+++ b/Doc/Manual/Go.html
@@ -666,9 +666,31 @@ func (arg SwigcptrWrapped_MyClass) GetAValue() (int, bool) {
few, then you might as well define your own struct that includes the
swig-wrapped object, instead of adding methods to the swig-generated object.
-This only works if your wrappers do not need to import other go modules.
-There is at present no way to insert import statements in the correct place
-in swig-generated go. If you need to do that, you must put your go code
-in a separate file.
+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!")
+}
+
+%}
+
+
+