From e1e3e298bf8e6fd3bb3a8620c363a077d6019a7e Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Sat, 13 Apr 2024 16:44:07 +0200 Subject: [PATCH] Add lua exit(code) --- README.md | 3 +++ man/tio.1.in | 2 ++ src/script.c | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 0558d32..fc6d3c1 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,9 @@ In addition to the Lua API tio makes the following functions available: Protocol can be any of XMODEM_1K, XMODEM_CRC, YMODEM. + exit(code) + Exit with code. + high(line) Set tty line high. diff --git a/man/tio.1.in b/man/tio.1.in index 1bc32c8..45ee188 100644 --- a/man/tio.1.in +++ b/man/tio.1.in @@ -389,6 +389,8 @@ Send string. Send file using x/y-modem protocol. Protocol can be any of XMODEM_1K, XMODEM_CRC, YMODEM. +.IP "\fBexit(code)" +Exit with exit code. .IP "\fBhigh(line)" Set tty line high. .IP "\fBlow(line)" diff --git a/src/script.c b/src/script.c index 7874574..d8c4487 100644 --- a/src/script.c +++ b/src/script.c @@ -315,6 +315,16 @@ error: return 1; } +// lua: exit(code) +static int exit_(lua_State *L) +{ + long code = lua_tointeger(L, 1); + + exit(code); + + return 0; +} + static void script_buffer_run(lua_State *L, const char *script_buffer) { int error; @@ -341,6 +351,7 @@ static const struct luaL_Reg tio_lib[] = { "modem_send", modem_send}, { "send", send}, { "expect", expect}, + { "exit", exit_}, {NULL, NULL} };