luaconf.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /*
  2. ** $Id: luaconf.h,v 1.26 2005/01/10 18:17:39 roberto Exp roberto $
  3. ** Configuration file for Lua
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lconfig_h
  7. #define lconfig_h
  8. #include <limits.h>
  9. #include <stddef.h>
  10. /*
  11. ** {======================================================
  12. ** Index (search for keyword to find corresponding entry)
  13. ** =======================================================
  14. */
  15. /* }====================================================== */
  16. /*
  17. ** {======================================================
  18. ** Generic configuration
  19. ** =======================================================
  20. */
  21. /* default path */
  22. #if defined(_WIN32)
  23. #define LUA_ROOT "C:\\Program Files\\Lua51"
  24. #define LUA_LDIR LUA_ROOT "\\lua"
  25. #define LUA_CDIR LUA_ROOT "\\dll"
  26. #define LUA_PATH_DEFAULT \
  27. "?.lua;" LUA_LDIR "\\?.lua;" LUA_LDIR "\\?\\init.lua"
  28. #define LUA_CPATH_DEFAULT "?.dll;" LUA_CDIR "\\?.dll"
  29. #else
  30. #define LUA_ROOT "/usr/local"
  31. #define LUA_LDIR LUA_ROOT "/share/lua/5.1"
  32. #define LUA_CDIR LUA_ROOT "/lib/lua/5.1"
  33. #define LUA_PATH_DEFAULT \
  34. "./?.lua;" LUA_LDIR "/?.lua;" LUA_LDIR "/?/init.lua"
  35. #define LUA_CPATH_DEFAULT "./?.so;" LUA_CDIR "/?.so"
  36. #endif
  37. /* type of numbers in Lua */
  38. #define LUA_NUMBER double
  39. /* formats for Lua numbers */
  40. #define LUA_NUMBER_SCAN "%lf"
  41. #define LUA_NUMBER_FMT "%.14g"
  42. /*
  43. ** type for integer functions
  44. ** on most machines, `ptrdiff_t' gives a reasonable size for integers
  45. */
  46. #define LUA_INTEGER ptrdiff_t
  47. /* mark for all API functions */
  48. #define LUA_API extern
  49. /* mark for auxlib functions */
  50. #define LUALIB_API extern
  51. /* buffer size used by lauxlib buffer system */
  52. #define LUAL_BUFFERSIZE BUFSIZ
  53. /* assertions in Lua (mainly for internal debugging) */
  54. #define lua_assert(c) ((void)0)
  55. /* }====================================================== */
  56. /*
  57. ** {======================================================
  58. ** Stand-alone configuration
  59. ** =======================================================
  60. */
  61. #ifdef lua_c
  62. /* definition of `isatty' */
  63. #ifdef _POSIX_C_SOURCE
  64. #include <unistd.h>
  65. #define stdin_is_tty() isatty(0)
  66. #elif defined(_WIN32)
  67. #include <io.h>
  68. #include <stdio.h>
  69. #define stdin_is_tty() _isatty(_fileno(stdin))
  70. #else
  71. #define stdin_is_tty() 1 /* assume stdin is a tty */
  72. #endif
  73. #define PROMPT "> "
  74. #define PROMPT2 ">> "
  75. #define PROGNAME "lua"
  76. /*
  77. ** this macro can be used by some `history' system to save lines
  78. ** read in manual input
  79. */
  80. #define lua_saveline(L,line) /* empty */
  81. #endif
  82. /* }====================================================== */
  83. /*
  84. ** {======================================================
  85. ** Core configuration
  86. ** =======================================================
  87. */
  88. #ifdef LUA_CORE
  89. /* LUA-C API assertions */
  90. #define api_check(L,o) lua_assert(o)
  91. /* number of bits in an `int' */
  92. /* avoid overflows in comparison */
  93. #if INT_MAX-20 < 32760
  94. #define LUA_BITSINT 16
  95. #elif INT_MAX > 2147483640L
  96. /* `int' has at least 32 bits */
  97. #define LUA_BITSINT 32
  98. #else
  99. #error "you must define LUA_BITSINT with number of bits in an integer"
  100. #endif
  101. /*
  102. ** L_UINT32: unsigned integer with at least 32 bits
  103. ** L_INT32: signed integer with at least 32 bits
  104. ** LU_MEM: an unsigned integer big enough to count the total memory used by Lua
  105. ** L_MEM: a signed integer big enough to count the total memory used by Lua
  106. */
  107. #if LUA_BITSINT >= 32
  108. #define LUA_UINT32 unsigned int
  109. #define LUA_INT32 int
  110. #define LUA_MAXINT32 INT_MAX
  111. #define LU_MEM size_t
  112. #define L_MEM ptrdiff_t
  113. #else
  114. /* 16-bit ints */
  115. #define LUA_UINT32 unsigned long
  116. #define LUA_INT32 long
  117. #define LUA_MAXINT32 LONG_MAX
  118. #define LU_MEM LUA_UINT32
  119. #define L_MEM ptrdiff_t
  120. #endif
  121. /* maximum depth for calls (unsigned short) */
  122. #define LUA_MAXCALLS 10000
  123. /*
  124. ** maximum depth for C calls (unsigned short): Not too big, or may
  125. ** overflow the C stack...
  126. */
  127. #define LUA_MAXCCALLS 200
  128. /* maximum size for the virtual stack of a C function */
  129. #define MAXCSTACK 2048
  130. /*
  131. ** maximum number of syntactical nested non-terminals: Not too big,
  132. ** or may overflow the C stack...
  133. */
  134. #define LUA_MAXPARSERLEVEL 200
  135. /* maximum number of variables declared in a function */
  136. #define MAXVARS 200 /* <MAXSTACK */
  137. /* maximum number of upvalues per function */
  138. #define MAXUPVALUES 60 /* <MAXSTACK */
  139. /* maximum size of expressions for optimizing `while' code */
  140. #define MAXEXPWHILE 100
  141. /* function to convert a lua_Number to int (with any rounding method) */
  142. #if defined(__GNUC__) && defined(__i386)
  143. #define lua_number2int(i,d) __asm__ ("fistpl %0":"=m"(i):"t"(d):"st")
  144. #elif defined(_MSC_VER) && defined(_M_IX86)
  145. #pragma warning(disable: 4514)
  146. __inline int l_lrint (double flt)
  147. { int i;
  148. _asm {
  149. fld flt
  150. fistp i
  151. };
  152. return i;
  153. }
  154. #define lua_number2int(i,d) ((i)=l_lrint((d)))
  155. #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199900L)
  156. /* on machines compliant with C99, you can try `lrint' */
  157. #include <math.h>
  158. #define lua_number2int(i,d) ((i)=lrint(d))
  159. #else
  160. #define lua_number2int(i,d) ((i)=(int)(d))
  161. #endif
  162. /* function to convert a lua_Number to lua_Integer (with any rounding method) */
  163. #define lua_number2integer(i,n) lua_number2int((i), (n))
  164. /* function to convert a lua_Number to a string */
  165. #include <stdio.h>
  166. #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
  167. /* maximum size of previous conversion */
  168. #define MAX_NUMBER2STR 32 /* 16 digits, sign, point and \0 (+ some extra) */
  169. /* function to convert a string to a lua_Number */
  170. #define lua_str2number(s,p) strtod((s), (p))
  171. /* result of a `usual argument conversion' over lua_Number */
  172. #define LUA_UACNUMBER double
  173. /* primitive operators for numbers */
  174. #define num_add(a,b) ((a)+(b))
  175. #define num_sub(a,b) ((a)-(b))
  176. #define num_mul(a,b) ((a)*(b))
  177. #define num_div(a,b) ((a)/(b))
  178. #define num_unm(a) (-(a))
  179. #define num_eq(a,b) ((a)==(b))
  180. #define num_lt(a,b) ((a)<(b))
  181. #define num_le(a,b) ((a)<=(b))
  182. #include <math.h>
  183. #define num_pow(a,b) pow(a,b)
  184. /* type to ensure maximum alignment */
  185. #define LUSER_ALIGNMENT_T union { double u; void *s; long l; }
  186. /* exception handling */
  187. #ifndef __cplusplus
  188. /* default handling with long jumps */
  189. #include <setjmp.h>
  190. #define L_THROW(L,c) longjmp((c)->b, 1)
  191. #define L_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
  192. #define l_jmpbuf jmp_buf
  193. #else
  194. /* C++ exceptions */
  195. #define L_THROW(L,c) throw(c)
  196. #define L_TRY(L,c,a) try { a } catch(...) \
  197. { if ((c)->status == 0) (c)->status = -1; }
  198. #define l_jmpbuf int /* dummy variable */
  199. #endif
  200. /*
  201. ** macros for thread synchronization inside Lua core machine:
  202. ** all accesses to the global state and to global objects are synchronized.
  203. ** Because threads can read the stack of other threads
  204. ** (when running garbage collection),
  205. ** a thread must also synchronize any write-access to its own stack.
  206. ** Unsynchronized accesses are allowed only when reading its own stack,
  207. ** or when reading immutable fields from global objects
  208. ** (such as string values and udata values).
  209. */
  210. #define lua_lock(L) ((void) 0)
  211. #define lua_unlock(L) ((void) 0)
  212. /*
  213. ** this macro allows a thread switch in appropriate places in the Lua
  214. ** core
  215. */
  216. #define lua_threadyield(L) {lua_unlock(L); lua_lock(L);}
  217. /* allows user-specific initialization on new threads */
  218. #define lua_userstateopen(L) /* empty */
  219. #endif
  220. /* }====================================================== */
  221. /*
  222. ** {======================================================
  223. ** Library configuration
  224. ** =======================================================
  225. */
  226. #ifdef LUA_LIB
  227. /* `assert' options */
  228. /* environment variables that hold the search path for packages */
  229. #define LUA_PATH "LUA_PATH"
  230. #define LUA_CPATH "LUA_CPATH"
  231. /* prefix for open functions in C libraries */
  232. #define LUA_POF "luaopen_"
  233. /* separator for open functions in C libraries */
  234. #define LUA_OFSEP ""
  235. /* directory separator (for submodules) */
  236. #if defined(_WIN32)
  237. #define LUA_DIRSEP "\\"
  238. #else
  239. #define LUA_DIRSEP "/"
  240. #endif
  241. /* separator of templates in a path */
  242. #define LUA_PATH_SEP ';'
  243. /* wild char in each template */
  244. #define LUA_PATH_MARK "?"
  245. /* maximum number of captures in pattern-matching */
  246. #define MAX_CAPTURES 32 /* arbitrary limit */
  247. /*
  248. ** by default, gcc does not get `tmpname'
  249. */
  250. #ifdef __GNUC__
  251. #define USE_TMPNAME 0
  252. #else
  253. #define USE_TMPNAME 1
  254. #endif
  255. /*
  256. ** Configuration for loadlib
  257. */
  258. #if defined(_WIN32)
  259. #define USE_DLL
  260. #elif defined(__APPLE__) && defined(__MACH__)
  261. #define USE_DYLD
  262. #elif defined(__linux) || defined(sun) || defined(sgi) || defined(BSD)
  263. #define USE_DLOPEN
  264. #endif
  265. #endif
  266. /* }====================================================== */
  267. /* Local configuration */
  268. #undef USE_TMPNAME
  269. #define USE_TMPNAME 1
  270. #endif