Add string & length typemap for Go.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12394 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Ian Lance Taylor 2011-01-14 21:31:36 +00:00
commit ef3644f052
2 changed files with 48 additions and 0 deletions

View file

@ -0,0 +1,25 @@
package main
import . "./char_binary"
func main() {
t := NewTest()
if t.Strlen("hile") != 4 {
print(t.Strlen("hile"))
panic("bad multi-arg typemap")
}
if t.Strlen("hil\000") != 4 {
panic("bad multi-arg typemap")
}
// creating a raw char*
pc := New_pchar(5)
Pchar_setitem(pc, 0, 'h')
Pchar_setitem(pc, 1, 'o')
Pchar_setitem(pc, 2, 'l')
Pchar_setitem(pc, 3, 'a')
Pchar_setitem(pc, 4, 0)
Delete_pchar(pc)
}

View file

@ -333,6 +333,28 @@
unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[]
%{ $result = ($1_ltype)$input.p; %}
/* String & length */
%typemap(gotype) (char *STRING, size_t LENGTH) "string"
%typemap(in) (char *STRING, size_t LENGTH)
%{
$1 = ($1_ltype)$input.p;
$2 = ($2_ltype)$input.n;
%}
%typemap(out) (char *STRING, size_t LENGTH)
%{ $result = _swig_makegostring((char*)$1, (size_t)$2); %}
%typemap(directorin) (char *STRING, size_t LENGTH)
%{ $input = _swig_makegostring((char*)$1_name, $2_name); %}
%typemap(directorout) (char *STRING, size_t LENGTH)
%{
$1 = ($1_ltype)$input.p;
$2 = ($2_ltype)$input.n;
%}
/* Enums. We can't do the right thing for enums in typemap(gotype) so
we deliberately don't define them. The right thing would be to
capitalize the name. This is instead done in go.cxx. */
@ -500,6 +522,7 @@
SWIGTYPE [],
SWIGTYPE (CLASS::*)
""
/* Go keywords. */
%include <gokw.swg>