I’m guessing by now that my regular visitors have grown tired of watching my new blog change WordPress themes from day-to-day and occasionally go berserk as I fiddle with all the blog settings and break the PHP code. With that said, I’ve decided to set things right by writing a series of tutorials on the Lua scripting which is loosely based on the course that I teach at the Guildhall at SMU.
Lua is a rather popular scripting language for game design. If you don’t believe me just check out this list of games that use Lua. Clearly, anyone serious about game programming and especially learning scripting for level design, which is where Lua shines brightest, should take a moment out of their busy schedule and get too know Lua.
Ok, enough with the sales pitch.. let’s just jump in and gets this party started!
Installing Lua for Windows
The first thing I need you to do is download Lua and get it installed on your system and the fasted way to do this is to simply install the Windows for Lua binaries which not only contains Lua already compiled and ready to go but includes numerous other libraries that you may find helpful in the future. The version that I downloaded was LuaForWindows_v5.1.4-40.exe. Other than downloading it, the install is the standard fare… click next, next, next, etc… you know the drill.
Install the ConTEXT editor
Next, we need a text editor (preferably free) aimed at programmers which will make coding and running our Lua scripts a bit more organized. The text editor I use for my Guildhall course is ConTEXT which allows me customize the highlight of my Lua code and execute scripts from the editor with a simple push of a button. The version of ConTEXT that I downloaded was ConTEXTv0_986.exe. If there is another text editor you would prefer to use, please feel free to use it, but keep in mind that these tutorials will be written as if you were using ConTEXT.
Once you’ve downloaded and installed both Lua and the ConTEXT editor please follow these steps to finish the setup.
- First off, we need to setup ConTEXT to execute our Lua scripts by pressing the F11 key.
- Open ConTEXT and select from the menu Options->Environment Options.
- On the Environment Options dialog select the Execute Keys tab.
- Click the Add button and add a new extension called “Lua”
- Select the new Lua extension in the tree view and set the Execute path to “C:\Program Files (x86)\Lua\5.1\lua.exe” This path maybe different on your computer depending on your OS version where you installed Lua For Windows.
- Set the Parameters edit box to “%n”.
- Click the Apply button and close the Environment Options dialog.
- Finally, add my custom Lua highlighter file to ConTEXT. This is optional, but it makes the code look really sweet instead of plain ol’ black-on-white and who doesn’t want that? Further instructions are included in the zip file.
When done, the Environment Options dialog of ConTEXT should look like this:
Testing Our Development Setup
The last thing we’re going to do is test our development setup by creating a new Lua script and attempting to execute it from ConTEXT. To accomplish this, follow theses steps:
- Open ConTEXT and create a new file by selecting from the menu File->New.
- In this new file type the following line: print( “Hello Lua!” )
- Save the file by selecting from the menu File->Save and name it “hello.lua”. You can save it anywhere you want.
- Finally, hit the F11 key to execute the script.
- If everything works, you should see the the words “Hello Lua!” printed out in ConTEXT’s Output Console.
When done, ConTEXT should look something like this:
In the next tutorial, we’ll start leveraging our new development setup to learn the basic syntax of Lua. If you have any troubles getting any of this working, please feel free to reply below.