How to create standalone Lua executables?

LuaServer Side ProgrammingProgramming

We can create standalone Lua executables with the help of the third party packages like srlua.

srlua does a perfect job in converting a Lua script file into an executable, and we can do it on both the major platforms, whether that is the windows or the Unix based systems.

Let’s first learn how to do it on a Windows system.

Consider the steps mentioned below as a reference −

First, visit the github link of the srlua project. Please click the following link. After that, you need to clone the repository on your local windows machine with this command −

git clone https://github.com/LuaDist/srlua.git

It should be noted that you need to have git bash for you to clone the git repo on Windows OS.

After that, you need to create srlua.exe and glue.exe first. You can create these executable by running the following commands to the terminal

gcc srlua.c -o srlua.exe
gcc glue.c -o glue.exe

Now you just need to run the following command to create a standalone lua executable

glue srlua.exe prog.lua prog.exe

In the above example, the prog.lua is the Lua file which you want to convert into a standalone executable.

It should be noted that you can obviously change the name from prog.exe to whatever you like.

For Unix OS, you need to edit the Makefile that is present in the root directory, and then run the make command like this

make

This will build srlua and glue, and run a simple test.

Now finally you need to run the following command and you will have your executable for Unix os as well.

glue srlua prog.lua a.out chmod +x a.out

It should be noted that the prog.lua is the Lua file which you want to convert into a standalone executable.

raja
Published on 20-Jul-2021 14:32:47
Advertisements