环境
OS:windows 11 64bit
IDE:Visual Studio 2022
版本:Lua 5.4.6

1.下载Lua

2.编写编译脚本

  1. VC_x86.bat

    @echo off
    %comspec% /k ""C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat"" x86
    
  2. VC_x64.bat

    @echo off
    %comspec% /k ""C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat"" x86
    
  3. compile_Debug.bat

    md bin
    md include
    md lib
    
    cd src
    cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MDd *.c
    del lua.obj luac.obj
    link /LIB /out:lua54.lib /verbose:lib *.obj
    copy lua54.lib ..\lib\lua54.lib
    del *.obj *.lib *.dll *.exp
    cd ..\
    echo Compile lua54.lib successfully...
    
    cd src
    cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MDd /DLUA_BUILD_AS_DLL /D_CRT_SECURE_NO_DEPRECATE *.c
    del lua.obj luac.obj
    link /DLL /out:lua54.dll /verbose:lib *.obj
    copy lua54.dll ..\lib\lua54.dll
    del *.obj *.lib *.dll *.exp
    cd ..\
    echo Compile lua54.dll successfully...
    
    cd src
    cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MDd *.c
    del luac.obj
    link /out:lua54.exe /verbose:lib *.obj
    copy lua54.exe ..\bin\lua54.exe
    del *.obj *.lib *.dll *.exp *.exe
    cd ..\
    echo Compile lua54.exe successfully...
    
    cd src
    cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MDd *.c
    del lua.obj
    link /out:luac54.exe /verbose:lib *.obj
    copy luac54.exe ..\bin\luac54.exe
    del *.obj *.lib *.dll *.exp *.exe
    cd ..\
    echo Compile luac54.exe successfully...
    
    cd src
    copy lauxlib.h ..\include\lauxlib.h
    copy lua.h ..\include\lua.h
    copy lua.hpp ..\include\lua.hpp
    copy luaconf.h ..\include\luaconf.h
    copy lualib.h ..\include\lualib.h
    cd ..\
    echo Copy lua include file successfully...
    
  4. compile_Release.bat

    md bin
    md include
    md lib
    
    cd src
    cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MD *.c
    del lua.obj luac.obj
    link /LIB /out:lua54.lib /verbose:lib *.obj
    copy lua54.lib ..\lib\lua54.lib
    del *.obj *.lib *.dll *.exp
    cd ..\
    echo Compile lua54.lib successfully...
    
    cd src
    cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MD /DLUA_BUILD_AS_DLL /D_CRT_SECURE_NO_DEPRECATE *.c
    del lua.obj luac.obj
    link /DLL /out:lua54.dll /verbose:lib *.obj
    copy lua54.dll ..\lib\lua54.dll
    del *.obj *.lib *.dll *.exp
    cd ..\
    echo Compile lua54.dll successfully...
    
    cd src
    cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MD *.c
    del luac.obj
    link /out:lua54.exe /verbose:lib *.obj
    copy lua54.exe ..\bin\lua54.exe
    del *.obj *.lib *.dll *.exp *.exe
    cd ..\
    echo Compile lua54.exe successfully...
    
    cd src
    cl /c /nologo /W3 /O2 /Ob1 /Oi /Gs /MD *.c
    del lua.obj
    link /out:luac54.exe /verbose:lib *.obj
    copy luac54.exe ..\bin\luac54.exe
    del *.obj *.lib *.dll *.exp *.exe
    cd ..\
    echo Compile luac54.exe successfully...
    
    cd src
    copy lauxlib.h ..\include\lauxlib.h
    copy lua.h ..\include\lua.h
    copy lua.hpp ..\include\lua.hpp
    copy luaconf.h ..\include\luaconf.h
    copy lualib.h ..\include\lualib.h
    cd ..\
    echo Copy lua include file successfully...
    

3.编译

  1. 以 x64_Release 为例,双击执行
    image-icnw.png
  2. 输入 compile_Release
    image-xidk.png
  3. 编译完成
    image-wfoz.png