1*088332b5SXin Li /* 2*088332b5SXin Li ** $Id: luaconf.h $ 3*088332b5SXin Li ** Configuration file for Lua 4*088332b5SXin Li ** See Copyright Notice in lua.h 5*088332b5SXin Li */ 6*088332b5SXin Li 7*088332b5SXin Li 8*088332b5SXin Li #ifndef luaconf_h 9*088332b5SXin Li #define luaconf_h 10*088332b5SXin Li 11*088332b5SXin Li #include <limits.h> 12*088332b5SXin Li #include <stddef.h> 13*088332b5SXin Li 14*088332b5SXin Li 15*088332b5SXin Li /* 16*088332b5SXin Li ** =================================================================== 17*088332b5SXin Li ** General Configuration File for Lua 18*088332b5SXin Li ** 19*088332b5SXin Li ** Some definitions here can be changed externally, through the 20*088332b5SXin Li ** compiler (e.g., with '-D' options). Those are protected by 21*088332b5SXin Li ** '#if !defined' guards. However, several other definitions should 22*088332b5SXin Li ** be changed directly here, either because they affect the Lua 23*088332b5SXin Li ** ABI (by making the changes here, you ensure that all software 24*088332b5SXin Li ** connected to Lua, such as C libraries, will be compiled with the 25*088332b5SXin Li ** same configuration); or because they are seldom changed. 26*088332b5SXin Li ** 27*088332b5SXin Li ** Search for "@@" to find all configurable definitions. 28*088332b5SXin Li ** =================================================================== 29*088332b5SXin Li */ 30*088332b5SXin Li 31*088332b5SXin Li 32*088332b5SXin Li /* 33*088332b5SXin Li ** {==================================================================== 34*088332b5SXin Li ** System Configuration: macros to adapt (if needed) Lua to some 35*088332b5SXin Li ** particular platform, for instance restricting it to C89. 36*088332b5SXin Li ** ===================================================================== 37*088332b5SXin Li */ 38*088332b5SXin Li 39*088332b5SXin Li /* 40*088332b5SXin Li @@ LUAI_MAXCSTACK defines the maximum depth for nested calls and 41*088332b5SXin Li ** also limits the maximum depth of other recursive algorithms in 42*088332b5SXin Li ** the implementation, such as syntactic analysis. A value too 43*088332b5SXin Li ** large may allow the interpreter to crash (C-stack overflow). 44*088332b5SXin Li ** The default value seems ok for regular machines, but may be 45*088332b5SXin Li ** too high for restricted hardware. 46*088332b5SXin Li ** The test file 'cstack.lua' may help finding a good limit. 47*088332b5SXin Li ** (It will crash with a limit too high.) 48*088332b5SXin Li */ 49*088332b5SXin Li #if !defined(LUAI_MAXCSTACK) 50*088332b5SXin Li #define LUAI_MAXCSTACK 2000 51*088332b5SXin Li #endif 52*088332b5SXin Li 53*088332b5SXin Li 54*088332b5SXin Li /* 55*088332b5SXin Li @@ LUA_USE_C89 controls the use of non-ISO-C89 features. 56*088332b5SXin Li ** Define it if you want Lua to avoid the use of a few C99 features 57*088332b5SXin Li ** or Windows-specific features on Windows. 58*088332b5SXin Li */ 59*088332b5SXin Li /* #define LUA_USE_C89 */ 60*088332b5SXin Li 61*088332b5SXin Li 62*088332b5SXin Li /* 63*088332b5SXin Li ** By default, Lua on Windows use (some) specific Windows features 64*088332b5SXin Li */ 65*088332b5SXin Li #if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE) 66*088332b5SXin Li #define LUA_USE_WINDOWS /* enable goodies for regular Windows */ 67*088332b5SXin Li #endif 68*088332b5SXin Li 69*088332b5SXin Li 70*088332b5SXin Li #if defined(LUA_USE_WINDOWS) 71*088332b5SXin Li #define LUA_DL_DLL /* enable support for DLL */ 72*088332b5SXin Li #define LUA_USE_C89 /* broadly, Windows is C89 */ 73*088332b5SXin Li #endif 74*088332b5SXin Li 75*088332b5SXin Li 76*088332b5SXin Li #if defined(LUA_USE_LINUX) 77*088332b5SXin Li #define LUA_USE_POSIX 78*088332b5SXin Li #define LUA_USE_DLOPEN /* needs an extra library: -ldl */ 79*088332b5SXin Li #endif 80*088332b5SXin Li 81*088332b5SXin Li 82*088332b5SXin Li #if defined(LUA_USE_MACOSX) 83*088332b5SXin Li #define LUA_USE_POSIX 84*088332b5SXin Li #define LUA_USE_DLOPEN /* MacOS does not need -ldl */ 85*088332b5SXin Li #endif 86*088332b5SXin Li 87*088332b5SXin Li 88*088332b5SXin Li /* 89*088332b5SXin Li @@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits. 90*088332b5SXin Li */ 91*088332b5SXin Li #define LUAI_IS32INT ((UINT_MAX >> 30) >= 3) 92*088332b5SXin Li 93*088332b5SXin Li /* }================================================================== */ 94*088332b5SXin Li 95*088332b5SXin Li 96*088332b5SXin Li 97*088332b5SXin Li /* 98*088332b5SXin Li ** {================================================================== 99*088332b5SXin Li ** Configuration for Number types. 100*088332b5SXin Li ** =================================================================== 101*088332b5SXin Li */ 102*088332b5SXin Li 103*088332b5SXin Li /* 104*088332b5SXin Li @@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. 105*088332b5SXin Li */ 106*088332b5SXin Li /* #define LUA_32BITS */ 107*088332b5SXin Li 108*088332b5SXin Li 109*088332b5SXin Li /* 110*088332b5SXin Li @@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for 111*088332b5SXin Li ** C89 ('long' and 'double'); Windows always has '__int64', so it does 112*088332b5SXin Li ** not need to use this case. 113*088332b5SXin Li */ 114*088332b5SXin Li #if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS) 115*088332b5SXin Li #define LUA_C89_NUMBERS 116*088332b5SXin Li #endif 117*088332b5SXin Li 118*088332b5SXin Li 119*088332b5SXin Li /* 120*088332b5SXin Li @@ LUA_INT_TYPE defines the type for Lua integers. 121*088332b5SXin Li @@ LUA_FLOAT_TYPE defines the type for Lua floats. 122*088332b5SXin Li ** Lua should work fine with any mix of these options supported 123*088332b5SXin Li ** by your C compiler. The usual configurations are 64-bit integers 124*088332b5SXin Li ** and 'double' (the default), 32-bit integers and 'float' (for 125*088332b5SXin Li ** restricted platforms), and 'long'/'double' (for C compilers not 126*088332b5SXin Li ** compliant with C99, which may not have support for 'long long'). 127*088332b5SXin Li */ 128*088332b5SXin Li 129*088332b5SXin Li /* predefined options for LUA_INT_TYPE */ 130*088332b5SXin Li #define LUA_INT_INT 1 131*088332b5SXin Li #define LUA_INT_LONG 2 132*088332b5SXin Li #define LUA_INT_LONGLONG 3 133*088332b5SXin Li 134*088332b5SXin Li /* predefined options for LUA_FLOAT_TYPE */ 135*088332b5SXin Li #define LUA_FLOAT_FLOAT 1 136*088332b5SXin Li #define LUA_FLOAT_DOUBLE 2 137*088332b5SXin Li #define LUA_FLOAT_LONGDOUBLE 3 138*088332b5SXin Li 139*088332b5SXin Li #if defined(LUA_32BITS) /* { */ 140*088332b5SXin Li /* 141*088332b5SXin Li ** 32-bit integers and 'float' 142*088332b5SXin Li */ 143*088332b5SXin Li #if LUAI_IS32INT /* use 'int' if big enough */ 144*088332b5SXin Li #define LUA_INT_TYPE LUA_INT_INT 145*088332b5SXin Li #else /* otherwise use 'long' */ 146*088332b5SXin Li #define LUA_INT_TYPE LUA_INT_LONG 147*088332b5SXin Li #endif 148*088332b5SXin Li #define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT 149*088332b5SXin Li 150*088332b5SXin Li #elif defined(LUA_C89_NUMBERS) /* }{ */ 151*088332b5SXin Li /* 152*088332b5SXin Li ** largest types available for C89 ('long' and 'double') 153*088332b5SXin Li */ 154*088332b5SXin Li #define LUA_INT_TYPE LUA_INT_LONG 155*088332b5SXin Li #define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE 156*088332b5SXin Li 157*088332b5SXin Li #endif /* } */ 158*088332b5SXin Li 159*088332b5SXin Li 160*088332b5SXin Li /* 161*088332b5SXin Li ** default configuration for 64-bit Lua ('long long' and 'double') 162*088332b5SXin Li */ 163*088332b5SXin Li #if !defined(LUA_INT_TYPE) 164*088332b5SXin Li #define LUA_INT_TYPE LUA_INT_LONGLONG 165*088332b5SXin Li #endif 166*088332b5SXin Li 167*088332b5SXin Li #if !defined(LUA_FLOAT_TYPE) 168*088332b5SXin Li #define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE 169*088332b5SXin Li #endif 170*088332b5SXin Li 171*088332b5SXin Li /* }================================================================== */ 172*088332b5SXin Li 173*088332b5SXin Li 174*088332b5SXin Li 175*088332b5SXin Li /* 176*088332b5SXin Li ** {================================================================== 177*088332b5SXin Li ** Configuration for Paths. 178*088332b5SXin Li ** =================================================================== 179*088332b5SXin Li */ 180*088332b5SXin Li 181*088332b5SXin Li /* 182*088332b5SXin Li ** LUA_PATH_SEP is the character that separates templates in a path. 183*088332b5SXin Li ** LUA_PATH_MARK is the string that marks the substitution points in a 184*088332b5SXin Li ** template. 185*088332b5SXin Li ** LUA_EXEC_DIR in a Windows path is replaced by the executable's 186*088332b5SXin Li ** directory. 187*088332b5SXin Li */ 188*088332b5SXin Li #define LUA_PATH_SEP ";" 189*088332b5SXin Li #define LUA_PATH_MARK "?" 190*088332b5SXin Li #define LUA_EXEC_DIR "!" 191*088332b5SXin Li 192*088332b5SXin Li 193*088332b5SXin Li /* 194*088332b5SXin Li @@ LUA_PATH_DEFAULT is the default path that Lua uses to look for 195*088332b5SXin Li ** Lua libraries. 196*088332b5SXin Li @@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for 197*088332b5SXin Li ** C libraries. 198*088332b5SXin Li ** CHANGE them if your machine has a non-conventional directory 199*088332b5SXin Li ** hierarchy or if you want to install your libraries in 200*088332b5SXin Li ** non-conventional directories. 201*088332b5SXin Li */ 202*088332b5SXin Li 203*088332b5SXin Li #define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR 204*088332b5SXin Li #if defined(_WIN32) /* { */ 205*088332b5SXin Li /* 206*088332b5SXin Li ** In Windows, any exclamation mark ('!') in the path is replaced by the 207*088332b5SXin Li ** path of the directory of the executable file of the current process. 208*088332b5SXin Li */ 209*088332b5SXin Li #define LUA_LDIR "!\\lua\\" 210*088332b5SXin Li #define LUA_CDIR "!\\" 211*088332b5SXin Li #define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\" 212*088332b5SXin Li 213*088332b5SXin Li #if !defined(LUA_PATH_DEFAULT) 214*088332b5SXin Li #define LUA_PATH_DEFAULT \ 215*088332b5SXin Li LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ 216*088332b5SXin Li LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \ 217*088332b5SXin Li LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \ 218*088332b5SXin Li ".\\?.lua;" ".\\?\\init.lua" 219*088332b5SXin Li #endif 220*088332b5SXin Li 221*088332b5SXin Li #if !defined(LUA_CPATH_DEFAULT) 222*088332b5SXin Li #define LUA_CPATH_DEFAULT \ 223*088332b5SXin Li LUA_CDIR"?.dll;" \ 224*088332b5SXin Li LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \ 225*088332b5SXin Li LUA_CDIR"loadall.dll;" ".\\?.dll" 226*088332b5SXin Li #endif 227*088332b5SXin Li 228*088332b5SXin Li #else /* }{ */ 229*088332b5SXin Li 230*088332b5SXin Li #define LUA_ROOT "/usr/local/" 231*088332b5SXin Li #define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/" 232*088332b5SXin Li #define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/" 233*088332b5SXin Li 234*088332b5SXin Li #if !defined(LUA_PATH_DEFAULT) 235*088332b5SXin Li #define LUA_PATH_DEFAULT \ 236*088332b5SXin Li LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ 237*088332b5SXin Li LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \ 238*088332b5SXin Li "./?.lua;" "./?/init.lua" 239*088332b5SXin Li #endif 240*088332b5SXin Li 241*088332b5SXin Li #if !defined(LUA_CPATH_DEFAULT) 242*088332b5SXin Li #define LUA_CPATH_DEFAULT \ 243*088332b5SXin Li LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so" 244*088332b5SXin Li #endif 245*088332b5SXin Li 246*088332b5SXin Li #endif /* } */ 247*088332b5SXin Li 248*088332b5SXin Li 249*088332b5SXin Li /* 250*088332b5SXin Li @@ LUA_DIRSEP is the directory separator (for submodules). 251*088332b5SXin Li ** CHANGE it if your machine does not use "/" as the directory separator 252*088332b5SXin Li ** and is not Windows. (On Windows Lua automatically uses "\".) 253*088332b5SXin Li */ 254*088332b5SXin Li #if !defined(LUA_DIRSEP) 255*088332b5SXin Li 256*088332b5SXin Li #if defined(_WIN32) 257*088332b5SXin Li #define LUA_DIRSEP "\\" 258*088332b5SXin Li #else 259*088332b5SXin Li #define LUA_DIRSEP "/" 260*088332b5SXin Li #endif 261*088332b5SXin Li 262*088332b5SXin Li #endif 263*088332b5SXin Li 264*088332b5SXin Li /* }================================================================== */ 265*088332b5SXin Li 266*088332b5SXin Li 267*088332b5SXin Li /* 268*088332b5SXin Li ** {================================================================== 269*088332b5SXin Li ** Marks for exported symbols in the C code 270*088332b5SXin Li ** =================================================================== 271*088332b5SXin Li */ 272*088332b5SXin Li 273*088332b5SXin Li /* 274*088332b5SXin Li @@ LUA_API is a mark for all core API functions. 275*088332b5SXin Li @@ LUALIB_API is a mark for all auxiliary library functions. 276*088332b5SXin Li @@ LUAMOD_API is a mark for all standard library opening functions. 277*088332b5SXin Li ** CHANGE them if you need to define those functions in some special way. 278*088332b5SXin Li ** For instance, if you want to create one Windows DLL with the core and 279*088332b5SXin Li ** the libraries, you may want to use the following definition (define 280*088332b5SXin Li ** LUA_BUILD_AS_DLL to get it). 281*088332b5SXin Li */ 282*088332b5SXin Li #if defined(LUA_BUILD_AS_DLL) /* { */ 283*088332b5SXin Li 284*088332b5SXin Li #if defined(LUA_CORE) || defined(LUA_LIB) /* { */ 285*088332b5SXin Li #define LUA_API __declspec(dllexport) 286*088332b5SXin Li #else /* }{ */ 287*088332b5SXin Li #define LUA_API __declspec(dllimport) 288*088332b5SXin Li #endif /* } */ 289*088332b5SXin Li 290*088332b5SXin Li #else /* }{ */ 291*088332b5SXin Li 292*088332b5SXin Li #define LUA_API extern 293*088332b5SXin Li 294*088332b5SXin Li #endif /* } */ 295*088332b5SXin Li 296*088332b5SXin Li 297*088332b5SXin Li /* 298*088332b5SXin Li ** More often than not the libs go together with the core. 299*088332b5SXin Li */ 300*088332b5SXin Li #define LUALIB_API LUA_API 301*088332b5SXin Li #define LUAMOD_API LUA_API 302*088332b5SXin Li 303*088332b5SXin Li 304*088332b5SXin Li /* 305*088332b5SXin Li @@ LUAI_FUNC is a mark for all extern functions that are not to be 306*088332b5SXin Li ** exported to outside modules. 307*088332b5SXin Li @@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables, 308*088332b5SXin Li ** none of which to be exported to outside modules (LUAI_DDEF for 309*088332b5SXin Li ** definitions and LUAI_DDEC for declarations). 310*088332b5SXin Li ** CHANGE them if you need to mark them in some special way. Elf/gcc 311*088332b5SXin Li ** (versions 3.2 and later) mark them as "hidden" to optimize access 312*088332b5SXin Li ** when Lua is compiled as a shared library. Not all elf targets support 313*088332b5SXin Li ** this attribute. Unfortunately, gcc does not offer a way to check 314*088332b5SXin Li ** whether the target offers that support, and those without support 315*088332b5SXin Li ** give a warning about it. To avoid these warnings, change to the 316*088332b5SXin Li ** default definition. 317*088332b5SXin Li */ 318*088332b5SXin Li #if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ 319*088332b5SXin Li defined(__ELF__) /* { */ 320*088332b5SXin Li #define LUAI_FUNC __attribute__((visibility("internal"))) extern 321*088332b5SXin Li #else /* }{ */ 322*088332b5SXin Li #define LUAI_FUNC extern 323*088332b5SXin Li #endif /* } */ 324*088332b5SXin Li 325*088332b5SXin Li #define LUAI_DDEC(dec) LUAI_FUNC dec 326*088332b5SXin Li #define LUAI_DDEF /* empty */ 327*088332b5SXin Li 328*088332b5SXin Li /* }================================================================== */ 329*088332b5SXin Li 330*088332b5SXin Li 331*088332b5SXin Li /* 332*088332b5SXin Li ** {================================================================== 333*088332b5SXin Li ** Compatibility with previous versions 334*088332b5SXin Li ** =================================================================== 335*088332b5SXin Li */ 336*088332b5SXin Li 337*088332b5SXin Li /* 338*088332b5SXin Li @@ LUA_COMPAT_5_3 controls other macros for compatibility with Lua 5.3. 339*088332b5SXin Li ** You can define it to get all options, or change specific options 340*088332b5SXin Li ** to fit your specific needs. 341*088332b5SXin Li */ 342*088332b5SXin Li #if defined(LUA_COMPAT_5_3) /* { */ 343*088332b5SXin Li 344*088332b5SXin Li /* 345*088332b5SXin Li @@ LUA_COMPAT_MATHLIB controls the presence of several deprecated 346*088332b5SXin Li ** functions in the mathematical library. 347*088332b5SXin Li ** (These functions were already officially removed in 5.3; 348*088332b5SXin Li ** nevertheless they are still available here.) 349*088332b5SXin Li */ 350*088332b5SXin Li #define LUA_COMPAT_MATHLIB 351*088332b5SXin Li 352*088332b5SXin Li /* 353*088332b5SXin Li @@ LUA_COMPAT_APIINTCASTS controls the presence of macros for 354*088332b5SXin Li ** manipulating other integer types (lua_pushunsigned, lua_tounsigned, 355*088332b5SXin Li ** luaL_checkint, luaL_checklong, etc.) 356*088332b5SXin Li ** (These macros were also officially removed in 5.3, but they are still 357*088332b5SXin Li ** available here.) 358*088332b5SXin Li */ 359*088332b5SXin Li #define LUA_COMPAT_APIINTCASTS 360*088332b5SXin Li 361*088332b5SXin Li 362*088332b5SXin Li /* 363*088332b5SXin Li @@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod 364*088332b5SXin Li ** using '__lt'. 365*088332b5SXin Li */ 366*088332b5SXin Li #define LUA_COMPAT_LT_LE 367*088332b5SXin Li 368*088332b5SXin Li 369*088332b5SXin Li /* 370*088332b5SXin Li @@ The following macros supply trivial compatibility for some 371*088332b5SXin Li ** changes in the API. The macros themselves document how to 372*088332b5SXin Li ** change your code to avoid using them. 373*088332b5SXin Li ** (Once more, these macros were officially removed in 5.3, but they are 374*088332b5SXin Li ** still available here.) 375*088332b5SXin Li */ 376*088332b5SXin Li #define lua_strlen(L,i) lua_rawlen(L, (i)) 377*088332b5SXin Li 378*088332b5SXin Li #define lua_objlen(L,i) lua_rawlen(L, (i)) 379*088332b5SXin Li 380*088332b5SXin Li #define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) 381*088332b5SXin Li #define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT) 382*088332b5SXin Li 383*088332b5SXin Li #endif /* } */ 384*088332b5SXin Li 385*088332b5SXin Li /* }================================================================== */ 386*088332b5SXin Li 387*088332b5SXin Li 388*088332b5SXin Li 389*088332b5SXin Li /* 390*088332b5SXin Li ** {================================================================== 391*088332b5SXin Li ** Configuration for Numbers. 392*088332b5SXin Li ** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_* 393*088332b5SXin Li ** satisfy your needs. 394*088332b5SXin Li ** =================================================================== 395*088332b5SXin Li */ 396*088332b5SXin Li 397*088332b5SXin Li /* 398*088332b5SXin Li @@ LUA_NUMBER is the floating-point type used by Lua. 399*088332b5SXin Li @@ LUAI_UACNUMBER is the result of a 'default argument promotion' 400*088332b5SXin Li @@ over a floating number. 401*088332b5SXin Li @@ l_floatatt(x) corrects float attribute 'x' to the proper float type 402*088332b5SXin Li ** by prefixing it with one of FLT/DBL/LDBL. 403*088332b5SXin Li @@ LUA_NUMBER_FRMLEN is the length modifier for writing floats. 404*088332b5SXin Li @@ LUA_NUMBER_FMT is the format for writing floats. 405*088332b5SXin Li @@ lua_number2str converts a float to a string. 406*088332b5SXin Li @@ l_mathop allows the addition of an 'l' or 'f' to all math operations. 407*088332b5SXin Li @@ l_floor takes the floor of a float. 408*088332b5SXin Li @@ lua_str2number converts a decimal numeral to a number. 409*088332b5SXin Li */ 410*088332b5SXin Li 411*088332b5SXin Li 412*088332b5SXin Li /* The following definitions are good for most cases here */ 413*088332b5SXin Li 414*088332b5SXin Li #define l_floor(x) (l_mathop(floor)(x)) 415*088332b5SXin Li 416*088332b5SXin Li #define lua_number2str(s,sz,n) \ 417*088332b5SXin Li l_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n)) 418*088332b5SXin Li 419*088332b5SXin Li /* 420*088332b5SXin Li @@ lua_numbertointeger converts a float number with an integral value 421*088332b5SXin Li ** to an integer, or returns 0 if float is not within the range of 422*088332b5SXin Li ** a lua_Integer. (The range comparisons are tricky because of 423*088332b5SXin Li ** rounding. The tests here assume a two-complement representation, 424*088332b5SXin Li ** where MININTEGER always has an exact representation as a float; 425*088332b5SXin Li ** MAXINTEGER may not have one, and therefore its conversion to float 426*088332b5SXin Li ** may have an ill-defined value.) 427*088332b5SXin Li */ 428*088332b5SXin Li #define lua_numbertointeger(n,p) \ 429*088332b5SXin Li ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \ 430*088332b5SXin Li (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \ 431*088332b5SXin Li (*(p) = (LUA_INTEGER)(n), 1)) 432*088332b5SXin Li 433*088332b5SXin Li 434*088332b5SXin Li /* now the variable definitions */ 435*088332b5SXin Li 436*088332b5SXin Li #if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */ 437*088332b5SXin Li 438*088332b5SXin Li #define LUA_NUMBER float 439*088332b5SXin Li 440*088332b5SXin Li #define l_floatatt(n) (FLT_##n) 441*088332b5SXin Li 442*088332b5SXin Li #define LUAI_UACNUMBER double 443*088332b5SXin Li 444*088332b5SXin Li #define LUA_NUMBER_FRMLEN "" 445*088332b5SXin Li #define LUA_NUMBER_FMT "%.7g" 446*088332b5SXin Li 447*088332b5SXin Li #define l_mathop(op) op##f 448*088332b5SXin Li 449*088332b5SXin Li #define lua_str2number(s,p) strtof((s), (p)) 450*088332b5SXin Li 451*088332b5SXin Li 452*088332b5SXin Li #elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */ 453*088332b5SXin Li 454*088332b5SXin Li #define LUA_NUMBER long double 455*088332b5SXin Li 456*088332b5SXin Li #define l_floatatt(n) (LDBL_##n) 457*088332b5SXin Li 458*088332b5SXin Li #define LUAI_UACNUMBER long double 459*088332b5SXin Li 460*088332b5SXin Li #define LUA_NUMBER_FRMLEN "L" 461*088332b5SXin Li #define LUA_NUMBER_FMT "%.19Lg" 462*088332b5SXin Li 463*088332b5SXin Li #define l_mathop(op) op##l 464*088332b5SXin Li 465*088332b5SXin Li #define lua_str2number(s,p) strtold((s), (p)) 466*088332b5SXin Li 467*088332b5SXin Li #elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */ 468*088332b5SXin Li 469*088332b5SXin Li #define LUA_NUMBER double 470*088332b5SXin Li 471*088332b5SXin Li #define l_floatatt(n) (DBL_##n) 472*088332b5SXin Li 473*088332b5SXin Li #define LUAI_UACNUMBER double 474*088332b5SXin Li 475*088332b5SXin Li #define LUA_NUMBER_FRMLEN "" 476*088332b5SXin Li #define LUA_NUMBER_FMT "%.14g" 477*088332b5SXin Li 478*088332b5SXin Li #define l_mathop(op) op 479*088332b5SXin Li 480*088332b5SXin Li #define lua_str2number(s,p) strtod((s), (p)) 481*088332b5SXin Li 482*088332b5SXin Li #else /* }{ */ 483*088332b5SXin Li 484*088332b5SXin Li #error "numeric float type not defined" 485*088332b5SXin Li 486*088332b5SXin Li #endif /* } */ 487*088332b5SXin Li 488*088332b5SXin Li 489*088332b5SXin Li 490*088332b5SXin Li /* 491*088332b5SXin Li @@ LUA_INTEGER is the integer type used by Lua. 492*088332b5SXin Li ** 493*088332b5SXin Li @@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER. 494*088332b5SXin Li ** 495*088332b5SXin Li @@ LUAI_UACINT is the result of a 'default argument promotion' 496*088332b5SXin Li @@ over a LUA_INTEGER. 497*088332b5SXin Li @@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers. 498*088332b5SXin Li @@ LUA_INTEGER_FMT is the format for writing integers. 499*088332b5SXin Li @@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER. 500*088332b5SXin Li @@ LUA_MININTEGER is the minimum value for a LUA_INTEGER. 501*088332b5SXin Li @@ LUA_MAXUNSIGNED is the maximum value for a LUA_UNSIGNED. 502*088332b5SXin Li @@ LUA_UNSIGNEDBITS is the number of bits in a LUA_UNSIGNED. 503*088332b5SXin Li @@ lua_integer2str converts an integer to a string. 504*088332b5SXin Li */ 505*088332b5SXin Li 506*088332b5SXin Li 507*088332b5SXin Li /* The following definitions are good for most cases here */ 508*088332b5SXin Li 509*088332b5SXin Li #define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d" 510*088332b5SXin Li 511*088332b5SXin Li #define LUAI_UACINT LUA_INTEGER 512*088332b5SXin Li 513*088332b5SXin Li #define lua_integer2str(s,sz,n) \ 514*088332b5SXin Li l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n)) 515*088332b5SXin Li 516*088332b5SXin Li /* 517*088332b5SXin Li ** use LUAI_UACINT here to avoid problems with promotions (which 518*088332b5SXin Li ** can turn a comparison between unsigneds into a signed comparison) 519*088332b5SXin Li */ 520*088332b5SXin Li #define LUA_UNSIGNED unsigned LUAI_UACINT 521*088332b5SXin Li 522*088332b5SXin Li 523*088332b5SXin Li #define LUA_UNSIGNEDBITS (sizeof(LUA_UNSIGNED) * CHAR_BIT) 524*088332b5SXin Li 525*088332b5SXin Li 526*088332b5SXin Li /* now the variable definitions */ 527*088332b5SXin Li 528*088332b5SXin Li #if LUA_INT_TYPE == LUA_INT_INT /* { int */ 529*088332b5SXin Li 530*088332b5SXin Li #define LUA_INTEGER int 531*088332b5SXin Li #define LUA_INTEGER_FRMLEN "" 532*088332b5SXin Li 533*088332b5SXin Li #define LUA_MAXINTEGER INT_MAX 534*088332b5SXin Li #define LUA_MININTEGER INT_MIN 535*088332b5SXin Li 536*088332b5SXin Li #define LUA_MAXUNSIGNED UINT_MAX 537*088332b5SXin Li 538*088332b5SXin Li #elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */ 539*088332b5SXin Li 540*088332b5SXin Li #define LUA_INTEGER long 541*088332b5SXin Li #define LUA_INTEGER_FRMLEN "l" 542*088332b5SXin Li 543*088332b5SXin Li #define LUA_MAXINTEGER LONG_MAX 544*088332b5SXin Li #define LUA_MININTEGER LONG_MIN 545*088332b5SXin Li 546*088332b5SXin Li #define LUA_MAXUNSIGNED ULONG_MAX 547*088332b5SXin Li 548*088332b5SXin Li #elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */ 549*088332b5SXin Li 550*088332b5SXin Li /* use presence of macro LLONG_MAX as proxy for C99 compliance */ 551*088332b5SXin Li #if defined(LLONG_MAX) /* { */ 552*088332b5SXin Li /* use ISO C99 stuff */ 553*088332b5SXin Li 554*088332b5SXin Li #define LUA_INTEGER long long 555*088332b5SXin Li #define LUA_INTEGER_FRMLEN "ll" 556*088332b5SXin Li 557*088332b5SXin Li #define LUA_MAXINTEGER LLONG_MAX 558*088332b5SXin Li #define LUA_MININTEGER LLONG_MIN 559*088332b5SXin Li 560*088332b5SXin Li #define LUA_MAXUNSIGNED ULLONG_MAX 561*088332b5SXin Li 562*088332b5SXin Li #elif defined(LUA_USE_WINDOWS) /* }{ */ 563*088332b5SXin Li /* in Windows, can use specific Windows types */ 564*088332b5SXin Li 565*088332b5SXin Li #define LUA_INTEGER __int64 566*088332b5SXin Li #define LUA_INTEGER_FRMLEN "I64" 567*088332b5SXin Li 568*088332b5SXin Li #define LUA_MAXINTEGER _I64_MAX 569*088332b5SXin Li #define LUA_MININTEGER _I64_MIN 570*088332b5SXin Li 571*088332b5SXin Li #define LUA_MAXUNSIGNED _UI64_MAX 572*088332b5SXin Li 573*088332b5SXin Li #else /* }{ */ 574*088332b5SXin Li 575*088332b5SXin Li #error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \ 576*088332b5SXin Li or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)" 577*088332b5SXin Li 578*088332b5SXin Li #endif /* } */ 579*088332b5SXin Li 580*088332b5SXin Li #else /* }{ */ 581*088332b5SXin Li 582*088332b5SXin Li #error "numeric integer type not defined" 583*088332b5SXin Li 584*088332b5SXin Li #endif /* } */ 585*088332b5SXin Li 586*088332b5SXin Li /* }================================================================== */ 587*088332b5SXin Li 588*088332b5SXin Li 589*088332b5SXin Li /* 590*088332b5SXin Li ** {================================================================== 591*088332b5SXin Li ** Dependencies with C99 and other C details 592*088332b5SXin Li ** =================================================================== 593*088332b5SXin Li */ 594*088332b5SXin Li 595*088332b5SXin Li /* 596*088332b5SXin Li @@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89. 597*088332b5SXin Li ** (All uses in Lua have only one format item.) 598*088332b5SXin Li */ 599*088332b5SXin Li #if !defined(LUA_USE_C89) 600*088332b5SXin Li #define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i) 601*088332b5SXin Li #else 602*088332b5SXin Li #define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i)) 603*088332b5SXin Li #endif 604*088332b5SXin Li 605*088332b5SXin Li 606*088332b5SXin Li /* 607*088332b5SXin Li @@ lua_strx2number converts a hexadecimal numeral to a number. 608*088332b5SXin Li ** In C99, 'strtod' does that conversion. Otherwise, you can 609*088332b5SXin Li ** leave 'lua_strx2number' undefined and Lua will provide its own 610*088332b5SXin Li ** implementation. 611*088332b5SXin Li */ 612*088332b5SXin Li #if !defined(LUA_USE_C89) 613*088332b5SXin Li #define lua_strx2number(s,p) lua_str2number(s,p) 614*088332b5SXin Li #endif 615*088332b5SXin Li 616*088332b5SXin Li 617*088332b5SXin Li /* 618*088332b5SXin Li @@ lua_pointer2str converts a pointer to a readable string in a 619*088332b5SXin Li ** non-specified way. 620*088332b5SXin Li */ 621*088332b5SXin Li #define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p) 622*088332b5SXin Li 623*088332b5SXin Li 624*088332b5SXin Li /* 625*088332b5SXin Li @@ lua_number2strx converts a float to a hexadecimal numeral. 626*088332b5SXin Li ** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that. 627*088332b5SXin Li ** Otherwise, you can leave 'lua_number2strx' undefined and Lua will 628*088332b5SXin Li ** provide its own implementation. 629*088332b5SXin Li */ 630*088332b5SXin Li #if !defined(LUA_USE_C89) 631*088332b5SXin Li #define lua_number2strx(L,b,sz,f,n) \ 632*088332b5SXin Li ((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n))) 633*088332b5SXin Li #endif 634*088332b5SXin Li 635*088332b5SXin Li 636*088332b5SXin Li /* 637*088332b5SXin Li ** 'strtof' and 'opf' variants for math functions are not valid in 638*088332b5SXin Li ** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the 639*088332b5SXin Li ** availability of these variants. ('math.h' is already included in 640*088332b5SXin Li ** all files that use these macros.) 641*088332b5SXin Li */ 642*088332b5SXin Li #if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF)) 643*088332b5SXin Li #undef l_mathop /* variants not available */ 644*088332b5SXin Li #undef lua_str2number 645*088332b5SXin Li #define l_mathop(op) (lua_Number)op /* no variant */ 646*088332b5SXin Li #define lua_str2number(s,p) ((lua_Number)strtod((s), (p))) 647*088332b5SXin Li #endif 648*088332b5SXin Li 649*088332b5SXin Li 650*088332b5SXin Li /* 651*088332b5SXin Li @@ LUA_KCONTEXT is the type of the context ('ctx') for continuation 652*088332b5SXin Li ** functions. It must be a numerical type; Lua will use 'intptr_t' if 653*088332b5SXin Li ** available, otherwise it will use 'ptrdiff_t' (the nearest thing to 654*088332b5SXin Li ** 'intptr_t' in C89) 655*088332b5SXin Li */ 656*088332b5SXin Li #define LUA_KCONTEXT ptrdiff_t 657*088332b5SXin Li 658*088332b5SXin Li #if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \ 659*088332b5SXin Li __STDC_VERSION__ >= 199901L 660*088332b5SXin Li #include <stdint.h> 661*088332b5SXin Li #if defined(INTPTR_MAX) /* even in C99 this type is optional */ 662*088332b5SXin Li #undef LUA_KCONTEXT 663*088332b5SXin Li #define LUA_KCONTEXT intptr_t 664*088332b5SXin Li #endif 665*088332b5SXin Li #endif 666*088332b5SXin Li 667*088332b5SXin Li 668*088332b5SXin Li /* 669*088332b5SXin Li @@ lua_getlocaledecpoint gets the locale "radix character" (decimal point). 670*088332b5SXin Li ** Change that if you do not want to use C locales. (Code using this 671*088332b5SXin Li ** macro must include the header 'locale.h'.) 672*088332b5SXin Li */ 673*088332b5SXin Li #if !defined(lua_getlocaledecpoint) 674*088332b5SXin Li #define lua_getlocaledecpoint() (localeconv()->decimal_point[0]) 675*088332b5SXin Li #endif 676*088332b5SXin Li 677*088332b5SXin Li /* }================================================================== */ 678*088332b5SXin Li 679*088332b5SXin Li 680*088332b5SXin Li /* 681*088332b5SXin Li ** {================================================================== 682*088332b5SXin Li ** Language Variations 683*088332b5SXin Li ** ===================================================================== 684*088332b5SXin Li */ 685*088332b5SXin Li 686*088332b5SXin Li /* 687*088332b5SXin Li @@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some 688*088332b5SXin Li ** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from 689*088332b5SXin Li ** numbers to strings. Define LUA_NOCVTS2N to turn off automatic 690*088332b5SXin Li ** coercion from strings to numbers. 691*088332b5SXin Li */ 692*088332b5SXin Li /* #define LUA_NOCVTN2S */ 693*088332b5SXin Li /* #define LUA_NOCVTS2N */ 694*088332b5SXin Li 695*088332b5SXin Li 696*088332b5SXin Li /* 697*088332b5SXin Li @@ LUA_USE_APICHECK turns on several consistency checks on the C API. 698*088332b5SXin Li ** Define it as a help when debugging C code. 699*088332b5SXin Li */ 700*088332b5SXin Li #if defined(LUA_USE_APICHECK) 701*088332b5SXin Li #include <assert.h> 702*088332b5SXin Li #define luai_apicheck(l,e) assert(e) 703*088332b5SXin Li #endif 704*088332b5SXin Li 705*088332b5SXin Li /* }================================================================== */ 706*088332b5SXin Li 707*088332b5SXin Li 708*088332b5SXin Li /* 709*088332b5SXin Li ** {================================================================== 710*088332b5SXin Li ** Macros that affect the API and must be stable (that is, must be the 711*088332b5SXin Li ** same when you compile Lua and when you compile code that links to 712*088332b5SXin Li ** Lua). 713*088332b5SXin Li ** ===================================================================== 714*088332b5SXin Li */ 715*088332b5SXin Li 716*088332b5SXin Li /* 717*088332b5SXin Li @@ LUAI_MAXSTACK limits the size of the Lua stack. 718*088332b5SXin Li ** CHANGE it if you need a different limit. This limit is arbitrary; 719*088332b5SXin Li ** its only purpose is to stop Lua from consuming unlimited stack 720*088332b5SXin Li ** space (and to reserve some numbers for pseudo-indices). 721*088332b5SXin Li ** (It must fit into max(size_t)/32.) 722*088332b5SXin Li */ 723*088332b5SXin Li #if LUAI_IS32INT 724*088332b5SXin Li #define LUAI_MAXSTACK 1000000 725*088332b5SXin Li #else 726*088332b5SXin Li #define LUAI_MAXSTACK 15000 727*088332b5SXin Li #endif 728*088332b5SXin Li 729*088332b5SXin Li 730*088332b5SXin Li /* 731*088332b5SXin Li @@ LUA_EXTRASPACE defines the size of a raw memory area associated with 732*088332b5SXin Li ** a Lua state with very fast access. 733*088332b5SXin Li ** CHANGE it if you need a different size. 734*088332b5SXin Li */ 735*088332b5SXin Li #define LUA_EXTRASPACE (sizeof(void *)) 736*088332b5SXin Li 737*088332b5SXin Li 738*088332b5SXin Li /* 739*088332b5SXin Li @@ LUA_IDSIZE gives the maximum size for the description of the source 740*088332b5SXin Li @@ of a function in debug information. 741*088332b5SXin Li ** CHANGE it if you want a different size. 742*088332b5SXin Li */ 743*088332b5SXin Li #define LUA_IDSIZE 60 744*088332b5SXin Li 745*088332b5SXin Li 746*088332b5SXin Li /* 747*088332b5SXin Li @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. 748*088332b5SXin Li */ 749*088332b5SXin Li #define LUAL_BUFFERSIZE ((int)(16 * sizeof(void*) * sizeof(lua_Number))) 750*088332b5SXin Li 751*088332b5SXin Li 752*088332b5SXin Li /* 753*088332b5SXin Li @@ LUAI_MAXALIGN defines fields that, when used in a union, ensure 754*088332b5SXin Li ** maximum alignment for the other items in that union. 755*088332b5SXin Li */ 756*088332b5SXin Li #define LUAI_MAXALIGN lua_Number n; double u; void *s; lua_Integer i; long l 757*088332b5SXin Li 758*088332b5SXin Li /* }================================================================== */ 759*088332b5SXin Li 760*088332b5SXin Li 761*088332b5SXin Li 762*088332b5SXin Li 763*088332b5SXin Li 764*088332b5SXin Li /* =================================================================== */ 765*088332b5SXin Li 766*088332b5SXin Li /* 767*088332b5SXin Li ** Local configuration. You can use this space to add your redefinitions 768*088332b5SXin Li ** without modifying the main part of the file. 769*088332b5SXin Li */ 770*088332b5SXin Li 771*088332b5SXin Li 772*088332b5SXin Li 773*088332b5SXin Li 774*088332b5SXin Li 775*088332b5SXin Li #endif 776*088332b5SXin Li 777