How to Compile a Lua Executable?


While there are different ways with which a person can compile a Lua executable, some of them require more time and resources.

The most basic approach is to set the Lua Path environment variable and then simply run the lua command. While this might seem to be not much of a pain, setting the Lua Path definitely requires some work.

Instead of setting the Lua path, we can simply make use of the env and lua combination which will allow us to convert a Lua file into an executable or run a Lua script.

The command shown below does the same −

#!/USR/BIN/ENV LUA

In the above command there are different keywords that we can understand individually, let’s do that.

  • The #! line at the beginning of a script needs an absolute path of the program to run this script.
  • env is a program that runs another program in the path if executed as "env program", and its absolute path is (or should be) /usr/bin/env.
  • So, put these two facts together as you will often do, and there you have #! /usr/bin/env lua

It should be noted that we need to have Lua installed on the machine where we are intending to make use of the above command.

Updated on: 20-Jul-2021

504 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements