From e612d80cc3c3ef139bfcf8b5acee57262b41be13 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Sat, 4 Jan 2025 04:29:39 +0100 Subject: WIP --- tools/wdye/wdye.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'tools/wdye/wdye.c') 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[] = -- cgit v1.2.3-70-g09d2