From f2ea3df8a481ca20badd85e5597525bb8cb194ac Mon Sep 17 00:00:00 2001 From: TerryE Date: Thu, 3 Mar 2016 02:03:23 +0000 Subject: [PATCH] Fix break in luac.cross build and add some documentation --- app/include/module.h | 2 +- app/modules/linit.c | 5 +++++ docs/en/upload.md | 21 ++++++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/include/module.h b/app/include/module.h index 919d5758..5a399f47 100644 --- a/app/include/module.h +++ b/app/include/module.h @@ -67,7 +67,7 @@ const LOCK_IN_SECTION(".lua_rotable") \ luaR_table MODULE_PASTE_(lua_rotable_,name) = { luaname, map } -#if !(MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2) +#if !defined(LUA_CROSS_COMPILER) && !(MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2) # error "NodeMCU modules must be built with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)" #endif diff --git a/app/modules/linit.c b/app/modules/linit.c index 3eba138d..da14b73b 100644 --- a/app/modules/linit.c +++ b/app/modules/linit.c @@ -57,7 +57,12 @@ extern const luaR_entry math_map[]; BUILTIN_LIB( MATH, LUA_MATHLIBNAME, math_map); #endif +#ifdef LUA_CROSS_COMPILER +const luaL_Reg lua_libs[] = {{NULL, NULL}}; +const luaR_table lua_rotable[] = {{NULL, NULL}}; +#else extern const luaL_Reg lua_libs[]; +#endif void luaL_openlibs (lua_State *L) { const luaL_Reg *lib = lua_libs; diff --git a/docs/en/upload.md b/docs/en/upload.md index 8563472d..69e5221b 100644 --- a/docs/en/upload.md +++ b/docs/en/upload.md @@ -35,4 +35,23 @@ Supported platforms: Windows Source: [https://github.com/4refr0nt/luatool](https://github.com/4refr0nt/luatool) -Supported platforms: OS X, Linux, Windows, anything that runs Python \ No newline at end of file +Supported platforms: OS X, Linux, Windows, anything that runs Python + +# Compiling Lua on your PC for Uploading + +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. +