Search code examples
luanodemcuesplorer

Compiling Code for NodeMCU using Esplorer


I used the builtin compiler of Esplorer to compile .lua files in excess of 2KB and am unable to compile. NodeMCU resets and compilation aborted. Is there a way around to compile files in excess using Esplorer or any other way doing it outside Esplorer environment.


Solution

  • You could cross-compile on your PC before uploading. There's a chapter in the docs at https://nodemcu.readthedocs.io/en/dev/en/upload/#compiling-lua-on-your-pc-for-uploading about that.

    If you install lua on your development PC or Laptop then you can use the standard Lua compiler to syntax check any Lua source before downloading it to the ESP8266 module. However, the nodemcu compiler output uses different data types (e.g. it supports ROMtables) so the compiled output cannot run on the ESP8266.

    Compiling source on one platform for use on another (e.g. Intel x38 Window to ESP8266) is known as cross-compilation and the nodemcu firmware supports the compilation of luac.cross on *nix patforms which have Lua 5.1, the Lua filesystem module (lfs), and the essential GCC tools. Simply change directory to the firmware root directoy and run the command:

    lua tools/cross-lua.lua
    

    This will generate a luac.cross executable in your root directory which can be used to compile and to syntax-check Lua source on the Development machine for execution under nodemcu lua on the ESP8266.