update swig on windows
This commit is contained in:
24
winx64/bin/swigwin-4.0.0/Examples/python/functor/Makefile
Normal file
24
winx64/bin/swigwin-4.0.0/Examples/python/functor/Makefile
Normal file
@@ -0,0 +1,24 @@
|
||||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS =
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
29
winx64/bin/swigwin-4.0.0/Examples/python/functor/example.i
Normal file
29
winx64/bin/swigwin-4.0.0/Examples/python/functor/example.i
Normal file
@@ -0,0 +1,29 @@
|
||||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
|
||||
%inline %{
|
||||
// From B. Strousjoup, "The C++ Programming Language, Third Edition", p. 514
|
||||
template<class T> class Sum {
|
||||
T res;
|
||||
public:
|
||||
Sum(T i = 0) : res(i) { }
|
||||
void operator() (T x) { res += x; }
|
||||
T result() const { return res; }
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
// Rename the application operator to __call__ for python.
|
||||
// Note: this is normally automatic, but if you had to do it yourself
|
||||
// you would use this directive:
|
||||
//
|
||||
// %rename(__call__) *::operator();
|
||||
|
||||
// Instantiate a few versions
|
||||
%template(intSum) Sum<int>;
|
||||
%template(doubleSum) Sum<double>;
|
||||
|
||||
|
||||
|
||||
|
||||
16
winx64/bin/swigwin-4.0.0/Examples/python/functor/runme.py
Normal file
16
winx64/bin/swigwin-4.0.0/Examples/python/functor/runme.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# Operator overloading example
|
||||
import example
|
||||
import math
|
||||
|
||||
a = example.intSum(0)
|
||||
b = example.doubleSum(100.0)
|
||||
|
||||
# Use the objects. They should be callable just like a normal
|
||||
# python function.
|
||||
|
||||
for i in range(0, 100):
|
||||
a(i) # Note: function call
|
||||
b(math.sqrt(i)) # Note: function call
|
||||
|
||||
print a.result()
|
||||
print b.result()
|
||||
Reference in New Issue
Block a user