Tick rate control
In Lua 5.1 we were able to limit the tick rate with the debug library, but it hasn't been implemented on UniLua. Can you at least implement some functions to control the tick rate/infinite loops/stack overflow?
Could you describe how this can be done in lua 5.1 for reference?
Right now I'm on phone, so I'll get you the quickest answer. Once I go to my computer I'll repost an implemented answer.
debug.sethook(function, "", quota) Quota is every how many operations Lua will trigger the function from the first argument. If you want, you can add an error to the function from the first argument and the execution will stop. I'm not sure about the second parameter because I haven't used used this function for more things, but as I said, I'll repost an implemented answer.
Also: if you put set the quota to 1000 and in Lua code you do the following. for i =1, 2000 do end
The function should be called, and if it triggers an error, the execution should stop on i = 1000
Thanks, I got it. It's the sethook function in debug library. I'll work on it later.
probably it will be pointless if I repost it now, because you seem to have got it. But I'll do it anyway. I used this code: debug.sethook(function () error("tick quota exceeded") end, "", 5000) for i = 1, 10000 do print(i) end It prints from 1 to 1249, and after 1249 it breaks with the error "tick quota exceeded"
Hey, after I did some more tests with the debug library I noticed that the "l" mode does not detect infinite loops. This is quite essential to execute untrusted code in the server environment. When you start making this function, could you add another mode like "a" that would detect any kind of loops (from the "l" mode) and incluiding while and repeat-loops (the undetectable ones)?
Hey, it's been about two or three months. So I'm just wondering if you can do it or not, how much more time would that take? The only purpose I have on this is to run untrustable code with UniLua so I could stop people from doing infinite loops that crashes the VM.