DEV Community

Sam
Sam

Posted on

Compile lua scripts to exe

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

rtcis 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.
rtccan be downloaded on theGitHub 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 simplehello.luafile containing this script:

print("Hello World!")
io.stdin:read("*l")
Enter fullscreen mode Exit fullscreen mode

Now, open a console or terminal prompt, go to the folder where you have saved the filehello.luaand enter the following command:

rtc hello.lua
Enter fullscreen mode Exit fullscreen mode

And voila!rtcshould have produced an executable namedhello.exe.You can run it like any other executable.

Static executables with rtc

By default,rtccreates dynamic executables, meaning the Lua VM is in the librarylua54.dlland its needed to run any program built withrtc(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 tellrtcto build a static executable with the-soption:

rtc-shello.lua
Enter fullscreen mode Exit fullscreen mode

Thehello.exefile 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 ofrtc.But there is more functionnalities available, like generating Desktop executables, changing default executable icon, embedding content...

Please read thertc documentationfor more on this.

Top comments(0)