annotate lib/swig/swigwin-2.0.11/Lib/lua/luarun.swg @ 1899:b3009adc0e2f

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