luaconf.h 14 KB

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