The Lua Architecture
Advanced Topics in Software Engineering
Mark Stroetzel Glasberg Jim Bresler Yongmin 'Kevin' Cho
Lua is a powerful light-weight programming language designed to extend applications. Lua started as a small language with modest goals. The language has grown incrementally. As a result, Lua has been re-architected and rewritten several times in the past ten years. The original functional requirements and motivation of the architecture were documented in the paper “Lua-an extensible extension language” . A few other versions of the language were briefly described in “The Evolution of an Extension Language: A History of Lua” . The architecture and implementation was created and is maintained by Roberto Ierusalimschy, Waldemar Celes and Luiz Henrique de Figueiredo at the Computer Graphics Technology Group of the Pontifical Catholic University of Rio de Janeiro in Brazil (PUC-Rio). Lua’s implementation consists of a small library of ANSI C functions that compiles unmodified in all known platforms. The implementation goals are simplicity, efficiency, portability, and the ability to run on small devices with limited capabilities. These implementation goals resulted is a fast language engine with small footprint, making it ideal in embedded systems. This paper reconstructs and documents the architecture of Lua version 5.0.2. Lua 5.0.2 contains approximately 25,000 lines of source code. The code base uses an instance of the compiler reference model, has several identifiable patterns, and is divided into clearly defined modules such as the code interpreter, parser and virtual machine. The language is being used in several projects at Tecgraf, PUC-Rio, University of Illinois at Urbana-Champaign and in several industry companies such as Microsoft, LucasArts Entertainment, and others.
Lua’s main quality attributes, which are simplicity, performance, flexibility, and portability, were driven by the business requirements of projects developed at Tecgraf. Tecgraf is a Computer Graphics Technology Group created in May 1987 in a partnership between PETROBRAS (the Brazilian main oil company) and the Pontifical Catholic University of Rio de Janeiro - PUC-Rio. Its purpose is to develop, establish, and maintain computer graphics and user interface software for technical and scientific applications.
The first project in which Lua was used needed to represent data for graphic simulators. This rudimentary ancestor of Lua was not a script language, but a data representation language. Because graphic information is naturally large, high performance was the first attribute to be considered. When users began to demand more power from this data 2
representation language - such as the use of boolean expressions, conditional control and loops - it was clear that a true programming language was needed. Data description played an important role in the evolution of Lua as different projects at Tecgraf were adopting Lua. Therefore, Lua had to be easily customizable for each application. Lua adopted the use of semi-structured data in the form of associative arrays. Moreover, metamethods (explained later) were introduced in the language to provide additional flexibility to data access. Portability was an important issue for Lua. At the time, Tecgraf’s main client, PETROBRAS, required all developed systems to be capable to run on a wide range of computers systems. Finally, the business drivers also originated other functional requirements such as concurrency support, string pattern matching, garbage collection, and namespaces for modules. Most of these functionalities were added at a later point in the evolution of the language.
Quality Attributes and Tactics
As a result of its business drivers, Lua’s main quality attributes were not only performance, portability, and extensibility, but also simplicity, availability, and compactness. The development process...
Please join StudyMode to read the full document