mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Add Lua API twrite
The twrite Lua API is a variation of the write API, with the output
character mapping and output-delay / output-line-delay features enabled.
Since it processes each character internally, writing speed is slower
than the write API.
~~~~~~~~~~~~~~~~~~~~~~~
twrite(string)
Translate string with output character mapping and write the
translated string to serial device with output-delay /
output-line-delay.
This commit is contained in:
parent
6a590bd598
commit
9e51d2e4ee
2 changed files with 20 additions and 0 deletions
18
src/script.c
18
src/script.c
|
|
@ -286,6 +286,23 @@ static int api_write(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lua: tio.twrite(string)
|
||||||
|
static int api_twrite(lua_State *L)
|
||||||
|
{
|
||||||
|
size_t len = 0;
|
||||||
|
const char *string = luaL_checklstring(L, 1, &len);
|
||||||
|
|
||||||
|
for (; len > 0; --len, string++)
|
||||||
|
{
|
||||||
|
forward_to_tty(device_fd, *string);
|
||||||
|
}
|
||||||
|
tty_sync(device_fd);
|
||||||
|
|
||||||
|
lua_getglobal(L, "tio");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// lua: tio.read(size, timeout)
|
// lua: tio.read(size, timeout)
|
||||||
static int api_read(lua_State *L)
|
static int api_read(lua_State *L)
|
||||||
{
|
{
|
||||||
|
|
@ -462,6 +479,7 @@ static const struct luaL_Reg tio_lib[] =
|
||||||
{ "line_set", line_set},
|
{ "line_set", line_set},
|
||||||
{ "send", api_send},
|
{ "send", api_send},
|
||||||
{ "write", api_write},
|
{ "write", api_write},
|
||||||
|
{ "twrite", api_twrite},
|
||||||
{ "read", api_read},
|
{ "read", api_read},
|
||||||
{ "readline", api_readline},
|
{ "readline", api_readline},
|
||||||
{ "ttysearch", api_ttysearch},
|
{ "ttysearch", api_ttysearch},
|
||||||
|
|
|
||||||
|
|
@ -84,3 +84,5 @@ void tty_input_thread_wait_ready(void);
|
||||||
void tty_line_set(int fd, tty_line_config_t line_config[]);
|
void tty_line_set(int fd, tty_line_config_t line_config[]);
|
||||||
void tty_search(void);
|
void tty_search(void);
|
||||||
GList *tty_search_for_serial_devices(void);
|
GList *tty_search_for_serial_devices(void);
|
||||||
|
void forward_to_tty(int fd, char output_char);
|
||||||
|
void tty_sync(int fd);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue