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