Advertisement
Naohiro19

Lua/C++ code generated by SWIG

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