Reputation: 15508
I stumbled across a problem where I am able to save my code onto the flash memory of an ESP8266 successfully, but as soon as it starts I get a "not enough memory" error.
The code itself doesn't create a lot of objects. It appears to me as if the code size per se is the problem. So I was wondering if the complete code would actually be loaded into the RAM in plain text during the execution.
I also tried the compile & upload button in my Esplorer, which didn't seem to change much.
By how much does compiling Lua actually reduce the code size? I would have thought that at least all the white space overhead would be gone.
Upvotes: 2
Views: 657
Reputation: 23535
We have a chapter on cross-compiling Lua for the ESP8266 on your computer at https://nodemcu.readthedocs.io/en/dev/en/upload/#compiling-lua-on-your-pc-for-uploading
Furthermore, if you combine node.stripdebug()
with node.compile()
(i.e. compiling on the device) you can also reduce the memory footprint of your application.
if you use
require("XXX")
to load your code then this will automatically search forXXX.lc
thenXXX.lua
Upvotes: 2
Reputation: 5847
Yes, script is loaded in ram before being executed.
It takes more ram if Lua source is plain text, as Lua VM will have to compile it into bytecode. In general, you can precompile Lua source outside of target Lua VM, see http://www.eluaproject.net/doc/v0.8/en_using.html, section "Cross-compiling your eLua programs"
And you will want to compile with debug info stripped out. See -s
option of luac
.
Upvotes: 2