luaconf.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. /*
  2. ** $Id: luaconf.h,v 1.134 2010/03/03 18:53:02 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_LOG10 defines the function 'log10' in the math library.
  187. ** You can rewrite 'log10(x)' as 'log(x, 10)'.
  188. */
  189. #define LUA_COMPAT_LOG10
  190. /*
  191. @@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.
  192. */
  193. #define LUA_COMPAT_MAXN
  194. /*
  195. @@ LUA_COMPAT_DEBUGLIB controls compatibility with preloading
  196. ** the debug library.
  197. ** You should add 'require"debug"' everywhere you need the debug
  198. ** library.
  199. */
  200. #define LUA_COMPAT_DEBUGLIB
  201. /*
  202. @@ The following macros supply trivial compatibility for some
  203. ** changes in the API. The macros themselves document how to
  204. ** change your code to avoid using them.
  205. */
  206. #define lua_strlen(L,i) lua_rawlen(L, (i))
  207. #define lua_objlen(L,i) lua_rawlen(L, (i))
  208. #define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
  209. #define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
  210. /* compatibility with previous wrong spelling */
  211. #define luaL_typerror luaL_typeerror
  212. #endif
  213. /* }================================================================== */
  214. /*
  215. @@ LUAI_BITSINT defines the number of bits in an int.
  216. ** CHANGE here if Lua cannot automatically detect the number of bits of
  217. ** your machine. Probably you do not need to change this.
  218. */
  219. /* avoid overflows in comparison */
  220. #if INT_MAX-20 < 32760
  221. #define LUAI_BITSINT 16
  222. #elif INT_MAX > 2147483640L
  223. /* int has at least 32 bits */
  224. #define LUAI_BITSINT 32
  225. #else
  226. #error "you must define LUA_BITSINT with number of bits in an integer"
  227. #endif
  228. /*
  229. @@ LUA_INT32 is an signed integer with exactly 32 bits.
  230. @@ LUAI_UMEM is an unsigned integer big enough to count the total
  231. @* memory used by Lua.
  232. @@ LUAI_MEM is a signed integer big enough to count the total memory
  233. @* used by Lua.
  234. ** CHANGE here if for some weird reason the default definitions are not
  235. ** good enough for your machine. Probably you do not need to change
  236. ** this.
  237. */
  238. #if LUAI_BITSINT >= 32
  239. #define LUA_INT32 int
  240. #define LUAI_UMEM size_t
  241. #define LUAI_MEM ptrdiff_t
  242. #else
  243. /* 16-bit ints */
  244. #define LUA_INT32 long
  245. #define LUAI_UMEM unsigned long
  246. #define LUAI_MEM long
  247. #endif
  248. /*
  249. @@ LUAI_MAXSTACK limits the size of the Lua stack.
  250. ** CHANGE it if you need a different limit. This limit is arbitrary;
  251. ** its only purpose is to stop Lua to consume unlimited stack
  252. ** space (and to reserve some numbers for pseudo-indices).
  253. */
  254. #if LUAI_BITSINT >= 32
  255. #define LUAI_MAXSTACK 1000000
  256. #else
  257. #define LUAI_MAXSTACK 15000
  258. #endif
  259. /* reserve some space for error handling */
  260. #define LUAI_FIRSTPSEUDOIDX (-LUAI_MAXSTACK - 1000)
  261. /*
  262. ** {==================================================================
  263. ** CHANGE (to smaller values) the following definitions if your system
  264. ** has a small C stack. (Or you may want to change them to larger
  265. ** values if your system has a large C stack and these limits are
  266. ** too rigid for you.) Some of these constants control the size of
  267. ** stack-allocated arrays used by the compiler or the interpreter, while
  268. ** others limit the maximum number of recursive calls that the compiler
  269. ** or the interpreter can perform. Values too large may cause a C stack
  270. ** overflow for some forms of deep constructs.
  271. ** ===================================================================
  272. */
  273. /*
  274. @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
  275. */
  276. #define LUAL_BUFFERSIZE BUFSIZ
  277. /* }================================================================== */
  278. /*
  279. ** {==================================================================
  280. @@ LUA_NUMBER is the type of numbers in Lua.
  281. ** CHANGE the following definitions only if you want to build Lua
  282. ** with a number type different from double. You may also need to
  283. ** change lua_number2int & lua_number2integer.
  284. ** ===================================================================
  285. */
  286. #define LUA_NUMBER_DOUBLE
  287. #define LUA_NUMBER double
  288. /*
  289. @@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
  290. @* over a number.
  291. */
  292. #define LUAI_UACNUMBER double
  293. /*
  294. @@ LUA_NUMBER_SCAN is the format for reading numbers.
  295. @@ LUA_NUMBER_FMT is the format for writing numbers.
  296. @@ lua_number2str converts a number to a string.
  297. @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
  298. @@ lua_str2number converts a string to a number.
  299. */
  300. #define LUA_NUMBER_SCAN "%lf"
  301. #define LUA_NUMBER_FMT "%.14g"
  302. #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
  303. #define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
  304. #define lua_str2number(s,p) strtod((s), (p))
  305. /*
  306. @@ The luai_num* macros define the primitive operations over numbers.
  307. */
  308. /* the following operations need the math library */
  309. #if defined(lobject_c) || defined(lvm_c) || defined(luaall_c)
  310. #include <math.h>
  311. #define luai_nummod(L,a,b) ((a) - floor((a)/(b))*(b))
  312. #define luai_numpow(L,a,b) (pow(a,b))
  313. #endif
  314. /* these are quite standard operations */
  315. #if defined(LUA_CORE)
  316. #define luai_numadd(L,a,b) ((a)+(b))
  317. #define luai_numsub(L,a,b) ((a)-(b))
  318. #define luai_nummul(L,a,b) ((a)*(b))
  319. #define luai_numdiv(L,a,b) ((a)/(b))
  320. #define luai_numunm(L,a) (-(a))
  321. #define luai_numeq(a,b) ((a)==(b))
  322. #define luai_numlt(L,a,b) ((a)<(b))
  323. #define luai_numle(L,a,b) ((a)<=(b))
  324. #define luai_numisnan(L,a) (!luai_numeq((a), (a)))
  325. #endif
  326. /*
  327. @@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
  328. ** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
  329. ** machines, ptrdiff_t gives a good choice between int or long.)
  330. */
  331. #define LUA_INTEGER ptrdiff_t
  332. /*
  333. @@ lua_number2int is a macro to convert lua_Number to int.
  334. @@ lua_number2integer is a macro to convert lua_Number to LUA_INTEGER.
  335. @@ lua_number2uint is a macro to convert a lua_Number to an unsigned
  336. @* LUA_INT32.
  337. @@ lua_uint2number is a macro to convert an unsigned LUA_INT32
  338. @* to a lua_Number.
  339. ** CHANGE them if you know a faster way to convert a lua_Number to
  340. ** int (with any rounding method and without throwing errors) in your
  341. ** system. In Pentium machines, a naive typecast from double to int
  342. ** in C is extremely slow, so any alternative is worth trying.
  343. */
  344. /* On a Pentium, resort to a trick */
  345. #if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \
  346. (defined(__i386) || defined (_M_IX86) || defined(__i386__))
  347. /* On a Microsoft compiler, use assembler */
  348. #if defined(_MSC_VER)
  349. #define lua_number2int(i,d) {__asm fld d __asm fistp i}
  350. #define lua_number2integer(i,n) lua_number2int(i, n)
  351. #define lua_number2uint(i,n) lua_number2int(i, n)
  352. #else
  353. /* the next trick should work on any Pentium, but sometimes clashes
  354. with a DirectX idiosyncrasy */
  355. union luai_Cast { double l_d; long l_l; };
  356. #define lua_number2int(i,d) \
  357. { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
  358. #define lua_number2integer(i,n) lua_number2int(i, n)
  359. #define lua_number2uint(i,n) lua_number2int(i, n)
  360. #endif
  361. #else
  362. /* this option always works, but may be slow */
  363. #define lua_number2int(i,d) ((i)=(int)(d))
  364. #define lua_number2integer(i,d) ((i)=(LUA_INTEGER)(d))
  365. #define lua_number2uint(i,d) ((i)=(unsigned LUA_INT32)(d))
  366. #endif
  367. /* on several machines, coercion from unsigned to double is too slow,
  368. so avoid that if possible */
  369. #define lua_uint2number(u) \
  370. ((LUA_INT32)(u) < 0 ? (lua_Number)(u) : (lua_Number)(LUA_INT32)(u))
  371. /*
  372. @@ luai_hashnum is a macro do hash a lua_Number value into an integer.
  373. @* The hash must be deterministic and give reasonable values for
  374. @* both small and large values (outside the range of integers).
  375. @* It is used only in ltable.c.
  376. */
  377. #if defined(ltable_c) || defined(luaall_c)
  378. #include <float.h>
  379. #include <math.h>
  380. #define luai_hashnum(i,d) { int e; \
  381. d = frexp(d, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \
  382. lua_number2int(i, d); i += e; }
  383. #endif
  384. /* }================================================================== */
  385. /* =================================================================== */
  386. /*
  387. ** Local configuration. You can use this space to add your redefinitions
  388. ** without modifying the main part of the file.
  389. */
  390. #endif