luaconf.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /*
  2. ** $Id: luaconf.h,v 1.123 2009/12/17 12:50:20 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. ** Search for "@@" to find all configurable definitions.
  13. ** ===================================================================
  14. */
  15. /*
  16. @@ LUA_ANSI controls the use of non-ansi features.
  17. ** CHANGE it (define it) if you want Lua to avoid the use of any
  18. ** non-ansi feature or library.
  19. */
  20. #if !defined(LUA_ANSI) && defined(__STRICT_ANSI__)
  21. #define LUA_ANSI
  22. #endif
  23. #if !defined(LUA_ANSI) && defined(_WIN32)
  24. #define LUA_WIN
  25. #endif
  26. #if defined(LUA_WIN)
  27. #include <windows.h>
  28. #endif
  29. #if defined(LUA_USE_LINUX)
  30. #define LUA_USE_POSIX
  31. #define LUA_USE_DLOPEN /* needs an extra library: -ldl */
  32. #define LUA_USE_READLINE /* needs some extra libraries */
  33. #endif
  34. #if defined(LUA_USE_MACOSX)
  35. #define LUA_USE_POSIX
  36. #define LUA_DL_DYLD /* does not need extra library */
  37. #endif
  38. /*
  39. @@ LUA_USE_POSIX includes all functionality listed as X/Open System
  40. @* Interfaces Extension (XSI).
  41. ** CHANGE it (define it) if your system is XSI compatible.
  42. */
  43. #if defined(LUA_USE_POSIX)
  44. #define LUA_USE_MKSTEMP
  45. #define LUA_USE_ISATTY
  46. #define LUA_USE_POPEN
  47. #define LUA_USE_ULONGJMP
  48. #endif
  49. /*
  50. @@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
  51. @* Lua libraries.
  52. @@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
  53. @* C libraries.
  54. ** CHANGE them if your machine has a non-conventional directory
  55. ** hierarchy or if you want to install your libraries in
  56. ** non-conventional directories.
  57. */
  58. #if defined(_WIN32)
  59. /*
  60. ** In Windows, any exclamation mark ('!') in the path is replaced by the
  61. ** path of the directory of the executable file of the current process.
  62. */
  63. #define LUA_LDIR "!\\lua\\"
  64. #define LUA_CDIR "!\\"
  65. #define LUA_PATH_DEFAULT \
  66. LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
  67. LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" ".\\?.lua"
  68. #define LUA_CPATH_DEFAULT \
  69. LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll;" ".\\?.dll"
  70. #else
  71. #define LUA_ROOT "/usr/local/"
  72. #define LUA_LDIR LUA_ROOT "share/lua/5.1/"
  73. #define LUA_CDIR LUA_ROOT "lib/lua/5.1/"
  74. #define LUA_PATH_DEFAULT \
  75. LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
  76. LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" "./?.lua"
  77. #define LUA_CPATH_DEFAULT \
  78. LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
  79. #endif
  80. /*
  81. @@ LUA_DIRSEP is the directory separator (for submodules).
  82. ** CHANGE it if your machine does not use "/" as the directory separator
  83. ** and is not Windows. (On Windows Lua automatically uses "\".)
  84. */
  85. #if defined(_WIN32)
  86. #define LUA_DIRSEP "\\"
  87. #else
  88. #define LUA_DIRSEP "/"
  89. #endif
  90. /*
  91. @@ LUA_API is a mark for all core API functions.
  92. @@ LUALIB_API is a mark for all auxiliary library functions.
  93. @@ LUAMOD_API is a mark for all standard library opening functions.
  94. ** CHANGE them if you need to define those functions in some special way.
  95. ** For instance, if you want to create one Windows DLL with the core and
  96. ** the libraries, you may want to use the following definition (define
  97. ** LUA_BUILD_AS_DLL to get it).
  98. */
  99. #if defined(LUA_BUILD_AS_DLL)
  100. #if defined(LUA_CORE) || defined(LUA_LIB)
  101. #define LUA_API __declspec(dllexport)
  102. #else
  103. #define LUA_API __declspec(dllimport)
  104. #endif
  105. #else
  106. #define LUA_API extern
  107. #endif
  108. /* more often than not the libs go together with the core */
  109. #define LUALIB_API LUA_API
  110. #define LUAMOD_API LUALIB_API
  111. /*
  112. @@ LUAI_FUNC is a mark for all extern functions that are not to be
  113. @* exported to outside modules.
  114. @@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables
  115. @* that are not to be exported to outside modules (LUAI_DDEF for
  116. @* definitions and LUAI_DDEC for declarations).
  117. ** CHANGE them if you need to mark them in some special way. Elf/gcc
  118. ** (versions 3.2 and later) mark them as "hidden" to optimize access
  119. ** when Lua is compiled as a shared library. Not all elf targets support
  120. ** this attribute. Unfortunately, gcc does not offer a way to check
  121. ** whether the target offers that support, and those without support
  122. ** give a warning about it. To avoid these warnings, change to the
  123. ** default definition.
  124. */
  125. #if defined(luaall_c)
  126. #define LUAI_FUNC static
  127. #define LUAI_DDEC static
  128. #define LUAI_DDEF static
  129. #elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
  130. defined(__ELF__)
  131. #define LUAI_FUNC __attribute__((visibility("hidden"))) extern
  132. #define LUAI_DDEC LUAI_FUNC
  133. #define LUAI_DDEF /* empty */
  134. #else
  135. #define LUAI_FUNC extern
  136. #define LUAI_DDEC extern
  137. #define LUAI_DDEF /* empty */
  138. #endif
  139. /*
  140. @@ LUA_QL describes how error messages quote program elements.
  141. ** CHANGE it if you want a different appearance.
  142. */
  143. #define LUA_QL(x) "'" x "'"
  144. #define LUA_QS LUA_QL("%s")
  145. /*
  146. @@ LUA_IDSIZE gives the maximum size for the description of the source
  147. @* of a function in debug information.
  148. ** CHANGE it if you want a different size.
  149. */
  150. #define LUA_IDSIZE 60
  151. /*
  152. @@ luai_writestring defines how 'print' prints its results.
  153. ** CHANGE it if your system does not have a useful stdout.
  154. */
  155. #define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
  156. /*
  157. ** {==================================================================
  158. ** Compatibility with previous versions
  159. ** ===================================================================
  160. */
  161. /*
  162. @@ LUA_COMPAT_FENV controls the presence of functions 'setfenv/getfenv'.
  163. ** CHANGE it (define it) if you need these functions. (You can replace
  164. ** them with lexical environments, 'loadin', or the debug library.)
  165. */
  166. /* #define LUA_COMPAT_FENV */
  167. /*
  168. @@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.
  169. ** CHANGE it (undefine it) if as soon as you rewrite all calls 'log10(x)'
  170. ** as 'log(x, 10)'
  171. */
  172. #define LUA_COMPAT_LOG10
  173. /*
  174. @@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.
  175. ** CHANGE it (define it) if you need that function.
  176. */
  177. /* #define LUA_COMPAT_MAXN */
  178. /*
  179. @@ LUA_COMPAT_API includes some macros and functions that supply some
  180. @* compatibility with previous versions.
  181. ** CHANGE it (undefine it) if you do not need these compatibility facilities.
  182. */
  183. #define LUA_COMPAT_API
  184. /*
  185. @@ LUA_COMPAT_DEBUGLIB controls compatibility with preloading
  186. @* the debug library.
  187. ** CHANGE it to undefined as soon as you add 'require"debug"' everywhere
  188. ** you need the debug library.
  189. */
  190. #define LUA_COMPAT_DEBUGLIB
  191. /* }================================================================== */
  192. /*
  193. @@ LUAI_BITSINT defines the number of bits in an int.
  194. ** CHANGE here if Lua cannot automatically detect the number of bits of
  195. ** your machine. Probably you do not need to change this.
  196. */
  197. /* avoid overflows in comparison */
  198. #if INT_MAX-20 < 32760
  199. #define LUAI_BITSINT 16
  200. #elif INT_MAX > 2147483640L
  201. /* int has at least 32 bits */
  202. #define LUAI_BITSINT 32
  203. #else
  204. #error "you must define LUA_BITSINT with number of bits in an integer"
  205. #endif
  206. /*
  207. @@ LUA_INT32 is an signed integer with exactly 32 bits.
  208. @@ LUAI_UMEM is an unsigned integer big enough to count the total
  209. @* memory used by Lua.
  210. @@ LUAI_MEM is a signed integer big enough to count the total memory
  211. @* used by Lua.
  212. ** CHANGE here if for some weird reason the default definitions are not
  213. ** good enough for your machine. Probably you do not need to change
  214. ** this.
  215. */
  216. #if LUAI_BITSINT >= 32
  217. #define LUA_INT32 int
  218. #define LUAI_UMEM size_t
  219. #define LUAI_MEM ptrdiff_t
  220. #else
  221. /* 16-bit ints */
  222. #define LUA_INT32 long
  223. #define LUAI_UMEM unsigned long
  224. #define LUAI_MEM long
  225. #endif
  226. /*
  227. @@ LUAI_MAXSTACK limits the size of the Lua stack.
  228. ** CHANGE it if you need a different limit. This limit is arbitrary;
  229. ** its only purpose is to stop Lua to consume unlimited stack
  230. ** space (and to reserve some numbers for pseudo-indices).
  231. */
  232. #if LUAI_BITSINT >= 32
  233. #define LUAI_MAXSTACK 1000000
  234. #else
  235. #define LUAI_MAXSTACK 15000
  236. #endif
  237. /* reserve some space for error handling */
  238. #define LUAI_FIRSTPSEUDOIDX (-LUAI_MAXSTACK - 1000)
  239. /*
  240. ** {==================================================================
  241. ** CHANGE (to smaller values) the following definitions if your system
  242. ** has a small C stack. (Or you may want to change them to larger
  243. ** values if your system has a large C stack and these limits are
  244. ** too rigid for you.) Some of these constants control the size of
  245. ** stack-allocated arrays used by the compiler or the interpreter, while
  246. ** others limit the maximum number of recursive calls that the compiler
  247. ** or the interpreter can perform. Values too large may cause a C stack
  248. ** overflow for some forms of deep constructs.
  249. ** ===================================================================
  250. */
  251. /*
  252. @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
  253. */
  254. #define LUAL_BUFFERSIZE BUFSIZ
  255. /* }================================================================== */
  256. /*
  257. ** {==================================================================
  258. @@ LUA_NUMBER is the type of numbers in Lua.
  259. ** CHANGE the following definitions only if you want to build Lua
  260. ** with a number type different from double. You may also need to
  261. ** change lua_number2int & lua_number2integer.
  262. ** ===================================================================
  263. */
  264. #define LUA_NUMBER_DOUBLE
  265. #define LUA_NUMBER double
  266. /*
  267. @@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
  268. @* over a number.
  269. */
  270. #define LUAI_UACNUMBER double
  271. /*
  272. @@ LUA_NUMBER_SCAN is the format for reading numbers.
  273. @@ LUA_NUMBER_FMT is the format for writing numbers.
  274. @@ lua_number2str converts a number to a string.
  275. @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
  276. @@ lua_str2number converts a string to a number.
  277. */
  278. #define LUA_NUMBER_SCAN "%lf"
  279. #define LUA_NUMBER_FMT "%.14g"
  280. #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
  281. #define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
  282. #define lua_str2number(s,p) strtod((s), (p))
  283. /*
  284. @@ The luai_num* macros define the primitive operations over numbers.
  285. */
  286. /* the following operations need the math library */
  287. #if defined(lobject_c) || defined(lvm_c) || defined(luaall_c)
  288. #include <math.h>
  289. #define luai_nummod(L,a,b) ((a) - floor((a)/(b))*(b))
  290. #define luai_numpow(L,a,b) (pow(a,b))
  291. #endif
  292. /* these are quite standard operations */
  293. #if defined(LUA_CORE)
  294. #define luai_numadd(L,a,b) ((a)+(b))
  295. #define luai_numsub(L,a,b) ((a)-(b))
  296. #define luai_nummul(L,a,b) ((a)*(b))
  297. #define luai_numdiv(L,a,b) ((a)/(b))
  298. #define luai_numunm(L,a) (-(a))
  299. #define luai_numeq(a,b) ((a)==(b))
  300. #define luai_numlt(L,a,b) ((a)<(b))
  301. #define luai_numle(L,a,b) ((a)<=(b))
  302. #define luai_numisnan(L,a) (!luai_numeq((a), (a)))
  303. #endif
  304. /*
  305. @@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
  306. ** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
  307. ** machines, ptrdiff_t gives a good choice between int or long.)
  308. */
  309. #define LUA_INTEGER ptrdiff_t
  310. /*
  311. @@ lua_number2int is a macro to convert lua_Number to int.
  312. @@ lua_number2integer is a macro to convert lua_Number to lUA_INTEGER.
  313. @@ lua_number2uint is a macro to convert a lua_Number to an unsigned
  314. @* LUA_INT32.
  315. @@ lua_uint2number is a macro to convert an unsigned LUA_INT32
  316. @* to a lua_Number.
  317. ** CHANGE them if you know a faster way to convert a lua_Number to
  318. ** int (with any rounding method and without throwing errors) in your
  319. ** system. In Pentium machines, a naive typecast from double to int
  320. ** in C is extremely slow, so any alternative is worth trying.
  321. */
  322. /* On a Pentium, resort to a trick */
  323. #if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \
  324. (defined(__i386) || defined (_M_IX86) || defined(__i386__))
  325. /* On a Microsoft compiler, use assembler */
  326. #if defined(_MSC_VER)
  327. #define lua_number2int(i,d) __asm fld d __asm fistp i
  328. #define lua_number2integer(i,n) lua_number2int(i, n)
  329. #else
  330. /* the next trick should work on any Pentium, but sometimes clashes
  331. with a DirectX idiosyncrasy */
  332. union luai_Cast { double l_d; long l_l; };
  333. #define lua_number2int(i,d) \
  334. { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
  335. #define lua_number2integer(i,n) lua_number2int(i, n)
  336. #define lua_number2uint(i,n) lua_number2int(i, n)
  337. #endif
  338. #else
  339. /* this option always works, but may be slow */
  340. #define lua_number2int(i,d) ((i)=(int)(d))
  341. #define lua_number2integer(i,d) ((i)=(LUA_INTEGER)(d))
  342. #define lua_number2uint(i,d) ((i)=(unsigned LUA_INT32)(d))
  343. #endif
  344. /* on several machines, coercion from unsigned to double is too slow,
  345. so avoid that if possible */
  346. #define lua_uint2number(u) \
  347. ((LUA_INT32)(u) < 0 ? (lua_Number)(u) : (lua_Number)(LUA_INT32)(u))
  348. /*
  349. @@ luai_hashnum is a macro do hash a lua_Number value into an integer.
  350. @* The hash must be deterministic and give reasonable values for
  351. @* both small and large values (outside the range of integers).
  352. @* It is used only in ltable.c.
  353. */
  354. #if defined(ltable_c) || defined(luaall_c)
  355. #include <float.h>
  356. #include <math.h>
  357. #define luai_hashnum(i,d) { int e; \
  358. d = frexp(d, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \
  359. lua_number2int(i, d); i += e; }
  360. #endif
  361. /* }================================================================== */
  362. /*
  363. @@ LUA_DL_* define which dynamic-library system Lua should use.
  364. ** CHANGE here if Lua has problems choosing the appropriate
  365. ** dynamic-library system for your platform (either Windows' DLL, Mac's
  366. ** dyld, or Unix's dlopen). If your system is some kind of Unix, there
  367. ** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for
  368. ** it. To use dlopen you also need to adapt the src/Makefile (probably
  369. ** adding -ldl to the linker options), so Lua does not select it
  370. ** automatically. (When you change the makefile to add -ldl, you must
  371. ** also add -DLUA_USE_DLOPEN.)
  372. ** If you do not want any kind of dynamic library, undefine all these
  373. ** options.
  374. ** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD.
  375. */
  376. #if defined(LUA_USE_DLOPEN)
  377. #define LUA_DL_DLOPEN
  378. #endif
  379. #if defined(LUA_WIN)
  380. #define LUA_DL_DLL
  381. #endif
  382. /* =================================================================== */
  383. /*
  384. ** Local configuration. You can use this space to add your redefinitions
  385. ** without modifying the main part of the file.
  386. */
  387. #endif