diff options
| author | ruki <[email protected]> | 2019-08-16 22:32:05 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-08-16 17:49:18 +0800 |
| commit | 11ae86985a2d2d8811d34eff4bbd37e3582aafc9 (patch) | |
| tree | c23759758dd97390beaa5522b6aec6175b6f81bc /core/src | |
| parent | 9588bc931c37322955165eb085c83d6e2dd4fee3 (diff) | |
improve process.open
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/process/open.c | 30 | ||||
| -rw-r--r-- | core/src/xmake/process/openv.c | 16 |
2 files changed, 33 insertions, 13 deletions
diff --git a/core/src/xmake/process/open.c b/core/src/xmake/process/open.c index 3318f6017..2b552028d 100644 --- a/core/src/xmake/process/open.c +++ b/core/src/xmake/process/open.c @@ -34,22 +34,44 @@ * implementation */ -// p = process.open(command, outpath, errpath) +// p = process.open(command, {outpath = "", errpath = ""}) tb_int_t xm_process_open(lua_State* lua) { // check tb_assert_and_check_return_val(lua, 0); - // get the command + // get command size_t command_size = 0; tb_char_t const* command = luaL_checklstring(lua, 1, &command_size); - tb_char_t const* outpath = lua_tostring(lua, 2); - tb_char_t const* errpath = lua_tostring(lua, 3); tb_check_return_val(command, 0); // init attributes tb_process_attr_t attr = {0}; + // get option arguments + tb_char_t const* outpath = tb_null; + tb_char_t const* errpath = tb_null; + if (lua_istable(lua, 2)) + { + // get outpath + lua_pushstring(lua, "outpath"); + lua_gettable(lua, 2); + outpath = lua_tostring(lua, -1); + lua_pop(lua, 1); + + // get errpath + lua_pushstring(lua, "errpath"); + lua_gettable(lua, 2); + errpath = lua_tostring(lua, -1); + lua_pop(lua, 1); + } + else + { + // @deprecated compatible with process.open(cmd, outpath, errpath) + outpath = lua_tostring(lua, 2); + errpath = lua_tostring(lua, 3); + } + // redirect stdout? if (outpath) { diff --git a/core/src/xmake/process/openv.c b/core/src/xmake/process/openv.c index 92e552783..d5539512a 100644 --- a/core/src/xmake/process/openv.c +++ b/core/src/xmake/process/openv.c @@ -34,7 +34,7 @@ * implementation */ -// p = process.openv(shellname, argv, outpath, errpath, envs) +// p = process.openv(shellname, argv, outfile, errfile, envs) tb_int_t xm_process_openv(lua_State* lua) { // check @@ -51,8 +51,8 @@ tb_int_t xm_process_openv(lua_State* lua) // get the output and error file tb_char_t const* shellname = lua_tostring(lua, 1); - tb_char_t const* outpath = lua_tostring(lua, 3); - tb_char_t const* errpath = lua_tostring(lua, 4); + tb_char_t const* outfile = lua_tostring(lua, 3); + tb_char_t const* errfile = lua_tostring(lua, 4); tb_check_return_val(shellname, 0); // get environments @@ -137,21 +137,19 @@ tb_int_t xm_process_openv(lua_State* lua) if (envn > 0) attr.envp = envs; // redirect stdout? - if (outpath) + if (outfile) { // redirect stdout to file - attr.outpath = outpath; + attr.outfile = outfile; attr.outmode = TB_FILE_MODE_RW | TB_FILE_MODE_TRUNC | TB_FILE_MODE_CREAT; - attr.outtype = TB_PROCESS_REDIRECT_TYPE_FILEPATH; } // redirect stderr? - if (errpath) + if (errfile) { // redirect stderr to file - attr.errpath = errpath; + attr.errfile = errfile; attr.errmode = TB_FILE_MODE_RW | TB_FILE_MODE_TRUNC | TB_FILE_MODE_CREAT; - attr.errtype = TB_PROCESS_REDIRECT_TYPE_FILEPATH; } // init process |
