update swig on windows
This commit is contained in:
24
winx64/bin/swigwin-4.0.0/Examples/python/callback/Makefile
Normal file
24
winx64/bin/swigwin-4.0.0/Examples/python/callback/Makefile
Normal file
@@ -0,0 +1,24 @@
|
||||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS = example.cxx
|
||||
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)' $(SWIGLIB) 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)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
@@ -0,0 +1,4 @@
|
||||
/* File : example.cxx */
|
||||
|
||||
#include "example.h"
|
||||
|
||||
22
winx64/bin/swigwin-4.0.0/Examples/python/callback/example.h
Normal file
22
winx64/bin/swigwin-4.0.0/Examples/python/callback/example.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/* File : example.h */
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class Callback {
|
||||
public:
|
||||
virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; }
|
||||
virtual void run() { std::cout << "Callback::run()" << std::endl; }
|
||||
};
|
||||
|
||||
|
||||
class Caller {
|
||||
private:
|
||||
Callback *_callback;
|
||||
public:
|
||||
Caller(): _callback(0) {}
|
||||
~Caller() { delCallback(); }
|
||||
void delCallback() { delete _callback; _callback = 0; }
|
||||
void setCallback(Callback *cb) { delCallback(); _callback = cb; }
|
||||
void call() { if (_callback) _callback->run(); }
|
||||
};
|
||||
|
||||
11
winx64/bin/swigwin-4.0.0/Examples/python/callback/example.i
Normal file
11
winx64/bin/swigwin-4.0.0/Examples/python/callback/example.i
Normal file
@@ -0,0 +1,11 @@
|
||||
/* File : example.i */
|
||||
%module(directors="1") example
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
/* turn on director wrapping Callback */
|
||||
%feature("director") Callback;
|
||||
|
||||
%include "example.h"
|
||||
|
||||
19
winx64/bin/swigwin-4.0.0/Examples/python/callback/index.html
Normal file
19
winx64/bin/swigwin-4.0.0/Examples/python/callback/index.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>SWIG:Examples:python:callback</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
|
||||
|
||||
<tt>SWIG/Examples/python/extend/</tt>
|
||||
<hr>
|
||||
|
||||
<H2>Implementing C++ callbacks in Python</H2>
|
||||
|
||||
<p>
|
||||
This example illustrates how to use directors to implement C++ callbacks in Python.
|
||||
|
||||
<hr>
|
||||
</body>
|
||||
</html>
|
||||
57
winx64/bin/swigwin-4.0.0/Examples/python/callback/runme.py
Normal file
57
winx64/bin/swigwin-4.0.0/Examples/python/callback/runme.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# file: runme.py
|
||||
|
||||
# This file illustrates the cross language polymorphism using directors.
|
||||
|
||||
import example
|
||||
|
||||
|
||||
class PyCallback(example.Callback):
|
||||
|
||||
def __init__(self):
|
||||
example.Callback.__init__(self)
|
||||
|
||||
def run(self):
|
||||
print "PyCallback.run()"
|
||||
|
||||
# Create an Caller instance
|
||||
|
||||
caller = example.Caller()
|
||||
|
||||
# Add a simple C++ callback (caller owns the callback, so
|
||||
# we disown it first by clearing the .thisown flag).
|
||||
|
||||
print "Adding and calling a normal C++ callback"
|
||||
print "----------------------------------------"
|
||||
|
||||
callback = example.Callback()
|
||||
callback.thisown = 0
|
||||
caller.setCallback(callback)
|
||||
caller.call()
|
||||
caller.delCallback()
|
||||
|
||||
print
|
||||
print "Adding and calling a Python callback"
|
||||
print "------------------------------------"
|
||||
|
||||
# Add a Python callback (caller owns the callback, so we
|
||||
# disown it first by calling __disown__).
|
||||
|
||||
caller.setCallback(PyCallback().__disown__())
|
||||
caller.call()
|
||||
caller.delCallback()
|
||||
|
||||
print
|
||||
print "Adding and calling another Python callback"
|
||||
print "------------------------------------------"
|
||||
|
||||
# Let's do the same but use the weak reference this time.
|
||||
|
||||
callback = PyCallback().__disown__()
|
||||
caller.setCallback(callback)
|
||||
caller.call()
|
||||
caller.delCallback()
|
||||
|
||||
# All done.
|
||||
|
||||
print
|
||||
print "python exit"
|
||||
Reference in New Issue
Block a user