Search code examples
lua

Compile your lua files


How can I build and compile my own Lua files on Windows? And make them executable.

I am reading Beginning Lua programming, and I have Windows 7 and MacOS Lion both installed. I am having the hard time to follow the instructions. They do not work for me.

On MacOS I open the terminal and put these in:

  1. export LUA_DIR=/usr/local/lib/lua/5.1
  2. mkdir -p /usr/local/lib/lua/5.1 (it tells me, mkdir: illegal option) and I can not follow from here
  3. SET LUA_DIR=”c:\program files\lua\5.1”

As for Windows I do this according to the book. This what I see in my shell c:\Users\bd>

  1. mkdir "c:\program files\utility" and it tells me access is denied

I have tried to right click on this folder and check off read only, but it does not work. Any clues would be appreciated, this part has been really confusing for me.


Solution

  • To package your Lua files into an executable on Windows you have several options. There is srlua, there is wxLuaFreeze from wxLua (available as a binary for Windows), and there are more options in this SO answer.

    Essentially, the main two options are: (1) append your Lua code to a precompiled exe file, such that it will be loaded and executed when that exe file is run, and (2) convert your Lua code into real executable by compiling it to bytecode, then to C, and then to your target platform.

    As to your MacOS issue, mkdir -p means that mkdir is asked to create intermediate directories (for example, you asked to create /a/b/c, it will also create /a/b if those don't exist). As you don't say which version of MacOS you run, it's difficult to provide more detailed answer.