Is Lua based primarily on well-established programming-language ideas?

Charles Stewart picture Charles Stewart · Jan 20, 2010 · Viewed 17k times · Source

Lua occupies a good place in the space of languages that can be embedded. Are the primary ideas behind Lua's design new ideas from the implementors, or is Lua primarily a well-executed combination of well-established ideas?

Comparison of properties and features of Lua to other PLs are particularly appropriate.

Answer

Norman Ramsey picture Norman Ramsey · Jan 20, 2010

This is a very interesting question. My day job is to study programming languages, and Lua will repay careful study. I would say that about very few other languages (perhaps Icon and CLU). Please note that it is the language as a whole, not the individual features, which makes Lua so worthy of study.

Is this a result of interesting new ideas the implementors had, or is it a result of good execution of well-established ideas?

Both. For the details, your best source for an answer to this question is the paper The Evolution of Lua, which appeared at the Third ACM Symposium on the History of Programming Languages. But I will add a few comments.

  • The use of Lua tables as the only mutable, non-atomic type of data was invented by the Lua team. They were inspired by developments in CLU, and I believe they were aware of similar work in Awk and Icon, but the refinement to this degree is an important contribution of the Lua team.

    Tables also have a very efficient implementation, which was invented by the Lua team.

  • The functional features of Lua have the same semantics as Scheme, but Lua has a unique implementation of first-class functions, which I think they ought to submit for publication in the Journal of Functional Programming.

  • The API for embedding has been greatly refined over the years. Its main distinguishing characteristic is that user-defined abstract types can participate fully in the embedding. This is the property that makes the Lua API superior to the Tcl API, for example. The Lua API has undergone a great deal of refinement over the years, including since its first publication at version 2.5. The Lua designers deserve a great deal of credit here.

  • The garbage-collection technology is standard.

  • Lua coroutines represent a new take on some very old ideas. The new take was considered worthy of publication in ACM Transactions on Programming Languages and Systems, so again I think the Lua team get credit for originality.

  • Lua metatables are related to the Common Lisp metaobject protocol.

I think that Lua's success result from a unique combination of strengths of the Lua team:

  • If you read the HOPL paper, you'll see that the Lua team were well aware of many developments in programming languages and were able to choose from among the best ideas. Most designers of popular scripting languages have been amateurs and have not been nearly so well informed.

  • Lua is superbly designed so that the pieces fit together very nicely, with an excellent power-to-weight ratio. This is the result of a lot of refinement over time, and PUC-Rio was willing for the Lua team to work on the language design and implementation instead of grinding out a huge number of papers. This work could not have been done at a North American university.

  • Lua is superbly engineered. The implementation is just staggeringly good. That's partly great work by great engineers and partly the opportunity to keep revising the design over a 15-year period.

I'll close by asking readers not to underestimate the difficulty of choosing and refining well-established ideas to form a coherent whole. This is extremely difficult work and is seldom recognized as it should be.