DEV Community

Water Run
Water Run

Posted on

luaToEXE: Compile Lua Scripts to Standalone Windows Executables

Introduction

The standard method to compile a .lua file into a standalone .exe with a built-in interpreter and no environment dependencies is to use srlua. However, srlua itself has not been updated for over a decade and does not provide precompiled binaries. Many community-compiled versions of srlua overlook dependency issues, resulting in missing DLL errors when running the compiled program on a machine without a Lua environment. Thus, it is not truly ready-to-use.

luaToEXE is an open-source project that wraps srlua, aiming to provide a simple solution for compiling .lua files into .exe files with a built-in interpreter.

Features:

  • Easy to use
  • The compiled .exe has no dependencies (tested in Windows sandbox environments)
  • Supports multiple Lua versions

The project consists of two sub-projects:

  1. lua-to-exe: A Python library that provides API functions for conversion and a graphical user interface
  2. exelua: A command-line tool with both 32-bit and 64-bit versions

Links:

Tutorial: lua-to-exe

  1. Install using pip install lua-to-exe

  1. Import the package in your project with import lua_to_exe (note the underscore)

  2. Graphical interface: Run lua_to_exe.gui() to launch the GUI

    • Includes file selection for input .lua and output .exe, and a convert button
    • Dropdown to select the Lua version (-32 means 32-bit, and so on)

  1. API: Call the lua_to_exe() function
    • lua_to_exe(lua_file, exe_file, lua_version='5.1.5-64'). The arguments are the input .lua file, the output .exe file, and an optional Lua version (default is 5.1.5-64)
    • Call all_available() to get a dictionary of all available Lua versions

Tutorial: exelua

  1. Download the appropriate version of exelua from the Release page

  1. Extract and add the directory to your environment variables, then restart your computer. Make sure the srlua folder is in the same directory

  1. In the Windows terminal, run exelua -v. If a version number is output, the installation was successful
  2. Run exelua -h for usage help, and exelua -list (the first run may take some time) to list all available versions

  1. Run exelua -c <input.lua> <output.exe> [-lua <version>] to perform the conversion. The parameters are: the input .lua file path, the output .exe file path, and the optional -lua (if you want to specify the Lua version) and the corresponding version. For example, to convert helloworld.lua to helloworld.exe, the command can be exelua -c helloworld.lua helloworld.exe, which uses the default 5.1.5-64/5.1.5-32 Lua interpreter version.

Star Request :-/

If this project has helped you, please consider giving it a Star :)

Top comments (0)