diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-10-30 16:50:03 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-10-30 16:50:03 -0200 |
commit | 80e817719de40823622f0c91288d129293373875 (patch) | |
tree | d302b33c1c855981e151ff44c717aa6e6c27ee15 /luaconf.h | |
parent | 96f3a31b24074b2ce77d00599e694d1d04e9e556 (diff) | |
download | lua-80e817719de40823622f0c91288d129293373875.tar.gz lua-80e817719de40823622f0c91288d129293373875.tar.bz2 lua-80e817719de40823622f0c91288d129293373875.zip |
default changed from C89 to C99 + extra tests before using C99
features (when possible) + LUA_32BITS use 'int' when possible
('long' can be 64 bits)
Diffstat (limited to 'luaconf.h')
-rw-r--r-- | luaconf.h | 174 |
1 files changed, 92 insertions, 82 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: luaconf.h,v 1.224 2014/10/27 19:21:56 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.225 2014/10/29 18:01:26 roberto Exp roberto $ |
3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -8,9 +8,12 @@ | |||
8 | #ifndef lconfig_h | 8 | #ifndef lconfig_h |
9 | #define lconfig_h | 9 | #define lconfig_h |
10 | 10 | ||
11 | #include <limits.h> | ||
12 | #include <stddef.h> | ||
13 | |||
11 | 14 | ||
12 | /* | 15 | /* |
13 | ** ================================================================== | 16 | ** =================================================================== |
14 | ** Search for "@@" to find all configurable definitions. | 17 | ** Search for "@@" to find all configurable definitions. |
15 | ** =================================================================== | 18 | ** =================================================================== |
16 | */ | 19 | */ |
@@ -18,73 +21,43 @@ | |||
18 | 21 | ||
19 | /* | 22 | /* |
20 | ** {================================================================== | 23 | ** {================================================================== |
21 | @@ LUA_INT_INT / LUA_INT_LONG / LUA_INT_LONGLONG defines type for | 24 | ** System Configuration: macros to adapt (if needed) Lua to some |
22 | ** Lua integers; you must define one of them. | 25 | ** particular platform, for instance compiling it as Small Lua (32 |
23 | @@ LUA_REAL_FLOAT / LUA_REAL_DOUBLE / LUA_REAL_LONGDOUBLE defines | 26 | ** bits) or restricting it to C89. |
24 | ** type for Lua floats. You must define one of them. | 27 | ** =================================================================== |
25 | ** | ||
26 | ** These definitions set the numeric types for Lua. Lua should work | ||
27 | ** fine with any mix of these previous options (if supported by your | ||
28 | ** C compiler). The usual configurations are 64-bit integers and | ||
29 | ** 'double' (the default) and 32-bit integers and 'float' (Small Lua, | ||
30 | ** for restricted platforms). | ||
31 | ** | ||
32 | ** Note that C compilers not compliant with C99 may not have | ||
33 | ** support for 'long long'. In that case, you should not use option | ||
34 | ** 'LUA_INT_LONGLONG'; use instead option 'LUA_32BITS' for Small Lua | ||
35 | ** (see below), or LUA_INT_LONG plus LUA_REAL_DOUBLE for an interpreter | ||
36 | ** with 32-bit integers and double floating-point numbers. | ||
37 | ** ===================================================================== | ||
38 | */ | 28 | */ |
39 | 29 | ||
40 | /* | 30 | /* |
41 | ** Just uncomment the next line for Small Lua; you can also define | 31 | @@ LUA_32BITS enables Small Lua (that is, Lua with 32-bit integers |
42 | ** LUA_32BITS in the make file, but changing here you ensure that | 32 | ** and 32-bit floats). You can also define LUA_32BITS in the make file, |
43 | ** all software connected to Lua will be compiled with the same | 33 | ** but changing here you ensure that all software connected to Lua will |
44 | ** configuration. | 34 | ** be compiled with the same configuration. |
45 | */ | 35 | */ |
46 | /* #define LUA_32BITS */ | 36 | /* #define LUA_32BITS */ |
47 | 37 | ||
48 | #if !defined(LUA_32BITS) && !defined(LUA_ANSI) | ||
49 | #define LUA_INT_LONGLONG | ||
50 | #define LUA_REAL_DOUBLE | ||
51 | #else /* Lua 32 bits */ | ||
52 | #define LUA_INT_LONG | ||
53 | #define LUA_REAL_FLOAT | ||
54 | #endif | ||
55 | |||
56 | /* }================================================================== */ | ||
57 | |||
58 | |||
59 | 38 | ||
60 | /* | 39 | /* |
61 | ** {================================================================== | 40 | @@ LUA_USE_C89 controls the use of non-ansi-C89 features. |
62 | ** System Configuration | 41 | ** Define it if you want Lua to avoid the use of a few C99 features. |
63 | ** =================================================================== | ||
64 | */ | 42 | */ |
43 | /* #define LUA_USE_C89 */ | ||
44 | |||
65 | 45 | ||
66 | /* | 46 | /* |
67 | @@ LUA_ANSI controls the use of non-ansi features. | 47 | ** By default, Lua on Windows use (some) specific Windows features |
68 | ** CHANGE it (define it) if you want Lua to avoid the use of any | ||
69 | ** non-ansi feature or library. | ||
70 | */ | 48 | */ |
71 | #if !defined(LUA_ANSI) && defined(__STRICT_ANSI__) | 49 | #if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE) |
72 | #define LUA_ANSI | 50 | #define LUA_USE_WINDOWS /* enable goodies for regular Windows */ |
73 | #endif | 51 | #endif |
74 | 52 | ||
75 | 53 | ||
76 | #if !defined(LUA_ANSI) && defined(_WIN32) && !defined(_WIN32_WCE) | 54 | #if defined(LUA_USE_WINDOWS) |
77 | #define LUA_WIN /* enable goodies for regular Windows platforms */ | 55 | #define LUA_DL_DLL /* enable support for DLL */ |
78 | #endif | 56 | #define LUA_USE_C89 /* broadly, Windows is C89 */ |
79 | |||
80 | #if defined(LUA_WIN) | ||
81 | #define LUA_DL_DLL | ||
82 | #define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */ | ||
83 | #endif | 57 | #endif |
84 | 58 | ||
85 | 59 | ||
86 | #if defined(LUA_USE_LINUX) | 60 | #if defined(LUA_USE_LINUX) |
87 | #define LUA_USE_C99 | ||
88 | #define LUA_USE_POSIX | 61 | #define LUA_USE_POSIX |
89 | #define LUA_USE_DLOPEN /* needs an extra library: -ldl */ | 62 | #define LUA_USE_DLOPEN /* needs an extra library: -ldl */ |
90 | #define LUA_USE_READLINE /* needs some extra libraries */ | 63 | #define LUA_USE_READLINE /* needs some extra libraries */ |
@@ -92,19 +65,67 @@ | |||
92 | 65 | ||
93 | 66 | ||
94 | #if defined(LUA_USE_MACOSX) | 67 | #if defined(LUA_USE_MACOSX) |
95 | #define LUA_USE_C99 | ||
96 | #define LUA_USE_POSIX | 68 | #define LUA_USE_POSIX |
97 | #define LUA_USE_DLOPEN /* does not need -ldl */ | 69 | #define LUA_USE_DLOPEN /* MacOS does not need -ldl */ |
98 | #define LUA_USE_READLINE /* needs an extra library: -lreadline */ | 70 | #define LUA_USE_READLINE /* needs an extra library: -lreadline */ |
99 | #endif | 71 | #endif |
100 | 72 | ||
101 | /* }================================================================== */ | ||
102 | 73 | ||
103 | 74 | ||
75 | /* | ||
76 | @@ LUAI_BITSINT defines the (minimum) number of bits in an int. | ||
77 | ** CHANGE here if Lua cannot automatically detect the number of bits of | ||
78 | ** your machine. Probably you do not need to change this. | ||
79 | */ | ||
80 | /* avoid undefined shifts */ | ||
81 | #if ((INT_MAX >> 15) >> 15) >= 1 | ||
82 | #define LUAI_BITSINT 32 | ||
83 | #else | ||
84 | /* 'int' always must have at least 16 bits */ | ||
85 | #define LUAI_BITSINT 16 | ||
86 | #endif | ||
87 | |||
88 | |||
89 | /* | ||
90 | @@ LUA_INT_INT / LUA_INT_LONG / LUA_INT_LONGLONG defines the type for | ||
91 | ** Lua integers. | ||
92 | @@ LUA_REAL_FLOAT / LUA_REAL_DOUBLE / LUA_REAL_LONGDOUBLE defines | ||
93 | ** the type for Lua floats. | ||
94 | ** Lua should work fine with any mix of these options (if supported by | ||
95 | ** your C compiler). The usual configurations are 64-bit integers and | ||
96 | ** 'double' (the default) and 32-bit integers and 'float' (Small Lua, | ||
97 | ** for restricted platforms). C compilers not compliant with C99 may | ||
98 | ** not have support for 'long long', so the default in that case is | ||
99 | ** 'long'/'double'. | ||
100 | */ | ||
101 | |||
102 | #if defined(LUA_32BITS) /* { */ | ||
103 | |||
104 | /* Small Lua */ | ||
105 | #if LUAI_BITSINT >= 32 /* use 'int' if big enough */ | ||
106 | #define LUA_INT_INT | ||
107 | #else /* otherwise use 'long' */ | ||
108 | #define LUA_INT_LONG | ||
109 | #endif | ||
110 | #define LUA_REAL_FLOAT | ||
111 | |||
112 | #elif defined(LUA_USE_C89) /* }{ */ | ||
113 | |||
114 | /* use largerst types available for C89 ('long' and 'double') */ | ||
115 | #define LUA_INT_LONG | ||
116 | #define LUA_REAL_DOUBLE | ||
117 | |||
118 | #else /* }{ */ | ||
119 | |||
120 | /* default configuration for 64-bit Lua ('long long' and 'double') */ | ||
121 | #define LUA_INT_LONGLONG | ||
122 | #define LUA_REAL_DOUBLE | ||
123 | |||
124 | #endif /* } */ | ||
125 | |||
126 | /* }================================================================== */ | ||
104 | 127 | ||
105 | 128 | ||
106 | #include <limits.h> | ||
107 | #include <stddef.h> | ||
108 | 129 | ||
109 | 130 | ||
110 | /* | 131 | /* |
@@ -346,21 +367,6 @@ | |||
346 | 367 | ||
347 | 368 | ||
348 | /* | 369 | /* |
349 | @@ LUAI_BITSINT defines the (minimum) number of bits in an int. | ||
350 | ** CHANGE here if Lua cannot automatically detect the number of bits of | ||
351 | ** your machine. Probably you do not need to change this. | ||
352 | */ | ||
353 | /* avoid undefined shifts */ | ||
354 | #if ((INT_MAX >> 15) >> 15) >= 1 | ||
355 | #define LUAI_BITSINT 32 | ||
356 | #else | ||
357 | /* 'int' always must have at least 16 bits */ | ||
358 | #define LUAI_BITSINT 16 | ||
359 | #endif | ||
360 | |||
361 | |||
362 | |||
363 | /* | ||
364 | ** {================================================================== | 370 | ** {================================================================== |
365 | ** Configuration for Numbers. | 371 | ** Configuration for Numbers. |
366 | ** Change these definitions if no predefined LUA_REAL_* / LUA_INT_* | 372 | ** Change these definitions if no predefined LUA_REAL_* / LUA_INT_* |
@@ -378,7 +384,7 @@ | |||
378 | @@ LUA_NUMBER_FMT is the format for writing floats. | 384 | @@ LUA_NUMBER_FMT is the format for writing floats. |
379 | @@ lua_number2str converts a float to a string. | 385 | @@ lua_number2str converts a float to a string. |
380 | ** | 386 | ** |
381 | @@ l_mathop allows the addition of an 'l' or 'f' to all math operations | 387 | @@ l_mathop allows the addition of an 'l' or 'f' to all math operations. |
382 | ** | 388 | ** |
383 | @@ lua_str2number converts a decimal numeric string to a number. | 389 | @@ lua_str2number converts a decimal numeric string to a number. |
384 | */ | 390 | */ |
@@ -533,7 +539,7 @@ | |||
533 | 539 | ||
534 | #elif defined(LUA_INT_LONGLONG) /* }{ long long */ | 540 | #elif defined(LUA_INT_LONGLONG) /* }{ long long */ |
535 | 541 | ||
536 | #if defined(LUA_WIN) | 542 | #if defined(LUA_USE_WINDOWS) |
537 | 543 | ||
538 | #define LUA_INTEGER __int64 | 544 | #define LUA_INTEGER __int64 |
539 | #define LUA_INTEGER_FRMLEN "I64" | 545 | #define LUA_INTEGER_FRMLEN "I64" |
@@ -544,7 +550,8 @@ | |||
544 | #else | 550 | #else |
545 | 551 | ||
546 | #if !defined(LLONG_MAX) | 552 | #if !defined(LLONG_MAX) |
547 | #error "Compiler does not support 'long long'. See file 'luaconf.h' line 24" | 553 | #error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \ |
554 | or '-DLUA_USE_C89' (see file 'luaconf.h' for details)" | ||
548 | #endif | 555 | #endif |
549 | 556 | ||
550 | #define LUA_INTEGER long long | 557 | #define LUA_INTEGER long long |
@@ -596,7 +603,7 @@ | |||
596 | ** leave 'lua_strx2number' undefined and Lua will provide its own | 603 | ** leave 'lua_strx2number' undefined and Lua will provide its own |
597 | ** implementation. | 604 | ** implementation. |
598 | */ | 605 | */ |
599 | #if defined(LUA_USE_C99) | 606 | #if !defined(LUA_USE_C89) |
600 | #define lua_strx2number(s,p) lua_str2number(s,p) | 607 | #define lua_strx2number(s,p) lua_str2number(s,p) |
601 | #endif | 608 | #endif |
602 | 609 | ||
@@ -604,21 +611,23 @@ | |||
604 | /* | 611 | /* |
605 | @@ LUA_USE_AFORMAT allows '%a'/'%A' specifiers in 'string.format' | 612 | @@ LUA_USE_AFORMAT allows '%a'/'%A' specifiers in 'string.format' |
606 | ** Enable it if the C function 'printf' supports these specifiers. | 613 | ** Enable it if the C function 'printf' supports these specifiers. |
607 | ** (C99 demands it.) | 614 | ** (C99 demands it and Windows also supports it.) |
608 | */ | 615 | */ |
609 | #if !defined(LUA_USE_AFORMAT) && defined(LUA_USE_C99) | 616 | #if !defined(LUA_USE_C89) || defined(LUA_USE_WINDOWS) |
610 | #define LUA_USE_AFORMAT | 617 | #define LUA_USE_AFORMAT |
611 | #endif | 618 | #endif |
612 | 619 | ||
613 | 620 | ||
614 | /* | 621 | /* |
615 | ** 'strtof' and 'opf' variants for math functions are valid only | 622 | ** 'strtof' and 'opf' variants for math functions are not valid in |
616 | ** in C99 | 623 | ** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the |
624 | ** availability of these variants. ('math.h' is already included in | ||
625 | ** all files that use these macros.) | ||
617 | */ | 626 | */ |
618 | #if !defined(LUA_USE_C99) | 627 | #if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF)) |
619 | #undef l_mathop | 628 | #undef l_mathop /* variants not available */ |
620 | #undef lua_str2number | 629 | #undef lua_str2number |
621 | #define l_mathop(op) (lua_Number)op | 630 | #define l_mathop(op) (lua_Number)op /* no variant */ |
622 | #define lua_str2number(s,p) ((lua_Number)strtod((s), (p))) | 631 | #define lua_str2number(s,p) ((lua_Number)strtod((s), (p))) |
623 | #endif | 632 | #endif |
624 | 633 | ||
@@ -631,7 +640,8 @@ | |||
631 | */ | 640 | */ |
632 | #define LUA_KCONTEXT ptrdiff_t | 641 | #define LUA_KCONTEXT ptrdiff_t |
633 | 642 | ||
634 | #if defined (LUA_USE_C99) | 643 | #if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \ |
644 | __STDC_VERSION__ >= 199901L | ||
635 | #include <stdint.h> | 645 | #include <stdint.h> |
636 | #if defined (INTPTR_MAX) /* even in C99 this type is optional */ | 646 | #if defined (INTPTR_MAX) /* even in C99 this type is optional */ |
637 | #undef LUA_KCONTEXT | 647 | #undef LUA_KCONTEXT |