In the early 1990s, engineers at Brazil's Petrobras needed graphical tools for two unglamorous jobs: preparing strictly formatted input for numerical simulators and configuring reports about geological profiles. At PUC-Rio's Tecgraf laboratory, the teams building those tools had made separate little languages. One described data-entry fields; the other described report layouts. As users asked for conditionals and more sophisticated layouts, both languages approached the point where a configuration format had to become a programming language. [1]
Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes joined those needs in 1993 to create Lua. They were not trying to displace the engineering applications. They needed code that those applications could load, call, and extend on several kinds of computer. That origin raises a question still relevant to engineers choosing a scripting system: what must a language give up, and what must its host take on, to make embedding a first-class design goal? Lua's answer was to make a few powerful language concepts available through a C interface and leave the application in charge of the surrounding system. [1] [2]
The application came first
Ierusalimschy and Celes led the report-generator team, which built SOL to describe objects with configurable attributes. Its interpreter was already a C library: the host called into it and registered callbacks for the kinds of objects it understood. The data-entry language, DEL, had shown how one graphical application could serve many workflows, but its users wanted control flow that DEL did not provide. Lua combined procedural programming with the ability to describe structured data. It also kept SOL's important architectural idea: the language would be a library that a C application could incorporate. [1]
The choice was shaped by local constraints. Tecgraf's clients used diverse machines, so the implementation had to be portable. The creators considered Tcl, then an established embeddable language, but judged its syntax, data-description facilities, and platform support unsuitable for their needs at the time. Their historical account also describes Brazilian restrictions on imported computing technology as part of the environment in which Tecgraf built tools for itself. Lua emerged from those practical requirements, not from a plan to design a universal language in isolation. [1]
A language built to cross the boundary
Lua itself is a library. Its command-line interpreter is a host program built on that library, rather than the program around which the library was added later. A C application creates a Lua state, loads code, invokes Lua functions, and can register its own C functions for scripts to call. That two-way connection is the crucial distinction between putting a scripting engine in a process and making it useful to the process. [2] [3]
The interface also shaped the language. Lua's tables can represent records, lists, modules, and objects; functions are values that can be stored in those tables. A host does not need separate C API machinery for each of those abstractions. It can create a table, insert a C function into it, and give the resulting value to a script. The Lua team describes its design preference as providing mechanisms from which programmers construct policies. In this case, fewer special forms meant fewer language features that the C interface could not express. [2] [3]
Moving values across that interface still requires discipline. Lua's C API uses a virtual stack for arguments, temporary values, and results. A host function can take a value from one position, push a result, and tell Lua how many results it produced. Keeping a value on the stack also keeps it visible to the garbage collector while C code works with it. This was a deliberate answer to the problem of managing the lifetime of language objects in native code; it does not make boundary code effortless, but it gives both sides a common protocol. [2]
Error handling follows the same host-centered logic. A script can fail without the application having to end: a protected call returns an error for the host to handle. Lua separates loading a chunk from running the resulting function, letting an application distinguish compilation errors from failures during execution. For a report generator, editor, or game, that separation lets the surrounding program decide what to do when a user script fails. [2] [3]
Portability has a bill
Lua's implementation in ISO C, compact core, and limited standard libraries made it easier to build for different systems and to fit inside an existing program. The host can supply a memory allocator when it creates a state and decide which standard libraries to load. Those choices matter when an application has its own memory budget or wants scripts to see only selected services. They also transfer work to the embedder: file access, platform integration, application objects, and the conventions for using them need to be designed for each host. [3] [4]
The freedom is especially consequential for untrusted scripts. Loading Lua into a process does not by itself create a security boundary. The current reference manual warns that its dynamic-library loader is inherently insecure and that crafted binary chunks can crash the interpreter; it provides a text-only load mode to exclude binary chunks. An application that accepts code from others must decide which libraries and native functions to expose and how to constrain its use of resources. Lua supplies mechanisms for that work, not a ready-made guarantee that arbitrary scripts are safe. [4]
Nor does “embed anywhere” mean “upgrade without work.” Lua's version history distinguishes bug-fix releases within a version, which preserve binary compatibility, from new versions, which can change the API and require embedders and C modules to be rebuilt. The creators have also acknowledged that Lua's flexible approach to objects can produce incompatible conventions among applications, while its lean library makes some standalone programs less convenient to write. These are costs of letting each host define much of the experience. [3] [5]
The Petrobras tools needed one language that could serve several applications without taking over any of them. Ierusalimschy and his collaborators answered by designing both a language and a boundary: tables and functions that C could manipulate, a stack through which values could travel, and a runtime the host could call on its own terms. Lua could spread to very different systems because the core asked relatively little of them. What each system then allowed Lua to do remained an engineering decision for the people embedding it.
Editorial disclosure. OpenAI Codex assisted with source research, analysis, and drafting.
References
- Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes. 2007. The Evolution of Lua. Proceedings of ACM HOPL III.
- Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes. 2011. Passing a Language Through the Eye of a Needle. Communications of the ACM 54(7).
- Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes. 2018. A Look at the Design of Lua. Communications of the ACM 61(11).
- Lua.org. Lua 5.5 Reference Manual, sections 4 and 6.
- Lua.org. Version History.