lua-users home
lua-l archive

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

Hi Dirk.

Your test for required modules is possible already.

  if not package.loaded.bit32 then

And yes, you are right, the _VERSION-string could be easier to test.
It should be a array instead a string containing:

  _VERSION = {
    copyright = "Lua-5.3 #some more text if wanted."
                -- "5.3" can easily extracted. its between first "-"
                -- and first space.
    api_version = 53     -- int: version * 10
    jit_version = 50     -- int: if luajit is running, else: nil
    -- more fields if necessary ...

Ulrich Schmidt.

Am 26.03.2014 07:46, schrieb Dirk Laurie:
There seems to be no way of making Lua code say politely:
"This program requires Lua 5.3" when running under Lua 5.2.
Instead, one gets a nasty message like

./myprog.lua:28: unexpected symbol near '&'

as soon as it hits a bitwise operator.

But maybe it is not late for next time round.  We are already
ignoring one leading `#` line. We could equally well ignore
all leading `#` lines and tag some of them as expressions to be
asserted _before_ proceeding to lexical analysis of the file.
This would allow elegant version control and more.


#! /usr/bin/env lua
#@ _VERSION >= 6.0
#@ bit32

When Lua 5.3 runs this program, or Lua 6.0 runs it without
having preloaded a bit32 library, the rest of the file would not
even be looked at.