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/xmake/process/open.c | |
| parent | 9588bc931c37322955165eb085c83d6e2dd4fee3 (diff) | |
improve process.open
Diffstat (limited to 'core/src/xmake/process/open.c')
| -rw-r--r-- | core/src/xmake/process/open.c | 30 |
1 files changed, 26 insertions, 4 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) { |
