From 418a43d96e949fa0f51696120b8e4bf7906484fa Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Fri, 12 Apr 2024 00:08:45 +0200 Subject: [PATCH] Add lua send(string) --- man/tio.1.in | 3 ++- src/script.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/man/tio.1.in b/man/tio.1.in index 1442975..bec35c0 100644 --- a/man/tio.1.in +++ b/man/tio.1.in @@ -384,7 +384,8 @@ available: Send file using x/y-modem protocol. Protocol can be any of XMODEM_1K, XMODEM_CRC, YMODEM. - +.IP "\fBsend(string)" +Send string. .IP "\fBhigh(line)" Set tty line high. .IP "\fBlow(line)" diff --git a/src/script.c b/src/script.c index e017205..063c583 100644 --- a/src/script.c +++ b/src/script.c @@ -19,6 +19,7 @@ * 02110-1301, USA. */ +#include #include #include #include @@ -186,6 +187,28 @@ static int modem_send(lua_State *L) return 0; } +// lua: send(string) +static int send(lua_State *L) +{ + const char *string = lua_tostring(L, 1); + int ret; + + if (string == NULL) + { + return 0; + } + + ret = write(serial_fd, string, strlen(string)); + if (ret < 0) + { + tio_error_print("%s\n", strerror(errno)); + } + + lua_pushnumber(L, ret); + + return 1; +} + static void script_buffer_run(lua_State *L, const char *script_buffer) { int error; @@ -210,6 +233,7 @@ static const struct luaL_Reg tio_lib[] = { "config_low", config_low}, { "config_apply", config_apply}, { "modem_send", modem_send}, + { "send", send}, {NULL, NULL} };