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.

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 the end of this chapter, you will be able to do the following:

  • Understand the Lua C API
  • Understand the Lua stack
  • Create Lua variables from C
  • Call Lua functions from C
  • Call C functions from Lua
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.217.5