aboutsummaryrefslogtreecommitdiff
path: root/luaconf.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-02-05 15:30:34 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-02-05 15:30:34 -0300
commitdee6433a89b088a1f8da9531a92a2a2693e5dac7 (patch)
treedac046884812c40d8f3cec9b2215626d30f79e7b /luaconf.h
parent2bfa13e520e53210b96ead88f49a9ca20c5a5d18 (diff)
downloadlua-dee6433a89b088a1f8da9531a92a2a2693e5dac7.tar.gz
lua-dee6433a89b088a1f8da9531a92a2a2693e5dac7.tar.bz2
lua-dee6433a89b088a1f8da9531a92a2a2693e5dac7.zip
Forbid changing numerical types through compiler options
'luaconf.h' always defines options LUA_32BITS, LUA_C89_NUMBERS, LUA_INT_TYPE, and LUA_FLOAT_TYPE (using 0/1 for the first two), to avoid they being set through compiler options. (It is too easy to forget these options when compiling other software that interoperates with Lua.)
Diffstat (limited to 'luaconf.h')
-rw-r--r--luaconf.h83
1 files changed, 42 insertions, 41 deletions
diff --git a/luaconf.h b/luaconf.h
index d9cf18ca..a44858c4 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -16,13 +16,13 @@
16** =================================================================== 16** ===================================================================
17** General Configuration File for Lua 17** General Configuration File for Lua
18** 18**
19** Some definitions here can be changed externally, through the 19** Some definitions here can be changed externally, through the compiler
20** compiler (e.g., with '-D' options). Those are protected by 20** (e.g., with '-D' options): They are commented out or protected
21** '#if !defined' guards. However, several other definitions should 21** by '#if !defined' guards. However, several other definitions
22** be changed directly here, either because they affect the Lua 22** should be changed directly here, either because they affect the
23** ABI (by making the changes here, you ensure that all software 23** Lua ABI (by making the changes here, you ensure that all software
24** connected to Lua, such as C libraries, will be compiled with the 24** connected to Lua, such as C libraries, will be compiled with the same
25** same configuration); or because they are seldom changed. 25** configuration); or because they are seldom changed.
26** 26**
27** Search for "@@" to find all configurable definitions. 27** Search for "@@" to find all configurable definitions.
28** =================================================================== 28** ===================================================================
@@ -81,27 +81,13 @@
81 81
82/* 82/*
83** {================================================================== 83** {==================================================================
84** Configuration for Number types. 84** Configuration for Number types. These options should not be
85** set externally, because any other code connected to Lua must
86** use the same configuration.
85** =================================================================== 87** ===================================================================
86*/ 88*/
87 89
88/* 90/*
89@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats.
90*/
91/* #define LUA_32BITS */
92
93
94/*
95@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
96** C89 ('long' and 'double'); Windows always has '__int64', so it does
97** not need to use this case.
98*/
99#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)
100#define LUA_C89_NUMBERS
101#endif
102
103
104/*
105@@ LUA_INT_TYPE defines the type for Lua integers. 91@@ LUA_INT_TYPE defines the type for Lua integers.
106@@ LUA_FLOAT_TYPE defines the type for Lua floats. 92@@ LUA_FLOAT_TYPE defines the type for Lua floats.
107** Lua should work fine with any mix of these options supported 93** Lua should work fine with any mix of these options supported
@@ -121,7 +107,31 @@
121#define LUA_FLOAT_DOUBLE 2 107#define LUA_FLOAT_DOUBLE 2
122#define LUA_FLOAT_LONGDOUBLE 3 108#define LUA_FLOAT_LONGDOUBLE 3
123 109
124#if defined(LUA_32BITS) /* { */ 110
111/* Default configuration ('long long' and 'double', for 64-bit Lua) */
112#define LUA_INT_DEFAULT LUA_INT_LONGLONG
113#define LUA_FLOAT_DEFAULT LUA_FLOAT_DOUBLE
114
115
116/*
117@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats.
118*/
119#define LUA_32BITS 0
120
121
122/*
123@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
124** C89 ('long' and 'double'); Windows always has '__int64', so it does
125** not need to use this case.
126*/
127#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)
128#define LUA_C89_NUMBERS 1
129#else
130#define LUA_C89_NUMBERS 0
131#endif
132
133
134#if LUA_32BITS /* { */
125/* 135/*
126** 32-bit integers and 'float' 136** 32-bit integers and 'float'
127*/ 137*/
@@ -132,26 +142,21 @@
132#endif 142#endif
133#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT 143#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT
134 144
135#elif defined(LUA_C89_NUMBERS) /* }{ */ 145#elif LUA_C89_NUMBERS /* }{ */
136/* 146/*
137** largest types available for C89 ('long' and 'double') 147** largest types available for C89 ('long' and 'double')
138*/ 148*/
139#define LUA_INT_TYPE LUA_INT_LONG 149#define LUA_INT_TYPE LUA_INT_LONG
140#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE 150#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
141 151
142#endif /* } */ 152#else /* }{ */
153/* use defaults */
143 154
155#define LUA_INT_TYPE LUA_INT_DEFAULT
156#define LUA_FLOAT_TYPE LUA_FLOAT_DEFAULT
144 157
145/* 158#endif /* } */
146** default configuration for 64-bit Lua ('long long' and 'double')
147*/
148#if !defined(LUA_INT_TYPE)
149#define LUA_INT_TYPE LUA_INT_LONGLONG
150#endif
151 159
152#if !defined(LUA_FLOAT_TYPE)
153#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
154#endif
155 160
156/* }================================================================== */ 161/* }================================================================== */
157 162
@@ -373,14 +378,13 @@
373 378
374/* 379/*
375** {================================================================== 380** {==================================================================
376** Configuration for Numbers. 381** Configuration for Numbers (low-level part).
377** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_* 382** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*
378** satisfy your needs. 383** satisfy your needs.
379** =================================================================== 384** ===================================================================
380*/ 385*/
381 386
382/* 387/*
383@@ LUA_NUMBER is the floating-point type used by Lua.
384@@ LUAI_UACNUMBER is the result of a 'default argument promotion' 388@@ LUAI_UACNUMBER is the result of a 'default argument promotion'
385@@ over a floating number. 389@@ over a floating number.
386@@ l_floatatt(x) corrects float attribute 'x' to the proper float type 390@@ l_floatatt(x) corrects float attribute 'x' to the proper float type
@@ -473,10 +477,7 @@
473 477
474 478
475/* 479/*
476@@ LUA_INTEGER is the integer type used by Lua.
477**
478@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER. 480@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.
479**
480@@ LUAI_UACINT is the result of a 'default argument promotion' 481@@ LUAI_UACINT is the result of a 'default argument promotion'
481@@ over a LUA_INTEGER. 482@@ over a LUA_INTEGER.
482@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers. 483@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.