Lua and C++

Now we will plug Lua into the game engine to provide scripting support for our future game projects. Distributed with the Lua library are the header files and library file that must be added to a game project. In our case, we’ll be adding these files to the Advanced2D engine project. Here are the headers:

  • lua.hpp

  • lua.h

  • luaxlib.h

  • luaconf.h

  • lualib.h

You may copy these files into your compiler’s .include folder so that they will always be available for future projects, or you may copy the headers into your project’s source code folder. Either way, you will need to include the lua.hpp file. This extension (.hpp) is technically the proper file extension for a C++ header file, but .h is so common and familiar that most programmers still use it. Although you need all of the Lua headers, you need only include lua.hpp as:

#include "lua.hpp"

Or, if referring to the file in your compiler’s .include folder, like so:

#include <lua.hpp>

This single header includes the others so you need only include this one file.

Lua can be compiled into a binary executable directly, but the more common way of including Lua support in a C++ program is with a library file. Included in the Lua distribution are the full sources with makefiles for various compilers. I have provided the precompiled library files for Dev-C++ and Visual C++ on the CD-ROM under the folder for this chapter.

The Dev-C++ library file is called liblua.a and is added to the linker options with -llua. The Visual C++ library file is called lua5.1.lib and is added to the linker options with the whole filename.

..................Content has been hidden....................

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