neolithos / neolua

A Lua implementation for the Dynamic Language Runtime (DLR).
https://neolua.codeplex.com/
Apache License 2.0
466 stars 76 forks source link

Abort or Cancel Lua code execution #136

Closed ShadowMarker789 closed 2 years ago

ShadowMarker789 commented 2 years ago

NeoLua Version: 1.3.13 from Nuget

Example to reproduce:

while(true) do
a = 1; 
end

If I'm letting users type in their own code and execute it, I need some way to 'cancel' the code execution.

I'm not able to see any methods that take in cancellation tokens or similar ways to stop execution.

As fun as it would be to abort the thread I have been told not to do this.

Also as fun as it would be to let users write while-true loops it's also a problem.

I could do it on another thread, but if we're wanting to manipulate UI elements the manipulations have to be executed on the WPF Dispatcher thread in the first place. That also doesn't solve the issue of having a Lua chunk spinning forever.

What do you think? I'm really enjoying NeoLua so far, it's fantastic.

ShadowMarker789 commented 2 years ago

I have just now realized that there is already issue #106 https://github.com/neolithos/neolua/issues/106 which for some reason did not come up when I searched "cancel" nor "abort"

neolithos commented 2 years ago

I descriped, a way to do this without changing the lua-script-code it self.

This is a strong, but really handy sword.