Hello! Welcome to your first lesson in learning Lua for Factorio modding. Our journey starts not in the game itself, but by setting up a professional workspace on your computer. This will allow us to learn the Lua language in a clean, controlled environment, which is the best way to build a strong foundation.
Today's goal is to set up a local Lua development environment. This might sound complicated, but it just means we're going to install two key pieces of software:
- A Lua Interpreter: This is the program that understands and executes Lua code. Think of it as the engine that runs your scripts.
- A Code Editor: This is a specialized program for writing code. We'll use Visual Studio Code, a powerful and popular free editor that will make writing Lua much easier than using a simple text editor like Notepad.
By the end of this lesson, you'll have a complete setup that lets you write and run Lua code with a single command.
Part 1: Installing the Lua Interpreter
First, we need to install the Lua interpreter on your computer. While Factorio has its own Lua interpreter built-in, having a separate, "standalone" one is essential for learning and testing code quickly without needing to launch the game.
We will be following a video guide for this process. It walks through every step visually, which is very helpful. I'll provide a summary of the steps for you to follow along.
1.1: Download and Prepare Lua
Our first task is to download the pre-compiled Lua files for Windows and place them in an easy-to-find location.
Installing Lua on Windows Terminal & VS Code
This video from the pikuma channel will guide you through downloading the Lua interpreter and setting it up on Windows. Please watch the first part to get the files we need.
Watch from 00:26 to 02:33. The video will show you how to: Navigate to the official Lua website. Find and download the pre-compiled binaries for Windows (the .zip file). Extract the downloaded files. Rename the folder to Lua and move it to your C:\ drive, so the path is C:\Lua.
1.2: Tell Windows Where to Find Lua
Now that Lua is on your computer, we need to tell Windows where to find it. We do this by editing the PATH environment variable. The PATH is just a list of directories that Windows automatically checks when you type a command into the terminal. By adding C:\Lua to this list, we can run Lua from any folder on our computer.
Installing Lua on Windows Terminal & VS Code
Let's continue with the same video. This next section explains how to add your new C:\Lua folder to the Windows PATH.
Watch from 02:33 to 04:57. Follow the steps to open the System Properties window, find the 'Environment Variables' section, and add a new entry for C:\Lua to the 'Path' variable. Important: After you save your changes, you must close and re-open any terminal or command prompt windows for the new setting to take effect.
1.3: Verify Your Installation
Let's make sure everything worked.
- Open a new Windows Terminal or Command Prompt.
- Type
lua -vand press Enter.
You should see a message confirming the Lua version, something like Lua 5.3.5. This proves that Windows can find and run the interpreter.
You can also start Lua's interactive mode by just typing lua and pressing Enter. You'll see a > prompt. This is called a REPL (Read-Eval-Print Loop), and it's useful for testing small snippets of code. Try typing print("Hello, Lua!") and press Enter. To exit the REPL, type os.exit() and press Enter.
Part 2: Setting Up Your Code Editor
While you could write Lua code in Notepad, a proper code editor gives you "superpowers" like syntax highlighting (making code colorful and easy to read) and error checking. We'll use Visual Studio Code (VS Code), which is the top choice for many programmers, including Factorio modders.
2.1: Install Visual Studio Code and an Extension
First, let's get VS Code installed and add an extension specifically for Lua. Extensions add extra functionality to the editor.
Installing Lua on Windows Terminal & VS Code
The same video guide will now show you how to install VS Code. We'll also add a crucial extension that the video doesn't mention, which will help us write better code.
Watch from 04:57 to 05:50 to download and install Visual Studio Code. Once it's installed and open, follow these additional steps: Click the 'Extensions' icon on the left-hand sidebar (it looks like four squares). In the search bar, type Lua. Find the extension named Lua Language Server (often the top result, by sumneko) and click 'Install'. This will give you smart code completion and error checking.
Here is what the extension looks like in the VS Code marketplace:

2.2: Configure VS Code to Run Lua Scripts
This is the final and most important step. We will create a special configuration file that tells VS Code how to use the Lua interpreter we installed earlier to run our scripts. This will allow us to run any Lua file by simply pressing a keyboard shortcut.
Installing Lua on Windows Terminal & VS Code
This last part of the video is crucial. It shows how to create a 'build task' in VS Code to run your Lua code directly from the editor.
Watch carefully from 07:01 to 11:25. The video will guide you through: Creating a folder for your Lua projects and opening it in VS Code. Creating a test file named myscript.lua. Using the Terminal > Run Build Task... menu to generate a tasks.json file. Crucially, you will replace the contents of tasks.json with a custom script. The next section provides the exact code you should use.
When the video prompts you to paste code into the tasks.json file, use the code block below. It's a slightly improved version of the one in the video.
First, check the name of your Lua executable file inside your C:\Lua folder. It will likely be lua53.exe or lua54.exe. Make sure the "command" line in the code below matches that filename exactly.
{
// This file tells VS Code how to "build" or run our code.
"version": "2.0.0",
"tasks": [
{
"label": "Run Current Lua File",
"type": "shell",
// IMPORTANT: Change "lua53" to "lua54" or whatever your .exe is named!
"command": "lua53",
"args": [
"${file}" // This tells the command to run the currently open file.
],
"group": {
"kind": "build",
"isDefault": true // This makes it the default build task.
},
"presentation": {
"clear": true // Clears the terminal before each run.
}
}
]
}
Copy the code above and paste it into your tasks.json file in VS Code, replacing everything that was there. Save the file.
Test your understanding!
After setting up tasks.json, you open a Lua file and press the build shortcut (Ctrl+Shift+B). You see an error in the terminal that says something like 'lua53' is not recognized as an internal or external command.... What are the two most likely causes of this problem?
Show answer
- The
PATHis incorrect or wasn't loaded. You might have made a typo when addingC:\Luato your environment variables, or you forgot to restart the terminal/VS Code after changing it. - The command name in
tasks.jsonis wrong. Your Lua executable might be namedlua54.exeorlua.exe, but yourtasks.jsonfile is still trying to runlua53.exe. You need to make them match.
Putting It All Together
You've done it! Your professional Lua development environment is ready. Let's do a final test.
- In VS Code, make sure you have a Lua file open (e.g.,
myscript.lua). - If the file is empty, add the line:
print("My Lua setup is working!") - Press
Ctrl+Shift+B(or go toTerminal > Run Build Task...).
You should see a terminal window pop up at the bottom of VS Code, and your message My Lua setup is working! should be printed there.
Conclusion
Congratulations on completing your first lesson! It was a very practical one, but absolutely essential. You have now:
- Installed the standard Lua interpreter.
- Configured your system
PATHso you can run Lua from anywhere. - Installed and configured Visual Studio Code, a professional code editor.
- Created a build task to run your Lua scripts with a simple keyboard shortcut.
You are now fully equipped to start programming. All the foundational work is done.
Preview of the next lesson: In our next session, we'll dive into the code. You will write and run your first simple Lua script, learn how to print text to the console, and get acquainted with variables—the most basic building blocks for storing information in any program.