|
|
|
@ -14,8 +14,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Generally useful function -- what luaL_checkudata() should do */
|
|
|
|
/* Generally useful function -- what luaL_checkudata() should do */
|
|
|
|
static void *
|
|
|
|
static void *luaL_checkuserdata(lua_State *L, int idx, const char *tname)
|
|
|
|
luaL_checkuserdata(lua_State *L, int idx, const char *tname)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
void *ud;
|
|
|
|
void *ud;
|
|
|
|
luaL_argcheck(L, ud = luaL_checkudata(L, idx, tname), idx, tname);
|
|
|
|
luaL_argcheck(L, ud = luaL_checkudata(L, idx, tname), idx, tname);
|
|
|
|
@ -45,24 +44,6 @@ static int windows_error(lua_State *L)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -- environment-table */
|
|
|
|
|
|
|
|
static int ex_environ(lua_State *L)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const char *envs, *nam, *val, *end;
|
|
|
|
|
|
|
|
if (!(envs = GetEnvironmentStrings()))
|
|
|
|
|
|
|
|
return windows_error(L);
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
|
|
|
|
for (nam = envs; *nam; nam = end + 1) {
|
|
|
|
|
|
|
|
val = strchr(nam, '=');
|
|
|
|
|
|
|
|
end = strchr(val, '\0');
|
|
|
|
|
|
|
|
lua_pushlstring(L, nam, val - nam);
|
|
|
|
|
|
|
|
val++;
|
|
|
|
|
|
|
|
lua_pushlstring(L, val, end - val);
|
|
|
|
|
|
|
|
lua_settable(L, -3);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* name -- value/nil */
|
|
|
|
/* name -- value/nil */
|
|
|
|
static int ex_getenv(lua_State *L)
|
|
|
|
static int ex_getenv(lua_State *L)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -100,6 +81,24 @@ static int ex_unsetenv(lua_State *L)
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -- environment-table */
|
|
|
|
|
|
|
|
static int ex_environ(lua_State *L)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const char *envs, *nam, *val, *end;
|
|
|
|
|
|
|
|
if (!(envs = GetEnvironmentStrings()))
|
|
|
|
|
|
|
|
return windows_error(L);
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
|
|
|
|
for (nam = envs; *nam; nam = end + 1) {
|
|
|
|
|
|
|
|
val = strchr(nam, '=');
|
|
|
|
|
|
|
|
end = strchr(val, '\0');
|
|
|
|
|
|
|
|
lua_pushlstring(L, nam, val - nam);
|
|
|
|
|
|
|
|
val++;
|
|
|
|
|
|
|
|
lua_pushlstring(L, val, end - val);
|
|
|
|
|
|
|
|
lua_settable(L, -3);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* seconds -- */
|
|
|
|
/* seconds -- */
|
|
|
|
static int ex_sleep(lua_State *L)
|
|
|
|
static int ex_sleep(lua_State *L)
|
|
|
|
@ -157,25 +156,21 @@ static int ex_dirent(lua_State *L) { return luaL_error(L, "not yet implemented")
|
|
|
|
static int file_lock(lua_State *L, FILE *fh, const char *mode, long offset, long length)
|
|
|
|
static int file_lock(lua_State *L, FILE *fh, const char *mode, long offset, long length)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HANDLE h = get_handle(fh);
|
|
|
|
HANDLE h = get_handle(fh);
|
|
|
|
DWORD flags = LOCKFILE_FAIL_IMMEDIATELY;
|
|
|
|
DWORD flags;
|
|
|
|
LARGE_INTEGER len = {0};
|
|
|
|
LARGE_INTEGER len = {0};
|
|
|
|
OVERLAPPED ov = {0};
|
|
|
|
OVERLAPPED ov = {0};
|
|
|
|
BOOL ret;
|
|
|
|
BOOL ret;
|
|
|
|
if (length)
|
|
|
|
if (length) len.LowPart = length;
|
|
|
|
len.LowPart = length;
|
|
|
|
else len.LowPart = GetFileSize(h, &len.HighPart);
|
|
|
|
else
|
|
|
|
|
|
|
|
len.LowPart = GetFileSize(h, &len.HighPart);
|
|
|
|
|
|
|
|
ov.Offset = offset;
|
|
|
|
ov.Offset = offset;
|
|
|
|
switch (*mode) {
|
|
|
|
switch (*mode) {
|
|
|
|
case 'r': break;
|
|
|
|
case 'w': flags = LOCKFILE_EXCLUSIVE_LOCK; /*FALLTHRU*/
|
|
|
|
case 'w': flags |= LOCKFILE_EXCLUSIVE_LOCK; break;
|
|
|
|
case 'r': flags |= LOCKFILE_FAIL_IMMEDIATELY; break;
|
|
|
|
case 'u': flags = 0; break;
|
|
|
|
case 'u': flags = 0; break;
|
|
|
|
default: return luaL_error(L, "invalid mode");
|
|
|
|
default: return luaL_error(L, "invalid mode");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flags)
|
|
|
|
ret = flags ? LockFileEx(h, flags, 0, len.LowPart, len.HighPart, &ov)
|
|
|
|
ret = LockFileEx(h, flags, 0, len.LowPart, len.HighPart, &ov);
|
|
|
|
: UnlockFileEx(h, 0, len.LowPart, len.HighPart, &ov);
|
|
|
|
else
|
|
|
|
|
|
|
|
ret = UnlockFileEx(h, 0, len.LowPart, len.HighPart, &ov);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
if (!ret)
|
|
|
|
return windows_error(L);
|
|
|
|
return windows_error(L);
|
|
|
|
lua_pushboolean(L, 1);
|
|
|
|
lua_pushboolean(L, 1);
|
|
|
|
@ -245,63 +240,69 @@ static int ex_pipe(lua_State *L)
|
|
|
|
return 2;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int needs_quoting(const char *s)
|
|
|
|
int abs_index(lua_State *L, int idx)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return idx >= 0 ? idx : lua_gettop(L) + idx + 1;
|
|
|
|
return s[0] != '"' && strchr(s, ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char *concat_args(lua_State *L, int index)
|
|
|
|
/* {arg1,arg 2} => " arg1 \"arg2\"" */
|
|
|
|
|
|
|
|
static const char *concat_args(lua_State *L)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
luaL_Buffer args;
|
|
|
|
luaL_Buffer args;
|
|
|
|
luaL_buffinit(L, &args);
|
|
|
|
luaL_buffinit(L, &args);
|
|
|
|
size_t i, n = lua_objlen(L, index);
|
|
|
|
size_t i, n = lua_objlen(L, -1);
|
|
|
|
index = abs_index(L, index);
|
|
|
|
|
|
|
|
for (i = 1; i <= n; i++) {
|
|
|
|
for (i = 1; i <= n; i++) {
|
|
|
|
int space;
|
|
|
|
int quote;
|
|
|
|
lua_rawgeti(L, index, i);
|
|
|
|
lua_rawgeti(L, -1, i); /* ... argtab arg */
|
|
|
|
space = 0 == strchr(luaL_checkstring(L, -1), ' ');
|
|
|
|
/* XXX checkstring is wrong here */
|
|
|
|
|
|
|
|
quote = needs_quoting(luaL_checkstring(L, -1));
|
|
|
|
luaL_putchar(&args, ' ');
|
|
|
|
luaL_putchar(&args, ' ');
|
|
|
|
if (space) luaL_putchar(&args, '"');
|
|
|
|
if (quote) luaL_putchar(&args, '"');
|
|
|
|
luaL_addvalue(&args);
|
|
|
|
luaL_addvalue(&args);
|
|
|
|
if (space) luaL_putchar(&args, '"');
|
|
|
|
if (quote) luaL_putchar(&args, '"');
|
|
|
|
|
|
|
|
lua_pop(L, 1); /* ... argtab */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lua_pop(L, n);
|
|
|
|
lua_pop(L, 1); /* ... */
|
|
|
|
luaL_pushresult(&args);
|
|
|
|
luaL_pushresult(&args); /* ... argstr */
|
|
|
|
return lua_tostring(L, -1);
|
|
|
|
return lua_tostring(L, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char *concat_env(lua_State *L, int index)
|
|
|
|
/* {nam1=val1,nam2=val2} => "nam1=val1\0nam2=val2\0" */
|
|
|
|
|
|
|
|
static const char *concat_env(lua_State *L)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
luaL_Buffer env;
|
|
|
|
luaL_Buffer env;
|
|
|
|
index = abs_index(L, index);
|
|
|
|
|
|
|
|
luaL_buffinit(L, &env);
|
|
|
|
luaL_buffinit(L, &env);
|
|
|
|
lua_pushnil(L); /* nil */
|
|
|
|
lua_pushnil(L); /* ... envtab nil */
|
|
|
|
while (lua_next(L, -2)) { /* k v */
|
|
|
|
while (lua_next(L, -2)) { /* ... envtab k v */
|
|
|
|
/* Is the luaL_checktype() warning message useful here? */
|
|
|
|
/* XXX luaL_checktype is wrong here */
|
|
|
|
luaL_checktype(L, -2, LUA_TSTRING);
|
|
|
|
luaL_checktype(L, -2, LUA_TSTRING);
|
|
|
|
luaL_checktype(L, -1, LUA_TSTRING);
|
|
|
|
luaL_checktype(L, -1, LUA_TSTRING);
|
|
|
|
lua_pushvalue(L, -2); /* k v k */
|
|
|
|
lua_pushvalue(L, -2); /* ... envtab k v k */
|
|
|
|
luaL_addvalue(&env);
|
|
|
|
luaL_addvalue(&env);
|
|
|
|
luaL_putchar(&env, '=');
|
|
|
|
luaL_putchar(&env, '=');
|
|
|
|
lua_pop(L, 1); /* k v */
|
|
|
|
lua_pop(L, 1); /* ... envtab k v */
|
|
|
|
luaL_addvalue(&env);
|
|
|
|
luaL_addvalue(&env);
|
|
|
|
luaL_putchar(&env, '\0');
|
|
|
|
luaL_putchar(&env, '\0');
|
|
|
|
lua_pop(L, 1); /* k */
|
|
|
|
lua_pop(L, 1); /* ... envtab k */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
luaL_putchar(&env, '\0');
|
|
|
|
luaL_putchar(&env, '\0');
|
|
|
|
luaL_pushresult(&env); /* env */
|
|
|
|
lua_pop(L, 1); /* ... */
|
|
|
|
|
|
|
|
luaL_pushresult(&env); /* ... envstr */
|
|
|
|
return lua_tostring(L, -1);
|
|
|
|
return lua_tostring(L, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void get_redirect(lua_State *L, const char *stream, HANDLE *handle)
|
|
|
|
/* XXX document me */
|
|
|
|
|
|
|
|
static int get_redirect(lua_State *L, const char *stdname, HANDLE *ph)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua_getfield(L, 2, stream);
|
|
|
|
int ret;
|
|
|
|
if (!lua_isnil(L, -1)) {
|
|
|
|
lua_getfield(L, 2, stdname);
|
|
|
|
|
|
|
|
if ((ret = !lua_isnil(L, -1))) {
|
|
|
|
|
|
|
|
/* XXX checkuserdata is wrong here */
|
|
|
|
FILE **pf = luaL_checkuserdata(L, -1, LUA_FILEHANDLE);
|
|
|
|
FILE **pf = luaL_checkuserdata(L, -1, LUA_FILEHANDLE);
|
|
|
|
*handle = get_handle(*pf);
|
|
|
|
*ph = get_handle(*pf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define PROCESS_HANDLE "process"
|
|
|
|
#define PROCESS_HANDLE "process"
|
|
|
|
@ -310,56 +311,110 @@ struct process {
|
|
|
|
int status;
|
|
|
|
int status;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* filename [options] -- true/nil,error */
|
|
|
|
/* filename [args-opts] -- true/nil,error */
|
|
|
|
/* args-options -- true/nil,error */
|
|
|
|
/* args-opts -- true/nil,error */
|
|
|
|
static int ex_spawn(lua_State *L)
|
|
|
|
static int ex_spawn(lua_State *L)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const char *cmdline;
|
|
|
|
const char *cmdline;
|
|
|
|
const char *environment;
|
|
|
|
const char *environment;
|
|
|
|
struct process *p;
|
|
|
|
struct process *p;
|
|
|
|
STARTUPINFO si;
|
|
|
|
STARTUPINFO si = {sizeof si};
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
BOOL ret;
|
|
|
|
BOOL ret;
|
|
|
|
/* XXX check for filename,options or just options */
|
|
|
|
|
|
|
|
luaL_checktype(L, 1, LUA_TSTRING);
|
|
|
|
if (lua_type(L, 1) == LUA_TTABLE) {
|
|
|
|
cmdline = lua_tostring(L, 1);
|
|
|
|
lua_getfield(L, 1, "command"); /* opts cmd */
|
|
|
|
|
|
|
|
if (!lua_isnil(L, -1)) {
|
|
|
|
|
|
|
|
/* convert {command=command,arg1,...} to command {arg1,...} */
|
|
|
|
|
|
|
|
lua_insert(L, 1); /* cmd opts */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
/* convert {arg0,arg1,...} to arg0 {arg1,...} */
|
|
|
|
|
|
|
|
int i, n = lua_objlen(L, 1);
|
|
|
|
|
|
|
|
lua_rawgeti(L, 1, 1); /* opts nil cmd */
|
|
|
|
|
|
|
|
if (lua_isnil(L, -1))
|
|
|
|
|
|
|
|
luaL_error(L, "no command specified");
|
|
|
|
|
|
|
|
lua_insert(L, 1); /* cmd opts nil */
|
|
|
|
|
|
|
|
for (i = 2; i <= n; i++) {
|
|
|
|
|
|
|
|
lua_rawgeti(L, 2, i); /* cmd opts nil argi */
|
|
|
|
|
|
|
|
lua_rawseti(L, 2, i - 1); /* cmd opts nil */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_rawseti(L, 2, n); /* cmd opts */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* get command */
|
|
|
|
|
|
|
|
cmdline = luaL_checkstring(L, 1);
|
|
|
|
|
|
|
|
if (needs_quoting(cmdline)) {
|
|
|
|
|
|
|
|
lua_pushliteral(L, "\""); /* cmd ... q */
|
|
|
|
|
|
|
|
lua_pushvalue(L, 1); /* cmd ... q cmd */
|
|
|
|
|
|
|
|
lua_pushvalue(L, -2); /* cmd ... q cmd q */
|
|
|
|
|
|
|
|
lua_concat(L, 3); /* cmd ... "cmd" */
|
|
|
|
|
|
|
|
lua_replace(L, 1); /* "cmd" ... */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* set defaults */
|
|
|
|
environment = 0;
|
|
|
|
environment = 0;
|
|
|
|
si.cb = sizeof si;
|
|
|
|
|
|
|
|
si.dwFlags = STARTF_USESTDHANDLES;
|
|
|
|
|
|
|
|
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
|
|
|
|
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
|
|
|
|
if (lua_type(L, 2) == LUA_TTABLE) {
|
|
|
|
|
|
|
|
lua_getfield(L, 2, "args");
|
|
|
|
/* get arguments, environment, and redirections */
|
|
|
|
if (!lua_isnil(L, -1)) {
|
|
|
|
switch (lua_type(L, 2)) {
|
|
|
|
luaL_checktype(L, -1, LUA_TTABLE);
|
|
|
|
default: luaL_argerror(L, 2, "expected options table"); break;
|
|
|
|
lua_pushvalue(L, 1); /* push filename */
|
|
|
|
case LUA_TNONE: break;
|
|
|
|
concat_args(L, -2);
|
|
|
|
case LUA_TTABLE:
|
|
|
|
lua_concat(L, 2); /* filename .. (" args")* */
|
|
|
|
lua_getfield(L, 2, "args"); /* cmd opts ... argtab */
|
|
|
|
|
|
|
|
switch (lua_type(L, -1)) {
|
|
|
|
|
|
|
|
default: luaL_error(L, "args option must be an array"); break;
|
|
|
|
|
|
|
|
case LUA_TNIL:
|
|
|
|
|
|
|
|
lua_pop(L, 1); /* cmd opts */
|
|
|
|
|
|
|
|
if (lua_objlen(L, 2) == 0) break;
|
|
|
|
|
|
|
|
lua_pushvalue(L, 2); /* cmd opts ... opts */
|
|
|
|
|
|
|
|
if (0)/*FALLTHRU*/
|
|
|
|
|
|
|
|
case LUA_TTABLE:
|
|
|
|
|
|
|
|
if (lua_objlen(L, -1) > 0)
|
|
|
|
|
|
|
|
luaL_error(L, "cannot specify both the args option and array values");
|
|
|
|
|
|
|
|
concat_args(L); /* cmd opts ... argstr */
|
|
|
|
|
|
|
|
lua_pushvalue(L, 1); /* cmd opts ... argstr cmd */
|
|
|
|
|
|
|
|
lua_replace(L, -2); /* cmd opts ... cmd argstr */
|
|
|
|
|
|
|
|
lua_concat(L, 2); /* cmd opts ... cmdline */
|
|
|
|
cmdline = lua_tostring(L, -1);
|
|
|
|
cmdline = lua_tostring(L, -1);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_getfield(L, 2, "env"); /* cmd opts ... envtab */
|
|
|
|
|
|
|
|
switch (lua_type(L, -1)) {
|
|
|
|
|
|
|
|
default: luaL_error(L, "env option must be a table"); break;
|
|
|
|
|
|
|
|
case LUA_TNIL:
|
|
|
|
|
|
|
|
lua_pop(L, 1); /* cmd opts */
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LUA_TTABLE:
|
|
|
|
|
|
|
|
environment = concat_env(L); /* cmd opts ... envstr */
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_redirect(L, "stdin", &si.hStdInput) /* cmd opts ... in? */
|
|
|
|
|
|
|
|
| get_redirect(L, "stdout", &si.hStdOutput) /* cmd opts ... out? */
|
|
|
|
|
|
|
|
| get_redirect(L, "stderr", &si.hStdError)) /* cmd opts ... err? */
|
|
|
|
|
|
|
|
si.dwFlags = STARTF_USESTDHANDLES;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lua_getfield(L, 2, "env");
|
|
|
|
p = lua_newuserdata(L, sizeof *p); /* cmd opts ... proc */
|
|
|
|
if (!lua_isnil(L, -1)) {
|
|
|
|
luaL_getmetatable(L, PROCESS_HANDLE); /* cmd opts ... proc M */
|
|
|
|
luaL_checktype(L, -1, LUA_TTABLE);
|
|
|
|
lua_setmetatable(L, -2); /* cmd opts ... proc */
|
|
|
|
environment = concat_env(L, -1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
get_redirect(L, "stdin", &si.hStdInput);
|
|
|
|
|
|
|
|
get_redirect(L, "stdout", &si.hStdOutput);
|
|
|
|
|
|
|
|
get_redirect(L, "stderr", &si.hStdError);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
p = lua_newuserdata(L, sizeof *p);
|
|
|
|
|
|
|
|
luaL_getmetatable(L, PROCESS_HANDLE);
|
|
|
|
|
|
|
|
lua_setmetatable(L, -2);
|
|
|
|
|
|
|
|
p->status = -1;
|
|
|
|
p->status = -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* XXX does CreateProcess modify its environment argument? */
|
|
|
|
cmdline = strdup(cmdline);
|
|
|
|
cmdline = strdup(cmdline);
|
|
|
|
environment = strdup(environment);
|
|
|
|
if (environment) environment = strdup(environment);
|
|
|
|
|
|
|
|
fprintf(stderr, "CreateProcess(%s)\n", cmdline);
|
|
|
|
ret = CreateProcess(0, (char *)cmdline, 0, 0, 0, 0, (char *)environment, 0, &si, &pi);
|
|
|
|
ret = CreateProcess(0, (char *)cmdline, 0, 0, 0, 0, (char *)environment, 0, &si, &pi);
|
|
|
|
free((char *)cmdline);
|
|
|
|
// if (environment) free((char *)environment);
|
|
|
|
free((char *)environment);
|
|
|
|
// free((char *)cmdline);
|
|
|
|
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
if (!ret)
|
|
|
|
return windows_error(L);
|
|
|
|
return windows_error(L);
|
|
|
|
p->hProcess = pi.hProcess;
|
|
|
|
p->hProcess = pi.hProcess;
|
|
|
|
return 1;
|
|
|
|
return 1; /* ... proc */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* proc -- exitcode/nil error */
|
|
|
|
/* proc -- exitcode/nil error */
|
|
|
|
@ -373,7 +428,7 @@ static int process_wait(lua_State *L)
|
|
|
|
p->status = exitcode;
|
|
|
|
p->status = exitcode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lua_pushnumber(L, p->status);
|
|
|
|
lua_pushnumber(L, p->status);
|
|
|
|
return 1;
|
|
|
|
return 1; /* exitcode */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -411,7 +466,6 @@ static const luaL_reg ex_process_methods[] = {
|
|
|
|
|
|
|
|
|
|
|
|
int luaopen_ex(lua_State *L)
|
|
|
|
int luaopen_ex(lua_State *L)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/* extend the io table */
|
|
|
|
/* extend the io table */
|
|
|
|
lua_getglobal(L, "io");
|
|
|
|
lua_getglobal(L, "io");
|
|
|
|
if (lua_isnil(L, -1)) luaL_error(L, "io not loaded");
|
|
|
|
if (lua_isnil(L, -1)) luaL_error(L, "io not loaded");
|
|
|
|
|