• entries
    206
  • comments
    217
  • views
    224474

RPG Anvil: The Lua Tutorial Part 2

Sign in to follow this  

585 views



Today, how to get Lua and link it with your game.

The previous installment of this tutorial is here:



Lua is available at http://www.lua.org/. As of this writing (June 25, 2009), the latest version is 5.1.4. There are various binary packages available, however, I recommend that you just download the source code (lua-5.1.4.tar.gz for me). Unpack this using your favorite unpacking utility; I put mine into C:\dev\lua-5.1.4.

Now, we'll make a project for this tutorial:

  • Fire up Visual Studio. I'm using Visual Studio 2005; your steps will likely vary somewhat if you're using a different version.

  • File/New/Project.

  • Pick a "Visual C++"/Win32/"Win32 Console Application". Call it luatest.

  • In "Application Settings", be sure we're doing "Console Application".

  • You can turn off ATL and MFC if you want to, though it shouldn't matter.

  • If you build and run at this point, you should get a Console Application that opens a console window, and then exits.


Next, we need to add the Lua files. Open the project properties, and go to "Configuration Properties"/"C/C++"/General. Add the Lua directories to "Additional Include Directories"; something like:

"C:\dev\lua-5.1.4\etc";"C:\dev\lua-5.1.4\src"

One more annoying step in the project properties. Lua uses the C-library string function calls like strcpy, and Microsoft doesn't like those anymore. The easiest way to deal with this is in the project properties, under "Configuration Properties"/"C/C++"/Preprocessor. Under there, add to "Preprocessor Definitions":

_CRT_SECURE_NO_WARNINGS=1

The easiest way to include the Lua sources are just to add the files. You can fool around with building Lua as an additional library (or even DLL), but I wouldn't bother. To do this, add the Lua source files to your project's "Source Files". There is a list of the files in C:\dev\lua-5.1.4\etc\all.c; you want all of those files except for lua.c.

And, even though we're not going to call into Lua yet, let's include the header files just for kicks. To your luatest.cpp, just under:

#include "stdafx.h"


Add:

#include 


At this point your luatest.cpp should look something like this:

// luatest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include

int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}



This should build cleanly. You can run your Lua-enabled app, which should fire up a console window, do nothing, and then exit. Congratulations!

Next: Calling a Lua script.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now