Copyright by Kurt Jung, Aaron Brown

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required