3

How to Call Lua from C++

In this chapter, we will implement a C++ utility class to execute Lua scripts. This serves two purposes. First, by doing this, you will learn in detail how to integrate the Lua library and call Lua code from C++. Second, you will have a Lua wrapper class ready to use. This helps in hiding all the details. We will start with a basic Lua executor and then we will gradually add more features to it as we progress. You will learn about the following:

  • Implementing a Lua executor
  • Executing a Lua file
  • Executing a Lua script
  • Understanding the Lua stack
  • Operating on global variables
  • Calling Lua functions

Technical requirements

Starting from this chapter, we will focus more on code and Lua integration itself and will be brief ...

Get Integrate Lua with C++ 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.