UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
swig_lua_runtime.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2  * This file was automatically generated by SWIG (http://www.swig.org).
3  * Version 3.0.8
4  *
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  * ----------------------------------------------------------------------------- */
10 
11 /* -----------------------------------------------------------------------------
12  * This section contains generic SWIG labels for method/variable
13  * declarations/attributes, and other compiler dependent labels.
14  * ----------------------------------------------------------------------------- */
15 
16 /* template workaround for compilers that cannot correctly implement the C++ standard */
17 #ifndef SWIGTEMPLATEDISAMBIGUATOR
18 # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
19 # define SWIGTEMPLATEDISAMBIGUATOR template
20 # elif defined(__HP_aCC)
21 /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
22 /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
23 # define SWIGTEMPLATEDISAMBIGUATOR template
24 # else
25 # define SWIGTEMPLATEDISAMBIGUATOR
26 # endif
27 #endif
28 
29 /* inline attribute */
30 #ifndef SWIGINLINE
31 # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
32 # define SWIGINLINE inline
33 # else
34 # define SWIGINLINE
35 # endif
36 #endif
37 
38 /* attribute recognised by some compilers to avoid 'unused' warnings */
39 #ifndef SWIGUNUSED
40 # if defined(__GNUC__)
41 # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
42 # define SWIGUNUSED __attribute__ ((__unused__))
43 # else
44 # define SWIGUNUSED
45 # endif
46 # elif defined(__ICC)
47 # define SWIGUNUSED __attribute__ ((__unused__))
48 # else
49 # define SWIGUNUSED
50 # endif
51 #endif
52 
53 #ifndef SWIG_MSC_UNSUPPRESS_4505
54 # if defined(_MSC_VER)
55 # pragma warning(disable : 4505) /* unreferenced local function has been removed */
56 # endif
57 #endif
58 
59 #ifndef SWIGUNUSEDPARM
60 # ifdef __cplusplus
61 # define SWIGUNUSEDPARM(p)
62 # else
63 # define SWIGUNUSEDPARM(p) p SWIGUNUSED
64 # endif
65 #endif
66 
67 /* internal SWIG method */
68 #ifndef SWIGINTERN
69 # define SWIGINTERN static SWIGUNUSED
70 #endif
71 
72 /* internal inline SWIG method */
73 #ifndef SWIGINTERNINLINE
74 # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
75 #endif
76 
77 /* exporting methods */
78 #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
79 # ifndef GCC_HASCLASSVISIBILITY
80 # define GCC_HASCLASSVISIBILITY
81 # endif
82 #endif
83 
84 #ifndef SWIGEXPORT
85 # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
86 # if defined(STATIC_LINKED)
87 # define SWIGEXPORT
88 # else
89 # define SWIGEXPORT __declspec(dllexport)
90 # endif
91 # else
92 # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
93 # define SWIGEXPORT __attribute__ ((visibility("default")))
94 # else
95 # define SWIGEXPORT
96 # endif
97 # endif
98 #endif
99 
100 /* calling conventions for Windows */
101 #ifndef SWIGSTDCALL
102 # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
103 # define SWIGSTDCALL __stdcall
104 # else
105 # define SWIGSTDCALL
106 # endif
107 #endif
108 
109 /* Deal with Microsoft's attempt at deprecating C standard runtime functions */
110 #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
111 # define _CRT_SECURE_NO_DEPRECATE
112 #endif
113 
114 /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
115 #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
116 # define _SCL_SECURE_NO_DEPRECATE
117 #endif
118 
119 /* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */
120 #if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES)
121 # define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
122 #endif
123 
124 /* Intel's compiler complains if a variable which was never initialised is
125  * cast to void, which is a common idiom which we use to indicate that we
126  * are aware a variable isn't used. So we just silence that warning.
127  * See: https://github.com/swig/swig/issues/192 for more discussion.
128  */
129 #ifdef __INTEL_COMPILER
130 # pragma warning disable 592
131 #endif
132 /* Errors in SWIG */
133 #define SWIG_UnknownError -1
134 #define SWIG_IOError -2
135 #define SWIG_RuntimeError -3
136 #define SWIG_IndexError -4
137 #define SWIG_TypeError -5
138 #define SWIG_DivisionByZero -6
139 #define SWIG_OverflowError -7
140 #define SWIG_SyntaxError -8
141 #define SWIG_ValueError -9
142 #define SWIG_SystemError -10
143 #define SWIG_AttributeError -11
144 #define SWIG_MemoryError -12
145 #define SWIG_NullReferenceError -13
146 
147 
148 /* -----------------------------------------------------------------------------
149  * swigrun.swg
150  *
151  * This file contains generic C API SWIG runtime support for pointer
152  * type checking.
153  * ----------------------------------------------------------------------------- */
154 
155 /* This should only be incremented when either the layout of swig_type_info changes,
156  or for whatever reason, the runtime changes incompatibly */
157 #define SWIG_RUNTIME_VERSION "4"
158 
159 /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */
160 #ifdef SWIG_TYPE_TABLE
161 # define SWIG_QUOTE_STRING(x) #x
162 # define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x)
163 # define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE)
164 #else
165 # define SWIG_TYPE_TABLE_NAME
166 #endif
167 
168 /*
169  You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for
170  creating a static or dynamic library from the SWIG runtime code.
171  In 99.9% of the cases, SWIG just needs to declare them as 'static'.
172 
173  But only do this if strictly necessary, ie, if you have problems
174  with your compiler or suchlike.
175 */
176 
177 #ifndef SWIGRUNTIME
178 # define SWIGRUNTIME SWIGINTERN
179 #endif
180 
181 #ifndef SWIGRUNTIMEINLINE
182 # define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE
183 #endif
184 
185 /* Generic buffer size */
186 #ifndef SWIG_BUFFER_SIZE
187 # define SWIG_BUFFER_SIZE 1024
188 #endif
189 
190 /* Flags for pointer conversions */
191 #define SWIG_POINTER_DISOWN 0x1
192 #define SWIG_CAST_NEW_MEMORY 0x2
193 
194 /* Flags for new pointer objects */
195 #define SWIG_POINTER_OWN 0x1
196 
197 
198 /*
199  Flags/methods for returning states.
200 
201  The SWIG conversion methods, as ConvertPtr, return an integer
202  that tells if the conversion was successful or not. And if not,
203  an error code can be returned (see swigerrors.swg for the codes).
204 
205  Use the following macros/flags to set or process the returning
206  states.
207 
208  In old versions of SWIG, code such as the following was usually written:
209 
210  if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) {
211  // success code
212  } else {
213  //fail code
214  }
215 
216  Now you can be more explicit:
217 
218  int res = SWIG_ConvertPtr(obj,vptr,ty.flags);
219  if (SWIG_IsOK(res)) {
220  // success code
221  } else {
222  // fail code
223  }
224 
225  which is the same really, but now you can also do
226 
227  Type *ptr;
228  int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags);
229  if (SWIG_IsOK(res)) {
230  // success code
231  if (SWIG_IsNewObj(res) {
232  ...
233  delete *ptr;
234  } else {
235  ...
236  }
237  } else {
238  // fail code
239  }
240 
241  I.e., now SWIG_ConvertPtr can return new objects and you can
242  identify the case and take care of the deallocation. Of course that
243  also requires SWIG_ConvertPtr to return new result values, such as
244 
245  int SWIG_ConvertPtr(obj, ptr,...) {
246  if (<obj is ok>) {
247  if (<need new object>) {
248  *ptr = <ptr to new allocated object>;
249  return SWIG_NEWOBJ;
250  } else {
251  *ptr = <ptr to old object>;
252  return SWIG_OLDOBJ;
253  }
254  } else {
255  return SWIG_BADOBJ;
256  }
257  }
258 
259  Of course, returning the plain '0(success)/-1(fail)' still works, but you can be
260  more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the
261  SWIG errors code.
262 
263  Finally, if the SWIG_CASTRANK_MODE is enabled, the result code
264  allows to return the 'cast rank', for example, if you have this
265 
266  int food(double)
267  int fooi(int);
268 
269  and you call
270 
271  food(1) // cast rank '1' (1 -> 1.0)
272  fooi(1) // cast rank '0'
273 
274  just use the SWIG_AddCast()/SWIG_CheckState()
275 */
276 
277 #define SWIG_OK (0)
278 #define SWIG_ERROR (-1)
279 #define SWIG_IsOK(r) (r >= 0)
280 #define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError)
281 
282 /* The CastRankLimit says how many bits are used for the cast rank */
283 #define SWIG_CASTRANKLIMIT (1 << 8)
284 /* The NewMask denotes the object was created (using new/malloc) */
285 #define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1)
286 /* The TmpMask is for in/out typemaps that use temporal objects */
287 #define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1)
288 /* Simple returning values */
289 #define SWIG_BADOBJ (SWIG_ERROR)
290 #define SWIG_OLDOBJ (SWIG_OK)
291 #define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK)
292 #define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK)
293 /* Check, add and del mask methods */
294 #define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r)
295 #define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r)
296 #define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK))
297 #define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r)
298 #define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r)
299 #define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK))
300 
301 /* Cast-Rank Mode */
302 #if defined(SWIG_CASTRANK_MODE)
303 # ifndef SWIG_TypeRank
304 # define SWIG_TypeRank unsigned long
305 # endif
306 # ifndef SWIG_MAXCASTRANK /* Default cast allowed */
307 # define SWIG_MAXCASTRANK (2)
308 # endif
309 # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1)
310 # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK)
311 SWIGINTERNINLINE int SWIG_AddCast(int r) {
312  return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r;
313 }
315  return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0;
316 }
317 #else /* no cast-rank mode */
318 # define SWIG_AddCast(r) (r)
319 # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0)
320 #endif
321 
322 
323 #include <string.h>
324 
325 #ifdef __cplusplus
326 extern "C" {
327 #endif
328 
329 typedef void *(*swig_converter_func)(void *, int *);
330 typedef struct swig_type_info *(*swig_dycast_func)(void **);
331 
332 /* Structure to store information on one type */
333 typedef struct swig_type_info {
334  const char *name; /* mangled name of this type */
335  const char *str; /* human readable name of this type */
336  swig_dycast_func dcast; /* dynamic cast function down a hierarchy */
337  struct swig_cast_info *cast; /* linked list of types that can cast into this type */
338  void *clientdata; /* language specific type data */
339  int owndata; /* flag if the structure owns the clientdata */
341 
342 /* Structure to store a type and conversion function used for casting */
343 typedef struct swig_cast_info {
344  swig_type_info *type; /* pointer to type that is equivalent to this type */
345  swig_converter_func converter; /* function to cast the void pointers */
346  struct swig_cast_info *next; /* pointer to next cast in linked list */
347  struct swig_cast_info *prev; /* pointer to the previous cast */
349 
350 /* Structure used to store module information
351  * Each module generates one structure like this, and the runtime collects
352  * all of these structures and stores them in a circularly linked list.*/
353 typedef struct swig_module_info {
354  swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */
355  size_t size; /* Number of types in this module */
356  struct swig_module_info *next; /* Pointer to next element in circularly linked list */
357  swig_type_info **type_initial; /* Array of initially generated type structures */
358  swig_cast_info **cast_initial; /* Array of initially generated casting structures */
359  void *clientdata; /* Language specific module data */
361 
362 /*
363  Compare two type names skipping the space characters, therefore
364  "char*" == "char *" and "Class<int>" == "Class<int >", etc.
365 
366  Return 0 when the two name types are equivalent, as in
367  strncmp, but skipping ' '.
368 */
369 SWIGRUNTIME int
370 SWIG_TypeNameComp(const char *f1, const char *l1,
371  const char *f2, const char *l2) {
372  for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {
373  while ((*f1 == ' ') && (f1 != l1)) ++f1;
374  while ((*f2 == ' ') && (f2 != l2)) ++f2;
375  if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1;
376  }
377  return (int)((l1 - f1) - (l2 - f2));
378 }
379 
380 /*
381  Check type equivalence in a name list like <name1>|<name2>|...
382  Return 0 if equal, -1 if nb < tb, 1 if nb > tb
383 */
384 SWIGRUNTIME int
385 SWIG_TypeCmp(const char *nb, const char *tb) {
386  int equiv = 1;
387  const char* te = tb + strlen(tb);
388  const char* ne = nb;
389  while (equiv != 0 && *ne) {
390  for (nb = ne; *ne; ++ne) {
391  if (*ne == '|') break;
392  }
393  equiv = SWIG_TypeNameComp(nb, ne, tb, te);
394  if (*ne) ++ne;
395  }
396  return equiv;
397 }
398 
399 /*
400  Check type equivalence in a name list like <name1>|<name2>|...
401  Return 0 if not equal, 1 if equal
402 */
403 SWIGRUNTIME int
404 SWIG_TypeEquiv(const char *nb, const char *tb) {
405  return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0;
406 }
407 
408 /*
409  Check the typename
410 */
412 SWIG_TypeCheck(const char *c, swig_type_info *ty) {
413  if (ty) {
414  swig_cast_info *iter = ty->cast;
415  while (iter) {
416  if (strcmp(iter->type->name, c) == 0) {
417  if (iter == ty->cast)
418  return iter;
419  /* Move iter to the top of the linked list */
420  iter->prev->next = iter->next;
421  if (iter->next)
422  iter->next->prev = iter->prev;
423  iter->next = ty->cast;
424  iter->prev = 0;
425  if (ty->cast) ty->cast->prev = iter;
426  ty->cast = iter;
427  return iter;
428  }
429  iter = iter->next;
430  }
431  }
432  return 0;
433 }
434 
435 /*
436  Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison
437 */
440  if (ty) {
441  swig_cast_info *iter = ty->cast;
442  while (iter) {
443  if (iter->type == from) {
444  if (iter == ty->cast)
445  return iter;
446  /* Move iter to the top of the linked list */
447  iter->prev->next = iter->next;
448  if (iter->next)
449  iter->next->prev = iter->prev;
450  iter->next = ty->cast;
451  iter->prev = 0;
452  if (ty->cast) ty->cast->prev = iter;
453  ty->cast = iter;
454  return iter;
455  }
456  iter = iter->next;
457  }
458  }
459  return 0;
460 }
461 
462 /*
463  Cast a pointer up an inheritance hierarchy
464 */
465 SWIGRUNTIMEINLINE void *
466 SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) {
467  return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory);
468 }
469 
470 /*
471  Dynamic pointer casting. Down an inheritance hierarchy
472 */
475  swig_type_info *lastty = ty;
476  if (!ty || !ty->dcast) return ty;
477  while (ty && (ty->dcast)) {
478  ty = (*ty->dcast)(ptr);
479  if (ty) lastty = ty;
480  }
481  return lastty;
482 }
483 
484 /*
485  Return the name associated with this type
486 */
487 SWIGRUNTIMEINLINE const char *
489  return ty->name;
490 }
491 
492 /*
493  Return the pretty name associated with this type,
494  that is an unmangled type name in a form presentable to the user.
495 */
496 SWIGRUNTIME const char *
498  /* The "str" field contains the equivalent pretty names of the
499  type, separated by vertical-bar characters. We choose
500  to print the last name, as it is often (?) the most
501  specific. */
502  if (!type) return NULL;
503  if (type->str != NULL) {
504  const char *last_name = type->str;
505  const char *s;
506  for (s = type->str; *s; s++)
507  if (*s == '|') last_name = s+1;
508  return last_name;
509  }
510  else
511  return type->name;
512 }
513 
514 /*
515  Set the clientdata field for a type
516 */
517 SWIGRUNTIME void
519  swig_cast_info *cast = ti->cast;
520  /* if (ti->clientdata == clientdata) return; */
521  ti->clientdata = clientdata;
522 
523  while (cast) {
524  if (!cast->converter) {
525  swig_type_info *tc = cast->type;
526  if (!tc->clientdata) {
527  SWIG_TypeClientData(tc, clientdata);
528  }
529  }
530  cast = cast->next;
531  }
532 }
533 SWIGRUNTIME void
535  SWIG_TypeClientData(ti, clientdata);
536  ti->owndata = 1;
537 }
538 
539 /*
540  Search for a swig_type_info structure only by mangled name
541  Search is a O(log #types)
542 
543  We start searching at module start, and finish searching when start == end.
544  Note: if start == end at the beginning of the function, we go all the way around
545  the circular list.
546 */
549  swig_module_info *end,
550  const char *name) {
551  swig_module_info *iter = start;
552  do {
553  if (iter->size) {
554  size_t l = 0;
555  size_t r = iter->size - 1;
556  do {
557  /* since l+r >= 0, we can (>> 1) instead (/ 2) */
558  size_t i = (l + r) >> 1;
559  const char *iname = iter->types[i]->name;
560  if (iname) {
561  int compare = strcmp(name, iname);
562  if (compare == 0) {
563  return iter->types[i];
564  } else if (compare < 0) {
565  if (i) {
566  r = i - 1;
567  } else {
568  break;
569  }
570  } else if (compare > 0) {
571  l = i + 1;
572  }
573  } else {
574  break; /* should never happen */
575  }
576  } while (l <= r);
577  }
578  iter = iter->next;
579  } while (iter != end);
580  return 0;
581 }
582 
583 /*
584  Search for a swig_type_info structure for either a mangled name or a human readable name.
585  It first searches the mangled names of the types, which is a O(log #types)
586  If a type is not found it then searches the human readable names, which is O(#types).
587 
588  We start searching at module start, and finish searching when start == end.
589  Note: if start == end at the beginning of the function, we go all the way around
590  the circular list.
591 */
594  swig_module_info *end,
595  const char *name) {
596  /* STEP 1: Search the name field using binary search */
597  swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name);
598  if (ret) {
599  return ret;
600  } else {
601  /* STEP 2: If the type hasn't been found, do a complete search
602  of the str field (the human readable name) */
603  swig_module_info *iter = start;
604  do {
605  size_t i = 0;
606  for (; i < iter->size; ++i) {
607  if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name)))
608  return iter->types[i];
609  }
610  iter = iter->next;
611  } while (iter != end);
612  }
613 
614  /* neither found a match */
615  return 0;
616 }
617 
618 /*
619  Pack binary data into a string
620 */
621 SWIGRUNTIME char *
622 SWIG_PackData(char *c, void *ptr, size_t sz) {
623  static const char hex[17] = "0123456789abcdef";
624  const unsigned char *u = (unsigned char *) ptr;
625  const unsigned char *eu = u + sz;
626  for (; u != eu; ++u) {
627  unsigned char uu = *u;
628  *(c++) = hex[(uu & 0xf0) >> 4];
629  *(c++) = hex[uu & 0xf];
630  }
631  return c;
632 }
633 
634 /*
635  Unpack binary data from a string
636 */
637 SWIGRUNTIME const char *
638 SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
639  unsigned char *u = (unsigned char *) ptr;
640  const unsigned char *eu = u + sz;
641  for (; u != eu; ++u) {
642  char d = *(c++);
643  unsigned char uu;
644  if ((d >= '0') && (d <= '9'))
645  uu = ((d - '0') << 4);
646  else if ((d >= 'a') && (d <= 'f'))
647  uu = ((d - ('a'-10)) << 4);
648  else
649  return (char *) 0;
650  d = *(c++);
651  if ((d >= '0') && (d <= '9'))
652  uu |= (d - '0');
653  else if ((d >= 'a') && (d <= 'f'))
654  uu |= (d - ('a'-10));
655  else
656  return (char *) 0;
657  *u = uu;
658  }
659  return c;
660 }
661 
662 /*
663  Pack 'void *' into a string buffer.
664 */
665 SWIGRUNTIME char *
666 SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) {
667  char *r = buff;
668  if ((2*sizeof(void *) + 2) > bsz) return 0;
669  *(r++) = '_';
670  r = SWIG_PackData(r,&ptr,sizeof(void *));
671  if (strlen(name) + 1 > (bsz - (r - buff))) return 0;
672  strcpy(r,name);
673  return buff;
674 }
675 
676 SWIGRUNTIME const char *
677 SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) {
678  if (*c != '_') {
679  if (strcmp(c,"NULL") == 0) {
680  *ptr = (void *) 0;
681  return name;
682  } else {
683  return 0;
684  }
685  }
686  return SWIG_UnpackData(++c,ptr,sizeof(void *));
687 }
688 
689 SWIGRUNTIME char *
690 SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) {
691  char *r = buff;
692  size_t lname = (name ? strlen(name) : 0);
693  if ((2*sz + 2 + lname) > bsz) return 0;
694  *(r++) = '_';
695  r = SWIG_PackData(r,ptr,sz);
696  if (lname) {
697  strncpy(r,name,lname+1);
698  } else {
699  *r = 0;
700  }
701  return buff;
702 }
703 
704 SWIGRUNTIME const char *
705 SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {
706  if (*c != '_') {
707  if (strcmp(c,"NULL") == 0) {
708  memset(ptr,0,sz);
709  return name;
710  } else {
711  return 0;
712  }
713  }
714  return SWIG_UnpackData(++c,ptr,sz);
715 }
716 
717 #ifdef __cplusplus
718 }
719 #endif
720 #define SWIG_LUA_TARGET SWIG_LUA_FLAVOR_LUA
721 /* -----------------------------------------------------------------------------
722  * luarun.swg
723  *
724  * This file contains the runtime support for Lua modules
725  * and includes code for managing global variables and pointer
726  * type checking.
727  * ----------------------------------------------------------------------------- */
728 
729 #ifdef __cplusplus
730 extern "C" {
731 #endif
732 
733 #include "lua.h"
734 #include "lauxlib.h"
735 #include <stdlib.h> /* for malloc */
736 #include <assert.h> /* for a few sanity tests */
737 
738 /* -----------------------------------------------------------------------------
739  * Lua flavors
740  * ----------------------------------------------------------------------------- */
741 
742 #define SWIG_LUA_FLAVOR_LUA 1
743 #define SWIG_LUA_FLAVOR_ELUA 2
744 #define SWIG_LUA_FLAVOR_ELUAC 3
745 
746 #if !defined(SWIG_LUA_TARGET)
747 # error SWIG_LUA_TARGET not defined
748 #endif
749 
750 #if defined(SWIG_LUA_ELUA_EMULATE)
751 
752 struct swig_elua_entry;
753 
754 typedef struct swig_elua_key {
755  int type;
756  union {
757  const char* strkey;
758  lua_Number numkey;
759  } key;
760 } swig_elua_key;
761 
762 typedef struct swig_elua_val {
763  int type;
764  union {
765  lua_Number number;
766  const struct swig_elua_entry *table;
767  const char *string;
768  lua_CFunction function;
769  struct {
770  char member;
771  long lvalue;
772  void *pvalue;
773  swig_type_info **ptype;
774  } userdata;
775  } value;
776 } swig_elua_val;
777 
778 typedef struct swig_elua_entry {
779  swig_elua_key key;
780  swig_elua_val value;
781 } swig_elua_entry;
782 
783 #define LSTRKEY(x) {LUA_TSTRING, {.strkey = x} }
784 #define LNUMKEY(x) {LUA_TNUMBER, {.numkey = x} }
785 #define LNILKEY {LUA_TNIL, {.strkey = 0} }
786 
787 #define LNUMVAL(x) {LUA_TNUMBER, {.number = x} }
788 #define LFUNCVAL(x) {LUA_TFUNCTION, {.function = x} }
789 #define LROVAL(x) {LUA_TTABLE, {.table = x} }
790 #define LNILVAL {LUA_TNIL, {.string = 0} }
791 #define LSTRVAL(x) {LUA_TSTRING, {.string = x} }
792 
793 #define LUA_REG_TYPE swig_elua_entry
794 
795 #define SWIG_LUA_ELUA_EMUL_METATABLE_KEY "__metatable"
796 
797 #define lua_pushrotable(L,p)\
798  lua_newtable(L);\
799  assert(p);\
800  SWIG_Lua_elua_emulate_register(L,(swig_elua_entry*)(p));
801 
802 #define SWIG_LUA_CONSTTAB_POINTER(B,C,D)\
803  LSTRKEY(B), {LUA_TUSERDATA, { .userdata={0,0,(void*)(C),&D} } }
804 
805 #define SWIG_LUA_CONSTTAB_BINARY(B,S,C,D)\
806  LSTRKEY(B), {LUA_TUSERDATA, { .userdata={1,S,(void*)(C),&D} } }
807 #endif
808 
809 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
810 # define SWIG_LUA_CONSTTAB_INT(B, C) LSTRKEY(B), LNUMVAL(C)
811 # define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C)
812 # define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C)
813 # define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C)
814  /* Those two types of constants are not supported in elua */
815 
816 #ifndef SWIG_LUA_CONSTTAB_POINTER
817 #warning eLua does not support pointers as constants. By default, nil will be used as value
818 #define SWIG_LUA_CONSTTAB_POINTER(B,C,D) LSTRKEY(B), LNILVAL
819 #endif
820 
821 #ifndef SWIG_LUA_CONSTTAB_BINARY
822 #warning eLua does not support pointers to member as constants. By default, nil will be used as value
823 #define SWIG_LUA_CONSTTAB_BINARY(B, S, C, D) LSTRKEY(B), LNILVAL
824 #endif
825 #else /* SWIG_LUA_FLAVOR_LUA */
826 # define SWIG_LUA_CONSTTAB_INT(B, C) SWIG_LUA_INT, (char *)B, (long)C, 0, 0, 0
827 # define SWIG_LUA_CONSTTAB_FLOAT(B, C) SWIG_LUA_FLOAT, (char *)B, 0, (double)C, 0, 0
828 # define SWIG_LUA_CONSTTAB_STRING(B, C) SWIG_LUA_STRING, (char *)B, 0, 0, (void *)C, 0
829 # define SWIG_LUA_CONSTTAB_CHAR(B, C) SWIG_LUA_CHAR, (char *)B, (long)C, 0, 0, 0
830 # define SWIG_LUA_CONSTTAB_POINTER(B,C,D)\
831  SWIG_LUA_POINTER, (char *)B, 0, 0, (void *)C, &D
832 # define SWIG_LUA_CONSTTAB_BINARY(B, S, C, D)\
833  SWIG_LUA_BINARY, (char *)B, S, 0, (void *)C, &D
834 #endif
835 
836 #ifndef SWIG_LUA_ELUA_EMULATE
837 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
838 # define LRO_STRVAL(v) {{.p = (char *) v}, LUA_TSTRING}
839 # define LSTRVAL LRO_STRVAL
840 #endif
841 #endif /* SWIG_LUA_ELUA_EMULATE*/
842 
843 #ifndef SWIG_LUA_ELUA_EMULATE
844 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
845 
846 #ifndef MIN_OPT_LEVEL
847 #define MIN_OPT_LEVEL 2
848 #endif
849 
850 #include "lrodefs.h"
851 #include "lrotable.h"
852 #endif
853 #endif /* SWIG_LUA_ELUA_EMULATE*/
854 /* -----------------------------------------------------------------------------
855  * compatibility defines
856  * ----------------------------------------------------------------------------- */
857 
858 /* History of Lua C API length functions: In Lua 5.0 (and before?)
859  there was "lua_strlen". In Lua 5.1, this was renamed "lua_objlen",
860  but a compatibility define of "lua_strlen" was added. In Lua 5.2,
861  this function was again renamed, to "lua_rawlen" (to emphasize that
862  it doesn't call the "__len" metamethod), and the compatibility
863  define of lua_strlen was removed. All SWIG uses have been updated
864  to "lua_rawlen", and we add our own defines of that here for older
865  versions of Lua. */
866 #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501
867 # define lua_rawlen lua_strlen
868 #elif LUA_VERSION_NUM == 501
869 # define lua_rawlen lua_objlen
870 #endif
871 
872 
873 /* lua_pushglobaltable is the recommended "future-proof" way to get
874  the global table for Lua 5.2 and later. Here we define
875  lua_pushglobaltable ourselves for Lua versions before 5.2. */
876 #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
877 # define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
878 #endif
879 
880 /* lua_absindex was introduced in Lua 5.2 */
881 #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
882 # define lua_absindex(L,i) ((i)>0 || (i) <= LUA_REGISTRYINDEX ? (i) : lua_gettop(L) + (i) + 1)
883 #endif
884 
885 /* lua_rawsetp was introduced in Lua 5.2 */
886 #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
887 #define lua_rawsetp(L,index,ptr)\
888  lua_pushlightuserdata(L,(void*)(ptr));\
889  lua_insert(L,-2);\
890  lua_rawset(L,index);
891 
892 #define lua_rawgetp(L,index,ptr)\
893  lua_pushlightuserdata(L,(void*)(ptr));\
894  lua_rawget(L,index);
895 
896 #endif
897 
898 /* --------------------------------------------------------------------------
899  * Helper functions for error handling
900  * -------------------------------------------------------------------------- */
901 
902 /* Push the string STR on the Lua stack, like lua_pushstring, but
903  prefixed with the the location of the innermost Lua call-point
904  (as formated by luaL_where). */
905 SWIGRUNTIME void
906 SWIG_Lua_pusherrstring (lua_State *L, const char *str)
907 {
908  luaL_where (L, 1);
909  lua_pushstring (L, str);
910  lua_concat (L, 2);
911 }
912 
913 /* Push a formatted string generated from FMT and following args on
914  the Lua stack, like lua_pushfstring, but prefixed with the the
915  location of the innermost Lua call-point (as formated by luaL_where). */
916 SWIGRUNTIME void
917 SWIG_Lua_pushferrstring (lua_State *L, const char *fmt, ...)
918 {
919  va_list argp;
920  va_start(argp, fmt);
921  luaL_where(L, 1);
922  lua_pushvfstring(L, fmt, argp);
923  va_end(argp);
924  lua_concat(L, 2);
925 }
926 
927 
928 /* -----------------------------------------------------------------------------
929  * global swig types
930  * ----------------------------------------------------------------------------- */
931 /* Constant table */
932 #define SWIG_LUA_INT 1
933 #define SWIG_LUA_FLOAT 2
934 #define SWIG_LUA_STRING 3
935 #define SWIG_LUA_POINTER 4
936 #define SWIG_LUA_BINARY 5
937 #define SWIG_LUA_CHAR 6
938 
939 /* Structure for variable linking table */
940 typedef struct {
941  const char *name;
942  lua_CFunction get;
943  lua_CFunction set;
945 
946 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
947 typedef const LUA_REG_TYPE swig_lua_method;
948 typedef const LUA_REG_TYPE swig_lua_const_info;
949 #else /* Normal lua */
950 typedef luaL_Reg swig_lua_method;
951 
952 /* Constant information structure */
953 typedef struct {
954  int type;
955  char *name;
956  long lvalue;
957  double dvalue;
958  void *pvalue;
959  swig_type_info **ptype;
960 } swig_lua_const_info;
961 
962 #endif
963 
964 typedef struct {
965  const char *name;
966  lua_CFunction getmethod;
967  lua_CFunction setmethod;
969 
970 
971 struct swig_lua_class;
972 /* Can be used to create namespaces. Currently used to wrap class static methods/variables/constants */
973 typedef struct swig_lua_namespace {
974  const char *name;
975  swig_lua_method *ns_methods;
977  swig_lua_const_info *ns_constants;
978  struct swig_lua_class **ns_classes;
981 
982 typedef struct swig_lua_class {
983  const char *name; /* Name that this class has in Lua */
984  const char *fqname; /* Fully qualified name - Scope + class name */
986  lua_CFunction constructor;
987  void (*destructor)(void *);
988  swig_lua_method *methods;
991  swig_lua_method *metatable; /* 0 for -eluac */
992  struct swig_lua_class **bases;
993  const char **base_names;
995 
996 /* this is the struct for wrapping all pointers in SwigLua
997 */
998 typedef struct {
1000  int own; /* 1 if owned & must be destroyed */
1001  void *ptr;
1003 
1004 /* this is the struct for wrapping arbitrary packed binary data
1005 (currently it is only used for member function pointers)
1006 the data ordering is similar to swig_lua_userdata, but it is currently not possible
1007 to tell the two structures apart within SWIG, other than by looking at the type
1008 */
1009 typedef struct {
1011  int own; /* 1 if owned & must be destroyed */
1012  char data[1]; /* arbitary amount of data */
1014 
1015 /* Common SWIG API */
1016 #define SWIG_NewPointerObj(L, ptr, type, owner) SWIG_Lua_NewPointerObj(L, (void *)ptr, type, owner)
1017 #define SWIG_ConvertPtr(L,idx, ptr, type, flags) SWIG_Lua_ConvertPtr(L,idx,ptr,type,flags)
1018 #define SWIG_MustGetPtr(L,idx, type,flags, argnum,fnname) SWIG_Lua_MustGetPtr(L,idx, type,flags, argnum,fnname)
1019 /* for C++ member pointers, ie, member methods */
1020 #define SWIG_ConvertMember(L, idx, ptr, sz, ty) SWIG_Lua_ConvertPacked(L, idx, ptr, sz, ty)
1021 #define SWIG_NewMemberObj(L, ptr, sz, type) SWIG_Lua_NewPackedObj(L, ptr, sz, type)
1022 
1023 /* Runtime API */
1024 #define SWIG_GetModule(clientdata) SWIG_Lua_GetModule((lua_State*)(clientdata))
1025 #define SWIG_SetModule(clientdata, pointer) SWIG_Lua_SetModule((lua_State*) (clientdata), pointer)
1026 #define SWIG_MODULE_CLIENTDATA_TYPE lua_State*
1027 
1028 /* Contract support */
1029 #define SWIG_contract_assert(expr, msg) \
1030  if (!(expr)) { SWIG_Lua_pusherrstring(L, (char *) msg); goto fail; } else
1031 
1032 
1033 /* helper #defines */
1034 #define SWIG_fail {goto fail;}
1035 #define SWIG_fail_arg(func_name,argnum,type) \
1036  {SWIG_Lua_pushferrstring(L,"Error in %s (arg %d), expected '%s' got '%s'",\
1037  func_name,argnum,type,SWIG_Lua_typename(L,argnum));\
1038  goto fail;}
1039 #define SWIG_fail_ptr(func_name,argnum,type) \
1040  SWIG_fail_arg(func_name,argnum,(type && type->str)?type->str:"void*")
1041 #define SWIG_check_num_args(func_name,a,b) \
1042  if (lua_gettop(L)<a || lua_gettop(L)>b) \
1043  {SWIG_Lua_pushferrstring(L,"Error in %s expected %d..%d args, got %d",func_name,a,b,lua_gettop(L));\
1044  goto fail;}
1045 
1046 
1047 #define SWIG_Lua_get_table(L,n) \
1048  (lua_pushstring(L, n), lua_rawget(L,-2))
1049 
1050 #define SWIG_Lua_add_function(L,n,f) \
1051  (lua_pushstring(L, n), \
1052  lua_pushcfunction(L, f), \
1053  lua_rawset(L,-3))
1054 
1055 #define SWIG_Lua_add_boolean(L,n,b) \
1056  (lua_pushstring(L, n), \
1057  lua_pushboolean(L, b), \
1058  lua_rawset(L,-3))
1059 
1060 /* special helper for allowing 'nil' for usertypes */
1061 #define SWIG_isptrtype(L,I) (lua_isuserdata(L,I) || lua_isnil(L,I))
1062 
1063 #ifdef __cplusplus
1064 /* Special helper for member function pointers
1065 it gets the address, casts it, then dereferences it */
1066 /*#define SWIG_mem_fn_as_voidptr(a) (*((char**)&(a))) */
1067 #endif
1068 
1069 /* storing/access of swig_module_info */
1071 SWIG_Lua_GetModule(lua_State *L) {
1072  swig_module_info *ret = 0;
1073  lua_pushstring(L,"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
1074  lua_rawget(L,LUA_REGISTRYINDEX);
1075  if (lua_islightuserdata(L,-1))
1076  ret=(swig_module_info*)lua_touserdata(L,-1);
1077  lua_pop(L,1); /* tidy */
1078  return ret;
1079 }
1080 
1081 SWIGRUNTIME void
1082 SWIG_Lua_SetModule(lua_State *L, swig_module_info *module) {
1083  /* add this all into the Lua registry: */
1084  lua_pushstring(L,"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
1085  lua_pushlightuserdata(L,(void*)module);
1086  lua_rawset(L,LUA_REGISTRYINDEX);
1087 }
1088 
1089 /* -----------------------------------------------------------------------------
1090  * global variable support code: modules
1091  * ----------------------------------------------------------------------------- */
1092 
1093 /* this function is called when trying to set an immutable.
1094 default action is to print an error.
1095 This can removed with a compile flag SWIGLUA_IGNORE_SET_IMMUTABLE */
1097 {
1098 /* there should be 1 param passed in: the new value */
1099 #ifndef SWIGLUA_IGNORE_SET_IMMUTABLE
1100  lua_pop(L,1); /* remove it */
1101  luaL_error(L,"This variable is immutable");
1102 #endif
1103  return 0; /* should not return anything */
1104 }
1105 
1106 #ifdef SWIG_LUA_ELUA_EMULATE
1107 
1108 SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *type, int own);
1109 SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_type_info *type);
1110 static int swig_lua_elua_emulate_unique_key;
1111 
1112 /* This function emulates eLua rotables behaviour. It loads a rotable definition into the usual lua table. */
1113 SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_entry *table)
1114 {
1115  int i, table_parsed, parsed_tables_array, target_table;
1116  assert(lua_istable(L,-1));
1117  target_table = lua_gettop(L);
1118  /* Get the registry where we put all parsed tables to avoid loops */
1119  lua_rawgetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key);
1120  if(lua_isnil(L,-1)) {
1121  lua_pop(L,1);
1122  lua_newtable(L);
1123  lua_pushvalue(L,-1);
1124  lua_rawsetp(L,LUA_REGISTRYINDEX,(void*)(&swig_lua_elua_emulate_unique_key));
1125  }
1126  parsed_tables_array = lua_gettop(L);
1127  lua_pushvalue(L,target_table);
1128  lua_rawsetp(L, parsed_tables_array, table);
1129  table_parsed = 0;
1130  const int SWIGUNUSED pairs_start = lua_gettop(L);
1131  for(i = 0;table[i].key.type != LUA_TNIL || table[i].value.type != LUA_TNIL;i++)
1132  {
1133  const swig_elua_entry *entry = table + i;
1134  int is_metatable = 0;
1135  switch(entry->key.type) {
1136  case LUA_TSTRING:
1137  lua_pushstring(L,entry->key.key.strkey);
1138  if(strcmp(entry->key.key.strkey, SWIG_LUA_ELUA_EMUL_METATABLE_KEY) == 0)
1139  is_metatable = 1;
1140  break;
1141  case LUA_TNUMBER:
1142  lua_pushnumber(L,entry->key.key.numkey);
1143  break;
1144  case LUA_TNIL:
1145  lua_pushnil(L);
1146  break;
1147  default:
1148  assert(0);
1149  }
1150  switch(entry->value.type) {
1151  case LUA_TSTRING:
1152  lua_pushstring(L,entry->value.value.string);
1153  break;
1154  case LUA_TNUMBER:
1155  lua_pushnumber(L,entry->value.value.number);
1156  break;
1157  case LUA_TFUNCTION:
1158  lua_pushcfunction(L,entry->value.value.function);
1159  break;
1160  case LUA_TTABLE:
1161  lua_rawgetp(L,parsed_tables_array, entry->value.value.table);
1162  table_parsed = !lua_isnil(L,-1);
1163  if(!table_parsed) {
1164  lua_pop(L,1); /*remove nil */
1165  lua_newtable(L);
1166  SWIG_Lua_elua_emulate_register(L,entry->value.value.table);
1167  }
1168  if(is_metatable) {
1169  assert(lua_istable(L,-1));
1170  lua_pushvalue(L,-1);
1171  lua_setmetatable(L,target_table);
1172  }
1173 
1174  break;
1175  case LUA_TUSERDATA:
1176  if(entry->value.value.userdata.member)
1177  SWIG_NewMemberObj(L,entry->value.value.userdata.pvalue,
1178  entry->value.value.userdata.lvalue,
1179  *(entry->value.value.userdata.ptype));
1180  else
1181  SWIG_NewPointerObj(L,entry->value.value.userdata.pvalue,
1182  *(entry->value.value.userdata.ptype),0);
1183  break;
1184  case LUA_TNIL:
1185  lua_pushnil(L);
1186  break;
1187  default:
1188  assert(0);
1189  }
1190  assert(lua_gettop(L) == pairs_start + 2);
1191  lua_rawset(L,target_table);
1192  }
1193  lua_pop(L,1); /* Removing parsed tables storage */
1194  assert(lua_gettop(L) == target_table);
1195 }
1196 
1197 SWIGINTERN void SWIG_Lua_elua_emulate_register_clear(lua_State *L)
1198 {
1199  lua_pushnil(L);
1200  lua_rawsetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key);
1201 }
1202 
1203 SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L);
1204 
1205 SWIGINTERN int SWIG_Lua_emulate_elua_getmetatable(lua_State *L)
1206 {
1207  SWIG_check_num_args("getmetatable(SWIG eLua emulation)", 1, 1);
1209  lua_getfield(L,-1,"lua_getmetatable");
1210  lua_remove(L,-2); /* remove the registry*/
1211  assert(!lua_isnil(L,-1));
1212  lua_pushvalue(L,1);
1213  assert(lua_gettop(L) == 3); /* object | function | object again */
1214  lua_call(L,1,1);
1215  if(!lua_isnil(L,-1)) /*There is an ordinary metatable */
1216  return 1;
1217  /*if it is a table, then emulate elua behaviour - check for __metatable attribute of a table*/
1218  assert(lua_gettop(L) == 2);
1219  if(lua_istable(L,-2)) {
1220  lua_pop(L,1); /*remove the nil*/
1221  lua_getfield(L,-1, SWIG_LUA_ELUA_EMUL_METATABLE_KEY);
1222  }
1223  assert(lua_gettop(L) == 2);
1224  return 1;
1225 
1226 fail:
1227  lua_error(L);
1228  return 0;
1229 }
1230 
1231 SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L)
1232 {
1235  lua_pushstring(L,"lua_getmetatable");
1236  lua_getfield(L,-2,"getmetatable");
1237  assert(!lua_isnil(L,-1));
1238  lua_rawset(L,-4);
1239  lua_pushstring(L, "getmetatable");
1240  lua_pushcfunction(L, SWIG_Lua_emulate_elua_getmetatable);
1241  lua_rawset(L,-3);
1242  lua_pop(L,2);
1243 
1244 }
1245 /* END OF REMOVE */
1246 
1247 #endif
1248 /* -----------------------------------------------------------------------------
1249  * global variable support code: namespaces and modules (which are the same thing)
1250  * ----------------------------------------------------------------------------- */
1251 
1253 {
1254 /* there should be 2 params passed in
1255  (1) table (not the meta table)
1256  (2) string name of the attribute
1257 */
1258  assert(lua_istable(L,-2)); /* just in case */
1259  lua_getmetatable(L,-2);
1260  assert(lua_istable(L,-1));
1261  SWIG_Lua_get_table(L,".get"); /* find the .get table */
1262  assert(lua_istable(L,-1));
1263  /* look for the key in the .get table */
1264  lua_pushvalue(L,2); /* key */
1265  lua_rawget(L,-2);
1266  lua_remove(L,-2); /* stack tidy, remove .get table */
1267  if (lua_iscfunction(L,-1))
1268  { /* found it so call the fn & return its value */
1269  lua_call(L,0,1); /* 1 value in (userdata),1 out (result) */
1270  lua_remove(L,-2); /* stack tidy, remove metatable */
1271  return 1;
1272  }
1273  lua_pop(L,1); /* remove whatever was there */
1274  /* ok, so try the .fn table */
1275  SWIG_Lua_get_table(L,".fn"); /* find the .get table */
1276  assert(lua_istable(L,-1)); /* just in case */
1277  lua_pushvalue(L,2); /* key */
1278  lua_rawget(L,-2); /* look for the fn */
1279  lua_remove(L,-2); /* stack tidy, remove .fn table */
1280  if (lua_isfunction(L,-1)) /* note: whether it's a C function or lua function */
1281  { /* found it so return the fn & let lua call it */
1282  lua_remove(L,-2); /* stack tidy, remove metatable */
1283  return 1;
1284  }
1285  lua_pop(L,1); /* remove whatever was there */
1286  return 0;
1287 }
1288 
1290 {
1291 /* there should be 3 params passed in
1292  (1) table (not the meta table)
1293  (2) string name of the attribute
1294  (3) any for the new value
1295 */
1296 
1297  assert(lua_istable(L,1));
1298  lua_getmetatable(L,1); /* get the meta table */
1299  assert(lua_istable(L,-1));
1300 
1301  SWIG_Lua_get_table(L,".set"); /* find the .set table */
1302  if (lua_istable(L,-1))
1303  {
1304  /* look for the key in the .set table */
1305  lua_pushvalue(L,2); /* key */
1306  lua_rawget(L,-2);
1307  if (lua_iscfunction(L,-1))
1308  { /* found it so call the fn & return its value */
1309  lua_pushvalue(L,3); /* value */
1310  lua_call(L,1,0);
1311  return 0;
1312  }
1313  lua_pop(L,1); /* remove the value */
1314  }
1315  lua_pop(L,1); /* remove the value .set table */
1316  lua_pop(L,1); /* remote metatable */
1317  lua_rawset(L,-3);
1318  return 0;
1319 }
1320 
1321 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) /* In elua this is useless */
1322 SWIGINTERN void SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]); /* forward declaration */
1323 SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn); /* forward declaration */
1324 SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss);
1325 
1326 /* helper function - register namespace methods and attributes into namespace */
1328 {
1329  int i;
1330  /* There must be namespace table (not metatable) at the top of the stack */
1331  assert(lua_istable(L,-1));
1333 
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);
1337  }
1338  lua_getmetatable(L,-1);
1339 
1340  /* add fns */
1341  for(i=0;ns->ns_attributes[i].name;i++){
1343  }
1344 
1345  /* clear stack - remove metatble */
1346  lua_pop(L,1);
1347  return 0;
1348 }
1349 
1350 /* Register all classes in the namespace */
1352 {
1353  swig_lua_class **classes;
1354 
1355  /* There must be a module/namespace table at the top of the stack */
1356  assert(lua_istable(L,-1));
1357 
1358  classes = ns->ns_classes;
1359 
1360  if( classes != 0 ) {
1361  while(*classes != 0) {
1362  SWIG_Lua_class_register(L, *classes);
1363  classes++;
1364  }
1365  }
1366 }
1367 
1368 /* Helper function. Creates namespace table and adds it to module table
1369  if 'reg' is true, then will register namespace table to parent one (must be on top of the stack
1370  when function is called).
1371  Function always returns newly registered table on top of the stack.
1372 */
1374 {
1375  swig_lua_namespace **sub_namespace;
1376  /* 1 argument - table on the top of the stack */
1377  const int SWIGUNUSED begin = lua_gettop(L);
1378  assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table or parent namespace table */
1379  lua_checkstack(L,5);
1380  lua_newtable(L); /* namespace itself */
1381  lua_newtable(L); /* metatable for namespace */
1382 
1383  /* add a table called ".get" */
1384  lua_pushstring(L,".get");
1385  lua_newtable(L);
1386  lua_rawset(L,-3);
1387  /* add a table called ".set" */
1388  lua_pushstring(L,".set");
1389  lua_newtable(L);
1390  lua_rawset(L,-3);
1391  /* add a table called ".fn" */
1392  lua_pushstring(L,".fn");
1393  lua_newtable(L);
1394  lua_rawset(L,-3);
1395 
1396  /* add accessor fns for using the .get,.set&.fn */
1399 
1400  lua_setmetatable(L,-2); /* set metatable */
1401 
1402  /* Register all functions, variables etc */
1404  /* Register classes */
1406 
1407  sub_namespace = ns->ns_namespaces;
1408  if( sub_namespace != 0) {
1409  while(*sub_namespace != 0) {
1410  SWIG_Lua_namespace_register(L, *sub_namespace, 1);
1411  lua_pop(L,1); /* removing sub-namespace table */
1412  sub_namespace++;
1413  }
1414  }
1415 
1416  if (reg) {
1417  lua_pushstring(L,ns->name);
1418  lua_pushvalue(L,-2);
1419  lua_rawset(L,-4); /* add namespace to module table */
1420  }
1421  assert(lua_gettop(L) == begin+1);
1422 }
1423 #endif /* SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA */
1424 
1425 /* -----------------------------------------------------------------------------
1426  * global variable support code: classes
1427  * ----------------------------------------------------------------------------- */
1428 
1429 SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname);
1430 
1431 typedef int (*swig_lua_base_iterator_func)(lua_State*,swig_type_info*, int, int *ret);
1432 
1433 SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info * SWIGUNUSED swig_type,
1434  int first_arg, swig_lua_base_iterator_func func, int *const ret)
1435 {
1436  /* first_arg - position of the object in stack. Everything that is above are arguments
1437  * and is passed to every evocation of the func */
1438  int last_arg = lua_gettop(L);/* position of last argument */
1439  int original_metatable = last_arg + 1;
1440  size_t bases_count;
1441  int result = SWIG_ERROR;
1442  int bases_table;
1443  (void)swig_type;
1444  lua_getmetatable(L,first_arg);
1445 
1446  /* initialise base search */
1447 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
1448  SWIG_Lua_get_table(L,".bases");
1449  assert(lua_istable(L,-1));
1450  bases_count = lua_rawlen(L,-1);
1451  bases_table = lua_gettop(L);
1452 #else
1453  /* In elua .bases table doesn't exist. Use table from swig_lua_class */
1454  (void)bases_table;
1455  assert(swig_type!=0);
1456  swig_module_info *module=SWIG_GetModule(L);
1457  swig_lua_class **bases= ((swig_lua_class*)(swig_type->clientdata))->bases;
1458  const char **base_names= ((swig_lua_class*)(swig_type->clientdata))->base_names;
1459  bases_count = 0;
1460  for(;base_names[bases_count];
1461  bases_count++);/* get length of bases */
1462 #endif
1463 
1464  if(ret)
1465  *ret = 0;
1466  if(bases_count>0)
1467  {
1468  int to_remove;
1469  size_t i;
1470  int j;
1471  int subcall_last_arg;
1472  int subcall_first_arg = lua_gettop(L) + 1;/* Here a copy of first_arg and arguments begin */
1473  int valid = 1;
1474  swig_type_info *base_swig_type = 0;
1475  for(j=first_arg;j<=last_arg;j++)
1476  lua_pushvalue(L,j);
1477  subcall_last_arg = lua_gettop(L);
1478 
1479  /* Trick: temporarily replacing original metatable with metatable for base class and call getter */
1480  for(i=0;i<bases_count;i++) {
1481  /* Iteration through class bases */
1482 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
1483  lua_rawgeti(L,bases_table,i+1);
1484  base_swig_type = 0;
1485  if(lua_isnil(L,-1)) {
1486  valid = 0;
1487  lua_pop(L,1);
1488  } else {
1489  valid = 1;
1490  }
1491 #else /* In elua .bases table doesn't exist. Use table from swig_lua_class */
1492  swig_lua_class *base_class = bases[i];
1493  if(!base_class) {
1494  valid = 0;
1495  } else {
1496  valid = 1;
1497  SWIG_Lua_get_class_metatable(L,base_class->fqname);
1498  base_swig_type = SWIG_TypeQueryModule(module,module,base_names[i]);
1499  assert(base_swig_type != 0);
1500  }
1501 #endif
1502 
1503  if(!valid)
1504  continue;
1505  assert(lua_isuserdata(L, subcall_first_arg));
1506  assert(lua_istable(L,-1));
1507  lua_setmetatable(L,subcall_first_arg); /* Set new metatable */
1508  assert(lua_gettop(L) == subcall_last_arg);
1509  result = func(L, base_swig_type,subcall_first_arg, ret); /* Forward call */
1510  if(result != SWIG_ERROR) {
1511  break;
1512  }
1513  }
1514  /* Restore original metatable */
1515  lua_pushvalue(L,original_metatable);
1516  lua_setmetatable(L,first_arg);
1517  /* Clear - remove everything between last_arg and subcall_last_arg including */
1518  to_remove = subcall_last_arg - last_arg;
1519  for(j=0;j<to_remove;j++)
1520  lua_remove(L,last_arg+1);
1521  } else {
1522  /* Remove everything after last_arg */
1523  lua_pop(L, lua_gettop(L) - last_arg);
1524  }
1525  if(ret) assert(lua_gettop(L) == last_arg + *ret);
1526  return result;
1527 }
1528 
1529 /* The class.get method helper, performs the lookup of class attributes.
1530  * It returns an error code. Number of function return values is passed inside 'ret'.
1531  * first_arg is not used in this function because function always has 2 arguments.
1532  */
1533 SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int SWIGUNUSED first_arg, int *ret)
1534 {
1535 /* there should be 2 params passed in
1536  (1) userdata (not the meta table)
1537  (2) string name of the attribute
1538 */
1539  int bases_search_result;
1540  int substack_start = lua_gettop(L)-2;
1541  assert(first_arg == substack_start+1);
1542  lua_checkstack(L,5);
1543  assert(lua_isuserdata(L,-2)); /* just in case */
1544  lua_getmetatable(L,-2); /* get the meta table */
1545  assert(lua_istable(L,-1)); /* just in case */
1546  SWIG_Lua_get_table(L,".get"); /* find the .get table */
1547  assert(lua_istable(L,-1)); /* just in case */
1548  /* look for the key in the .get table */
1549  lua_pushvalue(L,substack_start+2); /* key */
1550  lua_rawget(L,-2);
1551  lua_remove(L,-2); /* stack tidy, remove .get table */
1552  if (lua_iscfunction(L,-1))
1553  { /* found it so call the fn & return its value */
1554  lua_pushvalue(L,substack_start+1); /* the userdata */
1555  lua_call(L,1,1); /* 1 value in (userdata),1 out (result) */
1556  lua_remove(L,-2); /* stack tidy, remove metatable */
1557  if(ret)
1558  *ret = 1;
1559  return SWIG_OK;
1560  }
1561  lua_pop(L,1); /* remove whatever was there */
1562  /* ok, so try the .fn table */
1563  SWIG_Lua_get_table(L,".fn"); /* find the .fn table */
1564  assert(lua_istable(L,-1)); /* just in case */
1565  lua_pushvalue(L,substack_start+2); /* key */
1566  lua_rawget(L,-2); /* look for the fn */
1567  lua_remove(L,-2); /* stack tidy, remove .fn table */
1568  if (lua_isfunction(L,-1)) /* note: if its a C function or lua function */
1569  { /* found it so return the fn & let lua call it */
1570  lua_remove(L,-2); /* stack tidy, remove metatable */
1571  if(ret)
1572  *ret = 1;
1573  return SWIG_OK;
1574  }
1575  lua_pop(L,1); /* remove whatever was there */
1576  /* NEW: looks for the __getitem() fn
1577  this is a user provided get fn */
1578  SWIG_Lua_get_table(L,"__getitem"); /* find the __getitem fn */
1579  if (lua_iscfunction(L,-1)) /* if its there */
1580  { /* found it so call the fn & return its value */
1581  lua_pushvalue(L,substack_start+1); /* the userdata */
1582  lua_pushvalue(L,substack_start+2); /* the parameter */
1583  lua_call(L,2,1); /* 2 value in (userdata),1 out (result) */
1584  lua_remove(L,-2); /* stack tidy, remove metatable */
1585  if(ret) *ret = 1;
1586  return SWIG_OK;
1587  }
1588  lua_pop(L,1);
1589  /* Remove the metatable */
1590  lua_pop(L,1);
1591  /* Search in base classes */
1592  bases_search_result = SWIG_Lua_iterate_bases(L,type,substack_start+1,SWIG_Lua_class_do_get,ret);
1593  return bases_search_result; /* sorry not known */
1594 }
1595 
1596 /* the class.get method, performs the lookup of class attributes
1597  */
1599 {
1600 /* there should be 2 params passed in
1601  (1) userdata (not the meta table)
1602  (2) string name of the attribute
1603 */
1604  int result;
1605  swig_lua_userdata *usr;
1606  swig_type_info *type;
1607  int ret = 0;
1608  assert(lua_isuserdata(L,1));
1609  usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
1610  type = usr->type;
1611  result = SWIG_Lua_class_do_get(L,type,1,&ret);
1612  if(result == SWIG_OK)
1613  return ret;
1614 
1615  return 0;
1616 }
1617 
1618 /* helper for the class.set method, performs the lookup of class attributes
1619  * It returns error code. Number of function return values is passed inside 'ret'
1620  */
1621 SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int first_arg, int *ret)
1622 {
1623 /* there should be 3 params passed in
1624  (1) table (not the meta table)
1625  (2) string name of the attribute
1626  (3) any for the new value
1627  */
1628 
1629  int bases_search_result;
1630  int substack_start = lua_gettop(L) - 3;
1631  lua_checkstack(L,5);
1632  assert(lua_isuserdata(L,substack_start+1)); /* just in case */
1633  lua_getmetatable(L,substack_start+1); /* get the meta table */
1634  assert(lua_istable(L,-1)); /* just in case */
1635  if(ret)
1636  *ret = 0; /* it is setter - number of return values is always 0 */
1637 
1638  SWIG_Lua_get_table(L,".set"); /* find the .set table */
1639  if (lua_istable(L,-1))
1640  {
1641  /* look for the key in the .set table */
1642  lua_pushvalue(L,substack_start+2); /* key */
1643  lua_rawget(L,-2);
1644  lua_remove(L,-2); /* tidy stack, remove .set table */
1645  if (lua_iscfunction(L,-1))
1646  { /* found it so call the fn & return its value */
1647  lua_pushvalue(L,substack_start+1); /* userdata */
1648  lua_pushvalue(L,substack_start+3); /* value */
1649  lua_call(L,2,0);
1650  lua_remove(L,substack_start+4); /*remove metatable*/
1651  return SWIG_OK;
1652  }
1653  lua_pop(L,1); /* remove the value */
1654  } else {
1655  lua_pop(L,1); /* remove the answer for .set table request*/
1656  }
1657  /* NEW: looks for the __setitem() fn
1658  this is a user provided set fn */
1659  SWIG_Lua_get_table(L,"__setitem"); /* find the fn */
1660  if (lua_iscfunction(L,-1)) /* if its there */
1661  { /* found it so call the fn & return its value */
1662  lua_pushvalue(L,substack_start+1); /* the userdata */
1663  lua_pushvalue(L,substack_start+2); /* the parameter */
1664  lua_pushvalue(L,substack_start+3); /* the value */
1665  lua_call(L,3,0); /* 3 values in ,0 out */
1666  lua_remove(L,-2); /* stack tidy, remove metatable */
1667  return SWIG_OK;
1668  }
1669  lua_pop(L,1); /* remove value */
1670 
1671  lua_pop(L,1); /* remove metatable */
1672  /* Search among bases */
1673  bases_search_result = SWIG_Lua_iterate_bases(L,type,first_arg,SWIG_Lua_class_do_set,ret);
1674  if(ret)
1675  assert(*ret == 0);
1676  assert(lua_gettop(L) == substack_start + 3);
1677  return bases_search_result;
1678 }
1679 
1680 /* This is the actual method exported to Lua. It calls SWIG_Lua_class_do_set and correctly
1681  * handles return values.
1682  */
1684 {
1685 /* There should be 3 params passed in
1686  (1) table (not the meta table)
1687  (2) string name of the attribute
1688  (3) any for the new value
1689  */
1690  int ret = 0;
1691  int result;
1692  swig_lua_userdata *usr;
1693  swig_type_info *type;
1694  assert(lua_isuserdata(L,1));
1695  usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
1696  type = usr->type;
1697  result = SWIG_Lua_class_do_set(L,type,1,&ret);
1698  if(result != SWIG_OK) {
1699  SWIG_Lua_pushferrstring(L,"Assignment not possible. No setter/member with this name. For custom assignments implement __setitem method.");
1700  lua_error(L);
1701  } else {
1702  assert(ret==0);
1703  }
1704  return 0;
1705 }
1706 
1707 /* the class.destruct method called by the interpreter */
1709 {
1710 /* there should be 1 params passed in
1711  (1) userdata (not the meta table) */
1712  swig_lua_userdata *usr;
1713  swig_lua_class *clss;
1714  assert(lua_isuserdata(L,-1)); /* just in case */
1715  usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */
1716  /* if must be destroyed & has a destructor */
1717  if (usr->own) /* if must be destroyed */
1718  {
1719  clss=(swig_lua_class*)usr->type->clientdata; /* get the class */
1720  if (clss && clss->destructor) /* there is a destroy fn */
1721  {
1722  clss->destructor(usr->ptr); /* bye bye */
1723  }
1724  }
1725  return 0;
1726 }
1727 
1728 /* the class.__tostring method called by the interpreter and print */
1730 {
1731 /* there should be 1 param passed in
1732  (1) userdata (not the metatable) */
1733  const char *className;
1734  void* userData;
1735  assert(lua_isuserdata(L,1)); /* just in case */
1736  userData = lua_touserdata(L,1); /* get the userdata address for later */
1737  lua_getmetatable(L,1); /* get the meta table */
1738  assert(lua_istable(L,-1)); /* just in case */
1739 
1740  lua_getfield(L, -1, ".type");
1741  className = lua_tostring(L, -1);
1742 
1743  lua_pushfstring(L, "<%s userdata: %p>", className, userData);
1744  return 1;
1745 }
1746 
1747 /* to manually disown some userdata */
1749 {
1750 /* there should be 1 params passed in
1751  (1) userdata (not the meta table) */
1752  swig_lua_userdata *usr;
1753  assert(lua_isuserdata(L,-1)); /* just in case */
1754  usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */
1755 
1756  usr->own = 0; /* clear our ownership */
1757  return 0;
1758 }
1759 
1760 /* lua callable function to compare userdata's value
1761 the issue is that two userdata may point to the same thing
1762 but to lua, they are different objects */
1764 {
1765  int result;
1766  swig_lua_userdata *usr1,*usr2;
1767  if (!lua_isuserdata(L,1) || !lua_isuserdata(L,2)) /* just in case */
1768  return 0; /* nil reply */
1769  usr1=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */
1770  usr2=(swig_lua_userdata*)lua_touserdata(L,2); /* get data */
1771  /*result=(usr1->ptr==usr2->ptr && usr1->type==usr2->type); only works if type is the same*/
1772  result=(usr1->ptr==usr2->ptr);
1773  lua_pushboolean(L,result);
1774  return 1;
1775 }
1776 
1777 /* populate table at the top of the stack with metamethods that ought to be inherited */
1779 {
1780  SWIG_Lua_add_boolean(L, "__add", 1);
1781  SWIG_Lua_add_boolean(L, "__sub", 1);
1782  SWIG_Lua_add_boolean(L, "__mul", 1);
1783  SWIG_Lua_add_boolean(L, "__div", 1);
1784  SWIG_Lua_add_boolean(L, "__mod", 1);
1785  SWIG_Lua_add_boolean(L, "__pow", 1);
1786  SWIG_Lua_add_boolean(L, "__unm", 1);
1787  SWIG_Lua_add_boolean(L, "__len", 1 );
1788  SWIG_Lua_add_boolean(L, "__concat", 1 );
1789  SWIG_Lua_add_boolean(L, "__eq", 1);
1790  SWIG_Lua_add_boolean(L, "__lt", 1);
1791  SWIG_Lua_add_boolean(L, "__le", 1);
1792  SWIG_Lua_add_boolean(L, "__call", 1);
1793  SWIG_Lua_add_boolean(L, "__tostring", 1);
1794  SWIG_Lua_add_boolean(L, "__gc", 0);
1795 }
1796 
1797 /* creates the swig registry */
1799 {
1800  /* create main SWIG registry table */
1801  lua_pushstring(L,"SWIG");
1802  lua_newtable(L);
1803  /* populate it with some predefined data */
1804 
1805  /* .library table. Placeholder */
1806  lua_pushstring(L,".library");
1807  lua_newtable(L);
1808  {
1809  /* list of metamethods that class inherits from its bases */
1810  lua_pushstring(L,"inheritable_metamethods");
1811  lua_newtable(L);
1812  /* populate with list of metamethods */
1814  lua_rawset(L,-3);
1815  }
1816  lua_rawset(L,-3);
1817 
1818  lua_rawset(L,LUA_REGISTRYINDEX);
1819 }
1820 
1821 /* gets the swig registry (or creates it) */
1823 {
1824  /* add this all into the swig registry: */
1825  lua_pushstring(L,"SWIG");
1826  lua_rawget(L,LUA_REGISTRYINDEX); /* get the registry */
1827  if (!lua_istable(L,-1)) /* not there */
1828  { /* must be first time, so add it */
1829  lua_pop(L,1); /* remove the result */
1831  /* then get it */
1832  lua_pushstring(L,"SWIG");
1833  lua_rawget(L,LUA_REGISTRYINDEX);
1834  }
1835 }
1836 
1838 {
1840  lua_pushstring(L, ".library");
1841  lua_rawget(L,-2);
1842  assert( !lua_isnil(L,-1) );
1843  lua_pushstring(L, "inheritable_metamethods");
1844  lua_rawget(L,-2);
1845 
1846  /* Remove class registry and library table */
1847  lua_remove(L,-2);
1848  lua_remove(L,-2);
1849 }
1850 
1851 /* Helper function to get the classes metatable from the register */
1852 SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname)
1853 {
1854  SWIG_Lua_get_class_registry(L); /* get the registry */
1855  lua_pushstring(L,cname); /* get the name */
1856  lua_rawget(L,-2); /* get it */
1857  lua_remove(L,-2); /* tidy up (remove registry) */
1858 }
1859 
1860 /* Set up the base classes pointers.
1861 Each class structure has a list of pointers to the base class structures.
1862 This function fills them.
1863 It cannot be done at compile time, as this will not work with hireachies
1864 spread over more than one swig file.
1865 Therefore it must be done at runtime, querying the SWIG type system.
1866 */
1868 {
1869  int i=0;
1870  swig_module_info *module=SWIG_GetModule(L);
1871  for(i=0;clss->base_names[i];i++)
1872  {
1873  if (clss->bases[i]==0) /* not found yet */
1874  {
1875  /* lookup and cache the base class */
1876  swig_type_info *info = SWIG_TypeQueryModule(module,module,clss->base_names[i]);
1877  if (info) clss->bases[i] = (swig_lua_class *) info->clientdata;
1878  }
1879  }
1880 }
1881 
1882 #if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
1883 /* Merges two tables */
1884 SWIGINTERN void SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int source)
1885 {
1886  /* iterating */
1887  lua_pushnil(L);
1888  while (lua_next(L,source) != 0) {
1889  /* -1 - value, -2 - index */
1890  /* have to copy to assign */
1891  lua_pushvalue(L,-2); /* copy of index */
1892  lua_pushvalue(L,-2); /* copy of value */
1893  lua_rawset(L, target);
1894  lua_pop(L,1);
1895  /* only key is left */
1896  }
1897 }
1898 
1899 /* Merges two tables with given name. original - index of target metatable, base - index of source metatable */
1900 SWIGINTERN void SWIG_Lua_merge_tables(lua_State *L, const char* name, int original, int base)
1901 {
1902  /* push original[name], then base[name] */
1903  lua_pushstring(L,name);
1904  lua_rawget(L,original);
1905  int original_table = lua_gettop(L);
1906  lua_pushstring(L,name);
1907  lua_rawget(L,base);
1908  int base_table = lua_gettop(L);
1909  SWIG_Lua_merge_tables_by_index(L, original_table, base_table);
1910  /* clearing stack */
1911  lua_pop(L,2);
1912 }
1913 
1914 /* Function takes all symbols from base and adds it to derived class. It's just a helper. */
1915 SWIGINTERN void SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls)
1916 {
1917  /* There is one parameter - original, i.e. 'derived' class metatable */
1918  assert(lua_istable(L,-1));
1919  int original = lua_gettop(L);
1920  SWIG_Lua_get_class_metatable(L,base_cls->fqname);
1921  int base = lua_gettop(L);
1922  SWIG_Lua_merge_tables(L, ".fn", original, base );
1923  SWIG_Lua_merge_tables(L, ".set", original, base );
1924  SWIG_Lua_merge_tables(L, ".get", original, base );
1925  lua_pop(L,1);
1926 }
1927 
1928 /* Function squashes all symbols from 'clss' bases into itself */
1929 SWIGINTERN void SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss)
1930 {
1931  int i;
1933  for(i=0;clss->base_names[i];i++)
1934  {
1935  if (clss->bases[i]==0) /* Somehow it's not found. Skip it */
1936  continue;
1937  /* Thing is: all bases are already registered. Thus they have already executed
1938  * this function. So we just need to squash them into us, because their bases
1939  * are already squashed into them. No need for recursion here!
1940  */
1941  SWIG_Lua_class_squash_base(L, clss->bases[i]);
1942  }
1943  lua_pop(L,1); /*tidy stack*/
1944 }
1945 #endif
1946 
1947 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) /* In elua this is useless */
1948 /* helper add a variable to a registered class */
1949 SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn)
1950 {
1951  assert(lua_istable(L,-1)); /* just in case */
1952  SWIG_Lua_get_table(L,".get"); /* find the .get table */
1953  assert(lua_istable(L,-1)); /* just in case */
1954  SWIG_Lua_add_function(L,name,getFn);
1955  lua_pop(L,1); /* tidy stack (remove table) */
1956  if (setFn)
1957  {
1958  SWIG_Lua_get_table(L,".set"); /* find the .set table */
1959  assert(lua_istable(L,-1)); /* just in case */
1960  SWIG_Lua_add_function(L,name,setFn);
1961  lua_pop(L,1); /* tidy stack (remove table) */
1962  }
1963 }
1964 
1965 /* helper to recursively add class static details (static attributes, operations and constants) */
1967 {
1968  int i = 0;
1969  /* The class namespace table must be on the top of the stack */
1970  assert(lua_istable(L,-1));
1971  /* call all the base classes first: we can then override these later: */
1972  for(i=0;clss->bases[i];i++)
1973  {
1975  }
1976 
1978 }
1979 
1980 SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss); /* forward declaration */
1981 
1982 /* helper to recursively add class details (attributes & operations) */
1984 {
1985  int i;
1986  size_t bases_count = 0;
1987  /* Add bases to .bases table */
1988  SWIG_Lua_get_table(L,".bases");
1989  assert(lua_istable(L,-1)); /* just in case */
1990  for(i=0;clss->bases[i];i++)
1991  {
1993  /* Base class must be already registered */
1994  assert(lua_istable(L,-1));
1995  lua_rawseti(L,-2,i+1); /* In lua indexing starts from 1 */
1996  bases_count++;
1997  }
1998  assert(lua_rawlen(L,-1) == bases_count);
1999  lua_pop(L,1); /* remove .bases table */
2000  /* add attributes */
2001  for(i=0;clss->attributes[i].name;i++){
2003  }
2004  /* add methods to the metatable */
2005  SWIG_Lua_get_table(L,".fn"); /* find the .fn table */
2006  assert(lua_istable(L,-1)); /* just in case */
2007  for(i=0;clss->methods[i].name;i++){
2008  SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].func);
2009  }
2010  lua_pop(L,1); /* tidy stack (remove table) */
2011  /* add operator overloads
2012  This adds methods from metatable array to metatable. Can mess up garbage
2013  collectind if someone defines __gc method
2014  */
2015  if(clss->metatable) {
2016  for(i=0;clss->metatable[i].name;i++) {
2017  SWIG_Lua_add_function(L,clss->metatable[i].name,clss->metatable[i].func);
2018  }
2019  }
2020 
2021 #if !defined(SWIG_LUA_SQUASH_BASES)
2022  /* Adding metamethods that are defined in base classes. If bases were squashed
2023  * then it is obviously unnecessary
2024  */
2026 #endif
2027 }
2028 
2029 /* Helpers to add user defined class metamedhods - __add, __sub etc. The helpers are needed
2030  for the following issue: Lua runtime checks for metamethod existence with rawget function
2031  ignoring our SWIG-provided __index and __newindex functions. Thus our inheritance-aware method
2032  search algorithm doesn't work in such case. (Not to say that Lua runtime queries metamethod directly
2033  in metatable and not in object).
2034  Current solution is this: if somewhere in hierarchy metamethod __x is defined, then all descendants
2035  are automatically given a special proxy __x that calls the real __x method.
2036  Obvious idea - to copy __x instead of creating __x-proxy is wrong because if someone changes __x in runtime,
2037  those changes must be reflected in all descendants.
2038 */
2039 
2040 SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L); /*forward declaration*/
2041 
2042 /* The real function that resolves a metamethod.
2043  * Function searches given class and all it's bases(recursively) for first instance of something that is
2044  * not equal to SWIG_Lua_resolve_metatmethod. (Almost always this 'something' is actual metamethod implementation
2045  * and it is a SWIG-generated C function.). It returns value on the top of the L and there is no garbage below the
2046  * answer.
2047  * Returns 1 if found, 0 otherwise.
2048  * clss is class which metatable we will search for method
2049  * metamethod_name_idx is index in L where metamethod name (as string) lies
2050  * skip_check allows to skip searching metamethod in givel clss and immideatelly go to searching in bases. skip_check
2051  * is not caried to subsequent recursive calls - false is always passed. It is set to true only at first call from
2052  * SWIG_Lua_resolve_metamethod
2053  * */
2054 SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class *clss, int metamethod_name_idx,
2055  int skip_check)
2056 {
2057  /* This function is called recursively */
2058  int result = 0;
2059  int i = 0;
2060 
2061  if (!skip_check) {
2063  lua_pushvalue(L, metamethod_name_idx);
2064  lua_rawget(L,-2);
2065  /* If this is cfunction and it is equal to SWIG_Lua_resolve_metamethod then
2066  * this isn't the function we are looking for :)
2067  * lua_tocfunction will return NULL if not cfunction
2068  */
2069  if (!lua_isnil(L,-1) && lua_tocfunction(L,-1) != SWIG_Lua_resolve_metamethod ) {
2070  lua_remove(L,-2); /* removing class metatable */
2071  return 1;
2072  }
2073  lua_pop(L,2); /* remove class metatable and query result */
2074  }
2075 
2076  /* Forwarding calls to bases */
2077  for(i=0;clss->bases[i];i++)
2078  {
2079  result = SWIG_Lua_do_resolve_metamethod(L, clss->bases[i], metamethod_name_idx, 0);
2080  if (result)
2081  break;
2082  }
2083 
2084  return result;
2085 }
2086 
2087 /* The proxy function for metamethod. All parameters are passed as cclosure. Searches for actual method
2088  * and calls it */
2090 {
2091  int numargs;
2092  int metamethod_name_idx;
2093  const swig_lua_class* clss;
2094  int result;
2095 
2096  lua_checkstack(L,5);
2097  numargs = lua_gettop(L); /* number of arguments to pass to actual metamethod */
2098 
2099  /* Get upvalues from closure */
2100  lua_pushvalue(L, lua_upvalueindex(1)); /*Get function name*/
2101  metamethod_name_idx = lua_gettop(L);
2102 
2103  lua_pushvalue(L, lua_upvalueindex(2));
2104  clss = (const swig_lua_class*)(lua_touserdata(L,-1));
2105  lua_pop(L,1); /* remove lightuserdata with clss from stack */
2106 
2107  /* Actual work */
2108  result = SWIG_Lua_do_resolve_metamethod(L, clss, metamethod_name_idx, 1);
2109  if (!result) {
2110  SWIG_Lua_pushferrstring(L,"The metamethod proxy is set, but it failed to find actual metamethod. Memory corruption is most likely explanation.");
2111  lua_error(L);
2112  return 0;
2113  }
2114 
2115  lua_remove(L,-2); /* remove metamethod key */
2116  lua_insert(L,1); /* move function to correct position */
2117  lua_call(L, numargs, LUA_MULTRET);
2118  return lua_gettop(L); /* return all results */
2119 }
2120 
2121 
2122 /* If given metamethod must be present in given class, then creates appropriate proxy
2123  * Returns 1 if successfully added, 0 if not added because no base class has it, -1
2124  * if method is defined in the class metatable itself
2125  */
2126 SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *clss, const int metatable_index)
2127 {
2128  int key_index;
2129  int success = 0;
2130  int i = 0;
2131 
2132  /* metamethod name - on the top of the stack */
2133  assert(lua_isstring(L,-1));
2134 
2135  key_index = lua_gettop(L);
2136 
2137  /* Check whether method is already defined in metatable */
2138  lua_pushvalue(L,key_index); /* copy of the key */
2139  lua_gettable(L,metatable_index);
2140  if( !lua_isnil(L,-1) ) {
2141  lua_pop(L,1);
2142  return -1;
2143  }
2144  lua_pop(L,1);
2145 
2146  /* Iterating over immediate bases */
2147  for(i=0;clss->bases[i];i++)
2148  {
2149  const swig_lua_class *base = clss->bases[i];
2151  lua_pushvalue(L, key_index);
2152  lua_rawget(L, -2);
2153  if( !lua_isnil(L,-1) ) {
2154  lua_pushvalue(L, key_index);
2155 
2156  /* Add proxy function */
2157  lua_pushvalue(L, key_index); /* first closure value is function name */
2158  lua_pushlightuserdata(L, clss); /* second closure value is swig_lua_class structure */
2159  lua_pushcclosure(L, SWIG_Lua_resolve_metamethod, 2);
2160 
2161  lua_rawset(L, metatable_index);
2162  success = 1;
2163  }
2164  lua_pop(L,1); /* remove function or nil */
2165  lua_pop(L,1); /* remove base class metatable */
2166 
2167  if( success )
2168  break;
2169  }
2170 
2171  return success;
2172 }
2173 
2175 {
2176  int metatable_index;
2177  int metamethods_info_index;
2178  int tostring_undefined;
2179  int eq_undefined = 0;
2180 
2182  metatable_index = lua_gettop(L);
2184  assert(lua_istable(L,-1));
2185  metamethods_info_index = lua_gettop(L);
2186  lua_pushnil(L); /* first key */
2187  while(lua_next(L, metamethods_info_index) != 0 ) {
2188  /* key at index -2, value at index -1 */
2189  const int is_inheritable = lua_toboolean(L,-2);
2190  lua_pop(L,1); /* remove value - we don't need it anymore */
2191 
2192  if(is_inheritable) { /* if metamethod is inheritable */
2193  SWIG_Lua_add_class_user_metamethod(L,clss,metatable_index);
2194  }
2195  }
2196 
2197  lua_pop(L,1); /* remove inheritable metatmethods table */
2198 
2199  /* Special handling for __tostring method */
2200  lua_pushstring(L, "__tostring");
2201  lua_pushvalue(L,-1);
2202  lua_rawget(L,metatable_index);
2203  tostring_undefined = lua_isnil(L,-1);
2204  lua_pop(L,1);
2205  if( tostring_undefined ) {
2206  lua_pushcfunction(L, SWIG_Lua_class_tostring);
2207  lua_rawset(L, metatable_index);
2208  } else {
2209  lua_pop(L,1); /* remove copy of the key */
2210  }
2211 
2212  /* Special handling for __eq method */
2213  lua_pushstring(L, "__eq");
2214  lua_pushvalue(L,-1);
2215  lua_rawget(L,metatable_index);
2216  eq_undefined = lua_isnil(L,-1);
2217  lua_pop(L,1);
2218  if( eq_undefined ) {
2219  lua_pushcfunction(L, SWIG_Lua_class_equal);
2220  lua_rawset(L, metatable_index);
2221  } else {
2222  lua_pop(L,1); /* remove copy of the key */
2223  }
2224  /* Warning: __index and __newindex are SWIG-defined. For user-defined operator[]
2225  * a __getitem/__setitem method should be defined
2226  */
2227  lua_pop(L,1); /* pop class metatable */
2228 }
2229 
2230 /* Register class static methods,attributes etc as well as constructor proxy */
2232 {
2233  const int SWIGUNUSED begin = lua_gettop(L);
2234  lua_checkstack(L,5); /* just in case */
2235  assert(lua_istable(L,-1)); /* just in case */
2236  assert(strcmp(clss->name, clss->cls_static->name) == 0); /* in class those 2 must be equal */
2237 
2239 
2240  assert(lua_istable(L,-1)); /* just in case */
2241 
2242  /* add its constructor to module with the name of the class
2243  so you can do MyClass(...) as well as new_MyClass(...)
2244  BUT only if a constructor is defined
2245  (this overcomes the problem of pure virtual classes without constructors)*/
2246  if (clss->constructor)
2247  {
2248  lua_getmetatable(L,-1);
2249  assert(lua_istable(L,-1)); /* just in case */
2250  SWIG_Lua_add_function(L,"__call", clss->constructor);
2251  lua_pop(L,1);
2252  }
2253 
2254  assert(lua_istable(L,-1)); /* just in case */
2256 
2257  /* clear stack */
2258  lua_pop(L,1);
2259  assert( lua_gettop(L) == begin );
2260 }
2261 
2262 /* Performs the instance (non-static) class registration process. Metatable for class is created
2263  * and added to the class registry.
2264  */
2266 {
2267  const int SWIGUNUSED begin = lua_gettop(L);
2268  int i;
2269  /* if name already there (class is already registered) then do nothing */
2270  SWIG_Lua_get_class_registry(L); /* get the registry */
2271  lua_pushstring(L,clss->fqname); /* get the name */
2272  lua_rawget(L,-2);
2273  if(!lua_isnil(L,-1)) {
2274  lua_pop(L,2);
2275  assert(lua_gettop(L)==begin);
2276  return;
2277  }
2278  lua_pop(L,2); /* tidy stack */
2279  /* Recursively initialize all bases */
2280  for(i=0;clss->bases[i];i++)
2281  {
2283  }
2284  /* Again, get registry and push name */
2285  SWIG_Lua_get_class_registry(L); /* get the registry */
2286  lua_pushstring(L,clss->fqname); /* get the name */
2287  lua_newtable(L); /* create the metatable */
2288 #if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
2289  /* If squashing is requested, then merges all bases metatable into this one.
2290  * It would get us all special methods: __getitem, __add etc.
2291  * This would set .fn, .type, and other .xxx incorrectly, but we will overwrite it right away
2292  */
2293  {
2294  int new_metatable_index = lua_absindex(L,-1);
2295  for(i=0;clss->bases[i];i++)
2296  {
2297  int base_metatable;
2299  base_metatable = lua_absindex(L,-1);
2300  SWIG_Lua_merge_tables_by_index(L,new_metatable_index, base_metatable);
2301  lua_pop(L,1);
2302  }
2303  }
2304  /* And now we will overwrite all incorrectly set data */
2305 #endif
2306  /* add string of class name called ".type" */
2307  lua_pushstring(L,".type");
2308  lua_pushstring(L,clss->fqname);
2309  lua_rawset(L,-3);
2310  /* add a table called bases */
2311  lua_pushstring(L,".bases");
2312  lua_newtable(L);
2313  lua_rawset(L,-3);
2314  /* add a table called ".get" */
2315  lua_pushstring(L,".get");
2316  lua_newtable(L);
2317  lua_rawset(L,-3);
2318  /* add a table called ".set" */
2319  lua_pushstring(L,".set");
2320  lua_newtable(L);
2321  lua_rawset(L,-3);
2322  /* add a table called ".fn" */
2323  lua_pushstring(L,".fn");
2324  lua_newtable(L);
2325  /* add manual disown method */
2327  lua_rawset(L,-3);
2328  /* add accessor fns for using the .get,.set&.fn */
2330  SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_class_set);
2332  /* add it */
2333  lua_rawset(L,-3); /* metatable into registry */
2334  lua_pop(L,1); /* tidy stack (remove registry) */
2335  assert(lua_gettop(L) == begin);
2336 
2337 #if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
2338  /* Now merge all symbols from .fn, .set, .get etc from bases to our tables */
2339  SWIG_Lua_class_squash_bases(L,clss);
2340 #endif
2342  SWIG_Lua_add_class_instance_details(L,clss); /* recursive adding of details (atts & ops) */
2343  lua_pop(L,1); /* tidy stack (remove class metatable) */
2344  assert( lua_gettop(L) == begin );
2345 }
2346 
2348 {
2349  int SWIGUNUSED begin;
2350  assert(lua_istable(L,-1)); /* This is a table (module or namespace) where classes will be added */
2353 
2354  /* Add links from static part to instance part and vice versa */
2355  /* [SWIG registry] [Module]
2356  * "MyClass" ----> [MyClass metatable] <===== "MyClass" -+> [static part]
2357  * ".get" ----> ... | | getmetatable()----|
2358  * ".set" ----> ... | | |
2359  * ".static" --------------)----------------/ [static part metatable]
2360  * | ".get" --> ...
2361  * | ".set" --> ....
2362  * |=============================== ".instance"
2363  */
2364  begin = lua_gettop(L);
2365  lua_pushstring(L,clss->cls_static->name);
2366  lua_rawget(L,-2); /* get class static table */
2367  assert(lua_istable(L,-1));
2368  lua_getmetatable(L,-1);
2369  assert(lua_istable(L,-1)); /* get class static metatable */
2370  lua_pushstring(L,".instance"); /* prepare key */
2371 
2372  SWIG_Lua_get_class_metatable(L,clss->fqname); /* get class metatable */
2373  assert(lua_istable(L,-1));
2374  lua_pushstring(L,".static"); /* prepare key */
2375  lua_pushvalue(L, -4); /* push static class TABLE */
2376  assert(lua_istable(L,-1));
2377  lua_rawset(L,-3); /* assign static class table(!NOT metatable) as ".static" member of class metatable */
2378  lua_rawset(L,-3); /* assign class metatable as ".instance" member of class static METATABLE */
2379  lua_pop(L,2);
2380  assert(lua_gettop(L) == begin);
2381 }
2382 #endif /* SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA */
2383 
2384 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
2385 SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_class *clss)
2386 {
2387  const int SWIGUNUSED begin = lua_gettop(L);
2388  int i;
2389  /* if name already there (class is already registered) then do nothing */
2390  SWIG_Lua_get_class_registry(L); /* get the registry */
2391  lua_pushstring(L,clss->fqname); /* get the name */
2392  lua_rawget(L,-2);
2393  if(!lua_isnil(L,-1)) {
2394  lua_pop(L,2);
2395  assert(lua_gettop(L)==begin);
2396  return;
2397  }
2398  lua_pop(L,2); /* tidy stack */
2399  /* Recursively initialize all bases */
2400  for(i=0;clss->bases[i];i++)
2401  {
2402  SWIG_Lua_elua_class_register_instance(L,clss->bases[i]);
2403  }
2404  /* Again, get registry and push name */
2405  SWIG_Lua_get_class_registry(L); /* get the registry */
2406  lua_pushstring(L,clss->fqname); /* get the name */
2407  assert(clss->metatable);
2408  lua_pushrotable(L, (void*)(clss->metatable)); /* create the metatable */
2409  lua_rawset(L,-3);
2410  lua_pop(L,1);
2411  assert(lua_gettop(L) == begin);
2412 }
2413 #endif /* elua && eluac */
2414 
2415 /* -----------------------------------------------------------------------------
2416  * Class/structure conversion fns
2417  * ----------------------------------------------------------------------------- */
2418 
2419 /* helper to add metatable to new lua object */
2420 SWIGINTERN void SWIG_Lua_AddMetatable(lua_State *L,swig_type_info *type)
2421 {
2422  if (type->clientdata) /* there is clientdata: so add the metatable */
2423  {
2425  if (lua_istable(L,-1))
2426  {
2427  lua_setmetatable(L,-2);
2428  }
2429  else
2430  {
2431  lua_pop(L,1);
2432  }
2433  }
2434 }
2435 
2436 /* pushes a new object into the lua stack */
2437 SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *type, int own)
2438 {
2439  swig_lua_userdata *usr;
2440  if (!ptr){
2441  lua_pushnil(L);
2442  return;
2443  }
2444  usr=(swig_lua_userdata*)lua_newuserdata(L,sizeof(swig_lua_userdata)); /* get data */
2445  usr->ptr=ptr; /* set the ptr */
2446  usr->type=type;
2447  usr->own=own;
2448 #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
2449  SWIG_Lua_AddMetatable(L,type); /* add metatable */
2450 #endif
2451 }
2452 
2453 /* takes a object from the lua stack & converts it into an object of the correct type
2454  (if possible) */
2455 SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L,int index,void **ptr,swig_type_info *type,int flags)
2456 {
2457  swig_lua_userdata *usr;
2458  swig_cast_info *cast;
2459  if (lua_isnil(L,index)){*ptr=0; return SWIG_OK;} /* special case: lua nil => NULL pointer */
2460  usr=(swig_lua_userdata*)lua_touserdata(L,index); /* get data */
2461  if (usr)
2462  {
2463  if (flags & SWIG_POINTER_DISOWN) /* must disown the object */
2464  {
2465  usr->own=0;
2466  }
2467  if (!type) /* special cast void*, no casting fn */
2468  {
2469  *ptr=usr->ptr;
2470  return SWIG_OK; /* ok */
2471  }
2472  cast=SWIG_TypeCheckStruct(usr->type,type); /* performs normal type checking */
2473  if (cast)
2474  {
2475  int newmemory = 0;
2476  *ptr=SWIG_TypeCast(cast,usr->ptr,&newmemory);
2477  assert(!newmemory); /* newmemory handling not yet implemented */
2478  return SWIG_OK; /* ok */
2479  }
2480  }
2481  return SWIG_ERROR; /* error */
2482 }
2483 
2484 SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_State *L,int index,swig_type_info *type,int flags,
2485  int argnum,const char *func_name){
2486  void *result;
2487  if (!SWIG_IsOK(SWIG_ConvertPtr(L,index,&result,type,flags))){
2488  luaL_error (L,"Error in %s, expected a %s at argument number %d\n",
2489  func_name,(type && type->str)?type->str:"void*",argnum);
2490  }
2491  return result;
2492 }
2493 
2494 /* pushes a packed userdata. user for member fn pointers only */
2495 SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_type_info *type)
2496 {
2497  swig_lua_rawdata *raw;
2498  assert(ptr); /* not acceptable to pass in a NULL value */
2499  raw=(swig_lua_rawdata*)lua_newuserdata(L,sizeof(swig_lua_rawdata)-1+size); /* alloc data */
2500  raw->type=type;
2501  raw->own=0;
2502  memcpy(raw->data,ptr,size); /* copy the data */
2503  SWIG_Lua_AddMetatable(L,type); /* add metatable */
2504 }
2505 
2506 /* converts a packed userdata. user for member fn pointers only */
2507 SWIGRUNTIME int SWIG_Lua_ConvertPacked(lua_State *L,int index,void *ptr,size_t size,swig_type_info *type)
2508 {
2509  swig_lua_rawdata *raw;
2510  raw=(swig_lua_rawdata*)lua_touserdata(L,index); /* get data */
2511  if (!raw) return SWIG_ERROR; /* error */
2512  if (type==0 || type==raw->type) /* void* or identical type */
2513  {
2514  memcpy(ptr,raw->data,size); /* copy it */
2515  return SWIG_OK; /* ok */
2516  }
2517  return SWIG_ERROR; /* error */
2518 }
2519 
2520 /* a function to get the typestring of a piece of data */
2521 SWIGRUNTIME const char *SWIG_Lua_typename(lua_State *L, int tp)
2522 {
2523  swig_lua_userdata *usr;
2524  if (lua_isuserdata(L,tp))
2525  {
2526  usr=(swig_lua_userdata*)lua_touserdata(L,tp); /* get data */
2527  if (usr && usr->type && usr->type->str)
2528  return usr->type->str;
2529  return "userdata (unknown type)";
2530  }
2531  return lua_typename(L,lua_type(L,tp));
2532 }
2533 
2534 /* lua callable function to get the userdata's type */
2535 SWIGRUNTIME int SWIG_Lua_type(lua_State *L)
2536 {
2537  lua_pushstring(L,SWIG_Lua_typename(L,1));
2538  return 1;
2539 }
2540 
2541 /* -----------------------------------------------------------------------------
2542  * global variable support code: class/struct typemap functions
2543  * ----------------------------------------------------------------------------- */
2544 
2545 #if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
2546 /* Install Constants */
2547 SWIGINTERN void
2548 SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]) {
2549  int i;
2550  for (i = 0; constants[i].type; i++) {
2551  switch(constants[i].type) {
2552  case SWIG_LUA_INT:
2553  lua_pushstring(L,constants[i].name);
2554  lua_pushinteger(L,(lua_Number)constants[i].lvalue);
2555  lua_rawset(L,-3);
2556  break;
2557  case SWIG_LUA_FLOAT:
2558  lua_pushstring(L,constants[i].name);
2559  lua_pushnumber(L,(lua_Number)constants[i].dvalue);
2560  lua_rawset(L,-3);
2561  break;
2562  case SWIG_LUA_CHAR:
2563  lua_pushstring(L,constants[i].name);
2564  {
2565  char c = constants[i].lvalue;
2566  lua_pushlstring(L,&c,1);
2567  }
2568  lua_rawset(L,-3);
2569  break;
2570  case SWIG_LUA_STRING:
2571  lua_pushstring(L,constants[i].name);
2572  lua_pushstring(L,(char *) constants[i].pvalue);
2573  lua_rawset(L,-3);
2574  break;
2575  case SWIG_LUA_POINTER:
2576  lua_pushstring(L,constants[i].name);
2577  SWIG_NewPointerObj(L,constants[i].pvalue, *(constants[i]).ptype,0);
2578  lua_rawset(L,-3);
2579  break;
2580  case SWIG_LUA_BINARY:
2581  lua_pushstring(L,constants[i].name);
2582  SWIG_NewMemberObj(L,constants[i].pvalue,constants[i].lvalue,*(constants[i]).ptype);
2583  lua_rawset(L,-3);
2584  break;
2585  default:
2586  break;
2587  }
2588  }
2589 }
2590 #endif
2591 
2592 /* -----------------------------------------------------------------------------
2593  * executing lua code from within the wrapper
2594  * ----------------------------------------------------------------------------- */
2595 
2596 #ifndef SWIG_DOSTRING_FAIL /* Allows redefining of error function */
2597 #define SWIG_DOSTRING_FAIL(S) fprintf(stderr,"%s\n",S)
2598 #endif
2599 /* Executes a C string in Lua which is a really simple way of calling lua from C
2600 Unfortunately lua keeps changing its APIs, so we need a conditional compile
2601 In lua 5.0.X it's lua_dostring()
2602 In lua 5.1.X it's luaL_dostring()
2603 */
2604 SWIGINTERN int
2605 SWIG_Lua_dostring(lua_State *L, const char *str) {
2606  int ok,top;
2607  if (str==0 || str[0]==0) return 0; /* nothing to do */
2608  top=lua_gettop(L); /* save stack */
2609 #if (defined(LUA_VERSION_NUM) && (LUA_VERSION_NUM>=501))
2610  ok=luaL_dostring(L,str); /* looks like this is lua 5.1.X or later, good */
2611 #else
2612  ok=lua_dostring(L,str); /* might be lua 5.0.x, using lua_dostring */
2613 #endif
2614  if (ok!=0) {
2615  SWIG_DOSTRING_FAIL(lua_tostring(L,-1));
2616  }
2617  lua_settop(L,top); /* restore the stack */
2618  return ok;
2619 }
2620 
2621 #ifdef __cplusplus
2622 }
2623 #endif
2624 
2625 /* ------------------------------ end luarun.swg ------------------------------ */
2626 /* -----------------------------------------------------------------------------*
2627  Standard SWIG API for use inside user code.
2628 
2629  Don't include this file directly, run the command
2630  swig -python -external-runtime
2631  Also, read the Modules chapter of the SWIG Manual.
2632 
2633  * -----------------------------------------------------------------------------*/
2634 
2635 #ifdef SWIG_MODULE_CLIENTDATA_TYPE
2636 
2637 SWIGRUNTIMEINLINE swig_type_info *
2639  swig_module_info *module = SWIG_GetModule(clientdata);
2640  return SWIG_TypeQueryModule(module, module, name);
2641 }
2642 
2643 SWIGRUNTIMEINLINE swig_type_info *
2645  swig_module_info *module = SWIG_GetModule(clientdata);
2646  return SWIG_MangledTypeQueryModule(module, module, name);
2647 }
2648 
2649 #else
2650 
2651 SWIGRUNTIMEINLINE swig_type_info *
2652 SWIG_TypeQuery(const char *name) {
2653  swig_module_info *module = SWIG_GetModule(NULL);
2654  return SWIG_TypeQueryModule(module, module, name);
2655 }
2656 
2657 SWIGRUNTIMEINLINE swig_type_info *
2658 SWIG_MangledTypeQuery(const char *name) {
2659  swig_module_info *module = SWIG_GetModule(NULL);
2660  return SWIG_MangledTypeQueryModule(module, module, name);
2661 }
2662 
2663 #endif
SWIGINTERN void SWIG_Lua_get_inheritable_metamethods(lua_State *L)
#define SWIGINTERNINLINE
SWIGRUNTIME swig_cast_info * SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty)
SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L, void *ptr, size_t size, swig_type_info *type)
SWIGRUNTIME swig_module_info * SWIG_Lua_GetModule(lua_State *L)
#define SWIG_POINTER_DISOWN
#define SWIG_LUA_FLOAT
int(* swig_lua_base_iterator_func)(lua_State *, swig_type_info *, int, int *ret)
SWIGRUNTIME int SWIG_TypeCmp(const char *nb, const char *tb)
QGL_EXTERN GLint GLenum type
Definition: r_gl.h:94
SWIGRUNTIME swig_cast_info * SWIG_TypeCheck(const char *c, swig_type_info *ty)
SWIGINTERN void SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[])
SWIGRUNTIME char * SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz)
SWIGINTERN int SWIG_Lua_dostring(lua_State *L, const char *str)
SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State *L, swig_lua_class *clss)
SWIGRUNTIMEINLINE const char * SWIG_TypeName(const swig_type_info *ty)
SWIGINTERN int SWIG_Lua_set_immutable(lua_State *L)
SWIGRUNTIME int SWIG_TypeNameComp(const char *f1, const char *l1, const char *f2, const char *l2)
SWIGRUNTIME void SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata)
SWIGRUNTIMEINLINE swig_type_info * SWIG_TypeQuery(SWIG_MODULE_CLIENTDATA_TYPE clientdata, const char *name)
SWIGRUNTIME int SWIG_Lua_class_equal(lua_State *L)
#define SWIGINTERN
SWIGINTERN int SWIG_Lua_class_tostring(lua_State *L)
swig_dycast_func dcast
#define SWIG_AddCast(r)
SWIGRUNTIME void SWIG_TypeClientData(swig_type_info *ti, void *clientdata)
struct swig_cast_info * cast
struct swig_cast_info swig_cast_info
swig_type_info * type
SWIGINTERN int SWIG_Lua_class_get(lua_State *L)
#define SWIG_DOSTRING_FAIL(S)
SWIGINTERN void SWIG_Lua_AddMetatable(lua_State *L, swig_type_info *type)
swig_lua_method * methods
#define SWIG_GetModule(clientdata)
swig_lua_method * ns_methods
swig_type_info * type
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
#define lua_absindex(L, i)
struct swig_type_info swig_type_info
swig_lua_namespace * cls_static
SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L, void *ptr, swig_type_info *type, int own)
#define SWIG_RUNTIME_VERSION
SWIGINTERN int SWIG_Lua_class_disown(lua_State *L)
struct swig_lua_class ** ns_classes
#define SWIG_Lua_add_function(L, n, f)
SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L, swig_lua_class *clss)
swig_lua_attribute * ns_attributes
lua_CFunction setmethod
SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L, swig_lua_class *clss)
SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int SWIGUNUSED first_arg, int *ret)
SWIGRUNTIME const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz)
SWIGRUNTIME char * SWIG_PackData(char *c, void *ptr, size_t sz)
#define SWIG_LUA_STRING
const char * name
lua_CFunction getmethod
#define SWIG_check_num_args(func_name, a, b)
SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *clss)
#define SWIG_LUA_CHAR
#define lua_pushglobaltable(L)
unsigned int key
Definition: cl_input.cpp:68
SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L, const char *cname)
const char * fqname
SWIGINTERN int SWIG_Lua_namespace_set(lua_State *L)
SWIGINTERN int SWIG_Lua_class_destruct(lua_State *L)
GLsizei size
Definition: r_gl.h:152
struct swig_lua_class swig_lua_class
SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State *L, swig_lua_namespace *ns)
#define SWIG_MODULE_CLIENTDATA_TYPE
#define SWIG_NewPointerObj(L, ptr, type, owner)
SWIGRUNTIME int SWIG_Lua_ConvertPacked(lua_State *L, int index, void *ptr, size_t size, swig_type_info *type)
struct swig_module_info * next
SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L)
swig_converter_func converter
#define SWIG_ConvertPtr(L, idx, ptr, type, flags)
SWIGRUNTIME void SWIG_Lua_pushferrstring(lua_State *L, const char *fmt,...)
swig_lua_const_info * ns_constants
#define SWIG_LUA_BINARY
swig_type_info ** types
SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L, int index, void **ptr, swig_type_info *type, int flags)
SWIGRUNTIMEINLINE swig_type_info * SWIG_MangledTypeQuery(SWIG_MODULE_CLIENTDATA_TYPE clientdata, const char *name)
SWIGRUNTIME const char * SWIG_TypePrettyName(const swig_type_info *type)
swig_type_info ** type
lua_CFunction constructor
#define SWIG_LUA_POINTER
#define SWIG_TYPE_TABLE_NAME
SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int first_arg, int *ret)
SWIGRUNTIME swig_type_info * SWIG_MangledTypeQueryModule(swig_module_info *start, swig_module_info *end, const char *name)
struct swig_type_info *(* swig_dycast_func)(void **)
#define SWIG_CheckState(r)
SWIGINTERN void SWIG_Lua_create_class_registry(lua_State *L)
const GLuint *typedef void(APIENTRY *GenRenderbuffersEXT_t)(GLsizei
Definition: r_gl.h:189
QGL_EXTERN GLuint index
Definition: r_gl.h:110
SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace *ns)
const char * str
#define SWIG_IsOK(r)
#define SWIG_OK
SWIGRUNTIME void SWIG_Lua_SetModule(lua_State *L, swig_module_info *module)
#define lua_rawsetp(L, index, ptr)
void *(* swig_converter_func)(void *, int *)
SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *SWIGUNUSED swig_type, int first_arg, swig_lua_base_iterator_func func, int *const ret)
#define lua_rawlen
#define SWIG_LUA_INT
SWIGINTERN void SWIG_Lua_init_base_class(lua_State *L, swig_lua_class *clss)
SWIGRUNTIME void SWIG_Lua_pusherrstring(lua_State *L, const char *str)
QGL_EXTERN GLint i
Definition: r_gl.h:113
swig_lua_method * metatable
SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *clss, const int metatable_index)
SWIGRUNTIME swig_type_info * SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr)
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
#define SWIGRUNTIMEINLINE
SWIGRUNTIME const char * SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name)
SWIGRUNTIME char * SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz)
struct swig_lua_namespace swig_lua_namespace
SWIGINTERN void SWIG_Lua_class_register(lua_State *L, swig_lua_class *clss)
SWIGINTERN int SWIG_Lua_class_set(lua_State *L)
SWIGRUNTIME void * SWIG_Lua_MustGetPtr(lua_State *L, int index, swig_type_info *type, int flags, int argnum, const char *func_name)
struct swig_cast_info * next
#define lua_rawgetp(L, index, ptr)
struct swig_module_info swig_module_info
SWIGINTERN void SWIG_Lua_populate_inheritable_metamethods(lua_State *L)
#define SWIG_NewMemberObj(L, ptr, sz, type)
const char ** base_names
SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L)
#define SWIGUNUSED
swig_type_info * type
SWIGRUNTIME const char * SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name)
struct swig_lua_namespace ** ns_namespaces
struct swig_cast_info * prev
struct swig_lua_class ** bases
GLsizei const GLvoid * data
Definition: r_gl.h:152
swig_cast_info ** cast_initial
SWIGINTERN void SWIG_Lua_add_variable(lua_State *L, const char *name, lua_CFunction getFn, lua_CFunction setFn)
#define SWIG_Lua_get_table(L, n)
void(* destructor)(void *)
#define SWIG_ERROR
swig_type_info ** type_initial
SWIGINTERN int SWIG_Lua_namespace_get(lua_State *L)
const char * name
SWIGRUNTIME int SWIG_TypeEquiv(const char *nb, const char *tb)
SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss)
SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class *clss, int metamethod_name_idx, int skip_check)
luaL_Reg swig_lua_method
SWIGRUNTIMEINLINE void * SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory)
SWIGRUNTIME int SWIG_Lua_type(lua_State *L)
swig_lua_attribute * attributes
SWIGRUNTIME const char * SWIG_Lua_typename(lua_State *L, int tp)
SWIGINTERN void SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, int reg)
#define SWIG_Lua_add_boolean(L, n, b)
SWIGRUNTIME swig_type_info * SWIG_TypeQueryModule(swig_module_info *start, swig_module_info *end, const char *name)
#define SWIGRUNTIME