/*1** $Id: luaconf.h $2** Configuration file for Lua3** See Copyright Notice in lua.h4*/567#ifndef luaconf_h8#define luaconf_h910#include <limits.h>11#include <stddef.h>121314/*15** ===================================================================16** General Configuration File for Lua17**18** Some definitions here can be changed externally, through the19** compiler (e.g., with '-D' options). Those are protected by20** '#if !defined' guards. However, several other definitions should21** be changed directly here, either because they affect the Lua22** ABI (by making the changes here, you ensure that all software23** connected to Lua, such as C libraries, will be compiled with the24** same configuration); or because they are seldom changed.25**26** Search for "@@" to find all configurable definitions.27** ===================================================================28*/293031/*32** {====================================================================33** System Configuration: macros to adapt (if needed) Lua to some34** particular platform, for instance restricting it to C89.35** =====================================================================36*/3738/*39@@ LUA_USE_C89 controls the use of non-ISO-C89 features.40** Define it if you want Lua to avoid the use of a few C99 features41** or Windows-specific features on Windows.42*/43/* #define LUA_USE_C89 */444546/*47** By default, Lua on Windows use (some) specific Windows features48*/49#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE)50#define LUA_USE_WINDOWS /* enable goodies for regular Windows */51#endif525354#if defined(LUA_USE_WINDOWS)55#define LUA_DL_DLL /* enable support for DLL */56#define LUA_USE_C89 /* broadly, Windows is C89 */57#endif585960#if defined(LUA_USE_LINUX)61#define LUA_USE_POSIX62#define LUA_USE_DLOPEN /* needs an extra library: -ldl */63#endif646566#if defined(LUA_USE_MACOSX)67#define LUA_USE_POSIX68#define LUA_USE_DLOPEN /* MacOS does not need -ldl */69#endif707172/*73@@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits.74*/75#define LUAI_IS32INT ((UINT_MAX >> 30) >= 3)7677/* }================================================================== */78798081/*82** {==================================================================83** Configuration for Number types.84** ===================================================================85*/8687/*88@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats.89*/90/* #define LUA_32BITS */919293/*94@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for95** C89 ('long' and 'double'); Windows always has '__int64', so it does96** not need to use this case.97*/98#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)99#define LUA_C89_NUMBERS100#endif101102103/*104@@ LUA_INT_TYPE defines the type for Lua integers.105@@ LUA_FLOAT_TYPE defines the type for Lua floats.106** Lua should work fine with any mix of these options supported107** by your C compiler. The usual configurations are 64-bit integers108** and 'double' (the default), 32-bit integers and 'float' (for109** restricted platforms), and 'long'/'double' (for C compilers not110** compliant with C99, which may not have support for 'long long').111*/112113/* predefined options for LUA_INT_TYPE */114#define LUA_INT_INT 1115#define LUA_INT_LONG 2116#define LUA_INT_LONGLONG 3117118/* predefined options for LUA_FLOAT_TYPE */119#define LUA_FLOAT_FLOAT 1120#define LUA_FLOAT_DOUBLE 2121#define LUA_FLOAT_LONGDOUBLE 3122#define LUA_FLOAT_INT64 4123124#if defined(LUA_32BITS) /* { */125/*126** 32-bit integers and 'float'127*/128#if LUAI_IS32INT /* use 'int' if big enough */129#define LUA_INT_TYPE LUA_INT_INT130#else /* otherwise use 'long' */131#define LUA_INT_TYPE LUA_INT_LONG132#endif133#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT134135#elif defined(LUA_C89_NUMBERS) /* }{ */136/*137** largest types available for C89 ('long' and 'double')138*/139#define LUA_INT_TYPE LUA_INT_LONG140#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE141142#endif /* } */143144145/*146** default configuration for 64-bit Lua ('long long' and 'double')147*/148#if !defined(LUA_INT_TYPE)149#define LUA_INT_TYPE LUA_INT_LONGLONG150#endif151152#if !defined(LUA_FLOAT_TYPE)153#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE154#endif155156/* }================================================================== */157158159160/*161** {==================================================================162** Configuration for Paths.163** ===================================================================164*/165166/*167** LUA_PATH_SEP is the character that separates templates in a path.168** LUA_PATH_MARK is the string that marks the substitution points in a169** template.170** LUA_EXEC_DIR in a Windows path is replaced by the executable's171** directory.172*/173#define LUA_PATH_SEP ";"174#define LUA_PATH_MARK "?"175#define LUA_EXEC_DIR "!"176177178/*179@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for180** Lua libraries.181@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for182** C libraries.183** CHANGE them if your machine has a non-conventional directory184** hierarchy or if you want to install your libraries in185** non-conventional directories.186*/187188#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR189#if defined(_WIN32) /* { */190/*191** In Windows, any exclamation mark ('!') in the path is replaced by the192** path of the directory of the executable file of the current process.193*/194#define LUA_LDIR "!\\lua\\"195#define LUA_CDIR "!\\"196#define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\"197198#if !defined(LUA_PATH_DEFAULT)199#define LUA_PATH_DEFAULT \200LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \201LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \202LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \203".\\?.lua;" ".\\?\\init.lua"204#endif205206#if !defined(LUA_CPATH_DEFAULT)207#define LUA_CPATH_DEFAULT \208LUA_CDIR"?.dll;" \209LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \210LUA_CDIR"loadall.dll;" ".\\?.dll"211#endif212213#else /* }{ */214215#define LUA_ROOT LUA_PATH "/" LUA_VDIR "/"216#define LUA_LDIR LUA_ROOT "share/"217#define LUA_CDIR LUA_ROOT "lib/"218219#if !defined(LUA_PATH_DEFAULT)220#define LUA_PATH_DEFAULT \221LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \222LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \223"./?.lua;" "./?/init.lua"224#endif225226#if !defined(LUA_CPATH_DEFAULT)227#define LUA_CPATH_DEFAULT \228LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"229#endif230231#endif /* } */232233234/*235@@ LUA_DIRSEP is the directory separator (for submodules).236** CHANGE it if your machine does not use "/" as the directory separator237** and is not Windows. (On Windows Lua automatically uses "\".)238*/239#if !defined(LUA_DIRSEP)240241#if defined(_WIN32)242#define LUA_DIRSEP "\\"243#else244#define LUA_DIRSEP "/"245#endif246247#endif248249/* }================================================================== */250251252/*253** {==================================================================254** Marks for exported symbols in the C code255** ===================================================================256*/257258/*259@@ LUA_API is a mark for all core API functions.260@@ LUALIB_API is a mark for all auxiliary library functions.261@@ LUAMOD_API is a mark for all standard library opening functions.262** CHANGE them if you need to define those functions in some special way.263** For instance, if you want to create one Windows DLL with the core and264** the libraries, you may want to use the following definition (define265** LUA_BUILD_AS_DLL to get it).266*/267#if defined(LUA_BUILD_AS_DLL) /* { */268269#if defined(LUA_CORE) || defined(LUA_LIB) /* { */270#define LUA_API __declspec(dllexport)271#else /* }{ */272#define LUA_API __declspec(dllimport)273#endif /* } */274275#else /* }{ */276277#define LUA_API extern278279#endif /* } */280281282/*283** More often than not the libs go together with the core.284*/285#define LUALIB_API LUA_API286#define LUAMOD_API LUA_API287288289/*290@@ LUAI_FUNC is a mark for all extern functions that are not to be291** exported to outside modules.292@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables,293** none of which to be exported to outside modules (LUAI_DDEF for294** definitions and LUAI_DDEC for declarations).295** CHANGE them if you need to mark them in some special way. Elf/gcc296** (versions 3.2 and later) mark them as "hidden" to optimize access297** when Lua is compiled as a shared library. Not all elf targets support298** this attribute. Unfortunately, gcc does not offer a way to check299** whether the target offers that support, and those without support300** give a warning about it. To avoid these warnings, change to the301** default definition.302*/303#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \304defined(__ELF__) /* { */305#define LUAI_FUNC __attribute__((visibility("internal"))) extern306#else /* }{ */307#define LUAI_FUNC extern308#endif /* } */309310#define LUAI_DDEC(dec) LUAI_FUNC dec311#define LUAI_DDEF /* empty */312313/* }================================================================== */314315316/*317** {==================================================================318** Compatibility with previous versions319** ===================================================================320*/321322/*323@@ LUA_COMPAT_5_3 controls other macros for compatibility with Lua 5.3.324** You can define it to get all options, or change specific options325** to fit your specific needs.326*/327#if defined(LUA_COMPAT_5_3) /* { */328329/*330@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated331** functions in the mathematical library.332** (These functions were already officially removed in 5.3;333** nevertheless they are still available here.)334*/335#define LUA_COMPAT_MATHLIB336337/*338@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for339** manipulating other integer types (lua_pushunsigned, lua_tounsigned,340** luaL_checkint, luaL_checklong, etc.)341** (These macros were also officially removed in 5.3, but they are still342** available here.)343*/344#define LUA_COMPAT_APIINTCASTS345346347/*348@@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod349** using '__lt'.350*/351#define LUA_COMPAT_LT_LE352353354/*355@@ The following macros supply trivial compatibility for some356** changes in the API. The macros themselves document how to357** change your code to avoid using them.358** (Once more, these macros were officially removed in 5.3, but they are359** still available here.)360*/361#define lua_strlen(L,i) lua_rawlen(L, (i))362363#define lua_objlen(L,i) lua_rawlen(L, (i))364365#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)366#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)367368#endif /* } */369370/* }================================================================== */371372373374/*375** {==================================================================376** Configuration for Numbers.377** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*378** satisfy your needs.379** ===================================================================380*/381382/*383@@ LUA_NUMBER is the floating-point type used by Lua.384@@ LUAI_UACNUMBER is the result of a 'default argument promotion'385@@ over a floating number.386@@ l_floatatt(x) corrects float attribute 'x' to the proper float type387** by prefixing it with one of FLT/DBL/LDBL.388@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.389@@ LUA_NUMBER_FMT is the format for writing floats.390@@ lua_number2str converts a float to a string.391@@ l_mathop allows the addition of an 'l' or 'f' to all math operations.392@@ l_floor takes the floor of a float.393@@ lua_str2number converts a decimal numeral to a number.394*/395396397/* The following definitions are good for most cases here */398399#define l_floor(x) (l_mathop(floor)(x))400401#define lua_number2str(s,sz,n) \402l_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n))403404/*405@@ lua_numbertointeger converts a float number with an integral value406** to an integer, or returns 0 if float is not within the range of407** a lua_Integer. (The range comparisons are tricky because of408** rounding. The tests here assume a two-complement representation,409** where MININTEGER always has an exact representation as a float;410** MAXINTEGER may not have one, and therefore its conversion to float411** may have an ill-defined value.)412*/413#define lua_numbertointeger(n,p) \414(*(p) = (LUA_INTEGER)(n), 1)415416417/* now the variable definitions */418419#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */420421#define LUA_NUMBER float422423#define l_floatatt(n) (FLT_##n)424425#define LUAI_UACNUMBER double426427#define LUA_NUMBER_FRMLEN ""428#define LUA_NUMBER_FMT "%.7g"429430#define l_mathop(op) op##f431432#define lua_str2number(s,p) strtof((s), (p))433434435#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */436437#define LUA_NUMBER long double438439#define l_floatatt(n) (LDBL_##n)440441#define LUAI_UACNUMBER long double442443#define LUA_NUMBER_FRMLEN "L"444#define LUA_NUMBER_FMT "%.19Lg"445446#define l_mathop(op) op##l447448#define lua_str2number(s,p) strtold((s), (p))449450#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */451452#define LUA_NUMBER double453454#define l_floatatt(n) (DBL_##n)455456#define LUAI_UACNUMBER double457458#define LUA_NUMBER_FRMLEN ""459#define LUA_NUMBER_FMT "%.14g"460461#define l_mathop(op) op462463#define lua_str2number(s,p) strtod((s), (p))464465#elif LUA_FLOAT_TYPE == LUA_FLOAT_INT64 /* }{ int64 */466467#include "lstd.h"468469#include <machine/_inttypes.h>470471#define panic lua_panic472/* Hack to use int64 as the LUA_NUMBER from ZFS code, kinda */473474#define LUA_NUMBER int64_t475476#define l_mathlim(n) (LUA_FLOAT_INT_HACK_##n)477#define LUA_FLOAT_INT_HACK_MANT_DIG 32478#define LUA_FLOAT_INT_HACK_MAX_10_EXP 32479480#define LUAI_UACNUMBER int64_t481482#define LUA_NUMBER_FRMLEN ""483#define LUA_NUMBER_FMT "%" PRId64484485#define l_mathop(x) (lstd_ ## x)486487#define lua_str2number(s,p) strtoll((s), (p), 0)488489#define lua_getlocaledecpoint() '.'490491#else /* }{ */492493#error "numeric float type not defined"494495#endif /* } */496497498499/*500@@ LUA_INTEGER is the integer type used by Lua.501**502@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.503**504@@ LUAI_UACINT is the result of a 'default argument promotion'505@@ over a LUA_INTEGER.506@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.507@@ LUA_INTEGER_FMT is the format for writing integers.508@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.509@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.510@@ LUA_MAXUNSIGNED is the maximum value for a LUA_UNSIGNED.511@@ LUA_UNSIGNEDBITS is the number of bits in a LUA_UNSIGNED.512@@ lua_integer2str converts an integer to a string.513*/514515516/* The following definitions are good for most cases here */517518#define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d"519520#define LUAI_UACINT LUA_INTEGER521522#define lua_integer2str(s,sz,n) \523l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n))524525/*526** use LUAI_UACINT here to avoid problems with promotions (which527** can turn a comparison between unsigneds into a signed comparison)528*/529#define LUA_UNSIGNED unsigned LUAI_UACINT530531532#define LUA_UNSIGNEDBITS (sizeof(LUA_UNSIGNED) * CHAR_BIT)533534535/* now the variable definitions */536537#if LUA_INT_TYPE == LUA_INT_INT /* { int */538539#define LUA_INTEGER int540#define LUA_INTEGER_FRMLEN ""541542#define LUA_MAXINTEGER INT_MAX543#define LUA_MININTEGER INT_MIN544545#define LUA_MAXUNSIGNED UINT_MAX546547#elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */548549#define LUA_INTEGER long550#define LUA_INTEGER_FRMLEN "l"551552#define LUA_MAXINTEGER LONG_MAX553#define LUA_MININTEGER LONG_MIN554555#define LUA_MAXUNSIGNED ULONG_MAX556557#elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */558559/* use presence of macro LLONG_MAX as proxy for C99 compliance */560#if defined(LLONG_MAX) /* { */561/* use ISO C99 stuff */562563#define LUA_INTEGER long long564#define LUA_INTEGER_FRMLEN "ll"565566#define LUA_MAXINTEGER LLONG_MAX567#define LUA_MININTEGER LLONG_MIN568569#define LUA_MAXUNSIGNED ULLONG_MAX570571#elif defined(LUA_USE_WINDOWS) /* }{ */572/* in Windows, can use specific Windows types */573574#define LUA_INTEGER __int64575#define LUA_INTEGER_FRMLEN "I64"576577#define LUA_MAXINTEGER _I64_MAX578#define LUA_MININTEGER _I64_MIN579580#define LUA_MAXUNSIGNED _UI64_MAX581582#else /* }{ */583584#error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \585or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)"586587#endif /* } */588589#else /* }{ */590591#error "numeric integer type not defined"592593#endif /* } */594595/* }================================================================== */596597598/*599** {==================================================================600** Dependencies with C99 and other C details601** ===================================================================602*/603604/*605@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.606** (All uses in Lua have only one format item.)607*/608#if !defined(LUA_USE_C89)609#define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i)610#else611#define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i))612#endif613614615/*616@@ lua_strx2number converts a hexadecimal numeral to a number.617** In C99, 'strtod' does that conversion. Otherwise, you can618** leave 'lua_strx2number' undefined and Lua will provide its own619** implementation.620*/621#if !defined(LUA_USE_C89)622#define lua_strx2number(s,p) lua_str2number(s,p)623#endif624625626/*627@@ lua_pointer2str converts a pointer to a readable string in a628** non-specified way.629*/630#define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p)631632633/*634@@ lua_number2strx converts a float to a hexadecimal numeral.635** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.636** Otherwise, you can leave 'lua_number2strx' undefined and Lua will637** provide its own implementation.638*/639#if !defined(LUA_USE_C89)640#define lua_number2strx(L,b,sz,f,n) \641((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n)))642#endif643644645/*646** 'strtof' and 'opf' variants for math functions are not valid in647** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the648** availability of these variants. ('math.h' is already included in649** all files that use these macros.)650*/651#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF))652#undef l_mathop /* variants not available */653#undef lua_str2number654#define l_mathop(op) (lua_Number)op /* no variant */655#define lua_str2number(s,p) ((lua_Number)strtod((s), (p)))656#endif657658659/*660@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation661** functions. It must be a numerical type; Lua will use 'intptr_t' if662** available, otherwise it will use 'ptrdiff_t' (the nearest thing to663** 'intptr_t' in C89)664*/665#define LUA_KCONTEXT ptrdiff_t666667#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \668__STDC_VERSION__ >= 199901L669#include <stdint.h>670#if defined(INTPTR_MAX) /* even in C99 this type is optional */671#undef LUA_KCONTEXT672#define LUA_KCONTEXT intptr_t673#endif674#endif675676677/*678@@ lua_getlocaledecpoint gets the locale "radix character" (decimal point).679** Change that if you do not want to use C locales. (Code using this680** macro must include the header 'locale.h'.)681*/682#if !defined(lua_getlocaledecpoint)683#define lua_getlocaledecpoint() (localeconv()->decimal_point[0])684#endif685686/* }================================================================== */687688689/*690** {==================================================================691** Language Variations692** =====================================================================693*/694695/*696@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some697** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from698** numbers to strings. Define LUA_NOCVTS2N to turn off automatic699** coercion from strings to numbers.700*/701/* #define LUA_NOCVTN2S */702/* #define LUA_NOCVTS2N */703704705/*706@@ LUA_USE_APICHECK turns on several consistency checks on the C API.707** Define it as a help when debugging C code.708*/709#if defined(LUA_USE_APICHECK)710#include <assert.h>711#define luai_apicheck(l,e) assert(e)712#endif713714/* }================================================================== */715716717/*718** {==================================================================719** Macros that affect the API and must be stable (that is, must be the720** same when you compile Lua and when you compile code that links to721** Lua).722** =====================================================================723*/724725/*726@@ LUAI_MAXSTACK limits the size of the Lua stack.727** CHANGE it if you need a different limit. This limit is arbitrary;728** its only purpose is to stop Lua from consuming unlimited stack729** space (and to reserve some numbers for pseudo-indices).730** (It must fit into max(size_t)/32.)731*/732#if LUAI_IS32INT733#define LUAI_MAXSTACK 1000000734#else735#define LUAI_MAXSTACK 15000736#endif737738739/*740@@ LUA_EXTRASPACE defines the size of a raw memory area associated with741** a Lua state with very fast access.742** CHANGE it if you need a different size.743*/744#define LUA_EXTRASPACE (sizeof(void *))745746747/*748@@ LUA_IDSIZE gives the maximum size for the description of the source749@@ of a function in debug information.750** CHANGE it if you want a different size.751*/752#define LUA_IDSIZE 60753754755/*756@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.757*/758#define LUAL_BUFFERSIZE 128759760761/*762@@ LUAI_MAXALIGN defines fields that, when used in a union, ensure763** maximum alignment for the other items in that union.764*/765#define LUAI_MAXALIGN lua_Number n; void *s; lua_Integer i; long l766767/* }================================================================== */768769770771772773/* =================================================================== */774775/*776** Local configuration. You can use this space to add your redefinitions777** without modifying the main part of the file.778*/779780781782783784#endif785786787788