Shopify / go-lua

A Lua VM in Go
MIT License
3.13k stars 190 forks source link

How to deal with Lua infinite loop? #96

Open Charliechen1 opened 6 years ago

Charliechen1 commented 6 years ago

What if the Lua script is something like while true do end Is there any method that could kill such running lua script?

WillianBR commented 3 months ago

@Charliechen1 ,

Please, check the comment I wrote into Issue #132.

I guess the debug package has the sethook() function.

But I didn't test it on go-lua. I'll test it later today!

Using the Lua "C" library, I was able to limite the instructions count (IC). But the dangerous function should bee called with pcall() inside the Lua script, to avoid errors. And hooking into IC event, we can stop the loop.

I also need such feature into my own project with go-lua.

WillianBR