lua-users home
lua-l archive

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

Hello all,

I'm taken with the idea of embedding Lua for use in a multi-user game
environment, where users will be able to write and load Lua objects and
functions in real time that will interact in the game.

However, I am looking for a way to put limits on the code that users can
run.  Namely, I don't want to see somebody kick something off with an
infinite loop and lock up the entire game.

The solution seems to be to use Lua's debugging API to let the system
check the running process occasionally, and limit either the amount of
execution time a particular function gets, or the number of times that it
can loop through a particular point.  If I'm not mistaken, the line hook
should be sufficient for this sort of thing.

My question is, primarily, is this a bad way to go about it?  The hooks
are classified as being there for debugging purposes, and I'm essentially
wanting to use them to create a sandbox.  Are there any problems or
pitfalls to this approach that I should be aware of?  Would I be taking a
significant performance hit with this sort of monitoring?

I'd appreciate any thoughts or admonitions that the community might have
on this matter before I write a lot of ill advised code.  If you need more
of an idea of what I'm wanting to do, let me know, I'll be glad to share
my schemes.