├── Compile.bat └── README.md /Compile.bat: -------------------------------------------------------------------------------- 1 | :: 2 | :: Compiles Lua 3 | :: 4 | 5 | :: 6 | :: Set up environment 7 | :: 8 | 9 | :: Start local variable scope 10 | @SETLOCAL 11 | 12 | :: Locate 'vcvarsall.bat' 13 | @IF NOT "%VS120COMNTOOLS%"=="" @SET VSVARSALL=%VS120COMNTOOLS%..\..\VC\vcvarsall.bat 14 | @IF NOT "%VS140COMNTOOLS%"=="" @SET VSVARSALL=%VS140COMNTOOLS%..\..\VC\vcvarsall.bat 15 | @IF "%VSVARSALL%"=="" @GOTO ENDSETUP 16 | 17 | :: Identify the target architecture 18 | @IF NOT "%PROCESSOR_ARCHITECTURE%"=="" ( 19 | @IF "%PROCESSOR_ARCHITECTURE%"=="x86" @SET ARCH=x86 20 | @IF "%PROCESSOR_ARCHITECTURE%"=="AMD64" @SET ARCH=amd64 21 | ) 22 | @IF "%ARCH%"=="" @GOTO ENDSCRIPT 23 | 24 | :: Call the setup script 25 | @CALL "%VSVARSALL%" %ARCH% 26 | @ECHO ON 27 | 28 | :ENDSETUP 29 | 30 | :: 31 | :: Process files 32 | :: 33 | 34 | :: Move down into 'src' 35 | @PUSHD src 36 | 37 | :: Clean up files from previous builds 38 | @IF EXIST *.o @DEL *.o 39 | @IF EXIST *.obj @DEL *.obj 40 | @IF EXIST *.dll @DEL *.dll 41 | @IF EXIST *.exe @DEL *.exe 42 | 43 | :: Compile all .c files into .obj 44 | @CL /MD /O2 /c /DLUA_BUILD_AS_DLL *.c 45 | 46 | :: Rename two special files 47 | @REN lua.obj lua.o 48 | @REN luac.obj luac.o 49 | 50 | :: Link up all the other .objs into a .lib and .dll file 51 | @LINK /DLL /IMPLIB:lua.lib /OUT:lua.dll *.obj 52 | 53 | :: Link lua into an .exe 54 | @LINK /OUT:lua.exe lua.o lua.lib 55 | 56 | :: Create a static .lib 57 | @LIB /OUT:lua-static.lib *.obj 58 | 59 | :: Link luac into an .exe 60 | @LINK /OUT:luac.exe luac.o lua-static.lib 61 | 62 | :: Move back up out of 'src' 63 | @POPD 64 | 65 | :: Copy the library and executable files out from 'src' 66 | @COPY /Y src\lua.exe lua.exe 67 | @COPY /Y src\luac.exe luac.exe 68 | @COPY /Y src\lua.dll lua.dll 69 | 70 | :ENDSCRIPT 71 | 72 | :: End local variable scope 73 | @ENDLOCAL -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Compiling Lua 2 | A guide for compiling Lua for Windows, complete with script 3 | 4 | ## Prerequisites 5 | 6 | * A tool capable of extracting `.tar.gz` files 7 | * I recommend [7Zip](https://www.7-zip.org/) 8 | * _Either_ 9 | * A full [Visual Studio](https://visualstudio.microsoft.com/) installation 10 | * The [standalone Visual Studio build tools](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019) (unconfirmed) 11 | 12 | ## Steps 13 | 14 | 1. Go to the Lua [download area](https://www.lua.org/ftp/). 15 | 2. Download the version of Lua that you want. 16 | 3. Unzip the `.tar.gz` file using a decompression tool, giving you a folder of the form `lua-x.y.z`. 17 | * Where `x.y.z` corresponds to the version number of the Lua version you have downloaded, e.g. `lua-5.3.5`. 18 | * If you do not have a suitable decompression tool, I recommend [7Zip](https://www.7-zip.org/). 19 | * You may need to extract twice, once for the `.gz` wrapper and once for the `.tar` archiving. 20 | 4. Download the `Compile.bat` file from this repo and move it into the extracted `lua-x.y.z` folder. 21 | 5. Make sure you have `cl.exe`, `link.exe` and `lib.exe` either in your [`%PATH%` variable](https://en.wikipedia.org/wiki/PATH_(variable)) or in the extracted `lua-x.y.z` folder. 22 | 6. Run `Compile.bat` either by double-clicking it or running it from command line. 23 | * Windows may provide a security warning advising you not to run scripts from untrusted sources. If you have any doubts about whether or not you can trust the script then I advise that you _do not run it_ as I will not be held liable for any damages. 24 | 25 | After step 6, there should be a copy of `lua.exe`, `luac.exe` and `lua.dll` present in the `lua-x.y.z` folder. 26 | * `lua.exe` is the Lua interpreter, which interprets and runs scripts, and provides a Lua [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop) if run without arguments. 27 | * `luac.exe` compiles Lua files into standalone executables. 28 | * `lua.dll` is the library file that holds all the necessary Lua pipelining and must be kept with both `lua.exe` and `luac.exe` in order for them to function correctly. 29 | 30 | You may relocate these files as you please, as long as `lua.exe` and `luac.exe` have a copy of `lua.dll` in the same directory in which they are kept. 31 | 32 | It is recommended that you put the directory in which these files are kept on your [`%PATH%`](https://en.wikipedia.org/wiki/PATH_(variable)) so that you can run them from the command line. 33 | 34 | ## Legal 35 | 36 | The script I have provided is a modified version of the script found on [this blog](https://blog.spreendigital.de/2015/01/16/how-to-compile-lua-5-3-0-for-windows/). 37 | I am not the original author, but I am responsible for the various modifications. 38 | Regretably as the original script has no licence I cannot provide a licence for my modified version as I do not have proper copyright of it. 39 | The original author retains the right to request the removal of my modified version, a request with which I would willingly (if regretfully) comply, but personally I would rather the original author added a proper licence to their original version and possibly even incorporated my modifications, as that would be a more beneficial outcome. 40 | 41 | Regardless I will say that: 42 | > This software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. 43 | > In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software. 44 | --------------------------------------------------------------------------------