annotate lib/swig/swigwin-2.0.11/Lib/lua/luarun.swg @ 2353:bb9f180d50f6

Removing a few unsorted_subs includes
author Grumpy7
date Wed, 09 Apr 2014 21:58:09 +0200
parents 7a9477135943
children
rev   line source
1899
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2 * luarun.swg
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
3 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
4 * This file contains the runtime support for Lua modules
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
5 * and includes code for managing global variables and pointer
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
6 * type checking.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
7 * ----------------------------------------------------------------------------- */
2037
7a9477135943 Renamed Math.h -> OurMath.h (file resolution was sometimes ambiguous)
Nomad
parents: 1899
diff changeset
8
7a9477135943 Renamed Math.h -> OurMath.h (file resolution was sometimes ambiguous)
Nomad
parents: 1899
diff changeset
9 #include "lib/lua/lua.h"
1899
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
10 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
11 extern "C" {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
12 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
13
2037
7a9477135943 Renamed Math.h -> OurMath.h (file resolution was sometimes ambiguous)
Nomad
parents: 1899
diff changeset
14 //#include "lua.h"
7a9477135943 Renamed Math.h -> OurMath.h (file resolution was sometimes ambiguous)
Nomad
parents: 1899
diff changeset
15 //#include "lauxlib.h"
1899
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
16 #include <stdlib.h> /* for malloc */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
17 #include <assert.h> /* for a few sanity tests */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
18
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
19 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
20 * Lua flavors
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
21 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
22
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
23 #define SWIG_LUA_FLAVOR_LUA 1
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
24 #define SWIG_LUA_FLAVOR_ELUA 2
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
25 #define SWIG_LUA_FLAVOR_ELUAC 3
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
26
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
27 #if !defined(SWIG_LUA_TARGET)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
28 # error SWIG_LUA_TARGET not defined
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
29 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
30
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
31 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
32 # define SWIG_LUA_CONSTTAB_INT(B, C) LSTRKEY(B), LNUMVAL(C)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
33 # define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
34 # define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
35 # define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
36 #else /* SWIG_LUA_FLAVOR_LUA */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
37 # 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
38 # 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
39 # 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
40 # 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
41 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
42
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
43 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
44 # define LRO_STRVAL(v) {{.p = (char *) v}, LUA_TSTRING}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
45 # define LSTRVAL LRO_STRVAL
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
46 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
47
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
48 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
49 * compatibility defines
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
50 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
51
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
52 /* History of Lua C API length functions: In Lua 5.0 (and before?)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
53 there was "lua_strlen". In Lua 5.1, this was renamed "lua_objlen",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
54 but a compatibility define of "lua_strlen" was added. In Lua 5.2,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
55 this function was again renamed, to "lua_rawlen" (to emphasize that
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
56 it doesn't call the "__len" metamethod), and the compatibility
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
57 define of lua_strlen was removed. All SWIG uses have been updated
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
58 to "lua_rawlen", and we add our own defines of that here for older
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
59 versions of Lua. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
60 #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
61 # define lua_rawlen lua_strlen
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
62 #elif LUA_VERSION_NUM == 501
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
63 # define lua_rawlen lua_objlen
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
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
67 /* lua_pushglobaltable is the recommended "future-proof" way to get
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
68 the global table for Lua 5.2 and later. Here we define
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
69 lua_pushglobaltable ourselves for Lua versions before 5.2. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
70 #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
71 # define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
72 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
73
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
74
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
75 /* --------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
76 * Helper functions for error handling
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
77 * -------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
78
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
79 /* Push the string STR on the Lua stack, like lua_pushstring, but
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
80 prefixed with the the location of the innermost Lua call-point
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
81 (as formated by luaL_where). */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
82 SWIGRUNTIME void
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
83 SWIG_Lua_pusherrstring (lua_State *L, const char *str)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
84 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
85 luaL_where (L, 1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
86 lua_pushstring (L, str);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
87 lua_concat (L, 2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
88 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
89
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
90 /* Push a formatted string generated from FMT and following args on
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
91 the Lua stack, like lua_pushfstring, but prefixed with the the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
92 location of the innermost Lua call-point (as formated by luaL_where). */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
93 SWIGRUNTIME void
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
94 SWIG_Lua_pushferrstring (lua_State *L, const char *fmt, ...)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
95 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
96 va_list argp;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
97 va_start(argp, fmt);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
98 luaL_where(L, 1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
99 lua_pushvfstring(L, fmt, argp);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
100 va_end(argp);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
101 lua_concat(L, 2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
102 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
103
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
104
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
105 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
106 * global swig types
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
107 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
108 /* Constant table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
109 #define SWIG_LUA_INT 1
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
110 #define SWIG_LUA_FLOAT 2
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
111 #define SWIG_LUA_STRING 3
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
112 #define SWIG_LUA_POINTER 4
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
113 #define SWIG_LUA_BINARY 5
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
114 #define SWIG_LUA_CHAR 6
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
115
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
116 /* Structure for variable linking table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
117 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
118 const char *name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
119 lua_CFunction get;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
120 lua_CFunction set;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
121 } swig_lua_var_info;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
122
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
123 /* Constant information structure */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
124 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
125 int type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
126 char *name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
127 long lvalue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
128 double dvalue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
129 void *pvalue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
130 swig_type_info **ptype;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
131 } swig_lua_const_info;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
132
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
133 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
134 const char *name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
135 lua_CFunction method;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
136 } swig_lua_method;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
137
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
138 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
139 const char *name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
140 lua_CFunction getmethod;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
141 lua_CFunction setmethod;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
142 } swig_lua_attribute;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
143
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
144 // Can be used to create namespaces. Currently used to
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
145 // wrap class static methods/variables/constants
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
146 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
147 const char *name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
148 swig_lua_method *ns_methods;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
149 swig_lua_attribute *ns_attributes;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
150 swig_lua_const_info *ns_constants;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
151 } swig_lua_namespace;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
152
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
153 typedef struct swig_lua_class {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
154 const char *name;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
155 swig_type_info **type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
156 lua_CFunction constructor;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
157 void (*destructor)(void *);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
158 swig_lua_method *methods;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
159 swig_lua_attribute *attributes;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
160 swig_lua_namespace cls_static;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
161 struct swig_lua_class **bases;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
162 const char **base_names;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
163 } swig_lua_class;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
164
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
165 /* this is the struct for wrapping all pointers in SwigLua
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
166 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
167 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
168 swig_type_info *type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
169 int own; /* 1 if owned & must be destroyed */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
170 void *ptr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
171 } swig_lua_userdata;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
172
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
173 /* this is the struct for wrapping arbitrary packed binary data
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
174 (currently it is only used for member function pointers)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
175 the data ordering is similar to swig_lua_userdata, but it is currently not possible
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
176 to tell the two structures apart within SWIG, other than by looking at the type
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
177 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
178 typedef struct {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
179 swig_type_info *type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
180 int own; /* 1 if owned & must be destroyed */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
181 char data[1]; /* arbitary amount of data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
182 } swig_lua_rawdata;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
183
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
184 /* Common SWIG API */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
185 #define SWIG_NewPointerObj(L, ptr, type, owner) SWIG_Lua_NewPointerObj(L, (void *)ptr, type, owner)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
186 #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
187 #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
188 /* for C++ member pointers, ie, member methods */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
189 #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
190 #define SWIG_NewMemberObj(L, ptr, sz, type) SWIG_Lua_NewPackedObj(L, ptr, sz, type)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
191
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
192 /* Runtime API */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
193 #define SWIG_GetModule(clientdata) SWIG_Lua_GetModule((lua_State*)(clientdata))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
194 #define SWIG_SetModule(clientdata, pointer) SWIG_Lua_SetModule((lua_State*) (clientdata), pointer)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
195 #define SWIG_MODULE_CLIENTDATA_TYPE lua_State*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
196
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
197 /* Contract support */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
198 #define SWIG_contract_assert(expr, msg) \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
199 if (!(expr)) { SWIG_Lua_pusherrstring(L, (char *) msg); goto fail; } else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
200
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
201
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
202 /* helper #defines */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
203 #define SWIG_fail {goto fail;}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
204 #define SWIG_fail_arg(func_name,argnum,type) \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
205 {SWIG_Lua_pushferrstring(L,"Error in %s (arg %d), expected '%s' got '%s'",\
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
206 func_name,argnum,type,SWIG_Lua_typename(L,argnum));\
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
207 goto fail;}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
208 #define SWIG_fail_ptr(func_name,argnum,type) \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
209 SWIG_fail_arg(func_name,argnum,(type && type->str)?type->str:"void*")
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
210 #define SWIG_check_num_args(func_name,a,b) \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
211 if (lua_gettop(L)<a || lua_gettop(L)>b) \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
212 {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
213 goto fail;}
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 #define SWIG_Lua_get_table(L,n) \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
217 (lua_pushstring(L, n), lua_rawget(L,-2))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
218
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
219 #define SWIG_Lua_add_function(L,n,f) \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
220 (lua_pushstring(L, n), \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
221 lua_pushcfunction(L, f), \
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
222 lua_rawset(L,-3))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
223
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
224 /* special helper for allowing 'nil' for usertypes */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
225 #define SWIG_isptrtype(L,I) (lua_isuserdata(L,I) || lua_isnil(L,I))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
226
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
227 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
228 /* Special helper for member function pointers
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
229 it gets the address, casts it, then dereferences it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
230 //#define SWIG_mem_fn_as_voidptr(a) (*((char**)&(a)))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
231 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
232
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
233 /* storing/access of swig_module_info */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
234 SWIGRUNTIME swig_module_info *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
235 SWIG_Lua_GetModule(lua_State* L) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
236 swig_module_info *ret = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
237 lua_pushstring(L,"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
238 lua_rawget(L,LUA_REGISTRYINDEX);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
239 if (lua_islightuserdata(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
240 ret=(swig_module_info*)lua_touserdata(L,-1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
241 lua_pop(L,1); /* tidy */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
242 return ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
243 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
244
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
245 SWIGRUNTIME void
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
246 SWIG_Lua_SetModule(lua_State* L, swig_module_info *module) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
247 /* add this all into the Lua registry: */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
248 lua_pushstring(L,"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
249 lua_pushlightuserdata(L,(void*)module);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
250 lua_rawset(L,LUA_REGISTRYINDEX);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
251 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
252
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
253 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
254 * global variable support code: modules
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
255 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
256
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
257 /* this function is called when trying to set an immutable.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
258 default action is to print an error.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
259 This can removed with a compile flag SWIGLUA_IGNORE_SET_IMMUTABLE */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
260 SWIGINTERN int SWIG_Lua_set_immutable(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
261 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
262 /* there should be 1 param passed in: the new value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
263 #ifndef SWIGLUA_IGNORE_SET_IMMUTABLE
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
264 lua_pop(L,1); /* remove it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
265 luaL_error(L,"This variable is immutable");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
266 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
267 return 0; /* should not return anything */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
268 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
269
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
270 /* the module.get method used for getting linked data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
271 SWIGINTERN int SWIG_Lua_module_get(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
272 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
273 /* there should be 2 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
274 (1) table (not the meta table)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
275 (2) string name of the attribute
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
276 printf("SWIG_Lua_module_get %p(%s) '%s'\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
277 lua_topointer(L,1),lua_typename(L,lua_type(L,1)),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
278 lua_tostring(L,2));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
279 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
280 /* get the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
281 #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
282 assert(lua_isrotable(L,1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
283 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
284 assert(lua_istable(L,1)); /* default Lua action */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
285 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
286 lua_getmetatable(L,1); /* get the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
287 #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
288 assert(lua_isrotable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
289 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
290 assert(lua_istable(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
291 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
292 SWIG_Lua_get_table(L,".get"); /* get the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
293 lua_remove(L,3); /* remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
294 #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
295 if (lua_isrotable(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
296 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
297 if (lua_istable(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
298 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
299 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
300 /* look for the key in the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
301 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
302 lua_rawget(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
303 lua_remove(L,3); /* remove .get */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
304 if (lua_iscfunction(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
305 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
306 lua_call(L,0,1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
307 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
308 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
309 lua_pop(L,1); /* remove the top */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
310 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
311 lua_pop(L,1); /* remove the .get */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
312 lua_pushnil(L); /* return a nil */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
313 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
314 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
315
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
316 /* the module.set method used for setting linked data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
317 SWIGINTERN int SWIG_Lua_module_set(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
318 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
319 /* there should be 3 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
320 (1) table (not the meta table)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
321 (2) string name of the attribute
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
322 (3) any for the new value
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
323 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
324 /* get the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
325 #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
326 assert(lua_isrotable(L,1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
327 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
328 assert(lua_istable(L,1)); /* default Lua action */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
329 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
330 lua_getmetatable(L,1); /* get the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
331 #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
332 assert(lua_isrotable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
333 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
334 assert(lua_istable(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
335 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
336 SWIG_Lua_get_table(L,".set"); /* get the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
337 lua_remove(L,4); /* remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
338 #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
339 if (lua_isrotable(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
340 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
341 if (lua_istable(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
342 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
343 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
344 /* look for the key in the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
345 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
346 lua_rawget(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
347 lua_remove(L,4); /* remove .set */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
348 if (lua_iscfunction(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
349 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
350 lua_pushvalue(L,3); /* value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
351 lua_call(L,1,0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
352 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
353 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
354 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
355 else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
356 return 0; // Exits stoically if an invalid key is initialized.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
357 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
358 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
359 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
360 lua_settop(L,3); /* reset back to start */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
361 /* we now have the table, key & new value, so just set directly */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
362 lua_rawset(L,1); /* add direct */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
363 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
364 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
365
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
366 #if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
367 /* registering a module in lua. Pushes the module table on the stack. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
368 SWIGINTERN void SWIG_Lua_module_begin(lua_State* L,const char* name)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
369 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
370 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
371 lua_pushstring(L,name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
372 lua_newtable(L); /* the table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
373 /* add meta table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
374 lua_newtable(L); /* the meta table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
375 SWIG_Lua_add_function(L,"__index",SWIG_Lua_module_get);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
376 SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_module_set);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
377 lua_pushstring(L,".get");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
378 lua_newtable(L); /* the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
379 lua_rawset(L,-3); /* add .get into metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
380 lua_pushstring(L,".set");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
381 lua_newtable(L); /* the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
382 lua_rawset(L,-3); /* add .set into metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
383 lua_setmetatable(L,-2); /* sets meta table in module */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
384 #ifdef SWIG_LUA_MODULE_GLOBAL
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
385 /* If requested, install the module directly into the global namespace. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
386 lua_rawset(L,-3); /* add module into parent */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
387 SWIG_Lua_get_table(L,name); /* get the table back out */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
388 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
389 /* Do not install the module table as global name. The stack top has
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
390 the module table with the name below. We pop the top and replace
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
391 the name with it. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
392 lua_replace(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
393 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
394 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
395
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
396 /* ending the register */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
397 SWIGINTERN void SWIG_Lua_module_end(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
398 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
399 lua_pop(L,1); /* tidy stack (remove module) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
400 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
401
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
402 /* adding a linked variable to the module */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
403 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
404 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
405 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
406 lua_getmetatable(L,-1); /* get the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
407 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
408 SWIG_Lua_get_table(L,".get"); /* find the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
409 assert(lua_istable(L,-1)); /* should be a table: */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
410 SWIG_Lua_add_function(L,name,getFn);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
411 lua_pop(L,1); /* tidy stack (remove table) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
412 if (setFn) /* if there is a set fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
413 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
414 SWIG_Lua_get_table(L,".set"); /* find the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
415 assert(lua_istable(L,-1)); /* should be a table: */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
416 SWIG_Lua_add_function(L,name,setFn);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
417 lua_pop(L,1); /* tidy stack (remove table) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
418 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
419 lua_pop(L,1); /* tidy stack (remove meta) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
420 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
421 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
422
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
423 /* adding a function module */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
424 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
425 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
426 SWIG_Lua_add_function(L,name,fn);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
427 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
428
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
429 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
430 * global variable support code: namespaces
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
431 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
432
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
433 SWIGINTERN int SWIG_Lua_namespace_get(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
434 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
435 /* there should be 2 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
436 (1) table (not the meta table)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
437 (2) string name of the attribute
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
438 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
439 assert(lua_istable(L,-2)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
440 lua_getmetatable(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
441 assert(lua_istable(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
442 SWIG_Lua_get_table(L,".get"); /* find the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
443 assert(lua_istable(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
444 /* look for the key in the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
445 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
446 lua_rawget(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
447 lua_remove(L,-2); /* stack tidy, remove .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
448 if (lua_iscfunction(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
449 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
450 lua_call(L,0,1); /* 1 value in (userdata),1 out (result) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
451 lua_remove(L,-2); /* stack tidy, remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
452 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
453 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
454 lua_pop(L,1); /* remove whatever was there */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
455 /* ok, so try the .fn table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
456 SWIG_Lua_get_table(L,".fn"); /* find the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
457 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
458 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
459 lua_rawget(L,-2); /* look for the fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
460 lua_remove(L,-2); /* stack tidy, remove .fn table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
461 if (lua_isfunction(L,-1)) /* note: whether it's a C function or lua function */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
462 { /* found it so return the fn & let lua call it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
463 lua_remove(L,-2); /* stack tidy, remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
464 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
465 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
466 lua_pop(L,1); /* remove whatever was there */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
467 return 0;
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 SWIGINTERN int SWIG_Lua_namespace_set(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
471 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
472 /* there should be 3 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
473 (1) table (not the meta table)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
474 (2) string name of the attribute
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
475 (3) any for the new value
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
476 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
477
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
478 assert(lua_istable(L,1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
479 lua_getmetatable(L,1); /* get the meta table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
480 assert(lua_istable(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
481
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
482 SWIG_Lua_get_table(L,".set"); /* find the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
483 if (lua_istable(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
484 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
485 /* look for the key in the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
486 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
487 lua_rawget(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
488 if (lua_iscfunction(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
489 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
490 lua_pushvalue(L,3); /* value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
491 lua_call(L,1,0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
492 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
493 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
494 lua_pop(L,1); /* remove the value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
495 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
496 lua_pop(L,1); /* remove the value .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
497 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
498 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
499
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
500 SWIGINTERN void SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]); // forward declaration
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
501 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
502
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
503 /* helper function - register namespace methods and attributes into namespace */
2037
7a9477135943 Renamed Math.h -> OurMath.h (file resolution was sometimes ambiguous)
Nomad
parents: 1899
diff changeset
504 SWIGINTERN void SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* ns)
1899
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
505 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
506 int i = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
507 assert(lua_istable(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
508 /* There must be table at the top of the stack */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
509 SWIG_Lua_InstallConstants(L, ns->ns_constants);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
510
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
511 lua_getmetatable(L,-1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
512
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
513 /* add fns */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
514 for(i=0;ns->ns_attributes[i].name;i++){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
515 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
516 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
517
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
518 /* add methods to the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
519 SWIG_Lua_get_table(L,".fn"); /* find the .fn table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
520 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
521 for(i=0;ns->ns_methods[i].name;i++){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
522 SWIG_Lua_add_function(L,ns->ns_methods[i].name,ns->ns_methods[i].method);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
523 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
524 lua_pop(L,1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
525
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
526 /* clear stack - remove metatble */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
527 lua_pop(L,1);
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
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
531 /* helper function. creates namespace table and add it to module table */
2037
7a9477135943 Renamed Math.h -> OurMath.h (file resolution was sometimes ambiguous)
Nomad
parents: 1899
diff changeset
532 SWIGINTERN void SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns)
1899
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
533 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
534 assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
535 lua_checkstack(L,5);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
536 lua_pushstring(L, ns->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
537 lua_newtable(L); /* namespace itself */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
538 lua_newtable(L); /* metatable for namespace */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
539
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
540 /* add a table called ".get" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
541 lua_pushstring(L,".get");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
542 lua_newtable(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
543 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
544 /* add a table called ".set" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
545 lua_pushstring(L,".set");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
546 lua_newtable(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
547 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
548 /* add a table called ".fn" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
549 lua_pushstring(L,".fn");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
550 lua_newtable(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
551 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
552
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
553 /* add accessor fns for using the .get,.set&.fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
554 SWIG_Lua_add_function(L,"__index",SWIG_Lua_namespace_get);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
555 SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_namespace_set);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
556
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
557 lua_setmetatable(L,-2); /* set metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
558 lua_rawset(L,-3); /* add namespace to module table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
559 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
560 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
561 * global variable support code: classes
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
562 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
563
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
564 /* the class.get method, performs the lookup of class attributes */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
565 SWIGINTERN int SWIG_Lua_class_get(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
566 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
567 /* there should be 2 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
568 (1) userdata (not the meta table)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
569 (2) string name of the attribute
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
570 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
571 assert(lua_isuserdata(L,-2)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
572 lua_getmetatable(L,-2); /* get the meta table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
573 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
574 SWIG_Lua_get_table(L,".get"); /* find the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
575 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
576 /* look for the key in the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
577 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
578 lua_rawget(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
579 lua_remove(L,-2); /* stack tidy, remove .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
580 if (lua_iscfunction(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
581 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
582 lua_pushvalue(L,1); /* the userdata */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
583 lua_call(L,1,1); /* 1 value in (userdata),1 out (result) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
584 lua_remove(L,-2); /* stack tidy, remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
585 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
586 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
587 lua_pop(L,1); /* remove whatever was there */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
588 /* ok, so try the .fn table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
589 SWIG_Lua_get_table(L,".fn"); /* find the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
590 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
591 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
592 lua_rawget(L,-2); /* look for the fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
593 lua_remove(L,-2); /* stack tidy, remove .fn table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
594 if (lua_isfunction(L,-1)) /* note: if its a C function or lua function */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
595 { /* found it so return the fn & let lua call it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
596 lua_remove(L,-2); /* stack tidy, remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
597 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
598 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
599 lua_pop(L,1); /* remove whatever was there */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
600 /* NEW: looks for the __getitem() fn
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
601 this is a user provided get fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
602 SWIG_Lua_get_table(L,"__getitem"); /* find the __getitem fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
603 if (lua_iscfunction(L,-1)) /* if its there */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
604 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
605 lua_pushvalue(L,1); /* the userdata */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
606 lua_pushvalue(L,2); /* the parameter */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
607 lua_call(L,2,1); /* 2 value in (userdata),1 out (result) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
608 lua_remove(L,-2); /* stack tidy, remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
609 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
610 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
611 return 0; /* sorry not known */
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 /* the class.set method, performs the lookup of class attributes */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
615 SWIGINTERN int SWIG_Lua_class_set(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
616 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
617 /* there should be 3 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
618 (1) table (not the meta table)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
619 (2) string name of the attribute
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
620 (3) any for the new value
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
621 printf("SWIG_Lua_class_set %p(%s) '%s' %p(%s)\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
622 lua_topointer(L,1),lua_typename(L,lua_type(L,1)),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
623 lua_tostring(L,2),
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
624 lua_topointer(L,3),lua_typename(L,lua_type(L,3)));*/
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
625
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
626 assert(lua_isuserdata(L,1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
627 lua_getmetatable(L,1); /* get the meta table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
628 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
629
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
630 SWIG_Lua_get_table(L,".set"); /* find the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
631 if (lua_istable(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
632 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
633 /* look for the key in the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
634 lua_pushvalue(L,2); /* key */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
635 lua_rawget(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
636 if (lua_iscfunction(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
637 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
638 lua_pushvalue(L,1); /* userdata */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
639 lua_pushvalue(L,3); /* value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
640 lua_call(L,2,0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
641 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
642 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
643 lua_pop(L,1); /* remove the value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
644 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
645 lua_pop(L,1); /* remove the value .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
646 /* NEW: looks for the __setitem() fn
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
647 this is a user provided set fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
648 SWIG_Lua_get_table(L,"__setitem"); /* find the fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
649 if (lua_iscfunction(L,-1)) /* if its there */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
650 { /* found it so call the fn & return its value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
651 lua_pushvalue(L,1); /* the userdata */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
652 lua_pushvalue(L,2); /* the parameter */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
653 lua_pushvalue(L,3); /* the value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
654 lua_call(L,3,0); /* 3 values in ,0 out */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
655 lua_remove(L,-2); /* stack tidy, remove metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
656 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
657 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
658 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
659 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
660
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
661 /* the class.destruct method called by the interpreter */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
662 SWIGINTERN int SWIG_Lua_class_destruct(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
663 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
664 /* there should be 1 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
665 (1) userdata (not the meta table) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
666 swig_lua_userdata* usr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
667 swig_lua_class* clss;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
668 assert(lua_isuserdata(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
669 usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
670 /* if must be destroyed & has a destructor */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
671 if (usr->own) /* if must be destroyed */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
672 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
673 clss=(swig_lua_class*)usr->type->clientdata; /* get the class */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
674 if (clss && clss->destructor) /* there is a destroy fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
675 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
676 clss->destructor(usr->ptr); /* bye bye */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
677 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
678 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
679 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
680 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
681
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
682 /* the class.__tostring method called by the interpreter and print */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
683 SWIGINTERN int SWIG_Lua_class_tostring(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
684 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
685 /* there should be 1 param passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
686 (1) userdata (not the metatable) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
687 assert(lua_isuserdata(L,1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
688 unsigned long userData = (unsigned long)lua_touserdata(L,1); /* get the userdata address for later */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
689 lua_getmetatable(L,1); /* get the meta table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
690 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
691
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
692 lua_getfield(L, -1, ".type");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
693 const char* className = lua_tostring(L, -1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
694
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
695 char output[256];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
696 sprintf(output, "<%s userdata: %lX>", className, userData);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
697
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
698 lua_pushstring(L, (const char*)output);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
699 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
700 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
701
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
702 /* to manually disown some userdata */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
703 SWIGINTERN int SWIG_Lua_class_disown(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
704 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
705 /* there should be 1 params passed in
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
706 (1) userdata (not the meta table) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
707 swig_lua_userdata* usr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
708 assert(lua_isuserdata(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
709 usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
710
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
711 usr->own = 0; /* clear our ownership */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
712 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
713 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
714
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
715 /* Constructor proxy. Used when class name entry in module is not class constructor,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
716 but special table instead. */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
717 SWIGINTERN int SWIG_Lua_constructor_proxy(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
718 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
719 /* unlimited number of parameters
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
720 First one is our proxy table and we should remove it
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
721 Other we should pass to real constructor
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
722 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
723 assert(lua_istable(L,1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
724 lua_pushstring(L,".constructor");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
725 lua_rawget(L,1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
726 assert(!lua_isnil(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
727 lua_replace(L,1); /* replace our table with real constructor */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
728 lua_call(L,lua_gettop(L)-1,1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
729 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
730 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
731
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
732 /* gets the swig class registry (or creates it) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
733 SWIGINTERN void SWIG_Lua_get_class_registry(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
734 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
735 /* add this all into the swig registry: */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
736 lua_pushstring(L,"SWIG");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
737 lua_rawget(L,LUA_REGISTRYINDEX); /* get the registry */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
738 if (!lua_istable(L,-1)) /* not there */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
739 { /* must be first time, so add it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
740 lua_pop(L,1); /* remove the result */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
741 lua_pushstring(L,"SWIG");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
742 lua_newtable(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
743 lua_rawset(L,LUA_REGISTRYINDEX);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
744 /* then get it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
745 lua_pushstring(L,"SWIG");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
746 lua_rawget(L,LUA_REGISTRYINDEX);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
747 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
748 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
749
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
750 /* helper fn to get the classes metatable from the register */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
751 SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State* L,const char* cname)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
752 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
753 SWIG_Lua_get_class_registry(L); /* get the registry */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
754 lua_pushstring(L,cname); /* get the name */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
755 lua_rawget(L,-2); /* get it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
756 lua_remove(L,-2); /* tidy up (remove registry) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
757 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
758
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
759 /* helper add a variable to a registered class */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
760 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
761 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
762 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
763 SWIG_Lua_get_table(L,".get"); /* find the .get table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
764 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
765 SWIG_Lua_add_function(L,name,getFn);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
766 lua_pop(L,1); /* tidy stack (remove table) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
767 if (setFn)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
768 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
769 SWIG_Lua_get_table(L,".set"); /* find the .set table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
770 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
771 SWIG_Lua_add_function(L,name,setFn);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
772 lua_pop(L,1); /* tidy stack (remove table) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
773 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
774 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
775
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
776 /* helper to recursively add class static details (static attributes, operations and constants) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
777 SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State* L, swig_lua_class* clss)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
778 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
779 int i = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
780 /* The class namespace table must be on the top of the stack */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
781 assert(lua_istable(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
782 /* call all the base classes first: we can then override these later: */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
783 for(i=0;clss->bases[i];i++)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
784 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
785 SWIG_Lua_add_class_static_details(L,clss->bases[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
786 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
787
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
788 SWIG_Lua_add_namespace_details(L, &clss->cls_static);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
789 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
790
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
791 /* helper to recursively add class details (attributes & operations) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
792 SWIGINTERN void SWIG_Lua_add_class_details(lua_State* L,swig_lua_class* clss)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
793 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
794 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
795 /* call all the base classes first: we can then override these later: */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
796 for(i=0;clss->bases[i];i++)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
797 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
798 SWIG_Lua_add_class_details(L,clss->bases[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
799 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
800 /* add fns */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
801 for(i=0;clss->attributes[i].name;i++){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
802 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
803 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
804 /* add methods to the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
805 SWIG_Lua_get_table(L,".fn"); /* find the .fn table */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
806 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
807 for(i=0;clss->methods[i].name;i++){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
808 SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].method);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
809 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
810 lua_pop(L,1); /* tidy stack (remove table) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
811 /* add operator overloads
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
812 these look ANY method which start with "__" and assume they
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
813 are operator overloads & add them to the metatable
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
814 (this might mess up is someone defines a method __gc (the destructor)*/
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
815 for(i=0;clss->methods[i].name;i++){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
816 if (clss->methods[i].name[0]=='_' && clss->methods[i].name[1]=='_'){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
817 SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].method);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
818 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
819 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
820 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
821
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
822 /* set up the base classes pointers.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
823 Each class structure has a list of pointers to the base class structures.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
824 This function fills them.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
825 It cannot be done at compile time, as this will not work with hireachies
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
826 spread over more than one swig file.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
827 Therefore it must be done at runtime, querying the SWIG type system.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
828 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
829 SWIGINTERN void SWIG_Lua_init_base_class(lua_State* L,swig_lua_class* clss)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
830 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
831 int i=0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
832 swig_module_info* module=SWIG_GetModule(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
833 for(i=0;clss->base_names[i];i++)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
834 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
835 if (clss->bases[i]==0) /* not found yet */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
836 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
837 /* lookup and cache the base class */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
838 swig_type_info *info = SWIG_TypeQueryModule(module,module,clss->base_names[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
839 if (info) clss->bases[i] = (swig_lua_class *) info->clientdata;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
840 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
841 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
842 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
843
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
844 /* Register class static methods,attributes etc as well as constructor proxy */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
845 SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* clss)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
846 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
847 lua_checkstack(L,5); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
848 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
849 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
850
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
851 SWIG_Lua_namespace_register(L,&clss->cls_static);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
852
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
853 SWIG_Lua_get_table(L,clss->name); // Get namespace table back
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
854 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
855
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
856 /* add its constructor to module with the name of the class
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
857 so you can do MyClass(...) as well as new_MyClass(...)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
858 BUT only if a constructor is defined
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
859 (this overcomes the problem of pure virtual classes without constructors)*/
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
860 if (clss->constructor)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
861 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
862 SWIG_Lua_add_function(L,".constructor", clss->constructor);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
863 lua_getmetatable(L,-1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
864 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
865 SWIG_Lua_add_function(L,"__call", SWIG_Lua_constructor_proxy);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
866 lua_pop(L,1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
867 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
868
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
869 assert(lua_istable(L,-1)); /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
870 SWIG_Lua_add_class_static_details(L, clss);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
871
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
872 /* clear stack */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
873 lua_pop(L,1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
874 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
875
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
876 /* performs the entire class registration process */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
877 SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
878 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
879 SWIG_Lua_class_register_static(L,clss);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
880
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
881 SWIG_Lua_get_class_registry(L); /* get the registry */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
882 lua_pushstring(L,clss->name); /* get the name */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
883 lua_newtable(L); /* create the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
884 /* add string of class name called ".type" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
885 lua_pushstring(L,".type");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
886 lua_pushstring(L,clss->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
887 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
888 /* add a table called ".get" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
889 lua_pushstring(L,".get");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
890 lua_newtable(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
891 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
892 /* add a table called ".set" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
893 lua_pushstring(L,".set");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
894 lua_newtable(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
895 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
896 /* add a table called ".fn" */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
897 lua_pushstring(L,".fn");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
898 lua_newtable(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
899 /* add manual disown method */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
900 SWIG_Lua_add_function(L,"__disown",SWIG_Lua_class_disown);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
901 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
902 /* add accessor fns for using the .get,.set&.fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
903 SWIG_Lua_add_function(L,"__index",SWIG_Lua_class_get);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
904 SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_class_set);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
905 SWIG_Lua_add_function(L,"__gc",SWIG_Lua_class_destruct);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
906 /* add tostring method for better output */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
907 SWIG_Lua_add_function(L,"__tostring",SWIG_Lua_class_tostring);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
908 /* add it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
909 lua_rawset(L,-3); /* metatable into registry */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
910 lua_pop(L,1); /* tidy stack (remove registry) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
911
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
912 SWIG_Lua_get_class_metatable(L,clss->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
913 SWIG_Lua_add_class_details(L,clss); /* recursive adding of details (atts & ops) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
914 lua_pop(L,1); /* tidy stack (remove class metatable) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
915 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
916
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
917 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
918 * Class/structure conversion fns
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 to add metatable to new lua object */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
922 SWIGINTERN void _SWIG_Lua_AddMetatable(lua_State* L,swig_type_info *type)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
923 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
924 if (type->clientdata) /* there is clientdata: so add the metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
925 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
926 SWIG_Lua_get_class_metatable(L,((swig_lua_class*)(type->clientdata))->name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
927 if (lua_istable(L,-1))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
928 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
929 lua_setmetatable(L,-2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
930 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
931 else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
932 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
933 lua_pop(L,1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
934 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
935 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
936 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
937
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
938 /* pushes a new object into the lua stack */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
939 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
940 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
941 swig_lua_userdata* usr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
942 if (!ptr){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
943 lua_pushnil(L);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
944 return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
945 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
946 usr=(swig_lua_userdata*)lua_newuserdata(L,sizeof(swig_lua_userdata)); /* get data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
947 usr->ptr=ptr; /* set the ptr */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
948 usr->type=type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
949 usr->own=own;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
950 #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
951 _SWIG_Lua_AddMetatable(L,type); /* add metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
952 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
953 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
954
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
955 /* 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
956 (if possible) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
957 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
958 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
959 swig_lua_userdata* usr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
960 swig_cast_info *cast;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
961 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
962 usr=(swig_lua_userdata*)lua_touserdata(L,index); /* get data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
963 if (usr)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
964 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
965 if (flags & SWIG_POINTER_DISOWN) /* must disown the object */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
966 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
967 usr->own=0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
968 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
969 if (!type) /* special cast void*, no casting fn */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
970 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
971 *ptr=usr->ptr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
972 return SWIG_OK; /* ok */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
973 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
974 cast=SWIG_TypeCheckStruct(usr->type,type); /* performs normal type checking */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
975 if (cast)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
976 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
977 int newmemory = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
978 *ptr=SWIG_TypeCast(cast,usr->ptr,&newmemory);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
979 assert(!newmemory); /* newmemory handling not yet implemented */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
980 return SWIG_OK; /* ok */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
981 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
982 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
983 return SWIG_ERROR; /* error */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
984 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
985
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
986 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
987 int argnum,const char* func_name){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
988 void* result;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
989 if (!SWIG_IsOK(SWIG_ConvertPtr(L,index,&result,type,flags))){
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
990 luaL_error (L,"Error in %s, expected a %s at argument number %d\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
991 func_name,(type && type->str)?type->str:"void*",argnum);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
992 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
993 return result;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
994 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
995
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
996 /* pushes a packed userdata. user for member fn pointers only */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
997 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
998 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
999 swig_lua_rawdata* raw;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1000 assert(ptr); /* not acceptable to pass in a NULL value */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1001 raw=(swig_lua_rawdata*)lua_newuserdata(L,sizeof(swig_lua_rawdata)-1+size); /* alloc data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1002 raw->type=type;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1003 raw->own=0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1004 memcpy(raw->data,ptr,size); /* copy the data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1005 _SWIG_Lua_AddMetatable(L,type); /* add metatable */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1006 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1007
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1008 /* converts a packed userdata. user for member fn pointers only */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1009 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
1010 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1011 swig_lua_rawdata* raw;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1012 raw=(swig_lua_rawdata*)lua_touserdata(L,index); /* get data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1013 if (!raw) return SWIG_ERROR; /* error */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1014 if (type==0 || type==raw->type) /* void* or identical type */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1015 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1016 memcpy(ptr,raw->data,size); /* copy it */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1017 return SWIG_OK; /* ok */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1018 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1019 return SWIG_ERROR; /* error */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1020 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1021
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1022 /* a function to get the typestring of a piece of data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1023 SWIGRUNTIME const char *SWIG_Lua_typename(lua_State *L, int tp)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1024 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1025 swig_lua_userdata* usr;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1026 if (lua_isuserdata(L,tp))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1027 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1028 usr=(swig_lua_userdata*)lua_touserdata(L,tp); /* get data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1029 if (usr && usr->type && usr->type->str)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1030 return usr->type->str;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1031 return "userdata (unknown type)";
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1032 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1033 return lua_typename(L,lua_type(L,tp));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1034 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1035
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1036 /* lua callable function to get the userdata's type */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1037 SWIGRUNTIME int SWIG_Lua_type(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1038 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1039 lua_pushstring(L,SWIG_Lua_typename(L,1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1040 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1041 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1042
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1043 /* lua callable function to compare userdata's value
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1044 the issue is that two userdata may point to the same thing
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1045 but to lua, they are different objects */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1046 SWIGRUNTIME int SWIG_Lua_equal(lua_State* L)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1047 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1048 int result;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1049 swig_lua_userdata *usr1,*usr2;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1050 if (!lua_isuserdata(L,1) || !lua_isuserdata(L,2)) /* just in case */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1051 return 0; /* nil reply */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1052 usr1=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1053 usr2=(swig_lua_userdata*)lua_touserdata(L,2); /* get data */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1054 /*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
1055 result=(usr1->ptr==usr2->ptr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1056 lua_pushboolean(L,result);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1057 return 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1058 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1059
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1060 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1061 * global variable support code: class/struct typemap functions
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1062 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1063
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1064 #if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1065 /* Install Constants */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1066 SWIGINTERN void
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1067 SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1068 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1069 for (i = 0; constants[i].type; i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1070 switch(constants[i].type) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1071 case SWIG_LUA_INT:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1072 lua_pushstring(L,constants[i].name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1073 lua_pushnumber(L,(lua_Number)constants[i].lvalue);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1074 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1075 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1076 case SWIG_LUA_FLOAT:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1077 lua_pushstring(L,constants[i].name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1078 lua_pushnumber(L,(lua_Number)constants[i].dvalue);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1079 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1080 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1081 case SWIG_LUA_CHAR:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1082 lua_pushstring(L,constants[i].name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1083 lua_pushfstring(L,"%c",(char)constants[i].lvalue);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1084 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1085 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1086 case SWIG_LUA_STRING:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1087 lua_pushstring(L,constants[i].name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1088 lua_pushstring(L,(char *) constants[i].pvalue);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1089 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1090 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1091 case SWIG_LUA_POINTER:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1092 lua_pushstring(L,constants[i].name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1093 SWIG_NewPointerObj(L,constants[i].pvalue, *(constants[i]).ptype,0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1094 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1095 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1096 case SWIG_LUA_BINARY:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1097 lua_pushstring(L,constants[i].name);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1098 SWIG_NewMemberObj(L,constants[i].pvalue,constants[i].lvalue,*(constants[i]).ptype);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1099 lua_rawset(L,-3);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1100 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1101 default:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1102 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1103 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1104 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1105 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1106 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1107
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1108 /* -----------------------------------------------------------------------------
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1109 * executing lua code from within the wrapper
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1110 * ----------------------------------------------------------------------------- */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1111
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1112 #ifndef SWIG_DOSTRING_FAIL /* Allows redefining of error function */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1113 #define SWIG_DOSTRING_FAIL(S) fprintf(stderr,"%s\n",S)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1114 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1115 /* 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
1116 Unfortunately lua keeps changing its APIs, so we need a conditional compile
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1117 In lua 5.0.X its lua_dostring()
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1118 In lua 5.1.X its luaL_dostring()
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1119 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1120 SWIGINTERN int
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1121 SWIG_Lua_dostring(lua_State *L, const char* str) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1122 int ok,top;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1123 if (str==0 || str[0]==0) return 0; /* nothing to do */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1124 top=lua_gettop(L); /* save stack */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1125 #if (defined(LUA_VERSION_NUM) && (LUA_VERSION_NUM>=501))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1126 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
1127 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1128 ok=lua_dostring(L,str); /* might be lua 5.0.x, using lua_dostring */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1129 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1130 if (ok!=0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1131 SWIG_DOSTRING_FAIL(lua_tostring(L,-1));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1132 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1133 lua_settop(L,top); /* restore the stack */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1134 return ok;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1135 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1136
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1137 #ifdef __cplusplus
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1138 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1139 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1140
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1141 /* ------------------------------ end luarun.swg ------------------------------ */