Add repeat functionality
This commit is contained in:
parent
c2bd680299
commit
c117482d4f
@ -25,7 +25,7 @@ fn reentrant_command_handler(
|
||||
match command.split_out_command() {
|
||||
None => (),
|
||||
Some((cmd, rest)) => {
|
||||
if cmd.starts_with('#') {
|
||||
if let ("#", command_rest) = cmd.split_at(1) {
|
||||
if cmd == "##" {
|
||||
match lua_state.execute(debrace(&join(rest.arguments.iter(), " "))) {
|
||||
Ok(()) => (),
|
||||
@ -34,9 +34,17 @@ fn reentrant_command_handler(
|
||||
.unwrap_or(())
|
||||
}
|
||||
}
|
||||
} else if let Ok(repeat_count) = command_rest.parse::<u16>() {
|
||||
for _ in 0..repeat_count {
|
||||
reentrant_command_handler(
|
||||
lua_state,
|
||||
globals,
|
||||
term_frame,
|
||||
&join(rest.arguments.iter(), " "),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
let cmd = &cmd[1..];
|
||||
match lua_state.execute_command(cmd, &rest.arguments) {
|
||||
match lua_state.execute_command(command_rest, &rest.arguments) {
|
||||
Ok(()) => (),
|
||||
Err(msg) => {
|
||||
echo_to_term_frame(globals, term_frame, &format!("{}\r\n", msg))
|
||||
|
@ -58,8 +58,11 @@ impl LuaState {
|
||||
.try_enter(|ctx| {
|
||||
let commands =
|
||||
Table::from_value(ctx, ctx.get_global(ctx.intern_static(b"commands")))?;
|
||||
let command_fn =
|
||||
Function::from_value(ctx, commands.get(ctx, ctx.intern(command.as_bytes())))?;
|
||||
let command_value: Value = commands.get(ctx, ctx.intern(command.as_bytes()));
|
||||
if command_value.is_nil() {
|
||||
Err(anyhow::Error::msg("Unknown command"))?;
|
||||
}
|
||||
let command_fn = Function::from_value(ctx, command_value)?;
|
||||
ctx.fetch(&self.exec).restart(
|
||||
ctx,
|
||||
command_fn,
|
||||
|
Loading…
Reference in New Issue
Block a user