ABSTRACT

This chapter explains metatables, and how they provide a mechanism for user-defined types nearly identical to JavaScript’s prototypes. It examines how Lua allows its operators to take on new meanings under programmer control. The chapter discusses Lua’s implementation of a popular mechanism for concurrency: coroutines. Lua was born in 1993 at PUC-Rio, Pontificia Universidade Catolica do Rio de Janeiro. All values in Lua belong to one of eight types: nil, boolean, number, string, function, thread, userdata, and table. The first four are primitive types, and the latter four are reference types. Like JavaScript and CoffeeScript, Lua provides a single structure that can be used to hold both named and numbered properties. Lua’s structure is called a table. This chapter provides an example to show how tables are created and iterated over. The functions pairs and ipairs produce iterators. Coroutines allow one to structure an application into concurrent activities, each written independently of each other.