From 4144ba4d5865c248f7b7d6e2597e0a54f802da4c Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Fri, 30 Jan 2015 18:44:58 +0100 Subject: [PATCH] all: add hi.Concat(str1, str2) --- README.md | 2 ++ _examples/hi/hi.go | 5 +++++ _examples/py_hi/hi.c | 24 ++++++++++++++++++++++++ _examples/py_hi/hi.go | 25 ++++++++++--------------- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 8f1ec4a..b9284f6 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,8 @@ hi from go >>> hi.Hello("you") hello you from go +>>> hi.Concat("hello ","gopy-gen") +'hello gopy-gen' ``` ## Limitations diff --git a/_examples/hi/hi.go b/_examples/hi/hi.go index 781e009..67859a4 100644 --- a/_examples/hi/hi.go +++ b/_examples/hi/hi.go @@ -19,6 +19,11 @@ func Hello(s string) { fmt.Printf("hello %s from go\n", s) } +// Concat concatenates two strings together and returns the resulting string. +func Concat(s1, s2 string) string { + return s1 + s2 +} + // Add returns the sum of its arguments. func Add(i, j int) int { return i + j diff --git a/_examples/py_hi/hi.c b/_examples/py_hi/hi.c index f3bf760..396e180 100644 --- a/_examples/py_hi/hi.c +++ b/_examples/py_hi/hi.c @@ -88,6 +88,29 @@ gopy_Add(PyObject *self, PyObject *args) { } +/* pythonization of: hi.Concat */ +static PyObject* +gopy_Concat(PyObject *self, PyObject *args) { + const char* cgopy_s1; + GoString c_s1; + const char* cgopy_s2; + GoString c_s2; + const char* cgopy_gopy_ret; + GoString c_gopy_ret; + + if (!PyArg_ParseTuple(args, "ss", (GoString*)(&cgopy_s1), (GoString*)(&cgopy_s2))) { + return NULL; + } + + c_s1 = _cgopy_makegostring(cgopy_s1); + c_s2 = _cgopy_makegostring(cgopy_s2); + + c_gopy_ret = GoPy_Concat(c_s1, c_s2); + + return Py_BuildValue("s", c_gopy_ret); +} + + /* pythonization of: hi.Hello */ static PyObject* gopy_Hello(PyObject *self, PyObject *args) { @@ -119,6 +142,7 @@ gopy_Hi(PyObject *self, PyObject *args) { static PyMethodDef GoPy_hi_Methods[] = { {"Add", gopy_Add, METH_VARARGS, "doc for: hi.Add"}, + {"Concat", gopy_Concat, METH_VARARGS, "doc for: hi.Concat"}, {"Hello", gopy_Hello, METH_VARARGS, "doc for: hi.Hello"}, {"Hi", gopy_Hi, METH_VARARGS, "doc for: hi.Hi"}, {NULL, NULL, 0, NULL} /* Sentinel */ diff --git a/_examples/py_hi/hi.go b/_examples/py_hi/hi.go index 87d4cce..d28e074 100644 --- a/_examples/py_hi/hi.go +++ b/_examples/py_hi/hi.go @@ -13,33 +13,28 @@ import ( //export GoPy_Add -// GoPy_Add wraps hi.Add -// github.com/go-python/gopy-gen/_examples/hi.Add -// func(i int, j int) int -// (i int, j int) -// (int) +// GoPy_Add wraps github.com/go-python/gopy-gen/_examples/hi.Add func GoPy_Add(i int, j int) int { return hi.Add(i, j) } +//export GoPy_Concat +// GoPy_Concat wraps github.com/go-python/gopy-gen/_examples/hi.Concat +func GoPy_Concat(s1 string, s2 string) string { + return hi.Concat(s1, s2) +} + + //export GoPy_Hello -// GoPy_Hello wraps hi.Hello -// github.com/go-python/gopy-gen/_examples/hi.Hello -// func(s string) -// (s string) -// () +// GoPy_Hello wraps github.com/go-python/gopy-gen/_examples/hi.Hello func GoPy_Hello(s string) { hi.Hello(s) } //export GoPy_Hi -// GoPy_Hi wraps hi.Hi -// github.com/go-python/gopy-gen/_examples/hi.Hi -// func() -// () -// () +// GoPy_Hi wraps github.com/go-python/gopy-gen/_examples/hi.Hi func GoPy_Hi() { hi.Hi() }