Lua-r
Lua-r
Universität
Innsbruck
Summer 17.06.2023
Semester
2023
Contents
1 Abstract 3
2 Introduction 3
7 Conclusion 12
2
1 Abstract
Developed in the 1990s, Lua is a powerful and lightweight scripting language and has
become an indispensable tool for software development in recent years. It stands out
for its minimalist syntax and fast execution speed, making it ideal for integration into
other software projects. Embedded into existing systems, Lua provides high performance
and scalability, allowing it to find application in wider areas such as embedded systems,
web development, video games, data analysis and more. In this paper, we report at
the history and evolution of Lua, the necessity of its creation, strengths and limitations
compared to more common-known programming languages.
2 Introduction
Lua, the scripting language, emerged in 1993 within Tecgraf, a research and development
laboratory at PUC-Rio in Brazil. Its creators, Roberto Ierusalimschy, Luiz Henrique de
Figueiredo, and Waldemar Celes, had diverse backgrounds. Roberto was a computer
scientist specializing in programming languages, Luiz Henrique was a mathematician
focused on software tools and computer graphics, and Waldemar was an engineer inter-
ested in the applications of computer graphics.
Tecgraf, known for its collaboration with industrial partners, initially focused on devel-
oping basic software tools to meet the graphical program requirements of its clients. Due
to Brazil’s trade barriers during that time, Tecgraf’s clients faced difficulties obtaining
customized software from abroad. As a result, Tecgraf had to develop its own tools to
fulfill their needs. One of Tecgraf’s significant partners, Petrobras, the Brazilian oil com-
pany, relied on Tecgraf for interactive graphical programs in engineering applications.
They had already created two little languages, DEL and SOL, to serve specific purposes
within Petrobras. These languages laid the foundation for the development of Lua.
Tecgraf’s solution involved the creation of a dozen graphical front-ends that allowed the
engineers to input the numbers by clicking on the relevant parts of the simulation dia-
gram. To streamline the development, Luiz Henrique de Figueiredo and Luiz Cristovao
Gomes Coelho led a team that adopted a uniform coding approach, resulting to the
development of DEL.
3
3.1 DEL
DEL is a simple declarative language that described each data entry task. In a DEL
program, entries were defined with each entry having named and typed fields.
In this code section, entries are created and saved as entities defined under the state-
ment ”:e”. Every entity has a name and fields initialized with values. Below we have
the statement ”:p” which defines a section of predicate logic. This allows for basic data
validation as well as basic input rules.
While an entity in DEL could be associated as record or structure in some other program-
ming languages, there is one essential feature which made DEL suitable for Tecgraf’s
problem: Every entity produced a graphical meta-file with its name and the diagram
in which the engineers entered the data. This allowed the graphical programs to read
those files which could then be visualized for Petrobras with every aspect needed.
Soon, users would require even more from DEL, such as boolean expression, conditional
controls or even loops which the language was not suited for. This led the developer in
Tecgraf to come up and develop a greater programming language.
4
3.2 SOL
SOL stands for simple object language and heavily draws design ideas from BibTex[2]
and UIL. It was created for a different project at the same time DEL was developed.
This project consisted of generating reports, having different columns as well as different
fonts, size and options. Users would be able to create and modify these tracks and each
report would then be saved as file for reuse purposes. Instead of designing a language
that incorporates the objects needed, SOL was designed with type declaration in order
to handle every different type of reports.
We can observe some similarities between the creation of entities in 1 and 2. Both entities
have fields and values initialized as soon as the entity gets declared however SOL is able
to declare the type of the entity, which can be a track, a line or another option and
having their fields and values integrated in said declaration.
”Given the requirements of ED and PGM, we decided that we needed a real programming
language, with assignments, control structures, subroutines, etc. The language should
also offer data-description facilities, such as those offered by SOL. Moreover,because
many potential users of the language were not professional programmers, the language
should avoid cryptic syntax and semantics. The implementation of the new language
should be highly portable, because Tecgraf ’s clients had a very diverse collection of com-
puter platforms. Finally, since we expected that other Tecgraf products would also need
to embed a scripting language, the new language should follow the example of SOL and
be provided as a library with a C API”[3].
5
4.1 Lua 1
Combining both DEL and SOL was very successful and soon started to gain attention
in both Tecgraf and Petrobras as they identified Lua’s potential to support graphic
metafiles. Since it was a procedural language with type declaration, those files were
not relying on other languages to model those object. Lua 1.0 was born. As its user
base started to grow, many more demands were requested, the first one being for better
performance, even with bigger and heavier programs. One of Lua’s first update was
its compiler. Since all programs were precompiled to bytecode, this meant that it had
to run and compile fast. By removing the lex-generated scanner by a self-written one,
the developer achieved almost twice the original compiling speed. They also create
new compiler codes to decrease the amount of compiler instruction and created a new
instruction to help pushing elements from the stack. Instructions of the new compiler
looked like this:
The new instruction ”SETTABLE” allowed all elements within the given index to be
added to the list with only one instruction instead of using two separate instructions
for every single element. This procedure was able to cut instructions in half and also
decreased compile time. These changes were released as version 1.1 but under a restric-
tive license. This would allow using Lua under academic purposes but would prevent
commercial usage. This would prove to be as a big downside for the language as, during
this time, languages like Perl were free to use.
4.2 Lua 2
This version was released in early 1995 and was published as free software, lifting all re-
strictions from the previous versions. This version, 2.1, brought many important changes
for the language as the developer were still focused to increase the simplicity and decrease
compiling time. This caused the first major incompatibilities to older versions. Remov-
ing the ”@” from the constructor assignments was one particular important change as
it simplified a lot of the syntax and the semantics of defining tracks. Another important
update was the introduction of fallback functions. Users had now the ability to write
such functions which are called whenever Lua is stuck or didn’t know how to proceed
in the program. Lua has now become an extensible language. The first fallbacks were
designed for basic arithmetic and comparison but soon would include more functionali-
ties such as string concatenation and table access. Especially for table access, this was
revolutionary as table access in previous version was needed to be exact. With the now
6
added fallbacks, users could define functions for every eventuality or mistakes happening
during the access.
The ability for users to define these fallback functions themselves as compared to hard-
coded fallback functions would not only allow the users to write functions in a way they
need them and only for functionalities they would actually use in that moment, this
would also allow Lua to support object-oriented programming with the ability to write
method for inheritance and operator overloading. This so called ”meta-mechanism”
changed the main design pattern for Lua and in May 1996, these features would be
released as Lua 2.4. Additionally, this version featured a new compiler called luac.
Luac is a external compiler which saves the precompiled code and string tables to a
binary file. This binary file was portable and could avoid parsing and code generation
at run-time. This allowed for low compiling times even for bigger and more costly pro-
grams. Besides portability, luac introduced a syntax check and source code protection.
However, this compiler did not imply fast execution speed. This was merely a save mech-
anism for a file to be executable later. In November 1996, Lua 2.5 was released with its
own pattern-matching engine. This brought two new functions forward. ”strfind” was
able to find any string given to the function and ”gsub” was able to replace substrings
matching a given pattern in a large string. Although there were only a few updates,
this version proved to be the one with the most success on an international level. The
very same year an academic paper was published and Lua made its appearance in many
different magazines and research papers. Lua was even more praised in 1997 as it made
its first use as programming language for game development. In The evolution of an
extension language: a history of Lua, the authors wrote:
”This first use of Lua in a game attracted the attention of many game developers around
the world to the language. Soon after, Lua started to appear frequently in game news-
groups, such as rec.games.programmer and comp.ai.games” [1].
4.3 Lua 3
Within the same year, Lua 3.0 was released, now replacing its fallback methods with
tag methods. Users could now create tags and associate tables and user data to them,
essentially allowing user to create different fallback methods for different tags. At first
these tags were seen as an exception-handling mechanism but soon they were actually
used to represent user-created types. This further boosted object-oriented programming
since now every tag could have its own fallback methods rather than having them glob-
ally for every tag created. Another important feature of Lua 3.1 was the introduction
of functional programming. Users were now able to create anonymous functions and
function closures. Previous, higher functions and functions which take functions as pa-
rameter, like ”gsub”, have benefit by this implementation. Newer version like 3.2 didn’t
bring much change to the language as they were only maintenance releases. The C API,
on which Lua is based on, remained in tact and would not experience changes until Lua
4.0.
7
4.4 Lua 4
This version brought major changes as Lua would receive a new API released in Novem-
ber 2000, introducing multiple Lua states for applications as well as clear stack exchanges
between Lua and C. Lua 4.0 would also introduce for-loops for the first time. In the
paper The Evolution of Lua [3], the authors explained that they couldn’t agree on its
syntax as well as users forgetting to update their control variable in while-loops which
led to infinite loops. The developers finally settled on implementing two different for-
loops: A single, numeric for-loop as well as a table-traversing for-loop, comparable to
foreach-loop in other language.
4.5 Lua 5
Lua 4.1 was next in line but due to the many changes, the developer decided to have
it be version 5.0 instead. Implementations like threads, full lexical scoping and the
substitution of fallbacks with newly introduced, generic for-loops replacing all fallback
methods and tags were now available to use. Over the years, in version 5.1, Lua would
also receive a module system as well as an upgrade to its garbage collector. With the
latest release being Lua 5.6.4, not much has changed from its previous versions as syntax
and semantics remained the same.
8
5.1 Basic instructions and statements
The following instructions are all valid as Lua neither requires semicolons or line sepa-
ration to have them executed. Basic functionalities would also rely on being collected
to a chunk in order for the interpreter to execute them faster. Another common was
was just to use the stand-alone interpreter in the interactive mode. In this mode, Lua
would mostly have single-line chunks but not necessary as the interpreter could detect if
a chunk was not completed and therefor waits for more input to come. In this figure, all
declarations are local. To create a global variable, one has just to define it since there is
no error when accessing a variable or field that has not been initialized yet.
9
fields. This proves to be very effective when it comes to testing as you can include
the files via this method and then print the results of functions, fields, etc. without
debugging or writing tests for it.
In this figure we can observe two types of comments. Lua is also handling false com-
menting very well. If you would add another ”-” to this figure’s comment block, the
instruction remains valid as the compiler simply removes the falsely set comment block,
execute the instruction and would handle the line below as single line comment.
Just like C, Lua also covers basic arithmetic as well as logical and relational operations.
Another useful integration, this time applied from Python, Lua uses ”self” calls when
creating and assigning tables to a variable. Assume a table variable tab1. This now
would mean you can access its fields via tab1.self and tab1.x, tab1.y.
5.5 Constructors
Lua offers constructors to create and initialize tables. The simplest constructor form is
the empty constructor. A big advantage of constructors would be the limitless use of
expressions within since it does not need to use only constants or constant expressions.
Also typing of expressions and constants can be chosen at will.
10
Figure 6: Basic Constructor Instruction [4]
11
There currently exists a modification called ”OpenComputers” [5] where players have
the opportunity to directly code in Lua within a small operating system within the
modification itself. Not only can the players therefor impact many aspects of the main
game, they also have the ability to modify aspects to their own ideas. Building control
structures for artificial power generation, resource management and more is possible
throughout this modification.
Many other games are written in Lua and over the years, Lua found its success in this
section for being easy to learn, executing fast and being lightweight which allows it to
be integrated into other software rather easy.
7 Conclusion
Lua is a versatile and efficient programming language that has gained widespread pop-
ularity and adoption across various domains. Its lightweight nature, simplicity, and
extensibility make it a suitable choice for a wide range of applications, from embedded
systems to game development and scripting.
Lua’s design philosophy of providing a minimalistic core with powerful extension capa-
bilities has resulted in a language that is both easy to learn for beginners and powerful
enough to meet the demands of experienced programmers. Its small footprint and fast
execution speed make it ideal for resource-constrained environments and performance-
critical applications.
One of Lua’s standout features is its seamless integration with other programming lan-
guages, allowing developers to leverage existing code and libraries. Its C API provides
a bridge between Lua and C/C++, enabling efficient interoperability and the creation
of high-performance extensions.
Lua’s emphasis on simplicity and flexibility has also led to the creation of an active and
supportive community. The availability of extensive documentation, online resources,
12
and a wide range of libraries and frameworks further enhances the language’s appeal
and ease of use.
While Lua may not be as widely recognized as some mainstream languages, its unique
blend of simplicity, performance, and versatility has made it a favorite choice for many
developers and organizations. As a scripting language, Lua excels in providing a powerful
yet lightweight solution for embedding in larger applications, enabling users to extend
functionality and customize behavior.
In conclusion, Lua’s strengths lie in its simplicity, efficiency, and extensibility, making it
a valuable tool for a variety of programming tasks. Whether you’re a beginner looking
for an easy-to-learn language or an experienced developer seeking a flexible scripting
solution, Lua has proven itself as a reliable and capable programming language.
References
[1] Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes. The
evolution of an extension language: a history of lua. Website, 2013. Reprint of
Proceedings, online available at www.lua.org/history.html; visited 08.06.2023.
[3] Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes. The
evolution of lua. In Proceedings of the third ACM SIGPLAN conference on History
of programming languages, pages 2–1, 2007.
13