summaryrefslogtreecommitdiff
path: root/core/src/xmake/process/open.c
diff options
context:
space:
mode:
authorruki <[email protected]>2019-08-17 00:49:06 +0800
committerruki <[email protected]>2019-08-16 22:54:38 +0800
commit1de49ce846981a065ce3bea73591b797718ae993 (patch)
tree30f6332a3b94e112f7e8ef7e0c9d38e72e5dde81 /core/src/xmake/process/open.c
parent3edf63549fd45db761e09452b9b1af2ce23ee751 (diff)
add subprocess
Diffstat (limited to 'core/src/xmake/process/open.c')
-rw-r--r--core/src/xmake/process/open.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/core/src/xmake/process/open.c b/core/src/xmake/process/open.c
index fad3e8fec..bbb78ad27 100644
--- a/core/src/xmake/process/open.c
+++ b/core/src/xmake/process/open.c
@@ -133,7 +133,27 @@ tb_int_t xm_process_open(lua_State* lua)
// init process
tb_process_ref_t process = (tb_process_ref_t)tb_process_init_cmd(command, &attr);
- if (process) lua_pushlightuserdata(lua, (tb_pointer_t)process);
+ if (process)
+ {
+ // init subprocess
+ xm_subprocess_t* subprocess = xm_subprocess_new(lua);
+ subprocess->process = process;
+ subprocess->is_opened = tb_true;
+
+ // attach subprocess
+ tb_process_priv_set(process, subprocess);
+
+ // save subprocess name
+ tb_size_t name_maxn = tb_arrayn(subprocess->name);
+ tb_strlcpy(subprocess->name, "subprocess: ", name_maxn);
+ if (command_size < name_maxn - tb_arrayn("subprocess: "))
+ tb_strcat(subprocess->name, command);
+ else
+ {
+ tb_strcat(subprocess->name, "...");
+ tb_strcat(subprocess->name, command + (command_size - name_maxn + tb_arrayn("subprocess: ") + tb_arrayn("...")));
+ }
+ }
else lua_pushnil(lua);
return 1;
}