lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello all!

Since this is my first post here, I'll just have to start by saying thanks to everyone who has been working on Lua. I started using Lua a few months back, and so far it's been a joy. I think it's a very elegant language. Thank you!

I'm investigating using Lua as a scripting language for content designers. If I want to make sure that none of the designer-supplied scripts can loop forever and freeze the host application, how would I do that?

Sample problem code:

f = coroutine.create(function() while true do print('x') end end) -- No yield()
coroutine.resume(f) -- Oh no

Some possible solutions I'm looking at:
- Change the interpreter, so that it returns an error if we've spent too much time / done too many operations.

- Run Lua in a separate thread and somehow stop it if it takes too long.

- Wrap f in code that calls yield(), and disallow bytecode in f that contains loops or backwards jumps. This would of course greatly limit what can be in a script. Something like this:

mycode.create = function(f)
assert(mycode.checknoloops(f))
return coroutine.create(function() f() coroutine.yield() end)
end

- Alternatively, don't fix it in code, just spend some time on teaching the content designers to write their scripts right.

If you have any suggestions or experience on how to best attack this problem, I'd be grateful.

Cheers,
Christian.