lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Mar 26, 2014, at 2:00 PM, Rena <> wrote:

> That looks a lot like running Lua through the C preprocessor.
> #if LUA_VERSION < 53
> error("Script requires Lua 5.3 or higher")
> #else
> ...script here...
> #endif
> This might just work as long as you don't begin any lines with '#' (a space before it should be fine).
> -- 
> Sent from my Game Boy.

Version number checking is a mine-field, and should be avoided whenever possible. First, code rarely needs to know version information, it’s typically checking for *feature* support indirectly via the logic “Feature K is supported in Lua X.Y, therefore to check for feature K check for Lua X.Y”. it’s far far better to have a mechanism that directly checks for feature support and bypasses the indirect logic entirely.

Why? Because historically coders make a mess of the feature check. The Windows API now contains SEVEN (yes, seven) “get version” APIs many of which are rigged to return (by design) the WRONG version number when asked by certain apps (yes, it has a database of apps and which version it should return). MS had to do this because every time they bump the version number dozens of apps break because they idiotically get the version checking wrong, so they have to “fake” old version to keep the app running.

If this is going to be done elegantly (as per the OP), Lua really needs two things:
— A declarative syntax at the start of a chunk that specifies syntax compatibility (probably a simple numeric value).
— A method to query information about feature presence and support (before/after doing “require” etc).

Neither are trivial to implement at all, let alone well. And i’m not sure i would like the mess of checks that would result.