Have you ever wanted to compile your Lua scripts into Windows executables? Having trouble deploying Lua programs on other computers? Here's a quick and easy way to turn your Lua scripts into executables.
rtc, an open source Lua to exe compiler
rtc is a simple command line tool to build standalone executables from your Lua scripts. A GUI front end is available for those who are resistant to the console.
rtc can be downloaded on the GitHub project homepage, and available for x86 and x64 Windows platforms.
Once downloaded, put the content of the ZIP archive on your hard disk and make sure it's available on your system PATH.
Let's build our first executable
Create a simple hello.lua
file containing this script :
print("Hello World !")
io.stdin:read("*l")
Now, open a console or terminal prompt, go to the folder where you have saved the file hello.lua
and enter the following command :
rtc hello.lua
And voila ! rtc
should have produced an executable named hello.exe
. You can run it like any other executable.
Static executables with rtc
By default, rtc
creates dynamic executables, meaning the Lua VM is in the library lua54.dll
and its needed to run any program built with rtc
(this dependency can be found along your executable or in your system PATH).
If you want to get rid of this library dependency, you can tell rtc
to build a static executable with the -s
option :
rtc -s hello.lua
The hello.exe
file will be fatter, as it includes now the Lua VM. But be careful with those static executables, as it is strongly discouraged to require for Lua binary modules (may lead to crash). Use this option only if your program don't need any Lua binary module.
What's next ?
This tutorial shows basic usage of rtc
. But there is more functionnalities available, like generating Desktop executables, changing default executable icon, embedding content...
Please read the rtc documentation for more on this.