@AnalogWeapon
Yeah thats really good thinking.
I was aware of this problem but kinda just have been ignoring it. Technically only a problem if it actually happens lol. I mean if you think about it this is really also try for desktop Lua but there you usually have plenty of ram.
Anyway, I do think that handling the Lua memory allocation differently in this context makes a lot of sense.
As a rough proof on concept I think it should just kill the lua script without crashing the main program. If that's not what already happens.
I think ideally there would be some way or warning the user:
- Before the file is even sent to the device. (This isnt foolproof but we can at least make an attempt at this point)
- Before they actually run out of memory
This is getting very theoretical but we might even be able to do some static analysis on the Lua files. Kinda hard to say how much memory a given program might use when it is dynamically allocating. But in this case we actually have 100% control over all runtime "inputs". Meaning the user cant really do anything in the script that isnt evident just by reading the script. Whereas with a desktop Lua script the user could ask for input and get a number like 9 billion. In our case we can know and control the minimum and maximum ranges of all inputs. So we maybe can actually take a pretty good guess about how much memory a given script might use before it even runs.