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, where t is a table, is deprecated (although it is still supported). Use for 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 %var are 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 call function is deprecated. Use f(unpack(tab)) instead of call(f, tab) for unprotected calls, or the new pcall function for protected calls.

  • dofile does not handle errors, but simply propagates them.

  • dostring is deprecated. Use loadstring instead.

  • The read option *w is obsolete.

  • The format option %n$ is obsolete.

Changes in the API

  • lua_open does not have a stack size as its argument (stacks are dynamic).

  • lua_pushuserdata is deprecated. Use lua_newuserdata or lua_pushlightuserdata instead.