Why is Lua designed to generate intermediate opcodes?

For general comparison of bytecode interpreters and abstract syntax tree interpreters, see Wikipedia:Interpreter.

Lua has been using a virtual machine since its birth, and introduced a register-based virtual machine in Lua 5.0 (which is the first register-based virtual machine to have a wide use.) The Evolution of Lua, written by the authors of Lua, provides lots of resources on that topic.

Another paper written by the authors of Lua, The Implementation of Lua 5.0 provides lots of details on the implementation, Chapter 7 The Virtual Machine would be especially helpful to you, this paper is also a great reference for reading Lua's source code.


Using virtual machines is an old implementation technique for languages, dating as far back to at least UCSD Pascal, BCPL, and Smalltalk. Most scripting languages now use a virtual machine. Some use a general-purpose virtual machine. Lua uses a special purpose virtual machine that reflects the semantics of the language. Hence the specialized opcodes. Lua did introduce novelty in this area by moving in version 5.0 to a register-based virtual machine, instead of a traditional stack-based one.