Compiling Lua on Windows

Thanks to PICO-8, I've been writing Lua lately, and I've rather enjoyed it. I'm particularly interested in it given it's designed to be used as a language embedded in other projects to enable extensibility. Anyways, I found myself wanting to use it on my Windows computer, but winget didn't offer a simple Lua package I could install like on Linux1, so I took a look at how difficult it would be to get it compiled myself. It turns out it's trivial. The Lua FAQ page has a pretty good guide for how to do it. I took a look at the book they referenced, which contains a batch script you can use to build the source yourself. It references a print.o file that doesn't exist though, so I had to modify it to get it to compile luac correctly:

cl /MD /O2 /W3 /c /DLUA_BUILD_AS_DLL *.c
del *.o
ren lua.obj lua.o
ren luac.obj luac.o
ren print.obj print.o
link /DLL /IMPLIB:lua5.1.lib /OUT:lua5.1.dll *.obj
link /OUT:lua.exe lua.o lua5.1.lib
lib /out:lua5.1-static.lib *.obj
link /OUT:luac.exe luac.o lua5.1-static.lib

I didn't bother to update the version numbers even though I built Lua 5.4 because I'm not super concerned about it for now, but you could additionally do that if you so desired.


  1. There are some pre-packaged installers that include a bunch of other things I'm not really interested in but I just wanted the interpreter and compiler.