# 02 · instruction-limit **演示**:`debug.sethook(fn, "", 1000)` 每 1000 条指令回调,超限 `error` 中断。 **运行时**:`lua54`、`luajit`。 **运行**: ```sh .tools/bin/lua54 scripts/run-example.lua examples/30-embedding-and-cpp/02-instruction-limit .tools/bin/lua54 scripts/test-example.lua examples/30-embedding-and-cpp/02-instruction-limit ``` **预期输出**(lua 5.4.9 / macOS arm64): ```text aborted=true message=instruction limit exceeded ``` **看点**:宿主可用 hook 防死循环;hook 本身有开销。 **注意**:必须在结束后 `sethook()` 清除,否则影响后续代码。