It has been announced that the source texts have been opened and the first standalone release of the Luau programming language has been published, continuing the development of Lua and maintaining backward compatibility with Lua 5.1. The Luau language is primarily designed for embedding script handlers in applications and aims for high performance with low resource consumption. The project code is written in C++ and is released under the MIT license.
Luau extends Lua with type checking capabilities and some new syntactic constructs, such as string literals. The language is backward compatible with Lua 5.1 and partially with newer versions. The Lua Runtime API is supported, allowing Luau to be used with existing code and bindings. The language runtime is based on significantly reworked Lua runtime 5.1 code, but the interpreter has been completely rewritten. New optimization techniques have been employed, resulting in higher performance compared to Lua.
The project was developed by Roblox and is used in the code of the gaming platform, games, and user applications of the company, including the Roblox Studio editor. Initially, Luau developed behind closed doors, but it was ultimately decided to open it up as an open-source project for further collaborative development with community involvement.
Main features:
- A gradual type system that occupies an intermediate position between dynamic and static typing. Luau allows for static typing as needed by specifying type information through special annotations. Built-in types such as 'any', 'nil', 'boolean', 'number', 'string', and 'thread' are provided. It retains the ability to use dynamic typing without explicitly defining the types of variables and functions. function foo(x: number, y: string): boolean local k: string = y:rep(x) return k == 'a' end
- Support for string literals (as in Lua 5.3), such as '\0x**' (hexadecimal number), '\u{**}' (Unicode character), and '\z' (end of line), as well as the ability to present numbers visually (you can write 1_000_000 instead of 1000000), and literals for hexadecimal (0x…) and binary numbers (0b…….).
- Support for the expression "continue", complementing the existing keyword "break", to transition to a new iteration of the loop.
- Support for compound assignment operators (+=, -=, *=, /=, %=, ^=, ..=).
- Support for using conditional blocks "if-then-else" in the form of expressions that return values computed during the execution of the block. An arbitrary number of elseif expressions is allowed in the block. local maxValue = if a > b then a else b local sign = if x 0 then 1 else 0
- The presence of a sandbox mode that allows the execution of untrusted code. This feature can be used to run your own code alongside code written by another developer, for example, third-party libraries whose security cannot be guaranteed.
- Restrictions on the standard library from which functions that could potentially create security issues have been removed. For example, the standard set excludes the "io" library (file access and process execution), the "package" library (file access and module loading), the "os" library (functions for file access and changing environment variables are removed), the "debug" library (unsafe memory operations), and "dofile" and "loadfile" (access to the filesystem).
- Providing tools for static code analysis, error identification (linter), and type usage validation.
- Custom high-performance parser, bytecode interpreter, and compiler. Luau does not currently support JIT compilation, but it is claimed that the Luau interpreter is comparable in performance to LuaJIT in certain situations.
Source: opennet.ru
