[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Derive LUA_VERSION_MAJOR from LUA_VERSION_MAJOR_NUM etc. [Re: In `lua.h`, `LUA_VERSION_RELEASE_NUM` does not reflect `LUA_VERSION_RELEASE`]
- From: Thorkil Naur <naur@...>
- Date: Wed, 13 Jan 2021 18:04:24 +0100
Hello,
The following code demonstrates a technique for reducing redundancy in
defining LUA_VERSION etc.:
> #include <stdio.h>
>
> #define Stringize0( x ) #x
> #define Stringize( x ) Stringize0( x )
>
> #define LUA_VERSION_MAJOR_NUM 5
> #define LUA_VERSION_MAJOR Stringize( LUA_VERSION_MAJOR_NUM )
> #define LUA_VERSION_MINOR_NUM 4
> #define LUA_VERSION_MINOR Stringize( LUA_VERSION_MINOR_NUM )
> #define LUA_VERSION_NUM LUA_VERSION_MAJOR_NUM * 100 + LUA_VERSION_MINOR_NUM
> #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
>
> int main( int argc, char *argv[] ) {
> printf( "LUA_VERSION_MAJOR_NUM=%d\n", LUA_VERSION_MAJOR_NUM );
> printf( "LUA_VERSION_MAJOR=<%s>\n", LUA_VERSION_MAJOR );
> printf( "LUA_VERSION_MINOR_NUM=%d\n", LUA_VERSION_MINOR_NUM );
> printf( "LUA_VERSION_MINOR=<%s>\n", LUA_VERSION_MINOR );
> printf( "LUA_VERSION_NUM=%d\n", LUA_VERSION_NUM );
> printf( "LUA_VERSION=<%s>\n", LUA_VERSION );
> }
Running this program produces the output:
> LUA_VERSION_MAJOR_NUM=5
> LUA_VERSION_MAJOR=<5>
> LUA_VERSION_MINOR_NUM=4
> LUA_VERSION_MINOR=<4>
> LUA_VERSION_NUM=504
> LUA_VERSION=<Lua 5.4>
Whether the added obscurity by using this technique is worth the reduced
redundancy is not for me to decide.
Best
Thorkil