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...
References:   R. Ierusalimschy, L. H. de Figueiredo, W. Celes, “Lua-An Extensible Extension Language”, Software: Practice & Experience 26 pp 635-652 #6 (1996). L. H. de Figueiredo, R. Ierusalimschy, W. Celes, “The Design and Implementation of a Language for extending applications”, Proceedings of XXI Brazilian Seminar on Software and Hardware, pp 273-283 (1994). R. Ierusalimschy, L. H. de Figueiredo, W. Celes, “The Evolution of an Extension Language: A History Of Lua”, Proceedings of V Brazilian Symposium on Programming Languages B-14--B-28 (2001). L. H. de Figueiredo, R. Ierusalimschy, W. Celes, “Lua: An Extensible Embedded Language a Few Metamechanisms Replace a Host of Features”, Dr. Dobb 's Journal 21 #12 pp 26-33. [DDJ] (Dec 1996) J. Gracia-Martin, M. Sutil-Martin, “The Extreme Compiling Pattern Language” Associative Array at Wikipedia, “http://en.wikipedia.org/wiki/Associative_array” R. Ierusalimschy, L. H. de Figueiredo, W. Celes, “Lua 5.0 Reference Manual”, Technical Report MCC-14/03, PUC-Rio, 2003 L. H. de Figueiredo, R. Ierusalimschy, W. Celes, “The Design And Implementation Of A Language For Extending Applications”, Proceedings of XXI Brazilian Seminar on Software and Hardware pp 273-283 (1994). Len Bass, Paul Clements, and Rick Kazman; “Software Architecture in Practice”, second edition, Apr 9, 2003, Addison-Wesley Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, and Michael Stahl; “Pattern-Oriented Software Architecture: A System of Patterns” 1996, Wiley & Sons Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides; “Design Patterns” 1994, Addison-Wesley “The Kepler Project” at http://www.keplerproject.org, 2004, Fábrica Digital and PUC-Rio “tolua” at http://www.tecgraf.puc-rio.br/~celes/tolua/ , 2004, Tecgraf/PUC-Rio “IUP” http://www.tecgraf.org/iup, 2004, Tecgraf/PUC-Rio “LuaSocket” at http://www.tecgraf.org/luasocket, 2004, Fábrica Digital and PUCRio 17
   
    
     
“Luaorb” at http://www.tecgraf.puc-rio.br/luaorb , 2004, Tecgraf/PUC-Rio John R. Levine, Tony Mason, Doug Brown; “Lex & Yacc” 1992, O 'Reilly & Associates David Jeske, “A Fast Multiple-Inheritance Tag Method Implementation in Lua”, at http://www.lua.org/notes/ltn008.html Lua Technical Note 8. Ana Lúcia de Moura, Noemi Rodriguez, and Roberto Ierusalimschy; “Coroutines in Lua” July 2004 Journal of Universal Computer Science, pp 910-925 10(7). Kein-Hong Man. “A No-Frills Introduction to Lua 5 VM Instructions”, November 28th, 2004 Richard P. Brent; “Reducing the retrieval time of scatter storage techniques”
Please join StudyMode to read the full document