Chapter 6. Embedding Lua
So far, we have been using Lua as a standalone language. We did this by using the Lua interpreter, which is the lua52
program we renamed lua
in Chapter 1, Introduction to Lua. The Lua interpreter itself is written in C. In this chapter, we will explore some of the same methods used to create the interpreter.
Lua as a language was designed with C interoperability in mind. You can use Lua as a standalone language or as an embedded scripting language. Many games and other applications utilize Lua as a scripting language—we will see some examples of this in the next chapter.
In this chapter, we're going to focus on some of the common tasks involved in embedding Lua into any C or C++ application. While we are only focusing on the C API, Lua can be embedded into many languages using the same API.
Note
This chapter assumes you already have some working knowledge of C or C++. This chapter is not intended to be an introduction to C. As such, it only focuses on the Lua C API.
By...