16
16
#include <assert.h> /* for a few sanity tests */
18
18
/* -----------------------------------------------------------------------------
20
* ----------------------------------------------------------------------------- */
22
#define SWIG_LUA_FLAVOR_LUA 1
23
#define SWIG_LUA_FLAVOR_ELUA 2
24
#define SWIG_LUA_FLAVOR_ELUAC 3
26
#if !defined(SWIG_LUA_TARGET)
27
# error SWIG_LUA_TARGET not defined
30
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
31
# define SWIG_LUA_CONSTTAB_INT(B, C) LSTRKEY(B), LNUMVAL(C)
32
# define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C)
33
# define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C)
34
# define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C)
35
#else /* SWIG_LUA_FLAVOR_LUA */
36
# define SWIG_LUA_CONSTTAB_INT(B, C) SWIG_LUA_INT, (char *)B, (long)C, 0, 0, 0
37
# define SWIG_LUA_CONSTTAB_FLOAT(B, C) SWIG_LUA_FLOAT, (char *)B, 0, (double)C, 0, 0
38
# define SWIG_LUA_CONSTTAB_STRING(B, C) SWIG_LUA_STRING, (char *)B, 0, 0, (void *)C, 0
39
# define SWIG_LUA_CONSTTAB_CHAR(B, C) SWIG_LUA_CHAR, (char *)B, (long)C, 0, 0, 0
42
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
43
# define LRO_STRVAL(v) {{.p = (char *) v}, LUA_TSTRING}
44
# define LSTRVAL LRO_STRVAL
47
/* -----------------------------------------------------------------------------
48
* compatibility defines
49
* ----------------------------------------------------------------------------- */
51
/* History of Lua C API length functions: In Lua 5.0 (and before?)
52
there was "lua_strlen". In Lua 5.1, this was renamed "lua_objlen",
53
but a compatibility define of "lua_strlen" was added. In Lua 5.2,
54
this function was again renamed, to "lua_rawlen" (to emphasize that
55
it doesn't call the "__len" metamethod), and the compatibility
56
define of lua_strlen was removed. All SWIG uses have been updated
57
to "lua_rawlen", and we add our own defines of that here for older
59
#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501
60
# define lua_rawlen lua_strlen
61
#elif LUA_VERSION_NUM == 501
62
# define lua_rawlen lua_objlen
66
/* lua_pushglobaltable is the recommended "future-proof" way to get
67
the global table for Lua 5.2 and later. Here we define
68
lua_pushglobaltable ourselves for Lua versions before 5.2. */
69
#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
70
# define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
74
/* -----------------------------------------------------------------------------
19
75
* global swig types
20
76
* ----------------------------------------------------------------------------- */
21
77
/* Constant table */
181
237
lua_tostring(L,2));
183
239
/* get the metatable */
184
assert(lua_istable(L,1)); /* just in case */
240
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
241
assert(lua_isrotable(L,1)); /* just in case */
243
assert(lua_istable(L,1)); /* default Lua action */
185
245
lua_getmetatable(L,1); /* get the metatable */
186
assert(lua_istable(L,-1)); /* just in case */
246
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
247
assert(lua_isrotable(L,-1)); /* just in case */
249
assert(lua_istable(L,-1));
187
251
SWIG_Lua_get_table(L,".get"); /* get the .get table */
188
252
lua_remove(L,3); /* remove metatable */
253
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
254
if (lua_isrotable(L,-1))
189
256
if (lua_istable(L,-1))
191
259
/* look for the key in the .get table */
192
260
lua_pushvalue(L,2); /* key */
213
281
(3) any for the new value
215
283
/* get the metatable */
216
assert(lua_istable(L,1)); /* just in case */
284
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
285
assert(lua_isrotable(L,1)); /* just in case */
287
assert(lua_istable(L,1)); /* default Lua action */
217
289
lua_getmetatable(L,1); /* get the metatable */
218
assert(lua_istable(L,-1)); /* just in case */
290
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
291
assert(lua_isrotable(L,-1)); /* just in case */
293
assert(lua_istable(L,-1));
219
295
SWIG_Lua_get_table(L,".set"); /* get the .set table */
220
296
lua_remove(L,4); /* remove metatable */
297
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
298
if (lua_isrotable(L,-1))
221
300
if (lua_istable(L,-1))
223
303
/* look for the key in the .set table */
224
304
lua_pushvalue(L,2); /* key */
510
/* the class.__tostring method called by the interpreter and print */
511
SWIGINTERN int SWIG_Lua_class_tostring(lua_State* L)
513
/* there should be 1 param passed in
514
(1) userdata (not the metatable) */
515
assert(lua_isuserdata(L,1)); /* just in case */
516
unsigned long userData = (unsigned long)lua_touserdata(L,1); /* get the userdata address for later */
517
lua_getmetatable(L,1); /* get the meta table */
518
assert(lua_istable(L,-1)); /* just in case */
520
lua_getfield(L, -1, ".type");
521
const char* className = lua_tostring(L, -1);
524
sprintf(output, "<%s userdata: %lX>", className, userData);
526
lua_pushstring(L, (const char*)output);
530
/* to manually disown some userdata */
531
SWIGINTERN int SWIG_Lua_class_disown(lua_State* L)
533
/* there should be 1 params passed in
534
(1) userdata (not the meta table) */
535
swig_lua_userdata* usr;
536
assert(lua_isuserdata(L,-1)); /* just in case */
537
usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */
539
usr->own = 0; /* clear our ownership */
423
543
/* gets the swig class registry (or creates it) */
424
544
SWIGINTERN void SWIG_Lua_get_class_registry(lua_State* L)
545
665
/* add a table called ".fn" */
546
666
lua_pushstring(L,".fn");
668
/* add manual disown method */
669
SWIG_Lua_add_function(L,"__disown",SWIG_Lua_class_disown);
548
670
lua_rawset(L,-3);
549
671
/* add accessor fns for using the .get,.set&.fn */
550
672
SWIG_Lua_add_function(L,"__index",SWIG_Lua_class_get);
551
673
SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_class_set);
552
674
SWIG_Lua_add_function(L,"__gc",SWIG_Lua_class_destruct);
675
/* add tostring method for better output */
676
SWIG_Lua_add_function(L,"__tostring",SWIG_Lua_class_tostring);
554
678
lua_rawset(L,-3); /* metatable into registry */
555
679
lua_pop(L,1); /* tidy stack (remove registry) */