Browse files

SWIG support: small changes so that the test file actually compiles u…

…nder SWIG. The result is still not usable, though.
  • Loading branch information...
1 parent 8985d8f commit a370ce5ba676c7ade8b7e940465623a26b48bee1 @eddyb eddyb committed Jul 16, 2012
Showing with 23 additions and 26 deletions.
  1. +16 −16 swigwriter.vala
  2. +4 −7 t/vala/Makefile
  3. +3 −3 t/vala/test.py
View
32 swigwriter.vala
@@ -14,7 +14,6 @@ public class SwigWriter : ValabindWriter {
string enums = "";
string vectors = "";
string ?ns_pfx;
- string nspace = "";
public SwigWriter (bool cxx_mode) {
this.cxx_mode = cxx_mode;
@@ -209,26 +208,26 @@ public class SwigWriter : ValabindWriter {
}
public override void visit_class (Class c) {
- classname = ns_pfx+c.name;
+ // FIXME does SWIG support actual namespaces?
+ classname = c.get_full_name ().replace (ns_pfx, "").replace (".", "");
classcname = CCodeBaseModule.get_ccode_name (c);
add_includes (c);
- if (context.profile == Profile.GOBJECT) {
- classname = "%s%s".printf (nspace, classname);
+ if (context.profile == Profile.GOBJECT)
extends += "typedef struct _%s {\n%%extend {\n".printf (classcname);
- } else extends += "%%extend %s {\n".printf (classname);
+ else extends += "%%extend %s {\n".printf (classname);
foreach (Enum e in c.get_enums ())
e.accept (this);
foreach (Field f in c.get_fields ())
f.accept (this);
- if (CCodeBaseModule.is_reference_counting (c)) {
- string? freefun = CCodeBaseModule.get_ccode_unref_function (c);
- if (freefun != null && freefun != "")
- extends += " ~%s%s() {\n %s (self);\n }\n".printf (modulename, classname, freefun);
- } else {
- string? freefun = CCodeBaseModule.get_ccode_free_function (c);
- if (freefun != null && freefun != "")
- extends += " ~%s%s() {\n %s (self);\n }\n".printf (modulename, classname, freefun);
- }
+
+ string? freefun = null;
+ if (CCodeBaseModule.is_reference_counting (c))
+ freefun = CCodeBaseModule.get_ccode_unref_function (c);
+ else
+ freefun = CCodeBaseModule.get_ccode_free_function (c);
+ if (freefun != null && freefun != "")
+ extends += " ~%s() {\n %s (self);\n }\n".printf (classname, freefun);
+
foreach (Method m in c.get_methods ())
m.accept (this);
foreach (Struct s in c.get_structs ())
@@ -424,8 +423,9 @@ public class SwigWriter : ValabindWriter {
stream.printf ("}\n#include <vector>\n");
}
stream.printf ("%%}\n");
- foreach (var inc in includefiles)
- stream.printf ("%%include <%s>\n", inc);
+ // FIXME this breaks because the included files are not SWIG files.
+ //foreach (var inc in includefiles)
+ // stream.printf ("%%include <%s>\n", inc);
if (cxx_mode) {
stream.printf ("%%include \"std_vector.i\"\n\n");
if (vectors != "")
View
11 t/vala/Makefile
@@ -1,27 +1,24 @@
VAPI=vstest.vapi
-SWIGCFLAGS=-I. `pkg-config --cflags --libs gobject-2.0` -I/usr/include -g
+SWIGCFLAGS=-I. `pkg-config --cflags --libs gobject-2.0` -I/usr/include
all:
valac -H vstest.h -C --vapi=${VAPI} --library=libvstest vstest.vala
${CC} -fPIC -shared vstest.c -o libvstest.so `pkg-config --cflags --libs gobject-2.0`
- LDFLAGS="-L. -lvstest" valabind-cc python vstest ${VAPI} ${SWIGCFLAGS} -x
+ LDFLAGS="-L. -lvstest" valabind-cc python vstest -NFood ${VAPI} ${SWIGCFLAGS} -x
cxx:
valac -H vstest.h -C --vapi=${VAPI} --library=libvstest vstest.vala
- LDFLAGS="-L. -lvstest" valabind-cc python vstest -X ${VAPI} ${SWIGCFLAGS}
+ LDFLAGS="-L. -lvstest" valabind-cc python vstest -NFood -X ${VAPI} ${SWIGCFLAGS}
# compile vstest.cxx as included in test.cxx
gcc -c vstest.c -I. `pkg-config gobject-2.0 --cflags --libs`
g++ vstest.o test.cxx -I. `pkg-config gobject-2.0 --cflags --libs`
#g++ test.cxx -I. `pkg-config gobject-2.0 --cflags --libs`
-v8:
- ../../valabind --gear -m vstest vstest.vapi
-
test:
LD_LIBRARY_PATH=. python test.py
foo:
- valabind-cc python vstest ${VAPI} -I. `pkg-config --cflags --libs gobject-2.0`
+ valabind-cc python vstest -NFood ${VAPI} -I. `pkg-config --cflags --libs gobject-2.0`
clean:
rm -f vstest.vapi vstest.h *.so vstest.cxx *.o *.i a.out vstest.c vstest.py* vstest_wrap.c
View
6 t/vala/test.py
@@ -1,12 +1,12 @@
import vstest
#import gobject
-a = vstest.FoodElement ()
+a = vstest.Element ()
a.say ("world")
print ("--")
a.say ("cruel world")
print ("--")
# Creating a 2nd element make it segfault
-#b=vstest.FoodElement ()
-#b.say ("salsa")
+b=vstest.Element ()
+b.say ("salsa")

0 comments on commit a370ce5

Please sign in to comment.