luaconf.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. /*
  2. ** $Id: luaconf.h,v 1.36 2005/03/18 18:02:04 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. ** Index (search for keyword to find corresponding entry)
  13. ** ===================================================================
  14. */
  15. /* }================================================================== */
  16. /*
  17. *@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
  18. ** Lua libraries.
  19. *@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
  20. ** C libraries.
  21. ** CHANGE them if your machine has a non-conventional directory
  22. ** hierarchy or if you want to install your libraries in
  23. ** non-conventional directories.
  24. */
  25. #if defined(_WIN32)
  26. #define LUA_ROOT "C:\\Program Files\\Lua51"
  27. #define LUA_LDIR LUA_ROOT "\\lua"
  28. #define LUA_CDIR LUA_ROOT "\\dll"
  29. #define LUA_PATH_DEFAULT \
  30. "?.lua;" LUA_LDIR"\\?.lua;" LUA_LDIR"\\?\\init.lua"
  31. #define LUA_CPATH_DEFAULT \
  32. "?.dll;" "l?.dll;" LUA_CDIR"\\?.dll;" LUA_CDIR"\\l?.dll"
  33. #else
  34. #define LUA_ROOT "/usr/local"
  35. #define LUA_LDIR LUA_ROOT "/share/lua/5.1"
  36. #define LUA_CDIR LUA_ROOT "/lib/lua/5.1"
  37. #define LUA_PATH_DEFAULT \
  38. "./?.lua;" LUA_LDIR"/?.lua;" LUA_LDIR"/?/init.lua"
  39. #define LUA_CPATH_DEFAULT \
  40. "./?.so;" "./l?.so;" LUA_CDIR"/?.so;" LUA_CDIR"/l?.so"
  41. #endif
  42. /*
  43. *@ LUA_DIRSEP is the directory separator (for submodules).
  44. ** CHANGE it if your machine does not use "/" as the directory separator
  45. ** and is not Windows. (On Windows Lua automatically uses "\".)
  46. */
  47. #if defined(_WIN32)
  48. #define LUA_DIRSEP "\\"
  49. #else
  50. #define LUA_DIRSEP "/"
  51. #endif
  52. /*
  53. *@ LUA_PATHSEP is the character that separates templates in a path.
  54. ** CHANGE it if for some reason your system cannot use a
  55. ** semicolon. (E.g., a semicolon may be a too common character in
  56. ** file/directory names.) Probably you do not need to change this.
  57. */
  58. #define LUA_PATHSEP ';'
  59. /*
  60. *@ LUA_PATH_MARK is ths string that marks the substitution points in a
  61. ** template.
  62. ** CHANGE it if for some reason your system cannot use an interogation
  63. ** mark. (E.g., an interogation mark may be a too common character in
  64. ** file/directory names.) Probably you do not need to change this.
  65. */
  66. #define LUA_PATH_MARK "?"
  67. /*
  68. *@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
  69. ** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
  70. ** machines, ptrdiff_t gives a good choice between int or long.)
  71. */
  72. #define LUA_INTEGER ptrdiff_t
  73. /*
  74. *@ LUA_API is a mark for all core API functions.
  75. *@ LUALIB_API is a mark for all standard library functions.
  76. ** CHANGE them if you need to define those functions in some special way.
  77. ** For instance, if you want to create two Windows DLLs, one with the
  78. ** core, the other with the libraries, you may want to use the following
  79. ** definition:
  80. **
  81. ** #ifdef LUA_CORE
  82. ** #define LUA_API __declspec(__dllexport)
  83. ** #else
  84. ** #define LUA_API __declspec(__dllimport)
  85. ** #endif
  86. ** #ifdef LUA_LIB
  87. ** #define LUALIB_API __declspec(__dllexport)
  88. ** #else
  89. ** #define LUALIB_API __declspec(__dllimport)
  90. ** #endif
  91. */
  92. #define LUA_API extern
  93. #define LUALIB_API extern
  94. /*
  95. *@ lua_assert describes the internal assertions in Lua.
  96. ** CHANGE that only if you need to debug Lua.
  97. */
  98. #define lua_assert(c) ((void)0)
  99. /*
  100. ** {==================================================================
  101. ** Stand-alone configuration
  102. ** ===================================================================
  103. */
  104. #ifdef lua_c
  105. /* CONFIG: definition of isatty */
  106. #ifdef _POSIX_C_SOURCE
  107. #include <unistd.h>
  108. #define stdin_is_tty() isatty(0)
  109. #elif defined(_WIN32)
  110. #include <io.h>
  111. #include <stdio.h>
  112. #define stdin_is_tty() _isatty(_fileno(stdin))
  113. #else
  114. #define stdin_is_tty() 1 /* assume stdin is a tty */
  115. #endif
  116. #define PROMPT "> "
  117. #define PROMPT2 ">> "
  118. #define PROGNAME "lua"
  119. /*
  120. ** CONFIG: this macro can be used by some history system to save lines
  121. ** read in manual input
  122. */
  123. #define lua_saveline(L,line) /* empty */
  124. #endif
  125. /* }================================================================== */
  126. /*
  127. ** CHANGE here (undefining both luaL_getn and luaL_setn) if you want
  128. ** exact compatibility with the behavior of setn/getn in Lua 5.0.
  129. */
  130. #define luaL_getn(L,i) lua_objsize(L, i)
  131. #define luaL_setn(L,i,j) ((void)0) /* no op! */
  132. /*
  133. ** CHANGE luai_apicheck if you want Lua to perform some checks in the
  134. ** parameters it gets from API calls. This may slow down the interpreter
  135. ** a bit, but may be quite useful when debugging C code that interfaces
  136. ** with Lua. A useful redefinition may be like this:
  137. **
  138. ** #include <assert.h>
  139. ** #define luai_apicheck(L,o) assert(o)
  140. **
  141. ** (By default lua_assert is empty, so luai_apicheck is also empty.)
  142. */
  143. #define luai_apicheck(L,o) lua_assert(o)
  144. /*
  145. ** CHANGE here if Lua cannot automatically detect the number of bits of
  146. ** your machine. (In that case, simply define LUA_BITSINT.) Probably you
  147. ** do not need to change this.
  148. */
  149. /* avoid overflows in comparison */
  150. #if INT_MAX-20 < 32760
  151. #define LUAI_BITSINT 16
  152. #elif INT_MAX > 2147483640L
  153. /* int has at least 32 bits */
  154. #define LUAI_BITSINT 32
  155. #else
  156. #error "you must define LUA_BITSINT with number of bits in an integer"
  157. #endif
  158. /*
  159. *@ LUAI_UINT32 is an unsigned integer with at least 32 bits.
  160. *@ LUAI_INT32 is an signed integer with at least 32 bits.
  161. *@ LUAI_UMEM is an an unsigned integer big enough to count the total
  162. ** memory used by Lua.
  163. *@ LUAI_MEM is an a signed integer big enough to count the total memory
  164. ** used by Lua.
  165. ** CHANGE here if for some weird reason the default definitions are not
  166. ** good enough for your machine. The `else' definition always works, but
  167. ** may waste space on machines with 64-bit longs. Probably you do not
  168. ** need to change this.
  169. */
  170. #if LUAI_BITSINT >= 32
  171. #define LUAI_UINT32 unsigned int
  172. #define LUAI_INT32 int
  173. #define LUAI_MAXINT32 INT_MAX
  174. #define LUAI_UMEM size_t
  175. #define LUAI_MEM ptrdiff_t
  176. #else
  177. /* 16-bit ints */
  178. #define LUAI_UINT32 unsigned long
  179. #define LUAI_INT32 long
  180. #define LUAI_MAXINT32 LONG_MAX
  181. #define LUAI_UMEM unsigned long
  182. #define LUAI_MEM long
  183. #endif
  184. /*
  185. *@ LUAI_MAXCALLS limits the number of nested calls.
  186. ** CHANGE it if you need really deep recursive calls. This limit is
  187. ** arbitrary; its only purpose is to stop infinite recursion before
  188. ** exhausting memory.
  189. */
  190. #define LUAI_MAXCALLS 20000
  191. /*
  192. *@ LUAI_MAXCSTACK limits the number of slots that a C function can use.
  193. ** CHANGE it if you need lots of (Lua) stack space for your C
  194. ** functions. This limit is arbitrary; its only purpose is to stop C
  195. ** functions to consume unlimited stack space.
  196. */
  197. #define LUAI_MAXCSTACK 2048
  198. /*
  199. ** {==================================================================
  200. ** CHANGE (to smaller values) the following definitions if your system
  201. ** has a small C stack. (Or you may want to change them to larger
  202. ** values if your system has a large C stack and these limits are
  203. ** too rigid for you.) Some of these constants control the size of
  204. ** stack-allocated arrays used by the compiler or the interpreter, while
  205. ** others limit the maximum number of recursive calls that the compiler
  206. ** or the interpreter can perform. Values too large may cause a C stack
  207. ** overflow for some forms of deep constructs.
  208. ** ===================================================================
  209. */
  210. /*
  211. *@ LUAI_MAXCCALLS is the maximum depth for nested C calls (unsigned short).
  212. */
  213. #define LUAI_MAXCCALLS 200
  214. /*
  215. *@ LUAI_MAXPARSERLEVEL is the maximum number of syntactical nested
  216. ** non-terminals in a program.
  217. */
  218. #define LUAI_MAXPARSERLEVEL 200
  219. /*
  220. *@ LUAI_MAXVARS is the maximum number of local variables per function
  221. ** (must be smaller than 250).
  222. */
  223. #define LUAI_MAXVARS 200
  224. /*
  225. *@ LUAI_MAXUPVALUES is the maximum number of upvalues per function
  226. ** (must be smaller than 250).
  227. */
  228. #define LUAI_MAXUPVALUES 60
  229. /*
  230. *@ LUAI_MAXEXPWHILE is the maximum size of code for expressions
  231. ** controling a `while' loop.
  232. */
  233. #define LUAI_MAXEXPWHILE 100
  234. /*
  235. *@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
  236. */
  237. #define LUAL_BUFFERSIZE BUFSIZ
  238. /* }================================================================== */
  239. /*
  240. *@ lua_number2int is a macro to convert lua_Number to int.
  241. ** CHANGE that if you know a faster way to convert a lua_Number to
  242. ** int (with any rounding method and without throwing errors) in your
  243. ** system. In Pentium machines, a naive typecast from doulbe to int
  244. ** in C is extremely slow, so any alternative is worth trying.
  245. */
  246. /* On a GNU/Pentium, resort to assembler */
  247. #if defined(__GNUC__) && defined(__i386)
  248. #define lua_number2int(i,d) __asm__ ("fistpl %0":"=m"(i):"t"(d):"st")
  249. /* On Windows/Pentium, resort to assembler */
  250. #elif defined(_MSC_VER) && defined(_M_IX86)
  251. #pragma warning(disable: 4514)
  252. __inline int l_lrint (double flt)
  253. { int i;
  254. _asm {
  255. fld flt
  256. fistp i
  257. };
  258. return i;
  259. }
  260. #define lua_number2int(i,d) ((i)=l_lrint((d)))
  261. /* on Pentium machines compliant with C99, you can try lrint */
  262. #elif defined (__i386) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199900L)
  263. #define lua_number2int(i,d) ((i)=lrint(d))
  264. /* this option always work, but may be slow */
  265. #else
  266. #define lua_number2int(i,d) ((i)=(int)(d))
  267. #endif
  268. /*
  269. *@ lua_number2integer is a macro to convert lua_Number to lua_Integer.
  270. ** CHANGE (see lua_number2int).
  271. */
  272. /* On a GNU or Windows/Pentium, resort to assembler */
  273. #if (defined(__GNUC__) && defined(__i386)) || \
  274. (defined(_MSC_VER) && defined(_M_IX86))
  275. #define lua_number2integer(i,n) lua_number2int((i), (n))
  276. /* this option always work, but may be slow */
  277. #else
  278. #define lua_number2integer(i,d) ((i)=(lua_Integer)(d))
  279. #endif
  280. /*
  281. ** {==================================================================
  282. ** CHANGE the following definitions only if you want to build Lua
  283. ** with a number type different from double. You may also need to
  284. ** change lua_number2int & lua_number2integer.
  285. ** ===================================================================
  286. */
  287. /*
  288. *@ LUA_NUMBER is the type of numbers in Lua.
  289. *@ LUAI_UACNUMBER is the result of an `usual argument conversion'
  290. ** over a number.
  291. */
  292. #define LUA_NUMBER double
  293. #define LUAI_UACNUMBER LUA_NUMBER
  294. /*
  295. *@ LUA_NUMBER_SCAN is the format for reading numbers.
  296. *@ LUA_NUMBER_FMT is the format for writing numbers.
  297. *@ lua_number2str converts a number to a string.
  298. *@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
  299. *@ lua_str2number converts a string to a number.
  300. */
  301. #define LUA_NUMBER_SCAN "%lf"
  302. #define LUA_NUMBER_FMT "%.14g"
  303. #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
  304. #define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
  305. #define lua_str2number(s,p) strtod((s), (p))
  306. /*
  307. *@ The luai_num* macros define the primitive operations over numbers.
  308. */
  309. #define luai_numadd(a,b) ((a)+(b))
  310. #define luai_numsub(a,b) ((a)-(b))
  311. #define luai_nummul(a,b) ((a)*(b))
  312. #define luai_numdiv(a,b) ((a)/(b))
  313. #define luai_nummod(a,b) ((a) - floor((a)/(b))*(b))
  314. #define luai_numpow(a,b) pow(a,b)
  315. #define luai_numunm(a) (-(a))
  316. #define luai_numeq(a,b) ((a)==(b))
  317. #define luai_numlt(a,b) ((a)<(b))
  318. #define luai_numle(a,b) ((a)<=(b))
  319. /* }================================================================== */
  320. /*
  321. *@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment.
  322. ** CHANGE it if your system requires alignments larger than double. (For
  323. ** instance, if your system supports long double and those long doubles
  324. ** must be aligned in 16-byte boundaries, then you should add long
  325. ** double in the union.) Probably you do not need to change this.
  326. */
  327. #define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }
  328. /*
  329. *@ LUAI_THROW/LUAI_TRY define how Lua does exception handling.
  330. ** CHANGE them if you prefer to use longjmp/setjmp even with C++. By
  331. ** default, Lua handles errors with longjmp/setjmp when compiling as C
  332. ** code and with exceptions when compiling as C++ code.
  333. */
  334. #ifndef __cplusplus
  335. /* default handling with long jumps */
  336. #define LUAI_THROW(L,c) longjmp((c)->b, 1)
  337. #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
  338. #define luai_jmpbuf jmp_buf
  339. #else
  340. /* C++ exceptions */
  341. #define LUAI_THROW(L,c) throw(c)
  342. #define LUAI_TRY(L,c,a) try { a } catch(...) \
  343. { if ((c)->status == 0) (c)->status = -1; }
  344. #define luai_jmpbuf int /* dummy variable */
  345. #endif
  346. /*
  347. *@ LUA_MAXCAPTURES is the maximum number of captures that a pattern
  348. ** can do during pattern-matching.
  349. ** CHANGE it if you need more captures. This limit is arbitrary.
  350. */
  351. #define LUA_MAXCAPTURES 32
  352. /*
  353. *@ lua_tmpnam is the function that the OS library uses to create a
  354. ** temporary name.
  355. ** CHANGE it if you have an alternative to tmpnam (which is considered
  356. ** insecure) or if you want the original tmpnam anyway. By default,
  357. ** Lua uses tmpnam except when compiled when POSIX is available, where
  358. ** it uses mkstemp.
  359. */
  360. #ifdef _POSIX_C_SOURCE
  361. #include <unistd.h>
  362. #define LUA_TMPNAMBUFSIZE 32
  363. #define lua_tmpnam(b,e) { \
  364. strcpy(b, "/tmp/lua_XXXXXX"); \
  365. e = mkstemp(b); \
  366. if (e != -1) close(e); \
  367. e = (e == -1); }
  368. #else
  369. #define LUA_TMPNAMBUFSIZE L_tmpnam
  370. #define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
  371. #endif
  372. /*
  373. *@ LUA_USE_* define which dynamic-library system Lua should use.
  374. ** CHANGE here if Lua has problems choosing the appropriate
  375. ** dynamic-library system for your platform (either Windows' DLL, Mac's
  376. ** dyld, or Unix's dlopen). If your system is some kind of Unix, there
  377. ** is a good chance that LUA_USE_DLOPEN will work for it. (You may need
  378. ** to adapt also the makefile.) If you do not want any kind of dynamic
  379. ** library, undefine all these options (or just remove these definitions).
  380. */
  381. #if defined(_WIN32)
  382. #define LUA_USE_DLL
  383. #elif defined(__APPLE__) && defined(__MACH__)
  384. #define LUA_USE_DYLD
  385. #elif defined(__linux) || defined(sun) || defined(sgi) || defined(BSD)
  386. #define LUA_USE_DLOPEN
  387. #endif
  388. /*
  389. *@ lua_lock/lua_unlock are macros for thread synchronization inside the
  390. ** Lua core. This is an attempt to simplify the implementation of a
  391. ** multithreaded version of Lua.
  392. ** CHANGE them only if you know what you are doing. all accesses to
  393. ** the global state and to global objects are synchronized. Because
  394. ** threads can read the stack of other threads (when running garbage
  395. ** collection), a thread must also synchronize any write-access to its
  396. ** own stack. Unsynchronized accesses are allowed only when reading its
  397. ** own stack, or when reading immutable fields from global objects (such
  398. ** as string values and udata values).
  399. */
  400. #define lua_lock(L) ((void) 0)
  401. #define lua_unlock(L) ((void) 0)
  402. /*
  403. *@ lua_threadyield allows a thread switch in appropriate places in the core.
  404. ** CHANGE it only if you know what you are doing. (See lua_lock.)
  405. */
  406. #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
  407. /*
  408. *@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State
  409. ** (the data goes just *before* the lua_State pointer).
  410. ** CHANGE (define) this if you really need that. This value must be
  411. ** a multiple of the maximum alignment required for your machine.
  412. */
  413. #define LUAI_EXTRASPACE 0
  414. /*
  415. *@ luai_userstateopen allows user-specific initialization on new threads.
  416. ** CHANGE it if you defined LUAI_EXTRASPACE and need to initialize that
  417. ** data whenever a new lua_State is created.
  418. */
  419. #define luai_userstateopen(L) ((void)0)
  420. /* =================================================================== */
  421. /* Local configuration */
  422. #endif