From ce02b53196adfdc6fdcc048df082d9ab8244ecc4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 15 Sep 2006 22:14:34 +0000 Subject: [PATCH] clearer example - patch #1524059 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9287 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Examples/java/native/example.i | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/SWIG/Examples/java/native/example.i b/SWIG/Examples/java/native/example.i index 65710f2bc..851b6fdc2 100644 --- a/SWIG/Examples/java/native/example.i +++ b/SWIG/Examples/java/native/example.i @@ -18,27 +18,29 @@ Point *point_create(int x, int y) { return p; } -/* this function will be wrapped by SWIG */ -char *point_toString1(Point *p) { +static char *point_toString(char *format, Point *p) { static char buf[80]; - sprintf(buf, "(%d,%d)", p->x, p->y); + sprintf(buf, format, p->x, p->y); return buf; } +/* this function will be wrapped by SWIG */ +char *point_toString1(Point *p) { + return point_toString("(%d,%d)", p); +} + /* this one we wrapped manually*/ JNIEXPORT jstring JNICALL Java_exampleJNI_point_1toString2(JNIEnv *jenv, jclass jcls, jlong jpoint) { Point * p; - char buf[80]; jstring result; (void)jcls; p = *(Point **)&jpoint; - sprintf(buf, "[%d,%d]", p->x, p->y); - result = (*jenv)->NewStringUTF(jenv, buf); + result = (*jenv)->NewStringUTF(jenv, point_toString("[%d,%d]", p)); return result; }