fix little endian vs big endian in the macros... again... but this time correct
[RRG-proxmark3.git] / client / src / pm3_luawrap.c
blob0b4cd024b8d43b3874f7a6483d379a8c108005ef
1 /* ----------------------------------------------------------------------------
2 * This file was automatically generated by SWIG (http://www.swig.org).
3 * Version 4.0.1
5 * This file is not intended to be easily readable and contains a number of
6 * coding conventions designed to improve portability and efficiency. Do not make
7 * changes to this file unless you know what you are doing--modify the SWIG
8 * interface file instead.
9 * ----------------------------------------------------------------------------- */
12 #ifndef SWIGLUA
13 #define SWIGLUA
14 #endif
16 #define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_LUA
17 #define SWIG_LUA_MODULE_GLOBAL
19 /* -----------------------------------------------------------------------------
20 * This section contains generic SWIG labels for method/variable
21 * declarations/attributes, and other compiler dependent labels.
22 * ----------------------------------------------------------------------------- */
24 /* template workaround for compilers that cannot correctly implement the C++ standard */
25 #ifndef SWIGTEMPLATEDISAMBIGUATOR
26 # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
27 # define SWIGTEMPLATEDISAMBIGUATOR template
28 # elif defined(__HP_aCC)
29 /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
30 /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
31 # define SWIGTEMPLATEDISAMBIGUATOR template
32 # else
33 # define SWIGTEMPLATEDISAMBIGUATOR
34 # endif
35 #endif
37 /* inline attribute */
38 #ifndef SWIGINLINE
39 # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
40 # define SWIGINLINE inline
41 # else
42 # define SWIGINLINE
43 # endif
44 #endif
46 /* attribute recognised by some compilers to avoid 'unused' warnings */
47 #ifndef SWIGUNUSED
48 # if defined(__GNUC__)
49 # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
50 # define SWIGUNUSED __attribute__ ((__unused__))
51 # else
52 # define SWIGUNUSED
53 # endif
54 # elif defined(__ICC)
55 # define SWIGUNUSED __attribute__ ((__unused__))
56 # else
57 # define SWIGUNUSED
58 # endif
59 #endif
61 #ifndef SWIG_MSC_UNSUPPRESS_4505
62 # if defined(_MSC_VER)
63 # pragma warning(disable : 4505) /* unreferenced local function has been removed */
64 # endif
65 #endif
67 #ifndef SWIGUNUSEDPARM
68 # ifdef __cplusplus
69 # define SWIGUNUSEDPARM(p)
70 # else
71 # define SWIGUNUSEDPARM(p) p SWIGUNUSED
72 # endif
73 #endif
75 /* internal SWIG method */
76 #ifndef SWIGINTERN
77 # define SWIGINTERN static SWIGUNUSED
78 #endif
80 /* internal inline SWIG method */
81 #ifndef SWIGINTERNINLINE
82 # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
83 #endif
85 /* exporting methods */
86 #if defined(__GNUC__)
87 # if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
88 # ifndef GCC_HASCLASSVISIBILITY
89 # define GCC_HASCLASSVISIBILITY
90 # endif
91 # endif
92 #endif
94 #ifndef SWIGEXPORT
95 # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
96 # if defined(STATIC_LINKED)
97 # define SWIGEXPORT
98 # else
99 # define SWIGEXPORT __declspec(dllexport)
100 # endif
101 # else
102 # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
103 # define SWIGEXPORT __attribute__ ((visibility("default")))
104 # else
105 # define SWIGEXPORT
106 # endif
107 # endif
108 #endif
110 /* calling conventions for Windows */
111 #ifndef SWIGSTDCALL
112 # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
113 # define SWIGSTDCALL __stdcall
114 # else
115 # define SWIGSTDCALL
116 # endif
117 #endif
119 /* Deal with Microsoft's attempt at deprecating C standard runtime functions */
120 #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
121 # define _CRT_SECURE_NO_DEPRECATE
122 #endif
124 /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
125 #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
126 # define _SCL_SECURE_NO_DEPRECATE
127 #endif
129 /* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */
130 #if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES)
131 # define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
132 #endif
134 /* Intel's compiler complains if a variable which was never initialised is
135 * cast to void, which is a common idiom which we use to indicate that we
136 * are aware a variable isn't used. So we just silence that warning.
137 * See: https://github.com/swig/swig/issues/192 for more discussion.
139 #ifdef __INTEL_COMPILER
140 # pragma warning disable 592
141 #endif
143 /* -----------------------------------------------------------------------------
144 * swigrun.swg
146 * This file contains generic C API SWIG runtime support for pointer
147 * type checking.
148 * ----------------------------------------------------------------------------- */
150 /* This should only be incremented when either the layout of swig_type_info changes,
151 or for whatever reason, the runtime changes incompatibly */
152 #define SWIG_RUNTIME_VERSION "4"
154 /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */
155 #ifdef SWIG_TYPE_TABLE
156 # define SWIG_QUOTE_STRING(x) #x
157 # define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x)
158 # define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE)
159 #else
160 # define SWIG_TYPE_TABLE_NAME
161 #endif
164 You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for
165 creating a static or dynamic library from the SWIG runtime code.
166 In 99.9% of the cases, SWIG just needs to declare them as 'static'.
168 But only do this if strictly necessary, ie, if you have problems
169 with your compiler or suchlike.
172 #ifndef SWIGRUNTIME
173 # define SWIGRUNTIME SWIGINTERN
174 #endif
176 #ifndef SWIGRUNTIMEINLINE
177 # define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE
178 #endif
180 /* Generic buffer size */
181 #ifndef SWIG_BUFFER_SIZE
182 # define SWIG_BUFFER_SIZE 1024
183 #endif
185 /* Flags for pointer conversions */
186 #define SWIG_POINTER_DISOWN 0x1
187 #define SWIG_CAST_NEW_MEMORY 0x2
188 #define SWIG_POINTER_NO_NULL 0x4
190 /* Flags for new pointer objects */
191 #define SWIG_POINTER_OWN 0x1
195 Flags/methods for returning states.
197 The SWIG conversion methods, as ConvertPtr, return an integer
198 that tells if the conversion was successful or not. And if not,
199 an error code can be returned (see swigerrors.swg for the codes).
201 Use the following macros/flags to set or process the returning
202 states.
204 In old versions of SWIG, code such as the following was usually written:
206 if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) {
207 // success code
208 } else {
209 //fail code
212 Now you can be more explicit:
214 int res = SWIG_ConvertPtr(obj,vptr,ty.flags);
215 if (SWIG_IsOK(res)) {
216 // success code
217 } else {
218 // fail code
221 which is the same really, but now you can also do
223 Type *ptr;
224 int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags);
225 if (SWIG_IsOK(res)) {
226 // success code
227 if (SWIG_IsNewObj(res) {
229 delete *ptr;
230 } else {
233 } else {
234 // fail code
237 I.e., now SWIG_ConvertPtr can return new objects and you can
238 identify the case and take care of the deallocation. Of course that
239 also requires SWIG_ConvertPtr to return new result values, such as
241 int SWIG_ConvertPtr(obj, ptr,...) {
242 if (<obj is ok>) {
243 if (<need new object>) {
244 *ptr = <ptr to new allocated object>;
245 return SWIG_NEWOBJ;
246 } else {
247 *ptr = <ptr to old object>;
248 return SWIG_OLDOBJ;
250 } else {
251 return SWIG_BADOBJ;
255 Of course, returning the plain '0(success)/-1(fail)' still works, but you can be
256 more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the
257 SWIG errors code.
259 Finally, if the SWIG_CASTRANK_MODE is enabled, the result code
260 allows to return the 'cast rank', for example, if you have this
262 int food(double)
263 int fooi(int);
265 and you call
267 food(1) // cast rank '1' (1 -> 1.0)
268 fooi(1) // cast rank '0'
270 just use the SWIG_AddCast()/SWIG_CheckState()
273 #define SWIG_OK (0)
274 #define SWIG_ERROR (-1)
275 #define SWIG_IsOK(r) (r >= 0)
276 #define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError)
278 /* The CastRankLimit says how many bits are used for the cast rank */
279 #define SWIG_CASTRANKLIMIT (1 << 8)
280 /* The NewMask denotes the object was created (using new/malloc) */
281 #define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1)
282 /* The TmpMask is for in/out typemaps that use temporal objects */
283 #define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1)
284 /* Simple returning values */
285 #define SWIG_BADOBJ (SWIG_ERROR)
286 #define SWIG_OLDOBJ (SWIG_OK)
287 #define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK)
288 #define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK)
289 /* Check, add and del mask methods */
290 #define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r)
291 #define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r)
292 #define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK))
293 #define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r)
294 #define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r)
295 #define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK))
297 /* Cast-Rank Mode */
298 #if defined(SWIG_CASTRANK_MODE)
299 # ifndef SWIG_TypeRank
300 # define SWIG_TypeRank unsigned long
301 # endif
302 # ifndef SWIG_MAXCASTRANK /* Default cast allowed */
303 # define SWIG_MAXCASTRANK (2)
304 # endif
305 # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1)
306 # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK)
307 SWIGINTERNINLINE int SWIG_AddCast(int r) {
308 return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r;
310 SWIGINTERNINLINE int SWIG_CheckState(int r) {
311 return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0;
313 #else /* no cast-rank mode */
314 # define SWIG_AddCast(r) (r)
315 # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0)
316 #endif
319 #include <string.h>
321 #ifdef __cplusplus
322 extern "C" {
323 #endif
325 typedef void *(*swig_converter_func)(void *, int *);
326 typedef struct swig_type_info *(*swig_dycast_func)(void **);
328 /* Structure to store information on one type */
329 typedef struct swig_type_info {
330 const char *name; /* mangled name of this type */
331 const char *str; /* human readable name of this type */
332 swig_dycast_func dcast; /* dynamic cast function down a hierarchy */
333 struct swig_cast_info *cast; /* linked list of types that can cast into this type */
334 void *clientdata; /* language specific type data */
335 int owndata; /* flag if the structure owns the clientdata */
336 } swig_type_info;
338 /* Structure to store a type and conversion function used for casting */
339 typedef struct swig_cast_info {
340 swig_type_info *type; /* pointer to type that is equivalent to this type */
341 swig_converter_func converter; /* function to cast the void pointers */
342 struct swig_cast_info *next; /* pointer to next cast in linked list */
343 struct swig_cast_info *prev; /* pointer to the previous cast */
344 } swig_cast_info;
346 /* Structure used to store module information
347 * Each module generates one structure like this, and the runtime collects
348 * all of these structures and stores them in a circularly linked list.*/
349 typedef struct swig_module_info {
350 swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */
351 size_t size; /* Number of types in this module */
352 struct swig_module_info *next; /* Pointer to next element in circularly linked list */
353 swig_type_info **type_initial; /* Array of initially generated type structures */
354 swig_cast_info **cast_initial; /* Array of initially generated casting structures */
355 void *clientdata; /* Language specific module data */
356 } swig_module_info;
359 Compare two type names skipping the space characters, therefore
360 "char*" == "char *" and "Class<int>" == "Class<int >", etc.
362 Return 0 when the two name types are equivalent, as in
363 strncmp, but skipping ' '.
365 SWIGRUNTIME int
366 SWIG_TypeNameComp(const char *f1, const char *l1,
367 const char *f2, const char *l2) {
368 for (; (f1 != l1) && (f2 != l2); ++f1, ++f2) {
369 while ((*f1 == ' ') && (f1 != l1)) ++f1;
370 while ((*f2 == ' ') && (f2 != l2)) ++f2;
371 if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1;
373 return (int)((l1 - f1) - (l2 - f2));
377 Check type equivalence in a name list like <name1>|<name2>|...
378 Return 0 if equal, -1 if nb < tb, 1 if nb > tb
380 SWIGRUNTIME int
381 SWIG_TypeCmp(const char *nb, const char *tb) {
382 int equiv = 1;
383 const char *te = tb + strlen(tb);
384 const char *ne = nb;
385 while (equiv != 0 && *ne) {
386 for (nb = ne; *ne; ++ne) {
387 if (*ne == '|') break;
389 equiv = SWIG_TypeNameComp(nb, ne, tb, te);
390 if (*ne) ++ne;
392 return equiv;
396 Check type equivalence in a name list like <name1>|<name2>|...
397 Return 0 if not equal, 1 if equal
399 SWIGRUNTIME int
400 SWIG_TypeEquiv(const char *nb, const char *tb) {
401 return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0;
405 Check the typename
407 SWIGRUNTIME swig_cast_info *
408 SWIG_TypeCheck(const char *c, swig_type_info *ty) {
409 if (ty) {
410 swig_cast_info *iter = ty->cast;
411 while (iter) {
412 if (strcmp(iter->type->name, c) == 0) {
413 if (iter == ty->cast)
414 return iter;
415 /* Move iter to the top of the linked list */
416 iter->prev->next = iter->next;
417 if (iter->next)
418 iter->next->prev = iter->prev;
419 iter->next = ty->cast;
420 iter->prev = 0;
421 if (ty->cast) ty->cast->prev = iter;
422 ty->cast = iter;
423 return iter;
425 iter = iter->next;
428 return 0;
432 Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison
434 SWIGRUNTIME swig_cast_info *
435 SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) {
436 if (ty) {
437 swig_cast_info *iter = ty->cast;
438 while (iter) {
439 if (iter->type == from) {
440 if (iter == ty->cast)
441 return iter;
442 /* Move iter to the top of the linked list */
443 iter->prev->next = iter->next;
444 if (iter->next)
445 iter->next->prev = iter->prev;
446 iter->next = ty->cast;
447 iter->prev = 0;
448 if (ty->cast) ty->cast->prev = iter;
449 ty->cast = iter;
450 return iter;
452 iter = iter->next;
455 return 0;
459 Cast a pointer up an inheritance hierarchy
461 SWIGRUNTIMEINLINE void *
462 SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) {
463 return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory);
467 Dynamic pointer casting. Down an inheritance hierarchy
469 SWIGRUNTIME swig_type_info *
470 SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) {
471 swig_type_info *lastty = ty;
472 if (!ty || !ty->dcast) return ty;
473 while (ty && (ty->dcast)) {
474 ty = (*ty->dcast)(ptr);
475 if (ty) lastty = ty;
477 return lastty;
481 Return the name associated with this type
483 SWIGRUNTIMEINLINE const char *
484 SWIG_TypeName(const swig_type_info *ty) {
485 return ty->name;
489 Return the pretty name associated with this type,
490 that is an unmangled type name in a form presentable to the user.
492 SWIGRUNTIME const char *
493 SWIG_TypePrettyName(const swig_type_info *type) {
494 /* The "str" field contains the equivalent pretty names of the
495 type, separated by vertical-bar characters. We choose
496 to print the last name, as it is often (?) the most
497 specific. */
498 if (!type) return NULL;
499 if (type->str != NULL) {
500 const char *last_name = type->str;
501 const char *s;
502 for (s = type->str; *s; s++)
503 if (*s == '|') last_name = s + 1;
504 return last_name;
505 } else
506 return type->name;
510 Set the clientdata field for a type
512 SWIGRUNTIME void
513 SWIG_TypeClientData(swig_type_info *ti, void *clientdata) {
514 swig_cast_info *cast = ti->cast;
515 /* if (ti->clientdata == clientdata) return; */
516 ti->clientdata = clientdata;
518 while (cast) {
519 if (!cast->converter) {
520 swig_type_info *tc = cast->type;
521 if (!tc->clientdata) {
522 SWIG_TypeClientData(tc, clientdata);
525 cast = cast->next;
528 SWIGRUNTIME void
529 SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) {
530 SWIG_TypeClientData(ti, clientdata);
531 ti->owndata = 1;
535 Search for a swig_type_info structure only by mangled name
536 Search is a O(log #types)
538 We start searching at module start, and finish searching when start == end.
539 Note: if start == end at the beginning of the function, we go all the way around
540 the circular list.
542 SWIGRUNTIME swig_type_info *
543 SWIG_MangledTypeQueryModule(swig_module_info *start,
544 swig_module_info *end,
545 const char *name) {
546 swig_module_info *iter = start;
547 do {
548 if (iter->size) {
549 size_t l = 0;
550 size_t r = iter->size - 1;
551 do {
552 /* since l+r >= 0, we can (>> 1) instead (/ 2) */
553 size_t i = (l + r) >> 1;
554 const char *iname = iter->types[i]->name;
555 if (iname) {
556 int compare = strcmp(name, iname);
557 if (compare == 0) {
558 return iter->types[i];
559 } else if (compare < 0) {
560 if (i) {
561 r = i - 1;
562 } else {
563 break;
565 } else if (compare > 0) {
566 l = i + 1;
568 } else {
569 break; /* should never happen */
571 } while (l <= r);
573 iter = iter->next;
574 } while (iter != end);
575 return 0;
579 Search for a swig_type_info structure for either a mangled name or a human readable name.
580 It first searches the mangled names of the types, which is a O(log #types)
581 If a type is not found it then searches the human readable names, which is O(#types).
583 We start searching at module start, and finish searching when start == end.
584 Note: if start == end at the beginning of the function, we go all the way around
585 the circular list.
587 SWIGRUNTIME swig_type_info *
588 SWIG_TypeQueryModule(swig_module_info *start,
589 swig_module_info *end,
590 const char *name) {
591 /* STEP 1: Search the name field using binary search */
592 swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name);
593 if (ret) {
594 return ret;
595 } else {
596 /* STEP 2: If the type hasn't been found, do a complete search
597 of the str field (the human readable name) */
598 swig_module_info *iter = start;
599 do {
600 size_t i = 0;
601 for (; i < iter->size; ++i) {
602 if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name)))
603 return iter->types[i];
605 iter = iter->next;
606 } while (iter != end);
609 /* neither found a match */
610 return 0;
614 Pack binary data into a string
616 SWIGRUNTIME char *
617 SWIG_PackData(char *c, void *ptr, size_t sz) {
618 static const char hex[17] = "0123456789abcdef";
619 const unsigned char *u = (unsigned char *) ptr;
620 const unsigned char *eu = u + sz;
621 for (; u != eu; ++u) {
622 unsigned char uu = *u;
623 *(c++) = hex[(uu & 0xf0) >> 4];
624 *(c++) = hex[uu & 0xf];
626 return c;
630 Unpack binary data from a string
632 SWIGRUNTIME const char *
633 SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
634 unsigned char *u = (unsigned char *) ptr;
635 const unsigned char *eu = u + sz;
636 for (; u != eu; ++u) {
637 char d = *(c++);
638 unsigned char uu;
639 if ((d >= '0') && (d <= '9'))
640 uu = (unsigned char)((d - '0') << 4);
641 else if ((d >= 'a') && (d <= 'f'))
642 uu = (unsigned char)((d - ('a' - 10)) << 4);
643 else
644 return (char *) 0;
645 d = *(c++);
646 if ((d >= '0') && (d <= '9'))
647 uu |= (unsigned char)(d - '0');
648 else if ((d >= 'a') && (d <= 'f'))
649 uu |= (unsigned char)(d - ('a' - 10));
650 else
651 return (char *) 0;
652 *u = uu;
654 return c;
658 Pack 'void *' into a string buffer.
660 SWIGRUNTIME char *
661 SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) {
662 char *r = buff;
663 if ((2 * sizeof(void *) + 2) > bsz) return 0;
664 *(r++) = '_';
665 r = SWIG_PackData(r, &ptr, sizeof(void *));
666 if (strlen(name) + 1 > (bsz - (r - buff))) return 0;
667 strcpy(r, name);
668 return buff;
671 SWIGRUNTIME const char *
672 SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) {
673 if (*c != '_') {
674 if (strcmp(c, "NULL") == 0) {
675 *ptr = (void *) 0;
676 return name;
677 } else {
678 return 0;
681 return SWIG_UnpackData(++c, ptr, sizeof(void *));
684 SWIGRUNTIME char *
685 SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) {
686 char *r = buff;
687 size_t lname = (name ? strlen(name) : 0);
688 if ((2 * sz + 2 + lname) > bsz) return 0;
689 *(r++) = '_';
690 r = SWIG_PackData(r, ptr, sz);
691 if (lname) {
692 strncpy(r, name, lname + 1);
693 } else {
694 *r = 0;
696 return buff;
699 SWIGRUNTIME const char *
700 SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {
701 if (*c != '_') {
702 if (strcmp(c, "NULL") == 0) {
703 memset(ptr, 0, sz);
704 return name;
705 } else {
706 return 0;
709 return SWIG_UnpackData(++c, ptr, sz);
712 #ifdef __cplusplus
714 #endif
716 /* Errors in SWIG */
717 #define SWIG_UnknownError -1
718 #define SWIG_IOError -2
719 #define SWIG_RuntimeError -3
720 #define SWIG_IndexError -4
721 #define SWIG_TypeError -5
722 #define SWIG_DivisionByZero -6
723 #define SWIG_OverflowError -7
724 #define SWIG_SyntaxError -8
725 #define SWIG_ValueError -9
726 #define SWIG_SystemError -10
727 #define SWIG_AttributeError -11
728 #define SWIG_MemoryError -12
729 #define SWIG_NullReferenceError -13
733 /* -----------------------------------------------------------------------------
734 * luarun.swg
736 * This file contains the runtime support for Lua modules
737 * and includes code for managing global variables and pointer
738 * type checking.
739 * ----------------------------------------------------------------------------- */
741 #ifdef __cplusplus
742 extern "C" {
743 #endif
745 #include "lua.h"
746 #include "lauxlib.h"
747 #include <stdlib.h> /* for malloc */
748 #include <assert.h> /* for a few sanity tests */
750 /* -----------------------------------------------------------------------------
751 * Lua flavors
752 * ----------------------------------------------------------------------------- */
754 #define SWIG_LUA_FLAVOR_LUA 1
755 #define SWIG_LUA_FLAVOR_ELUA 2
756 #define SWIG_LUA_FLAVOR_ELUAC 3
758 #if !defined(SWIG_LUA_TARGET)
759 # error SWIG_LUA_TARGET not defined
760 #endif
762 #if defined(SWIG_LUA_ELUA_EMULATE)
764 struct swig_elua_entry;
766 typedef struct swig_elua_key {
767 int type;
768 union {
769 const char *strkey;
770 lua_Number numkey;
771 } key;
772 } swig_elua_key;
774 typedef struct swig_elua_val {
775 int type;
776 union {
777 lua_Number number;
778 const struct swig_elua_entry *table;
779 const char *string;
780 lua_CFunction function;
781 struct {
782 char member;
783 long lvalue;
784 void *pvalue;
785 swig_type_info **ptype;
786 } userdata;
787 } value;
788 } swig_elua_val;
790 typedef struct swig_elua_entry {
791 swig_elua_key key;
792 swig_elua_val value;
793 } swig_elua_entry;
795 #define LSTRKEY(x) {LUA_TSTRING, {.strkey = x} }
796 #define LNUMKEY(x) {LUA_TNUMBER, {.numkey = x} }
797 #define LNILKEY {LUA_TNIL, {.strkey = 0} }
799 #define LNUMVAL(x) {LUA_TNUMBER, {.number = x} }
800 #define LFUNCVAL(x) {LUA_TFUNCTION, {.function = x} }
801 #define LROVAL(x) {LUA_TTABLE, {.table = x} }
802 #define LNILVAL {LUA_TNIL, {.string = 0} }
803 #define LSTRVAL(x) {LUA_TSTRING, {.string = x} }
805 #define LUA_REG_TYPE swig_elua_entry
807 #define SWIG_LUA_ELUA_EMUL_METATABLE_KEY "__metatable"
809 #define lua_pushrotable(L,p)\
810 lua_newtable(L);\
811 assert(p);\
812 SWIG_Lua_elua_emulate_register(L,(swig_elua_entry*)(p));
814 #define SWIG_LUA_CONSTTAB_POINTER(B,C,D)\
815 LSTRKEY(B), {LUA_TUSERDATA, { .userdata={0,0,(void*)(C),&D} } }
817 #define SWIG_LUA_CONSTTAB_BINARY(B,S,C,D)\
818 LSTRKEY(B), {LUA_TUSERDATA, { .userdata={1,S,(void*)(C),&D} } }
819 #endif
821 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
822 # define SWIG_LUA_CONSTTAB_INT(B, C) LSTRKEY(B), LNUMVAL(C)
823 # define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C)
824 # define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C)
825 # define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C)
826 /* Those two types of constants are not supported in elua */
828 #ifndef SWIG_LUA_CONSTTAB_POINTER
829 #warning eLua does not support pointers as constants. By default, nil will be used as value
830 #define SWIG_LUA_CONSTTAB_POINTER(B,C,D) LSTRKEY(B), LNILVAL
831 #endif
833 #ifndef SWIG_LUA_CONSTTAB_BINARY
834 #warning eLua does not support pointers to member as constants. By default, nil will be used as value
835 #define SWIG_LUA_CONSTTAB_BINARY(B, S, C, D) LSTRKEY(B), LNILVAL
836 #endif
837 #else /* SWIG_LUA_FLAVOR_LUA */
838 # define SWIG_LUA_CONSTTAB_INT(B, C) SWIG_LUA_INT, (char *)B, (long)C, 0, 0, 0
839 # define SWIG_LUA_CONSTTAB_FLOAT(B, C) SWIG_LUA_FLOAT, (char *)B, 0, (double)C, 0, 0
840 # define SWIG_LUA_CONSTTAB_STRING(B, C) SWIG_LUA_STRING, (char *)B, 0, 0, (void *)C, 0
841 # define SWIG_LUA_CONSTTAB_CHAR(B, C) SWIG_LUA_CHAR, (char *)B, (long)C, 0, 0, 0
842 # define SWIG_LUA_CONSTTAB_POINTER(B,C,D)\
843 SWIG_LUA_POINTER, (char *)B, 0, 0, (void *)C, &D
844 # define SWIG_LUA_CONSTTAB_BINARY(B, S, C, D)\
845 SWIG_LUA_BINARY, (char *)B, S, 0, (void *)C, &D
846 #endif
848 #ifndef SWIG_LUA_ELUA_EMULATE
849 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
850 # define LRO_STRVAL(v) {{.p = (char *) v}, LUA_TSTRING}
851 # define LSTRVAL LRO_STRVAL
852 #endif
853 #endif /* SWIG_LUA_ELUA_EMULATE*/
855 #ifndef SWIG_LUA_ELUA_EMULATE
856 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
858 #ifndef MIN_OPT_LEVEL
859 #define MIN_OPT_LEVEL 2
860 #endif
862 #include "lrodefs.h"
863 #include "lrotable.h"
864 #endif
865 #endif /* SWIG_LUA_ELUA_EMULATE*/
866 /* -----------------------------------------------------------------------------
867 * compatibility defines
868 * ----------------------------------------------------------------------------- */
870 /* History of Lua C API length functions: In Lua 5.0 (and before?)
871 there was "lua_strlen". In Lua 5.1, this was renamed "lua_objlen",
872 but a compatibility define of "lua_strlen" was added. In Lua 5.2,
873 this function was again renamed, to "lua_rawlen" (to emphasize that
874 it doesn't call the "__len" metamethod), and the compatibility
875 define of lua_strlen was removed. All SWIG uses have been updated
876 to "lua_rawlen", and we add our own defines of that here for older
877 versions of Lua. */
878 #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501
879 # define lua_rawlen lua_strlen
880 #elif LUA_VERSION_NUM == 501
881 # define lua_rawlen lua_objlen
882 #endif
885 /* lua_pushglobaltable is the recommended "future-proof" way to get
886 the global table for Lua 5.2 and later. Here we define
887 lua_pushglobaltable ourselves for Lua versions before 5.2. */
888 #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
889 # define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
890 #endif
892 /* lua_absindex was introduced in Lua 5.2 */
893 #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
894 # define lua_absindex(L,i) ((i)>0 || (i) <= LUA_REGISTRYINDEX ? (i) : lua_gettop(L) + (i) + 1)
895 #endif
897 /* lua_rawsetp was introduced in Lua 5.2 */
898 #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
899 #define lua_rawsetp(L,index,ptr)\
900 lua_pushlightuserdata(L,(void*)(ptr));\
901 lua_insert(L,-2);\
902 lua_rawset(L,index);
904 #define lua_rawgetp(L,index,ptr)\
905 lua_pushlightuserdata(L,(void*)(ptr));\
906 lua_rawget(L,index);
908 #endif
910 /* --------------------------------------------------------------------------
911 * Helper functions for error handling
912 * -------------------------------------------------------------------------- */
914 /* Push the string STR on the Lua stack, like lua_pushstring, but
915 prefixed with the location of the innermost Lua call-point
916 (as formatted by luaL_where). */
917 SWIGRUNTIME void
918 SWIG_Lua_pusherrstring(lua_State *L, const char *str) {
919 luaL_where(L, 1);
920 lua_pushstring(L, str);
921 lua_concat(L, 2);
924 /* Push a formatted string generated from FMT and following args on
925 the Lua stack, like lua_pushfstring, but prefixed with the
926 location of the innermost Lua call-point (as formatted by luaL_where). */
927 SWIGRUNTIME void
928 SWIG_Lua_pushferrstring(lua_State *L, const char *fmt, ...) {
929 va_list argp;
930 va_start(argp, fmt);
931 luaL_where(L, 1);
932 lua_pushvfstring(L, fmt, argp);
933 va_end(argp);
934 lua_concat(L, 2);
938 /* -----------------------------------------------------------------------------
939 * global swig types
940 * ----------------------------------------------------------------------------- */
941 /* Constant table */
942 #define SWIG_LUA_INT 1
943 #define SWIG_LUA_FLOAT 2
944 #define SWIG_LUA_STRING 3
945 #define SWIG_LUA_POINTER 4
946 #define SWIG_LUA_BINARY 5
947 #define SWIG_LUA_CHAR 6
949 /* Structure for variable linking table */
950 typedef struct {
951 const char *name;
952 lua_CFunction get;
953 lua_CFunction set;
954 } swig_lua_var_info;
956 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
957 typedef const LUA_REG_TYPE swig_lua_method;
958 typedef const LUA_REG_TYPE swig_lua_const_info;
959 #else /* Normal lua */
960 typedef luaL_Reg swig_lua_method;
962 /* Constant information structure */
963 typedef struct {
964 int type;
965 char *name;
966 long lvalue;
967 double dvalue;
968 void *pvalue;
969 swig_type_info **ptype;
970 } swig_lua_const_info;
972 #endif
974 typedef struct {
975 const char *name;
976 lua_CFunction getmethod;
977 lua_CFunction setmethod;
978 } swig_lua_attribute;
981 struct swig_lua_class;
982 /* Can be used to create namespaces. Currently used to wrap class static methods/variables/constants */
983 typedef struct swig_lua_namespace {
984 const char *name;
985 swig_lua_method *ns_methods;
986 swig_lua_attribute *ns_attributes;
987 swig_lua_const_info *ns_constants;
988 struct swig_lua_class **ns_classes;
989 struct swig_lua_namespace **ns_namespaces;
990 } swig_lua_namespace;
992 typedef struct swig_lua_class {
993 const char *name; /* Name that this class has in Lua */
994 const char *fqname; /* Fully qualified name - Scope + class name */
995 swig_type_info **type;
996 lua_CFunction constructor;
997 void (*destructor)(void *);
998 swig_lua_method *methods;
999 swig_lua_attribute *attributes;
1000 swig_lua_namespace *cls_static;
1001 swig_lua_method *metatable; /* 0 for -eluac */
1002 struct swig_lua_class **bases;
1003 const char **base_names;
1004 } swig_lua_class;
1006 /* this is the struct for wrapping all pointers in SwigLua
1008 typedef struct {
1009 swig_type_info *type;
1010 int own; /* 1 if owned & must be destroyed */
1011 void *ptr;
1012 } swig_lua_userdata;
1014 /* this is the struct for wrapping arbitrary packed binary data
1015 (currently it is only used for member function pointers)
1016 the data ordering is similar to swig_lua_userdata, but it is currently not possible
1017 to tell the two structures apart within SWIG, other than by looking at the type
1019 typedef struct {
1020 swig_type_info *type;
1021 int own; /* 1 if owned & must be destroyed */
1022 char data[1]; /* arbitrary amount of data */
1023 } swig_lua_rawdata;
1025 /* Common SWIG API */
1026 #define SWIG_NewPointerObj(L, ptr, type, owner) SWIG_Lua_NewPointerObj(L, (void *)ptr, type, owner)
1027 #define SWIG_ConvertPtr(L,idx, ptr, type, flags) SWIG_Lua_ConvertPtr(L,idx,ptr,type,flags)
1028 #define SWIG_MustGetPtr(L,idx, type,flags, argnum,fnname) SWIG_Lua_MustGetPtr(L,idx, type,flags, argnum,fnname)
1029 /* for C++ member pointers, ie, member methods */
1030 #define SWIG_ConvertMember(L, idx, ptr, sz, ty) SWIG_Lua_ConvertPacked(L, idx, ptr, sz, ty)
1031 #define SWIG_NewMemberObj(L, ptr, sz, type) SWIG_Lua_NewPackedObj(L, ptr, sz, type)
1033 /* Runtime API */
1034 #define SWIG_GetModule(clientdata) SWIG_Lua_GetModule((lua_State*)(clientdata))
1035 #define SWIG_SetModule(clientdata, pointer) SWIG_Lua_SetModule((lua_State*) (clientdata), pointer)
1036 #define SWIG_MODULE_CLIENTDATA_TYPE lua_State*
1038 /* Contract support */
1039 #define SWIG_contract_assert(expr, msg) \
1040 if (!(expr)) { SWIG_Lua_pusherrstring(L, (char *) msg); goto fail; } else
1043 /* helper #defines */
1044 #define SWIG_fail {goto fail;}
1045 #define SWIG_fail_arg(func_name,argnum,type) \
1046 {SWIG_Lua_pushferrstring(L,"Error in %s (arg %d), expected '%s' got '%s'",\
1047 func_name,argnum,type,SWIG_Lua_typename(L,argnum));\
1048 goto fail;}
1049 #define SWIG_fail_ptr(func_name,argnum,type) \
1050 SWIG_fail_arg(func_name,argnum,(type && type->str)?type->str:"void*")
1051 #define SWIG_check_num_args(func_name,a,b) \
1052 if (lua_gettop(L)<a || lua_gettop(L)>b) \
1053 {SWIG_Lua_pushferrstring(L,"Error in %s expected %d..%d args, got %d",func_name,a,b,lua_gettop(L));\
1054 goto fail;}
1057 #define SWIG_Lua_get_table(L,n) \
1058 (lua_pushstring(L, n), lua_rawget(L,-2))
1060 #define SWIG_Lua_add_function(L,n,f) \
1061 (lua_pushstring(L, n), \
1062 lua_pushcfunction(L, f), \
1063 lua_rawset(L,-3))
1065 #define SWIG_Lua_add_boolean(L,n,b) \
1066 (lua_pushstring(L, n), \
1067 lua_pushboolean(L, b), \
1068 lua_rawset(L,-3))
1070 /* special helper for allowing 'nil' for usertypes */
1071 #define SWIG_isptrtype(L,I) (lua_isuserdata(L,I) || lua_isnil(L,I))
1073 #ifdef __cplusplus
1074 /* Special helper for member function pointers
1075 it gets the address, casts it, then dereferences it */
1076 /*#define SWIG_mem_fn_as_voidptr(a) (*((char**)&(a))) */
1077 #endif
1079 /* storing/access of swig_module_info */
1080 SWIGRUNTIME swig_module_info *
1081 SWIG_Lua_GetModule(lua_State *L) {
1082 swig_module_info *ret = 0;
1083 lua_pushstring(L, "swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
1084 lua_rawget(L, LUA_REGISTRYINDEX);
1085 if (lua_islightuserdata(L, -1))
1086 ret = (swig_module_info *)lua_touserdata(L, -1);
1087 lua_pop(L, 1); /* tidy */
1088 return ret;
1091 SWIGRUNTIME void
1092 SWIG_Lua_SetModule(lua_State *L, swig_module_info *module) {
1093 /* add this all into the Lua registry: */
1094 lua_pushstring(L, "swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
1095 lua_pushlightuserdata(L, (void *)module);
1096 lua_rawset(L, LUA_REGISTRYINDEX);
1099 /* -----------------------------------------------------------------------------
1100 * global variable support code: modules
1101 * ----------------------------------------------------------------------------- */
1103 /* this function is called when trying to set an immutable.
1104 default action is to print an error.
1105 This can removed with a compile flag SWIGLUA_IGNORE_SET_IMMUTABLE */
1106 SWIGINTERN int SWIG_Lua_set_immutable(lua_State *L) {
1107 /* there should be 1 param passed in: the new value */
1108 #ifndef SWIGLUA_IGNORE_SET_IMMUTABLE
1109 lua_pop(L, 1); /* remove it */
1110 luaL_error(L, "This variable is immutable");
1111 #endif
1112 return 0; /* should not return anything */
1115 #ifdef SWIG_LUA_ELUA_EMULATE
1117 SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L, void *ptr, swig_type_info *type, int own);
1118 SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L, void *ptr, size_t size, swig_type_info *type);
1119 static int swig_lua_elua_emulate_unique_key;
1121 /* This function emulates eLua rotables behaviour. It loads a rotable definition into the usual lua table. */
1122 SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_entry *table) {
1123 int i, table_parsed, parsed_tables_array, target_table;
1124 assert(lua_istable(L, -1));
1125 target_table = lua_gettop(L);
1126 /* Get the registry where we put all parsed tables to avoid loops */
1127 lua_rawgetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key);
1128 if (lua_isnil(L, -1)) {
1129 lua_pop(L, 1);
1130 lua_newtable(L);
1131 lua_pushvalue(L, -1);
1132 lua_rawsetp(L, LUA_REGISTRYINDEX, (void *)(&swig_lua_elua_emulate_unique_key));
1134 parsed_tables_array = lua_gettop(L);
1135 lua_pushvalue(L, target_table);
1136 lua_rawsetp(L, parsed_tables_array, table);
1137 table_parsed = 0;
1138 const int SWIGUNUSED pairs_start = lua_gettop(L);
1139 for (i = 0; table[i].key.type != LUA_TNIL || table[i].value.type != LUA_TNIL; i++) {
1140 const swig_elua_entry *entry = table + i;
1141 int is_metatable = 0;
1142 switch (entry->key.type) {
1143 case LUA_TSTRING:
1144 lua_pushstring(L, entry->key.key.strkey);
1145 if (strcmp(entry->key.key.strkey, SWIG_LUA_ELUA_EMUL_METATABLE_KEY) == 0)
1146 is_metatable = 1;
1147 break;
1148 case LUA_TNUMBER:
1149 lua_pushnumber(L, entry->key.key.numkey);
1150 break;
1151 case LUA_TNIL:
1152 lua_pushnil(L);
1153 break;
1154 default:
1155 assert(0);
1157 switch (entry->value.type) {
1158 case LUA_TSTRING:
1159 lua_pushstring(L, entry->value.value.string);
1160 break;
1161 case LUA_TNUMBER:
1162 lua_pushnumber(L, entry->value.value.number);
1163 break;
1164 case LUA_TFUNCTION:
1165 lua_pushcfunction(L, entry->value.value.function);
1166 break;
1167 case LUA_TTABLE:
1168 lua_rawgetp(L, parsed_tables_array, entry->value.value.table);
1169 table_parsed = !lua_isnil(L, -1);
1170 if (!table_parsed) {
1171 lua_pop(L, 1); /*remove nil */
1172 lua_newtable(L);
1173 SWIG_Lua_elua_emulate_register(L, entry->value.value.table);
1175 if (is_metatable) {
1176 assert(lua_istable(L, -1));
1177 lua_pushvalue(L, -1);
1178 lua_setmetatable(L, target_table);
1181 break;
1182 case LUA_TUSERDATA:
1183 if (entry->value.value.userdata.member)
1184 SWIG_NewMemberObj(L, entry->value.value.userdata.pvalue,
1185 entry->value.value.userdata.lvalue,
1186 *(entry->value.value.userdata.ptype));
1187 else
1188 SWIG_NewPointerObj(L, entry->value.value.userdata.pvalue,
1189 *(entry->value.value.userdata.ptype), 0);
1190 break;
1191 case LUA_TNIL:
1192 lua_pushnil(L);
1193 break;
1194 default:
1195 assert(0);
1197 assert(lua_gettop(L) == pairs_start + 2);
1198 lua_rawset(L, target_table);
1200 lua_pop(L, 1); /* Removing parsed tables storage */
1201 assert(lua_gettop(L) == target_table);
1204 SWIGINTERN void SWIG_Lua_elua_emulate_register_clear(lua_State *L) {
1205 lua_pushnil(L);
1206 lua_rawsetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key);
1209 SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L);
1211 SWIGINTERN int SWIG_Lua_emulate_elua_getmetatable(lua_State *L) {
1212 SWIG_check_num_args("getmetatable(SWIG eLua emulation)", 1, 1);
1213 SWIG_Lua_get_class_registry(L);
1214 lua_getfield(L, -1, "lua_getmetatable");
1215 lua_remove(L, -2); /* remove the registry*/
1216 assert(!lua_isnil(L, -1));
1217 lua_pushvalue(L, 1);
1218 assert(lua_gettop(L) == 3); /* object | function | object again */
1219 lua_call(L, 1, 1);
1220 if (!lua_isnil(L, -1)) /*There is an ordinary metatable */
1221 return 1;
1222 /*if it is a table, then emulate elua behaviour - check for __metatable attribute of a table*/
1223 assert(lua_gettop(L) == 2);
1224 if (lua_istable(L, -2)) {
1225 lua_pop(L, 1); /*remove the nil*/
1226 lua_getfield(L, -1, SWIG_LUA_ELUA_EMUL_METATABLE_KEY);
1228 assert(lua_gettop(L) == 2);
1229 return 1;
1231 fail:
1232 lua_error(L);
1233 return 0;
1236 SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L) {
1237 SWIG_Lua_get_class_registry(L);
1238 lua_pushglobaltable(L);
1239 lua_pushstring(L, "lua_getmetatable");
1240 lua_getfield(L, -2, "getmetatable");
1241 assert(!lua_isnil(L, -1));
1242 lua_rawset(L, -4);
1243 lua_pushstring(L, "getmetatable");
1244 lua_pushcfunction(L, SWIG_Lua_emulate_elua_getmetatable);
1245 lua_rawset(L, -3);
1246 lua_pop(L, 2);
1249 /* END OF REMOVE */
1251 #endif
1252 /* -----------------------------------------------------------------------------
1253 * global variable support code: namespaces and modules (which are the same thing)
1254 * ----------------------------------------------------------------------------- */
1256 SWIGINTERN int SWIG_Lua_namespace_get(lua_State *L) {
1257 /* there should be 2 params passed in
1258 (1) table (not the meta table)
1259 (2) string name of the attribute
1261 assert(lua_istable(L, -2)); /* just in case */
1262 lua_getmetatable(L, -2);
1263 assert(lua_istable(L, -1));
1264 SWIG_Lua_get_table(L, ".get"); /* find the .get table */
1265 assert(lua_istable(L, -1));
1266 /* look for the key in the .get table */
1267 lua_pushvalue(L, 2); /* key */
1268 lua_rawget(L, -2);
1269 lua_remove(L, -2); /* stack tidy, remove .get table */
1270 if (lua_iscfunction(L, -1)) {
1271 /* found it so call the fn & return its value */
1272 lua_call(L, 0, 1); /* 1 value in (userdata),1 out (result) */
1273 lua_remove(L, -2); /* stack tidy, remove metatable */
1274 return 1;
1276 lua_pop(L, 1); /* remove whatever was there */
1277 /* ok, so try the .fn table */
1278 SWIG_Lua_get_table(L, ".fn"); /* find the .get table */
1279 assert(lua_istable(L, -1)); /* just in case */
1280 lua_pushvalue(L, 2); /* key */
1281 lua_rawget(L, -2); /* look for the fn */
1282 lua_remove(L, -2); /* stack tidy, remove .fn table */
1283 if (lua_isfunction(L, -1)) { /* note: whether it's a C function or lua function */
1284 /* found it so return the fn & let lua call it */
1285 lua_remove(L, -2); /* stack tidy, remove metatable */
1286 return 1;
1288 lua_pop(L, 1); /* remove whatever was there */
1289 return 0;
1292 SWIGINTERN int SWIG_Lua_namespace_set(lua_State *L) {
1293 /* there should be 3 params passed in
1294 (1) table (not the meta table)
1295 (2) string name of the attribute
1296 (3) any for the new value
1299 assert(lua_istable(L, 1));
1300 lua_getmetatable(L, 1); /* get the meta table */
1301 assert(lua_istable(L, -1));
1303 SWIG_Lua_get_table(L, ".set"); /* find the .set table */
1304 if (lua_istable(L, -1)) {
1305 /* look for the key in the .set table */
1306 lua_pushvalue(L, 2); /* key */
1307 lua_rawget(L, -2);
1308 if (lua_iscfunction(L, -1)) {
1309 /* found it so call the fn & return its value */
1310 lua_pushvalue(L, 3); /* value */
1311 lua_call(L, 1, 0);
1312 return 0;
1314 lua_pop(L, 1); /* remove the value */
1316 lua_pop(L, 1); /* remove the value .set table */
1317 lua_pop(L, 1); /* remote metatable */
1318 lua_rawset(L, -3);
1319 return 0;
1322 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) /* In elua this is useless */
1323 SWIGINTERN void SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]); /* forward declaration */
1324 SWIGINTERN void SWIG_Lua_add_variable(lua_State *L, const char *name, lua_CFunction getFn, lua_CFunction setFn); /* forward declaration */
1325 SWIGINTERN void SWIG_Lua_class_register(lua_State *L, swig_lua_class *clss);
1327 /* helper function - register namespace methods and attributes into namespace */
1328 SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State *L, swig_lua_namespace *ns) {
1329 int i;
1330 /* There must be namespace table (not metatable) at the top of the stack */
1331 assert(lua_istable(L, -1));
1332 SWIG_Lua_InstallConstants(L, ns->ns_constants);
1334 /* add methods to the namespace/module table */
1335 for (i = 0; ns->ns_methods[i].name; i++) {
1336 SWIG_Lua_add_function(L, ns->ns_methods[i].name, ns->ns_methods[i].func);
1338 lua_getmetatable(L, -1);
1340 /* add fns */
1341 for (i = 0; ns->ns_attributes[i].name; i++) {
1342 SWIG_Lua_add_variable(L, ns->ns_attributes[i].name, ns->ns_attributes[i].getmethod, ns->ns_attributes[i].setmethod);
1345 /* clear stack - remove metatble */
1346 lua_pop(L, 1);
1347 return 0;
1350 /* Register all classes in the namespace */
1351 SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace *ns) {
1352 swig_lua_class **classes;
1354 /* There must be a module/namespace table at the top of the stack */
1355 assert(lua_istable(L, -1));
1357 classes = ns->ns_classes;
1359 if (classes != 0) {
1360 while (*classes != 0) {
1361 SWIG_Lua_class_register(L, *classes);
1362 classes++;
1367 /* Helper function. Creates namespace table and adds it to module table
1368 if 'reg' is true, then will register namespace table to parent one (must be on top of the stack
1369 when function is called).
1370 Function always returns newly registered table on top of the stack.
1372 SWIGINTERN void SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, int reg) {
1373 swig_lua_namespace **sub_namespace;
1374 /* 1 argument - table on the top of the stack */
1375 const int SWIGUNUSED begin = lua_gettop(L);
1376 assert(lua_istable(L, -1)); /* just in case. This is supposed to be module table or parent namespace table */
1377 lua_checkstack(L, 5);
1378 lua_newtable(L); /* namespace itself */
1379 lua_newtable(L); /* metatable for namespace */
1381 /* add a table called ".get" */
1382 lua_pushstring(L, ".get");
1383 lua_newtable(L);
1384 lua_rawset(L, -3);
1385 /* add a table called ".set" */
1386 lua_pushstring(L, ".set");
1387 lua_newtable(L);
1388 lua_rawset(L, -3);
1389 /* add a table called ".fn" */
1390 lua_pushstring(L, ".fn");
1391 lua_newtable(L);
1392 lua_rawset(L, -3);
1394 /* add accessor fns for using the .get,.set&.fn */
1395 SWIG_Lua_add_function(L, "__index", SWIG_Lua_namespace_get);
1396 SWIG_Lua_add_function(L, "__newindex", SWIG_Lua_namespace_set);
1398 lua_setmetatable(L, -2); /* set metatable */
1400 /* Register all functions, variables etc */
1401 SWIG_Lua_add_namespace_details(L, ns);
1402 /* Register classes */
1403 SWIG_Lua_add_namespace_classes(L, ns);
1405 sub_namespace = ns->ns_namespaces;
1406 if (sub_namespace != 0) {
1407 while (*sub_namespace != 0) {
1408 SWIG_Lua_namespace_register(L, *sub_namespace, 1);
1409 lua_pop(L, 1); /* removing sub-namespace table */
1410 sub_namespace++;
1414 if (reg) {
1415 lua_pushstring(L, ns->name);
1416 lua_pushvalue(L, -2);
1417 lua_rawset(L, -4); /* add namespace to module table */
1419 assert(lua_gettop(L) == begin + 1);
1421 #endif /* SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA */
1423 /* -----------------------------------------------------------------------------
1424 * global variable support code: classes
1425 * ----------------------------------------------------------------------------- */
1427 SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L, const char *cname);
1429 typedef int (*swig_lua_base_iterator_func)(lua_State *, swig_type_info *, int, int *ret);
1431 SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *SWIGUNUSED swig_type,
1432 int first_arg, swig_lua_base_iterator_func func, int *const ret) {
1433 /* first_arg - position of the object in stack. Everything that is above are arguments
1434 * and is passed to every evocation of the func */
1435 int last_arg = lua_gettop(L);/* position of last argument */
1436 int original_metatable = last_arg + 1;
1437 size_t bases_count;
1438 int result = SWIG_ERROR;
1439 int bases_table;
1440 (void)swig_type;
1441 lua_getmetatable(L, first_arg);
1443 /* initialise base search */
1444 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
1445 SWIG_Lua_get_table(L, ".bases");
1446 assert(lua_istable(L, -1));
1447 bases_count = lua_rawlen(L, -1);
1448 bases_table = lua_gettop(L);
1449 #else
1450 /* In elua .bases table doesn't exist. Use table from swig_lua_class */
1451 (void)bases_table;
1452 assert(swig_type != 0);
1453 swig_module_info *module = SWIG_GetModule(L);
1454 swig_lua_class **bases = ((swig_lua_class *)(swig_type->clientdata))->bases;
1455 const char **base_names = ((swig_lua_class *)(swig_type->clientdata))->base_names;
1456 bases_count = 0;
1457 for (; base_names[bases_count];
1458 bases_count++);/* get length of bases */
1459 #endif
1461 if (ret)
1462 *ret = 0;
1463 if (bases_count > 0) {
1464 int to_remove;
1465 size_t i;
1466 int j;
1467 int subcall_last_arg;
1468 int subcall_first_arg = lua_gettop(L) + 1;/* Here a copy of first_arg and arguments begin */
1469 int valid = 1;
1470 swig_type_info *base_swig_type = 0;
1471 for (j = first_arg; j <= last_arg; j++)
1472 lua_pushvalue(L, j);
1473 subcall_last_arg = lua_gettop(L);
1475 /* Trick: temporarily replacing original metatable with metatable for base class and call getter */
1476 for (i = 0; i < bases_count; i++) {
1477 /* Iteration through class bases */
1478 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
1479 lua_rawgeti(L, bases_table, i + 1);
1480 base_swig_type = 0;
1481 if (lua_isnil(L, -1)) {
1482 valid = 0;
1483 lua_pop(L, 1);
1484 } else {
1485 valid = 1;
1487 #else /* In elua .bases table doesn't exist. Use table from swig_lua_class */
1488 swig_lua_class *base_class = bases[i];
1489 if (!base_class) {
1490 valid = 0;
1491 } else {
1492 valid = 1;
1493 SWIG_Lua_get_class_metatable(L, base_class->fqname);
1494 base_swig_type = SWIG_TypeQueryModule(module, module, base_names[i]);
1495 assert(base_swig_type != 0);
1497 #endif
1499 if (!valid)
1500 continue;
1501 assert(lua_isuserdata(L, subcall_first_arg));
1502 assert(lua_istable(L, -1));
1503 lua_setmetatable(L, subcall_first_arg); /* Set new metatable */
1504 assert(lua_gettop(L) == subcall_last_arg);
1505 result = func(L, base_swig_type, subcall_first_arg, ret); /* Forward call */
1506 if (result != SWIG_ERROR) {
1507 break;
1510 /* Restore original metatable */
1511 lua_pushvalue(L, original_metatable);
1512 lua_setmetatable(L, first_arg);
1513 /* Clear - remove everything between last_arg and subcall_last_arg including */
1514 to_remove = subcall_last_arg - last_arg;
1515 for (j = 0; j < to_remove; j++)
1516 lua_remove(L, last_arg + 1);
1517 } else {
1518 /* Remove everything after last_arg */
1519 lua_pop(L, lua_gettop(L) - last_arg);
1521 if (ret) assert(lua_gettop(L) == last_arg + *ret);
1522 return result;
1525 /* The class.get method helper, performs the lookup of class attributes.
1526 * It returns an error code. Number of function return values is passed inside 'ret'.
1527 * first_arg is not used in this function because function always has 2 arguments.
1529 SWIGINTERN int SWIG_Lua_class_do_get_item(lua_State *L, swig_type_info *type, int SWIGUNUSED first_arg, int *ret) {
1530 /* there should be 2 params passed in
1531 (1) userdata (not the meta table)
1532 (2) string name of the attribute
1534 int bases_search_result;
1535 int substack_start = lua_gettop(L) - 2;
1536 assert(first_arg == substack_start + 1);
1537 lua_checkstack(L, 5);
1538 assert(lua_isuserdata(L, -2)); /* just in case */
1539 lua_getmetatable(L, -2); /* get the meta table */
1540 assert(lua_istable(L, -1)); /* just in case */
1541 /* NEW: looks for the __getitem() fn
1542 this is a user provided get fn */
1543 SWIG_Lua_get_table(L, "__getitem"); /* find the __getitem fn */
1544 if (lua_iscfunction(L, -1)) { /* if its there */
1545 /* found it so call the fn & return its value */
1546 lua_pushvalue(L, substack_start + 1); /* the userdata */
1547 lua_pushvalue(L, substack_start + 2); /* the parameter */
1548 lua_call(L, 2, 1); /* 2 value in (userdata),1 out (result) */
1549 lua_remove(L, -2); /* stack tidy, remove metatable */
1550 if (ret) *ret = 1;
1551 return SWIG_OK;
1553 lua_pop(L, 1);
1554 /* Remove the metatable */
1555 lua_pop(L, 1);
1556 /* Search in base classes */
1557 bases_search_result = SWIG_Lua_iterate_bases(L, type, substack_start + 1, SWIG_Lua_class_do_get_item, ret);
1558 return bases_search_result; /* sorry not known */
1562 /* The class.get method helper, performs the lookup of class attributes.
1563 * It returns an error code. Number of function return values is passed inside 'ret'.
1564 * first_arg is not used in this function because function always has 2 arguments.
1566 SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int SWIGUNUSED first_arg, int *ret) {
1567 /* there should be 2 params passed in
1568 (1) userdata (not the meta table)
1569 (2) string name of the attribute
1571 int bases_search_result;
1572 int substack_start = lua_gettop(L) - 2;
1573 assert(first_arg == substack_start + 1);
1574 lua_checkstack(L, 5);
1575 assert(lua_isuserdata(L, -2)); /* just in case */
1576 lua_getmetatable(L, -2); /* get the meta table */
1577 assert(lua_istable(L, -1)); /* just in case */
1578 SWIG_Lua_get_table(L, ".get"); /* find the .get table */
1579 assert(lua_istable(L, -1)); /* just in case */
1580 /* look for the key in the .get table */
1581 lua_pushvalue(L, substack_start + 2); /* key */
1582 lua_rawget(L, -2);
1583 lua_remove(L, -2); /* stack tidy, remove .get table */
1584 if (lua_iscfunction(L, -1)) {
1585 /* found it so call the fn & return its value */
1586 lua_pushvalue(L, substack_start + 1); /* the userdata */
1587 lua_call(L, 1, 1); /* 1 value in (userdata),1 out (result) */
1588 lua_remove(L, -2); /* stack tidy, remove metatable */
1589 if (ret)
1590 *ret = 1;
1591 return SWIG_OK;
1593 lua_pop(L, 1); /* remove whatever was there */
1594 /* ok, so try the .fn table */
1595 SWIG_Lua_get_table(L, ".fn"); /* find the .fn table */
1596 assert(lua_istable(L, -1)); /* just in case */
1597 lua_pushvalue(L, substack_start + 2); /* key */
1598 lua_rawget(L, -2); /* look for the fn */
1599 lua_remove(L, -2); /* stack tidy, remove .fn table */
1600 if (lua_isfunction(L, -1)) { /* note: if its a C function or lua function */
1601 /* found it so return the fn & let lua call it */
1602 lua_remove(L, -2); /* stack tidy, remove metatable */
1603 if (ret)
1604 *ret = 1;
1605 return SWIG_OK;
1607 lua_pop(L, 1); /* remove whatever was there */
1608 /* Remove the metatable */
1609 lua_pop(L, 1);
1610 /* Search in base classes */
1611 bases_search_result = SWIG_Lua_iterate_bases(L, type, substack_start + 1, SWIG_Lua_class_do_get, ret);
1612 return bases_search_result; /* sorry not known */
1615 /* the class.get method, performs the lookup of class attributes
1617 SWIGINTERN int SWIG_Lua_class_get(lua_State *L) {
1618 /* there should be 2 params passed in
1619 (1) userdata (not the meta table)
1620 (2) string name of the attribute
1622 int result;
1623 swig_lua_userdata *usr;
1624 swig_type_info *type;
1625 int ret = 0;
1626 assert(lua_isuserdata(L, 1));
1627 usr = (swig_lua_userdata *)lua_touserdata(L, 1); /* get data */
1628 type = usr->type;
1629 result = SWIG_Lua_class_do_get(L, type, 1, &ret);
1630 if (result == SWIG_OK)
1631 return ret;
1633 result = SWIG_Lua_class_do_get_item(L, type, 1, &ret);
1634 if (result == SWIG_OK)
1635 return ret;
1637 return 0;
1640 /* helper for the class.set method, performs the lookup of class attributes
1641 * It returns error code. Number of function return values is passed inside 'ret'
1643 SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int first_arg, int *ret) {
1644 /* there should be 3 params passed in
1645 (1) table (not the meta table)
1646 (2) string name of the attribute
1647 (3) any for the new value
1650 int bases_search_result;
1651 int substack_start = lua_gettop(L) - 3;
1652 lua_checkstack(L, 5);
1653 assert(lua_isuserdata(L, substack_start + 1)); /* just in case */
1654 lua_getmetatable(L, substack_start + 1); /* get the meta table */
1655 assert(lua_istable(L, -1)); /* just in case */
1656 if (ret)
1657 *ret = 0; /* it is setter - number of return values is always 0 */
1659 SWIG_Lua_get_table(L, ".set"); /* find the .set table */
1660 if (lua_istable(L, -1)) {
1661 /* look for the key in the .set table */
1662 lua_pushvalue(L, substack_start + 2); /* key */
1663 lua_rawget(L, -2);
1664 lua_remove(L, -2); /* tidy stack, remove .set table */
1665 if (lua_iscfunction(L, -1)) {
1666 /* found it so call the fn & return its value */
1667 lua_pushvalue(L, substack_start + 1); /* userdata */
1668 lua_pushvalue(L, substack_start + 3); /* value */
1669 lua_call(L, 2, 0);
1670 lua_remove(L, substack_start + 4); /*remove metatable*/
1671 return SWIG_OK;
1673 lua_pop(L, 1); /* remove the value */
1674 } else {
1675 lua_pop(L, 1); /* remove the answer for .set table request*/
1677 /* NEW: looks for the __setitem() fn
1678 this is a user provided set fn */
1679 SWIG_Lua_get_table(L, "__setitem"); /* find the fn */
1680 if (lua_iscfunction(L, -1)) { /* if its there */
1681 /* found it so call the fn & return its value */
1682 lua_pushvalue(L, substack_start + 1); /* the userdata */
1683 lua_pushvalue(L, substack_start + 2); /* the parameter */
1684 lua_pushvalue(L, substack_start + 3); /* the value */
1685 lua_call(L, 3, 0); /* 3 values in ,0 out */
1686 lua_remove(L, -2); /* stack tidy, remove metatable */
1687 return SWIG_OK;
1689 lua_pop(L, 1); /* remove value */
1691 lua_pop(L, 1); /* remove metatable */
1692 /* Search among bases */
1693 bases_search_result = SWIG_Lua_iterate_bases(L, type, first_arg, SWIG_Lua_class_do_set, ret);
1694 if (ret)
1695 assert(*ret == 0);
1696 assert(lua_gettop(L) == substack_start + 3);
1697 return bases_search_result;
1700 /* This is the actual method exported to Lua. It calls SWIG_Lua_class_do_set and correctly
1701 * handles return values.
1703 SWIGINTERN int SWIG_Lua_class_set(lua_State *L) {
1704 /* There should be 3 params passed in
1705 (1) table (not the meta table)
1706 (2) string name of the attribute
1707 (3) any for the new value
1709 int ret = 0;
1710 int result;
1711 swig_lua_userdata *usr;
1712 swig_type_info *type;
1713 assert(lua_isuserdata(L, 1));
1714 usr = (swig_lua_userdata *)lua_touserdata(L, 1); /* get data */
1715 type = usr->type;
1716 result = SWIG_Lua_class_do_set(L, type, 1, &ret);
1717 if (result != SWIG_OK) {
1718 SWIG_Lua_pushferrstring(L, "Assignment not possible. No setter/member with this name. For custom assignments implement __setitem method.");
1719 lua_error(L);
1720 } else {
1721 assert(ret == 0);
1723 return 0;
1726 /* the class.destruct method called by the interpreter */
1727 SWIGINTERN int SWIG_Lua_class_destruct(lua_State *L) {
1728 /* there should be 1 params passed in
1729 (1) userdata (not the meta table) */
1730 swig_lua_userdata *usr;
1731 swig_lua_class *clss;
1732 assert(lua_isuserdata(L, -1)); /* just in case */
1733 usr = (swig_lua_userdata *)lua_touserdata(L, -1); /* get it */
1734 /* if must be destroyed & has a destructor */
1735 if (usr->own) { /* if must be destroyed */
1736 clss = (swig_lua_class *)usr->type->clientdata; /* get the class */
1737 if (clss && clss->destructor) { /* there is a destroy fn */
1738 clss->destructor(usr->ptr); /* bye bye */
1741 return 0;
1744 /* the class.__tostring method called by the interpreter and print */
1745 SWIGINTERN int SWIG_Lua_class_tostring(lua_State *L) {
1746 /* there should be 1 param passed in
1747 (1) userdata (not the metatable) */
1748 swig_lua_userdata *userData;
1749 assert(lua_isuserdata(L, 1)); /* just in case */
1750 userData = (swig_lua_userdata *)lua_touserdata(L, 1); /* get the userdata address */
1752 lua_pushfstring(L, "<userdata of type '%s' at %p>", userData->type->str, userData->ptr);
1753 return 1;
1756 /* to manually disown some userdata */
1757 SWIGINTERN int SWIG_Lua_class_disown(lua_State *L) {
1758 /* there should be 1 params passed in
1759 (1) userdata (not the meta table) */
1760 swig_lua_userdata *usr;
1761 assert(lua_isuserdata(L, -1)); /* just in case */
1762 usr = (swig_lua_userdata *)lua_touserdata(L, -1); /* get it */
1764 usr->own = 0; /* clear our ownership */
1765 return 0;
1768 /* lua callable function to compare userdata's value
1769 the issue is that two userdata may point to the same thing
1770 but to lua, they are different objects */
1771 SWIGRUNTIME int SWIG_Lua_class_equal(lua_State *L) {
1772 int result;
1773 swig_lua_userdata *usr1, *usr2;
1774 if (!lua_isuserdata(L, 1) || !lua_isuserdata(L, 2)) /* just in case */
1775 return 0; /* nil reply */
1776 usr1 = (swig_lua_userdata *)lua_touserdata(L, 1); /* get data */
1777 usr2 = (swig_lua_userdata *)lua_touserdata(L, 2); /* get data */
1778 /*result=(usr1->ptr==usr2->ptr && usr1->type==usr2->type); only works if type is the same*/
1779 result = (usr1->ptr == usr2->ptr);
1780 lua_pushboolean(L, result);
1781 return 1;
1784 /* populate table at the top of the stack with metamethods that ought to be inherited */
1785 SWIGINTERN void SWIG_Lua_populate_inheritable_metamethods(lua_State *L) {
1786 SWIG_Lua_add_boolean(L, "__add", 1);
1787 SWIG_Lua_add_boolean(L, "__sub", 1);
1788 SWIG_Lua_add_boolean(L, "__mul", 1);
1789 SWIG_Lua_add_boolean(L, "__div", 1);
1790 SWIG_Lua_add_boolean(L, "__mod", 1);
1791 SWIG_Lua_add_boolean(L, "__pow", 1);
1792 SWIG_Lua_add_boolean(L, "__unm", 1);
1793 SWIG_Lua_add_boolean(L, "__len", 1);
1794 SWIG_Lua_add_boolean(L, "__concat", 1);
1795 SWIG_Lua_add_boolean(L, "__eq", 1);
1796 SWIG_Lua_add_boolean(L, "__lt", 1);
1797 SWIG_Lua_add_boolean(L, "__le", 1);
1798 SWIG_Lua_add_boolean(L, "__call", 1);
1799 SWIG_Lua_add_boolean(L, "__tostring", 1);
1800 SWIG_Lua_add_boolean(L, "__gc", 0);
1803 /* creates the swig registry */
1804 SWIGINTERN void SWIG_Lua_create_class_registry(lua_State *L) {
1805 /* create main SWIG registry table */
1806 lua_pushstring(L, "SWIG");
1807 lua_newtable(L);
1808 /* populate it with some predefined data */
1810 /* .library table. Placeholder */
1811 lua_pushstring(L, ".library");
1812 lua_newtable(L);
1814 /* list of metamethods that class inherits from its bases */
1815 lua_pushstring(L, "inheritable_metamethods");
1816 lua_newtable(L);
1817 /* populate with list of metamethods */
1818 SWIG_Lua_populate_inheritable_metamethods(L);
1819 lua_rawset(L, -3);
1821 lua_rawset(L, -3);
1823 lua_rawset(L, LUA_REGISTRYINDEX);
1826 /* gets the swig registry (or creates it) */
1827 SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L) {
1828 /* add this all into the swig registry: */
1829 lua_pushstring(L, "SWIG");
1830 lua_rawget(L, LUA_REGISTRYINDEX); /* get the registry */
1831 if (!lua_istable(L, -1)) { /* not there */
1832 /* must be first time, so add it */
1833 lua_pop(L, 1); /* remove the result */
1834 SWIG_Lua_create_class_registry(L);
1835 /* then get it */
1836 lua_pushstring(L, "SWIG");
1837 lua_rawget(L, LUA_REGISTRYINDEX);
1841 SWIGINTERN void SWIG_Lua_get_inheritable_metamethods(lua_State *L) {
1842 SWIG_Lua_get_class_registry(L);
1843 lua_pushstring(L, ".library");
1844 lua_rawget(L, -2);
1845 assert(!lua_isnil(L, -1));
1846 lua_pushstring(L, "inheritable_metamethods");
1847 lua_rawget(L, -2);
1849 /* Remove class registry and library table */
1850 lua_remove(L, -2);
1851 lua_remove(L, -2);
1854 /* Helper function to get the classes metatable from the register */
1855 SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L, const char *cname) {
1856 SWIG_Lua_get_class_registry(L); /* get the registry */
1857 lua_pushstring(L, cname); /* get the name */
1858 lua_rawget(L, -2); /* get it */
1859 lua_remove(L, -2); /* tidy up (remove registry) */
1862 /* Set up the base classes pointers.
1863 Each class structure has a list of pointers to the base class structures.
1864 This function fills them.
1865 It cannot be done at compile time, as this will not work with hireachies
1866 spread over more than one swig file.
1867 Therefore it must be done at runtime, querying the SWIG type system.
1869 SWIGINTERN void SWIG_Lua_init_base_class(lua_State *L, swig_lua_class *clss) {
1870 int i = 0;
1871 swig_module_info *module = SWIG_GetModule(L);
1872 for (i = 0; clss->base_names[i]; i++) {
1873 if (clss->bases[i] == 0) { /* not found yet */
1874 /* lookup and cache the base class */
1875 swig_type_info *info = SWIG_TypeQueryModule(module, module, clss->base_names[i]);
1876 if (info) clss->bases[i] = (swig_lua_class *) info->clientdata;
1881 #if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
1882 /* Merges two tables */
1883 SWIGINTERN void SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int source) {
1884 /* iterating */
1885 lua_pushnil(L);
1886 while (lua_next(L, source) != 0) {
1887 /* -1 - value, -2 - index */
1888 /* have to copy to assign */
1889 lua_pushvalue(L, -2); /* copy of index */
1890 lua_pushvalue(L, -2); /* copy of value */
1891 lua_rawset(L, target);
1892 lua_pop(L, 1);
1893 /* only key is left */
1897 /* Merges two tables with given name. original - index of target metatable, base - index of source metatable */
1898 SWIGINTERN void SWIG_Lua_merge_tables(lua_State *L, const char *name, int original, int base) {
1899 /* push original[name], then base[name] */
1900 lua_pushstring(L, name);
1901 lua_rawget(L, original);
1902 int original_table = lua_gettop(L);
1903 lua_pushstring(L, name);
1904 lua_rawget(L, base);
1905 int base_table = lua_gettop(L);
1906 SWIG_Lua_merge_tables_by_index(L, original_table, base_table);
1907 /* clearing stack */
1908 lua_pop(L, 2);
1911 /* Function takes all symbols from base and adds it to derived class. It's just a helper. */
1912 SWIGINTERN void SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls) {
1913 /* There is one parameter - original, i.e. 'derived' class metatable */
1914 assert(lua_istable(L, -1));
1915 int original = lua_gettop(L);
1916 SWIG_Lua_get_class_metatable(L, base_cls->fqname);
1917 int base = lua_gettop(L);
1918 SWIG_Lua_merge_tables(L, ".fn", original, base);
1919 SWIG_Lua_merge_tables(L, ".set", original, base);
1920 SWIG_Lua_merge_tables(L, ".get", original, base);
1921 lua_pop(L, 1);
1924 /* Function squashes all symbols from 'clss' bases into itself */
1925 SWIGINTERN void SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss) {
1926 int i;
1927 SWIG_Lua_get_class_metatable(L, clss->fqname);
1928 for (i = 0; clss->base_names[i]; i++) {
1929 if (clss->bases[i] == 0) /* Somehow it's not found. Skip it */
1930 continue;
1931 /* Thing is: all bases are already registered. Thus they have already executed
1932 * this function. So we just need to squash them into us, because their bases
1933 * are already squashed into them. No need for recursion here!
1935 SWIG_Lua_class_squash_base(L, clss->bases[i]);
1937 lua_pop(L, 1); /*tidy stack*/
1939 #endif
1941 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) /* In elua this is useless */
1942 /* helper add a variable to a registered class */
1943 SWIGINTERN void SWIG_Lua_add_variable(lua_State *L, const char *name, lua_CFunction getFn, lua_CFunction setFn) {
1944 assert(lua_istable(L, -1)); /* just in case */
1945 SWIG_Lua_get_table(L, ".get"); /* find the .get table */
1946 assert(lua_istable(L, -1)); /* just in case */
1947 SWIG_Lua_add_function(L, name, getFn);
1948 lua_pop(L, 1); /* tidy stack (remove table) */
1949 if (setFn) {
1950 SWIG_Lua_get_table(L, ".set"); /* find the .set table */
1951 assert(lua_istable(L, -1)); /* just in case */
1952 SWIG_Lua_add_function(L, name, setFn);
1953 lua_pop(L, 1); /* tidy stack (remove table) */
1957 /* helper to recursively add class static details (static attributes, operations and constants) */
1958 SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State *L, swig_lua_class *clss) {
1959 int i = 0;
1960 /* The class namespace table must be on the top of the stack */
1961 assert(lua_istable(L, -1));
1962 /* call all the base classes first: we can then override these later: */
1963 for (i = 0; clss->bases[i]; i++) {
1964 SWIG_Lua_add_class_static_details(L, clss->bases[i]);
1967 SWIG_Lua_add_namespace_details(L, clss->cls_static);
1970 SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss); /* forward declaration */
1972 /* helper to recursively add class details (attributes & operations) */
1973 SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L, swig_lua_class *clss) {
1974 int i;
1975 size_t bases_count = 0;
1976 /* Add bases to .bases table */
1977 SWIG_Lua_get_table(L, ".bases");
1978 assert(lua_istable(L, -1)); /* just in case */
1979 for (i = 0; clss->bases[i]; i++) {
1980 SWIG_Lua_get_class_metatable(L, clss->bases[i]->fqname);
1981 /* Base class must be already registered */
1982 assert(lua_istable(L, -1));
1983 lua_rawseti(L, -2, i + 1); /* In lua indexing starts from 1 */
1984 bases_count++;
1986 assert(lua_rawlen(L, -1) == bases_count);
1987 lua_pop(L, 1); /* remove .bases table */
1988 /* add attributes */
1989 for (i = 0; clss->attributes[i].name; i++) {
1990 SWIG_Lua_add_variable(L, clss->attributes[i].name, clss->attributes[i].getmethod, clss->attributes[i].setmethod);
1992 /* add methods to the metatable */
1993 SWIG_Lua_get_table(L, ".fn"); /* find the .fn table */
1994 assert(lua_istable(L, -1)); /* just in case */
1995 for (i = 0; clss->methods[i].name; i++) {
1996 SWIG_Lua_add_function(L, clss->methods[i].name, clss->methods[i].func);
1998 lua_pop(L, 1); /* tidy stack (remove table) */
1999 /* add operator overloads
2000 This adds methods from metatable array to metatable. Can mess up garbage
2001 collectind if someone defines __gc method
2003 if (clss->metatable) {
2004 for (i = 0; clss->metatable[i].name; i++) {
2005 SWIG_Lua_add_function(L, clss->metatable[i].name, clss->metatable[i].func);
2009 #if !defined(SWIG_LUA_SQUASH_BASES)
2010 /* Adding metamethods that are defined in base classes. If bases were squashed
2011 * then it is obviously unnecessary
2013 SWIG_Lua_add_class_user_metamethods(L, clss);
2014 #endif
2017 /* Helpers to add user defined class metamedhods - __add, __sub etc. The helpers are needed
2018 for the following issue: Lua runtime checks for metamethod existence with rawget function
2019 ignoring our SWIG-provided __index and __newindex functions. Thus our inheritance-aware method
2020 search algorithm doesn't work in such case. (Not to say that Lua runtime queries metamethod directly
2021 in metatable and not in object).
2022 Current solution is this: if somewhere in hierarchy metamethod __x is defined, then all descendants
2023 are automatically given a special proxy __x that calls the real __x method.
2024 Obvious idea - to copy __x instead of creating __x-proxy is wrong because if someone changes __x in runtime,
2025 those changes must be reflected in all descendants.
2028 SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L); /*forward declaration*/
2030 /* The real function that resolves a metamethod.
2031 * Function searches given class and all it's bases(recursively) for first instance of something that is
2032 * not equal to SWIG_Lua_resolve_metatmethod. (Almost always this 'something' is actual metamethod implementation
2033 * and it is a SWIG-generated C function.). It returns value on the top of the L and there is no garbage below the
2034 * answer.
2035 * Returns 1 if found, 0 otherwise.
2036 * clss is class which metatable we will search for method
2037 * metamethod_name_idx is index in L where metamethod name (as string) lies
2038 * skip_check allows to skip searching metamethod in givel clss and immideatelly go to searching in bases. skip_check
2039 * is not caried to subsequent recursive calls - false is always passed. It is set to true only at first call from
2040 * SWIG_Lua_resolve_metamethod
2041 * */
2042 SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class *clss, int metamethod_name_idx,
2043 int skip_check) {
2044 /* This function is called recursively */
2045 int result = 0;
2046 int i = 0;
2048 if (!skip_check) {
2049 SWIG_Lua_get_class_metatable(L, clss->fqname);
2050 lua_pushvalue(L, metamethod_name_idx);
2051 lua_rawget(L, -2);
2052 /* If this is cfunction and it is equal to SWIG_Lua_resolve_metamethod then
2053 * this isn't the function we are looking for :)
2054 * lua_tocfunction will return NULL if not cfunction
2056 if (!lua_isnil(L, -1) && lua_tocfunction(L, -1) != SWIG_Lua_resolve_metamethod) {
2057 lua_remove(L, -2); /* removing class metatable */
2058 return 1;
2060 lua_pop(L, 2); /* remove class metatable and query result */
2063 /* Forwarding calls to bases */
2064 for (i = 0; clss->bases[i]; i++) {
2065 result = SWIG_Lua_do_resolve_metamethod(L, clss->bases[i], metamethod_name_idx, 0);
2066 if (result)
2067 break;
2070 return result;
2073 /* The proxy function for metamethod. All parameters are passed as cclosure. Searches for actual method
2074 * and calls it */
2075 SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L) {
2076 int numargs;
2077 int metamethod_name_idx;
2078 const swig_lua_class *clss;
2079 int result;
2081 lua_checkstack(L, 5);
2082 numargs = lua_gettop(L); /* number of arguments to pass to actual metamethod */
2084 /* Get upvalues from closure */
2085 lua_pushvalue(L, lua_upvalueindex(1)); /*Get function name*/
2086 metamethod_name_idx = lua_gettop(L);
2088 lua_pushvalue(L, lua_upvalueindex(2));
2089 clss = (const swig_lua_class *)(lua_touserdata(L, -1));
2090 lua_pop(L, 1); /* remove lightuserdata with clss from stack */
2092 /* Actual work */
2093 result = SWIG_Lua_do_resolve_metamethod(L, clss, metamethod_name_idx, 1);
2094 if (!result) {
2095 SWIG_Lua_pushferrstring(L, "The metamethod proxy is set, but it failed to find actual metamethod. Memory corruption is most likely explanation.");
2096 lua_error(L);
2097 return 0;
2100 lua_remove(L, -2); /* remove metamethod key */
2101 lua_insert(L, 1); /* move function to correct position */
2102 lua_call(L, numargs, LUA_MULTRET);
2103 return lua_gettop(L); /* return all results */
2107 /* If given metamethod must be present in given class, then creates appropriate proxy
2108 * Returns 1 if successfully added, 0 if not added because no base class has it, -1
2109 * if method is defined in the class metatable itself
2111 SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *clss, const int metatable_index) {
2112 int key_index;
2113 int success = 0;
2114 int i = 0;
2116 /* metamethod name - on the top of the stack */
2117 assert(lua_isstring(L, -1));
2119 key_index = lua_gettop(L);
2121 /* Check whether method is already defined in metatable */
2122 lua_pushvalue(L, key_index); /* copy of the key */
2123 lua_gettable(L, metatable_index);
2124 if (!lua_isnil(L, -1)) {
2125 lua_pop(L, 1);
2126 return -1;
2128 lua_pop(L, 1);
2130 /* Iterating over immediate bases */
2131 for (i = 0; clss->bases[i]; i++) {
2132 const swig_lua_class *base = clss->bases[i];
2133 SWIG_Lua_get_class_metatable(L, base->fqname);
2134 lua_pushvalue(L, key_index);
2135 lua_rawget(L, -2);
2136 if (!lua_isnil(L, -1)) {
2137 lua_pushvalue(L, key_index);
2139 /* Add proxy function */
2140 lua_pushvalue(L, key_index); /* first closure value is function name */
2141 lua_pushlightuserdata(L, clss); /* second closure value is swig_lua_class structure */
2142 lua_pushcclosure(L, SWIG_Lua_resolve_metamethod, 2);
2144 lua_rawset(L, metatable_index);
2145 success = 1;
2147 lua_pop(L, 1); /* remove function or nil */
2148 lua_pop(L, 1); /* remove base class metatable */
2150 if (success)
2151 break;
2154 return success;
2157 SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss) {
2158 int metatable_index;
2159 int metamethods_info_index;
2160 int tostring_undefined;
2161 int eq_undefined = 0;
2163 SWIG_Lua_get_class_metatable(L, clss->fqname);
2164 metatable_index = lua_gettop(L);
2165 SWIG_Lua_get_inheritable_metamethods(L);
2166 assert(lua_istable(L, -1));
2167 metamethods_info_index = lua_gettop(L);
2168 lua_pushnil(L); /* first key */
2169 while (lua_next(L, metamethods_info_index) != 0) {
2170 /* key at index -2, value at index -1 */
2171 const int is_inheritable = lua_toboolean(L, -2);
2172 lua_pop(L, 1); /* remove value - we don't need it anymore */
2174 if (is_inheritable) { /* if metamethod is inheritable */
2175 SWIG_Lua_add_class_user_metamethod(L, clss, metatable_index);
2179 lua_pop(L, 1); /* remove inheritable metatmethods table */
2181 /* Special handling for __tostring method */
2182 lua_pushstring(L, "__tostring");
2183 lua_pushvalue(L, -1);
2184 lua_rawget(L, metatable_index);
2185 tostring_undefined = lua_isnil(L, -1);
2186 lua_pop(L, 1);
2187 if (tostring_undefined) {
2188 lua_pushcfunction(L, SWIG_Lua_class_tostring);
2189 lua_rawset(L, metatable_index);
2190 } else {
2191 lua_pop(L, 1); /* remove copy of the key */
2194 /* Special handling for __eq method */
2195 lua_pushstring(L, "__eq");
2196 lua_pushvalue(L, -1);
2197 lua_rawget(L, metatable_index);
2198 eq_undefined = lua_isnil(L, -1);
2199 lua_pop(L, 1);
2200 if (eq_undefined) {
2201 lua_pushcfunction(L, SWIG_Lua_class_equal);
2202 lua_rawset(L, metatable_index);
2203 } else {
2204 lua_pop(L, 1); /* remove copy of the key */
2206 /* Warning: __index and __newindex are SWIG-defined. For user-defined operator[]
2207 * a __getitem/__setitem method should be defined
2209 lua_pop(L, 1); /* pop class metatable */
2212 /* Register class static methods,attributes etc as well as constructor proxy */
2213 SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *clss) {
2214 const int SWIGUNUSED begin = lua_gettop(L);
2215 lua_checkstack(L, 5); /* just in case */
2216 assert(lua_istable(L, -1)); /* just in case */
2217 assert(strcmp(clss->name, clss->cls_static->name) == 0); /* in class those 2 must be equal */
2219 SWIG_Lua_namespace_register(L, clss->cls_static, 1);
2221 assert(lua_istable(L, -1)); /* just in case */
2223 /* add its constructor to module with the name of the class
2224 so you can do MyClass(...) as well as new_MyClass(...)
2225 BUT only if a constructor is defined
2226 (this overcomes the problem of pure virtual classes without constructors)*/
2227 if (clss->constructor) {
2228 lua_getmetatable(L, -1);
2229 assert(lua_istable(L, -1)); /* just in case */
2230 SWIG_Lua_add_function(L, "__call", clss->constructor);
2231 lua_pop(L, 1);
2234 assert(lua_istable(L, -1)); /* just in case */
2235 SWIG_Lua_add_class_static_details(L, clss);
2237 /* clear stack */
2238 lua_pop(L, 1);
2239 assert(lua_gettop(L) == begin);
2242 /* Performs the instance (non-static) class registration process. Metatable for class is created
2243 * and added to the class registry.
2245 SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L, swig_lua_class *clss) {
2246 const int SWIGUNUSED begin = lua_gettop(L);
2247 int i;
2248 /* if name already there (class is already registered) then do nothing */
2249 SWIG_Lua_get_class_registry(L); /* get the registry */
2250 lua_pushstring(L, clss->fqname); /* get the name */
2251 lua_rawget(L, -2);
2252 if (!lua_isnil(L, -1)) {
2253 lua_pop(L, 2);
2254 assert(lua_gettop(L) == begin);
2255 return;
2257 lua_pop(L, 2); /* tidy stack */
2258 /* Recursively initialize all bases */
2259 for (i = 0; clss->bases[i]; i++) {
2260 SWIG_Lua_class_register_instance(L, clss->bases[i]);
2262 /* Again, get registry and push name */
2263 SWIG_Lua_get_class_registry(L); /* get the registry */
2264 lua_pushstring(L, clss->fqname); /* get the name */
2265 lua_newtable(L); /* create the metatable */
2266 #if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
2267 /* If squashing is requested, then merges all bases metatable into this one.
2268 * It would get us all special methods: __getitem, __add etc.
2269 * This would set .fn, .type, and other .xxx incorrectly, but we will overwrite it right away
2272 int new_metatable_index = lua_absindex(L, -1);
2273 for (i = 0; clss->bases[i]; i++) {
2274 int base_metatable;
2275 SWIG_Lua_get_class_metatable(L, clss->bases[i]->fqname);
2276 base_metatable = lua_absindex(L, -1);
2277 SWIG_Lua_merge_tables_by_index(L, new_metatable_index, base_metatable);
2278 lua_pop(L, 1);
2281 /* And now we will overwrite all incorrectly set data */
2282 #endif
2283 /* add string of class name called ".type" */
2284 lua_pushstring(L, ".type");
2285 lua_pushstring(L, clss->fqname);
2286 lua_rawset(L, -3);
2287 /* add a table called bases */
2288 lua_pushstring(L, ".bases");
2289 lua_newtable(L);
2290 lua_rawset(L, -3);
2291 /* add a table called ".get" */
2292 lua_pushstring(L, ".get");
2293 lua_newtable(L);
2294 lua_rawset(L, -3);
2295 /* add a table called ".set" */
2296 lua_pushstring(L, ".set");
2297 lua_newtable(L);
2298 lua_rawset(L, -3);
2299 /* add a table called ".fn" */
2300 lua_pushstring(L, ".fn");
2301 lua_newtable(L);
2302 /* add manual disown method */
2303 SWIG_Lua_add_function(L, "__disown", SWIG_Lua_class_disown);
2304 lua_rawset(L, -3);
2305 /* add accessor fns for using the .get,.set&.fn */
2306 SWIG_Lua_add_function(L, "__index", SWIG_Lua_class_get);
2307 SWIG_Lua_add_function(L, "__newindex", SWIG_Lua_class_set);
2308 SWIG_Lua_add_function(L, "__gc", SWIG_Lua_class_destruct);
2309 /* add it */
2310 lua_rawset(L, -3); /* metatable into registry */
2311 lua_pop(L, 1); /* tidy stack (remove registry) */
2312 assert(lua_gettop(L) == begin);
2314 #if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
2315 /* Now merge all symbols from .fn, .set, .get etc from bases to our tables */
2316 SWIG_Lua_class_squash_bases(L, clss);
2317 #endif
2318 SWIG_Lua_get_class_metatable(L, clss->fqname);
2319 SWIG_Lua_add_class_instance_details(L, clss); /* recursive adding of details (atts & ops) */
2320 lua_pop(L, 1); /* tidy stack (remove class metatable) */
2321 assert(lua_gettop(L) == begin);
2324 SWIGINTERN void SWIG_Lua_class_register(lua_State *L, swig_lua_class *clss) {
2325 int SWIGUNUSED begin;
2326 assert(lua_istable(L, -1)); /* This is a table (module or namespace) where classes will be added */
2327 SWIG_Lua_class_register_instance(L, clss);
2328 SWIG_Lua_class_register_static(L, clss);
2330 /* Add links from static part to instance part and vice versa */
2331 /* [SWIG registry] [Module]
2332 * "MyClass" ----> [MyClass metatable] <===== "MyClass" -+> [static part]
2333 * ".get" ----> ... | | getmetatable()----|
2334 * ".set" ----> ... | | |
2335 * ".static" --------------)----------------/ [static part metatable]
2336 * | ".get" --> ...
2337 * | ".set" --> ....
2338 * |=============================== ".instance"
2340 begin = lua_gettop(L);
2341 lua_pushstring(L, clss->cls_static->name);
2342 lua_rawget(L, -2); /* get class static table */
2343 assert(lua_istable(L, -1));
2344 lua_getmetatable(L, -1);
2345 assert(lua_istable(L, -1)); /* get class static metatable */
2346 lua_pushstring(L, ".instance"); /* prepare key */
2348 SWIG_Lua_get_class_metatable(L, clss->fqname); /* get class metatable */
2349 assert(lua_istable(L, -1));
2350 lua_pushstring(L, ".static"); /* prepare key */
2351 lua_pushvalue(L, -4); /* push static class TABLE */
2352 assert(lua_istable(L, -1));
2353 lua_rawset(L, -3); /* assign static class table(!NOT metatable) as ".static" member of class metatable */
2354 lua_rawset(L, -3); /* assign class metatable as ".instance" member of class static METATABLE */
2355 lua_pop(L, 2);
2356 assert(lua_gettop(L) == begin);
2358 #endif /* SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA */
2360 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
2361 SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_class *clss) {
2362 const int SWIGUNUSED begin = lua_gettop(L);
2363 int i;
2364 /* if name already there (class is already registered) then do nothing */
2365 SWIG_Lua_get_class_registry(L); /* get the registry */
2366 lua_pushstring(L, clss->fqname); /* get the name */
2367 lua_rawget(L, -2);
2368 if (!lua_isnil(L, -1)) {
2369 lua_pop(L, 2);
2370 assert(lua_gettop(L) == begin);
2371 return;
2373 lua_pop(L, 2); /* tidy stack */
2374 /* Recursively initialize all bases */
2375 for (i = 0; clss->bases[i]; i++) {
2376 SWIG_Lua_elua_class_register_instance(L, clss->bases[i]);
2378 /* Again, get registry and push name */
2379 SWIG_Lua_get_class_registry(L); /* get the registry */
2380 lua_pushstring(L, clss->fqname); /* get the name */
2381 assert(clss->metatable);
2382 lua_pushrotable(L, (void *)(clss->metatable)); /* create the metatable */
2383 lua_rawset(L, -3);
2384 lua_pop(L, 1);
2385 assert(lua_gettop(L) == begin);
2387 #endif /* elua && eluac */
2389 /* -----------------------------------------------------------------------------
2390 * Class/structure conversion fns
2391 * ----------------------------------------------------------------------------- */
2393 /* helper to add metatable to new lua object */
2394 SWIGINTERN void SWIG_Lua_AddMetatable(lua_State *L, swig_type_info *type) {
2395 if (type->clientdata) { /* there is clientdata: so add the metatable */
2396 SWIG_Lua_get_class_metatable(L, ((swig_lua_class *)(type->clientdata))->fqname);
2397 if (lua_istable(L, -1)) {
2398 lua_setmetatable(L, -2);
2399 } else {
2400 lua_pop(L, 1);
2405 /* pushes a new object into the lua stack */
2406 SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L, void *ptr, swig_type_info *type, int own) {
2407 swig_lua_userdata *usr;
2408 if (!ptr) {
2409 lua_pushnil(L);
2410 return;
2412 usr = (swig_lua_userdata *)lua_newuserdata(L, sizeof(swig_lua_userdata)); /* get data */
2413 usr->ptr = ptr; /* set the ptr */
2414 usr->type = type;
2415 usr->own = own;
2416 #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
2417 SWIG_Lua_AddMetatable(L, type); /* add metatable */
2418 #endif
2421 /* takes a object from the lua stack & converts it into an object of the correct type
2422 (if possible) */
2423 SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L, int index, void **ptr, swig_type_info *type, int flags) {
2424 swig_lua_userdata *usr;
2425 swig_cast_info *cast;
2426 /* special case: lua nil => NULL pointer */
2427 if (lua_isnil(L, index)) {
2428 *ptr = 0;
2429 return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
2431 usr = (swig_lua_userdata *)lua_touserdata(L, index); /* get data */
2432 if (usr) {
2433 if (flags & SWIG_POINTER_DISOWN) { /* must disown the object */
2434 usr->own = 0;
2436 if (!type) { /* special cast void*, no casting fn */
2437 *ptr = usr->ptr;
2438 return SWIG_OK; /* ok */
2440 cast = SWIG_TypeCheckStruct(usr->type, type); /* performs normal type checking */
2441 if (cast) {
2442 int newmemory = 0;
2443 *ptr = SWIG_TypeCast(cast, usr->ptr, &newmemory);
2444 assert(!newmemory); /* newmemory handling not yet implemented */
2445 return SWIG_OK; /* ok */
2448 return SWIG_ERROR; /* error */
2451 SWIGRUNTIME void *SWIG_Lua_MustGetPtr(lua_State *L, int index, swig_type_info *type, int flags,
2452 int argnum, const char *func_name) {
2453 void *result;
2454 if (!SWIG_IsOK(SWIG_ConvertPtr(L, index, &result, type, flags))) {
2455 luaL_error(L, "Error in %s, expected a %s at argument number %d\n",
2456 func_name, (type && type->str) ? type->str : "void*", argnum);
2458 return result;
2461 /* pushes a packed userdata. user for member fn pointers only */
2462 SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L, void *ptr, size_t size, swig_type_info *type) {
2463 swig_lua_rawdata *raw;
2464 assert(ptr); /* not acceptable to pass in a NULL value */
2465 raw = (swig_lua_rawdata *)lua_newuserdata(L, sizeof(swig_lua_rawdata) - 1 + size); /* alloc data */
2466 raw->type = type;
2467 raw->own = 0;
2468 memcpy(raw->data, ptr, size); /* copy the data */
2469 SWIG_Lua_AddMetatable(L, type); /* add metatable */
2472 /* converts a packed userdata. user for member fn pointers only */
2473 SWIGRUNTIME int SWIG_Lua_ConvertPacked(lua_State *L, int index, void *ptr, size_t size, swig_type_info *type) {
2474 swig_lua_rawdata *raw;
2475 raw = (swig_lua_rawdata *)lua_touserdata(L, index); /* get data */
2476 if (!raw) return SWIG_ERROR; /* error */
2477 if (type == 0 || type == raw->type) { /* void* or identical type */
2478 memcpy(ptr, raw->data, size); /* copy it */
2479 return SWIG_OK; /* ok */
2481 return SWIG_ERROR; /* error */
2484 /* a function to get the typestring of a piece of data */
2485 SWIGRUNTIME const char *SWIG_Lua_typename(lua_State *L, int tp) {
2486 swig_lua_userdata *usr;
2487 if (lua_isuserdata(L, tp)) {
2488 usr = (swig_lua_userdata *)lua_touserdata(L, tp); /* get data */
2489 if (usr && usr->type && usr->type->str)
2490 return usr->type->str;
2491 return "userdata (unknown type)";
2493 return lua_typename(L, lua_type(L, tp));
2496 /* lua callable function to get the userdata's type */
2497 SWIGRUNTIME int SWIG_Lua_type(lua_State *L) {
2498 lua_pushstring(L, SWIG_Lua_typename(L, 1));
2499 return 1;
2502 /* -----------------------------------------------------------------------------
2503 * global variable support code: class/struct typemap functions
2504 * ----------------------------------------------------------------------------- */
2506 #if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
2507 /* Install Constants */
2508 SWIGINTERN void
2509 SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]) {
2510 int i;
2511 for (i = 0; constants[i].type; i++) {
2512 switch (constants[i].type) {
2513 case SWIG_LUA_INT:
2514 lua_pushstring(L, constants[i].name);
2515 lua_pushinteger(L, (lua_Integer)constants[i].lvalue);
2516 lua_rawset(L, -3);
2517 break;
2518 case SWIG_LUA_FLOAT:
2519 lua_pushstring(L, constants[i].name);
2520 lua_pushnumber(L, (lua_Number)constants[i].dvalue);
2521 lua_rawset(L, -3);
2522 break;
2523 case SWIG_LUA_CHAR:
2524 lua_pushstring(L, constants[i].name);
2526 char c = (char)constants[i].lvalue;
2527 lua_pushlstring(L, &c, 1);
2529 lua_rawset(L, -3);
2530 break;
2531 case SWIG_LUA_STRING:
2532 lua_pushstring(L, constants[i].name);
2533 lua_pushstring(L, (char *) constants[i].pvalue);
2534 lua_rawset(L, -3);
2535 break;
2536 case SWIG_LUA_POINTER:
2537 lua_pushstring(L, constants[i].name);
2538 SWIG_NewPointerObj(L, constants[i].pvalue, *(constants[i]).ptype, 0);
2539 lua_rawset(L, -3);
2540 break;
2541 case SWIG_LUA_BINARY:
2542 lua_pushstring(L, constants[i].name);
2543 SWIG_NewMemberObj(L, constants[i].pvalue, constants[i].lvalue, *(constants[i]).ptype);
2544 lua_rawset(L, -3);
2545 break;
2546 default:
2547 break;
2551 #endif
2553 /* -----------------------------------------------------------------------------
2554 * executing lua code from within the wrapper
2555 * ----------------------------------------------------------------------------- */
2557 #ifndef SWIG_DOSTRING_FAIL /* Allows redefining of error function */
2558 #define SWIG_DOSTRING_FAIL(S) fprintf(stderr,"%s\n",S)
2559 #endif
2560 /* Executes a C string in Lua which is a really simple way of calling lua from C
2561 Unfortunately lua keeps changing its APIs, so we need a conditional compile
2562 In lua 5.0.X it's lua_dostring()
2563 In lua 5.1.X it's luaL_dostring()
2565 SWIGINTERN int
2566 SWIG_Lua_dostring(lua_State *L, const char *str) {
2567 int ok, top;
2568 if (str == 0 || str[0] == 0) return 0; /* nothing to do */
2569 top = lua_gettop(L); /* save stack */
2570 #if (defined(LUA_VERSION_NUM) && (LUA_VERSION_NUM>=501))
2571 ok = luaL_dostring(L, str); /* looks like this is lua 5.1.X or later, good */
2572 #else
2573 ok = lua_dostring(L, str); /* might be lua 5.0.x, using lua_dostring */
2574 #endif
2575 if (ok != 0) {
2576 SWIG_DOSTRING_FAIL(lua_tostring(L, -1));
2578 lua_settop(L, top); /* restore the stack */
2579 return ok;
2582 #ifdef __cplusplus
2584 #endif
2586 /* ------------------------------ end luarun.swg ------------------------------ */
2589 /* -------- TYPES TABLE (BEGIN) -------- */
2591 #define SWIGTYPE_p_pm3 swig_types[0]
2592 static swig_type_info *swig_types[2];
2593 static swig_module_info swig_module = {swig_types, 1, 0, 0, 0, 0};
2594 #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
2595 #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
2597 /* -------- TYPES TABLE (END) -------- */
2599 #define SWIG_name "pm3"
2600 #define SWIG_init luaopen_pm3
2601 #define SWIG_init_user luaopen_pm3_user
2603 #define SWIG_LUACODE luaopen_pm3_luacode
2605 /* Include the header in the wrapper code */
2606 #include "pm3.h"
2607 #include "comms.h"
2609 SWIGINTERN pm3 *new_pm3__SWIG_0(void) {
2610 // printf("SWIG pm3 constructor, get current pm3\n");
2611 pm3_device *p = pm3_get_current_dev();
2612 p->script_embedded = 1;
2613 return p;
2616 SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) {
2617 int ret = lua_isstring(L, idx);
2618 if (!ret)
2619 ret = lua_isnil(L, idx);
2620 return ret;
2623 SWIGINTERN pm3 *new_pm3__SWIG_1(char *port) {
2624 // printf("SWIG pm3 constructor with port, open pm3\n");
2625 pm3_device *p = pm3_open(port);
2626 p->script_embedded = 0;
2627 return p;
2629 SWIGINTERN void delete_pm3(pm3 *self) {
2630 if (self->script_embedded) {
2631 // printf("SWIG pm3 destructor, nothing to do\n");
2632 } else {
2633 // printf("SWIG pm3 destructor, close pm3\n");
2634 pm3_close(self);
2637 #ifdef __cplusplus
2638 extern "C" {
2639 #endif
2640 static int _wrap_new_pm3__SWIG_0(lua_State *L) {
2641 int SWIG_arg = 0;
2642 pm3 *result = 0 ;
2644 SWIG_check_num_args("pm3::pm3", 0, 0)
2645 result = (pm3 *)new_pm3__SWIG_0();
2646 SWIG_NewPointerObj(L, result, SWIGTYPE_p_pm3, 1);
2647 SWIG_arg++;
2648 return SWIG_arg;
2650 if (0) SWIG_fail;
2652 fail:
2653 lua_error(L);
2654 return SWIG_arg;
2658 static int _wrap_new_pm3__SWIG_1(lua_State *L) {
2659 int SWIG_arg = 0;
2660 char *arg1 = (char *) 0 ;
2661 pm3 *result = 0 ;
2663 SWIG_check_num_args("pm3::pm3", 1, 1)
2664 if (!SWIG_lua_isnilstring(L, 1)) SWIG_fail_arg("pm3::pm3", 1, "char *");
2665 arg1 = (char *)lua_tostring(L, 1);
2666 result = (pm3 *)new_pm3__SWIG_1(arg1);
2667 SWIG_NewPointerObj(L, result, SWIGTYPE_p_pm3, 1);
2668 SWIG_arg++;
2669 return SWIG_arg;
2671 if (0) SWIG_fail;
2673 fail:
2674 lua_error(L);
2675 return SWIG_arg;
2679 static int _wrap_new_pm3(lua_State *L) {
2680 int argc;
2681 int argv[2] = {
2682 1, 2
2685 argc = lua_gettop(L);
2686 if (argc == 0) {
2687 return _wrap_new_pm3__SWIG_0(L);
2689 if (argc == 1) {
2690 int _v;
2692 _v = SWIG_lua_isnilstring(L, argv[0]);
2694 if (_v) {
2695 return _wrap_new_pm3__SWIG_1(L);
2699 SWIG_Lua_pusherrstring(L, "Wrong arguments for overloaded function 'new_pm3'\n"
2700 " Possible C/C++ prototypes are:\n"
2701 " pm3::pm3()\n"
2702 " pm3::pm3(char *)\n");
2703 lua_error(L);
2704 return 0;
2708 static int _wrap_pm3_console(lua_State *L) {
2709 int SWIG_arg = 0;
2710 pm3 *arg1 = (pm3 *) 0 ;
2711 char *arg2 = (char *) 0 ;
2712 int result;
2714 SWIG_check_num_args("pm3::console", 2, 2)
2715 if (!SWIG_isptrtype(L, 1)) SWIG_fail_arg("pm3::console", 1, "pm3 *");
2716 if (!SWIG_lua_isnilstring(L, 2)) SWIG_fail_arg("pm3::console", 2, "char *");
2718 if (!SWIG_IsOK(SWIG_ConvertPtr(L, 1, (void **)&arg1, SWIGTYPE_p_pm3, 0))) {
2719 SWIG_fail_ptr("pm3_console", 1, SWIGTYPE_p_pm3);
2722 arg2 = (char *)lua_tostring(L, 2);
2723 result = (int)pm3_console(arg1, arg2);
2724 lua_pushnumber(L, (lua_Number) result);
2725 SWIG_arg++;
2726 return SWIG_arg;
2728 if (0) SWIG_fail;
2730 fail:
2731 lua_error(L);
2732 return SWIG_arg;
2736 static int _wrap_pm3_name_get(lua_State *L) {
2737 int SWIG_arg = 0;
2738 pm3 *arg1 = (pm3 *) 0 ;
2739 char *result = 0 ;
2741 SWIG_check_num_args("pm3::name", 1, 1)
2742 if (!SWIG_isptrtype(L, 1)) SWIG_fail_arg("pm3::name", 1, "pm3 *");
2744 if (!SWIG_IsOK(SWIG_ConvertPtr(L, 1, (void **)&arg1, SWIGTYPE_p_pm3, 0))) {
2745 SWIG_fail_ptr("pm3_name_get", 1, SWIGTYPE_p_pm3);
2748 result = (char *)pm3_name_get(arg1);
2749 lua_pushstring(L, (const char *)result);
2750 SWIG_arg++;
2751 return SWIG_arg;
2753 if (0) SWIG_fail;
2755 fail:
2756 lua_error(L);
2757 return SWIG_arg;
2761 static void swig_delete_pm3(void *obj) {
2762 pm3 *arg1 = (pm3 *) obj;
2763 delete_pm3(arg1);
2765 static int _proxy__wrap_new_pm3(lua_State *L) {
2766 assert(lua_istable(L, 1));
2767 lua_pushcfunction(L, _wrap_new_pm3);
2768 assert(!lua_isnil(L, -1));
2769 lua_replace(L, 1); /* replace our table with real constructor */
2770 lua_call(L, lua_gettop(L) - 1, 1);
2771 return 1;
2773 static swig_lua_attribute swig_pm3_attributes[] = {
2774 { "name", _wrap_pm3_name_get, SWIG_Lua_set_immutable },
2775 {0, 0, 0}
2777 static swig_lua_method swig_pm3_methods[] = {
2778 { "console", _wrap_pm3_console},
2779 {0, 0}
2781 static swig_lua_method swig_pm3_meta[] = {
2782 {0, 0}
2785 static swig_lua_attribute swig_pm3_Sf_SwigStatic_attributes[] = {
2786 {0, 0, 0}
2788 static swig_lua_const_info swig_pm3_Sf_SwigStatic_constants[] = {
2789 {0, 0, 0, 0, 0, 0}
2791 static swig_lua_method swig_pm3_Sf_SwigStatic_methods[] = {
2792 {0, 0}
2794 static swig_lua_class *swig_pm3_Sf_SwigStatic_classes[] = {
2798 static swig_lua_namespace swig_pm3_Sf_SwigStatic = {
2799 "pm3",
2800 swig_pm3_Sf_SwigStatic_methods,
2801 swig_pm3_Sf_SwigStatic_attributes,
2802 swig_pm3_Sf_SwigStatic_constants,
2803 swig_pm3_Sf_SwigStatic_classes,
2806 static swig_lua_class *swig_pm3_bases[] = {0};
2807 static const char *swig_pm3_base_names[] = {0};
2808 static swig_lua_class _wrap_class_pm3 = { "pm3", "pm3", &SWIGTYPE_p_pm3, _proxy__wrap_new_pm3, swig_delete_pm3, swig_pm3_methods, swig_pm3_attributes, &swig_pm3_Sf_SwigStatic, swig_pm3_meta, swig_pm3_bases, swig_pm3_base_names };
2810 static swig_lua_attribute swig_SwigModule_attributes[] = {
2811 {0, 0, 0}
2813 static swig_lua_const_info swig_SwigModule_constants[] = {
2814 {0, 0, 0, 0, 0, 0}
2816 static swig_lua_method swig_SwigModule_methods[] = {
2817 {0, 0}
2819 static swig_lua_class *swig_SwigModule_classes[] = {
2820 &_wrap_class_pm3,
2823 static swig_lua_namespace *swig_SwigModule_namespaces[] = {
2827 static swig_lua_namespace swig_SwigModule = {
2828 "pm3",
2829 swig_SwigModule_methods,
2830 swig_SwigModule_attributes,
2831 swig_SwigModule_constants,
2832 swig_SwigModule_classes,
2833 swig_SwigModule_namespaces
2835 #ifdef __cplusplus
2837 #endif
2839 /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
2841 static swig_type_info _swigt__p_pm3 = {"_p_pm3", "pm3 *", 0, 0, (void *) &_wrap_class_pm3, 0};
2843 static swig_type_info *swig_type_initial[] = {
2844 &_swigt__p_pm3,
2847 static swig_cast_info _swigc__p_pm3[] = { {&_swigt__p_pm3, 0, 0, 0}, {0, 0, 0, 0}};
2849 static swig_cast_info *swig_cast_initial[] = {
2850 _swigc__p_pm3,
2854 /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */
2856 /* -----------------------------------------------------------------------------
2857 * Type initialization:
2858 * This problem is tough by the requirement that no dynamic
2859 * memory is used. Also, since swig_type_info structures store pointers to
2860 * swig_cast_info structures and swig_cast_info structures store pointers back
2861 * to swig_type_info structures, we need some lookup code at initialization.
2862 * The idea is that swig generates all the structures that are needed.
2863 * The runtime then collects these partially filled structures.
2864 * The SWIG_InitializeModule function takes these initial arrays out of
2865 * swig_module, and does all the lookup, filling in the swig_module.types
2866 * array with the correct data and linking the correct swig_cast_info
2867 * structures together.
2869 * The generated swig_type_info structures are assigned statically to an initial
2870 * array. We just loop through that array, and handle each type individually.
2871 * First we lookup if this type has been already loaded, and if so, use the
2872 * loaded structure instead of the generated one. Then we have to fill in the
2873 * cast linked list. The cast data is initially stored in something like a
2874 * two-dimensional array. Each row corresponds to a type (there are the same
2875 * number of rows as there are in the swig_type_initial array). Each entry in
2876 * a column is one of the swig_cast_info structures for that type.
2877 * The cast_initial array is actually an array of arrays, because each row has
2878 * a variable number of columns. So to actually build the cast linked list,
2879 * we find the array of casts associated with the type, and loop through it
2880 * adding the casts to the list. The one last trick we need to do is making
2881 * sure the type pointer in the swig_cast_info struct is correct.
2883 * First off, we lookup the cast->type name to see if it is already loaded.
2884 * There are three cases to handle:
2885 * 1) If the cast->type has already been loaded AND the type we are adding
2886 * casting info to has not been loaded (it is in this module), THEN we
2887 * replace the cast->type pointer with the type pointer that has already
2888 * been loaded.
2889 * 2) If BOTH types (the one we are adding casting info to, and the
2890 * cast->type) are loaded, THEN the cast info has already been loaded by
2891 * the previous module so we just ignore it.
2892 * 3) Finally, if cast->type has not already been loaded, then we add that
2893 * swig_cast_info to the linked list (because the cast->type) pointer will
2894 * be correct.
2895 * ----------------------------------------------------------------------------- */
2897 #ifdef __cplusplus
2898 extern "C" {
2899 #if 0
2900 } /* c-mode */
2901 #endif
2902 #endif
2904 #if 0
2905 #define SWIGRUNTIME_DEBUG
2906 #endif
2909 SWIGRUNTIME void
2910 SWIG_InitializeModule(void *clientdata) {
2911 size_t i;
2912 swig_module_info *module_head, *iter;
2913 int init;
2915 /* check to see if the circular list has been setup, if not, set it up */
2916 if (swig_module.next == 0) {
2917 /* Initialize the swig_module */
2918 swig_module.type_initial = swig_type_initial;
2919 swig_module.cast_initial = swig_cast_initial;
2920 swig_module.next = &swig_module;
2921 init = 1;
2922 } else {
2923 init = 0;
2926 /* Try and load any already created modules */
2927 module_head = SWIG_GetModule(clientdata);
2928 if (!module_head) {
2929 /* This is the first module loaded for this interpreter */
2930 /* so set the swig module into the interpreter */
2931 SWIG_SetModule(clientdata, &swig_module);
2932 } else {
2933 /* the interpreter has loaded a SWIG module, but has it loaded this one? */
2934 iter = module_head;
2935 do {
2936 if (iter == &swig_module) {
2937 /* Our module is already in the list, so there's nothing more to do. */
2938 return;
2940 iter = iter->next;
2941 } while (iter != module_head);
2943 /* otherwise we must add our module into the list */
2944 swig_module.next = module_head->next;
2945 module_head->next = &swig_module;
2948 /* When multiple interpreters are used, a module could have already been initialized in
2949 a different interpreter, but not yet have a pointer in this interpreter.
2950 In this case, we do not want to continue adding types... everything should be
2951 set up already */
2952 if (init == 0) return;
2954 /* Now work on filling in swig_module.types */
2955 #ifdef SWIGRUNTIME_DEBUG
2956 printf("SWIG_InitializeModule: size %lu\n", (unsigned long)swig_module.size);
2957 #endif
2958 for (i = 0; i < swig_module.size; ++i) {
2959 swig_type_info *type = 0;
2960 swig_type_info *ret;
2961 swig_cast_info *cast;
2963 #ifdef SWIGRUNTIME_DEBUG
2964 printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name);
2965 #endif
2967 /* if there is another module already loaded */
2968 if (swig_module.next != &swig_module) {
2969 type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name);
2971 if (type) {
2972 /* Overwrite clientdata field */
2973 #ifdef SWIGRUNTIME_DEBUG
2974 printf("SWIG_InitializeModule: found type %s\n", type->name);
2975 #endif
2976 if (swig_module.type_initial[i]->clientdata) {
2977 type->clientdata = swig_module.type_initial[i]->clientdata;
2978 #ifdef SWIGRUNTIME_DEBUG
2979 printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name);
2980 #endif
2982 } else {
2983 type = swig_module.type_initial[i];
2986 /* Insert casting types */
2987 cast = swig_module.cast_initial[i];
2988 while (cast->type) {
2990 /* Don't need to add information already in the list */
2991 ret = 0;
2992 #ifdef SWIGRUNTIME_DEBUG
2993 printf("SWIG_InitializeModule: look cast %s\n", cast->type->name);
2994 #endif
2995 if (swig_module.next != &swig_module) {
2996 ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name);
2997 #ifdef SWIGRUNTIME_DEBUG
2998 if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name);
2999 #endif
3001 if (ret) {
3002 if (type == swig_module.type_initial[i]) {
3003 #ifdef SWIGRUNTIME_DEBUG
3004 printf("SWIG_InitializeModule: skip old type %s\n", ret->name);
3005 #endif
3006 cast->type = ret;
3007 ret = 0;
3008 } else {
3009 /* Check for casting already in the list */
3010 swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type);
3011 #ifdef SWIGRUNTIME_DEBUG
3012 if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name);
3013 #endif
3014 if (!ocast) ret = 0;
3018 if (!ret) {
3019 #ifdef SWIGRUNTIME_DEBUG
3020 printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name);
3021 #endif
3022 if (type->cast) {
3023 type->cast->prev = cast;
3024 cast->next = type->cast;
3026 type->cast = cast;
3028 cast++;
3030 /* Set entry in modules->types array equal to the type */
3031 swig_module.types[i] = type;
3033 swig_module.types[i] = 0;
3035 #ifdef SWIGRUNTIME_DEBUG
3036 printf("**** SWIG_InitializeModule: Cast List ******\n");
3037 for (i = 0; i < swig_module.size; ++i) {
3038 int j = 0;
3039 swig_cast_info *cast = swig_module.cast_initial[i];
3040 printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name);
3041 while (cast->type) {
3042 printf("SWIG_InitializeModule: cast type %s\n", cast->type->name);
3043 cast++;
3044 ++j;
3046 printf("---- Total casts: %d\n", j);
3048 printf("**** SWIG_InitializeModule: Cast List ******\n");
3049 #endif
3052 /* This function will propagate the clientdata field of type to
3053 * any new swig_type_info structures that have been added into the list
3054 * of equivalent types. It is like calling
3055 * SWIG_TypeClientData(type, clientdata) a second time.
3057 SWIGRUNTIME void
3058 SWIG_PropagateClientData(void) {
3059 size_t i;
3060 swig_cast_info *equiv;
3061 static int init_run = 0;
3063 if (init_run) return;
3064 init_run = 1;
3066 for (i = 0; i < swig_module.size; i++) {
3067 if (swig_module.types[i]->clientdata) {
3068 equiv = swig_module.types[i]->cast;
3069 while (equiv) {
3070 if (!equiv->converter) {
3071 if (equiv->type && !equiv->type->clientdata)
3072 SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata);
3074 equiv = equiv->next;
3080 #ifdef __cplusplus
3081 #if 0
3083 /* c-mode */
3084 #endif
3086 #endif
3090 /* Forward declaration of where the user's %init{} gets inserted */
3091 void SWIG_init_user(lua_State *L);
3093 #ifdef __cplusplus
3094 extern "C" {
3095 #endif
3096 /* this is the initialization function
3097 added at the very end of the code
3098 the function is always called SWIG_init, but an earlier #define will rename it
3100 #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
3101 LUALIB_API int SWIG_init(lua_State *L)
3102 #else
3103 SWIGEXPORT int SWIG_init(lua_State *L) /* default Lua action */
3104 #endif
3106 #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) /* valid for both Lua and eLua */
3107 int i;
3108 int globalRegister = 0;
3109 /* start with global table */
3110 lua_pushglobaltable(L);
3111 /* SWIG's internal initialisation */
3112 SWIG_InitializeModule((void *)L);
3113 SWIG_PropagateClientData();
3114 #endif
3116 #if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)) || defined(SWIG_LUA_ELUA_EMULATE)
3117 /* add a global fn */
3118 SWIG_Lua_add_function(L, "swig_type", SWIG_Lua_type);
3119 SWIG_Lua_add_function(L, "swig_equals", SWIG_Lua_class_equal);
3120 #endif
3122 #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
3123 /* set up base class pointers (the hierarchy) */
3124 for (i = 0; swig_types[i]; i++) {
3125 if (swig_types[i]->clientdata) {
3126 SWIG_Lua_init_base_class(L, (swig_lua_class *)(swig_types[i]->clientdata));
3129 #ifdef SWIG_LUA_MODULE_GLOBAL
3130 globalRegister = 1;
3131 #endif
3134 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
3135 SWIG_Lua_namespace_register(L, &swig_SwigModule, globalRegister);
3136 #endif
3138 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
3139 for (i = 0; swig_types[i]; i++) {
3140 if (swig_types[i]->clientdata) {
3141 SWIG_Lua_elua_class_register_instance(L, (swig_lua_class *)(swig_types[i]->clientdata));
3144 #endif
3146 #if defined(SWIG_LUA_ELUA_EMULATE)
3147 lua_newtable(L);
3148 SWIG_Lua_elua_emulate_register(L, swig_SwigModule.ns_methods);
3149 SWIG_Lua_elua_emulate_register_clear(L);
3150 if (globalRegister) {
3151 lua_pushstring(L, swig_SwigModule.name);
3152 lua_pushvalue(L, -2);
3153 lua_rawset(L, -4);
3155 #endif
3157 #endif
3159 #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
3160 /* invoke user-specific initialization */
3161 SWIG_init_user(L);
3162 /* end module */
3163 /* Note: We do not clean up the stack here (Lua will do this for us). At this
3164 point, we have the globals table and out module table on the stack. Returning
3165 one value makes the module table the result of the require command. */
3166 return 1;
3167 #else
3168 return 0;
3169 #endif
3172 #ifdef __cplusplus
3174 #endif
3177 const char *SWIG_LUACODE =
3180 void SWIG_init_user(lua_State *L) {
3181 /* exec Lua code if applicable */
3182 SWIG_Lua_dostring(L, SWIG_LUACODE);