diff options
| author | ruki <[email protected]> | 2019-08-20 00:08:52 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-08-19 18:53:17 +0800 |
| commit | 5dceabc08c22eb01c78dabab6d5a911d807ee850 (patch) | |
| tree | 9fe020abc692dac632b86ee241cd340904facf85 /xmake/core/base/io.lua | |
| parent | 45f213599deff032a2c64557bd2fadecdab6c272 (diff) | |
lazy loading stdfile
Diffstat (limited to 'xmake/core/base/io.lua')
| -rw-r--r-- | xmake/core/base/io.lua | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/xmake/core/base/io.lua b/xmake/core/base/io.lua index ac405dbac..883fdd19f 100644 --- a/xmake/core/base/io.lua +++ b/xmake/core/base/io.lua @@ -619,10 +619,20 @@ function io.tail(filepath, linecount, opt) end end --- init stdfile -io.stdin = io.stdfile("/dev/stdin") -io.stdout = io.stdfile("/dev/stdout") -io.stderr = io.stdfile("/dev/stderr") +-- lazy loading stdfile +io.stdin = nil +io.stdout = nil +io.stderr = nil +setmetatable(io, { __index = function (tbl, key) + local val = rawget(tbl, key) + if val == nil and (key == "stdin" or key == "stdout" or key == "stderr") then + val = io.stdfile("/dev/" .. key) + if val ~= nil then + rawset(tbl, key, val) + end + end + return val + end}) -- return module return io |
