|
Hi everyone,
i am quite new to lua and i want to execute pre compiled lua code directly from a memory mapped file. The background is this:
I am working in the embedded systems area and as you know memory consumption especially RAM usage is critical. In the system i am currently working on with a small team, there is the nice situation that we have a quite large flash. The uC in this system is capable of executing code directly from flash. From this flash the uC boots a small operating system which includes basic POSIX functionality like file operations etc.
On top of that we also included Lua as a script language based on a implementation from the eLua-project. In the eLua Version, which is Lua 5.1, there is a patch included which should save RAM usage.
I know now that the patch is not working as I expected because the pre compiled modules are still copied into the "package.loaded" table and therefore consume a lot of RAM.
The best thing would be, if we could execute pre compiled lua code from a memory mapped file. Than we could have a lot of pre compiled lua modules in the flash and work with them without wasting RAM. This feature would also be useful in Linux and Windows. In Linux you could use mmap() in windows there is an equivalent I don't know right now.
I would like to make a feature request on this for some next lua Version :) I think a generic implementation of this would be great in a lot of use cases. It could also be a feature you can activate or deactivate during the compilation of lua. I imagine something like this:
If you call mod = require 'mod' the loader can recognize if mod is in a pre-compiled file which is memory mapable. In Linux this would turn out in a call to mmap() in an embedded system you can
return a pointer with the starting address of the file in memory.
Than you can start using mod as you want but it is not copied into the lua state.
If there is another way or if you have other ideas how to save RAM in a lua sate please tell me.
Best regards,
Hans