lua IO
io.output("xxx1") -- also be writed: local ff1 = io.output("xxx1"); 實際是以"w"模式打開文件xxx1,只是把句柄保存到全局表裏
io.write("*")io.close() -- equal to [io.close(io.output())] and [io.output():close()]
io.input("xxx2") -- also be writed: local ff2 = io.output("xxx2"); 實際是以"r"模式打開文件xxx2,只是把句柄保存到全局表裏
io.read("*")
io.close(io.input()) -- io.input():close()
local f1 = io.open("xxx3", "w")
f1:close()
lua variable scope
改變函數的環境
aa = 1
bb = 2
function nn()
local _ENV = {["aa"] = 100, ["print"]=_ENV.print}
return function () -- 此函數的環境變量變爲 { ["aa"] = 100, ["print"]=_ENV.print }
print(aa) -- 100
print(bb) -- nil
end
end
local ff = nn()
ff()