Change Ctrl-t r lua funtcion to start with the previous call state

When calling the Lua interpreter with Ctrl-t r, change to start with the
previous call state.

This allows you to use it like REPL:
(example)
  Ctrl-t r : my_library.lua
  Ctrl-t r : !result1 = my_func("test1"); result2 = my_func("test2")
  Ctrl-t r : !if (result1 == result2) then print("OK") else print("NG")
  Ctrl-t r : @new

When you enter strings using Ctrl-t r, the string is interpreted as
follows:
- If the string does not begin with either "!" or "@", the string is
assumed to be the file name of a script and is executed.
- If the string begins with "!", the string excluding the "!" is
interpreted as Lua commands.
- If the string begins with "@", Strings beginning with "@" are
considered instructions to the interpreter. Currently valid instructions
are:
@new: Clear the Lua state. (== reset the Lua interpreter.)
@doopt: Execute the Lua script action specified by the option that start
with clearing the Lua state.
@nuldo=opt: do @doopt action when an empty string is entered (default).
@nuldo=none: Do nothing when an empty string is entered.

And now, lua interpreter start with GC.
If you need to stop GC, do lua function collectgarbage("stop").
This commit is contained in:
yabu76 2025-11-29 18:03:30 +09:00
parent 0983ce6eeb
commit a9f05a66f7
3 changed files with 95 additions and 24 deletions

View file

@ -1078,16 +1078,9 @@ void handle_command_sequence(char input_char, char *output_char, bool *forward)
case KEY_R:
/* Run script */
tio_printf("Run Lua script");
if (tio_subcmd_readln("Enter file name: "))
{
clear_line();
script_run(device_fd, line);
}
else
{
clear_line();
script_run(device_fd, NULL);
}
tio_subcmd_readln("Enter file name or \"!\" lua commands or \"@\" direction to interpreter: ");
clear_line();
script_run(device_fd, line);
break;
case KEY_SHIFT_R:
@ -2685,7 +2678,7 @@ int tty_connect(void)
/* Manage script activation */
if (option.script_run != SCRIPT_RUN_NEVER)
{
script_run(device_fd, NULL);
script_run_as_specified_by_options(device_fd);
if (option.script_run == SCRIPT_RUN_ONCE)
{