diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/.os.luadoc | 11 | ||||
-rw-r--r-- | core/init.lua | 16 |
2 files changed, 15 insertions, 12 deletions
diff --git a/core/.os.luadoc b/core/.os.luadoc index 4dd473fa..5891060b 100644 --- a/core/.os.luadoc +++ b/core/.os.luadoc @@ -14,11 +14,10 @@ module('os') -- @param argv A command line string that contains the program's name followed -- by arguments to pass to it. `PATH` is searched for program names. -- @param cwd Optional current working directory (cwd) for the child --- process. The default value is `nil`, which inherits the parent's cwd. +-- process. When omitted, the parent's cwd is used. -- @param env Optional list of environment variables for the child process. --- Each element in the list is a 'KEY=VALUE' string. The default value is --- `nil`, which inherits the parent's environment. --- This parameter should be omitted completely instead of specifying `nil`. +-- Each element in the list is a 'KEY=VALUE' string. When omitted, the +-- parent's environment is used. -- @param stdout_cb Optional Lua function that accepts a string parameter for a -- block of standard output read from the child. Stdout is read asynchronously -- in 1KB or 0.5KB blocks (depending on the platform), or however much data is @@ -32,8 +31,8 @@ module('os') -- @param exit_cb Optional Lua function that is called when the child process -- finishes. The child's exit status is passed. -- @return proc or nil plus an error message on failure --- @usage os.spawn('lua buffer.filename', nil, print) --- @usage proc = os.spawn('lua -e "print(io.read())"', nil, print) +-- @usage os.spawn('lua buffer.filename', print) +-- @usage proc = os.spawn('lua -e "print(io.read())"', print) -- proc:write('foo\n') -- @class function -- @name os.spawn diff --git a/core/init.lua b/core/init.lua index 25c28043..71e65c4f 100644 --- a/core/init.lua +++ b/core/init.lua @@ -18,14 +18,18 @@ keys = require('keys') _M = {} -- language modules table -- pdcurses compatibility. if CURSES and WIN32 then - function os.spawn(argv, cwd, ...) + function os.spawn(argv, ...) local current_dir = lfs.currentdir() - if cwd then lfs.chdir(cwd) end + local i = 1 + if type(select(i, ...)) == 'string' then + lfs.chdir(select(i, ...)) -- cwd + i = i + 1 + end + if type(select(i, ...)) == 'table' then i = i + 1 end -- env (ignore) local p = io.popen(argv..' 2>&1') - local cb_index = type(select(1, ...)) ~= 'table' and 1 or 2 -- ignore env - local stdout_cb, exit_cb = select(cb_index, ...), select(cb_index + 2, ...) - if stdout_cb then stdout_cb(p:read('a')) end - if exit_cb then exit_cb(select(3, p:close())) else p:close() end + if select(i, ...) then select(i, ...)(p:read('a')) end -- stdout_cb + local status = select(3, p:close()) + if select(i + 2, ...) then select(i + 2, ...)(status) end -- exit_cb lfs.chdir(current_dir) return p end |