Lua Was Built for Petrobras Engineers, Not Games. Then LucasArts Put It in Grim Fandango.

Roberto Ierusalimschy smiling during a talk, beside a pale panel with his name, a sun linked by a dotted arrow to a crescent moon, and the words “Lua · Rio de Janeiro, 1993”.


Lua, the scripting language later used in games such as World of Warcraft and Angry Birds, was created in 1993 in Rio de Janeiro for a very different audience: engineers at Petrobras, the Brazilian oil company.

Its creators say so bluntly. “We did not have game development as a target for Lua,” Roberto Ierusalimschy, Luiz Henrique de Figueiredo and Waldemar Celes wrote in their 2007 history of the language. The wide adoption of Lua in games, they also wrote, “came as a surprise to us.”

The story starts with columns of numbers. Several times a day, Petrobras engineers had to prepare input files for numerical simulators. These legacy programs needed strictly formatted input: typically bare columns of numbers, with no indication of what each number meant, in a format inherited from the days of punched cards. In early 1992, Petrobras asked Tecgraf — the computer graphics group at the Pontifical Catholic University of Rio de Janeiro (PUC-Rio) — for at least a dozen graphical front-ends, so that engineers could click on a diagram instead.

Tecgraf answered with little languages. A team led by de Figueiredo and Luiz Cristovão Gomes Coelho designed DEL, a data-entry language, and ran every front-end in a single interpreter. A second team, led by Ierusalimschy and Celes, worked on PGM, another program for Petrobras: a report generator for lithology profiles, which describe rock layers. To configure PGM, the team designed SOL, short for Simple Object Language and also the Portuguese word for sun. Soon DEL’s users were asking for conditionals and loops, and PGM would also need procedural programming.

Why Tecgraf built its own tools

As the Lua authors describe it, from 1977 until 1992 Brazil kept strong trade barriers on computer hardware and software, a policy called the market reserve, “motivated by a nationalistic feeling that Brazil could and should produce its own hardware and software.” In that atmosphere, Tecgraf’s clients “could not afford, either politically or financially, to buy customized software from abroad.” Under the rules, a client would have had to go through a complicated bureaucratic process to prove that no Brazilian company could meet its needs. Those obstacles, together with Brazil’s geographical isolation from other research centers, led Tecgraf to build its basic tools from scratch, the authors say. The policy ended in 1992, a year before Lua was born.

Mid-1993: one language instead of two

Around mid-1993, the three — Ierusalimschy, then an assistant professor of computer science at PUC-Rio; de Figueiredo, a postdoctoral fellow; and Celes, a PhD student — concluded that the data-entry language DEL and the report language SOL could be replaced by a single, more powerful language. They could have adopted an existing one. By their account, “the only real contender” in 1993 was Tcl, a scripting language designed to be embedded in applications. But Tcl had unfamiliar syntax, offered poor support for describing data, and ran only on Unix. They ruled out Lisp and Scheme for their “unfriendly syntax.” Python was “still in its infancy.” And in what they called the “free, do-it-yourself atmosphere” at Tecgraf, it was “quite natural” to try building their own.

Their design started from two decisions: keep the language simple and small, and keep the implementation simple and portable. Portability was not optional. Bound by very strict rules for spending public money, the state-owned Petrobras could not choose specific hardware, so Tecgraf’s software had to run on every machine the company had: “PC DOS, Windows (3.1, at that time), Macintosh, and all flavors of Unix.” Many of the language’s users would not be professional programmers, so it had to avoid cryptic syntax. Even semicolons were negotiated: requiring them might confuse engineers who knew Fortran, forbidding them might confuse C and Pascal programmers, so, “in typical committee fashion,” they became optional.

Because the new language was partly inspired by SOL — sun in Portuguese — a friend at Tecgraf, Carlos Henrique Levy, suggested a name: Lua, Portuguese for moon. It is a noun, not an acronym, the project’s site stresses, and should not be written in all capitals. By July 1993, Celes had finished the first implementation as a course project supervised by Ierusalimschy.

Small, embeddable, and eventually free

Following SOL’s example, Lua was built as a library with a C API (application programming interface), so a program written in C could embed it and hand parts of its work to scripts. Its single data structure was the table. Records used field names as keys, lists used numbers, and one mechanism handled both.

Lua 1.1, released in July 1994, was free for academic use, but commercial uses had to be negotiated. “That part of the license did not work,” the authors admitted: “no commercial uses were ever negotiated.” Lua 2.1 came out in February 1995 as unrestricted free software, and Lua 5.0 moved to the permissive MIT license.

The message from LucasArts

The road to games ran through a magazine. In December 1996, Dr. Dobb’s Journal, a publication for programmers, ran an article about Lua by its three creators. In January 1997, Bret Mogilefsky — lead programmer of Grim Fandango, an adventure game then in development at LucasArts — wrote to them: he had read the article, and his team planned to replace its home-brewed scripting language with Lua. The game came out in October 1998. In May 1999, Mogilefsky told the authors that a “tremendous” amount of it was written in Lua.

Grim Fandango mentioned Lua and PUC-Rio in its final credits. Several people at PUC-Rio first learned about Lua from that screen, the authors recall, “and were surprised to learn that Brazilian software was part of a hit game.” After Mogilefsky described his experience at the Game Developers Conference, Lua spread among game developers by word of mouth.

Built for engineers, ready for game designers

Today, Lua’s official site calls it “the leading scripting language in games,” citing a 2009 survey. Roblox’s scripting language, Luau, is derived from Lua. In 2007, the authors argued that the features that made Lua special were the ones games needed: a compiler for standard ANSI C was enough to build it, it was easy to combine with the language of a game’s engine, and it was simple, since “most game designers, scripters and level writers are not professional programmers.” The same paper called Lua “the only language created in a developing country to have achieved global relevance.”

What the constraints built

  • A constraint can become a design principle. A client’s mixed hardware led to a language built for portability from day one.
  • Design for the real user. The simple syntax chosen for Petrobras engineers also suited game designers; in both groups, many were not professional programmers.
  • A license is part of the product. Lua 1.1’s limits on commercial use brought no deals and, the authors concluded, could even discourage academic use.

When a customer’s constraint shapes your design, the result may be the part strangers end up valuing most. Lua grew out of a 1992 effort to spare Petrobras engineers from editing columns of numbers; in 1998, its name appeared in the final credits of a LucasArts game.

Related stories

Sources

Share this article
FacebookThreadsLinkedInX

Leave a Reply

Your email address will not be published. Required fields are marked *