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