lua中的luarocks模块
在luarocks模块中,有一个luarocks.site_config模块(一个lua文件),其安装时便设定了操作系统类型。
touch test.lua
local lsc = require "luarocks.site_config"
local system = lsc.LUAROCKS_UNAME_S or io.popen("uname -s"):read("*l")
if system == "Darwin" then
-- do something darwin related
elseif system == "Windows" then
-- do something Windows related
elseif system == "Linux" then
-- do something Linux related
end
print(system)
执行结果:
[root@localhost lua]# lua test.lua
Linux
Mastiff@MastiffdeMacBook-Pro:~/Desktop% lua test.lua
Darwin