开发者

Setting timeout for embedded Lua

开发者 https://www.devze.com 2023-01-31 14:22 出处:网络
I have embedded Lua in a C/C+= application. I want to be able to set a timeout value to prevent getting trapped with badly written scripts that can result in infinite loops (or even string searches th

I have embedded Lua in a C/C+= application. I want to be able to set a timeout value to prevent getting trapped with badly written scripts that can result in infinite loops (or even string searches that take an infinite time to complete).

Basically, I want to be able to set a time interval and if the script fails to complete running at the end of that time interval, I want to be able to kill the Lua script engine (gracefully, if possible).

Anyone knows of best practise way to do开发者_运维技巧 this?


One way to control the amount of time a script takes is to set a count hook and then raise an error in the hook. But this does not work if the script can call C functions that may take a long time.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号