2 ** $Id: luaconf_internal.h,v ... $
3 ** Configuration file for Lua (internal)
4 ** See Copyright Notice in lua.h
8 #ifndef lconfig_internal_h
9 #define lconfig_internal_h
16 ** ==================================================================
17 ** Search for "@@" to find all configurable definitions.
18 ** ===================================================================
23 @@ LUA_ANSI controls the use of non-ansi features.
24 ** CHANGE it (define it) if you want Lua to avoid the use of any
25 ** non-ansi feature or library.
27 #if defined(__STRICT_ANSI__)
32 #if !defined(LUA_ANSI) && defined(_WIN32)
36 #if defined(LUA_USE_LINUX)
38 #define LUA_USE_DLOPEN /* needs an extra library: -ldl */
39 #define LUA_USE_READLINE /* needs some extra libraries */
42 #if defined(LUA_USE_MACOSX)
44 #define LUA_DL_DYLD /* does not need extra library */
50 @@ LUA_USE_POSIX includes all functionallity listed as X/Open System
51 @* Interfaces Extension (XSI).
52 ** CHANGE it (define it) if your system is XSI compatible.
54 #if defined(LUA_USE_POSIX)
55 #define LUA_USE_MKSTEMP
56 #define LUA_USE_ISATTY
58 #define LUA_USE_ULONGJMP
63 @@ LUA_DIRSEP is the directory separator (for submodules).
64 ** CHANGE it if your machine does not use "/" as the directory separator
65 ** and is not Windows. (On Windows Lua automatically uses "\".)
68 #define LUA_DIRSEP "\\"
70 #define LUA_DIRSEP "/"
75 @@ LUA_PATHSEP is the character that separates templates in a path.
76 @@ LUA_PATH_MARK is the string that marks the substitution points in a
78 @@ LUA_EXECDIR in a Windows path is replaced by the executable's
80 @@ LUA_IGMARK is a mark to ignore all before it when bulding the
81 @* luaopen_ function name.
82 ** CHANGE them if for some reason your system cannot use those
83 ** characters. (E.g., if one of those characters is a common character
84 ** in file/directory names.) Probably you do not need to change them.
86 #define LUA_PATHSEP ";"
87 #define LUA_PATH_MARK "?"
88 #define LUA_EXECDIR "!"
89 #define LUA_IGMARK "-"
93 ** Default number mode
95 #if (!defined LNUM_DOUBLE) && (!defined LNUM_FLOAT) && (!defined LNUM_LDOUBLE)
100 ** Require C99 mode for COMPLEX, FLOAT and LDOUBLE (only DOUBLE is ANSI C).
102 #if defined(LNUM_COMPLEX) && (__STDC_VERSION__ < 199901L)
103 # error "Need C99 for complex (use '--std=c99' or similar)"
104 #elif defined(LNUM_LDOUBLE) && (__STDC_VERSION__ < 199901L) && !defined(_MSC_VER)
105 # error "Need C99 for 'long double' (use '--std=c99' or similar)"
106 #elif defined(LNUM_FLOAT) && (__STDC_VERSION__ < 199901L)
107 /* LNUM_FLOAT not supported on Windows */
108 # error "Need C99 for 'float' (use '--std=c99' or similar)"
112 ** COMPLEX mode currently only with integer optimization
114 #if defined(LNUM_COMPLEX) && !(defined(LNUM_INT32) || defined(LNUM_INT64))
115 # error "LNUM_COMPLEX needs to be used together with LNUM_INTxx"
119 ** Number mode identifier to accompany the version string.
122 # define _LNUM1 "complex "
127 # define _LNUM2 "double"
128 #elif defined(LNUM_FLOAT)
129 # define _LNUM2 "float"
130 #elif defined(LNUM_LDOUBLE)
131 # define _LNUM2 "ldouble"
134 # define _LNUM3 " int32"
135 #elif defined(LNUM_INT64)
136 # define _LNUM3 " int64"
141 # define _LNUM4 "fastmath"
145 #define LUA_LNUM _LNUM1 _LNUM2 _LNUM3 _LNUM4
149 ** LUAI_MAXNUMBER2STR: size of a buffer fitting any number->string result.
151 ** double: 24 (sign, x.xxxxxxxxxxxxxxe+nnnn, and \0)
152 ** int64: 21 (19 digits, sign, and \0)
153 ** long double: 43 for 128-bit (sign, x.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxe+nnnn, and \0)
154 ** 30 for 80-bit (sign, x.xxxxxxxxxxxxxxxxxxxxe+nnnn, and \0)
157 # define _LUAI_MN2S 44
159 # define _LUAI_MN2S 24
163 # define LUAI_MAXNUMBER2STR (2*_LUAI_MN2S)
165 # define LUAI_MAXNUMBER2STR _LUAI_MN2S
169 @@ lua_number2int is a macro to convert lua_Number to int.
170 @@ lua_number2integer is a macro to convert lua_Number to lua_Integer.
171 ** CHANGE them if you know a faster way to convert a lua_Number to
172 ** int (with any rounding method and without throwing errors) in your
173 ** system. In Pentium machines, a naive typecast from double to int
174 ** in C is extremely slow, so any alternative is worth trying.
176 ** Note: Using '-msse' or '-msse3' is highly recommended for newer x86
177 ** processors. They have fast instructions to bypass the Pentium FP->int
178 ** efficiency problem altogether. --AKa 6-Apr-2009
181 /* On old Pentium (SSE not enabled), resort to a trick */
182 #if defined(LNUM_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \
183 (defined(__i386) || defined (_M_IX86) || defined(__i386__))
185 /* On a Microsoft compiler, use assembler */
186 # if defined(_MSC_VER)
187 # define lua_number2int(i,d) __asm fld d __asm fistp i
190 /* the next trick should work on any Pentium, but sometimes clashes
191 with a DirectX idiosyncrasy */
192 union luai_Cast { double l_d; long l_l; };
193 # define lua_number2int(i,d) \
194 { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
198 # define lua_number2integer lua_number2int
201 /* this option always works (and is fast on most platforms) */
203 # define lua_number2int(i,d) ((i)=(int)(d))
206 /* Note: Some compilers (OS X gcc 4.0?) may choke on double->long long conversion
207 * since it can lose precision. Others do require 'long long' there.
209 #ifndef lua_number2integer
210 # define lua_number2integer(i,d) ((i)=(lua_Integer)(d))
214 ** 'luai_abs()' to give absolute value of 'lua_Integer'
217 # if (__STDC_VERSION__ >= 199901L)
218 # define luai_abs llabs
220 # define luai_abs(v) ((v) >= 0 ? (v) : -(v))
223 # define luai_abs abs
227 ** LUAI_UACNUMBER is the result of an 'usual argument conversion' over a number.
228 ** LUAI_UACINTEGER the same, over an integer.
230 #define LUAI_UACNUMBER double
231 #define LUAI_UACINTEGER long
233 /* ANSI C only has math funcs for 'double. C99 required for float and long double
237 # define _LF(name) name
238 #elif defined(LNUM_FLOAT)
239 # define _LF(name) name ## f
240 #elif defined(LNUM_LDOUBLE)
241 # define _LF(name) name ## l
246 @@ LUAI_FUNC is a mark for all extern functions that are not to be
247 @* exported to outside modules.
248 @@ LUAI_DATA is a mark for all extern (const) variables that are not to
249 @* be exported to outside modules.
250 ** CHANGE them if you need to mark them in some special way. Elf/gcc
251 ** (versions 3.2 and later) mark them as "hidden" to optimize access
252 ** when Lua is compiled as a shared library.
254 #if defined(luaall_c)
255 #define LUAI_FUNC static
256 #define LUAI_DATA /* empty */
258 #elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
260 #define LUAI_FUNC __attribute__((visibility("hidden"))) extern
261 #define LUAI_DATA LUAI_FUNC
264 #define LUAI_FUNC extern
265 #define LUAI_DATA extern
271 @@ LUA_QL describes how error messages quote program elements.
272 ** CHANGE it if you want a different appearance.
274 #define LUA_QL(x) "'" x "'"
275 #define LUA_QS LUA_QL("%s")
279 ** {==================================================================
280 ** Stand-alone configuration
281 ** ===================================================================
284 #if defined(lua_c) || defined(luaall_c)
287 @@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that
288 @* is, whether we're running lua interactively).
289 ** CHANGE it if you have a better definition for non-POSIX/non-Windows
292 #if defined(LUA_USE_ISATTY)
294 #define lua_stdin_is_tty() isatty(0)
295 #elif defined(LUA_WIN)
298 #define lua_stdin_is_tty() _isatty(_fileno(stdin))
300 #define lua_stdin_is_tty() 1 /* assume stdin is a tty */
305 @@ LUA_PROMPT is the default prompt used by stand-alone Lua.
306 @@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.
307 ** CHANGE them if you want different prompts. (You can also change the
308 ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
310 #define LUA_PROMPT "> "
311 #define LUA_PROMPT2 ">> "
315 @@ LUA_PROGNAME is the default name for the stand-alone Lua program.
316 ** CHANGE it if your stand-alone interpreter has a different name and
317 ** your system is not able to detect that name automatically.
319 #define LUA_PROGNAME "lua"
323 @@ LUA_MAXINPUT is the maximum length for an input line in the
324 @* stand-alone interpreter.
325 ** CHANGE it if you need longer lines.
327 #define LUA_MAXINPUT 512
331 @@ lua_readline defines how to show a prompt and then read a line from
332 @* the standard input.
333 @@ lua_saveline defines how to "save" a read line in a "history".
334 @@ lua_freeline defines how to free a line read by lua_readline.
335 ** CHANGE them if you want to improve this functionality (e.g., by using
336 ** GNU readline and history facilities).
338 #if defined(LUA_USE_READLINE)
340 #include <readline/readline.h>
341 #include <readline/history.h>
342 #define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
343 #define lua_saveline(L,idx) \
344 if (lua_strlen(L,idx) > 0) /* non-empty line? */ \
345 add_history(lua_tostring(L, idx)); /* add it to history */
346 #define lua_freeline(L,b) ((void)L, free(b))
348 #define lua_readline(L,b,p) \
349 ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
350 fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
351 #define lua_saveline(L,idx) { (void)L; (void)idx; }
352 #define lua_freeline(L,b) { (void)L; (void)b; }
357 /* }================================================================== */
361 @@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles
363 ** CHANGE it if you want the GC to run faster or slower (higher values
364 ** mean larger pauses which mean slower collection.) You can also change
365 ** this value dynamically.
367 #define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */
371 @@ LUAI_GCMUL defines the default speed of garbage collection relative to
372 @* memory allocation as a percentage.
373 ** CHANGE it if you want to change the granularity of the garbage
374 ** collection. (Higher values mean coarser collections. 0 represents
375 ** infinity, where each step performs a full collection.) You can also
376 ** change this value dynamically.
378 #define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */
382 @@ luai_apicheck is the assert macro used by the Lua-C API.
383 ** CHANGE luai_apicheck if you want Lua to perform some checks in the
384 ** parameters it gets from API calls. This may slow down the interpreter
385 ** a bit, but may be quite useful when debugging C code that interfaces
386 ** with Lua. A useful redefinition is to use assert.h.
388 #if defined(LUA_USE_APICHECK)
390 #define luai_apicheck(L,o) { (void)L; assert(o); }
392 #define luai_apicheck(L,o) { (void)L; }
397 @@ LUAI_UINT32 is an unsigned integer with at least 32 bits.
398 @@ LUAI_INT32 is an signed integer with at least 32 bits.
399 @@ LUAI_UMEM is an unsigned integer big enough to count the total
400 @* memory used by Lua.
401 @@ LUAI_MEM is a signed integer big enough to count the total memory
403 ** CHANGE here if for some weird reason the default definitions are not
404 ** good enough for your machine. (The definitions in the 'else'
405 ** part always works, but may waste space on machines with 64-bit
406 ** longs.) Probably you do not need to change this.
408 #if LUAI_BITSINT >= 32
409 #define LUAI_UINT32 unsigned int
410 #define LUAI_INT32 int
411 #define LUAI_MAXINT32 INT_MAX
412 #define LUAI_UMEM size_t
413 #define LUAI_MEM ptrdiff_t
416 #define LUAI_UINT32 unsigned long
417 #define LUAI_INT32 long
418 #define LUAI_MAXINT32 LONG_MAX
419 #define LUAI_UMEM unsigned long
420 #define LUAI_MEM long
424 @@ LUAI_MAXCALLS limits the number of nested calls.
425 ** CHANGE it if you need really deep recursive calls. This limit is
426 ** arbitrary; its only purpose is to stop infinite recursion before
427 ** exhausting memory.
429 #define LUAI_MAXCALLS 20000
433 @@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function
435 ** CHANGE it if you need lots of (Lua) stack space for your C
436 ** functions. This limit is arbitrary; its only purpose is to stop C
437 ** functions to consume unlimited stack space. (must be smaller than
438 ** -LUA_REGISTRYINDEX)
440 #define LUAI_MAXCSTACK 8000
445 ** {==================================================================
446 ** CHANGE (to smaller values) the following definitions if your system
447 ** has a small C stack. (Or you may want to change them to larger
448 ** values if your system has a large C stack and these limits are
449 ** too rigid for you.) Some of these constants control the size of
450 ** stack-allocated arrays used by the compiler or the interpreter, while
451 ** others limit the maximum number of recursive calls that the compiler
452 ** or the interpreter can perform. Values too large may cause a C stack
453 ** overflow for some forms of deep constructs.
454 ** ===================================================================
459 @@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and
460 @* syntactical nested non-terminals in a program.
462 #define LUAI_MAXCCALLS 200
466 @@ LUAI_MAXVARS is the maximum number of local variables per function
467 @* (must be smaller than 250).
469 #define LUAI_MAXVARS 200
473 @@ LUAI_MAXUPVALUES is the maximum number of upvalues per function
474 @* (must be smaller than 250).
476 #define LUAI_MAXUPVALUES 60
479 /* }================================================================== */
483 @@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment.
485 #define LUAI_USER_ALIGNMENT_T union { LUA_NUMBER u; void *s; long l; }
489 @@ LUAI_THROW/LUAI_TRY define how Lua does exception handling.
490 ** CHANGE them if you prefer to use longjmp/setjmp even with C++
491 ** or if want/don't to use _longjmp/_setjmp instead of regular
492 ** longjmp/setjmp. By default, Lua handles errors with exceptions when
493 ** compiling as C++ code, with _longjmp/_setjmp when asked to use them,
494 ** and with longjmp/setjmp otherwise.
496 #if defined(__cplusplus)
498 #define LUAI_THROW(L,c) throw(c)
499 #define LUAI_TRY(L,c,a) try { a } catch(...) \
500 { if ((c)->status == 0) (c)->status = -1; }
501 #define luai_jmpbuf int /* dummy variable */
503 #elif defined(LUA_USE_ULONGJMP)
504 /* in Unix, try _longjmp/_setjmp (more efficient) */
505 #define LUAI_THROW(L,c) _longjmp((c)->b, 1)
506 #define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
507 #define luai_jmpbuf jmp_buf
510 /* default handling with long jumps */
511 #define LUAI_THROW(L,c) longjmp((c)->b, 1)
512 #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
513 #define luai_jmpbuf jmp_buf
519 @@ LUA_MAXCAPTURES is the maximum number of captures that a pattern
520 @* can do during pattern-matching.
521 ** CHANGE it if you need more captures. This limit is arbitrary.
523 #define LUA_MAXCAPTURES 32
527 @@ lua_tmpnam is the function that the OS library uses to create a
529 @@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam.
530 ** CHANGE them if you have an alternative to tmpnam (which is considered
531 ** insecure) or if you want the original tmpnam anyway. By default, Lua
532 ** uses tmpnam except when POSIX is available, where it uses mkstemp.
534 #if defined(loslib_c) || defined(luaall_c)
536 #if defined(LUA_USE_MKSTEMP)
538 #define LUA_TMPNAMBUFSIZE 32
539 #define lua_tmpnam(b,e) { \
540 strcpy(b, "/tmp/lua_XXXXXX"); \
542 if (e != -1) close(e); \
546 #define LUA_TMPNAMBUFSIZE L_tmpnam
547 #define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
554 @@ lua_popen spawns a new process connected to the current one through
556 ** CHANGE it if you have a way to implement it in your system.
558 #if defined(LUA_USE_POPEN)
560 #define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
561 #define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
563 #elif defined(LUA_WIN)
565 #define lua_popen(L,c,m) ((void)L, _popen(c,m))
566 #define lua_pclose(L,file) ((void)L, (_pclose(file) != -1))
570 #define lua_popen(L,c,m) ((void)((void)c, m), \
571 luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
572 #define lua_pclose(L,file) ((void)((void)L, file), 0)
577 @@ LUA_DL_* define which dynamic-library system Lua should use.
578 ** CHANGE here if Lua has problems choosing the appropriate
579 ** dynamic-library system for your platform (either Windows' DLL, Mac's
580 ** dyld, or Unix's dlopen). If your system is some kind of Unix, there
581 ** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for
582 ** it. To use dlopen you also need to adapt the src/Makefile (probably
583 ** adding -ldl to the linker options), so Lua does not select it
584 ** automatically. (When you change the makefile to add -ldl, you must
585 ** also add -DLUA_USE_DLOPEN.)
586 ** If you do not want any kind of dynamic library, undefine all these
588 ** By default, _WIN32 gets LUA_DL_DLL and Mac OS X gets LUA_DL_DYLD.
590 #if defined(LUA_USE_DLOPEN)
591 #define LUA_DL_DLOPEN
600 @@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State
601 @* (the data goes just *before* the lua_State pointer).
602 ** CHANGE (define) this if you really need that. This value must be
603 ** a multiple of the maximum alignment required for your machine.
605 #define LUAI_EXTRASPACE 0
609 @@ luai_userstate* allow user-specific actions on threads.
610 ** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
611 ** extra when a thread is created/deleted/resumed/yielded.
613 #define luai_userstateopen(L) ((void)L)
614 #define luai_userstateclose(L) ((void)L)
615 #define luai_userstatethread(L,L1) ((void)L)
616 #define luai_userstatefree(L) ((void)L)
617 #define luai_userstateresume(L,n) ((void)L)
618 #define luai_userstateyield(L,n) ((void)L)
621 /* =================================================================== */
624 ** Local configuration. You can use this space to add your redefinitions
625 ** without modifying the main part of the file.