NLua / NLua

Bridge between Lua and the .NET.
http://nlua.org
MIT License
2.05k stars 309 forks source link

Dispose NLua #526

Closed 1ToastyBred1 closed 3 months ago

1ToastyBred1 commented 9 months ago

what if user makes infinite loop? how do i stop NLua from executing without disposing it

maiswan commented 4 months ago

327 refers to a similar scenario, and this Stack Overflow question shows a sample implementation.

The main idea is to set up a hook that triggers upon Lua executing a new line:

state.SetDebugHook(KeraLua.LuaHookMask.Line, 0);
state.DebugHook += State_DebugHook

In the event handler, if needed (e.g. runtime exceeded), raise an exception to halt the script:

sender.State.Error()

Remember to catch the exception in the .NET code.

1ToastyBred1 commented 3 months ago

Oh thanks, I haven't noticed you commenting, it works so I will close issue as completed.