diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/wdye/wdye.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/tools/wdye/wdye.c b/tools/wdye/wdye.c index 3985abf..6ab903f 100644 --- a/tools/wdye/wdye.c +++ b/tools/wdye/wdye.c @@ -235,8 +235,23 @@ static int xlua_process_send (lua_State *L) { struct process *self = luaL_checkudata (L, 1, XLUA_PROCESS_METATABLE); - // TODO(p) - return 0; + int nargs = lua_gettop (L); + for (int i = 2; i <= nargs; i++) + if (!lua_isstring (L, i)) + return luaL_error (L, "need string arguments"); + + for (int i = 2; i <= nargs; i++) + { + size_t len = 0; + const char *arg = lua_tolstring (L, i, &len); + ssize_t written = write (self->terminal_fd, arg, len); + if (written == -1) + return luaL_error (L, "write failed: %s", strerror (errno)); + else if (written != len) + return luaL_error (L, "write failed: %s", "short write"); + } + lua_pushvalue (L, 1); + return 1; } static luaL_Reg xlua_process_table[] = |