Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 12 Scripting with Lua > Binding Lua to C++

BINDING LUA TO C++

Hopefully by now you have a pretty good understanding of Lua and how it works. The remainder of this chapter will build upon this foundation and create a working relationship between Lua script and the C++ engine we’ve been creating throughout this entire book. First, we’ll look at some integration strategies and third-party libraries to make the process of embedding Lua into the C++ engine easier. Then we’ll go over some of the glue to get Lua to play nicely with the Process Manager and event system. Finally, I’ll bring it all together with a couple of examples.

The Lua C API

As I said earlier in this chapter, Lua was built from the ground up to be integrated into an existing system. (Its original intent was to be an embedded configuration language.) To facilitate this, there is a core C API for integrating Lua into your codebase. Unfortunately, this API is rather lacking in terms of usability. You have to manually deal with the Lua stack and language internals. Binding C functions to the Lua API is not particularly easy, and calling Lua functions from C is equally difficult. Good luck trying to bind a C++ class or function!


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial