After five years of development, the release of Lua 5.5 is available, a fast and compact scripting language that has gained widespread use as an embedded language for configuration definition and extension writing. The Lua interpreter code is written in C and is distributed under the MIT license.
Lua combines a simple procedural syntax with data description capabilities through the use of associative arrays and the language's extensible semantics. Lua employs dynamic typing, and language constructs are compiled into bytecode that runs on top of a register-based virtual machine with automatic garbage collection. The interpreter is designed as a library, integrable into projects using C and C++.
Key innovations:
- Most garbage collection operations utilize an incremental mode, in which the garbage collection cycle is broken into separate steps that alternate with program execution, allowing for the elimination of lengthy pauses in applications with a large number of objects in memory.
- A compact implementation of arrays has been proposed, which requires 60% less memory for arrays with homogeneous data (the savings are achieved by storing type information not for each element, but for a group of elements).
- The ability to explicitly declare global variables in any code block using the keyword 'global' has been added. When expressions containing the keyword 'global' are specified in a code block, all variables must be explicitly declared. If the 'global' declaration is absent, an implicit 'global *' expression is used, preserving the old behavior where all variables are treated as global. A 'global*' expression has also been added, which makes all implicitly defined global variables available in read-only mode. X = 1 — Ok, X is a global variable, old default behavior. do global Y — declaration of variable Y as global, all other variables in the block must be explicitly declared Y = 1 — Ok, variable Y has been previously defined X = 1 — Error, variable X is not defined end X = 2 — Ok, outside the global block, the old behavior applies.
- The control variables specified in the "for" loops are now read-only and cannot be modified within the loop body. For example, the variable i declared in the loop "for i = 1, 5 do" cannot be changed inside the loop.
- When printing floating-point numbers through the print function, a sufficient number of digits is now displayed for accurate reverse conversion from string to the original representation.
- The allowable number of levels of nested table constructors has been increased.
- The function table.create(nseq, nrec) has been added for creating an empty table and preallocating memory for the specified number of elements.
- In the utf8.offset function, the return now includes not only the byte offset to the start of the character but also the position of the end of the character.
- Support for creating external strings stored in memory not managed by the Lua garbage collector has been added.
- The function luaL_openselectedlibs has been added to load the selected library, along with the function luaL_makeseed that generates a seed for the lua_newstate function.
- Dynamic loading of the 'readline' library in lua.c is provided if it is available (if the library exists in the system — it is loaded and string editing functions become available).
- An optimization for memory saving when loading precompiled bytecode has been implemented — Lua can now reuse memory in some internal structures without creating duplicates when loading duplicate bytecode.
- All strings in the 'dump' and 'undump' operations are reused.
- Buffer reuse (without copying to a new buffer) has been ensured in auxiliary buffers when creating the final string.
Source: opennet.ru
