Lua Basics - Windows 7 Installation and Running Lua Files from the Command Line

David Black
Feb 1, 2016 · 4 min read

What is Lua? Lua is a fast lightweight, embeddable scripting language.

Estimated Space Required: 410MB
Time Required: ~15 Minutes (Download Time Dependent)

Lua is a portable, dynamically typed, easily embedded, interpreted scripting language. This is a quick tutorial for how to build Lua from source on Windows 7 and set up command line to interpret Lua files.

Step 1: Download the Lua Source Code and GCC

Before you begin any downloads, you will need a folder to save them to. I suggest creating a folder right on the C drive with no spaces in its name - this may prevent issues with installation.

Next you will need to download the Lua source code from You will need to download the file called lua-5.3.2.tar.gz (5.3.2 is the current version as of time of writing). Save this to the folder you created earlier.

Next is the GNU Compiler Collection (GCC). The Lua Wiki suggests using the Windows port by TDM. The link is here Download the file tdm64-gcc-5.1.0–2.exe if you are running a 64 bit operating system and save it to the folder you created earlier (This executable may take a few minutes to download).

Step 2: Install the Compiler

Run the tdm64-gcc-5.1.0–2 executable you downloaded earlier. To speed up this process, uncheck the box that says “Check for updated files on the TDM-GCC server.” Then click Create. Now, click Browse… and navigate to the folder you created. Append “\tdm-gcc” (no quotes) to the end of the path and click Ok then Next.

You will see a Tree structure on this step. Scroll to the bottom and uncheck “Start Menu Items” and “Add to PATH”. This will prevent extra files from being added to your computer. Click Install and when the installation is finished, click Next then Finish.

Step 3: Unpack Lua Sources with 7-Zip

(7-Zip is not mandatory here, any decompressor that can unpack TAR-GZ files will work)

Using the 7-Zip file manager. Navigate to the folder containing your Lua Sources - lua-5.3.2.tar.gz. Open this package and you will find a package called lua-5.3.2.tar. Open this package as well and you will find a folder called lua-5.3.2. Copy this folder to the root of the folder you created earlier.

Step 4: Build Lua and Create a Clean Binary Distribution.

I’ll take a second to explain exactly what we’re going to do here. First off, we will use mingw32-make.exe, downloaded as part of the GCC to build Lua, then we will copy select files from the Lua Source to a new Directory so that we have a version that does not contain all the source code. This will allow us to remove the installation directory and all source code we downloaded if we are working with limited storage.

The Lua Users Wiki contains a useful Shell Script to complete this step for us. The following code has been modified from the wiki to work with Lua-5.3.2. Copy this code to a file called build.cmd, save it to the folder you created and run it.

@echo off
:: ========================
:: file build.cmd
:: ========================
:: you may change the following variable’s value
:: to suit the downloaded version
set lua_version=5.3.2
set work_dir=%~dp0
:: Removes trailing backslash
:: to enhance readability in the following steps
set work_dir=%work_dir:~0,-1%
set lua_install_dir=%work_dir%\lua
set compiler_bin_dir=%work_dir%\tdm-gcc\bin
set lua_build_dir=%work_dir%\lua-%lua_version%
set path=%compiler_bin_dir%;%path%
cd /D %lua_build_dir%
mingw32-make PLAT=mingw
:: create a clean “binary” installation
mkdir %lua_install_dir%
mkdir %lua_install_dir%\doc
mkdir %lua_install_dir%\bin
mkdir %lua_install_dir%\include
copy %lua_build_dir%\doc\*.* %lua_install_dir%\doc\*.*
copy %lua_build_dir%\src\*.exe %lua_install_dir%\bin\*.*
copy %lua_build_dir%\src\*.dll %lua_install_dir%\bin\*.*
copy %lua_build_dir%\src\luaconf.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lua.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lualib.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lauxlib.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lua.hpp %lua_install_dir%\include\*.*
%lua_install_dir%\bin\lua.exe -e”print [[Hello!]];print[[Simple Lua test successful!!!]]”echo.pause

If you got a message saying “Hello! Simple Lua test successful!!!”, then congrats. You’ve manage to build Lua on Windows 7! At this point, copy the newly created lua folder from the folder you created and place it wherever you want. Feel free to delete the installation folder you created once the lua folder is copied, or keep it so you have the files for a clean install.

Step 5: Adding Lua to the Windows Search Path and Testing

Go to your Start menu and type SystemPropertiesAdvanced.exe in the Search bar, or type it in Run if you prefer. In the window that opens, click the button at the bottom labeled Environment Variables… and turn your attention to the lower box. Scroll through here until you find a Variable named “Path”. Click on it and then click the Edit… button. In the Variable value field, go to the end of the text and append the following:


Where C:\lua is replaced with the full path of where you copied the lua folder to in the last step. Click OK on all 3 windows to save.

Now we’re going to test if adding to the Search Path was successful. Create a file anywhere you like with the following code:

io.write(“Hello World!”)

The name and the file extension don’t matter, but I went ahead and called it test.lua. Now open up the Windows Command Processor cmd.exe and use the cd command to navigate to the directory where you saved your test code. (Hint: Right Click on the address bar in Windows Explorer and click “Copy as Text” to get the path.) Example:

C:\> cd C:\Users\MyName\Desktop

Now for the moment of truth. Type the following command with test.lua replaced with your test file and extension:

C:\Users\MyName\Desktop> lua test.lua

If the command prompt returned “Hello World!”, then congrats! You’ve successfully added Lua to your Windows Search Path. At this point you’re ready to begin writing in Lua. Take some time to learn the language and practice! The Reference Manual: provides a good start and many resources exist both online and in printed form to help you learn!

 by the author.

David Black

Written by

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade