add the java example

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8183 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2006-01-02 11:43:32 +00:00
commit e484bb1721
6 changed files with 105 additions and 2 deletions

View file

@ -163,6 +163,7 @@ PERL5_INCLUDE= @PERL5EXT@
# Extra Perl specific dynamic linking options
PERL5_DLNK = @PERL5DYNAMICLINKING@
PERL5_CCFLAGS = @PERL5CCFLAGS@
PERL5_EXP = -Dexplicit=
# ----------------------------------------------------------------
# Build a Perl5 dynamically loadable module (C)
@ -179,7 +180,7 @@ perl5: $(SRCS)
perl5_cpp: $(SRCS)
$(SWIG) -perl5 -c++ $(SWIGOPT) $(INTERFACE)
$(CXX) -c $(CCSHARED) $(CFLAGS) -Dexplicit= $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PERL5_CCFLAGS) -I$(PERL5_INCLUDE)
$(CXX) -c $(CCSHARED) $(CFLAGS) $(PERL5_EXP) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PERL5_CCFLAGS) -I$(PERL5_INCLUDE)
$(CXXSHARED) $(OBJS) $(IOBJS) $(PERL5_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
# ----------------------------------------------------------------
@ -201,7 +202,7 @@ perl5_static: $(SRCS)
perl5_static_cpp: $(SRCS)
$(SWIG) -perl5 -c++ -static -lperlmain.i $(SWIGOPT) $(INTERFACE)
$(CXX) $(CFLAGS) -Dexplicit= $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET)
$(CXX) $(CFLAGS) $(PERL5_EXP) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET)
# -----------------------------------------------------------------
# Cleaning the Perl5 examples

View file

@ -12,3 +12,4 @@ reference
simple
value
variables
java

View file

@ -0,0 +1,29 @@
public class Example {
public int mPublicInt;
public Example() {
mPublicInt = 0;
}
public Example(int IntVal) {
mPublicInt = IntVal;
}
public int Add(int a, int b) {
return (a+b);
}
public float Add(float a, float b) {
return (a+b);
}
public String Add(String a, String b) {
return (a+b);
}
public Example Add(Example a, Example b) {
return new Example(a.mPublicInt + b.mPublicInt);
}
}

View file

@ -0,0 +1,28 @@
CXX = gcj
TOP = ../..
SWIG = $(TOP)/../preinst-swig
CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
all:: Example.class
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CXX="gcj" CFLAGS="-fPIC" \
CXXSHARED="gcj -fPIC -shared Example.class" PERL5_CCFLAGS='' PERL5_EXP='' perl5_cpp
clean::
$(MAKE) -f $(TOP)/Makefile perl5_clean
rm -f *.class Example.h
check: all
run:
perl runme.pl
Example.class: Example.java
gcj -v || exit 0
gcj -fPIC -C -c -g Example.java
gcjh Example

View file

@ -0,0 +1,18 @@
%module example
%{
#undef STATIC
%}
%include <gcj/cni.i>
%include <jstring.i>
%{
#undef TRUE
#define TRUE 1
%}
%{
#include "Example.h"
%}
%include Example.h

View file

@ -0,0 +1,26 @@
use example;
example::JvCreateJavaVM(undef);
example::JvAttachCurrentThread(undef, undef);
$e1 = new example::Example(1);
print $e1->{mPublicInt},"\n";
$e2 = new example::Example(2);
print $e2->{mPublicInt},"\n";
$i = $e1->Add(1,2);
print $i,"\n";
$d = $e2->Add(1.0,2.0);
print $d,"\n";
$d = $e2->Add("1","2");
print $d,"\n";
$e3 = $e1->Add($e1,$e2);
print $e3->{mPublicInt},"\n";
example::JvDetachCurrentThread()