本文使用Windows 11进行编译和安装,其他Windows版本大同小异。
首先到官网下载最新的Lua源码:http://www.lua.org/download.html
另外,需要提前下载并安装 MinGW-w64
,具体方式自行解决,本文略
将其解压到任意一个目录,注意该目录路径不要有空格
例如:D:\lua_build\lua-5.4.3
在该目录新建 build.bat
,修改以下内容并保存:
将 set lua_version=5.4.3
修改为你下载的Lua版本
将 set compiler_bin_dir=C:\MinGW-w64\mingw64\bin
修改为你的 mingw
的 bin
目录
@echo off
:: ========================
:: file build.cmd
:: ========================
setlocal
:: you may change the following variable's value
:: to suit the downloaded version
set lua_version=5.4.3
set work_dir=%~dp0
:: Removes trailing backslash
:: to enhance readability in the following steps
set work_dir=%work_dir:~0,-1%
set lua_install_dir=%work_dir%\lua
set compiler_bin_dir=C:\MinGW-w64\mingw64\bin
set lua_build_dir=%work_dir%\lua-%lua_version%
cd /D %lua_build_dir%
mingw32-make PLAT=mingw
echo.
echo **** COMPILATION TERMINATED ****
echo.
echo **** BUILDING BINARY DISTRIBUTION ****
echo.
:: create a clean "binary" installation
mkdir %lua_install_dir%
mkdir %lua_install_dir%\doc
mkdir %lua_install_dir%\bin
mkdir %lua_install_dir%\include
copy %lua_build_dir%\doc\*.* %lua_install_dir%\doc\*.*
copy %lua_build_dir%\src\*.exe %lua_install_dir%\bin\*.*
copy %lua_build_dir%\src\*.dll %lua_install_dir%\bin\*.*
copy %lua_build_dir%\src\luaconf.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lua.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lualib.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lauxlib.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lua.hpp %lua_install_dir%\include\*.*
echo.
echo **** BINARY DISTRIBUTION BUILT ****
echo.
%lua_install_dir%\bin\lua.exe -e"print [[Hello!]];print[[Simple Lua test successful!!!]]"
echo.
pause
右键以管理员身份运行 build.bat
不出意外的话会有如下显示,同时当前目录下出现 lua
目录
将 lua
目录放到安装位置,并将其 bin
目录添加到环境变量 PATH
中
输入 lua -i
验证安装
完成