New example
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@860 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
9b3c9e12d2
commit
3d800bf53c
6 changed files with 151 additions and 0 deletions
19
Examples/tcl/enum/Makefile
Normal file
19
Examples/tcl/enum/Makefile
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
TOP = ../..
|
||||||
|
SWIG = $(TOP)/../swig
|
||||||
|
CXXSRCS = example.cxx
|
||||||
|
TARGET = example
|
||||||
|
INTERFACE = example.i
|
||||||
|
LIBS = -lm
|
||||||
|
|
||||||
|
all::
|
||||||
|
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||||
|
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tcl_cpp
|
||||||
|
|
||||||
|
static::
|
||||||
|
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||||
|
TARGET='mytclsh' INTERFACE='$(INTERFACE)' tclsh_cpp_static
|
||||||
|
|
||||||
|
clean::
|
||||||
|
rm -f *_wrap* *.o *~ *.so mytclsh *.pyc .~* core
|
||||||
|
|
||||||
|
check: all
|
||||||
37
Examples/tcl/enum/example.cxx
Normal file
37
Examples/tcl/enum/example.cxx
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* File : example.c */
|
||||||
|
|
||||||
|
#include "example.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void Foo::enum_test(speed s) {
|
||||||
|
if (s == IMPULSE) {
|
||||||
|
printf("IMPULSE speed\n");
|
||||||
|
} else if (s == WARP) {
|
||||||
|
printf("WARP speed\n");
|
||||||
|
} else if (s == LUDICROUS) {
|
||||||
|
printf("LUDICROUS speed\n");
|
||||||
|
} else {
|
||||||
|
printf("Unknown speed\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void enum_test(color c, Foo::speed s) {
|
||||||
|
if (c == RED) {
|
||||||
|
printf("color = RED, ");
|
||||||
|
} else if (c == BLUE) {
|
||||||
|
printf("color = BLUE, ");
|
||||||
|
} else if (c == GREEN) {
|
||||||
|
printf("color = GREEN, ");
|
||||||
|
} else {
|
||||||
|
printf("color = Unknown color!, ");
|
||||||
|
}
|
||||||
|
if (s == Foo::IMPULSE) {
|
||||||
|
printf("speed = IMPULSE speed\n");
|
||||||
|
} else if (s == Foo::WARP) {
|
||||||
|
printf("speed = WARP speed\n");
|
||||||
|
} else if (s == Foo::LUDICROUS) {
|
||||||
|
printf("speed = LUDICROUS speed\n");
|
||||||
|
} else {
|
||||||
|
printf("speed = Unknown speed!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
13
Examples/tcl/enum/example.h
Normal file
13
Examples/tcl/enum/example.h
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
/* File : example.h */
|
||||||
|
|
||||||
|
enum color { RED, BLUE, GREEN };
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
public:
|
||||||
|
Foo() { }
|
||||||
|
enum speed { IMPULSE, WARP, LUDICROUS };
|
||||||
|
void enum_test(speed s);
|
||||||
|
};
|
||||||
|
|
||||||
|
void enum_test(color c, Foo::speed s);
|
||||||
|
|
||||||
11
Examples/tcl/enum/example.i
Normal file
11
Examples/tcl/enum/example.i
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
/* File : example.i */
|
||||||
|
%module example
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "example.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* Let's just grab the original header file here */
|
||||||
|
|
||||||
|
%include "example.h"
|
||||||
|
|
||||||
34
Examples/tcl/enum/example.tcl
Normal file
34
Examples/tcl/enum/example.tcl
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
# file: example.tcl
|
||||||
|
|
||||||
|
|
||||||
|
catch { load ./example.so example}
|
||||||
|
catch { load ./example.dll example} ;# Windows
|
||||||
|
|
||||||
|
# ----- Object creation -----
|
||||||
|
|
||||||
|
# Print out the value of some enums
|
||||||
|
puts "*** color ***"
|
||||||
|
puts " RED = $RED"
|
||||||
|
puts " BLUE = $BLUE"
|
||||||
|
puts " GREEN = $GREEN"
|
||||||
|
|
||||||
|
puts "\n*** Foo::speed ***"
|
||||||
|
puts " Foo_IMPULSE = $Foo_IMPULSE"
|
||||||
|
puts " Foo_WARP = $Foo_WARP"
|
||||||
|
puts " Foo_LUDICROUS = $Foo_LUDICROUS"
|
||||||
|
|
||||||
|
|
||||||
|
puts "\nTesting use of enums with functions\n"
|
||||||
|
|
||||||
|
enum_test $RED $Foo_IMPULSE
|
||||||
|
enum_test $BLUE $Foo_WARP
|
||||||
|
enum_test $GREEN $Foo_LUDICROUS
|
||||||
|
enum_test 1234 5678
|
||||||
|
|
||||||
|
puts "\nTesting use of enum with class method"
|
||||||
|
Foo f
|
||||||
|
|
||||||
|
f enum_test $Foo_IMPULSE
|
||||||
|
f enum_test $Foo_WARP
|
||||||
|
f enum_test $Foo_LUDICROUS
|
||||||
|
|
||||||
37
Examples/tcl/enum/index.html
Normal file
37
Examples/tcl/enum/index.html
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>SWIG:Examples:tcl:enum</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body bgcolor="#ffffff">
|
||||||
|
|
||||||
|
|
||||||
|
<tt>SWIG/Examples/tcl/enum/</tt>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<H2>Wrapping enumerations</H2>
|
||||||
|
|
||||||
|
<tt>$Header$</tt><br>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
This example tests SWIG's ability to wrap enumerations. By default, SWIG
|
||||||
|
converts enumeration specifications into integer constants. Further use
|
||||||
|
of enumerated types are handled as integers.
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><a href="example.h">example.h</a>. Header file containing some enums.
|
||||||
|
<li><a href="example.i">example.i</a>. Interface file.
|
||||||
|
<li><a href="example.tcl">example.tcl</a>. Sample Tcl script.
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>Notes</h2>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>SWIG allows arbitrary integers to be passed as enum values. However,
|
||||||
|
the result of passing an integer not corresponding to any of the values
|
||||||
|
specified in the <tt>enum</tt> specification is undefined.
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue