manen

Fancy Lua REPL
Log | Files | Refs | README | LICENSE

commit 67b49e180447c7f5c51019939dce271debb91612
parent 9797b0c74825cb672d639c24644277a0fdabcc77
Author: Sylvia Ivory <git@sivory.net>
Date:   Mon, 23 Jun 2025 17:01:32 -0700

Prevent hinter from stalling

Diffstat:
Msrc/editor.rs | 4++--
Msrc/hinter.rs | 5+++++
2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/editor.rs b/src/editor.rs @@ -6,7 +6,7 @@ use std::{ }, }; -use mlua::{HookTriggers, prelude::*}; +use mlua::prelude::*; use reedline::{ DefaultPrompt, DefaultPromptSegment, EditCommand, Emacs, KeyCode, KeyModifiers, Reedline, ReedlineEvent, Signal, default_emacs_keybindings, @@ -34,7 +34,7 @@ impl Editor { let cancel_lua = Arc::new(AtomicBool::new(false)); let inner_cancel = cancel_lua.clone(); - lua.set_hook(HookTriggers::EVERY_LINE, move |_lua, _debug| { + lua.set_hook(LuaHookTriggers::EVERY_LINE, move |_lua, _debug| { if inner_cancel.load(Ordering::Relaxed) { inner_cancel.store(false, Ordering::Relaxed); diff --git a/src/hinter.rs b/src/hinter.rs @@ -20,6 +20,11 @@ fn burner_lua() -> Lua { let math: LuaTable = globals.get("math").unwrap(); math.raw_remove("random").unwrap(); + lua.set_hook( + LuaHookTriggers::new().every_nth_instruction(256), + |_lua, _debug| Err(LuaError::runtime("timed out")), + ); + lua }