3 ** Configuration file for Lua
4 ** See Copyright Notice in lua.h
16 ** ===================================================================
17 ** General Configuration File for Lua
19 ** Some definitions here can be changed externally, through the
20 ** compiler (e.g., with '-D' options). Those are protected by
21 ** '#if !defined' guards. However, several other definitions should
22 ** be changed directly here, either because they affect the Lua
23 ** ABI (by making the changes here, you ensure that all software
24 ** connected to Lua, such as C libraries, will be compiled with the
25 ** same configuration); or because they are seldom changed.
27 ** Search for "@@" to find all configurable definitions.
28 ** ===================================================================
33 ** {====================================================================
34 ** System Configuration: macros to adapt (if needed) Lua to some
35 ** particular platform, for instance restricting it to C89.
36 ** =====================================================================
40 @@ LUA_USE_C89 controls the use of non-ISO-C89 features.
41 ** Define it if you want Lua to avoid the use of a few C99 features
42 ** or Windows-specific features on Windows.
44 /* #define LUA_USE_C89 */
48 ** By default, Lua on Windows use (some) specific Windows features
50 #if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE)
51 #define LUA_USE_WINDOWS /* enable goodies for regular Windows */
55 #if defined(LUA_USE_WINDOWS)
56 #define LUA_DL_DLL /* enable support for DLL */
57 #define LUA_USE_C89 /* broadly, Windows is C89 */
61 #if defined(LUA_USE_LINUX)
63 #define LUA_USE_DLOPEN /* needs an extra library: -ldl */
67 #if defined(LUA_USE_MACOSX)
69 #define LUA_USE_DLOPEN /* MacOS does not need -ldl */
72 /* Local modifications: need io.popen */
76 #define LUA_USE_DLOPEN
81 @@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits.
83 #define LUAI_IS32INT ((UINT_MAX >> 30) >= 3)
85 /* }================================================================== */
90 ** {==================================================================
91 ** Configuration for Number types.
92 ** ===================================================================
96 @@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats.
98 /* #define LUA_32BITS */
102 @@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
103 ** C89 ('long' and 'double'); Windows always has '__int64', so it does
104 ** not need to use this case.
106 #if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)
107 #define LUA_C89_NUMBERS
112 @@ LUA_INT_TYPE defines the type for Lua integers.
113 @@ LUA_FLOAT_TYPE defines the type for Lua floats.
114 ** Lua should work fine with any mix of these options supported
115 ** by your C compiler. The usual configurations are 64-bit integers
116 ** and 'double' (the default), 32-bit integers and 'float' (for
117 ** restricted platforms), and 'long'/'double' (for C compilers not
118 ** compliant with C99, which may not have support for 'long long').
121 /* predefined options for LUA_INT_TYPE */
122 #define LUA_INT_INT 1
123 #define LUA_INT_LONG 2
124 #define LUA_INT_LONGLONG 3
126 /* predefined options for LUA_FLOAT_TYPE */
127 #define LUA_FLOAT_FLOAT 1
128 #define LUA_FLOAT_DOUBLE 2
129 #define LUA_FLOAT_LONGDOUBLE 3
130 #define LUA_FLOAT_INT64 4
132 #if defined(LUA_32BITS) /* { */
134 ** 32-bit integers and 'float'
136 #if LUAI_IS32INT /* use 'int' if big enough */
137 #define LUA_INT_TYPE LUA_INT_INT
138 #else /* otherwise use 'long' */
139 #define LUA_INT_TYPE LUA_INT_LONG
141 #define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT
143 #elif defined(LUA_C89_NUMBERS) /* }{ */
145 ** largest types available for C89 ('long' and 'double')
147 #define LUA_INT_TYPE LUA_INT_LONG
148 #define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
154 ** default configuration for 64-bit Lua ('long long' and 'double')
156 #if !defined(LUA_INT_TYPE)
157 #define LUA_INT_TYPE LUA_INT_LONGLONG
160 #if !defined(LUA_FLOAT_TYPE)
161 #define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
164 /* }================================================================== */
169 ** {==================================================================
170 ** Configuration for Paths.
171 ** ===================================================================
175 ** LUA_PATH_SEP is the character that separates templates in a path.
176 ** LUA_PATH_MARK is the string that marks the substitution points in a
178 ** LUA_EXEC_DIR in a Windows path is replaced by the executable's
181 #define LUA_PATH_SEP ";"
182 #define LUA_PATH_MARK "?"
183 #define LUA_EXEC_DIR "!"
187 @@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
189 @@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
191 ** CHANGE them if your machine has a non-conventional directory
192 ** hierarchy or if you want to install your libraries in
193 ** non-conventional directories.
196 #define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
197 #if defined(_WIN32) /* { */
199 ** In Windows, any exclamation mark ('!') in the path is replaced by the
200 ** path of the directory of the executable file of the current process.
202 #define LUA_LDIR "!\\lua\\"
203 #define LUA_CDIR "!\\"
204 #define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\"
206 #if !defined(LUA_PATH_DEFAULT)
207 #define LUA_PATH_DEFAULT \
208 LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
209 LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \
210 LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \
211 ".\\?.lua;" ".\\?\\init.lua"
214 #if !defined(LUA_CPATH_DEFAULT)
215 #define LUA_CPATH_DEFAULT \
217 LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \
218 LUA_CDIR"loadall.dll;" ".\\?.dll"
223 #define LUA_ROOT "/usr/"
224 #define LUA_LDIR LUA_ROOT "share/flua/"
225 #define LUA_CDIR LUA_ROOT "lib/flua/"
227 #if !defined(LUA_PATH_DEFAULT)
228 #define LUA_PATH_DEFAULT \
229 LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
230 LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \
231 "./?.lua;" "./?/init.lua"
234 #if !defined(LUA_CPATH_DEFAULT)
235 #define LUA_CPATH_DEFAULT \
236 LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
243 @@ LUA_DIRSEP is the directory separator (for submodules).
244 ** CHANGE it if your machine does not use "/" as the directory separator
245 ** and is not Windows. (On Windows Lua automatically uses "\".)
247 #if !defined(LUA_DIRSEP)
250 #define LUA_DIRSEP "\\"
252 #define LUA_DIRSEP "/"
257 /* }================================================================== */
261 ** {==================================================================
262 ** Marks for exported symbols in the C code
263 ** ===================================================================
267 @@ LUA_API is a mark for all core API functions.
268 @@ LUALIB_API is a mark for all auxiliary library functions.
269 @@ LUAMOD_API is a mark for all standard library opening functions.
270 ** CHANGE them if you need to define those functions in some special way.
271 ** For instance, if you want to create one Windows DLL with the core and
272 ** the libraries, you may want to use the following definition (define
273 ** LUA_BUILD_AS_DLL to get it).
275 #if defined(LUA_BUILD_AS_DLL) /* { */
277 #if defined(LUA_CORE) || defined(LUA_LIB) /* { */
278 #define LUA_API __declspec(dllexport)
280 #define LUA_API __declspec(dllimport)
285 #define LUA_API extern
291 ** More often than not the libs go together with the core.
293 #define LUALIB_API LUA_API
294 #define LUAMOD_API LUA_API
298 @@ LUAI_FUNC is a mark for all extern functions that are not to be
299 ** exported to outside modules.
300 @@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables,
301 ** none of which to be exported to outside modules (LUAI_DDEF for
302 ** definitions and LUAI_DDEC for declarations).
303 ** CHANGE them if you need to mark them in some special way. Elf/gcc
304 ** (versions 3.2 and later) mark them as "hidden" to optimize access
305 ** when Lua is compiled as a shared library. Not all elf targets support
306 ** this attribute. Unfortunately, gcc does not offer a way to check
307 ** whether the target offers that support, and those without support
308 ** give a warning about it. To avoid these warnings, change to the
309 ** default definition.
311 #if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
312 defined(__ELF__) /* { */
313 #define LUAI_FUNC __attribute__((visibility("internal"))) extern
315 #define LUAI_FUNC extern
318 #define LUAI_DDEC(dec) LUAI_FUNC dec
319 #define LUAI_DDEF /* empty */
321 /* }================================================================== */
325 ** {==================================================================
326 ** Compatibility with previous versions
327 ** ===================================================================
331 @@ LUA_COMPAT_5_3 controls other macros for compatibility with Lua 5.3.
332 ** You can define it to get all options, or change specific options
333 ** to fit your specific needs.
335 #if defined(LUA_COMPAT_5_3) /* { */
338 @@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
339 ** functions in the mathematical library.
340 ** (These functions were already officially removed in 5.3;
341 ** nevertheless they are still available here.)
343 #define LUA_COMPAT_MATHLIB
346 @@ LUA_COMPAT_APIINTCASTS controls the presence of macros for
347 ** manipulating other integer types (lua_pushunsigned, lua_tounsigned,
348 ** luaL_checkint, luaL_checklong, etc.)
349 ** (These macros were also officially removed in 5.3, but they are still
352 #define LUA_COMPAT_APIINTCASTS
356 @@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod
359 #define LUA_COMPAT_LT_LE
363 @@ The following macros supply trivial compatibility for some
364 ** changes in the API. The macros themselves document how to
365 ** change your code to avoid using them.
366 ** (Once more, these macros were officially removed in 5.3, but they are
367 ** still available here.)
369 #define lua_strlen(L,i) lua_rawlen(L, (i))
371 #define lua_objlen(L,i) lua_rawlen(L, (i))
373 #define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
374 #define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
378 /* }================================================================== */
383 ** {==================================================================
384 ** Configuration for Numbers.
385 ** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*
386 ** satisfy your needs.
387 ** ===================================================================
391 @@ LUA_NUMBER is the floating-point type used by Lua.
392 @@ LUAI_UACNUMBER is the result of a 'default argument promotion'
393 @@ over a floating number.
394 @@ l_floatatt(x) corrects float attribute 'x' to the proper float type
395 ** by prefixing it with one of FLT/DBL/LDBL.
396 @@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.
397 @@ LUA_NUMBER_FMT is the format for writing floats.
398 @@ lua_number2str converts a float to a string.
399 @@ l_mathop allows the addition of an 'l' or 'f' to all math operations.
400 @@ l_floor takes the floor of a float.
401 @@ lua_str2number converts a decimal numeral to a number.
405 /* The following definitions are good for most cases here */
407 #define l_floor(x) (l_mathop(floor)(x))
409 #define lua_number2str(s,sz,n) \
410 l_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n))
413 @@ lua_numbertointeger converts a float number with an integral value
414 ** to an integer, or returns 0 if float is not within the range of
415 ** a lua_Integer. (The range comparisons are tricky because of
416 ** rounding. The tests here assume a two-complement representation,
417 ** where MININTEGER always has an exact representation as a float;
418 ** MAXINTEGER may not have one, and therefore its conversion to float
419 ** may have an ill-defined value.)
421 #define lua_numbertointeger(n,p) \
422 ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \
423 (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \
424 (*(p) = (LUA_INTEGER)(n), 1))
427 /* now the variable definitions */
429 #if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */
431 #define LUA_NUMBER float
433 #define l_floatatt(n) (FLT_##n)
435 #define LUAI_UACNUMBER double
437 #define LUA_NUMBER_FRMLEN ""
438 #define LUA_NUMBER_FMT "%.7g"
440 #define l_mathop(op) op##f
442 #define lua_str2number(s,p) strtof((s), (p))
445 #elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */
447 #define LUA_NUMBER long double
449 #define l_floatatt(n) (LDBL_##n)
451 #define LUAI_UACNUMBER long double
453 #define LUA_NUMBER_FRMLEN "L"
454 #define LUA_NUMBER_FMT "%.19Lg"
456 #define l_mathop(op) op##l
458 #define lua_str2number(s,p) strtold((s), (p))
460 #elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */
462 #define LUA_NUMBER double
464 #define l_floatatt(n) (DBL_##n)
466 #define LUAI_UACNUMBER double
468 #define LUA_NUMBER_FRMLEN ""
469 #define LUA_NUMBER_FMT "%.14g"
471 #define l_mathop(op) op
473 #define lua_str2number(s,p) strtod((s), (p))
477 #error "numeric float type not defined"
484 @@ LUA_INTEGER is the integer type used by Lua.
486 @@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.
488 @@ LUAI_UACINT is the result of a 'default argument promotion'
489 @@ over a LUA_INTEGER.
490 @@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.
491 @@ LUA_INTEGER_FMT is the format for writing integers.
492 @@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.
493 @@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.
494 @@ LUA_MAXUNSIGNED is the maximum value for a LUA_UNSIGNED.
495 @@ LUA_UNSIGNEDBITS is the number of bits in a LUA_UNSIGNED.
496 @@ lua_integer2str converts an integer to a string.
500 /* The following definitions are good for most cases here */
502 #define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d"
504 #define LUAI_UACINT LUA_INTEGER
506 #define lua_integer2str(s,sz,n) \
507 l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n))
510 ** use LUAI_UACINT here to avoid problems with promotions (which
511 ** can turn a comparison between unsigneds into a signed comparison)
513 #define LUA_UNSIGNED unsigned LUAI_UACINT
516 #define LUA_UNSIGNEDBITS (sizeof(LUA_UNSIGNED) * CHAR_BIT)
519 /* now the variable definitions */
521 #if LUA_INT_TYPE == LUA_INT_INT /* { int */
523 #define LUA_INTEGER int
524 #define LUA_INTEGER_FRMLEN ""
526 #define LUA_MAXINTEGER INT_MAX
527 #define LUA_MININTEGER INT_MIN
529 #define LUA_MAXUNSIGNED UINT_MAX
531 #elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */
533 #define LUA_INTEGER long
534 #define LUA_INTEGER_FRMLEN "l"
536 #define LUA_MAXINTEGER LONG_MAX
537 #define LUA_MININTEGER LONG_MIN
539 #define LUA_MAXUNSIGNED ULONG_MAX
541 #elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */
543 /* use presence of macro LLONG_MAX as proxy for C99 compliance */
544 #if defined(LLONG_MAX) /* { */
545 /* use ISO C99 stuff */
547 #define LUA_INTEGER long long
548 #define LUA_INTEGER_FRMLEN "ll"
550 #define LUA_MAXINTEGER LLONG_MAX
551 #define LUA_MININTEGER LLONG_MIN
553 #define LUA_MAXUNSIGNED ULLONG_MAX
555 #elif defined(LUA_USE_WINDOWS) /* }{ */
556 /* in Windows, can use specific Windows types */
558 #define LUA_INTEGER __int64
559 #define LUA_INTEGER_FRMLEN "I64"
561 #define LUA_MAXINTEGER _I64_MAX
562 #define LUA_MININTEGER _I64_MIN
564 #define LUA_MAXUNSIGNED _UI64_MAX
568 #error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \
569 or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)"
575 #error "numeric integer type not defined"
579 /* }================================================================== */
583 ** {==================================================================
584 ** Dependencies with C99 and other C details
585 ** ===================================================================
589 @@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.
590 ** (All uses in Lua have only one format item.)
592 #if !defined(LUA_USE_C89)
593 #define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i)
595 #define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i))
600 @@ lua_strx2number converts a hexadecimal numeral to a number.
601 ** In C99, 'strtod' does that conversion. Otherwise, you can
602 ** leave 'lua_strx2number' undefined and Lua will provide its own
605 #if !defined(LUA_USE_C89)
606 #define lua_strx2number(s,p) lua_str2number(s,p)
611 @@ lua_pointer2str converts a pointer to a readable string in a
612 ** non-specified way.
614 #define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p)
618 @@ lua_number2strx converts a float to a hexadecimal numeral.
619 ** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.
620 ** Otherwise, you can leave 'lua_number2strx' undefined and Lua will
621 ** provide its own implementation.
623 #if !defined(LUA_USE_C89)
624 #define lua_number2strx(L,b,sz,f,n) \
625 ((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n)))
630 ** 'strtof' and 'opf' variants for math functions are not valid in
631 ** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the
632 ** availability of these variants. ('math.h' is already included in
633 ** all files that use these macros.)
635 #if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF))
636 #undef l_mathop /* variants not available */
637 #undef lua_str2number
638 #define l_mathop(op) (lua_Number)op /* no variant */
639 #define lua_str2number(s,p) ((lua_Number)strtod((s), (p)))
644 @@ LUA_KCONTEXT is the type of the context ('ctx') for continuation
645 ** functions. It must be a numerical type; Lua will use 'intptr_t' if
646 ** available, otherwise it will use 'ptrdiff_t' (the nearest thing to
647 ** 'intptr_t' in C89)
649 #define LUA_KCONTEXT ptrdiff_t
651 #if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \
652 __STDC_VERSION__ >= 199901L
654 #if defined(INTPTR_MAX) /* even in C99 this type is optional */
656 #define LUA_KCONTEXT intptr_t
662 @@ lua_getlocaledecpoint gets the locale "radix character" (decimal point).
663 ** Change that if you do not want to use C locales. (Code using this
664 ** macro must include the header 'locale.h'.)
666 #if !defined(lua_getlocaledecpoint)
667 #define lua_getlocaledecpoint() (localeconv()->decimal_point[0])
670 /* }================================================================== */
674 ** {==================================================================
675 ** Language Variations
676 ** =====================================================================
680 @@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some
681 ** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from
682 ** numbers to strings. Define LUA_NOCVTS2N to turn off automatic
683 ** coercion from strings to numbers.
685 /* #define LUA_NOCVTN2S */
686 /* #define LUA_NOCVTS2N */
690 @@ LUA_USE_APICHECK turns on several consistency checks on the C API.
691 ** Define it as a help when debugging C code.
693 #if defined(LUA_USE_APICHECK)
695 #define luai_apicheck(l,e) assert(e)
698 /* }================================================================== */
702 ** {==================================================================
703 ** Macros that affect the API and must be stable (that is, must be the
704 ** same when you compile Lua and when you compile code that links to
706 ** =====================================================================
710 @@ LUAI_MAXSTACK limits the size of the Lua stack.
711 ** CHANGE it if you need a different limit. This limit is arbitrary;
712 ** its only purpose is to stop Lua from consuming unlimited stack
713 ** space (and to reserve some numbers for pseudo-indices).
714 ** (It must fit into max(size_t)/32.)
717 #define LUAI_MAXSTACK 1000000
719 #define LUAI_MAXSTACK 15000
724 @@ LUA_EXTRASPACE defines the size of a raw memory area associated with
725 ** a Lua state with very fast access.
726 ** CHANGE it if you need a different size.
728 #define LUA_EXTRASPACE (sizeof(void *))
732 @@ LUA_IDSIZE gives the maximum size for the description of the source
733 @@ of a function in debug information.
734 ** CHANGE it if you want a different size.
736 #define LUA_IDSIZE 60
740 @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
742 #define LUAL_BUFFERSIZE ((int)(16 * sizeof(void*) * sizeof(lua_Number)))
746 @@ LUAI_MAXALIGN defines fields that, when used in a union, ensure
747 ** maximum alignment for the other items in that union.
749 #define LUAI_MAXALIGN lua_Number n; double u; void *s; lua_Integer i; long l
751 /* }================================================================== */
757 /* =================================================================== */
760 ** Local configuration. You can use this space to add your redefinitions
761 ** without modifying the main part of the file.