/tags/rel-1.3.33/Lib/lua/lua.swg

# · Unknown · 206 lines · 167 code · 39 blank · 0 comment · 0 complexity · 519e0bfae774c823be6a1355891dc156 MD5 · raw file

  1. /* -----------------------------------------------------------------------------
  2. * See the LICENSE file for information on copyright, usage and redistribution
  3. * of SWIG, and the README file for authors - http://www.swig.org/release.html.
  4. *
  5. * lua.swg
  6. *
  7. * SWIG Configuration File for Lua.
  8. * This file is parsed by SWIG before reading any other interface file.
  9. * ----------------------------------------------------------------------------- */
  10. /* -----------------------------------------------------------------------------
  11. * includes
  12. * ----------------------------------------------------------------------------- */
  13. %include <luatypemaps.swg> /* The typemaps */
  14. %include <luaruntime.swg> /* The runtime stuff */
  15. /* -----------------------------------------------------------------------------
  16. * constants typemaps
  17. * ----------------------------------------------------------------------------- */
  18. // this basically adds to a table of constants
  19. %typemap(consttab) int, unsigned int, short, unsigned short, long, unsigned long, unsigned char, signed char, bool, enum SWIGTYPE
  20. { SWIG_LUA_INT, (char *)"$symname", (long) $value, 0, 0, 0}
  21. %typemap(consttab) float, double
  22. { SWIG_LUA_FLOAT, (char *)"$symname", 0, (double) $value, 0, 0}
  23. %typemap(consttab) long long, unsigned long long, signed long long
  24. { SWIG_LUA_FLOAT, (char *)"$symname", 0, (double) $value, 0, 0}
  25. %typemap(consttab) const long long&, const unsigned long long&, const signed long long&
  26. { SWIG_LUA_FLOAT, (char *)"$symname", 0, (double) *$value, 0, 0}
  27. %typemap(consttab) char *, const char *, char [], const char []
  28. { SWIG_LUA_STRING, (char *)"$symname", 0, 0, (void *)$value, 0}
  29. // note: char is treated as a seperate special type
  30. // signed char & unsigned char are numbers
  31. %typemap(consttab) char
  32. { SWIG_LUA_CHAR, (char *)"$symname", (long)$value, 0, 0, 0}
  33. %typemap(consttab) long long, unsigned long long
  34. { SWIG_LUA_STRING, (char *) "$symname", 0, 0, (void *)"$value", 0}
  35. %typemap(consttab) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
  36. { SWIG_LUA_POINTER, (char *)"$symname", 0, 0, (void *)$value, &$1_descriptor}
  37. // member function pointers
  38. %typemap(consttab) SWIGTYPE (CLASS::*)
  39. { SWIG_LUA_BINARY, (char *)"$symname", sizeof($type), 0, (void *)&$value, &$1_descriptor}
  40. /* -----------------------------------------------------------------------------
  41. * Overloaded operator support
  42. * ----------------------------------------------------------------------------- */
  43. // lua calls the + operator '__add'
  44. // python likes to call it '__add__'
  45. // Assuming most SWIGers will probably use the __add__ if they extend their classes
  46. // we have two sets of renames
  47. // one to rename the operator+() to __add()
  48. // (this lets SWIG rename the operator overloads)
  49. // another is to rename __add__() to __add()
  50. // (this means that people who wrote SWIG code to do that add will also work)
  51. #ifdef __cplusplus
  52. // this is extra renaming for lua
  53. // not all operators are supported, so only those that are, are listed
  54. %rename(__add) *::operator+;
  55. %rename(__sub) *::operator-;
  56. %rename(__mul) *::operator*;
  57. %rename(__div) *::operator/;
  58. %rename(__unm) *::operator-();
  59. %rename(__unm) *::operator-() const;
  60. %rename(__eq) *::operator==;
  61. %ignore *::operator!=; // note: Lua does not have a notequal operator
  62. // it just uses 'not (a==b)'
  63. %rename(__lt) *::operator<;
  64. %ignore *::operator>; // ditto less than vs greater than
  65. %rename(__le) *::operator<=;
  66. %ignore *::operator>=; // ditto less than vs greater than
  67. %ignore *::operator!; // does not support not
  68. %rename(__call) *::operator(); // the fn call operator
  69. // lua does not support overloading of:
  70. // logical/bitwise operators
  71. // assign operator
  72. // +=,-=,*=, etc
  73. // therefore ignoring them for now
  74. // it also doesn't support non class operators
  75. // eg friends or XX operator+(XX,XX)
  76. // also ignoring
  77. // note: some of these might be better to rename, but not doing that for now
  78. %ignore *::operator&&; %ignore operator&&;
  79. %ignore *::operator||; %ignore operator||;
  80. %ignore *::operator+=;
  81. %ignore *::operator-=;
  82. %ignore *::operator*=;
  83. %ignore *::operator/=;
  84. %ignore *::operator%=;
  85. %ignore *::operator++; %ignore *::operator--;
  86. %ignore *::operator=; // note: this might be better to rename to assign() or similar
  87. %ignore operator+;
  88. %ignore operator-;
  89. %ignore operator*;
  90. %ignore operator/;
  91. %ignore operator%;
  92. %ignore operator[];
  93. %ignore operator>; %ignore operator>=;
  94. %ignore operator<; %ignore operator<=;
  95. %ignore operator==; %ignore operator!=;
  96. // renaming the python operators to be compatible with lua
  97. // this means that if a developer has written a fn __add__()
  98. // it will be used for the lua +
  99. %rename(__add) *::__add__;
  100. %rename(__sub) *::__sub__;
  101. %rename(__mul) *::__mul__;
  102. %rename(__div) *::__div__;
  103. %rename(__unm) *::__neg__; // lua calls unary minus,'unm' not 'neg'
  104. %rename(__tostring) *::__str__; // both map to __tostring
  105. %rename(__tostring) *::__repr__; // both map to __tostring
  106. %rename(__pow) *::__pow__; // lua power '^' operator
  107. %rename(__concat) *::__concat__; // lua concat '..' operator
  108. %rename(__eq) *::__eq__;
  109. %rename(__lt) *::__lt__;
  110. %rename(__le) *::__le__;
  111. %rename(__call) *::__call__; // the fn call operator()
  112. // the [] operator has two parts, the get & the set
  113. %rename(__getitem) *::__getitem__; // the v=X[i] (get operator)
  114. %rename(__setitem) *::__setitem__; // the X[i]=v (set operator)
  115. #endif
  116. /* ------------------------------------------------------------
  117. * Exceptions
  118. * ------------------------------------------------------------ */
  119. /* Confession: I dont really like C++ exceptions
  120. The python/lua ones are great, but C++ ones I dont like
  121. (mainly because I cannot get the stack trace out of it)
  122. Therefore I have not bothered to try doing much in this
  123. Therefore currently its just enough to get a few test cases running ok
  124. note: if you wish to throw anything related to std::exception
  125. use %include <std_except.i> instead
  126. */
  127. %typemap(throws) int,unsigned int,signed int,
  128. long,unsigned long,signed long,
  129. short,unsigned short,signed short,
  130. bool,float,double,
  131. long long,unsigned long long,
  132. char, unsigned char, signed char,
  133. enum SWIGTYPE
  134. %{lua_pushfstring(L,"numeric exception:%f",(double)$1);SWIG_fail; %}
  135. // strings are just sent as errors
  136. %typemap(throws) char*, const char*
  137. %{lua_pushstring(L,$1);SWIG_fail;%}
  138. /*
  139. Throwing object is a serious problem:
  140. Assuming some code throws a 'FooBar'
  141. There are a few options:
  142. - return a pointer to it: but its unclear how long this will last for.
  143. - return a copy of it: but not all objects are copyable
  144. (see exception_partial_info in the test suite for a case where you cannot)
  145. - convert to a string & throw that
  146. its not so useful, but it works (this is more lua like).
  147. The third option (though not nice) is used
  148. For a more useful solution: see std_except for more details
  149. */
  150. %typemap(throws) SWIGTYPE
  151. {
  152. lua_pushfstring(L,"object exception:%s",SWIG_TypePrettyName($1_descriptor));
  153. SWIG_fail;
  154. }
  155. // old code: fails under exception_partial_info
  156. // if you have a function which throws a FooBar & you want SWIG to throw the actual object
  157. // then use
  158. // %apply SWIGTYPE BY_VAL {FooBar};
  159. %typemap(throws) SWIGTYPE BY_VAL
  160. {
  161. SWIG_NewPointerObj(L,(void *)new $1_ltype(($1_ltype &) $1),$&1_descriptor,1);
  162. SWIG_fail;
  163. }
  164. /* -----------------------------------------------------------------------------
  165. * extras
  166. * ----------------------------------------------------------------------------- */
  167. /* ------------------------------ end lua.swg ------------------------------ */