This page is dedicated to information on ensuring that Lua code remains compatible across multiple versions of Lua (e.g. 5.1 and
LuaFiveTwo), as well as different
LuaImplementations.
- The Lua Reference Manual lists "Incompatibilities with the Previous Version" [5.1] [5.2-alpha]. The Lua 5.2.0-alpha documentation lists [Changes since 5.1] (see also LuaFiveTwo).
- Bytecode: Lua 5.1 and Lua 5.2.0-alpha are not bytecode compatible, and LuaJit 2.x doesn't support the standard Lua interpreter's bytecodes. Even within a single version of Lua (5.1), bytecode on different platforms (e.g. Intel x86, Intel x86-64, and PPC) may not be compatible. Source code is more compatible, and source code can be minified (e.g. see squish: CompressionAndArchiving). This typically affects C modules that bundle compiled bytecode (e.g. via BinToCee) and has affected MetaLua.
- Source lexing: Lua 5.1 and 5.2.0-alpha use the same tokens, although there are some lexical differences involving things like locales [1] and perhaps [4].
- [Lua Compat-5.1] provides an implementation of the Lua 5.1 package model to be used with Lua 5.0.
- CompatibilityWithLuaFive shows how to make your code compatible with all Lua 5.X versions.
- Bit libraries: LuaFiveTwo (5.2.0-alpha) and LuaJit (Lua BitOp) come with different built-in bit libraries, which are compatible to only some extent (e.g. signedness/overflow). Lua BitOp can be installed on 5.2, and see also [bit32 for Lua 5.1?]. [lua-bit-numberlua] provides a bit library with Lua 5.2 "bit32" and LuaBitOp "bit" compatibility interfaces.
- [lua-compat-env] provides Lua 5.1/5.2 environment compatibility functions:
load
, loadfile
, getfenv
, and setfenv
for use in 5.1 and 5.2
- [lua-parser-loose] provides an implementation of
_ENV
in Lua 5.1.
- Version check. The global Lua variable
_VERSION
contains the Lua version string (e.g. "Lua 5.1" [2] or "Lua 5.2" [3]. (Note: LuaJit 2.0-beta reports the Lua version as 5.1.) LuaFiveTwo contains new library functions: [lua_version] and [luaL_checkversion]. In C code, lua.h of Lua 5.1 contains these defines:
#define LUA_VERSION "Lua 5.1"
#define LUA_RELEASE "Lua 5.1.4"
#define LUA_VERSION_NUM 501
- There are reasons to prefer capability detection over version detection [5]. Doing tests like
_VERSION == "Lua 5.2"
will almost certainly break in 5.3. _VERSION ~= "Lua 5.1"
will more likely be forward compatible, though will break in 5.0 (if that matters).
RecentChanges ·
preferences
edit ·
history Last edited March 1, 2014 12:44 pm GMT
(diff)