luaconf.h 14 KB

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