隱藏功能

lua-users home
wiki

Lua C API 與標準程式庫可能含有部分未記錄、不被支援、和/或實驗性的功能。它們可能因為某些原因不受支持,而且可能會隨時消失或作出更改——請自行承擔相關風險。

關閉標準檔案

自 5.1.3 起,由於可能會產生 bug,所以不允許關閉標準檔案(例如 stdin、stdout 與 stderr)[1][5]

> assert(io.stdout:close())
stdin:1: cannot close standard file

以下為一個應謹慎使用的方法

local f = assert(io.open '/dev/null') -- or possibly NUL on Windows
debug.setfenv(io.stdout, debug.getfenv(f))
f:close()
assert(io.stdout:close()) -- ok

舊項目

參見


RecentChanges · 喜好設定
編輯 · 歷史
最後編輯時間 2014 年 9 月 27 日上午 1:46 GMT (diff)