Draft: Limit memory and CPU usage for Lua scripts
Adds configurable limits for memory and CPU usage in Lua scripts.
So even
while true do end
in a script can not freeze the game.
But we have a problem. With default build options LuaJIT doesn't allow to pass a custom allocator. Lua 5.1 C API has such function, but in LuaJIT it returns an error if LuaJIT was built without GC64.
So we have the following options:
- Do not limit memory for Lua scripts.
- Compile LuaJIT with
-DLUAJIT_ENABLE_GC64
and never use the LuaJIT provided by the system. - Sacrifice performance and switch to mainstream Lua. In this case we can also upgrade to Lua 5.3 or Lua 5.4 and have benefits of new language features (it particular it would automatically resolve #6505 (closed)).