Incompatibilities with Previous Versions
Lua 5.0 is a major release. There are several incompatibilities with its previous version, Lua 4.0.
Incompatibilities with version 4.0
Changes in the Language
The whole tag-method scheme was replaced by metatables.
Function calls written between parentheses result in exactly one value.
A function call as the last expression in a list constructor (like
{a,b,f()}) has all its return values inserted in the list.The precedence of or is smaller than the precedence of and.
in, false, and true are reserved words.
The old construction
for k,v in t, wheretis a table, is deprecated (although it is still supported). Usefor k,v in pairs(t)instead.When a literal string of the form
[[...]]starts with a newline, this newline is ignored.Upvalues in the form
%varare obsolete; use external local variables instead.
Changes in the Libraries
Most library functions now are defined inside tables. There is a compatibility script (
compat.lua) that redefines most of them as global names.In the math library, angles are expressed in radians. With the compatibility script (
compat.lua), functions still work in degrees.The
callfunction is deprecated. Usef(unpack(tab))instead ofcall(f, tab)for unprotected calls, or the newpcallfunction for protected calls.dofiledoes not handle errors, but simply propagates them.dostringis deprecated. Useloadstringinstead.The
readoption*wis obsolete.The
formatoption%n$is obsolete.
Changes in the API
lua_opendoes not have a stack size as its argument (stacks are dynamic).lua_pushuserdatais deprecated. Uselua_newuserdataorlua_pushlightuserdatainstead.
