Chapter 11. Exploring Lua's Libraries

Up to this point in the book you've been learning about the fundamentals of Lua, occasionally using some of its library functions. In this chapter, all of Lua's standard library functions are briefly summarized to remind you of their basic usage. Practically every function has many more features than can be covered in detail within the scope of this book, and the examples that are included here are mostly contrived for brevity. (For the definitive documentation of these features, see the Lua Reference Manual.)

In this chapter, you'll find summaries of the following:

  • General-purpose functions in the core library

  • Functions that manage coroutines

  • Package functions that implement Lua's module system

  • String conversion and pattern matching functions

  • Functions that help with using tables as arrays

  • Bindings to the C runtime library's math functions

  • Functions for reading from and writing to files and streams

  • Operating system functions

  • Functions to help with debugging your Lua programs

An example is provided for each function or group of functions.

Core Library

The core library functions reside in the global environment. They have no containing namespace table.

Environment Functions

The following functions let you set and retrieve a function's environment—the table that Lua uses to resolve global references—and get or set the global environment of the running thread when given a stack level of 0:

  • getfenv(optional function or stack level): Returns the environment table ...

Get Beginning Lua Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.