annotate lib/swig/swigwin-2.0.11/example_wrap.cxx @ 1983:5cd26f2c6904

small fix
author Ritor1
date Fri, 01 Nov 2013 17:29:49 +0600
parents b3009adc0e2f
children e78fa9082174
rev   line source
1899
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1 /* ----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2 * This file was automatically generated by SWIG (http://www.swig.org).
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
3 * Version 2.0.11
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
4 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
5 * This file is not intended to be easily readable and contains a number of
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
6 * coding conventions designed to improve portability and efficiency. Do not make
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
7 * changes to this file unless you know what you are doing--modify the SWIG
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
8 * interface file instead.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
9 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
10
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
11 #define SWIGLUA
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
12 #define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_LUA
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
13 #define SWIG_LUA_MODULE_GLOBAL
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
14
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
15
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
16 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
17 /* SwigValueWrapper is described in swig.swg */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
18 template<typename T> class SwigValueWrapper {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
19 struct SwigMovePointer {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
20 T *ptr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
21 SwigMovePointer(T *p) : ptr(p) { }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
22 ~SwigMovePointer() { delete ptr; }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
23 SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
24 } pointer;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
25 SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
26 SwigValueWrapper(const SwigValueWrapper<T>& rhs);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
27 public:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
28 SwigValueWrapper() : pointer(0) { }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
29 SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
30 operator T&() const { return *pointer.ptr; }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
31 T *operator&() { return pointer.ptr; }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
32 };
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
33
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
34 template <typename T> T SwigValueInit() {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
35 return T();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
36 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
37 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
38
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
39 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
40 * This section contains generic SWIG labels for method/variable
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
41 * declarations/attributes, and other compiler dependent labels.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
42 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
43
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
44 /* template workaround for compilers that cannot correctly implement the C++ standard */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
45 #ifndef SWIGTEMPLATEDISAMBIGUATOR
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
46 # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
47 # define SWIGTEMPLATEDISAMBIGUATOR template
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
48 # elif defined(__HP_aCC)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
49 /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
50 /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
51 # define SWIGTEMPLATEDISAMBIGUATOR template
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
52 # else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
53 # define SWIGTEMPLATEDISAMBIGUATOR
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
54 # endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
55 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
56
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
57 /* inline attribute */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
58 #ifndef SWIGINLINE
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
59 # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
60 # define SWIGINLINE inline
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
61 # else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
62 # define SWIGINLINE
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
63 # endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
64 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
65
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
66 /* attribute recognised by some compilers to avoid 'unused' warnings */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
67 #ifndef SWIGUNUSED
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
68 # if defined(__GNUC__)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
69 # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
70 # define SWIGUNUSED __attribute__ ((__unused__))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
71 # else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
72 # define SWIGUNUSED
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
73 # endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
74 # elif defined(__ICC)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
75 # define SWIGUNUSED __attribute__ ((__unused__))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
76 # else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
77 # define SWIGUNUSED
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
78 # endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
79 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
80
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
81 #ifndef SWIG_MSC_UNSUPPRESS_4505
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
82 # if defined(_MSC_VER)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
83 # pragma warning(disable : 4505) /* unreferenced local function has been removed */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
84 # endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
85 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
86
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
87 #ifndef SWIGUNUSEDPARM
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
88 # ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
89 # define SWIGUNUSEDPARM(p)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
90 # else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
91 # define SWIGUNUSEDPARM(p) p SWIGUNUSED
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
92 # endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
93 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
94
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
95 /* internal SWIG method */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
96 #ifndef SWIGINTERN
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
97 # define SWIGINTERN static SWIGUNUSED
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
98 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
99
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
100 /* internal inline SWIG method */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
101 #ifndef SWIGINTERNINLINE
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
102 # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
103 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
104
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
105 /* exporting methods */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
106 #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
107 # ifndef GCC_HASCLASSVISIBILITY
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
108 # define GCC_HASCLASSVISIBILITY
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
109 # endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
110 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
111
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
112 #ifndef SWIGEXPORT
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
113 # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
114 # if defined(STATIC_LINKED)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
115 # define SWIGEXPORT
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
116 # else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
117 # define SWIGEXPORT __declspec(dllexport)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
118 # endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
119 # else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
120 # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
121 # define SWIGEXPORT __attribute__ ((visibility("default")))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
122 # else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
123 # define SWIGEXPORT
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
124 # endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
125 # endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
126 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
127
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
128 /* calling conventions for Windows */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
129 #ifndef SWIGSTDCALL
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
130 # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
131 # define SWIGSTDCALL __stdcall
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
132 # else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
133 # define SWIGSTDCALL
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
134 # endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
135 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
136
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
137 /* Deal with Microsoft's attempt at deprecating C standard runtime functions */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
138 #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
139 # define _CRT_SECURE_NO_DEPRECATE
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
140 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
141
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
142 /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
143 #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
144 # define _SCL_SECURE_NO_DEPRECATE
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
145 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
146
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
147
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
148 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
149 * swigrun.swg
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
150 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
151 * This file contains generic C API SWIG runtime support for pointer
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
152 * type checking.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
153 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
154
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
155 /* This should only be incremented when either the layout of swig_type_info changes,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
156 or for whatever reason, the runtime changes incompatibly */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
157 #define SWIG_RUNTIME_VERSION "4"
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
158
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
159 /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
160 #ifdef SWIG_TYPE_TABLE
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
161 # define SWIG_QUOTE_STRING(x) #x
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
162 # define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
163 # define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
164 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
165 # define SWIG_TYPE_TABLE_NAME
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
166 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
167
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
168 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
169 You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
170 creating a static or dynamic library from the SWIG runtime code.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
171 In 99.9% of the cases, SWIG just needs to declare them as 'static'.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
172
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
173 But only do this if strictly necessary, ie, if you have problems
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
174 with your compiler or suchlike.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
175 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
176
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
177 #ifndef SWIGRUNTIME
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
178 # define SWIGRUNTIME SWIGINTERN
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
179 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
180
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
181 #ifndef SWIGRUNTIMEINLINE
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
182 # define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
183 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
184
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
185 /* Generic buffer size */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
186 #ifndef SWIG_BUFFER_SIZE
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
187 # define SWIG_BUFFER_SIZE 1024
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
188 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
189
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
190 /* Flags for pointer conversions */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
191 #define SWIG_POINTER_DISOWN 0x1
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
192 #define SWIG_CAST_NEW_MEMORY 0x2
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
193
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
194 /* Flags for new pointer objects */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
195 #define SWIG_POINTER_OWN 0x1
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
196
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
197
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
198 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
199 Flags/methods for returning states.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
200
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
201 The SWIG conversion methods, as ConvertPtr, return an integer
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
202 that tells if the conversion was successful or not. And if not,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
203 an error code can be returned (see swigerrors.swg for the codes).
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
204
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
205 Use the following macros/flags to set or process the returning
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
206 states.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
207
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
208 In old versions of SWIG, code such as the following was usually written:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
209
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
210 if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
211 // success code
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
212 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
213 //fail code
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
214 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
215
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
216 Now you can be more explicit:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
217
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
218 int res = SWIG_ConvertPtr(obj,vptr,ty.flags);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
219 if (SWIG_IsOK(res)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
220 // success code
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
221 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
222 // fail code
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
223 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
224
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
225 which is the same really, but now you can also do
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
226
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
227 Type *ptr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
228 int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
229 if (SWIG_IsOK(res)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
230 // success code
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
231 if (SWIG_IsNewObj(res) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
232 ...
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
233 delete *ptr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
234 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
235 ...
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
236 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
237 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
238 // fail code
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
239 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
240
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
241 I.e., now SWIG_ConvertPtr can return new objects and you can
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
242 identify the case and take care of the deallocation. Of course that
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
243 also requires SWIG_ConvertPtr to return new result values, such as
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
244
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
245 int SWIG_ConvertPtr(obj, ptr,...) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
246 if (<obj is ok>) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
247 if (<need new object>) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
248 *ptr = <ptr to new allocated object>;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
249 return SWIG_NEWOBJ;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
250 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
251 *ptr = <ptr to old object>;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
252 return SWIG_OLDOBJ;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
253 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
254 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
255 return SWIG_BADOBJ;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
256 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
257 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
258
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
259 Of course, returning the plain '0(success)/-1(fail)' still works, but you can be
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
260 more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
261 SWIG errors code.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
262
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
263 Finally, if the SWIG_CASTRANK_MODE is enabled, the result code
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
264 allows to return the 'cast rank', for example, if you have this
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
265
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
266 int food(double)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
267 int fooi(int);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
268
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
269 and you call
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
270
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
271 food(1) // cast rank '1' (1 -> 1.0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
272 fooi(1) // cast rank '0'
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
273
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
274 just use the SWIG_AddCast()/SWIG_CheckState()
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
275 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
276
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
277 #define SWIG_OK (0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
278 #define SWIG_ERROR (-1)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
279 #define SWIG_IsOK(r) (r >= 0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
280 #define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
281
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
282 /* The CastRankLimit says how many bits are used for the cast rank */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
283 #define SWIG_CASTRANKLIMIT (1 << 8)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
284 /* The NewMask denotes the object was created (using new/malloc) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
285 #define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
286 /* The TmpMask is for in/out typemaps that use temporal objects */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
287 #define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
288 /* Simple returning values */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
289 #define SWIG_BADOBJ (SWIG_ERROR)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
290 #define SWIG_OLDOBJ (SWIG_OK)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
291 #define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
292 #define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
293 /* Check, add and del mask methods */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
294 #define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
295 #define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
296 #define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
297 #define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
298 #define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
299 #define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
300
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
301 /* Cast-Rank Mode */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
302 #if defined(SWIG_CASTRANK_MODE)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
303 # ifndef SWIG_TypeRank
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
304 # define SWIG_TypeRank unsigned long
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
305 # endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
306 # ifndef SWIG_MAXCASTRANK /* Default cast allowed */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
307 # define SWIG_MAXCASTRANK (2)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
308 # endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
309 # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
310 # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
311 SWIGINTERNINLINE int SWIG_AddCast(int r) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
312 return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
313 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
314 SWIGINTERNINLINE int SWIG_CheckState(int r) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
315 return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
316 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
317 #else /* no cast-rank mode */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
318 # define SWIG_AddCast(r) (r)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
319 # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
320 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
321
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
322
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
323 #include <string.h>
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
324
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
325 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
326 extern "C" {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
327 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
328
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
329 typedef void *(*swig_converter_func)(void *, int *);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
330 typedef struct swig_type_info *(*swig_dycast_func)(void **);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
331
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
332 /* Structure to store information on one type */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
333 typedef struct swig_type_info {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
334 const char *name; /* mangled name of this type */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
335 const char *str; /* human readable name of this type */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
336 swig_dycast_func dcast; /* dynamic cast function down a hierarchy */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
337 struct swig_cast_info *cast; /* linked list of types that can cast into this type */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
338 void *clientdata; /* language specific type data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
339 int owndata; /* flag if the structure owns the clientdata */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
340 } swig_type_info;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
341
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
342 /* Structure to store a type and conversion function used for casting */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
343 typedef struct swig_cast_info {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
344 swig_type_info *type; /* pointer to type that is equivalent to this type */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
345 swig_converter_func converter; /* function to cast the void pointers */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
346 struct swig_cast_info *next; /* pointer to next cast in linked list */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
347 struct swig_cast_info *prev; /* pointer to the previous cast */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
348 } swig_cast_info;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
349
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
350 /* Structure used to store module information
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
351 * Each module generates one structure like this, and the runtime collects
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
352 * all of these structures and stores them in a circularly linked list.*/
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
353 typedef struct swig_module_info {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
354 swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
355 size_t size; /* Number of types in this module */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
356 struct swig_module_info *next; /* Pointer to next element in circularly linked list */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
357 swig_type_info **type_initial; /* Array of initially generated type structures */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
358 swig_cast_info **cast_initial; /* Array of initially generated casting structures */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
359 void *clientdata; /* Language specific module data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
360 } swig_module_info;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
361
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
362 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
363 Compare two type names skipping the space characters, therefore
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
364 "char*" == "char *" and "Class<int>" == "Class<int >", etc.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
365
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
366 Return 0 when the two name types are equivalent, as in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
367 strncmp, but skipping ' '.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
368 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
369 SWIGRUNTIME int
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
370 SWIG_TypeNameComp(const char *f1, const char *l1,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
371 const char *f2, const char *l2) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
372 for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
373 while ((*f1 == ' ') && (f1 != l1)) ++f1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
374 while ((*f2 == ' ') && (f2 != l2)) ++f2;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
375 if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
376 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
377 return (int)((l1 - f1) - (l2 - f2));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
378 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
379
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
380 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
381 Check type equivalence in a name list like <name1>|<name2>|...
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
382 Return 0 if equal, -1 if nb < tb, 1 if nb > tb
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
383 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
384 SWIGRUNTIME int
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
385 SWIG_TypeCmp(const char *nb, const char *tb) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
386 int equiv = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
387 const char* te = tb + strlen(tb);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
388 const char* ne = nb;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
389 while (equiv != 0 && *ne) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
390 for (nb = ne; *ne; ++ne) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
391 if (*ne == '|') break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
392 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
393 equiv = SWIG_TypeNameComp(nb, ne, tb, te);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
394 if (*ne) ++ne;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
395 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
396 return equiv;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
397 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
398
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
399 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
400 Check type equivalence in a name list like <name1>|<name2>|...
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
401 Return 0 if not equal, 1 if equal
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
402 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
403 SWIGRUNTIME int
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
404 SWIG_TypeEquiv(const char *nb, const char *tb) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
405 return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
406 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
407
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
408 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
409 Check the typename
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
410 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
411 SWIGRUNTIME swig_cast_info *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
412 SWIG_TypeCheck(const char *c, swig_type_info *ty) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
413 if (ty) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
414 swig_cast_info *iter = ty->cast;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
415 while (iter) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
416 if (strcmp(iter->type->name, c) == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
417 if (iter == ty->cast)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
418 return iter;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
419 /* Move iter to the top of the linked list */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
420 iter->prev->next = iter->next;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
421 if (iter->next)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
422 iter->next->prev = iter->prev;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
423 iter->next = ty->cast;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
424 iter->prev = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
425 if (ty->cast) ty->cast->prev = iter;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
426 ty->cast = iter;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
427 return iter;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
428 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
429 iter = iter->next;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
430 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
431 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
432 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
433 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
434
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
435 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
436 Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
437 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
438 SWIGRUNTIME swig_cast_info *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
439 SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
440 if (ty) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
441 swig_cast_info *iter = ty->cast;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
442 while (iter) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
443 if (iter->type == from) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
444 if (iter == ty->cast)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
445 return iter;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
446 /* Move iter to the top of the linked list */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
447 iter->prev->next = iter->next;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
448 if (iter->next)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
449 iter->next->prev = iter->prev;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
450 iter->next = ty->cast;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
451 iter->prev = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
452 if (ty->cast) ty->cast->prev = iter;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
453 ty->cast = iter;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
454 return iter;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
455 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
456 iter = iter->next;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
457 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
458 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
459 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
460 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
461
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
462 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
463 Cast a pointer up an inheritance hierarchy
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
464 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
465 SWIGRUNTIMEINLINE void *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
466 SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
467 return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
468 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
469
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
470 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
471 Dynamic pointer casting. Down an inheritance hierarchy
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
472 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
473 SWIGRUNTIME swig_type_info *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
474 SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
475 swig_type_info *lastty = ty;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
476 if (!ty || !ty->dcast) return ty;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
477 while (ty && (ty->dcast)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
478 ty = (*ty->dcast)(ptr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
479 if (ty) lastty = ty;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
480 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
481 return lastty;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
482 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
483
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
484 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
485 Return the name associated with this type
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
486 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
487 SWIGRUNTIMEINLINE const char *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
488 SWIG_TypeName(const swig_type_info *ty) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
489 return ty->name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
490 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
491
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
492 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
493 Return the pretty name associated with this type,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
494 that is an unmangled type name in a form presentable to the user.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
495 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
496 SWIGRUNTIME const char *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
497 SWIG_TypePrettyName(const swig_type_info *type) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
498 /* The "str" field contains the equivalent pretty names of the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
499 type, separated by vertical-bar characters. We choose
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
500 to print the last name, as it is often (?) the most
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
501 specific. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
502 if (!type) return NULL;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
503 if (type->str != NULL) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
504 const char *last_name = type->str;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
505 const char *s;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
506 for (s = type->str; *s; s++)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
507 if (*s == '|') last_name = s+1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
508 return last_name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
509 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
510 else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
511 return type->name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
512 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
513
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
514 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
515 Set the clientdata field for a type
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
516 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
517 SWIGRUNTIME void
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
518 SWIG_TypeClientData(swig_type_info *ti, void *clientdata) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
519 swig_cast_info *cast = ti->cast;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
520 /* if (ti->clientdata == clientdata) return; */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
521 ti->clientdata = clientdata;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
522
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
523 while (cast) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
524 if (!cast->converter) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
525 swig_type_info *tc = cast->type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
526 if (!tc->clientdata) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
527 SWIG_TypeClientData(tc, clientdata);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
528 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
529 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
530 cast = cast->next;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
531 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
532 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
533 SWIGRUNTIME void
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
534 SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
535 SWIG_TypeClientData(ti, clientdata);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
536 ti->owndata = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
537 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
538
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
539 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
540 Search for a swig_type_info structure only by mangled name
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
541 Search is a O(log #types)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
542
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
543 We start searching at module start, and finish searching when start == end.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
544 Note: if start == end at the beginning of the function, we go all the way around
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
545 the circular list.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
546 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
547 SWIGRUNTIME swig_type_info *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
548 SWIG_MangledTypeQueryModule(swig_module_info *start,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
549 swig_module_info *end,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
550 const char *name) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
551 swig_module_info *iter = start;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
552 do {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
553 if (iter->size) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
554 register size_t l = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
555 register size_t r = iter->size - 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
556 do {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
557 /* since l+r >= 0, we can (>> 1) instead (/ 2) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
558 register size_t i = (l + r) >> 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
559 const char *iname = iter->types[i]->name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
560 if (iname) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
561 register int compare = strcmp(name, iname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
562 if (compare == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
563 return iter->types[i];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
564 } else if (compare < 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
565 if (i) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
566 r = i - 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
567 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
568 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
569 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
570 } else if (compare > 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
571 l = i + 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
572 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
573 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
574 break; /* should never happen */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
575 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
576 } while (l <= r);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
577 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
578 iter = iter->next;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
579 } while (iter != end);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
580 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
581 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
582
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
583 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
584 Search for a swig_type_info structure for either a mangled name or a human readable name.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
585 It first searches the mangled names of the types, which is a O(log #types)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
586 If a type is not found it then searches the human readable names, which is O(#types).
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
587
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
588 We start searching at module start, and finish searching when start == end.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
589 Note: if start == end at the beginning of the function, we go all the way around
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
590 the circular list.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
591 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
592 SWIGRUNTIME swig_type_info *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
593 SWIG_TypeQueryModule(swig_module_info *start,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
594 swig_module_info *end,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
595 const char *name) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
596 /* STEP 1: Search the name field using binary search */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
597 swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
598 if (ret) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
599 return ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
600 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
601 /* STEP 2: If the type hasn't been found, do a complete search
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
602 of the str field (the human readable name) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
603 swig_module_info *iter = start;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
604 do {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
605 register size_t i = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
606 for (; i < iter->size; ++i) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
607 if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name)))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
608 return iter->types[i];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
609 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
610 iter = iter->next;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
611 } while (iter != end);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
612 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
613
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
614 /* neither found a match */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
615 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
616 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
617
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
618 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
619 Pack binary data into a string
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
620 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
621 SWIGRUNTIME char *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
622 SWIG_PackData(char *c, void *ptr, size_t sz) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
623 static const char hex[17] = "0123456789abcdef";
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
624 register const unsigned char *u = (unsigned char *) ptr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
625 register const unsigned char *eu = u + sz;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
626 for (; u != eu; ++u) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
627 register unsigned char uu = *u;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
628 *(c++) = hex[(uu & 0xf0) >> 4];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
629 *(c++) = hex[uu & 0xf];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
630 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
631 return c;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
632 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
633
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
634 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
635 Unpack binary data from a string
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
636 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
637 SWIGRUNTIME const char *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
638 SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
639 register unsigned char *u = (unsigned char *) ptr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
640 register const unsigned char *eu = u + sz;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
641 for (; u != eu; ++u) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
642 register char d = *(c++);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
643 register unsigned char uu;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
644 if ((d >= '0') && (d <= '9'))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
645 uu = ((d - '0') << 4);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
646 else if ((d >= 'a') && (d <= 'f'))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
647 uu = ((d - ('a'-10)) << 4);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
648 else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
649 return (char *) 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
650 d = *(c++);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
651 if ((d >= '0') && (d <= '9'))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
652 uu |= (d - '0');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
653 else if ((d >= 'a') && (d <= 'f'))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
654 uu |= (d - ('a'-10));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
655 else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
656 return (char *) 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
657 *u = uu;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
658 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
659 return c;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
660 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
661
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
662 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
663 Pack 'void *' into a string buffer.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
664 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
665 SWIGRUNTIME char *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
666 SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
667 char *r = buff;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
668 if ((2*sizeof(void *) + 2) > bsz) return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
669 *(r++) = '_';
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
670 r = SWIG_PackData(r,&ptr,sizeof(void *));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
671 if (strlen(name) + 1 > (bsz - (r - buff))) return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
672 strcpy(r,name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
673 return buff;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
674 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
675
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
676 SWIGRUNTIME const char *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
677 SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
678 if (*c != '_') {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
679 if (strcmp(c,"NULL") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
680 *ptr = (void *) 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
681 return name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
682 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
683 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
684 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
685 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
686 return SWIG_UnpackData(++c,ptr,sizeof(void *));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
687 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
688
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
689 SWIGRUNTIME char *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
690 SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
691 char *r = buff;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
692 size_t lname = (name ? strlen(name) : 0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
693 if ((2*sz + 2 + lname) > bsz) return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
694 *(r++) = '_';
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
695 r = SWIG_PackData(r,ptr,sz);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
696 if (lname) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
697 strncpy(r,name,lname+1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
698 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
699 *r = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
700 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
701 return buff;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
702 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
703
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
704 SWIGRUNTIME const char *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
705 SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
706 if (*c != '_') {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
707 if (strcmp(c,"NULL") == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
708 memset(ptr,0,sz);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
709 return name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
710 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
711 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
712 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
713 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
714 return SWIG_UnpackData(++c,ptr,sz);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
715 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
716
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
717 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
718 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
719 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
720
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
721 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
722 * luarun.swg
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
723 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
724 * This file contains the runtime support for Lua modules
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
725 * and includes code for managing global variables and pointer
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
726 * type checking.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
727 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
728
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
729 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
730 extern "C" {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
731 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
732
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
733 #include "lua.h"
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
734 #include "lauxlib.h"
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
735 #include <stdlib.h> /* for malloc */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
736 #include <assert.h> /* for a few sanity tests */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
737
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
738 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
739 * Lua flavors
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
740 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
741
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
742 #define SWIG_LUA_FLAVOR_LUA 1
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
743 #define SWIG_LUA_FLAVOR_ELUA 2
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
744 #define SWIG_LUA_FLAVOR_ELUAC 3
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
745
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
746 #if !defined(SWIG_LUA_TARGET)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
747 # error SWIG_LUA_TARGET not defined
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
748 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
749
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
750 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
751 # define SWIG_LUA_CONSTTAB_INT(B, C) LSTRKEY(B), LNUMVAL(C)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
752 # define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
753 # define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
754 # define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
755 #else /* SWIG_LUA_FLAVOR_LUA */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
756 # define SWIG_LUA_CONSTTAB_INT(B, C) SWIG_LUA_INT, (char *)B, (long)C, 0, 0, 0
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
757 # define SWIG_LUA_CONSTTAB_FLOAT(B, C) SWIG_LUA_FLOAT, (char *)B, 0, (double)C, 0, 0
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
758 # define SWIG_LUA_CONSTTAB_STRING(B, C) SWIG_LUA_STRING, (char *)B, 0, 0, (void *)C, 0
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
759 # define SWIG_LUA_CONSTTAB_CHAR(B, C) SWIG_LUA_CHAR, (char *)B, (long)C, 0, 0, 0
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
760 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
761
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
762 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
763 # define LRO_STRVAL(v) {{.p = (char *) v}, LUA_TSTRING}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
764 # define LSTRVAL LRO_STRVAL
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
765 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
766
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
767 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
768 * compatibility defines
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
769 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
770
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
771 /* History of Lua C API length functions: In Lua 5.0 (and before?)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
772 there was "lua_strlen". In Lua 5.1, this was renamed "lua_objlen",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
773 but a compatibility define of "lua_strlen" was added. In Lua 5.2,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
774 this function was again renamed, to "lua_rawlen" (to emphasize that
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
775 it doesn't call the "__len" metamethod), and the compatibility
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
776 define of lua_strlen was removed. All SWIG uses have been updated
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
777 to "lua_rawlen", and we add our own defines of that here for older
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
778 versions of Lua. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
779 #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
780 # define lua_rawlen lua_strlen
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
781 #elif LUA_VERSION_NUM == 501
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
782 # define lua_rawlen lua_objlen
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
783 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
784
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
785
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
786 /* lua_pushglobaltable is the recommended "future-proof" way to get
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
787 the global table for Lua 5.2 and later. Here we define
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
788 lua_pushglobaltable ourselves for Lua versions before 5.2. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
789 #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
790 # define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
791 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
792
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
793
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
794 /* --------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
795 * Helper functions for error handling
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
796 * -------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
797
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
798 /* Push the string STR on the Lua stack, like lua_pushstring, but
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
799 prefixed with the the location of the innermost Lua call-point
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
800 (as formated by luaL_where). */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
801 SWIGRUNTIME void
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
802 SWIG_Lua_pusherrstring (lua_State *L, const char *str)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
803 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
804 luaL_where (L, 1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
805 lua_pushstring (L, str);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
806 lua_concat (L, 2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
807 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
808
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
809 /* Push a formatted string generated from FMT and following args on
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
810 the Lua stack, like lua_pushfstring, but prefixed with the the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
811 location of the innermost Lua call-point (as formated by luaL_where). */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
812 SWIGRUNTIME void
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
813 SWIG_Lua_pushferrstring (lua_State *L, const char *fmt, ...)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
814 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
815 va_list argp;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
816 va_start(argp, fmt);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
817 luaL_where(L, 1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
818 lua_pushvfstring(L, fmt, argp);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
819 va_end(argp);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
820 lua_concat(L, 2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
821 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
822
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
823
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
824 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
825 * global swig types
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
826 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
827 /* Constant table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
828 #define SWIG_LUA_INT 1
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
829 #define SWIG_LUA_FLOAT 2
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
830 #define SWIG_LUA_STRING 3
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
831 #define SWIG_LUA_POINTER 4
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
832 #define SWIG_LUA_BINARY 5
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
833 #define SWIG_LUA_CHAR 6
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
834
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
835 /* Structure for variable linking table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
836 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
837 const char *name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
838 lua_CFunction get;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
839 lua_CFunction set;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
840 } swig_lua_var_info;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
841
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
842 /* Constant information structure */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
843 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
844 int type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
845 char *name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
846 long lvalue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
847 double dvalue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
848 void *pvalue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
849 swig_type_info **ptype;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
850 } swig_lua_const_info;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
851
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
852 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
853 const char *name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
854 lua_CFunction method;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
855 } swig_lua_method;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
856
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
857 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
858 const char *name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
859 lua_CFunction getmethod;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
860 lua_CFunction setmethod;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
861 } swig_lua_attribute;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
862
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
863 // Can be used to create namespaces. Currently used to
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
864 // wrap class static methods/variables/constants
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
865 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
866 const char *name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
867 swig_lua_method *ns_methods;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
868 swig_lua_attribute *ns_attributes;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
869 swig_lua_const_info *ns_constants;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
870 } swig_lua_namespace;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
871
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
872 typedef struct swig_lua_class {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
873 const char *name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
874 swig_type_info **type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
875 lua_CFunction constructor;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
876 void (*destructor)(void *);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
877 swig_lua_method *methods;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
878 swig_lua_attribute *attributes;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
879 swig_lua_namespace cls_static;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
880 struct swig_lua_class **bases;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
881 const char **base_names;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
882 } swig_lua_class;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
883
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
884 /* this is the struct for wrapping all pointers in SwigLua
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
885 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
886 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
887 swig_type_info *type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
888 int own; /* 1 if owned & must be destroyed */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
889 void *ptr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
890 } swig_lua_userdata;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
891
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
892 /* this is the struct for wrapping arbitrary packed binary data
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
893 (currently it is only used for member function pointers)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
894 the data ordering is similar to swig_lua_userdata, but it is currently not possible
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
895 to tell the two structures apart within SWIG, other than by looking at the type
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
896 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
897 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
898 swig_type_info *type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
899 int own; /* 1 if owned & must be destroyed */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
900 char data[1]; /* arbitary amount of data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
901 } swig_lua_rawdata;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
902
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
903 /* Common SWIG API */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
904 #define SWIG_NewPointerObj(L, ptr, type, owner) SWIG_Lua_NewPointerObj(L, (void *)ptr, type, owner)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
905 #define SWIG_ConvertPtr(L,idx, ptr, type, flags) SWIG_Lua_ConvertPtr(L,idx,ptr,type,flags)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
906 #define SWIG_MustGetPtr(L,idx, type,flags, argnum,fnname) SWIG_Lua_MustGetPtr(L,idx, type,flags, argnum,fnname)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
907 /* for C++ member pointers, ie, member methods */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
908 #define SWIG_ConvertMember(L, idx, ptr, sz, ty) SWIG_Lua_ConvertPacked(L, idx, ptr, sz, ty)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
909 #define SWIG_NewMemberObj(L, ptr, sz, type) SWIG_Lua_NewPackedObj(L, ptr, sz, type)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
910
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
911 /* Runtime API */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
912 #define SWIG_GetModule(clientdata) SWIG_Lua_GetModule((lua_State*)(clientdata))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
913 #define SWIG_SetModule(clientdata, pointer) SWIG_Lua_SetModule((lua_State*) (clientdata), pointer)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
914 #define SWIG_MODULE_CLIENTDATA_TYPE lua_State*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
915
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
916 /* Contract support */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
917 #define SWIG_contract_assert(expr, msg) \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
918 if (!(expr)) { SWIG_Lua_pusherrstring(L, (char *) msg); goto fail; } else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
919
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
920
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
921 /* helper #defines */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
922 #define SWIG_fail {goto fail;}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
923 #define SWIG_fail_arg(func_name,argnum,type) \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
924 {SWIG_Lua_pushferrstring(L,"Error in %s (arg %d), expected '%s' got '%s'",\
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
925 func_name,argnum,type,SWIG_Lua_typename(L,argnum));\
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
926 goto fail;}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
927 #define SWIG_fail_ptr(func_name,argnum,type) \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
928 SWIG_fail_arg(func_name,argnum,(type && type->str)?type->str:"void*")
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
929 #define SWIG_check_num_args(func_name,a,b) \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
930 if (lua_gettop(L)<a || lua_gettop(L)>b) \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
931 {SWIG_Lua_pushferrstring(L,"Error in %s expected %d..%d args, got %d",func_name,a,b,lua_gettop(L));\
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
932 goto fail;}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
933
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
934
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
935 #define SWIG_Lua_get_table(L,n) \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
936 (lua_pushstring(L, n), lua_rawget(L,-2))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
937
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
938 #define SWIG_Lua_add_function(L,n,f) \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
939 (lua_pushstring(L, n), \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
940 lua_pushcfunction(L, f), \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
941 lua_rawset(L,-3))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
942
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
943 /* special helper for allowing 'nil' for usertypes */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
944 #define SWIG_isptrtype(L,I) (lua_isuserdata(L,I) || lua_isnil(L,I))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
945
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
946 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
947 /* Special helper for member function pointers
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
948 it gets the address, casts it, then dereferences it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
949 //#define SWIG_mem_fn_as_voidptr(a) (*((char**)&(a)))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
950 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
951
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
952 /* storing/access of swig_module_info */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
953 SWIGRUNTIME swig_module_info *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
954 SWIG_Lua_GetModule(lua_State* L) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
955 swig_module_info *ret = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
956 lua_pushstring(L,"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
957 lua_rawget(L,LUA_REGISTRYINDEX);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
958 if (lua_islightuserdata(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
959 ret=(swig_module_info*)lua_touserdata(L,-1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
960 lua_pop(L,1); /* tidy */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
961 return ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
962 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
963
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
964 SWIGRUNTIME void
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
965 SWIG_Lua_SetModule(lua_State* L, swig_module_info *module) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
966 /* add this all into the Lua registry: */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
967 lua_pushstring(L,"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
968 lua_pushlightuserdata(L,(void*)module);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
969 lua_rawset(L,LUA_REGISTRYINDEX);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
970 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
971
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
972 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
973 * global variable support code: modules
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
974 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
975
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
976 /* this function is called when trying to set an immutable.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
977 default action is to print an error.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
978 This can removed with a compile flag SWIGLUA_IGNORE_SET_IMMUTABLE */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
979 SWIGINTERN int SWIG_Lua_set_immutable(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
980 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
981 /* there should be 1 param passed in: the new value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
982 #ifndef SWIGLUA_IGNORE_SET_IMMUTABLE
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
983 lua_pop(L,1); /* remove it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
984 luaL_error(L,"This variable is immutable");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
985 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
986 return 0; /* should not return anything */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
987 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
988
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
989 /* the module.get method used for getting linked data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
990 SWIGINTERN int SWIG_Lua_module_get(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
991 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
992 /* there should be 2 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
993 (1) table (not the meta table)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
994 (2) string name of the attribute
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
995 printf("SWIG_Lua_module_get %p(%s) '%s'\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
996 lua_topointer(L,1),lua_typename(L,lua_type(L,1)),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
997 lua_tostring(L,2));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
998 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
999 /* get the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1000 #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1001 assert(lua_isrotable(L,1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1002 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1003 assert(lua_istable(L,1)); /* default Lua action */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1004 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1005 lua_getmetatable(L,1); /* get the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1006 #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1007 assert(lua_isrotable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1008 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1009 assert(lua_istable(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1010 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1011 SWIG_Lua_get_table(L,".get"); /* get the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1012 lua_remove(L,3); /* remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1013 #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1014 if (lua_isrotable(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1015 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1016 if (lua_istable(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1017 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1018 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1019 /* look for the key in the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1020 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1021 lua_rawget(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1022 lua_remove(L,3); /* remove .get */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1023 if (lua_iscfunction(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1024 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1025 lua_call(L,0,1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1026 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1027 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1028 lua_pop(L,1); /* remove the top */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1029 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1030 lua_pop(L,1); /* remove the .get */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1031 lua_pushnil(L); /* return a nil */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1032 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1033 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1034
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1035 /* the module.set method used for setting linked data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1036 SWIGINTERN int SWIG_Lua_module_set(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1037 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1038 /* there should be 3 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1039 (1) table (not the meta table)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1040 (2) string name of the attribute
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1041 (3) any for the new value
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1042 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1043 /* get the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1044 #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1045 assert(lua_isrotable(L,1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1046 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1047 assert(lua_istable(L,1)); /* default Lua action */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1048 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1049 lua_getmetatable(L,1); /* get the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1050 #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1051 assert(lua_isrotable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1052 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1053 assert(lua_istable(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1054 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1055 SWIG_Lua_get_table(L,".set"); /* get the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1056 lua_remove(L,4); /* remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1057 #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1058 if (lua_isrotable(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1059 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1060 if (lua_istable(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1061 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1062 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1063 /* look for the key in the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1064 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1065 lua_rawget(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1066 lua_remove(L,4); /* remove .set */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1067 if (lua_iscfunction(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1068 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1069 lua_pushvalue(L,3); /* value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1070 lua_call(L,1,0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1071 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1072 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1073 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1074 else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1075 return 0; // Exits stoically if an invalid key is initialized.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1076 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1077 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1078 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1079 lua_settop(L,3); /* reset back to start */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1080 /* we now have the table, key & new value, so just set directly */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1081 lua_rawset(L,1); /* add direct */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1082 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1083 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1084
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1085 #if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1086 /* registering a module in lua. Pushes the module table on the stack. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1087 SWIGINTERN void SWIG_Lua_module_begin(lua_State* L,const char* name)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1088 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1089 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1090 lua_pushstring(L,name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1091 lua_newtable(L); /* the table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1092 /* add meta table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1093 lua_newtable(L); /* the meta table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1094 SWIG_Lua_add_function(L,"__index",SWIG_Lua_module_get);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1095 SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_module_set);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1096 lua_pushstring(L,".get");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1097 lua_newtable(L); /* the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1098 lua_rawset(L,-3); /* add .get into metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1099 lua_pushstring(L,".set");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1100 lua_newtable(L); /* the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1101 lua_rawset(L,-3); /* add .set into metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1102 lua_setmetatable(L,-2); /* sets meta table in module */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1103 #ifdef SWIG_LUA_MODULE_GLOBAL
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1104 /* If requested, install the module directly into the global namespace. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1105 lua_rawset(L,-3); /* add module into parent */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1106 SWIG_Lua_get_table(L,name); /* get the table back out */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1107 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1108 /* Do not install the module table as global name. The stack top has
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1109 the module table with the name below. We pop the top and replace
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1110 the name with it. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1111 lua_replace(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1112 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1113 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1114
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1115 /* ending the register */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1116 SWIGINTERN void SWIG_Lua_module_end(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1117 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1118 lua_pop(L,1); /* tidy stack (remove module) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1119 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1120
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1121 /* adding a linked variable to the module */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1122 SWIGINTERN void SWIG_Lua_module_add_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1123 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1124 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1125 lua_getmetatable(L,-1); /* get the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1126 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1127 SWIG_Lua_get_table(L,".get"); /* find the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1128 assert(lua_istable(L,-1)); /* should be a table: */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1129 SWIG_Lua_add_function(L,name,getFn);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1130 lua_pop(L,1); /* tidy stack (remove table) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1131 if (setFn) /* if there is a set fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1132 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1133 SWIG_Lua_get_table(L,".set"); /* find the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1134 assert(lua_istable(L,-1)); /* should be a table: */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1135 SWIG_Lua_add_function(L,name,setFn);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1136 lua_pop(L,1); /* tidy stack (remove table) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1137 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1138 lua_pop(L,1); /* tidy stack (remove meta) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1139 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1140 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1141
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1142 /* adding a function module */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1143 SWIGINTERN void SWIG_Lua_module_add_function(lua_State* L,const char* name,lua_CFunction fn)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1144 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1145 SWIG_Lua_add_function(L,name,fn);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1146 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1147
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1148 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1149 * global variable support code: namespaces
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1150 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1151
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1152 SWIGINTERN int SWIG_Lua_namespace_get(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1153 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1154 /* there should be 2 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1155 (1) table (not the meta table)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1156 (2) string name of the attribute
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1157 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1158 assert(lua_istable(L,-2)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1159 lua_getmetatable(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1160 assert(lua_istable(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1161 SWIG_Lua_get_table(L,".get"); /* find the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1162 assert(lua_istable(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1163 /* look for the key in the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1164 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1165 lua_rawget(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1166 lua_remove(L,-2); /* stack tidy, remove .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1167 if (lua_iscfunction(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1168 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1169 lua_call(L,0,1); /* 1 value in (userdata),1 out (result) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1170 lua_remove(L,-2); /* stack tidy, remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1171 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1172 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1173 lua_pop(L,1); /* remove whatever was there */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1174 /* ok, so try the .fn table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1175 SWIG_Lua_get_table(L,".fn"); /* find the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1176 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1177 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1178 lua_rawget(L,-2); /* look for the fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1179 lua_remove(L,-2); /* stack tidy, remove .fn table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1180 if (lua_isfunction(L,-1)) /* note: whether it's a C function or lua function */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1181 { /* found it so return the fn & let lua call it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1182 lua_remove(L,-2); /* stack tidy, remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1183 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1184 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1185 lua_pop(L,1); /* remove whatever was there */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1186 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1187 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1188
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1189 SWIGINTERN int SWIG_Lua_namespace_set(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1190 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1191 /* there should be 3 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1192 (1) table (not the meta table)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1193 (2) string name of the attribute
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1194 (3) any for the new value
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1195 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1196
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1197 assert(lua_istable(L,1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1198 lua_getmetatable(L,1); /* get the meta table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1199 assert(lua_istable(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1200
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1201 SWIG_Lua_get_table(L,".set"); /* find the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1202 if (lua_istable(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1203 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1204 /* look for the key in the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1205 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1206 lua_rawget(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1207 if (lua_iscfunction(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1208 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1209 lua_pushvalue(L,3); /* value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1210 lua_call(L,1,0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1211 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1212 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1213 lua_pop(L,1); /* remove the value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1214 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1215 lua_pop(L,1); /* remove the value .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1216 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1217 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1218
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1219 SWIGINTERN void SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]); // forward declaration
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1220 SWIGINTERN void SWIG_Lua_add_class_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn); // forward declaration
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1221
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1222 /* helper function - register namespace methods and attributes into namespace */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1223 SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* ns)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1224 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1225 int i = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1226 assert(lua_istable(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1227 /* There must be table at the top of the stack */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1228 SWIG_Lua_InstallConstants(L, ns->ns_constants);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1229
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1230 lua_getmetatable(L,-1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1231
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1232 /* add fns */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1233 for(i=0;ns->ns_attributes[i].name;i++){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1234 SWIG_Lua_add_class_variable(L,ns->ns_attributes[i].name,ns->ns_attributes[i].getmethod,ns->ns_attributes[i].setmethod);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1235 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1236
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1237 /* add methods to the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1238 SWIG_Lua_get_table(L,".fn"); /* find the .fn table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1239 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1240 for(i=0;ns->ns_methods[i].name;i++){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1241 SWIG_Lua_add_function(L,ns->ns_methods[i].name,ns->ns_methods[i].method);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1242 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1243 lua_pop(L,1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1244
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1245 /* clear stack - remove metatble */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1246 lua_pop(L,1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1247
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1248 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1249
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1250 /* helper function. creates namespace table and add it to module table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1251 SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1252 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1253 assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1254 lua_checkstack(L,5);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1255 lua_pushstring(L, ns->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1256 lua_newtable(L); /* namespace itself */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1257 lua_newtable(L); /* metatable for namespace */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1258
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1259 /* add a table called ".get" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1260 lua_pushstring(L,".get");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1261 lua_newtable(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1262 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1263 /* add a table called ".set" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1264 lua_pushstring(L,".set");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1265 lua_newtable(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1266 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1267 /* add a table called ".fn" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1268 lua_pushstring(L,".fn");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1269 lua_newtable(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1270 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1271
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1272 /* add accessor fns for using the .get,.set&.fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1273 SWIG_Lua_add_function(L,"__index",SWIG_Lua_namespace_get);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1274 SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_namespace_set);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1275
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1276 lua_setmetatable(L,-2); /* set metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1277 lua_rawset(L,-3); /* add namespace to module table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1278 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1279 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1280 * global variable support code: classes
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1281 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1282
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1283 /* the class.get method, performs the lookup of class attributes */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1284 SWIGINTERN int SWIG_Lua_class_get(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1285 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1286 /* there should be 2 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1287 (1) userdata (not the meta table)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1288 (2) string name of the attribute
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1289 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1290 assert(lua_isuserdata(L,-2)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1291 lua_getmetatable(L,-2); /* get the meta table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1292 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1293 SWIG_Lua_get_table(L,".get"); /* find the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1294 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1295 /* look for the key in the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1296 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1297 lua_rawget(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1298 lua_remove(L,-2); /* stack tidy, remove .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1299 if (lua_iscfunction(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1300 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1301 lua_pushvalue(L,1); /* the userdata */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1302 lua_call(L,1,1); /* 1 value in (userdata),1 out (result) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1303 lua_remove(L,-2); /* stack tidy, remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1304 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1305 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1306 lua_pop(L,1); /* remove whatever was there */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1307 /* ok, so try the .fn table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1308 SWIG_Lua_get_table(L,".fn"); /* find the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1309 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1310 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1311 lua_rawget(L,-2); /* look for the fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1312 lua_remove(L,-2); /* stack tidy, remove .fn table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1313 if (lua_isfunction(L,-1)) /* note: if its a C function or lua function */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1314 { /* found it so return the fn & let lua call it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1315 lua_remove(L,-2); /* stack tidy, remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1316 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1317 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1318 lua_pop(L,1); /* remove whatever was there */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1319 /* NEW: looks for the __getitem() fn
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1320 this is a user provided get fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1321 SWIG_Lua_get_table(L,"__getitem"); /* find the __getitem fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1322 if (lua_iscfunction(L,-1)) /* if its there */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1323 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1324 lua_pushvalue(L,1); /* the userdata */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1325 lua_pushvalue(L,2); /* the parameter */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1326 lua_call(L,2,1); /* 2 value in (userdata),1 out (result) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1327 lua_remove(L,-2); /* stack tidy, remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1328 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1329 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1330 return 0; /* sorry not known */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1331 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1332
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1333 /* the class.set method, performs the lookup of class attributes */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1334 SWIGINTERN int SWIG_Lua_class_set(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1335 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1336 /* there should be 3 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1337 (1) table (not the meta table)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1338 (2) string name of the attribute
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1339 (3) any for the new value
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1340 printf("SWIG_Lua_class_set %p(%s) '%s' %p(%s)\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1341 lua_topointer(L,1),lua_typename(L,lua_type(L,1)),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1342 lua_tostring(L,2),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1343 lua_topointer(L,3),lua_typename(L,lua_type(L,3)));*/
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1344
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1345 assert(lua_isuserdata(L,1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1346 lua_getmetatable(L,1); /* get the meta table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1347 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1348
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1349 SWIG_Lua_get_table(L,".set"); /* find the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1350 if (lua_istable(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1351 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1352 /* look for the key in the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1353 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1354 lua_rawget(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1355 if (lua_iscfunction(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1356 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1357 lua_pushvalue(L,1); /* userdata */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1358 lua_pushvalue(L,3); /* value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1359 lua_call(L,2,0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1360 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1361 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1362 lua_pop(L,1); /* remove the value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1363 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1364 lua_pop(L,1); /* remove the value .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1365 /* NEW: looks for the __setitem() fn
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1366 this is a user provided set fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1367 SWIG_Lua_get_table(L,"__setitem"); /* find the fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1368 if (lua_iscfunction(L,-1)) /* if its there */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1369 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1370 lua_pushvalue(L,1); /* the userdata */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1371 lua_pushvalue(L,2); /* the parameter */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1372 lua_pushvalue(L,3); /* the value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1373 lua_call(L,3,0); /* 3 values in ,0 out */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1374 lua_remove(L,-2); /* stack tidy, remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1375 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1376 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1377 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1378 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1379
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1380 /* the class.destruct method called by the interpreter */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1381 SWIGINTERN int SWIG_Lua_class_destruct(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1382 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1383 /* there should be 1 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1384 (1) userdata (not the meta table) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1385 swig_lua_userdata* usr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1386 swig_lua_class* clss;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1387 assert(lua_isuserdata(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1388 usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1389 /* if must be destroyed & has a destructor */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1390 if (usr->own) /* if must be destroyed */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1391 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1392 clss=(swig_lua_class*)usr->type->clientdata; /* get the class */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1393 if (clss && clss->destructor) /* there is a destroy fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1394 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1395 clss->destructor(usr->ptr); /* bye bye */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1396 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1397 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1398 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1399 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1400
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1401 /* the class.__tostring method called by the interpreter and print */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1402 SWIGINTERN int SWIG_Lua_class_tostring(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1403 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1404 /* there should be 1 param passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1405 (1) userdata (not the metatable) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1406 assert(lua_isuserdata(L,1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1407 unsigned long userData = (unsigned long)lua_touserdata(L,1); /* get the userdata address for later */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1408 lua_getmetatable(L,1); /* get the meta table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1409 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1410
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1411 lua_getfield(L, -1, ".type");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1412 const char* className = lua_tostring(L, -1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1413
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1414 char output[256];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1415 sprintf(output, "<%s userdata: %lX>", className, userData);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1416
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1417 lua_pushstring(L, (const char*)output);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1418 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1419 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1420
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1421 /* to manually disown some userdata */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1422 SWIGINTERN int SWIG_Lua_class_disown(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1423 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1424 /* there should be 1 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1425 (1) userdata (not the meta table) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1426 swig_lua_userdata* usr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1427 assert(lua_isuserdata(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1428 usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1429
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1430 usr->own = 0; /* clear our ownership */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1431 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1432 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1433
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1434 /* Constructor proxy. Used when class name entry in module is not class constructor,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1435 but special table instead. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1436 SWIGINTERN int SWIG_Lua_constructor_proxy(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1437 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1438 /* unlimited number of parameters
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1439 First one is our proxy table and we should remove it
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1440 Other we should pass to real constructor
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1441 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1442 assert(lua_istable(L,1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1443 lua_pushstring(L,".constructor");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1444 lua_rawget(L,1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1445 assert(!lua_isnil(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1446 lua_replace(L,1); /* replace our table with real constructor */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1447 lua_call(L,lua_gettop(L)-1,1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1448 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1449 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1450
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1451 /* gets the swig class registry (or creates it) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1452 SWIGINTERN void SWIG_Lua_get_class_registry(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1453 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1454 /* add this all into the swig registry: */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1455 lua_pushstring(L,"SWIG");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1456 lua_rawget(L,LUA_REGISTRYINDEX); /* get the registry */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1457 if (!lua_istable(L,-1)) /* not there */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1458 { /* must be first time, so add it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1459 lua_pop(L,1); /* remove the result */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1460 lua_pushstring(L,"SWIG");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1461 lua_newtable(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1462 lua_rawset(L,LUA_REGISTRYINDEX);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1463 /* then get it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1464 lua_pushstring(L,"SWIG");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1465 lua_rawget(L,LUA_REGISTRYINDEX);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1466 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1467 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1468
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1469 /* helper fn to get the classes metatable from the register */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1470 SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State* L,const char* cname)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1471 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1472 SWIG_Lua_get_class_registry(L); /* get the registry */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1473 lua_pushstring(L,cname); /* get the name */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1474 lua_rawget(L,-2); /* get it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1475 lua_remove(L,-2); /* tidy up (remove registry) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1476 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1477
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1478 /* helper add a variable to a registered class */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1479 SWIGINTERN void SWIG_Lua_add_class_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1480 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1481 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1482 SWIG_Lua_get_table(L,".get"); /* find the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1483 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1484 SWIG_Lua_add_function(L,name,getFn);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1485 lua_pop(L,1); /* tidy stack (remove table) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1486 if (setFn)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1487 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1488 SWIG_Lua_get_table(L,".set"); /* find the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1489 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1490 SWIG_Lua_add_function(L,name,setFn);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1491 lua_pop(L,1); /* tidy stack (remove table) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1492 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1493 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1494
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1495 /* helper to recursively add class static details (static attributes, operations and constants) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1496 SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State* L, swig_lua_class* clss)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1497 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1498 int i = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1499 /* The class namespace table must be on the top of the stack */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1500 assert(lua_istable(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1501 /* call all the base classes first: we can then override these later: */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1502 for(i=0;clss->bases[i];i++)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1503 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1504 SWIG_Lua_add_class_static_details(L,clss->bases[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1505 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1506
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1507 SWIG_Lua_add_namespace_details(L, &clss->cls_static);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1508 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1509
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1510 /* helper to recursively add class details (attributes & operations) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1511 SWIGINTERN void SWIG_Lua_add_class_details(lua_State* L,swig_lua_class* clss)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1512 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1513 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1514 /* call all the base classes first: we can then override these later: */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1515 for(i=0;clss->bases[i];i++)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1516 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1517 SWIG_Lua_add_class_details(L,clss->bases[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1518 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1519 /* add fns */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1520 for(i=0;clss->attributes[i].name;i++){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1521 SWIG_Lua_add_class_variable(L,clss->attributes[i].name,clss->attributes[i].getmethod,clss->attributes[i].setmethod);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1522 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1523 /* add methods to the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1524 SWIG_Lua_get_table(L,".fn"); /* find the .fn table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1525 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1526 for(i=0;clss->methods[i].name;i++){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1527 SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].method);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1528 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1529 lua_pop(L,1); /* tidy stack (remove table) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1530 /* add operator overloads
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1531 these look ANY method which start with "__" and assume they
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1532 are operator overloads & add them to the metatable
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1533 (this might mess up is someone defines a method __gc (the destructor)*/
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1534 for(i=0;clss->methods[i].name;i++){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1535 if (clss->methods[i].name[0]=='_' && clss->methods[i].name[1]=='_'){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1536 SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].method);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1537 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1538 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1539 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1540
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1541 /* set up the base classes pointers.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1542 Each class structure has a list of pointers to the base class structures.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1543 This function fills them.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1544 It cannot be done at compile time, as this will not work with hireachies
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1545 spread over more than one swig file.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1546 Therefore it must be done at runtime, querying the SWIG type system.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1547 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1548 SWIGINTERN void SWIG_Lua_init_base_class(lua_State* L,swig_lua_class* clss)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1549 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1550 int i=0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1551 swig_module_info* module=SWIG_GetModule(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1552 for(i=0;clss->base_names[i];i++)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1553 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1554 if (clss->bases[i]==0) /* not found yet */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1555 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1556 /* lookup and cache the base class */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1557 swig_type_info *info = SWIG_TypeQueryModule(module,module,clss->base_names[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1558 if (info) clss->bases[i] = (swig_lua_class *) info->clientdata;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1559 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1560 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1561 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1562
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1563 /* Register class static methods,attributes etc as well as constructor proxy */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1564 SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* clss)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1565 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1566 lua_checkstack(L,5); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1567 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1568 assert(strcmp(clss->name, clss->cls_static.name) == 0); /* in class those 2 must be equal */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1569
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1570 SWIG_Lua_namespace_register(L,&clss->cls_static);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1571
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1572 SWIG_Lua_get_table(L,clss->name); // Get namespace table back
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1573 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1574
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1575 /* add its constructor to module with the name of the class
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1576 so you can do MyClass(...) as well as new_MyClass(...)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1577 BUT only if a constructor is defined
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1578 (this overcomes the problem of pure virtual classes without constructors)*/
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1579 if (clss->constructor)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1580 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1581 SWIG_Lua_add_function(L,".constructor", clss->constructor);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1582 lua_getmetatable(L,-1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1583 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1584 SWIG_Lua_add_function(L,"__call", SWIG_Lua_constructor_proxy);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1585 lua_pop(L,1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1586 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1587
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1588 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1589 SWIG_Lua_add_class_static_details(L, clss);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1590
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1591 /* clear stack */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1592 lua_pop(L,1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1593 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1594
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1595 /* performs the entire class registration process */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1596 SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1597 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1598 SWIG_Lua_class_register_static(L,clss);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1599
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1600 SWIG_Lua_get_class_registry(L); /* get the registry */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1601 lua_pushstring(L,clss->name); /* get the name */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1602 lua_newtable(L); /* create the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1603 /* add string of class name called ".type" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1604 lua_pushstring(L,".type");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1605 lua_pushstring(L,clss->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1606 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1607 /* add a table called ".get" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1608 lua_pushstring(L,".get");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1609 lua_newtable(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1610 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1611 /* add a table called ".set" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1612 lua_pushstring(L,".set");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1613 lua_newtable(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1614 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1615 /* add a table called ".fn" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1616 lua_pushstring(L,".fn");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1617 lua_newtable(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1618 /* add manual disown method */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1619 SWIG_Lua_add_function(L,"__disown",SWIG_Lua_class_disown);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1620 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1621 /* add accessor fns for using the .get,.set&.fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1622 SWIG_Lua_add_function(L,"__index",SWIG_Lua_class_get);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1623 SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_class_set);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1624 SWIG_Lua_add_function(L,"__gc",SWIG_Lua_class_destruct);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1625 /* add tostring method for better output */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1626 SWIG_Lua_add_function(L,"__tostring",SWIG_Lua_class_tostring);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1627 /* add it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1628 lua_rawset(L,-3); /* metatable into registry */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1629 lua_pop(L,1); /* tidy stack (remove registry) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1630
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1631 SWIG_Lua_get_class_metatable(L,clss->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1632 SWIG_Lua_add_class_details(L,clss); /* recursive adding of details (atts & ops) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1633 lua_pop(L,1); /* tidy stack (remove class metatable) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1634 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1635
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1636 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1637 * Class/structure conversion fns
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1638 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1639
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1640 /* helper to add metatable to new lua object */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1641 SWIGINTERN void _SWIG_Lua_AddMetatable(lua_State* L,swig_type_info *type)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1642 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1643 if (type->clientdata) /* there is clientdata: so add the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1644 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1645 SWIG_Lua_get_class_metatable(L,((swig_lua_class*)(type->clientdata))->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1646 if (lua_istable(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1647 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1648 lua_setmetatable(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1649 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1650 else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1651 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1652 lua_pop(L,1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1653 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1654 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1655 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1656
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1657 /* pushes a new object into the lua stack */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1658 SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State* L,void* ptr,swig_type_info *type, int own)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1659 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1660 swig_lua_userdata* usr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1661 if (!ptr){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1662 lua_pushnil(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1663 return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1664 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1665 usr=(swig_lua_userdata*)lua_newuserdata(L,sizeof(swig_lua_userdata)); /* get data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1666 usr->ptr=ptr; /* set the ptr */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1667 usr->type=type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1668 usr->own=own;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1669 #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1670 _SWIG_Lua_AddMetatable(L,type); /* add metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1671 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1672 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1673
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1674 /* takes a object from the lua stack & converts it into an object of the correct type
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1675 (if possible) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1676 SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State* L,int index,void** ptr,swig_type_info *type,int flags)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1677 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1678 swig_lua_userdata* usr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1679 swig_cast_info *cast;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1680 if (lua_isnil(L,index)){*ptr=0; return SWIG_OK;} /* special case: lua nil => NULL pointer */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1681 usr=(swig_lua_userdata*)lua_touserdata(L,index); /* get data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1682 if (usr)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1683 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1684 if (flags & SWIG_POINTER_DISOWN) /* must disown the object */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1685 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1686 usr->own=0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1687 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1688 if (!type) /* special cast void*, no casting fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1689 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1690 *ptr=usr->ptr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1691 return SWIG_OK; /* ok */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1692 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1693 cast=SWIG_TypeCheckStruct(usr->type,type); /* performs normal type checking */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1694 if (cast)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1695 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1696 int newmemory = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1697 *ptr=SWIG_TypeCast(cast,usr->ptr,&newmemory);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1698 assert(!newmemory); /* newmemory handling not yet implemented */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1699 return SWIG_OK; /* ok */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1700 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1701 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1702 return SWIG_ERROR; /* error */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1703 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1704
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1705 SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_State* L,int index,swig_type_info *type,int flags,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1706 int argnum,const char* func_name){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1707 void* result;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1708 if (!SWIG_IsOK(SWIG_ConvertPtr(L,index,&result,type,flags))){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1709 luaL_error (L,"Error in %s, expected a %s at argument number %d\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1710 func_name,(type && type->str)?type->str:"void*",argnum);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1711 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1712 return result;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1713 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1714
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1715 /* pushes a packed userdata. user for member fn pointers only */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1716 SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State* L,void* ptr,size_t size,swig_type_info *type)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1717 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1718 swig_lua_rawdata* raw;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1719 assert(ptr); /* not acceptable to pass in a NULL value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1720 raw=(swig_lua_rawdata*)lua_newuserdata(L,sizeof(swig_lua_rawdata)-1+size); /* alloc data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1721 raw->type=type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1722 raw->own=0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1723 memcpy(raw->data,ptr,size); /* copy the data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1724 _SWIG_Lua_AddMetatable(L,type); /* add metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1725 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1726
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1727 /* converts a packed userdata. user for member fn pointers only */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1728 SWIGRUNTIME int SWIG_Lua_ConvertPacked(lua_State* L,int index,void* ptr,size_t size,swig_type_info *type)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1729 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1730 swig_lua_rawdata* raw;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1731 raw=(swig_lua_rawdata*)lua_touserdata(L,index); /* get data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1732 if (!raw) return SWIG_ERROR; /* error */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1733 if (type==0 || type==raw->type) /* void* or identical type */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1734 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1735 memcpy(ptr,raw->data,size); /* copy it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1736 return SWIG_OK; /* ok */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1737 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1738 return SWIG_ERROR; /* error */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1739 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1740
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1741 /* a function to get the typestring of a piece of data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1742 SWIGRUNTIME const char *SWIG_Lua_typename(lua_State *L, int tp)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1743 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1744 swig_lua_userdata* usr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1745 if (lua_isuserdata(L,tp))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1746 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1747 usr=(swig_lua_userdata*)lua_touserdata(L,tp); /* get data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1748 if (usr && usr->type && usr->type->str)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1749 return usr->type->str;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1750 return "userdata (unknown type)";
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1751 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1752 return lua_typename(L,lua_type(L,tp));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1753 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1754
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1755 /* lua callable function to get the userdata's type */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1756 SWIGRUNTIME int SWIG_Lua_type(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1757 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1758 lua_pushstring(L,SWIG_Lua_typename(L,1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1759 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1760 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1761
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1762 /* lua callable function to compare userdata's value
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1763 the issue is that two userdata may point to the same thing
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1764 but to lua, they are different objects */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1765 SWIGRUNTIME int SWIG_Lua_equal(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1766 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1767 int result;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1768 swig_lua_userdata *usr1,*usr2;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1769 if (!lua_isuserdata(L,1) || !lua_isuserdata(L,2)) /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1770 return 0; /* nil reply */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1771 usr1=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1772 usr2=(swig_lua_userdata*)lua_touserdata(L,2); /* get data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1773 /*result=(usr1->ptr==usr2->ptr && usr1->type==usr2->type); only works if type is the same*/
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1774 result=(usr1->ptr==usr2->ptr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1775 lua_pushboolean(L,result);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1776 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1777 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1778
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1779 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1780 * global variable support code: class/struct typemap functions
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1781 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1782
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1783 #if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1784 /* Install Constants */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1785 SWIGINTERN void
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1786 SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1787 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1788 for (i = 0; constants[i].type; i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1789 switch(constants[i].type) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1790 case SWIG_LUA_INT:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1791 lua_pushstring(L,constants[i].name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1792 lua_pushnumber(L,(lua_Number)constants[i].lvalue);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1793 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1794 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1795 case SWIG_LUA_FLOAT:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1796 lua_pushstring(L,constants[i].name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1797 lua_pushnumber(L,(lua_Number)constants[i].dvalue);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1798 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1799 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1800 case SWIG_LUA_CHAR:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1801 lua_pushstring(L,constants[i].name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1802 lua_pushfstring(L,"%c",(char)constants[i].lvalue);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1803 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1804 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1805 case SWIG_LUA_STRING:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1806 lua_pushstring(L,constants[i].name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1807 lua_pushstring(L,(char *) constants[i].pvalue);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1808 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1809 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1810 case SWIG_LUA_POINTER:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1811 lua_pushstring(L,constants[i].name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1812 SWIG_NewPointerObj(L,constants[i].pvalue, *(constants[i]).ptype,0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1813 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1814 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1815 case SWIG_LUA_BINARY:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1816 lua_pushstring(L,constants[i].name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1817 SWIG_NewMemberObj(L,constants[i].pvalue,constants[i].lvalue,*(constants[i]).ptype);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1818 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1819 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1820 default:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1821 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1822 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1823 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1824 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1825 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1826
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1827 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1828 * executing lua code from within the wrapper
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1829 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1830
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1831 #ifndef SWIG_DOSTRING_FAIL /* Allows redefining of error function */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1832 #define SWIG_DOSTRING_FAIL(S) fprintf(stderr,"%s\n",S)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1833 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1834 /* Executes a C string in Lua which is a really simple way of calling lua from C
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1835 Unfortunately lua keeps changing its APIs, so we need a conditional compile
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1836 In lua 5.0.X its lua_dostring()
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1837 In lua 5.1.X its luaL_dostring()
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1838 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1839 SWIGINTERN int
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1840 SWIG_Lua_dostring(lua_State *L, const char* str) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1841 int ok,top;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1842 if (str==0 || str[0]==0) return 0; /* nothing to do */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1843 top=lua_gettop(L); /* save stack */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1844 #if (defined(LUA_VERSION_NUM) && (LUA_VERSION_NUM>=501))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1845 ok=luaL_dostring(L,str); /* looks like this is lua 5.1.X or later, good */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1846 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1847 ok=lua_dostring(L,str); /* might be lua 5.0.x, using lua_dostring */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1848 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1849 if (ok!=0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1850 SWIG_DOSTRING_FAIL(lua_tostring(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1851 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1852 lua_settop(L,top); /* restore the stack */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1853 return ok;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1854 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1855
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1856 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1857 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1858 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1859
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1860 /* ------------------------------ end luarun.swg ------------------------------ */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1861
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1862
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1863 /* -------- TYPES TABLE (BEGIN) -------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1864
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1865 static swig_type_info *swig_types[1];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1866 static swig_module_info swig_module = {swig_types, 0, 0, 0, 0, 0};
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1867 #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1868 #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1869
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1870 /* -------- TYPES TABLE (END) -------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1871
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1872 #define SWIG_name "example"
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1873 #define SWIG_init luaopen_example
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1874 #define SWIG_init_user luaopen_example_user
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1875
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1876 #define SWIG_LUACODE luaopen_example_luacode
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1877
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1878 namespace swig {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1879 typedef struct{} LANGUAGE_OBJ;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1880 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1881
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1882
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1883 #include "example.h"
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1884
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1885 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1886 extern "C" {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1887 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1888 static int _wrap_gcd(lua_State* L) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1889 int SWIG_arg = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1890 int arg1 ;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1891 int arg2 ;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1892 int result;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1893
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1894 SWIG_check_num_args("gcd",2,2)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1895 if(!lua_isnumber(L,1)) SWIG_fail_arg("gcd",1,"int");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1896 if(!lua_isnumber(L,2)) SWIG_fail_arg("gcd",2,"int");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1897 arg1 = (int)lua_tonumber(L, 1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1898 arg2 = (int)lua_tonumber(L, 2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1899 result = (int)gcd(arg1,arg2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1900 lua_pushnumber(L, (lua_Number) result); SWIG_arg++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1901 return SWIG_arg;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1902
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1903 if(0) SWIG_fail;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1904
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1905 fail:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1906 lua_error(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1907 return SWIG_arg;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1908 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1909
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1910
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1911 static int _wrap_Foo_set(lua_State* L) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1912 int SWIG_arg = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1913 double arg1 ;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1914
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1915 SWIG_check_num_args("Foo",1,1)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1916 if(!lua_isnumber(L,1)) SWIG_fail_arg("Foo",1,"double");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1917 arg1 = (double)lua_tonumber(L, 1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1918 Foo = arg1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1919
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1920 return SWIG_arg;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1921
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1922 if(0) SWIG_fail;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1923
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1924 fail:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1925 lua_error(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1926 return SWIG_arg;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1927 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1928
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1929
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1930 static int _wrap_Foo_get(lua_State* L) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1931 int SWIG_arg = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1932 double result;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1933
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1934 SWIG_check_num_args("Foo",0,0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1935 result = (double)Foo;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1936 lua_pushnumber(L, (lua_Number) result); SWIG_arg++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1937 return SWIG_arg;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1938
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1939 if(0) SWIG_fail;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1940
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1941 fail:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1942 lua_error(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1943 return SWIG_arg;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1944 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1945
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1946
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1947 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1948 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1949 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1950
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1951 static const struct luaL_Reg swig_commands[] = {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1952 { "gcd", _wrap_gcd},
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1953 {0,0}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1954 };
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1955
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1956 static swig_lua_var_info swig_variables[] = {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1957 { "Foo", _wrap_Foo_get, _wrap_Foo_set },
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1958 {0,0,0}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1959 };
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1960
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1961 static swig_lua_const_info swig_constants[] = {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1962 {0,0,0,0,0,0}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1963 };
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1964
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1965 /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1966
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1967
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1968 static swig_type_info *swig_type_initial[] = {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1969 NULL
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1970 };
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1971
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1972
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1973 static swig_cast_info *swig_cast_initial[] = {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1974 NULL
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1975 };
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1976
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1977
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1978 /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1979
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1980 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1981 * Type initialization:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1982 * This problem is tough by the requirement that no dynamic
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1983 * memory is used. Also, since swig_type_info structures store pointers to
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1984 * swig_cast_info structures and swig_cast_info structures store pointers back
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1985 * to swig_type_info structures, we need some lookup code at initialization.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1986 * The idea is that swig generates all the structures that are needed.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1987 * The runtime then collects these partially filled structures.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1988 * The SWIG_InitializeModule function takes these initial arrays out of
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1989 * swig_module, and does all the lookup, filling in the swig_module.types
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1990 * array with the correct data and linking the correct swig_cast_info
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1991 * structures together.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1992 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1993 * The generated swig_type_info structures are assigned staticly to an initial
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1994 * array. We just loop through that array, and handle each type individually.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1995 * First we lookup if this type has been already loaded, and if so, use the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1996 * loaded structure instead of the generated one. Then we have to fill in the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1997 * cast linked list. The cast data is initially stored in something like a
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1998 * two-dimensional array. Each row corresponds to a type (there are the same
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1999 * number of rows as there are in the swig_type_initial array). Each entry in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2000 * a column is one of the swig_cast_info structures for that type.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2001 * The cast_initial array is actually an array of arrays, because each row has
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2002 * a variable number of columns. So to actually build the cast linked list,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2003 * we find the array of casts associated with the type, and loop through it
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2004 * adding the casts to the list. The one last trick we need to do is making
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2005 * sure the type pointer in the swig_cast_info struct is correct.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2006 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2007 * First off, we lookup the cast->type name to see if it is already loaded.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2008 * There are three cases to handle:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2009 * 1) If the cast->type has already been loaded AND the type we are adding
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2010 * casting info to has not been loaded (it is in this module), THEN we
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2011 * replace the cast->type pointer with the type pointer that has already
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2012 * been loaded.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2013 * 2) If BOTH types (the one we are adding casting info to, and the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2014 * cast->type) are loaded, THEN the cast info has already been loaded by
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2015 * the previous module so we just ignore it.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2016 * 3) Finally, if cast->type has not already been loaded, then we add that
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2017 * swig_cast_info to the linked list (because the cast->type) pointer will
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2018 * be correct.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2019 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2020
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2021 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2022 extern "C" {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2023 #if 0
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2024 } /* c-mode */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2025 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2026 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2027
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2028 #if 0
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2029 #define SWIGRUNTIME_DEBUG
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2030 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2031
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2032
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2033 SWIGRUNTIME void
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2034 SWIG_InitializeModule(void *clientdata) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2035 size_t i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2036 swig_module_info *module_head, *iter;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2037 int found, init;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2038
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2039 /* check to see if the circular list has been setup, if not, set it up */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2040 if (swig_module.next==0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2041 /* Initialize the swig_module */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2042 swig_module.type_initial = swig_type_initial;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2043 swig_module.cast_initial = swig_cast_initial;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2044 swig_module.next = &swig_module;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2045 init = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2046 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2047 init = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2048 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2049
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2050 /* Try and load any already created modules */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2051 module_head = SWIG_GetModule(clientdata);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2052 if (!module_head) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2053 /* This is the first module loaded for this interpreter */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2054 /* so set the swig module into the interpreter */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2055 SWIG_SetModule(clientdata, &swig_module);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2056 module_head = &swig_module;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2057 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2058 /* the interpreter has loaded a SWIG module, but has it loaded this one? */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2059 found=0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2060 iter=module_head;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2061 do {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2062 if (iter==&swig_module) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2063 found=1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2064 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2065 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2066 iter=iter->next;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2067 } while (iter!= module_head);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2068
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2069 /* if the is found in the list, then all is done and we may leave */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2070 if (found) return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2071 /* otherwise we must add out module into the list */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2072 swig_module.next = module_head->next;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2073 module_head->next = &swig_module;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2074 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2075
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2076 /* When multiple interpreters are used, a module could have already been initialized in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2077 a different interpreter, but not yet have a pointer in this interpreter.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2078 In this case, we do not want to continue adding types... everything should be
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2079 set up already */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2080 if (init == 0) return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2081
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2082 /* Now work on filling in swig_module.types */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2083 #ifdef SWIGRUNTIME_DEBUG
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2084 printf("SWIG_InitializeModule: size %d\n", swig_module.size);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2085 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2086 for (i = 0; i < swig_module.size; ++i) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2087 swig_type_info *type = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2088 swig_type_info *ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2089 swig_cast_info *cast;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2090
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2091 #ifdef SWIGRUNTIME_DEBUG
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2092 printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2093 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2094
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2095 /* if there is another module already loaded */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2096 if (swig_module.next != &swig_module) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2097 type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2098 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2099 if (type) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2100 /* Overwrite clientdata field */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2101 #ifdef SWIGRUNTIME_DEBUG
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2102 printf("SWIG_InitializeModule: found type %s\n", type->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2103 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2104 if (swig_module.type_initial[i]->clientdata) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2105 type->clientdata = swig_module.type_initial[i]->clientdata;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2106 #ifdef SWIGRUNTIME_DEBUG
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2107 printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2108 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2109 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2110 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2111 type = swig_module.type_initial[i];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2112 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2113
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2114 /* Insert casting types */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2115 cast = swig_module.cast_initial[i];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2116 while (cast->type) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2117
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2118 /* Don't need to add information already in the list */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2119 ret = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2120 #ifdef SWIGRUNTIME_DEBUG
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2121 printf("SWIG_InitializeModule: look cast %s\n", cast->type->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2122 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2123 if (swig_module.next != &swig_module) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2124 ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2125 #ifdef SWIGRUNTIME_DEBUG
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2126 if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2127 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2128 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2129 if (ret) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2130 if (type == swig_module.type_initial[i]) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2131 #ifdef SWIGRUNTIME_DEBUG
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2132 printf("SWIG_InitializeModule: skip old type %s\n", ret->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2133 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2134 cast->type = ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2135 ret = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2136 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2137 /* Check for casting already in the list */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2138 swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2139 #ifdef SWIGRUNTIME_DEBUG
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2140 if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2141 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2142 if (!ocast) ret = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2143 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2144 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2145
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2146 if (!ret) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2147 #ifdef SWIGRUNTIME_DEBUG
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2148 printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2149 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2150 if (type->cast) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2151 type->cast->prev = cast;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2152 cast->next = type->cast;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2153 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2154 type->cast = cast;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2155 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2156 cast++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2157 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2158 /* Set entry in modules->types array equal to the type */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2159 swig_module.types[i] = type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2160 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2161 swig_module.types[i] = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2162
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2163 #ifdef SWIGRUNTIME_DEBUG
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2164 printf("**** SWIG_InitializeModule: Cast List ******\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2165 for (i = 0; i < swig_module.size; ++i) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2166 int j = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2167 swig_cast_info *cast = swig_module.cast_initial[i];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2168 printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2169 while (cast->type) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2170 printf("SWIG_InitializeModule: cast type %s\n", cast->type->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2171 cast++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2172 ++j;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2173 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2174 printf("---- Total casts: %d\n",j);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2175 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2176 printf("**** SWIG_InitializeModule: Cast List ******\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2177 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2178 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2179
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2180 /* This function will propagate the clientdata field of type to
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2181 * any new swig_type_info structures that have been added into the list
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2182 * of equivalent types. It is like calling
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2183 * SWIG_TypeClientData(type, clientdata) a second time.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2184 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2185 SWIGRUNTIME void
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2186 SWIG_PropagateClientData(void) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2187 size_t i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2188 swig_cast_info *equiv;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2189 static int init_run = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2190
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2191 if (init_run) return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2192 init_run = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2193
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2194 for (i = 0; i < swig_module.size; i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2195 if (swig_module.types[i]->clientdata) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2196 equiv = swig_module.types[i]->cast;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2197 while (equiv) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2198 if (!equiv->converter) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2199 if (equiv->type && !equiv->type->clientdata)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2200 SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2201 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2202 equiv = equiv->next;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2203 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2204 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2205 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2206 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2207
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2208 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2209 #if 0
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2210 { /* c-mode */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2211 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2212 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2213 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2214
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2215
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2216
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2217 /* Forward declaration of where the user's %init{} gets inserted */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2218 void SWIG_init_user(lua_State* L );
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2219
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2220 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2221 extern "C" {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2222 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2223 /* this is the initialization function
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2224 added at the very end of the code
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2225 the function is always called SWIG_init, but an earlier #define will rename it
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2226 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2227 #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2228 LUALIB_API int SWIG_init(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2229 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2230 SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2231 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2232 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2233 #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) /* valid for both Lua and eLua */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2234 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2235 /* start with global table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2236 lua_pushglobaltable (L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2237 /* SWIG's internal initalisation */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2238 SWIG_InitializeModule((void*)L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2239 SWIG_PropagateClientData();
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2240 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2241
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2242 #if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2243 /* add a global fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2244 SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2245 SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_equal);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2246 /* begin the module (its a table with the same name as the module) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2247 SWIG_Lua_module_begin(L,SWIG_name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2248 /* add commands/functions */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2249 for (i = 0; swig_commands[i].name; i++){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2250 SWIG_Lua_module_add_function(L,swig_commands[i].name,swig_commands[i].func);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2251 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2252 /* add variables */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2253 for (i = 0; swig_variables[i].name; i++){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2254 SWIG_Lua_module_add_variable(L,swig_variables[i].name,swig_variables[i].get,swig_variables[i].set);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2255 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2256 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2257
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2258 #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2259 /* set up base class pointers (the hierarchy) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2260 for (i = 0; swig_types[i]; i++){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2261 if (swig_types[i]->clientdata){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2262 SWIG_Lua_init_base_class(L,(swig_lua_class*)(swig_types[i]->clientdata));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2263 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2264 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2265 /* additional registration structs & classes in lua */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2266 for (i = 0; swig_types[i]; i++){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2267 if (swig_types[i]->clientdata){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2268 SWIG_Lua_class_register(L,(swig_lua_class*)(swig_types[i]->clientdata));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2269 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2270 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2271 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2272
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2273 #if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2274 /* constants */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2275 SWIG_Lua_InstallConstants(L,swig_constants);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2276 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2277
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2278 #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2279 /* invoke user-specific initialization */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2280 SWIG_init_user(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2281 /* end module */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2282 /* Note: We do not clean up the stack here (Lua will do this for us). At this
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2283 point, we have the globals table and out module table on the stack. Returning
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2284 one value makes the module table the result of the require command. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2285 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2286 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2287 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2288 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2289 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2290
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2291 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2292 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2293 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2294
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2295
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2296 const char* SWIG_LUACODE=
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2297 "";
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2298
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2299 void SWIG_init_user(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2300 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2301 /* exec Lua code if applicable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2302 SWIG_Lua_dostring(L,SWIG_LUACODE);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2303 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2304