lua-users home
lua-l archive

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


On Fri, Nov 18, 2011 at 8:29 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
> Moreover, keep in mind that for Lua compiled with LUA_COMPAT_ALL on,
> most of these differences vanish. (LUA_COMPAT_ALL is on in the default
> makefile.)

This is an important point; in particular, module() is going to be
available for a long time.

Old Lua 5.0-isms like local 'arg' are easy to fix and LuaJIT has been
useful in this respect.

There are some gotchas, for instance the return type of os.execute
changes. So my preferred approach has been to write compatibility
routines, and so far I've really had no problems writing Lua that
works with both versions.

In Penlight, the 5.1/5.2 compatibility functions are in pl.utils, lines 200-280

https://github.com/stevedonovan/Penlight/blob/master/lua/pl/utils.lua

There's a version of set/getfenv there as written by Sergey Rozhenko [1]

The approach to functions like load() and os.execute() that have
changed signatures is to define utils.load and utils.execute that
behave consistently.

Separating this code out as lua52-compat.lua would be straightforward.

steve d.

[1] http://lua-users.org/lists/lua-l/2010-06/msg00313.html