lupa
lupa copied to clipboard
Option to limit memory usage
I'd love to see an option to limit the max memory usage of a single LuaRuntime.
Lua supports passing a custom allocator function to lua_newstate
which could refuse to allocate more memory when the limit is reached.
An example of this can be found here on stackoverflow.
Currently implementing this in my fork and I stumpled over 2 problems:
- max_memory < ~2kb causes a
Failed to initialise Lua runtime
error (expected) - max_memory < 24kb causes a lua panic by
lua.luaL_openlibs(L)
- max_memory < 24440b causes a segmentation fault by
set_overflow_handler
So max_memory between 2kb-24.5kb causes some not very nice bugs.
Sounds like a great idea.
We could probably avoid initialisation time crashes by disabling the limitation until the Lua runtime is initialised. I think that's a fair thing to do: apply the limit only to memory that the user can control, not something that Lupa needs.
Sounds good, I'll finish writing tests and then work on that.