luaconf.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /*
  2. ** $Id: luaconf.h,v 1.187 2013/10/10 15:45:03 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) && !defined(_WIN32_WCE)
  24. #define LUA_WIN /* enable goodies for regular Windows platforms */
  25. #endif
  26. #if defined(LUA_WIN)
  27. #define LUA_DL_DLL
  28. #define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
  29. #endif
  30. #if defined(LUA_USE_LINUX)
  31. #define LUA_USE_POSIX
  32. #define LUA_USE_DLOPEN /* needs an extra library: -ldl */
  33. #define LUA_USE_READLINE /* needs some extra libraries */
  34. #define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
  35. #define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
  36. #define LUA_USE_LONGLONG /* assume support for long long */
  37. #endif
  38. #if defined(LUA_USE_MACOSX)
  39. #define LUA_USE_POSIX
  40. #define LUA_USE_DLOPEN /* does not need -ldl */
  41. #define LUA_USE_READLINE /* needs an extra library: -lreadline */
  42. #define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
  43. #define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
  44. #define LUA_USE_LONGLONG /* assume support for long long */
  45. #endif
  46. /*
  47. @@ LUA_USE_POSIX includes all functionality listed as X/Open System
  48. @* Interfaces Extension (XSI).
  49. ** CHANGE it (define it) if your system is XSI compatible.
  50. */
  51. #if defined(LUA_USE_POSIX)
  52. #define LUA_USE_MKSTEMP
  53. #define LUA_USE_ISATTY
  54. #define LUA_USE_POPEN
  55. #define LUA_USE_ULONGJMP
  56. #define LUA_USE_GMTIME_R
  57. #endif
  58. /*
  59. @@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
  60. @* Lua libraries.
  61. @@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
  62. @* C libraries.
  63. ** CHANGE them if your machine has a non-conventional directory
  64. ** hierarchy or if you want to install your libraries in
  65. ** non-conventional directories.
  66. */
  67. #if defined(_WIN32) /* { */
  68. /*
  69. ** In Windows, any exclamation mark ('!') in the path is replaced by the
  70. ** path of the directory of the executable file of the current process.
  71. */
  72. #define LUA_LDIR "!\\lua\\"
  73. #define LUA_CDIR "!\\"
  74. #define LUA_PATH_DEFAULT \
  75. LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
  76. LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \
  77. ".\\?.lua;" ".\\?\\init.lua"
  78. #define LUA_CPATH_DEFAULT \
  79. LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll;" ".\\?.dll"
  80. #else /* }{ */
  81. #define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR "/"
  82. #define LUA_ROOT "/usr/local/"
  83. #define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR
  84. #define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR
  85. #define LUA_PATH_DEFAULT \
  86. LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
  87. LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \
  88. "./?.lua;" "./?/init.lua"
  89. #define LUA_CPATH_DEFAULT \
  90. LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
  91. #endif /* } */
  92. /*
  93. @@ LUA_DIRSEP is the directory separator (for submodules).
  94. ** CHANGE it if your machine does not use "/" as the directory separator
  95. ** and is not Windows. (On Windows Lua automatically uses "\".)
  96. */
  97. #if defined(_WIN32)
  98. #define LUA_DIRSEP "\\"
  99. #else
  100. #define LUA_DIRSEP "/"
  101. #endif
  102. /*
  103. @@ LUA_ENV is the name of the variable that holds the current
  104. @@ environment, used to access global names.
  105. ** CHANGE it if you do not like this name.
  106. */
  107. #define LUA_ENV "_ENV"
  108. /*
  109. @@ LUA_API is a mark for all core API functions.
  110. @@ LUALIB_API is a mark for all auxiliary library functions.
  111. @@ LUAMOD_API is a mark for all standard library opening functions.
  112. ** CHANGE them if you need to define those functions in some special way.
  113. ** For instance, if you want to create one Windows DLL with the core and
  114. ** the libraries, you may want to use the following definition (define
  115. ** LUA_BUILD_AS_DLL to get it).
  116. */
  117. #if defined(LUA_BUILD_AS_DLL) /* { */
  118. #if defined(LUA_CORE) || defined(LUA_LIB) /* { */
  119. #define LUA_API __declspec(dllexport)
  120. #else /* }{ */
  121. #define LUA_API __declspec(dllimport)
  122. #endif /* } */
  123. #else /* }{ */
  124. #define LUA_API extern
  125. #endif /* } */
  126. /* more often than not the libs go together with the core */
  127. #define LUALIB_API LUA_API
  128. #define LUAMOD_API LUALIB_API
  129. /*
  130. @@ LUAI_FUNC is a mark for all extern functions that are not to be
  131. @* exported to outside modules.
  132. @@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables
  133. @* that are not to be exported to outside modules (LUAI_DDEF for
  134. @* definitions and LUAI_DDEC for declarations).
  135. ** CHANGE them if you need to mark them in some special way. Elf/gcc
  136. ** (versions 3.2 and later) mark them as "hidden" to optimize access
  137. ** when Lua is compiled as a shared library. Not all elf targets support
  138. ** this attribute. Unfortunately, gcc does not offer a way to check
  139. ** whether the target offers that support, and those without support
  140. ** give a warning about it. To avoid these warnings, change to the
  141. ** default definition.
  142. */
  143. #if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
  144. defined(__ELF__) /* { */
  145. #define LUAI_FUNC __attribute__((visibility("hidden"))) extern
  146. #define LUAI_DDEC LUAI_FUNC
  147. #define LUAI_DDEF /* empty */
  148. #else /* }{ */
  149. #define LUAI_FUNC extern
  150. #define LUAI_DDEC extern
  151. #define LUAI_DDEF /* empty */
  152. #endif /* } */
  153. /*
  154. @@ LUA_QL describes how error messages quote program elements.
  155. ** CHANGE it if you want a different appearance.
  156. */
  157. #define LUA_QL(x) "'" x "'"
  158. #define LUA_QS LUA_QL("%s")
  159. /*
  160. @@ LUA_IDSIZE gives the maximum size for the description of the source
  161. @* of a function in debug information.
  162. ** CHANGE it if you want a different size.
  163. */
  164. #define LUA_IDSIZE 60
  165. /*
  166. @@ luai_writestring/luai_writeline define how 'print' prints its results.
  167. ** They are only used in libraries and the stand-alone program. (The #if
  168. ** avoids including 'stdio.h' everywhere.)
  169. */
  170. #if defined(LUA_LIB) || defined(lua_c)
  171. #include <stdio.h>
  172. #define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
  173. #define luai_writeline() (luai_writestring("\n", 1), fflush(stdout))
  174. #endif
  175. /*
  176. @@ luai_writestringerror defines how to print error messages.
  177. ** (A format string with one argument is enough for Lua...)
  178. */
  179. #define luai_writestringerror(s,p) \
  180. (fprintf(stderr, (s), (p)), fflush(stderr))
  181. /*
  182. @@ LUAI_MAXSHORTLEN is the maximum length for short strings, that is,
  183. ** strings that are internalized. (Cannot be smaller than reserved words
  184. ** or tags for metamethods, as these strings must be internalized;
  185. ** #("function") = 8, #("__newindex") = 10.)
  186. */
  187. #define LUAI_MAXSHORTLEN 40
  188. /*
  189. ** {==================================================================
  190. ** Compatibility with previous versions
  191. ** ===================================================================
  192. */
  193. /*
  194. @@ LUA_COMPAT_ALL controls all compatibility options.
  195. ** You can define it to get all options, or change specific options
  196. ** to fit your specific needs.
  197. */
  198. #if defined(LUA_COMPAT_ALL) /* { */
  199. /*
  200. @@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.
  201. ** You can replace it with 'table.unpack'.
  202. */
  203. #define LUA_COMPAT_UNPACK
  204. /*
  205. @@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'.
  206. ** You can replace it with 'package.searchers'.
  207. */
  208. #define LUA_COMPAT_LOADERS
  209. /*
  210. @@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.
  211. ** You can call your C function directly (with light C functions).
  212. */
  213. #define lua_cpcall(L,f,u) \
  214. (lua_pushcfunction(L, (f)), \
  215. lua_pushlightuserdata(L,(u)), \
  216. lua_pcall(L,1,0,0))
  217. /*
  218. @@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.
  219. ** You can rewrite 'log10(x)' as 'log(x, 10)'.
  220. */
  221. #define LUA_COMPAT_LOG10
  222. /*
  223. @@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base
  224. ** library. You can rewrite 'loadstring(s)' as 'load(s)'.
  225. */
  226. #define LUA_COMPAT_LOADSTRING
  227. /*
  228. @@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.
  229. */
  230. #define LUA_COMPAT_MAXN
  231. /*
  232. @@ The following macros supply trivial compatibility for some
  233. ** changes in the API. The macros themselves document how to
  234. ** change your code to avoid using them.
  235. */
  236. #define lua_strlen(L,i) lua_rawlen(L, (i))
  237. #define lua_objlen(L,i) lua_rawlen(L, (i))
  238. #define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
  239. #define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
  240. /*
  241. @@ LUA_COMPAT_MODULE controls compatibility with previous
  242. ** module functions 'module' (Lua) and 'luaL_register' (C).
  243. */
  244. #define LUA_COMPAT_MODULE
  245. #endif /* } */
  246. /* }================================================================== */
  247. /*
  248. @@ LUAI_BITSINT defines the number of bits in an int.
  249. ** CHANGE here if Lua cannot automatically detect the number of bits of
  250. ** your machine. Probably you do not need to change this.
  251. */
  252. /* avoid overflows in comparison */
  253. #if INT_MAX-20 < 32760 /* { */
  254. #define LUAI_BITSINT 16
  255. #elif INT_MAX > 2147483640L /* }{ */
  256. /* int has at least 32 bits */
  257. #define LUAI_BITSINT 32
  258. #else /* }{ */
  259. #error "you must define LUA_BITSINT with number of bits in an integer"
  260. #endif /* } */
  261. /*
  262. @@ LUA_INT32 is an signed integer with exactly 32 bits.
  263. @@ LUAI_UMEM is an unsigned integer big enough to count the total
  264. @* memory used by Lua.
  265. @@ LUAI_MEM is a signed integer big enough to count the total memory
  266. @* used by Lua.
  267. ** CHANGE here if for some weird reason the default definitions are not
  268. ** good enough for your machine. Probably you do not need to change
  269. ** this.
  270. */
  271. #if LUAI_BITSINT >= 32 /* { */
  272. #define LUA_INT32 int
  273. #define LUAI_UMEM size_t
  274. #define LUAI_MEM ptrdiff_t
  275. #else /* }{ */
  276. /* 16-bit ints */
  277. #define LUA_INT32 long
  278. #define LUAI_UMEM unsigned long
  279. #define LUAI_MEM long
  280. #endif /* } */
  281. /*
  282. @@ LUAI_MAXSTACK limits the size of the Lua stack.
  283. ** CHANGE it if you need a different limit. This limit is arbitrary;
  284. ** its only purpose is to stop Lua from consuming unlimited stack
  285. ** space (and to reserve some numbers for pseudo-indices).
  286. */
  287. #if LUAI_BITSINT >= 32
  288. #define LUAI_MAXSTACK 1000000
  289. #else
  290. #define LUAI_MAXSTACK 15000
  291. #endif
  292. /* reserve some space for error handling */
  293. #define LUAI_FIRSTPSEUDOIDX (-LUAI_MAXSTACK - 1000)
  294. /*
  295. @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
  296. ** CHANGE it if it uses too much C-stack space.
  297. */
  298. #define LUAL_BUFFERSIZE BUFSIZ
  299. /*
  300. ** {==================================================================
  301. ** The following definitions set the numeric types for Lua.
  302. ** Lua should work fine with 32-bit or 64-bit integers mixed with
  303. ** 32-bit or 64-bit floats. The usual configurations are 64-bit
  304. ** integers and floats (the default) and 32-bit integers and floats.
  305. ** ===================================================================
  306. */
  307. /*
  308. @@ LUA_INT_INT/LUA_INT_LONG/LUA_INT_LONGLONG defines size for Lua integers;
  309. @@ LUA_REAL_FLOAT/LUA_REAL_DOUBLE/LUA_REAL_LONGDOUBLE defines size for
  310. @* Lua floats.
  311. ** Default is long long + double
  312. */
  313. #define LUA_INT_LONGLONG
  314. #define LUA_REAL_DOUBLE
  315. /*
  316. @@ LUA_NUMBER is the floating-point type used by Lua.
  317. **
  318. @@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
  319. @* over a floating number.
  320. **
  321. @@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.
  322. @@ LUA_NUMBER_SCAN is the format for reading floats.
  323. @@ LUA_NUMBER_FMT is the format for writing floats.
  324. @@ lua_number2str converts a floats to a string.
  325. **
  326. @@ l_mathop allows the addition of an 'l' or 'f' to all math operations
  327. **
  328. @@ lua_str2number converts a decimal numeric string to a number.
  329. */
  330. #if defined(LUA_REAL_FLOAT) /* { single float */
  331. #define LUA_NUMBER float
  332. #define LUAI_UACNUMBER double
  333. #define LUA_NUMBER_FRMLEN ""
  334. #define LUA_NUMBER_SCAN "%f"
  335. #define LUA_NUMBER_FMT "%.7g"
  336. #define l_mathop(op) op##f
  337. #define lua_str2number(s,p) strtof((s), (p))
  338. #elif defined(LUA_REAL_LONGDOUBLE) /* }{ long double */
  339. #define LUA_NUMBER long double
  340. #define LUAI_UACNUMBER long double
  341. #define LUA_NUMBER_FRMLEN "L"
  342. #define LUA_NUMBER_SCAN "%Lf"
  343. #define LUA_NUMBER_FMT "%.19Lg"
  344. #define l_mathop(op) op##l
  345. #define lua_str2number(s,p) strtold((s), (p))
  346. #elif defined(LUA_REAL_DOUBLE) /* }{ double */
  347. #define LUA_NUMBER double
  348. #define LUAI_UACNUMBER double
  349. #define LUA_NUMBER_FRMLEN ""
  350. #define LUA_NUMBER_SCAN "%lf"
  351. #define LUA_NUMBER_FMT "%.14g"
  352. #define l_mathop(op) op
  353. #define lua_str2number(s,p) strtod((s), (p))
  354. #else /* }{ */
  355. #error "numeric real type not defined"
  356. #endif /* } */
  357. #if defined(LUA_ANSI)
  358. /* C89 does not support 'opf' variants for math functions */
  359. #undef l_mathop
  360. #define l_mathop(op) (lua_Number)op
  361. #endif
  362. #if defined(LUA_ANSI) || defined(_WIN32)
  363. /* C89 and Windows do not support 'strtof'... */
  364. #undef lua_str2number
  365. #define lua_str2number(s,p) ((lua_Number)strtod((s), (p)))
  366. #endif
  367. #define l_floor(x) (l_mathop(floor)(x))
  368. #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
  369. /*
  370. @@ The luai_num* macros define the primitive operations over numbers.
  371. @* They should work for any size of floating numbers.
  372. */
  373. /* the following operations need the math library */
  374. #if defined(lobject_c) || defined(lvm_c)
  375. #include <math.h>
  376. #define luai_nummod(L,a,b) ((a) - l_floor((a)/(b))*(b))
  377. #define luai_numpow(L,a,b) (l_mathop(pow)(a,b))
  378. #endif
  379. /* these are quite standard operations */
  380. #if defined(LUA_CORE)
  381. #define luai_numadd(L,a,b) ((a)+(b))
  382. #define luai_numsub(L,a,b) ((a)-(b))
  383. #define luai_nummul(L,a,b) ((a)*(b))
  384. #define luai_numdiv(L,a,b) ((a)/(b))
  385. #define luai_numunm(L,a) (-(a))
  386. #define luai_numeq(a,b) ((a)==(b))
  387. #define luai_numlt(L,a,b) ((a)<(b))
  388. #define luai_numle(L,a,b) ((a)<=(b))
  389. #define luai_numisnan(L,a) (!luai_numeq((a), (a)))
  390. #endif
  391. /*
  392. @@ LUA_INTEGER is the integer type used by Lua.
  393. **
  394. @@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.
  395. **
  396. @@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.
  397. @@ LUA_INTEGER_SCAN is the format for reading integers.
  398. @@ LUA_INTEGER_FMT is the format for writing integers.
  399. @@ lua_integer2str converts an integer to a string.
  400. */
  401. #if defined(LUA_INT_INT) /* { int */
  402. #define LUA_INTEGER int
  403. #define LUA_INTEGER_FRMLEN ""
  404. #elif defined(LUA_INT_LONG) /* }{ long */
  405. #define LUA_INTEGER long
  406. #define LUA_INTEGER_FRMLEN "l"
  407. #elif defined(LUA_INT_LONGLONG) /* }{ long long */
  408. #if defined(_WIN32)
  409. #define LUA_INTEGER __int64
  410. #define LUA_INTEGER_FRMLEN "I64"
  411. #else
  412. #define LUA_INTEGER long long
  413. #define LUA_INTEGER_FRMLEN "ll"
  414. #endif
  415. #else /* }{ */
  416. #error "numeric integer type not defined"
  417. #endif /* } */
  418. #define LUA_INTEGER_SCAN "%" LUA_INTEGER_FRMLEN "d"
  419. #define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d"
  420. #define lua_integer2str(s,n) sprintf((s), LUA_INTEGER_FMT, (n))
  421. #define LUA_UNSIGNED unsigned LUA_INTEGER
  422. /* }================================================================== */
  423. /* =================================================================== */
  424. /*
  425. ** Local configuration. You can use this space to add your redefinitions
  426. ** without modifying the main part of the file.
  427. */
  428. #endif