replace Process() constructor with process.start()
fixes wrong metatable and removes redundancy writing process.Process()
This commit is contained in:
parent
b07d37b89a
commit
9e5b6c72a7
|
@ -55,7 +55,7 @@ static int poll_process(process_t* proc, int timeout)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int process_new(lua_State* L)
|
static int process_start(lua_State* L)
|
||||||
{
|
{
|
||||||
int cmd_len = lua_rawlen(L, 1) + 1;
|
int cmd_len = lua_rawlen(L, 1) + 1;
|
||||||
const char** cmd = malloc(sizeof(char *) * cmd_len);
|
const char** cmd = malloc(sizeof(char *) * cmd_len);
|
||||||
|
@ -316,9 +316,10 @@ static int f_running(lua_State* L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct luaL_Reg process_methods[] = {
|
static const struct luaL_Reg lib[] = {
|
||||||
{ "__call", process_new },
|
{"start", process_start},
|
||||||
{ "__gc", f_gc},
|
{"strerror", process_strerror},
|
||||||
|
{"__gc", f_gc},
|
||||||
{"pid", f_pid},
|
{"pid", f_pid},
|
||||||
{"returncode", f_returncode},
|
{"returncode", f_returncode},
|
||||||
{"read", f_read},
|
{"read", f_read},
|
||||||
|
@ -333,20 +334,12 @@ static const struct luaL_Reg process_methods[] = {
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct luaL_Reg lib[] = {
|
|
||||||
{"strerror", process_strerror},
|
|
||||||
{NULL, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
int luaopen_process(lua_State *L)
|
int luaopen_process(lua_State *L)
|
||||||
{
|
{
|
||||||
luaL_newlib(L, lib);
|
|
||||||
|
|
||||||
luaL_newmetatable(L, API_TYPE_PROCESS);
|
luaL_newmetatable(L, API_TYPE_PROCESS);
|
||||||
luaL_setfuncs(L, process_methods, 0);
|
luaL_setfuncs(L, lib, 0);
|
||||||
lua_pushvalue(L, -1);
|
lua_pushvalue(L, -1);
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
lua_setfield(L, -2, "Process"); // process.Process
|
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
L_SETNUM(L, -1, "ERROR_INVAL", REPROC_EINVAL);
|
L_SETNUM(L, -1, "ERROR_INVAL", REPROC_EINVAL);
|
||||||
|
|
Loading…
Reference in New Issue