luaconf.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /*
  2. ** $Id: luaconf.h,v 1.21 2004/12/13 12:08:34 roberto Exp $
  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. ** {======================================================
  18. ** Generic configuration
  19. ** =======================================================
  20. */
  21. /* default path */
  22. #if defined(_WIN32)
  23. #define LUA_ROOT "C:\\Program Files\\Lua51"
  24. #define LUA_LDIR LUA_ROOT "\\lua"
  25. #define LUA_CDIR LUA_ROOT "\\dll"
  26. #define LUA_PATH_DEFAULT \
  27. "?.lua;" LUA_LDIR "\\?.lua;" LUA_LDIR "\\?\\init.lua"
  28. #define LUA_CPATH_DEFAULT "?.dll;" LUA_CDIR "\\?.dll"
  29. #else
  30. #define LUA_ROOT "/usr/local"
  31. #define LUA_LDIR LUA_ROOT "/share/lua/5.1"
  32. #define LUA_CDIR LUA_ROOT "/lib/lua/5.1"
  33. #define LUA_PATH_DEFAULT \
  34. "./?.lua;" LUA_LDIR "/?.lua;" LUA_LDIR "/?/init.lua"
  35. #define LUA_CPATH_DEFAULT "./?.so;" LUA_CDIR "/?.so"
  36. #endif
  37. /* type of numbers in Lua */
  38. #define LUA_NUMBER double
  39. /* formats for Lua numbers */
  40. #define LUA_NUMBER_SCAN "%lf"
  41. #define LUA_NUMBER_FMT "%.14g"
  42. /*
  43. ** type for integer functions
  44. ** on most machines, `ptrdiff_t' gives a reasonable size for integers
  45. */
  46. #define LUA_INTEGER ptrdiff_t
  47. /* mark for all API functions */
  48. #define LUA_API extern
  49. /* mark for auxlib functions */
  50. #define LUALIB_API extern
  51. /* buffer size used by lauxlib buffer system */
  52. #define LUAL_BUFFERSIZE BUFSIZ
  53. /* assertions in Lua (mainly for internal debugging) */
  54. #define lua_assert(c) ((void)0)
  55. /* }====================================================== */
  56. /*
  57. ** {======================================================
  58. ** Stand-alone configuration
  59. ** =======================================================
  60. */
  61. #ifdef lua_c
  62. /* definition of `isatty' */
  63. #ifdef _POSIX_C_SOURCE
  64. #include <unistd.h>
  65. #define stdin_is_tty() isatty(0)
  66. #elif defined(_WIN32)
  67. #include <io.h>
  68. #include <fcntl.h>
  69. #define stdin_is_tty() _isatty(_fileno(stdin))
  70. #else
  71. #define stdin_is_tty() 1 /* assume stdin is a tty */
  72. #endif
  73. #define PROMPT "> "
  74. #define PROMPT2 ">> "
  75. #define PROGNAME "lua"
  76. /*
  77. ** this macro allows you to open other libraries when starting the
  78. ** stand-alone interpreter
  79. */
  80. #define lua_userinit(L) luaopen_stdlibs(L)
  81. /*
  82. ** #define lua_userinit(L) { int luaopen_mylibs(lua_State *L); \
  83. ** luaopen_stdlibs(L); luaopen_mylibs(L); }
  84. */
  85. /*
  86. ** this macro can be used by some `history' system to save lines
  87. ** read in manual input
  88. */
  89. #define lua_saveline(L,line) /* empty */
  90. #endif
  91. /* }====================================================== */
  92. /*
  93. ** {======================================================
  94. ** Core configuration
  95. ** =======================================================
  96. */
  97. #ifdef LUA_CORE
  98. /* LUA-C API assertions */
  99. #define api_check(L,o) lua_assert(o)
  100. /* number of bits in an `int' */
  101. /* avoid overflows in comparison */
  102. #if INT_MAX-20 < 32760
  103. #define LUA_BITSINT 16
  104. #elif INT_MAX > 2147483640L
  105. /* `int' has at least 32 bits */
  106. #define LUA_BITSINT 32
  107. #else
  108. #error "you must define LUA_BITSINT with number of bits in an integer"
  109. #endif
  110. /*
  111. ** L_UINT32: unsigned integer with at least 32 bits
  112. ** L_INT32: signed integer with at least 32 bits
  113. ** LU_MEM: an unsigned integer big enough to count the total memory used by Lua
  114. ** L_MEM: a signed integer big enough to count the total memory used by Lua
  115. */
  116. #if LUA_BITSINT >= 32
  117. #define LUA_UINT32 unsigned int
  118. #define LUA_INT32 int
  119. #define LUA_MAXINT32 INT_MAX
  120. #define LU_MEM size_t
  121. #define L_MEM ptrdiff_t
  122. #else
  123. /* 16-bit ints */
  124. #define LUA_UINT32 unsigned long
  125. #define LUA_INT32 long
  126. #define LUA_MAXINT32 LONG_MAX
  127. #define LU_MEM LUA_UINT32
  128. #define L_MEM ptrdiff_t
  129. #endif
  130. /* maximum depth for calls (unsigned short) */
  131. #define LUA_MAXCALLS 10000
  132. /*
  133. ** maximum depth for C calls (unsigned short): Not too big, or may
  134. ** overflow the C stack...
  135. */
  136. #define LUA_MAXCCALLS 200
  137. /* maximum size for the virtual stack of a C function */
  138. #define MAXCSTACK 2048
  139. /*
  140. ** maximum number of syntactical nested non-terminals: Not too big,
  141. ** or may overflow the C stack...
  142. */
  143. #define LUA_MAXPARSERLEVEL 200
  144. /* maximum number of variables declared in a function */
  145. #define MAXVARS 200 /* <MAXSTACK */
  146. /* maximum number of upvalues per function */
  147. #define MAXUPVALUES 60 /* <MAXSTACK */
  148. /* maximum size of expressions for optimizing `while' code */
  149. #define MAXEXPWHILE 100
  150. /* function to convert a lua_Number to int (with any rounding method) */
  151. #if defined(__GNUC__) && defined(__i386)
  152. #define lua_number2int(i,d) __asm__ ("fistpl %0":"=m"(i):"t"(d):"st")
  153. #elif defined(_WIN32) && defined(_M_IX86)
  154. #include <math.h>
  155. #pragma warning(disable: 4514)
  156. __inline int l_lrint (double flt)
  157. { int i;
  158. _asm {
  159. fld flt
  160. fistp i
  161. };
  162. return i;
  163. }
  164. #define lua_number2int(i,d) ((i)=l_lrint((d)))
  165. #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199900L)
  166. /* on machines compliant with C99, you can try `lrint' */
  167. #include <math.h>
  168. #define lua_number2int(i,d) ((i)=lrint(d))
  169. #else
  170. #define lua_number2int(i,d) ((i)=(int)(d))
  171. #endif
  172. /* function to convert a lua_Number to lua_Integer (with any rounding method) */
  173. #define lua_number2integer(i,n) lua_number2int((i), (n))
  174. /* function to convert a lua_Number to a string */
  175. #include <stdio.h>
  176. #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
  177. /* function to convert a string to a lua_Number */
  178. #define lua_str2number(s,p) strtod((s), (p))
  179. /* result of a `usual argument conversion' over lua_Number */
  180. #define LUA_UACNUMBER double
  181. /* type to ensure maximum alignment */
  182. #define LUSER_ALIGNMENT_T union { double u; void *s; long l; }
  183. /* exception handling */
  184. #ifndef __cplusplus
  185. /* default handling with long jumps */
  186. #include <setjmp.h>
  187. #define L_THROW(L,c) longjmp((c)->b, 1)
  188. #define L_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
  189. #define l_jmpbuf jmp_buf
  190. #else
  191. /* C++ exceptions */
  192. #define L_THROW(L,c) throw(c)
  193. #define L_TRY(L,c,a) try { a } catch(...) \
  194. { if ((c)->status == 0) (c)->status = -1; }
  195. #define l_jmpbuf int /* dummy variable */
  196. #endif
  197. /*
  198. ** macros for thread synchronization inside Lua core machine:
  199. ** all accesses to the global state and to global objects are synchronized.
  200. ** Because threads can read the stack of other threads
  201. ** (when running garbage collection),
  202. ** a thread must also synchronize any write-access to its own stack.
  203. ** Unsynchronized accesses are allowed only when reading its own stack,
  204. ** or when reading immutable fields from global objects
  205. ** (such as string values and udata values).
  206. */
  207. #define lua_lock(L) ((void) 0)
  208. #define lua_unlock(L) ((void) 0)
  209. /*
  210. ** this macro allows a thread switch in appropriate places in the Lua
  211. ** core
  212. */
  213. #define lua_threadyield(L) {lua_unlock(L); lua_lock(L);}
  214. /* allows user-specific initialization on new threads */
  215. #define lua_userstateopen(L) /* empty */
  216. #endif
  217. /* }====================================================== */
  218. /*
  219. ** {======================================================
  220. ** Library configuration
  221. ** =======================================================
  222. */
  223. #ifdef LUA_LIB
  224. /* `assert' options */
  225. /* environment variables that hold the search path for packages */
  226. #define LUA_PATH "LUA_PATH"
  227. #define LUA_CPATH "LUA_CPATH"
  228. /* prefix for open functions in C libraries */
  229. #if defined(__APPLE__) && defined(__MACH__)
  230. #define LUA_POF "_luaopen_"
  231. #else
  232. #define LUA_POF "luaopen_"
  233. #endif
  234. /* separator for open functions in C libraries */
  235. #define LUA_OFSEP ""
  236. /* directory separator (for submodules) */
  237. #if defined(_WIN32)
  238. #define LUA_DIRSEP "\\"
  239. #else
  240. #define LUA_DIRSEP "/"
  241. #endif
  242. /* separator of templates in a path */
  243. #define LUA_PATH_SEP ';'
  244. /* wild char in each template */
  245. #define LUA_PATH_MARK "?"
  246. /* maximum number of captures in pattern-matching */
  247. #define MAX_CAPTURES 32 /* arbitrary limit */
  248. /*
  249. ** by default, gcc does not get `tmpname'
  250. */
  251. #ifdef __GNUC__
  252. #define USE_TMPNAME 0
  253. #else
  254. #define USE_TMPNAME 1
  255. #endif
  256. /*
  257. ** Configuration for loadlib
  258. */
  259. #if defined(_WIN32)
  260. #define USE_DLL
  261. #elif defined(__APPLE__) && defined(__MACH__)
  262. #define USE_DYLD
  263. #elif defined(__linux) || defined(sun) || defined(sgi) || defined(BSD)
  264. #define USE_DLOPEN
  265. #endif
  266. #endif
  267. /* }====================================================== */
  268. /* Local configuration */
  269. #undef USE_TMPNAME
  270. #define USE_TMPNAME 1
  271. #endif