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