Browse Source

Updated ROTables 1st tranch (#2742)

Updated ROTables
Terry Ellison 5 years ago
parent
commit
1990f95740
90 changed files with 1684 additions and 1863 deletions
  1. 0 2
      app/Makefile
  2. 5 10
      app/include/module.h
  3. 5 11
      app/include/pm/pmSleep.h
  4. 1 1
      app/include/user_config.h
  5. 0 4
      app/lua/lauxlib.c
  6. 59 69
      app/lua/lbaselib.c
  7. 20 24
      app/lua/ldblib.c
  8. 67 55
      app/lua/linit.c
  9. 44 78
      app/lua/lmathlib.c
  10. 14 21
      app/lua/loadlib.c
  11. 12 6
      app/lua/lrodefs.h
  12. 24 47
      app/lua/lrotable.c
  13. 21 14
      app/lua/lrotable.h
  14. 23 53
      app/lua/lstrlib.c
  15. 2 6
      app/lua/ltable.c
  16. 13 16
      app/lua/ltablib.c
  17. 1 1
      app/lua/luac_cross/Makefile
  18. 28 33
      app/lua/luac_cross/liolib.c
  19. 15 19
      app/lua/luac_cross/loslib.c
  20. 2 2
      app/lua/luaconf.h
  21. 9 9
      app/modules/adc.c
  22. 57 60
      app/modules/ads1115.c
  23. 6 6
      app/modules/adxl345.c
  24. 6 6
      app/modules/am2320.c
  25. 5 6
      app/modules/apa102.c
  26. 17 17
      app/modules/bit.c
  27. 14 14
      app/modules/bloom.c
  28. 14 14
      app/modules/bme280.c
  29. 11 11
      app/modules/bme680.c
  30. 9 9
      app/modules/bmp085.c
  31. 37 38
      app/modules/coap.c
  32. 9 10
      app/modules/color_utils.c
  33. 15 15
      app/modules/cron.c
  34. 22 22
      app/modules/crypto.c
  35. 10 10
      app/modules/dht.c
  36. 9 9
      app/modules/encoder.c
  37. 8 8
      app/modules/enduser_setup.c
  38. 55 51
      app/modules/file.c
  39. 7 7
      app/modules/gdbstub.c
  40. 19 19
      app/modules/gpio.c
  41. 19 20
      app/modules/gpio_pulse.c
  42. 6 6
      app/modules/hdc1080.c
  43. 6 6
      app/modules/hmc5883l.c
  44. 11 11
      app/modules/http.c
  45. 6 6
      app/modules/hx711.c
  46. 16 16
      app/modules/i2c.c
  47. 6 6
      app/modules/l3g4200d.c
  48. 11 11
      app/modules/mcp4725.c
  49. 6 6
      app/modules/mdns.c
  50. 34 34
      app/modules/mqtt.c
  51. 63 63
      app/modules/net.c
  52. 58 61
      app/modules/node.c
  53. 19 19
      app/modules/ow.c
  54. 25 25
      app/modules/pcm.c
  55. 6 6
      app/modules/perf.c
  56. 13 13
      app/modules/pwm.c
  57. 5 5
      app/modules/rc.c
  58. 5 6
      app/modules/rfswitch.c
  59. 17 17
      app/modules/rotary.c
  60. 12 12
      app/modules/rtcfifo.c
  61. 6 6
      app/modules/rtcmem.c
  62. 11 11
      app/modules/rtctime.c
  63. 16 16
      app/modules/si7021.c
  64. 10 11
      app/modules/sigma_delta.c
  65. 25 66
      app/modules/sjson.c
  66. 7 7
      app/modules/sntp.c
  67. 9 9
      app/modules/somfy.c
  68. 21 21
      app/modules/spi.c
  69. 2 0
      app/modules/sqlite3.c
  70. 5 6
      app/modules/struct.c
  71. 10 10
      app/modules/switec.c
  72. 11 11
      app/modules/tcs34725.c
  73. 30 30
      app/modules/tls.c
  74. 5 6
      app/modules/tm1829.c
  75. 31 31
      app/modules/tmr.c
  76. 23 23
      app/modules/tsl2561.c
  77. 62 66
      app/modules/u8g2.c
  78. 16 16
      app/modules/uart.c
  79. 65 67
      app/modules/ucg.c
  80. 17 19
      app/modules/websocket.c
  81. 102 102
      app/modules/wifi.c
  82. 2 2
      app/modules/wifi_common.h
  83. 47 49
      app/modules/wifi_eventmon.c
  84. 22 22
      app/modules/wifi_monitor.c
  85. 12 12
      app/modules/wps.c
  86. 7 8
      app/modules/ws2801.c
  87. 33 35
      app/modules/ws2812.c
  88. 17 18
      app/modules/ws2812_effects.c
  89. 12 12
      app/modules/xpt2046.c
  90. 9 9
      app/pm/swtimer.c

+ 0 - 2
app/Makefile

@@ -138,8 +138,6 @@ DEPENDS_eagle.app.v6 = 				\
 #	-DWLAN_CONFIG_CCX
 CONFIGURATION_DEFINES =	-D__ets__ 		\
 			-DICACHE_FLASH 		\
-			-DLUA_OPTIMIZE_MEMORY=2	\
-			-DMIN_OPT_LEVEL=2	\
 			-DLWIP_OPEN_SRC 	\
 			-DPBUF_RSV_FOR_WLAN 	\
 			-DEBUF_LWIP		\

+ 5 - 10
app/include/module.h

@@ -2,7 +2,7 @@
 #define __MODULE_H__
 
 #include "user_modules.h"
-#include "lrodefs.h"
+#include "lrotable.h"
 
 /* Registering a module within NodeMCU is really easy these days!
  *
@@ -18,11 +18,11 @@
  *
  * Then simply put a line like this at the bottom of your module file:
  *
- *   NODEMCU_MODULE(MYNAME, "myname", myname_map, luaopen_myname);
+ *   NODEMCU_MODULE(MYNAME, "myname", myname, luaopen_myname);
  *
  * or perhaps
  *
- *   NODEMCU_MODULE(MYNAME, "myname", myname_map, NULL);
+ *   NODEMCU_MODULE(MYNAME, "myname", myname, NULL);
  *
  * if you don't need an init function.
  *
@@ -67,13 +67,8 @@
  */
 #define NODEMCU_MODULE(cfgname, luaname, map, initfunc) \
   const LOCK_IN_SECTION(libs) \
-    luaL_Reg MODULE_PASTE_(lua_lib_,cfgname) = { luaname, initfunc }; \
+    luaR_entry MODULE_PASTE_(lua_lib_,cfgname) = { luaname, LRO_FUNCVAL(initfunc) }; \
   const LOCK_IN_SECTION(rotable) \
     luaR_entry MODULE_EXPAND_PASTE_(cfgname,MODULE_EXPAND_PASTE_(_module_selected,MODULE_PASTE_(LUA_USE_MODULES_,cfgname))) \
-    = {LSTRKEY(luaname), LROVAL(map)}
-
-#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
-
+    = {luaname, LRO_ROVAL(map ## _map)}
 #endif

+ 5 - 11
app/include/pm/pmSleep.h

@@ -24,23 +24,17 @@
   #define PMSLEEP_ERR(...)
 #endif
 
-
-
-
-
 #define PMSLEEP_SLEEP_MIN_TIME 50000
 #define PMSLEEP_SLEEP_MAX_TIME 268435454 //FPM_MAX_SLEEP_TIME-1
 #define pmSleep_INIT_CFG(X) pmSleep_param_t X = {.sleep_duration=0, .wake_pin=255, \
     .preserve_opmode=TRUE, .suspend_cb_ptr=NULL, .resume_cb_ptr=NULL}
 
 #define PMSLEEP_INT_MAP \
-  { LSTRKEY( "INT_BOTH" ),      LNUMVAL( GPIO_PIN_INTR_ANYEDGE ) }, \
-  { LSTRKEY( "INT_UP" ),        LNUMVAL( GPIO_PIN_INTR_POSEDGE ) }, \
-  { LSTRKEY( "INT_DOWN" ),      LNUMVAL( GPIO_PIN_INTR_NEGEDGE ) }, \
-  { LSTRKEY( "INT_HIGH" ),      LNUMVAL( GPIO_PIN_INTR_HILEVEL ) }, \
-  { LSTRKEY( "INT_LOW" ),       LNUMVAL( GPIO_PIN_INTR_LOLEVEL ) }
-
-
+  LROT_NUMENTRY( INT_BOTH, GPIO_PIN_INTR_ANYEDGE ) \
+  LROT_NUMENTRY( INT_UP, GPIO_PIN_INTR_POSEDGE ) \
+  LROT_NUMENTRY( INT_DOWN, GPIO_PIN_INTR_NEGEDGE ) \
+  LROT_NUMENTRY( INT_HIGH, GPIO_PIN_INTR_HILEVEL ) \
+  LROT_NUMENTRY( INT_LOW, GPIO_PIN_INTR_LOLEVEL )
 
 typedef struct pmSleep_param{
   uint32 sleep_duration;

+ 1 - 1
app/include/user_config.h

@@ -244,7 +244,7 @@ extern void luaL_dbgbreak(void);
 #endif
 #endif
 
-#if !defined(LUA_NUMBER_INTEGRAL) && defined (LUA_DWORD_ALIGNED_TVALUES)
+#if !defined(LUA_NUMBER_INTEGRAL) && !defined (LUA_DWORD_ALIGNED_TVALUES)
   #define LUA_PACK_TVALUES
 #else
   #undef LUA_PACK_TVALUES

+ 0 - 4
app/lua/lauxlib.c

@@ -419,11 +419,7 @@ LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
 
 LUALIB_API void (luaL_register_light) (lua_State *L, const char *libname,
                                 const luaL_Reg *l) {
-#if LUA_OPTIMIZE_MEMORY > 0
   luaI_openlib(L, libname, l, 0, LUA_USELIGHTFUNCTIONS);
-#else
-  luaI_openlib(L, libname, l, 0, LUA_USECCLOSURES);
-#endif
 }
 
 static int libsize (const luaL_Reg *l) {

+ 59 - 69
app/lua/lbaselib.c

@@ -16,7 +16,7 @@
 #include C_HEADER_STDLIB
 #include "lauxlib.h"
 #include "lualib.h"
-#include "lrodefs.h"
+#include "lrotable.h"
 
 
 
@@ -462,64 +462,59 @@ static int luaB_newproxy (lua_State *L) {
   return 1;
 }
 
-#include "lrodefs.h"
+#include "lrotable.h"
 
-extern const luaR_entry lua_rotable_base[];
+LROT_EXTERN(lua_rotable_base);
 
 /*
- * ESP builds use specific linker directives to marshal all ROTable declarations
- * into a single ROTable in the PSECT ".lua_rotable".
+ * Separate ROTables are used for the base functions and library ROTables, with
+ * the base functions ROTable declared below.  The library ROTable is chained
+ * from this using its __index meta-method.
  *
- * This is not practical on Posix builds using a standard link so for cross
- * compiler builds, separate ROTables are used for the base functions and library
- * ROTables, with the latter chained from the former using its __index meta-method.
- * In this case all library ROTables are defined in linit.c.
+ * ESP builds use specific linker directives to marshal all the ROTable entries
+ * for the library modules into a single ROTable in the PSECT ".lua_rotable".
+ * This is not practical on Posix builds using a standard GNU link, so the
+ * equivalent ROTable for the core libraries defined in linit.c for the cross-
+ * compiler build.
  */
-#ifdef LUA_CROSS_COMPILER
-#define BASE_ROTABLE    base_func_map
-#define LOCK_IN_ROTABLE
-static const LUA_REG_TYPE base_func_meta[] = {
-  LROT_TABENTRY(__index, lua_rotable_base),
-  LROT_END};
-#else
-#define BASE_ROTABLE    lua_rotable_base
-#define LOCK_IN_ROTABLE __attribute__((used,unused,section(".lua_rotable")))
-#endif
 
-static const LUA_REG_TYPE LOCK_IN_ROTABLE base_func_map[] = {
-  LROT_FUNCENTRY(assert,         luaB_assert),
-  LROT_FUNCENTRY(collectgarbage, luaB_collectgarbage),
-  LROT_FUNCENTRY(dofile,         luaB_dofile),
-  LROT_FUNCENTRY(error,          luaB_error),
-  LROT_FUNCENTRY(gcinfo,         luaB_gcinfo),
-  LROT_FUNCENTRY(getfenv,        luaB_getfenv),
-  LROT_FUNCENTRY(getmetatable,   luaB_getmetatable),
-  LROT_FUNCENTRY(loadfile,       luaB_loadfile),
-  LROT_FUNCENTRY(load,           luaB_load),
-  LROT_FUNCENTRY(loadstring,     luaB_loadstring),
-  LROT_FUNCENTRY(next,           luaB_next),
-  LROT_FUNCENTRY(pcall,          luaB_pcall),
-  LROT_FUNCENTRY(print,          luaB_print),
-  LROT_FUNCENTRY(rawequal,       luaB_rawequal),
-  LROT_FUNCENTRY(rawget,         luaB_rawget),
-  LROT_FUNCENTRY(rawset,         luaB_rawset),
-  LROT_FUNCENTRY(select,         luaB_select),
-  LROT_FUNCENTRY(setfenv,        luaB_setfenv),
-  LROT_FUNCENTRY(setmetatable,   luaB_setmetatable),
-  LROT_FUNCENTRY(tonumber,       luaB_tonumber),
-  LROT_FUNCENTRY(tostring,       luaB_tostring),
-  LROT_FUNCENTRY(type,           luaB_type),
-  LROT_FUNCENTRY(unpack,         luaB_unpack),
+LROT_EXTERN(lua_rotables);
+
+LROT_PUBLIC_BEGIN(base_func_meta)
+  LROT_TABENTRY( __index, lua_rotables )
+LROT_END(base_func, base_func_meta, LROT_MASK_INDEX)
+
+LROT_PUBLIC_BEGIN(base_func)
+  LROT_FUNCENTRY(assert,         luaB_assert)
+  LROT_FUNCENTRY(collectgarbage, luaB_collectgarbage)
+  LROT_FUNCENTRY(dofile,         luaB_dofile)
+  LROT_FUNCENTRY(error,          luaB_error)
+  LROT_FUNCENTRY(gcinfo,         luaB_gcinfo)
+  LROT_FUNCENTRY(getfenv,        luaB_getfenv)
+  LROT_FUNCENTRY(getmetatable,   luaB_getmetatable)
+  LROT_FUNCENTRY(loadfile,       luaB_loadfile)
+  LROT_FUNCENTRY(load,           luaB_load)
+  LROT_FUNCENTRY(loadstring,     luaB_loadstring)
+  LROT_FUNCENTRY(next,           luaB_next)
+  LROT_FUNCENTRY(pcall,          luaB_pcall)
+  LROT_FUNCENTRY(print,          luaB_print)
+  LROT_FUNCENTRY(rawequal,       luaB_rawequal)
+  LROT_FUNCENTRY(rawget,         luaB_rawget)
+  LROT_FUNCENTRY(rawset,         luaB_rawset)
+  LROT_FUNCENTRY(select,         luaB_select)
+  LROT_FUNCENTRY(setfenv,        luaB_setfenv)
+  LROT_FUNCENTRY(setmetatable,   luaB_setmetatable)
+  LROT_FUNCENTRY(tonumber,       luaB_tonumber)
+  LROT_FUNCENTRY(tostring,       luaB_tostring)
+  LROT_FUNCENTRY(type,           luaB_type)
+  LROT_FUNCENTRY(unpack,         luaB_unpack)
   LROT_FUNCENTRY(xpcall,         luaB_xpcall)
-#ifdef LUA_CROSS_COMPILER
- ,LROT_TABENTRY(__metatable,     base_func_meta),
-  LROT_END
-#endif
-};
+  LROT_TABENTRY(__metatable,     base_func_meta)
+LROT_END(base_func, base_func_meta, LROT_MASK_INDEX)
 
-static const luaL_Reg base_funcs[] = {
-  {NULL, NULL}
-};
+LROT_BEGIN(G_meta)
+  LROT_TABENTRY( __index, base_func )
+LROT_END(G_meta, NULL, 0)
 
 
 /*
@@ -650,17 +645,14 @@ static int luaB_corunning (lua_State *L) {
   return 1;
 }
 
-#undef MIN_OPT_LEVEL
-#define MIN_OPT_LEVEL 1
-const LUA_REG_TYPE co_funcs[] = {
-  {LSTRKEY("create"), LFUNCVAL(luaB_cocreate)},
-  {LSTRKEY("resume"), LFUNCVAL(luaB_coresume)},
-  {LSTRKEY("running"), LFUNCVAL(luaB_corunning)},
-  {LSTRKEY("status"), LFUNCVAL(luaB_costatus)},
-  {LSTRKEY("wrap"), LFUNCVAL(luaB_cowrap)},
-  {LSTRKEY("yield"), LFUNCVAL(luaB_yield)},
-  {LNILKEY, LNILVAL}
-};
+LROT_PUBLIC_BEGIN(co_funcs)
+  LROT_FUNCENTRY( create, luaB_cocreate )
+  LROT_FUNCENTRY( resume, luaB_coresume )
+  LROT_FUNCENTRY( running, luaB_corunning )
+  LROT_FUNCENTRY( status, luaB_costatus )
+  LROT_FUNCENTRY( wrap, luaB_cowrap )
+  LROT_FUNCENTRY( yield, luaB_yield )
+LROT_END (co_funcs, NULL, 0)
 
 /* }====================================================== */
 
@@ -676,14 +668,12 @@ static void base_open (lua_State *L) {
   /* set global _G */
   lua_pushvalue(L, LUA_GLOBALSINDEX);
   lua_setglobal(L, "_G");
+
   /* open lib into global table */
-  luaL_register_light(L, "_G", base_funcs);
-#if LUA_OPTIMIZE_MEMORY > 0
-  lua_pushvalue(L, -1);
-  lua_setmetatable(L, -2);
-  lua_pushrotable(L, (void *)BASE_ROTABLE);
-  lua_setglobal(L, "__index");
-#endif
+  luaL_register_light(L, "_G", &((luaL_Reg) {0}));
+  lua_pushrotable(L, LROT_TABLEREF(G_meta));
+  lua_setmetatable(L, LUA_GLOBALSINDEX);
+
   lua_pushliteral(L, LUA_VERSION);
   lua_setglobal(L, "_VERSION");  /* set global _VERSION */
   /* `ipairs' and `pairs' need auxliliary functions as upvalues */

+ 20 - 24
app/lua/ldblib.c

@@ -18,9 +18,9 @@
 #include "lualib.h"
 #include "lstring.h"
 #include "lflash.h"
-#include "user_modules.h"
-
+#include "lrotable.h"
 
+#include "user_modules.h"
 
 static int db_getregistry (lua_State *L) {
   lua_pushvalue(L, LUA_REGISTRYINDEX);
@@ -417,32 +417,28 @@ static int db_errorfb (lua_State *L) {
   return 1;
 }
 
-#undef MIN_OPT_LEVEL
-#define MIN_OPT_LEVEL 1
-#include "lrodefs.h"
-const LUA_REG_TYPE dblib[] = {
+LROT_PUBLIC_BEGIN(dblib)
 #ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
-  {LSTRKEY("debug"), LFUNCVAL(db_debug)},
-  {LSTRKEY("getfenv"), LFUNCVAL(db_getfenv)},
-  {LSTRKEY("gethook"), LFUNCVAL(db_gethook)},
-  {LSTRKEY("getinfo"), LFUNCVAL(db_getinfo)},
-  {LSTRKEY("getlocal"), LFUNCVAL(db_getlocal)},
+  LROT_FUNCENTRY( debug, db_debug )
+  LROT_FUNCENTRY( getfenv, db_getfenv )
+  LROT_FUNCENTRY( gethook, db_gethook )
+  LROT_FUNCENTRY( getinfo, db_getinfo )
+  LROT_FUNCENTRY( getlocal, db_getlocal )
 #endif
-  {LSTRKEY("getregistry"), LFUNCVAL(db_getregistry)},
-  {LSTRKEY("getstrings"), LFUNCVAL(db_getstrings)},
+  LROT_FUNCENTRY( getregistry, db_getregistry )
+  LROT_FUNCENTRY( getstrings, db_getstrings )
 #ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
-  {LSTRKEY("getmetatable"), LFUNCVAL(db_getmetatable)},
-  {LSTRKEY("getupvalue"), LFUNCVAL(db_getupvalue)},
-  {LSTRKEY("setfenv"), LFUNCVAL(db_setfenv)},
-  {LSTRKEY("sethook"), LFUNCVAL(db_sethook)},
-  {LSTRKEY("setlocal"), LFUNCVAL(db_setlocal)},
-  {LSTRKEY("setmetatable"), LFUNCVAL(db_setmetatable)},
-  {LSTRKEY("setupvalue"), LFUNCVAL(db_setupvalue)},
+  LROT_FUNCENTRY( getmetatable, db_getmetatable )
+  LROT_FUNCENTRY( getupvalue, db_getupvalue )
+  LROT_FUNCENTRY( setfenv, db_setfenv )
+  LROT_FUNCENTRY( sethook, db_sethook )
+  LROT_FUNCENTRY( setlocal, db_setlocal )
+  LROT_FUNCENTRY( setmetatable, db_setmetatable )
+  LROT_FUNCENTRY( setupvalue, db_setupvalue )
 #endif
-  {LSTRKEY("traceback"), LFUNCVAL(db_errorfb)},
-  {LNILKEY, LNILVAL}
-};
+  LROT_FUNCENTRY( traceback, db_errorfb )
+LROT_END(dblib, NULL, 0)
 
 LUALIB_API int luaopen_debug (lua_State *L) {
-  LREGISTER(L, LUA_DBLIBNAME, dblib);
+  return 0;
 }

+ 67 - 55
app/lua/linit.c

@@ -15,45 +15,43 @@
 #include "lauxlib.h"
 #include "luaconf.h"
 #include "module.h"
+#include "lstate.h"
 
-#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)"
+LROT_EXTERN(strlib);
+LROT_EXTERN(tab_funcs);
+LROT_EXTERN(dblib);
+LROT_EXTERN(co_funcs);
+LROT_EXTERN(math);
+#if defined(LUA_CROSS_COMPILER)
+LROT_EXTERN(oslib);
+LROT_EXTERN(iolib);
 #endif
-
-extern const luaR_entry strlib[], tab_funcs[],  dblib[],
-                        co_funcs[], math_map[], syslib[];
-extern const luaR_entry syslib[], io_funcs[];  // Only used on cross-compile builds
-
 /*
  * The NodeMCU Lua initalisation has been adapted to use linker-based module
- * registration.  This uses a PSECT naming convention to allow the lib and rotab
- * entries to be collected by the linker into consoliated tables.  The linker
- * defines lua_libs_base and lua_rotable_base.
+ * registration.  This uses a PSECT naming convention to allow the ROTable and
+ * initialisation function entries to be collected by the linker into two
+ * consoliated ROTables.  This significantly simplifies adding new modules and
+ * configuring builds with a small subset of the total modules.
+ *
+ * This linker-based approach is not practical for cross compiler builds which
+ * must link on a range of platforms, and where we don't have control of PSECT
+ * placement.   However unlike the target builds, the  luac.cross builds only
+ * used a small and fixed list of libraries and so in this case the table can
+ * be defined in this source file, so in this case all library ROTables are
+ * defined here, avoiding the need for linker magic is avoided on host builds.
  *
- * This is not practical on Posix builds which use a standard loader declaration
- * so for cross compiler builds, separate ROTables are used for the base functions
- * and library ROTables, with the latter chained from the former using its __index
- * meta-method. In this case all library ROTables are defined here, avoiding the
- * need for linker magic is avoided on host builds.
+ * Note that a separate ROTable is defined in lbaselib.c for the base functions
+ * and there is a metatable index cascade from _G to this base function table to
+ * the master rotables table.  In the target build, the linker marshals the
+ * table, hence the LROT_BREAK() macros which don't 0 terminate the lists.
  */
 
-#if defined(LUA_CROSS_COMPILER)
-#define LUA_ROTABLES lua_rotable_base
-#define LUA_LIBS     lua_libs_base
-#else /* declare Xtensa toolchain linker defined constants */
-extern const luaL_Reg    lua_libs_base[];
-extern const luaR_entry  lua_rotable_base[];
-#define LUA_ROTABLES lua_rotable_core
-#define LUA_LIBS     lua_libs_core
-#endif
-
 #ifdef _MSC_VER
 //MSVC requires us to declare these sections before we refer to them
 #pragma section(__ROSECNAME(A), read)
 #pragma section(__ROSECNAME(zzzzzzzz), read)
 #pragma section(__ROSECNAME(libs), read)
 #pragma section(__ROSECNAME(rotable), read)
-
 //These help us to find the beginning and ending of the RO data.  NOTE:  linker
 //magic is used; the section names are lexically sorted, so 'a' and 'z' are
 //important to keep the other sections lexically between these two dummy
@@ -61,43 +59,57 @@ extern const luaR_entry  lua_rotable_base[];
 const LOCK_IN_SECTION(A) char _ro_start[1] = {0};
 const LOCK_IN_SECTION(zzzzzzzz) char _ro_end[1] = {0};
 #endif
-static const LOCK_IN_SECTION(libs) luaL_reg LUA_LIBS[] = {
-  {"",              luaopen_base},
-  {LUA_LOADLIBNAME, luaopen_package},
-  {LUA_STRLIBNAME,  luaopen_string},
-  {LUA_TABLIBNAME,  luaopen_table},
-  {LUA_DBLIBNAME,   luaopen_debug}
-#if defined(LUA_CROSS_COMPILER)
- ,{LUA_IOLIBNAME,   luaopen_io},
-  {NULL,            NULL}
+
+LROT_PUBLIC_TABLE(lua_rotables)
+
+LROT_PUBLIC_BEGIN(LOCK_IN_SECTION(rotable) lua_rotables)
+  LROT_TABENTRY( string, strlib )
+  LROT_TABENTRY( table, tab_funcs )
+  LROT_TABENTRY( debug, dblib)
+  LROT_TABENTRY( coroutine, co_funcs )
+  LROT_TABENTRY( math, math )
+  LROT_TABENTRY( ROM, lua_rotables )
+#ifdef LUA_CROSS_COMPILER
+  LROT_TABENTRY( os, oslib )
+  LROT_TABENTRY( io, iolib )
+LROT_END(lua_rotables, NULL, 0)
+#else
+LROT_BREAK(lua_rotables)
 #endif
-};
 
-#define ENTRY(n,t)  {LSTRKEY(n), LRO_ROVAL(t)}
+LROT_PUBLIC_BEGIN(LOCK_IN_SECTION(libs) lua_libs)
+  LROT_FUNCENTRY( _, luaopen_base )
+  LROT_FUNCENTRY( package, luaopen_package )
+  LROT_FUNCENTRY( string, luaopen_string )
+  LROT_FUNCENTRY( table, luaopen_table )
+  LROT_FUNCENTRY( debug, luaopen_debug )
+#ifndef LUA_CROSS_COMPILER
+LROT_BREAK(lua_rotables)
+#else
+  LROT_FUNCENTRY( io, luaopen_io )
+LROT_END( lua_libs, NULL, 0)
+#endif
 
-const LOCK_IN_SECTION(rotable) ROTable LUA_ROTABLES[] = {
-  ENTRY("ROM",           LUA_ROTABLES),
-  ENTRY(LUA_STRLIBNAME,  strlib),
-  ENTRY(LUA_TABLIBNAME,  tab_funcs),
-  ENTRY(LUA_DBLIBNAME,   dblib),
-  ENTRY(LUA_COLIBNAME,   co_funcs),
-  ENTRY(LUA_MATHLIBNAME, math_map)
-#if defined(LUA_CROSS_COMPILER)
- ,ENTRY(LUA_OSLIBNAME,   syslib),
-  LROT_END
+#ifndef LUA_CROSS_COMPILER
+extern void luaL_dbgbreak(void);
 #endif
-  };
 
 void luaL_openlibs (lua_State *L) {
-  const luaL_Reg *lib = lua_libs_base;
 
+  lua_pushrotable(L, LROT_TABLEREF(lua_libs));
+  lua_pushnil(L);  /* first key */
   /* loop round and open libraries */
-  for (; lib->name; lib++) {
-    if (lib->func) {
-      lua_pushcfunction(L, lib->func);
-      lua_pushstring(L, lib->name);
-      lua_call(L, 1, 0);
+#ifndef LUA_CROSS_COMPILER
+// luaL_dbgbreak();  // This is a test point for debugging library start ups
+#endif
+  while (lua_next(L, -2) != 0) {
+    if (lua_islightfunction(L,-1) &&
+        fvalue(L->top-1)) { // only process function entries
+      lua_pushvalue(L, -2);
+      lua_call(L, 1, 0);  // call luaopen_XXX(libname)
+    } else {
+      lua_pop(L, 1);
     }
   }
+  lua_pop(L, 1);  //cleanup stack
 }
-

+ 44 - 78
app/lua/lmathlib.c

@@ -15,6 +15,7 @@
 
 #include "lauxlib.h"
 #include "lualib.h"
+#include "lrotable.h"
 
 #undef PI
 #define PI (3.14159265358979323846)
@@ -308,92 +309,57 @@ static int math_randomseed (lua_State *L) {
   return 0;
 }
 
-
-
-#undef MIN_OPT_LEVEL
-#define MIN_OPT_LEVEL 1
-#include "lrodefs.h"
-const LUA_REG_TYPE math_map[] = {
+LROT_PUBLIC_BEGIN(math)
 #ifdef LUA_NUMBER_INTEGRAL
-  {LSTRKEY("abs"),   LFUNCVAL(math_abs)},
-  {LSTRKEY("ceil"),  LFUNCVAL(math_identity)},
-  {LSTRKEY("floor"), LFUNCVAL(math_identity)},
-  {LSTRKEY("max"),   LFUNCVAL(math_max)},
-  {LSTRKEY("min"),   LFUNCVAL(math_min)},
-  {LSTRKEY("pow"),   LFUNCVAL(math_pow)},
-  {LSTRKEY("random"),     LFUNCVAL(math_random)},
-  {LSTRKEY("randomseed"), LFUNCVAL(math_randomseed)},
-  {LSTRKEY("sqrt"),  LFUNCVAL(math_sqrt)},
-#if LUA_OPTIMIZE_MEMORY > 0
-  {LSTRKEY("huge"),  LNUMVAL(INT_MAX)},
-#endif
+  LROT_FUNCENTRY( abs, math_abs )
+  LROT_FUNCENTRY( ceil, math_identity )
+  LROT_FUNCENTRY( floor, math_identity )
+  LROT_FUNCENTRY( max, math_max )
+  LROT_FUNCENTRY( min, math_min )
+  LROT_FUNCENTRY( pow, math_pow )
+  LROT_FUNCENTRY( random, math_random )
+  LROT_FUNCENTRY( randomseed, math_randomseed )
+  LROT_FUNCENTRY( sqrt, math_sqrt )
+  LROT_NUMENTRY( huge, INT_MAX )
 #else
-  {LSTRKEY("abs"),   LFUNCVAL(math_abs)},
-  // {LSTRKEY("acos"),  LFUNCVAL(math_acos)},
-  // {LSTRKEY("asin"),  LFUNCVAL(math_asin)},
-  // {LSTRKEY("atan2"), LFUNCVAL(math_atan2)},
-  // {LSTRKEY("atan"),  LFUNCVAL(math_atan)},
-  {LSTRKEY("ceil"),  LFUNCVAL(math_ceil)},
-  // {LSTRKEY("cosh"),  LFUNCVAL(math_cosh)},
-  // {LSTRKEY("cos"),   LFUNCVAL(math_cos)},
-  // {LSTRKEY("deg"),   LFUNCVAL(math_deg)},
-  // {LSTRKEY("exp"),   LFUNCVAL(math_exp)},
-  {LSTRKEY("floor"), LFUNCVAL(math_floor)},
-  // {LSTRKEY("fmod"),  LFUNCVAL(math_fmod)},
-#if LUA_OPTIMIZE_MEMORY > 0 && defined(LUA_COMPAT_MOD)
-  // {LSTRKEY("mod"),   LFUNCVAL(math_fmod)},
-#endif
-  // {LSTRKEY("frexp"), LFUNCVAL(math_frexp)},
-  // {LSTRKEY("ldexp"), LFUNCVAL(math_ldexp)},
-  // {LSTRKEY("log10"), LFUNCVAL(math_log10)},
-  // {LSTRKEY("log"),   LFUNCVAL(math_log)},
-  {LSTRKEY("max"),   LFUNCVAL(math_max)},
-  {LSTRKEY("min"),   LFUNCVAL(math_min)},
-  // {LSTRKEY("modf"),   LFUNCVAL(math_modf)},
-  {LSTRKEY("pow"),   LFUNCVAL(math_pow)},
-  // {LSTRKEY("rad"),   LFUNCVAL(math_rad)},
-  {LSTRKEY("random"),     LFUNCVAL(math_random)},
-  {LSTRKEY("randomseed"), LFUNCVAL(math_randomseed)},
-  // {LSTRKEY("sinh"),   LFUNCVAL(math_sinh)},
-  // {LSTRKEY("sin"),   LFUNCVAL(math_sin)},
-  {LSTRKEY("sqrt"),  LFUNCVAL(math_sqrt)},
-  // {LSTRKEY("tanh"),   LFUNCVAL(math_tanh)},
-  // {LSTRKEY("tan"),   LFUNCVAL(math_tan)},
-#if LUA_OPTIMIZE_MEMORY > 0
-  {LSTRKEY("pi"),    LNUMVAL(PI)},
-  {LSTRKEY("huge"),  LNUMVAL(HUGE_VAL)},
-#endif // #if LUA_OPTIMIZE_MEMORY > 0
+  LROT_FUNCENTRY( abs, math_abs )
+// LROT_FUNCENTRY( acos, math_acos )
+// LROT_FUNCENTRY( asin, math_asin )
+// LROT_FUNCENTRY( atan2, math_atan2 )
+// LROT_FUNCENTRY( atan, math_atan )
+  LROT_FUNCENTRY( ceil, math_ceil )
+// LROT_FUNCENTRY( cosh, math_cosh )
+// LROT_FUNCENTRY( cos, math_cos )
+// LROT_FUNCENTRY( deg, math_deg )
+// LROT_FUNCENTRY( exp, math_exp )
+  LROT_FUNCENTRY( floor, math_floor )
+// LROT_FUNCENTRY( fmod, math_fmod )
+// LROT_FUNCENTRY( mod, math_fmod )
+// LROT_FUNCENTRY( frexp, math_frexp )
+// LROT_FUNCENTRY( ldexp, math_ldexp )
+// LROT_FUNCENTRY( log10, math_log10 )
+// LROT_FUNCENTRY( log, math_log )
+  LROT_FUNCENTRY( max, math_max )
+  LROT_FUNCENTRY( min, math_min )
+// LROT_FUNCENTRY( modf, math_modf )
+  LROT_FUNCENTRY( pow, math_pow )
+// LROT_FUNCENTRY( rad, math_rad )
+  LROT_FUNCENTRY( random, math_random )
+  LROT_FUNCENTRY( randomseed, math_randomseed )
+// LROT_FUNCENTRY( sinh, math_sinh )
+// LROT_FUNCENTRY( sin, math_sin )
+  LROT_FUNCENTRY( sqrt, math_sqrt )
+// LROT_FUNCENTRY( tanh, math_tanh )
+// LROT_FUNCENTRY( tan, math_tan )
+  LROT_NUMENTRY( pi, PI )
+  LROT_NUMENTRY( huge, HUGE_VAL )
 #endif // #ifdef LUA_NUMBER_INTEGRAL
-  {LNILKEY, LNILVAL}
-};
+LROT_END(math, NULL, 0)
 
 
 /*
 ** Open math library
 */
-
-#if defined LUA_NUMBER_INTEGRAL
-# include "c_limits.h"		/* for INT_MAX */
-#endif
-
 LUALIB_API int luaopen_math (lua_State *L) {
-#if LUA_OPTIMIZE_MEMORY > 0
   return 0;
-#else
-  luaL_register(L, LUA_MATHLIBNAME, math_map);
-# if defined LUA_NUMBER_INTEGRAL
-  lua_pushnumber(L, INT_MAX);
-  lua_setfield(L, -2, "huge");
-# else
-  lua_pushnumber(L, PI);
-  lua_setfield(L, -2, "pi");
-  lua_pushnumber(L, HUGE_VAL);
-  lua_setfield(L, -2, "huge");
-#  if defined(LUA_COMPAT_MOD)
-  lua_getfield(L, -1, "fmod");
-  lua_setfield(L, -2, "mod");
-#  endif
-# endif
-  return 1;
-#endif
 }

+ 14 - 21
app/lua/loadlib.c

@@ -24,6 +24,7 @@
 
 #include "lauxlib.h"
 #include "lualib.h"
+#include "lrotable.h"
 
 /* prefix for open functions in C libraries */
 #define LUA_POF		"luaopen_"
@@ -361,7 +362,9 @@ static const char * findfile (lua_State *L, const char *name,
                                            const char *pname) {
   const char *path;
   name = luaL_gsub(L, name, ".", LUA_DIRSEP);
-  lua_getfield(L, LUA_ENVIRONINDEX, pname);
+  lua_getfield(L, LUA_GLOBALSINDEX, "package");
+  lua_getfield(L, -1, pname);
+  lua_remove(L, -2);
   path = lua_tostring(L, -1);
   if (path == NULL)
     luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
@@ -447,7 +450,9 @@ static int loader_Croot (lua_State *L) {
 
 static int loader_preload (lua_State *L) {
   const char *name = luaL_checkstring(L, 1);
-  lua_getfield(L, LUA_ENVIRONINDEX, "preload");
+  lua_getfield(L, LUA_GLOBALSINDEX, "package");
+  lua_getfield(L, -1, "preload");
+  lua_remove(L, -2);
   if (!lua_istable(L, -1))
     luaL_error(L, LUA_QL("package.preload") " must be a table");
   lua_getfield(L, -1, name);
@@ -480,7 +485,9 @@ static int ll_require (lua_State *L) {
     lua_pop(L, 1);
   }
   /* else must load it; iterate over available loaders */
-  lua_getfield(L, LUA_ENVIRONINDEX, "loaders");
+  lua_getfield(L, LUA_GLOBALSINDEX, "package");
+  lua_getfield(L, -1, "loaders");
+  lua_remove(L, -2);
   if (!lua_istable(L, -1))
     luaL_error(L, LUA_QL("package.loaders") " must be a table");
   lua_pushliteral(L, "");  /* error message accumulator */
@@ -650,34 +657,20 @@ static const luaL_Reg ll_funcs[] = {
 static const lua_CFunction loaders[] =
   {loader_preload, loader_Lua, loader_C, loader_Croot, NULL};
 
-#if LUA_OPTIMIZE_MEMORY > 0
-#undef MIN_OPT_LEVEL
-#define MIN_OPT_LEVEL 1
-#include "lrodefs.h"
-const LUA_REG_TYPE lmt[] = {
-  {LRO_STRKEY("__gc"), LRO_FUNCVAL(gctm)},
-  {LRO_NILKEY, LRO_NILVAL}
-};
-#endif
+LROT_PUBLIC_BEGIN(lmt)
+  LROT_FUNCENTRY(__gc,gctm)
+LROT_END(lmt,lmt, LROT_MASK_GC)
 
 LUALIB_API int luaopen_package (lua_State *L) {
   int i;
   /* create new type _LOADLIB */
-#if LUA_OPTIMIZE_MEMORY == 0
-  luaL_newmetatable(L, "_LOADLIB");
-  lua_pushlightfunction(L, gctm);
-  lua_setfield(L, -2, "__gc");
-#else
-  luaL_rometatable(L, "_LOADLIB", (void*)lmt);
-#endif
+  luaL_rometatable(L, "_LOADLIB",LROT_TABLEREF(lmt));
   /* create `package' table */
   luaL_register_light(L, LUA_LOADLIBNAME, pk_funcs);
 #if defined(LUA_COMPAT_LOADLIB)
   lua_getfield(L, -1, "loadlib");
   lua_setfield(L, LUA_GLOBALSINDEX, "loadlib");
 #endif
-  lua_pushvalue(L, -1);
-  lua_replace(L, LUA_ENVIRONINDEX);
   /* create `loaders' table */
   lua_createtable(L, sizeof(loaders)/sizeof(loaders[0]) - 1, 0);
   /* fill it with pre-defined loaders */

+ 12 - 6
app/lua/lrodefs.h

@@ -25,8 +25,7 @@
 #define LNUMVAL                     LRO_NUMVAL
 #define LROVAL                      LRO_ROVAL
 #define LNILVAL                     LRO_NILVAL
-#define LREGISTER(L, name, table)\
-  return 0
+#define LREGISTER(L, name, table) return 0
 #else
 #define LUA_REG_TYPE                luaL_reg
 #define LSTRKEY(x)                  x
@@ -38,10 +37,17 @@
   return 1
 #endif
 
-#define LROT_TABENTRY(n,t)  {LSTRKEY(#n), LRO_ROVAL(t)}
-#define LROT_FUNCENTRY(n,f) {LSTRKEY(#n), LRO_FUNCVAL(f)}
-#define LROT_NUMENTRY(n,x)  {LSTRKEY(#n), LRO_NUMVAL(x)}
-#define LROT_END            {LNILKEY, LNILVAL}
+#define LROT_TABLE(t)        static const LUA_REG_TYPE t ## _map[];
+#define LROT_TABLEREF(t)     ((void *) t ## _map)
+#define LROT_BEGIN(t)        static const LUA_REG_TYPE t ## _map [] = {
+#define LROT_PUBLIC_BEGIN(t) const LUA_REG_TYPE t ## _map[] = {
+#define LROT_EXTERN(t)       extern const LUA_REG_TYPE t ## _map[]
+#define LROT_TABENTRY(n,t)   {LRO_STRKEY(#n), LRO_ROVAL(t ## _map)},
+#define LROT_FUNCENTRY(n,f)  {LRO_STRKEY(#n), LRO_FUNCVAL(f)},
+#define LROT_NUMENTRY(n,x)   {LRO_STRKEY(#n), LRO_NUMVAL(x)},
+#define LROT_LUDENTRY(n,x)   {LRO_STRKEY(#n), LRO_LUDATA((void *) x)},
+#define LROT_END(t,mt, f)    {LRO_NILKEY, LRO_NILVAL} };
+#define LREGISTER(L, name, table) return 0
 
 #endif /* lrodefs_h */
 

+ 24 - 47
app/lua/lrotable.c

@@ -14,7 +14,7 @@
 #else
 #define ALIGNED_STRING (__attribute__((aligned(4))) char *)
 #endif
-#define LA_LINES 16
+#define LA_LINES 32
 #define LA_SLOTS 4
 //#define COLLECT_STATS
 
@@ -36,7 +36,7 @@
  * Note that this hash does a couple of prime multiples and a modulus 2^X
  * with is all evaluated in H/W, and adequately randomizes the lookup.
  */
-#define HASH(a,b) (519*((size_t)(a)>>4) + 17*((size_t)(b)>>4))
+#define HASH(a,b) ((((519*(size_t)(a)))>>4) + ((b) ? (b)->tsv.hash: 0))
 
 static struct {
   unsigned hash;
@@ -83,19 +83,18 @@ static void update_cache(unsigned hash, ROTable *rotable, unsigned ndx) {
 const TValue* luaR_findentry(ROTable *rotable, TString *key, unsigned *ppos) {
   const luaR_entry *pentry = rotable;
   const char *strkey = key ? getstr(key) : ALIGNED_STRING "__metatable" ;
-  size_t      hash   = HASH(rotable, key);
+  unsigned   hash    = HASH(rotable, key);
+
   unsigned    i      = 0;
   int         j      = lookup_cache(hash, rotable);
   unsigned    l      = key ? key->tsv.len : sizeof("__metatable")-1;
 
   if (pentry) {
-    if (j >= 0){
-      if ((pentry[j].key.type == LUA_TSTRING) &&
-        !c_strcmp(pentry[j].key.id.strkey, strkey)) {
-        if (ppos)
-          *ppos = j;
-        return &pentry[j].value;
-      }
+    if (j >= 0 && !c_strcmp(pentry[j].key, strkey)) {
+      if (ppos)
+        *ppos = j;
+//dbg_printf("%3d hit  %p %s\n", (hash>>2) & (LA_LINES-1), rotable, strkey);
+      return &pentry[j].value;
     }
     /*
      * The invariants for 1st word comparison are deferred to here since they
@@ -105,40 +104,22 @@ const TValue* luaR_findentry(ROTable *rotable, TString *key, unsigned *ppos) {
     unsigned name4, mask4 = l > 2 ? (~0u) : (~0u)>>((3-l)*8);
     c_memcpy(&name4, strkey, sizeof(name4));
 
-    for(;pentry->key.type != LUA_TNIL; i++, pentry++) {
-      if ((pentry->key.type == LUA_TSTRING) &&
-          ((*(unsigned *)pentry->key.id.strkey ^ name4) & mask4) == 0 &&
-          !c_strcmp(pentry->key.id.strkey, strkey)) {
+    for(;pentry->key != NULL; i++, pentry++) {
+      if (((*(unsigned *)pentry->key ^ name4) & mask4) == 0 &&
+          !c_strcmp(pentry->key, strkey)) {
+//dbg_printf("%p %s hit after %d probes \n", rotable, strkey, (int)(rotable-pentry));
         if (ppos)
           *ppos = i;
-        if (j==-1) {
-          update_cache(hash, rotable, pentry - rotable);
-        } else if (j != (pentry - rotable)) {
-          j = 0;
-        }
-        return &pentry->value;
+        update_cache(hash, rotable, pentry - rotable);
+//dbg_printf("%3d %3d  %p %s\n", (hash>>2) & (LA_LINES-1), (int)(pentry-rotable), rotable, strkey);
+       return &pentry->value;
       }
     }
   }
+//dbg_printf("%p %s miss after %d probes \n", rotable, strkey, (int)(rotable-pentry));
   return luaO_nilobject;
 }
 
-const TValue* luaR_findentryN(ROTable *rotable, luaR_numkey numkey, unsigned *ppos) {
-  unsigned i = 0;
-  const luaR_entry *pentry = rotable;
-  if (pentry) {
-    for ( ;pentry->key.type != LUA_TNIL; i++, pentry++) {
-      if (pentry->key.type == LUA_TNUMBER && (luaR_numkey) pentry->key.id.numkey == numkey) {
-        if (ppos)
-          *ppos = i;
-        return &pentry->value;
-      }
-    }
-  }
-  return NULL;
-}
-
-
 /* Find the metatable of a given table */
 void* luaR_getmeta(ROTable *rotable) {
   const TValue *res = luaR_findentry(rotable, NULL, NULL);
@@ -147,15 +128,13 @@ void* luaR_getmeta(ROTable *rotable) {
 
 static void luaR_next_helper(lua_State *L, ROTable *pentries, int pos,
                              TValue *key, TValue *val) {
-  setnilvalue(key);
-  setnilvalue(val);
-  if (pentries[pos].key.type != LUA_TNIL) {
+  if (pentries[pos].key) {
     /* Found an entry */
-    if (pentries[pos].key.type == LUA_TSTRING)
-      setsvalue(L, key, luaS_new(L, pentries[pos].key.id.strkey))
-    else
-      setnvalue(key, (lua_Number)pentries[pos].key.id.numkey)
-   setobj2s(L, val, &pentries[pos].value);
+    setsvalue(L, key, luaS_new(L, pentries[pos].key));
+    setobj2s(L, val, &pentries[pos].value);
+  } else {
+    setnilvalue(key);
+    setnilvalue(val);
   }
 }
 
@@ -167,12 +146,10 @@ void luaR_next(lua_State *L, ROTable *rotable, TValue *key, TValue *val) {
   /* Special case: if key is nil, return the first element of the rotable */
   if (ttisnil(key))
     luaR_next_helper(L, rotable, 0, key, val);
-  else if (ttisstring(key) || ttisnumber(key)) {
+  else if (ttisstring(key)) {
     /* Find the previous key again */
     if (ttisstring(key)) {
       luaR_findentry(rotable, rawtsvalue(key), &keypos);
-    } else {
-      luaR_findentryN(rotable, (luaR_numkey)nvalue(key), &keypos);
     }
     /* Advance to next key */
     keypos ++;

+ 21 - 14
app/lua/lrotable.h

@@ -7,6 +7,7 @@
 #include "luaconf.h"
 #include "lobject.h"
 #include "llimits.h"
+#include "lrotable.h"
 
 /* Macros one can use to define rotable entries */
 #define LRO_FUNCVAL(v)  {{.p = v}, LUA_TLIGHTFUNCTION}
@@ -14,13 +15,28 @@
 #define LRO_NUMVAL(v)   {{.n = v}, LUA_TNUMBER}
 #define LRO_ROVAL(v)    {{.p = (void*)v}, LUA_TROTABLE}
 #define LRO_NILVAL      {{.p = NULL}, LUA_TNIL}
+
 #ifdef LUA_CROSS_COMPILER
-#define LRO_STRKEY(k)   {LUA_TSTRING, {.strkey = k}}
+#define LRO_STRKEY(k)   k
 #else
-#define LRO_STRKEY(k)   {LUA_TSTRING, {.strkey = (STORE_ATTR char *) k}}
+#define LRO_STRKEY(k)   ((STORE_ATTR char *) k)
 #endif
-#define LRO_NUMKEY(k)   {LUA_TNUMBER, {.numkey = k}}
-#define LRO_NILKEY      {LUA_TNIL, {.strkey=NULL}}
+
+#define LROT_TABLE(t)        static const LUA_REG_TYPE t ## _map[];
+#define LROT_PUBLIC_TABLE(t) const LUA_REG_TYPE t ## _map[];
+#define LROT_TABLEREF(t)     ((void *) t ## _map)
+#define LROT_BEGIN(t)        static const LUA_REG_TYPE t ## _map [] = {
+#define LROT_PUBLIC_BEGIN(t) const LUA_REG_TYPE t ## _map[] = {
+#define LROT_EXTERN(t)       extern const LUA_REG_TYPE t ## _map[]
+#define LROT_TABENTRY(n,t)   {LRO_STRKEY(#n), LRO_ROVAL(t ## _map)},
+#define LROT_FUNCENTRY(n,f)  {LRO_STRKEY(#n), LRO_FUNCVAL(f)},
+#define LROT_NUMENTRY(n,x)   {LRO_STRKEY(#n), LRO_NUMVAL(x)},
+#define LROT_LUDENTRY(n,x)   {LRO_STRKEY(#n), LRO_LUDATA((void *) x)},
+#define LROT_END(t,mt, f)    {NULL, LRO_NILVAL} };
+#define LROT_BREAK(t)         };
+
+#define LUA_REG_TYPE              luaR_entry
+#define LREGISTER(L, name, table) return 0
 
 /* Maximum length of a rotable name and of a string key*/
 #define LUA_MAX_ROTABLE_NAME      32
@@ -28,18 +44,9 @@
 /* Type of a numeric key in a rotable */
 typedef int luaR_numkey;
 
-/* The next structure defines the type of a key */
-typedef struct {
-  int type;
-  union {
-    const char*   strkey;
-    luaR_numkey   numkey;
-  } id;
-} luaR_key;
-
 /* An entry in the read only table */
 typedef struct luaR_entry {
-  const luaR_key key;
+  const char *key;
   const TValue value;
 } luaR_entry;
 

+ 23 - 53
app/lua/lstrlib.c

@@ -15,12 +15,12 @@
 
 #include "lauxlib.h"
 #include "lualib.h"
+#include "lrotable.h"
 
 /* macro to `unsign' a character */
 #define uchar(c)        ((unsigned char)(c))
 
 
-
 static int str_len (lua_State *L) {
   size_t l;
   luaL_checklstring(L, 1, &l);
@@ -576,7 +576,7 @@ static int gmatch (lua_State *L) {
   return 1;
 }
 
-#if LUA_OPTIMIZE_MEMORY == 0 || !defined(LUA_COMPAT_GFIND)
+#ifndef LUA_COMPAT_GFIND
 static int gfind_nodef (lua_State *L) {
   return luaL_error(L, LUA_QL("string.gfind") " was renamed to "
                        LUA_QL("string.gmatch"));
@@ -824,67 +824,37 @@ static int str_format (lua_State *L) {
   return 1;
 }
 
-#undef MIN_OPT_LEVEL
-#define MIN_OPT_LEVEL 1
-#include "lrodefs.h"
-const LUA_REG_TYPE strlib[] = {
-  {LSTRKEY("byte"), LFUNCVAL(str_byte)},
-  {LSTRKEY("char"), LFUNCVAL(str_char)},
-  {LSTRKEY("dump"), LFUNCVAL(str_dump)},
-  {LSTRKEY("find"), LFUNCVAL(str_find)},
-  {LSTRKEY("format"), LFUNCVAL(str_format)},
-#if LUA_OPTIMIZE_MEMORY > 0 && defined(LUA_COMPAT_GFIND)
-  {LSTRKEY("gfind"), LFUNCVAL(gmatch)},
+LROT_PUBLIC_BEGIN(strlib)
+  LROT_FUNCENTRY( byte, str_byte )
+  LROT_FUNCENTRY( char, str_char )
+  LROT_FUNCENTRY( dump, str_dump )
+  LROT_FUNCENTRY( find, str_find )
+  LROT_FUNCENTRY( format, str_format )
+#ifdef LUA_COMPAT_GFIND
+  LROT_FUNCENTRY( gfind, gmatch )
 #else
-  {LSTRKEY("gfind"), LFUNCVAL(gfind_nodef)},
-#endif
-  {LSTRKEY("gmatch"), LFUNCVAL(gmatch)},
-  {LSTRKEY("gsub"), LFUNCVAL(str_gsub)},
-  {LSTRKEY("len"), LFUNCVAL(str_len)},
-  {LSTRKEY("lower"), LFUNCVAL(str_lower)},
-  {LSTRKEY("match"), LFUNCVAL(str_match)},
-  {LSTRKEY("rep"), LFUNCVAL(str_rep)},
-  {LSTRKEY("reverse"), LFUNCVAL(str_reverse)},
-  {LSTRKEY("sub"), LFUNCVAL(str_sub)},
-  {LSTRKEY("upper"), LFUNCVAL(str_upper)},
-#if LUA_OPTIMIZE_MEMORY > 0
-  {LSTRKEY("__index"), LROVAL(strlib)},
-#endif
-  {LNILKEY, LNILVAL}
-};
-
-
-#if LUA_OPTIMIZE_MEMORY != 2
-static void createmetatable (lua_State *L) {
-  lua_createtable(L, 0, 1);  /* create metatable for strings */
-  lua_pushliteral(L, "");  /* dummy string */
-  lua_pushvalue(L, -2);
-  lua_setmetatable(L, -2);  /* set string metatable */
-  lua_pop(L, 1);  /* pop dummy string */
-  lua_pushvalue(L, -2);  /* string library... */
-  lua_setfield(L, -2, "__index");  /* ...is the __index metamethod */
-  lua_pop(L, 1);  /* pop metatable */
-}
+  LROT_FUNCENTRY( gfind, gfind_nodef )
 #endif
+  LROT_FUNCENTRY( gmatch, gmatch )
+  LROT_FUNCENTRY( gsub, str_gsub )
+  LROT_FUNCENTRY( len, str_len )
+  LROT_FUNCENTRY( lower, str_lower )
+  LROT_FUNCENTRY( match, str_match )
+  LROT_FUNCENTRY( rep, str_rep )
+  LROT_FUNCENTRY( reverse, str_reverse )
+  LROT_FUNCENTRY( sub, str_sub )
+  LROT_FUNCENTRY( upper, str_upper )
+  LROT_TABENTRY( __index, strlib )
+LROT_END(strlib, NULL, 0)  // OR DO WE NEED LRTO_MASK_INDEX    **TODO** 
 
 /*
 ** Open string library
 */
 LUALIB_API int luaopen_string (lua_State *L) {
-#if LUA_OPTIMIZE_MEMORY == 0
-  luaL_register(L, LUA_STRLIBNAME, strlib);
-#if defined(LUA_COMPAT_GFIND)
-  lua_getfield(L, -1, "gmatch");
-  lua_setfield(L, -2, "gfind");
-#endif
-  createmetatable(L);
-  return 1;
-#else
   lua_pushliteral(L,"");
-  lua_pushrotable(L, (void*)strlib);
+  lua_pushrotable(L, LROT_TABLEREF(strlib));
   lua_setmetatable(L, -2);
   lua_pop(L,1);
   return 0;
-#endif
 }
 

+ 2 - 6
app/lua/ltable.c

@@ -580,7 +580,7 @@ const TValue *luaH_getnum (Table *t, int key) {
 
 /* same thing for rotables */
 const TValue *luaH_getnum_ro (void *t, int key) {
-  const TValue *res = luaR_findentryN(t, key, NULL);
+  const TValue *res = NULL;  // integer values not supported: luaR_findentryN(t, key, NULL);
   return res ? res : luaO_nilobject;
 }
 
@@ -739,11 +739,7 @@ int luaH_getn (Table *t) {
 
 /* same thing for rotables */
 int luaH_getn_ro (void *t) {
-  int i = 1, len=0;
-
-  while(luaR_findentryN(t, i ++, NULL))
-    len ++;
-  return len;
+  return 0;  // Integer Keys are not currently supported for ROTables
 }
 
 int luaH_isdummy (Node *n) { return n == dummynode; }

+ 13 - 16
app/lua/ltablib.c

@@ -13,6 +13,7 @@
 
 #include "lauxlib.h"
 #include "lualib.h"
+#include "lrotable.h"
 
 
 #define aux_getn(L,n)	(luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n))
@@ -265,22 +266,18 @@ static int sort (lua_State *L) {
 /* }====================================================== */
 
 
-#undef MIN_OPT_LEVEL
-#define MIN_OPT_LEVEL 1
-#include "lrodefs.h"
-const LUA_REG_TYPE tab_funcs[] = {
-  {LSTRKEY("concat"), LFUNCVAL(tconcat)},
-  {LSTRKEY("foreach"), LFUNCVAL(foreach)},
-  {LSTRKEY("foreachi"), LFUNCVAL(foreachi)},
-  {LSTRKEY("getn"), LFUNCVAL(getn)},
-  {LSTRKEY("maxn"), LFUNCVAL(maxn)},
-  {LSTRKEY("insert"), LFUNCVAL(tinsert)},
-  {LSTRKEY("remove"), LFUNCVAL(tremove)},
-  {LSTRKEY("setn"), LFUNCVAL(setn)},
-  {LSTRKEY("sort"), LFUNCVAL(sort)},
-  {LNILKEY, LNILVAL}
-};
+LROT_PUBLIC_BEGIN(tab_funcs)
+  LROT_FUNCENTRY( concat, tconcat )
+  LROT_FUNCENTRY( foreach, foreach )
+  LROT_FUNCENTRY( foreachi, foreachi )
+  LROT_FUNCENTRY( getn, getn )
+  LROT_FUNCENTRY( maxn, maxn )
+  LROT_FUNCENTRY( insert, tinsert )
+  LROT_FUNCENTRY( remove, tremove )
+  LROT_FUNCENTRY( setn, setn )
+  LROT_FUNCENTRY( sort, sort )
+LROT_END(tab_funcs, NULL, 0)
 
 LUALIB_API int luaopen_table (lua_State *L) {
-  LREGISTER(L, LUA_TABLIBNAME, tab_funcs);
+  return 1;
 }

+ 1 - 1
app/lua/luac_cross/Makefile

@@ -13,7 +13,7 @@ LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld -lm -ldl -Wl,-Map=mapfile
 
 CCFLAGS += -Wall
 
-DEFINES += -DLUA_CROSS_COMPILER -DLUA_OPTIMIZE_MEMORY=2
+DEFINES += -DLUA_CROSS_COMPILER
 
 TARGET = host
 

+ 28 - 33
app/lua/luac_cross/liolib.c

@@ -12,12 +12,12 @@
 
 #define liolib_c
 #define LUA_LIB
-#define LUA_OPTIMIZE_MEMORY  2
 
 #include "lua.h"
 
 #include "lauxlib.h"
 #include "lualib.h"
+#include "lrotable.h"
 
 #define IO_INPUT	1
 #define IO_OUTPUT	2
@@ -439,36 +439,31 @@ static int f_flush (lua_State *L) {
   return pushresult(L, fflush(tofile(L)) == 0, NULL);
 }
 
-#define MIN_OPT_LEVEL 2
-#include "lrodefs.h"
-const LUA_REG_TYPE iolib_funcs[] = {
-  {LSTRKEY("close"),   LFUNCVAL(io_close)},
-  {LSTRKEY("flush"),   LFUNCVAL(io_flush)},
-  {LSTRKEY("input"),   LFUNCVAL(io_input)},
-  {LSTRKEY("lines"),   LFUNCVAL(io_lines)},
-  {LSTRKEY("open"),    LFUNCVAL(io_open)},
-  {LSTRKEY("output"),  LFUNCVAL(io_output)},
-  {LSTRKEY("read"),    LFUNCVAL(io_read)},
-  {LSTRKEY("type"),    LFUNCVAL(io_type)},
-  {LSTRKEY("write"),   LFUNCVAL(io_write)},
-  {LSTRKEY("__index"), LROVAL(iolib_funcs)},
-  {LNILKEY, LNILVAL}
-};
-
-#include "lrodefs.h"
-const LUA_REG_TYPE flib[] = {
-  {LSTRKEY("close"),      LFUNCVAL(io_close)},
-  {LSTRKEY("flush"),      LFUNCVAL(f_flush)},
-  {LSTRKEY("lines"),      LFUNCVAL(f_lines)},
-  {LSTRKEY("read"),       LFUNCVAL(f_read)},
-  {LSTRKEY("seek"),       LFUNCVAL(f_seek)},
-  {LSTRKEY("setvbuf"),    LFUNCVAL(f_setvbuf)},
-  {LSTRKEY("write"),      LFUNCVAL(f_write)},
-  {LSTRKEY("__gc"),       LFUNCVAL(io_gc)},
-  {LSTRKEY("__tostring"), LFUNCVAL(io_tostring)},
-  {LSTRKEY("__index"),    LROVAL(flib)},
-  {LNILKEY, LNILVAL}
-};
+LROT_PUBLIC_BEGIN(iolib)
+  LROT_FUNCENTRY( close, io_close )
+  LROT_FUNCENTRY( flush, io_flush )
+  LROT_FUNCENTRY( input, io_input )
+  LROT_FUNCENTRY( lines, io_lines )
+  LROT_FUNCENTRY( open, io_open )
+  LROT_FUNCENTRY( output, io_output )
+  LROT_FUNCENTRY( read, io_read )
+  LROT_FUNCENTRY( type, io_type )
+  LROT_FUNCENTRY( write, io_write )
+  LROT_TABENTRY( __index, iolib )
+LROT_END(iolib, NULL, 0)
+
+LROT_BEGIN(flib)
+  LROT_FUNCENTRY( close, io_close )
+  LROT_FUNCENTRY( flush, f_flush )
+  LROT_FUNCENTRY( lines, f_lines )
+  LROT_FUNCENTRY( read, f_read )
+  LROT_FUNCENTRY( seek, f_seek )
+  LROT_FUNCENTRY( setvbuf, f_setvbuf )
+  LROT_FUNCENTRY( write, f_write )
+  LROT_FUNCENTRY( __gc, io_gc )
+  LROT_FUNCENTRY( __tostring, io_tostring )
+  LROT_TABENTRY( __index, flib )
+LROT_END(flib, NULL, LROT_MASK_GC_INDEX)
 
 static const luaL_Reg io_base[] = {{NULL, NULL}};
 
@@ -481,12 +476,12 @@ static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {
 }
 
 LUALIB_API int luaopen_io(lua_State *L) {
-  luaL_rometatable(L, LUA_FILEHANDLE, (void*) flib);  /* create metatable for file handles */
+  luaL_rometatable(L, LUA_FILEHANDLE, LROT_TABLEREF(flib));  /* create metatable for file handles */
   luaL_register_light(L, LUA_IOLIBNAME, io_base);
   lua_pushvalue(L, -1);
   lua_setmetatable(L, -2);
   lua_pushliteral(L, "__index");
-  lua_pushrotable(L, (void *)iolib_funcs);
+  lua_pushrotable(L, LROT_TABLEREF(iolib));
   lua_rawset(L, -3);
 
   /* create (and set) default files */

+ 15 - 19
app/lua/luac_cross/loslib.c

@@ -20,6 +20,7 @@
 
 #include "lauxlib.h"
 #include "lualib.h"
+#include "lrotable.h"
 
 static int os_pushresult (lua_State *L, int i, const char *filename) {
   int en = errno;  /* calls to Lua API may change this value */
@@ -219,30 +220,25 @@ static int os_exit (lua_State *L) {
   c_exit(luaL_optint(L, 1, EXIT_SUCCESS));
 }
 
-#undef MIN_OPT_LEVEL
-#define MIN_OPT_LEVEL 1
-#include "lrodefs.h"
-const LUA_REG_TYPE syslib[] = {
-  {LSTRKEY("clock"),     LFUNCVAL(os_clock)},
-  {LSTRKEY("date"),      LFUNCVAL(os_date)},
+LROT_PUBLIC_BEGIN(oslib)
+  LROT_FUNCENTRY( clock, os_clock )
+  LROT_FUNCENTRY( date, os_date )
 #if !defined LUA_NUMBER_INTEGRAL
-  {LSTRKEY("difftime"),  LFUNCVAL(os_difftime)},
+  LROT_FUNCENTRY( difftime, os_difftime )
 #endif
-  {LSTRKEY("execute"),   LFUNCVAL(os_execute)},
-  {LSTRKEY("exit"),      LFUNCVAL(os_exit)},
-  {LSTRKEY("getenv"),    LFUNCVAL(os_getenv)},
-  {LSTRKEY("remove"),    LFUNCVAL(os_remove)},
-  {LSTRKEY("rename"),    LFUNCVAL(os_rename)},
-  {LSTRKEY("setlocale"), LFUNCVAL(os_setlocale)},
-  {LSTRKEY("time"),      LFUNCVAL(os_time)},
-  {LSTRKEY("tmpname"),   LFUNCVAL(os_tmpname)},
-  {LNILKEY, LNILVAL}
-};
-
+  LROT_FUNCENTRY( execute, os_execute )
+  LROT_FUNCENTRY( exit, os_exit )
+  LROT_FUNCENTRY( getenv, os_getenv )
+  LROT_FUNCENTRY( remove, os_remove )
+  LROT_FUNCENTRY( rename, os_rename )
+  LROT_FUNCENTRY( setlocale, os_setlocale )
+  LROT_FUNCENTRY( time, os_time )
+  LROT_FUNCENTRY( tmpname, os_tmpname )
+LROT_END(oslib, NULL, 0)
 /* }====================================================== */
 
 
 
 LUALIB_API int luaopen_os (lua_State *L) {
-  LREGISTER(L, LUA_OSLIBNAME, syslib);
+   return 1;
 }

+ 2 - 2
app/lua/luaconf.h

@@ -910,8 +910,8 @@ union luai_Cast { double l_d; long l_l; };
 ** without modifying the main part of the file.
 */
 
-#if LUA_OPTIMIZE_MEMORY == 2 && defined(LUA_USE_POPEN)
-#error "Pipes not supported in aggresive optimization mode (LUA_OPTIMIZE_MEMORY=2)"
+#if defined(LUA_USE_POPEN)
+#error "Pipes not supported NodeMCU firmware"
 #endif
 
 #endif

+ 9 - 9
app/modules/adc.c

@@ -61,13 +61,13 @@ static int adc_init107( lua_State *L )
 }
 
 // Module function map
-static const LUA_REG_TYPE adc_map[] = {
-  { LSTRKEY( "read" ),      LFUNCVAL( adc_sample ) },
-  { LSTRKEY( "readvdd33" ), LFUNCVAL( adc_readvdd33 ) },
-  { LSTRKEY( "force_init_mode" ), LFUNCVAL( adc_init107 ) },
-  { LSTRKEY( "INIT_ADC" ),  LNUMVAL( 0x00 ) },
-  { LSTRKEY( "INIT_VDD33" ),LNUMVAL( 0xff ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(adc)
+  LROT_FUNCENTRY( read, adc_sample )
+  LROT_FUNCENTRY( readvdd33, adc_readvdd33 )
+  LROT_FUNCENTRY( force_init_mode, adc_init107 )
+  LROT_NUMENTRY( INIT_ADC, 0x00 )
+  LROT_NUMENTRY( INIT_VDD33, 0xff )
+LROT_END( adc, NULL, 0 )
 
-NODEMCU_MODULE(ADC, "adc", adc_map, NULL);
+
+NODEMCU_MODULE(ADC, "adc", adc, NULL);

+ 57 - 60
app/modules/ads1115.c

@@ -531,71 +531,68 @@ static int ads1115_lua_delete(lua_State *L) {
     return 0;
 }
 
-static const LUA_REG_TYPE ads1115_map[] = {
-
-    {   LSTRKEY( "ads1115" ),       LFUNCVAL(ads1115_lua_register_1115) },
-    {   LSTRKEY( "ads1015" ),       LFUNCVAL(ads1115_lua_register_1015) },
-    {   LSTRKEY( "reset" ),         LFUNCVAL(ads1115_lua_reset)     },
-    {   LSTRKEY( "ADDR_GND" ),      LNUMVAL(ADS1115_I2C_ADDR_GND)   },
-    {   LSTRKEY( "ADDR_VDD" ),      LNUMVAL(ADS1115_I2C_ADDR_VDD)   },
-    {   LSTRKEY( "ADDR_SDA" ),      LNUMVAL(ADS1115_I2C_ADDR_SDA)   },
-    {   LSTRKEY( "ADDR_SCL" ),      LNUMVAL(ADS1115_I2C_ADDR_SCL)   },
-    {   LSTRKEY( "SINGLE_SHOT" ),   LNUMVAL(ADS1115_MODE_SINGLE)    },
-    {   LSTRKEY( "CONTINUOUS" ),    LNUMVAL(ADS1115_MODE_CONTIN)    },
-    {   LSTRKEY( "DIFF_0_1" ),      LNUMVAL(ADS1115_MUX_DIFF_0_1)   },
-    {   LSTRKEY( "DIFF_0_3" ),      LNUMVAL(ADS1115_MUX_DIFF_0_3)   },
-    {   LSTRKEY( "DIFF_1_3" ),      LNUMVAL(ADS1115_MUX_DIFF_1_3)   },
-    {   LSTRKEY( "DIFF_2_3" ),      LNUMVAL(ADS1115_MUX_DIFF_2_3)   },
-    {   LSTRKEY( "SINGLE_0" ),      LNUMVAL(ADS1115_MUX_SINGLE_0)   },
-    {   LSTRKEY( "SINGLE_1" ),      LNUMVAL(ADS1115_MUX_SINGLE_1)   },
-    {   LSTRKEY( "SINGLE_2" ),      LNUMVAL(ADS1115_MUX_SINGLE_2)   },
-    {   LSTRKEY( "SINGLE_3" ),      LNUMVAL(ADS1115_MUX_SINGLE_3)   },
-    {   LSTRKEY( "GAIN_6_144V" ),   LNUMVAL(ADS1115_PGA_6_144V)     },
-    {   LSTRKEY( "GAIN_4_096V" ),   LNUMVAL(ADS1115_PGA_4_096V)     },
-    {   LSTRKEY( "GAIN_2_048V" ),   LNUMVAL(ADS1115_PGA_2_048V)     },
-    {   LSTRKEY( "GAIN_1_024V" ),   LNUMVAL(ADS1115_PGA_1_024V)     },
-    {   LSTRKEY( "GAIN_0_512V" ),   LNUMVAL(ADS1115_PGA_0_512V)     },
-    {   LSTRKEY( "GAIN_0_256V" ),   LNUMVAL(ADS1115_PGA_0_256V)     },
-    {   LSTRKEY( "DR_8SPS" ),       LNUMVAL(ADS1115_DR_8SPS)        },
-    {   LSTRKEY( "DR_16SPS" ),      LNUMVAL(ADS1115_DR_16SPS)       },
-    {   LSTRKEY( "DR_32SPS" ),      LNUMVAL(ADS1115_DR_32SPS)       },
-    {   LSTRKEY( "DR_64SPS" ),      LNUMVAL(ADS1115_DR_64SPS)       },
-    {   LSTRKEY( "DR_128SPS" ),     LNUMVAL(ADS1115_DR_128SPS)      },
-    {   LSTRKEY( "DR_250SPS" ),     LNUMVAL(ADS1115_DR_250SPS)      },
-    {   LSTRKEY( "DR_475SPS" ),     LNUMVAL(ADS1115_DR_475SPS)      },
-    {   LSTRKEY( "DR_490SPS" ),     LNUMVAL(ADS1115_DR_490SPS)      },
-    {   LSTRKEY( "DR_860SPS" ),     LNUMVAL(ADS1115_DR_860SPS)      },
-    {   LSTRKEY( "DR_920SPS" ),     LNUMVAL(ADS1115_DR_920SPS)      },
-    {   LSTRKEY( "DR_1600SPS" ),    LNUMVAL(ADS1115_DR_1600SPS)     },
-    {   LSTRKEY( "DR_2400SPS" ),    LNUMVAL(ADS1115_DR_2400SPS)     },
-    {   LSTRKEY( "DR_3300SPS" ),    LNUMVAL(ADS1115_DR_3300SPS)     },
-    {   LSTRKEY( "CONV_RDY_1" ),    LNUMVAL(ADS1115_CQUE_1CONV)     },
-    {   LSTRKEY( "CONV_RDY_2" ),    LNUMVAL(ADS1115_CQUE_2CONV)     },
-    {   LSTRKEY( "CONV_RDY_4" ),    LNUMVAL(ADS1115_CQUE_4CONV)     },
-    {   LSTRKEY( "COMP_1CONV" ),    LNUMVAL(ADS1115_CQUE_1CONV)     },
-    {   LSTRKEY( "COMP_2CONV" ),    LNUMVAL(ADS1115_CQUE_2CONV)     },
-    {   LSTRKEY( "COMP_4CONV" ),    LNUMVAL(ADS1115_CQUE_4CONV)     },
-    {   LSTRKEY( "CMODE_TRAD"),     LNUMVAL(ADS1115_CMODE_TRAD)     },
-    {   LSTRKEY( "CMODE_WINDOW"),   LNUMVAL(ADS1115_CMODE_WINDOW)   },
-    {   LNILKEY, LNILVAL                                            }
-};
-
-static const LUA_REG_TYPE ads1115_instance_map[] = {
-    {   LSTRKEY( "setting" ),       LFUNCVAL(ads1115_lua_setting)   },
-    {   LSTRKEY( "startread" ),     LFUNCVAL(ads1115_lua_startread) },
-    {   LSTRKEY( "read" ),          LFUNCVAL(ads1115_lua_read)      },
+LROT_BEGIN(ads1115)
+  LROT_FUNCENTRY( ads1115, ads1115_lua_register_1115 )
+  LROT_FUNCENTRY( ads1015, ads1115_lua_register_1015 )
+  LROT_FUNCENTRY( reset, ads1115_lua_reset )
+  LROT_NUMENTRY( ADDR_GND, ADS1115_I2C_ADDR_GND )
+  LROT_NUMENTRY( ADDR_VDD, ADS1115_I2C_ADDR_VDD )
+  LROT_NUMENTRY( ADDR_SDA, ADS1115_I2C_ADDR_SDA )
+  LROT_NUMENTRY( ADDR_SCL, ADS1115_I2C_ADDR_SCL )
+  LROT_NUMENTRY( SINGLE_SHOT, ADS1115_MODE_SINGLE )
+  LROT_NUMENTRY( CONTINUOUS, ADS1115_MODE_CONTIN )
+  LROT_NUMENTRY( DIFF_0_1, ADS1115_MUX_DIFF_0_1 )
+  LROT_NUMENTRY( DIFF_0_3, ADS1115_MUX_DIFF_0_3 )
+  LROT_NUMENTRY( DIFF_1_3, ADS1115_MUX_DIFF_1_3 )
+  LROT_NUMENTRY( DIFF_2_3, ADS1115_MUX_DIFF_2_3 )
+  LROT_NUMENTRY( SINGLE_0, ADS1115_MUX_SINGLE_0 )
+  LROT_NUMENTRY( SINGLE_1, ADS1115_MUX_SINGLE_1 )
+  LROT_NUMENTRY( SINGLE_2, ADS1115_MUX_SINGLE_2 )
+  LROT_NUMENTRY( SINGLE_3, ADS1115_MUX_SINGLE_3 )
+  LROT_NUMENTRY( GAIN_6_144V, ADS1115_PGA_6_144V )
+  LROT_NUMENTRY( GAIN_4_096V, ADS1115_PGA_4_096V )
+  LROT_NUMENTRY( GAIN_2_048V, ADS1115_PGA_2_048V )
+  LROT_NUMENTRY( GAIN_1_024V, ADS1115_PGA_1_024V )
+  LROT_NUMENTRY( GAIN_0_512V, ADS1115_PGA_0_512V )
+  LROT_NUMENTRY( GAIN_0_256V, ADS1115_PGA_0_256V )
+  LROT_NUMENTRY( DR_8SPS, ADS1115_DR_8SPS )
+  LROT_NUMENTRY( DR_16SPS, ADS1115_DR_16SPS )
+  LROT_NUMENTRY( DR_32SPS, ADS1115_DR_32SPS )
+  LROT_NUMENTRY( DR_64SPS, ADS1115_DR_64SPS )
+  LROT_NUMENTRY( DR_128SPS, ADS1115_DR_128SPS )
+  LROT_NUMENTRY( DR_250SPS, ADS1115_DR_250SPS )
+  LROT_NUMENTRY( DR_475SPS, ADS1115_DR_475SPS )
+  LROT_NUMENTRY( DR_490SPS, ADS1115_DR_490SPS )
+  LROT_NUMENTRY( DR_860SPS, ADS1115_DR_860SPS )
+  LROT_NUMENTRY( DR_920SPS, ADS1115_DR_920SPS )
+  LROT_NUMENTRY( DR_1600SPS, ADS1115_DR_1600SPS )
+  LROT_NUMENTRY( DR_2400SPS, ADS1115_DR_2400SPS )
+  LROT_NUMENTRY( DR_3300SPS, ADS1115_DR_3300SPS )
+  LROT_NUMENTRY( CONV_RDY_1, ADS1115_CQUE_1CONV )
+  LROT_NUMENTRY( CONV_RDY_2, ADS1115_CQUE_2CONV )
+  LROT_NUMENTRY( CONV_RDY_4, ADS1115_CQUE_4CONV )
+  LROT_NUMENTRY( COMP_1CONV, ADS1115_CQUE_1CONV )
+  LROT_NUMENTRY( COMP_2CONV, ADS1115_CQUE_2CONV )
+  LROT_NUMENTRY( COMP_4CONV, ADS1115_CQUE_4CONV )
+  LROT_NUMENTRY( CMODE_TRAD, ADS1115_CMODE_TRAD )
+  LROT_NUMENTRY( CMODE_WINDOW, ADS1115_CMODE_WINDOW )
+LROT_END(ads1115, NULL, 0 )
+
+LROT_BEGIN(ads1115_instance)
+  LROT_FUNCENTRY( setting, ads1115_lua_setting )
+  LROT_FUNCENTRY( startread, ads1115_lua_startread )
+  LROT_FUNCENTRY( read, ads1115_lua_read )
 #ifdef ADS1115_INCLUDE_TEST_FUNCTION
-    {   LSTRKEY( "test_volt_conversion" ), LFUNCVAL(test_volt_conversion)},
+  LROT_FUNCENTRY( test_volt_conversion, test_volt_conversion )
 #endif
-    {   LSTRKEY( "__index" ),       LROVAL(ads1115_instance_map)    },
-    {   LSTRKEY( "__gc" ),          LFUNCVAL(ads1115_lua_delete)    },
-    {   LNILKEY, LNILVAL                                            }
-};
+  LROT_TABENTRY( "__index", ads1115_instance )
+  LROT_FUNCENTRY( __gc, ads1115_lua_delete )
+LROT_END(ads1115_instance, ads1115_instance, LROT_MASK_GC_INDEX )
 
 
 int luaopen_ads1115(lua_State *L) {
-    luaL_rometatable(L, metatable_name, (void *)ads1115_instance_map);
+    luaL_rometatable(L, metatable_name, LROT_TABLEREF(ads1115_instance));
     return 0;
 }
 
-NODEMCU_MODULE(ADS1115, "ads1115", ads1115_map, luaopen_ads1115);
+NODEMCU_MODULE(ADS1115, "ads1115", ads1115, luaopen_ads1115);

+ 6 - 6
app/modules/adxl345.c

@@ -76,10 +76,10 @@ static int adxl345_read(lua_State* L) {
     return 3;
 }
 
-static const LUA_REG_TYPE adxl345_map[] = {
-    { LSTRKEY( "read" ),         LFUNCVAL( adxl345_read )},
-    { LSTRKEY( "setup" ),        LFUNCVAL( adxl345_setup )},
-    { LNILKEY, LNILVAL}
-};
+LROT_BEGIN(adxl345)
+  LROT_FUNCENTRY( read, adxl345_read )
+  LROT_FUNCENTRY( setup, adxl345_setup )
+LROT_END( adxl345, NULL, 0 )
 
-NODEMCU_MODULE(ADXL345, "adxl345", adxl345_map, NULL);
+
+NODEMCU_MODULE(ADXL345, "adxl345", adxl345, NULL);

+ 6 - 6
app/modules/am2320.c

@@ -129,10 +129,10 @@ static int am2320_read(lua_State* L)
     return 2;
 }
 
-static const LUA_REG_TYPE am2320_map[] = {
-    { LSTRKEY( "read" ),  LFUNCVAL( am2320_read )},
-    { LSTRKEY( "setup" ), LFUNCVAL( am2320_setup )},
-    { LNILKEY, LNILVAL}
-};
+LROT_BEGIN(am2320)
+  LROT_FUNCENTRY( read, am2320_read )
+  LROT_FUNCENTRY( setup, am2320_setup )
+LROT_END( am2320, NULL, 0 )
 
-NODEMCU_MODULE(AM2320, "am2320", am2320_map, NULL);
+
+NODEMCU_MODULE(AM2320, "am2320", am2320, NULL);

+ 5 - 6
app/modules/apa102.c

@@ -101,15 +101,14 @@ static int apa102_write(lua_State* L) {
 }
 
 
-const LUA_REG_TYPE apa102_map[] =
-{
-  { LSTRKEY( "write" ), LFUNCVAL( apa102_write )},
-  { LNILKEY, LNILVAL}
-};
+LROT_PUBLIC_BEGIN(apa102)
+  LROT_FUNCENTRY( write, apa102_write )
+LROT_END( apa102, NULL, 0 )
+
 
 LUALIB_API int luaopen_apa102(lua_State *L) {
   LREGISTER(L, "apa102", apa102_map);
   return 0;
 }
 
-NODEMCU_MODULE(APA102, "apa102", apa102_map, luaopen_apa102);
+NODEMCU_MODULE(APA102, "apa102", apa102, luaopen_apa102);

+ 17 - 17
app/modules/bit.c

@@ -119,20 +119,20 @@ static int bit_clear( lua_State* L )
   return 1;
 }
 
-static const LUA_REG_TYPE bit_map[] = {
-  { LSTRKEY( "bnot" ),    LFUNCVAL( bit_bnot ) },
-  { LSTRKEY( "band" ),    LFUNCVAL( bit_band ) },
-  { LSTRKEY( "bor" ),     LFUNCVAL( bit_bor ) },
-  { LSTRKEY( "bxor" ),    LFUNCVAL( bit_bxor ) },
-  { LSTRKEY( "lshift" ),  LFUNCVAL( bit_lshift ) },
-  { LSTRKEY( "rshift" ),  LFUNCVAL( bit_rshift ) },
-  { LSTRKEY( "arshift" ), LFUNCVAL( bit_arshift ) },
-  { LSTRKEY( "bit" ),     LFUNCVAL( bit_bit ) },
-  { LSTRKEY( "set" ),     LFUNCVAL( bit_set ) },
-  { LSTRKEY( "clear" ),   LFUNCVAL( bit_clear ) },
-  { LSTRKEY( "isset" ),   LFUNCVAL( bit_isset ) },
-  { LSTRKEY( "isclear" ), LFUNCVAL( bit_isclear ) },
-  { LNILKEY, LNILVAL}
-};
-
-NODEMCU_MODULE(BIT, "bit", bit_map, NULL);
+LROT_BEGIN(bit)
+  LROT_FUNCENTRY( bnot, bit_bnot )
+  LROT_FUNCENTRY( band, bit_band )
+  LROT_FUNCENTRY( bor, bit_bor )
+  LROT_FUNCENTRY( bxor, bit_bxor )
+  LROT_FUNCENTRY( lshift, bit_lshift )
+  LROT_FUNCENTRY( rshift, bit_rshift )
+  LROT_FUNCENTRY( arshift, bit_arshift )
+  LROT_FUNCENTRY( bit, bit_bit )
+  LROT_FUNCENTRY( set, bit_set )
+  LROT_FUNCENTRY( clear, bit_clear )
+  LROT_FUNCENTRY( isset, bit_isset )
+  LROT_FUNCENTRY( isclear, bit_isclear )
+LROT_END( bit, NULL, 0 )
+
+
+NODEMCU_MODULE(BIT, "bit", bit, NULL);

+ 14 - 14
app/modules/bloom.c

@@ -169,24 +169,24 @@ static int bloom_create(lua_State *L) {
   return 1;
 }
 
-static const LUA_REG_TYPE bloom_filter_map[] = {
-  { LSTRKEY( "add" ),                   LFUNCVAL( bloom_filter_add ) },
-  { LSTRKEY( "check" ),                 LFUNCVAL( bloom_filter_check ) },
-  { LSTRKEY( "reset" ),                 LFUNCVAL( bloom_filter_reset ) },
-  { LSTRKEY( "info" ),                  LFUNCVAL( bloom_filter_info ) },
-  { LSTRKEY( "__index" ),               LROVAL( bloom_filter_map ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(bloom_filter)
+  LROT_FUNCENTRY( add, bloom_filter_add )
+  LROT_FUNCENTRY( check, bloom_filter_check )
+  LROT_FUNCENTRY( reset, bloom_filter_reset )
+  LROT_FUNCENTRY( info, bloom_filter_info )
+  LROT_TABENTRY( __index, bloom_filter )
+LROT_END( bloom_filter, bloom_filter, LROT_MASK_INDEX )
+
 
 // Module function map
-static const LUA_REG_TYPE bloom_map[] = {
-  { LSTRKEY( "create" ),   LFUNCVAL( bloom_create ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(bloom)
+  LROT_FUNCENTRY( create, bloom_create )
+LROT_END( bloom, NULL, 0 )
+
 
 LUALIB_API int bloom_open(lua_State *L) {
-  luaL_rometatable(L, "bloom.filter", (void *)bloom_filter_map);
+  luaL_rometatable(L, "bloom.filter", LROT_TABLEREF(bloom_filter));
   return 1;
 }
 
-NODEMCU_MODULE(BLOOM, "bloom", bloom_map, bloom_open);
+NODEMCU_MODULE(BLOOM, "bloom", bloom, bloom_open);

+ 14 - 14
app/modules/bme280.c

@@ -470,17 +470,17 @@ static int bme280_lua_dewpoint(lua_State* L) {
 	return 1;
 }
 
-static const LUA_REG_TYPE bme280_map[] = {
-	{ LSTRKEY( "setup" ), LFUNCVAL(bme280_lua_setup)},
-	{ LSTRKEY( "temp" ),  LFUNCVAL(bme280_lua_temp)},
-	{ LSTRKEY( "baro" ),  LFUNCVAL(bme280_lua_baro)},
-	{ LSTRKEY( "humi" ),  LFUNCVAL(bme280_lua_humi)},
-	{ LSTRKEY( "startreadout" ),  LFUNCVAL(bme280_lua_startreadout)},
-	{ LSTRKEY( "qfe2qnh" ),  LFUNCVAL(bme280_lua_qfe2qnh)},
-	{ LSTRKEY( "altitude" ),  LFUNCVAL(bme280_lua_altitude)},
-	{ LSTRKEY( "dewpoint" ),  LFUNCVAL(bme280_lua_dewpoint)},
-	{ LSTRKEY( "read" ),  LFUNCVAL(bme280_lua_read)},
-	{ LNILKEY, LNILVAL}
-};
-
-NODEMCU_MODULE(BME280, "bme280", bme280_map, NULL);
+LROT_BEGIN(bme280)
+  LROT_FUNCENTRY( setup, bme280_lua_setup )
+  LROT_FUNCENTRY( temp, bme280_lua_temp )
+  LROT_FUNCENTRY( baro, bme280_lua_baro )
+  LROT_FUNCENTRY( humi, bme280_lua_humi )
+  LROT_FUNCENTRY( startreadout, bme280_lua_startreadout )
+  LROT_FUNCENTRY( qfe2qnh, bme280_lua_qfe2qnh )
+  LROT_FUNCENTRY( altitude, bme280_lua_altitude )
+  LROT_FUNCENTRY( dewpoint, bme280_lua_dewpoint )
+  LROT_FUNCENTRY( read, bme280_lua_read )
+LROT_END( bme280, NULL, 0 )
+
+
+NODEMCU_MODULE(BME280, "bme280", bme280, NULL);

+ 11 - 11
app/modules/bme680.c

@@ -534,14 +534,14 @@ static int bme680_lua_dewpoint(lua_State* L) {
 	return 1;
 }
 
-static const LUA_REG_TYPE bme680_map[] = {
-	{ LSTRKEY( "setup" ), LFUNCVAL(bme680_lua_setup)},
-	{ LSTRKEY( "startreadout" ),  LFUNCVAL(bme680_lua_startreadout)},
-	{ LSTRKEY( "qfe2qnh" ),  LFUNCVAL(bme680_lua_qfe2qnh)},
-	{ LSTRKEY( "altitude" ),  LFUNCVAL(bme680_lua_altitude)},
-	{ LSTRKEY( "dewpoint" ),  LFUNCVAL(bme680_lua_dewpoint)},
-	{ LSTRKEY( "read" ),  LFUNCVAL(bme680_lua_read)},
-	{ LNILKEY, LNILVAL}
-};
-
-NODEMCU_MODULE(BME680, "bme680", bme680_map, NULL);
+LROT_BEGIN(bme680)
+  LROT_FUNCENTRY( setup, bme680_lua_setup )
+  LROT_FUNCENTRY( startreadout, bme680_lua_startreadout )
+  LROT_FUNCENTRY( qfe2qnh, bme680_lua_qfe2qnh )
+  LROT_FUNCENTRY( altitude, bme680_lua_altitude )
+  LROT_FUNCENTRY( dewpoint, bme680_lua_dewpoint )
+  LROT_FUNCENTRY( read, bme680_lua_read )
+LROT_END( bme680, NULL, 0 )
+
+
+NODEMCU_MODULE(BME680, "bme680", bme680, NULL);

+ 9 - 9
app/modules/bmp085.c

@@ -169,12 +169,12 @@ static int bmp085_lua_pressure(lua_State* L) {
     return 1;
 }
 
-static const LUA_REG_TYPE bmp085_map[] = {
-    { LSTRKEY( "temperature" ),  LFUNCVAL( bmp085_lua_temperature )},
-    { LSTRKEY( "pressure" ),     LFUNCVAL( bmp085_lua_pressure )},
-    { LSTRKEY( "pressure_raw" ), LFUNCVAL( bmp085_lua_pressure_raw )},
-    { LSTRKEY( "setup" ),        LFUNCVAL( bmp085_setup )},
-    { LNILKEY, LNILVAL}
-};
-
-NODEMCU_MODULE(BMP085, "bmp085", bmp085_map, NULL);
+LROT_BEGIN(bmp085)
+  LROT_FUNCENTRY( temperature, bmp085_lua_temperature )
+  LROT_FUNCENTRY( pressure, bmp085_lua_pressure )
+  LROT_FUNCENTRY( pressure_raw, bmp085_lua_pressure_raw )
+  LROT_FUNCENTRY( setup, bmp085_setup )
+LROT_END( bmp085, NULL, 0 )
+
+
+NODEMCU_MODULE(BMP085, "bmp085", bmp085, NULL);

+ 37 - 38
app/modules/coap.c

@@ -556,48 +556,47 @@ static int coap_client_delete( lua_State* L )
 }
 
 // Module function map
-static const LUA_REG_TYPE coap_server_map[] = {
-  { LSTRKEY( "listen" ),  LFUNCVAL( coap_server_listen ) },
-  { LSTRKEY( "close" ),   LFUNCVAL( coap_server_close ) },
-  { LSTRKEY( "var" ),     LFUNCVAL( coap_server_var ) },
-  { LSTRKEY( "func" ),    LFUNCVAL( coap_server_func ) },
-  { LSTRKEY( "__gc" ),    LFUNCVAL( coap_server_delete ) },
-  { LSTRKEY( "__index" ), LROVAL( coap_server_map ) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE coap_client_map[] = {
-  { LSTRKEY( "get" ),     LFUNCVAL( coap_client_get ) },
-  { LSTRKEY( "post" ),    LFUNCVAL( coap_client_post ) },
-  { LSTRKEY( "put" ),     LFUNCVAL( coap_client_put ) },
-  { LSTRKEY( "delete" ),  LFUNCVAL( coap_client_delete ) },
-  { LSTRKEY( "__gc" ),    LFUNCVAL( coap_client_gcdelete ) },
-  { LSTRKEY( "__index" ), LROVAL( coap_client_map ) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE coap_map[] =
-{
-  { LSTRKEY( "Server" ),      LFUNCVAL( coap_createServer ) },
-  { LSTRKEY( "Client" ),      LFUNCVAL( coap_createClient ) },
-  { LSTRKEY( "CON" ),         LNUMVAL( COAP_TYPE_CON ) },
-  { LSTRKEY( "NON" ),         LNUMVAL( COAP_TYPE_NONCON ) },
-  { LSTRKEY( "TEXT_PLAIN"),   LNUMVAL( COAP_CONTENTTYPE_TEXT_PLAIN ) },
-  { LSTRKEY( "LINKFORMAT"),   LNUMVAL( COAP_CONTENTTYPE_APPLICATION_LINKFORMAT ) },
-  { LSTRKEY( "XML"),          LNUMVAL( COAP_CONTENTTYPE_APPLICATION_XML ) },
-  { LSTRKEY( "OCTET_STREAM"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_OCTET_STREAM ) },
-  { LSTRKEY( "EXI"),          LNUMVAL( COAP_CONTENTTYPE_APPLICATION_EXI ) },
-  { LSTRKEY( "JSON"),         LNUMVAL( COAP_CONTENTTYPE_APPLICATION_JSON) },
-  { LSTRKEY( "__metatable" ), LROVAL( coap_map ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(coap_server)
+  LROT_FUNCENTRY( listen, coap_server_listen )
+  LROT_FUNCENTRY( close, coap_server_close )
+  LROT_FUNCENTRY( var, coap_server_var )
+  LROT_FUNCENTRY( func, coap_server_func )
+  LROT_FUNCENTRY( __gc, coap_server_delete )
+  LROT_TABENTRY( __index, coap_server )
+LROT_END( coap_server, coap_server, 0 )
+
+
+LROT_BEGIN(coap_client)
+  LROT_FUNCENTRY( get, coap_client_get )
+  LROT_FUNCENTRY( post, coap_client_post )
+  LROT_FUNCENTRY( put, coap_client_put )
+  LROT_FUNCENTRY( delete, coap_client_delete )
+  LROT_FUNCENTRY( __gc, coap_client_gcdelete )
+  LROT_TABENTRY( __index, coap_client )
+LROT_END( coap_client, coap_client, 0 )
+
+
+LROT_BEGIN(coap)
+  LROT_FUNCENTRY( Server, coap_createServer )
+  LROT_FUNCENTRY( Client, coap_createClient )
+  LROT_NUMENTRY( CON, COAP_TYPE_CON )
+  LROT_NUMENTRY( NON, COAP_TYPE_NONCON )
+  LROT_NUMENTRY( TEXT_PLAIN, COAP_CONTENTTYPE_TEXT_PLAIN )
+  LROT_NUMENTRY( LINKFORMAT, COAP_CONTENTTYPE_APPLICATION_LINKFORMAT )
+  LROT_NUMENTRY( XML, COAP_CONTENTTYPE_APPLICATION_XML )
+  LROT_NUMENTRY( OCTET_STREAM, COAP_CONTENTTYPE_APPLICATION_OCTET_STREAM )
+  LROT_NUMENTRY( EXI, COAP_CONTENTTYPE_APPLICATION_EXI )
+  LROT_NUMENTRY( JSON, COAP_CONTENTTYPE_APPLICATION_JSON )
+  LROT_TABENTRY( __metatable, coap )
+LROT_END( coap, coap, 0 )
+
 
 int luaopen_coap( lua_State *L )
 {
   endpoint_setup();
-  luaL_rometatable(L, "coap_server", (void *)coap_server_map);  // create metatable for coap_server
-  luaL_rometatable(L, "coap_client", (void *)coap_client_map);  // create metatable for coap_client
+  luaL_rometatable(L, "coap_server", LROT_TABLEREF(coap_server));
+  luaL_rometatable(L, "coap_client", LROT_TABLEREF(coap_client));
   return 0;
 }
 
-NODEMCU_MODULE(COAP, "coap", coap_map, luaopen_coap);
+NODEMCU_MODULE(COAP, "coap", coap, luaopen_coap);

+ 9 - 10
app/modules/color_utils.c

@@ -234,13 +234,12 @@ static int cu_grb2hsv(lua_State *L) {
 }
 
 
-static const LUA_REG_TYPE color_utils_map[] =
-{
-  { LSTRKEY( "hsv2grb" ),       LFUNCVAL( cu_hsv2grb )},
-  { LSTRKEY( "hsv2grbw" ),      LFUNCVAL( cu_hsv2grbw )},
-  { LSTRKEY( "colorWheel" ),    LFUNCVAL( cu_color_wheel )},
-  { LSTRKEY( "grb2hsv" ),       LFUNCVAL( cu_grb2hsv )},
-  { LNILKEY, LNILVAL}
-};
-
-NODEMCU_MODULE(COLOR_UTILS, "color_utils", color_utils_map, NULL);
+LROT_BEGIN(color_utils)
+  LROT_FUNCENTRY( hsv2grb, cu_hsv2grb )
+  LROT_FUNCENTRY( hsv2grbw, cu_hsv2grbw )
+  LROT_FUNCENTRY( colorWheel, cu_color_wheel )
+  LROT_FUNCENTRY( grb2hsv, cu_grb2hsv )
+LROT_END( color_utils, NULL, 0 )
+
+
+NODEMCU_MODULE(COLOR_UTILS, "color_utils", color_utils, NULL);

+ 15 - 15
app/modules/cron.c

@@ -224,20 +224,20 @@ static void cron_handle_tmr() {
   cron_handle_time(tm.tm_mon + 1, tm.tm_mday, tm.tm_wday, tm.tm_hour, tm.tm_min);
 }
 
-static const LUA_REG_TYPE cronent_map[] = {
-  { LSTRKEY( "schedule" ),   LFUNCVAL( lcron_schedule ) },
-  { LSTRKEY( "handler" ),    LFUNCVAL( lcron_handler ) },
-  { LSTRKEY( "unschedule" ), LFUNCVAL( lcron_unschedule ) },
-  { LSTRKEY( "__gc" ),       LFUNCVAL( lcron_delete ) },
-  { LSTRKEY( "__index" ),    LROVAL( cronent_map ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(cronent)
+  LROT_FUNCENTRY( schedule, lcron_schedule )
+  LROT_FUNCENTRY( handler, lcron_handler )
+  LROT_FUNCENTRY( unschedule, lcron_unschedule )
+  LROT_FUNCENTRY( __gc, lcron_delete )
+  LROT_TABENTRY( __index, cronent )
+LROT_END( cronent, cronent, LROT_MASK_GC_INDEX )
+
+
+LROT_BEGIN(cron)
+  LROT_FUNCENTRY( schedule, lcron_create )
+  LROT_FUNCENTRY( reset, lcron_reset )
+LROT_END( cron, NULL, 0 )
 
-static const LUA_REG_TYPE cron_map[] = {
-  { LSTRKEY( "schedule" ),   LFUNCVAL( lcron_create ) },
-  { LSTRKEY( "reset" ),      LFUNCVAL( lcron_reset ) },
-  { LNILKEY, LNILVAL }
-};
 #include "pm/swtimer.h"
 
 int luaopen_cron( lua_State *L ) {
@@ -247,8 +247,8 @@ int luaopen_cron( lua_State *L ) {
     //cron_handle_tmr determines when to execute a scheduled cron job
     //My guess: To be sure to give the other modules required by cron enough time to get to a ready state, restart cron_timer.
   os_timer_arm(&cron_timer, 1000, 0);
-  luaL_rometatable(L, "cron.entry", (void *)cronent_map);
+  luaL_rometatable(L, "cron.entry", LROT_TABLEREF(cronent));
   return 0;
 }
 
-NODEMCU_MODULE(CRON, "cron", cron_map, luaopen_cron);
+NODEMCU_MODULE(CRON, "cron", cron, luaopen_cron);

+ 22 - 22
app/modules/crypto.c

@@ -383,34 +383,34 @@ static int lcrypto_decrypt (lua_State *L)
 }
 
 // Hash function map
-static const LUA_REG_TYPE crypto_hash_map[] = {
-  { LSTRKEY( "update" ),  LFUNCVAL( crypto_hash_update ) },
-  { LSTRKEY( "finalize" ),   LFUNCVAL( crypto_hash_finalize ) },
-  { LSTRKEY( "__index" ), LROVAL( crypto_hash_map ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(crypto_hash)
+  LROT_FUNCENTRY( update, crypto_hash_update )
+  LROT_FUNCENTRY( finalize, crypto_hash_finalize )
+  LROT_TABENTRY( __index, crypto_hash )
+LROT_END( crypto_hash, crypto_hash, LROT_MASK_INDEX )
+
 
 
 // Module function map
-static const LUA_REG_TYPE crypto_map[] = {
-  { LSTRKEY( "sha1" ),     LFUNCVAL( crypto_sha1 ) },
-  { LSTRKEY( "toBase64" ), LFUNCVAL( crypto_base64_encode ) },
-  { LSTRKEY( "toHex" ),    LFUNCVAL( crypto_hex_encode ) },
-  { LSTRKEY( "mask" ),     LFUNCVAL( crypto_mask ) },
-  { LSTRKEY( "hash"   ),   LFUNCVAL( crypto_lhash ) },
-  { LSTRKEY( "fhash"  ),   LFUNCVAL( crypto_flhash ) },
-  { LSTRKEY( "new_hash"   ),   LFUNCVAL( crypto_new_hash ) },
-  { LSTRKEY( "hmac"   ),   LFUNCVAL( crypto_lhmac ) },
-  { LSTRKEY( "new_hmac"   ),   LFUNCVAL( crypto_new_hmac ) },
-  { LSTRKEY( "encrypt" ),  LFUNCVAL( lcrypto_encrypt ) },
-  { LSTRKEY( "decrypt" ),  LFUNCVAL( lcrypto_decrypt ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(crypto)
+  LROT_FUNCENTRY( sha1, crypto_sha1 )
+  LROT_FUNCENTRY( toBase64, crypto_base64_encode )
+  LROT_FUNCENTRY( toHex, crypto_hex_encode )
+  LROT_FUNCENTRY( mask, crypto_mask )
+  LROT_FUNCENTRY( hash, crypto_lhash )
+  LROT_FUNCENTRY( fhash, crypto_flhash )
+  LROT_FUNCENTRY( new_hash, crypto_new_hash )
+  LROT_FUNCENTRY( hmac, crypto_lhmac )
+  LROT_FUNCENTRY( new_hmac, crypto_new_hmac )
+  LROT_FUNCENTRY( encrypt, lcrypto_encrypt )
+  LROT_FUNCENTRY( decrypt, lcrypto_decrypt )
+LROT_END( crypto, NULL, 0 )
+
 
 int luaopen_crypto ( lua_State *L )
 {
-  luaL_rometatable(L, "crypto.hash", (void *)crypto_hash_map);  // create metatable for crypto.hash
+  luaL_rometatable(L, "crypto.hash", LROT_TABLEREF(crypto_hash));
   return 0;
 }
 
-NODEMCU_MODULE(CRYPTO, "crypto", crypto_map, luaopen_crypto);
+NODEMCU_MODULE(CRYPTO, "crypto", crypto, luaopen_crypto);

+ 10 - 10
app/modules/dht.c

@@ -99,14 +99,14 @@ static int dht_lapi_readxx( lua_State *L )
 // }
 
 // Module function map
-static const LUA_REG_TYPE dht_map[] = {
-  { LSTRKEY( "read" ),           LFUNCVAL( dht_lapi_read ) },
-  { LSTRKEY( "read11" ),         LFUNCVAL( dht_lapi_read11 ) },
-  { LSTRKEY( "readxx" ),         LFUNCVAL( dht_lapi_readxx ) },
-  { LSTRKEY( "OK" ),             LNUMVAL( DHTLIB_OK ) },
-  { LSTRKEY( "ERROR_CHECKSUM" ), LNUMVAL( DHTLIB_ERROR_CHECKSUM ) },
-  { LSTRKEY( "ERROR_TIMEOUT" ),  LNUMVAL( DHTLIB_ERROR_TIMEOUT ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(dht)
+  LROT_FUNCENTRY( read, dht_lapi_read )
+  LROT_FUNCENTRY( read11, dht_lapi_read11 )
+  LROT_FUNCENTRY( readxx, dht_lapi_readxx )
+  LROT_NUMENTRY( OK, DHTLIB_OK )
+  LROT_NUMENTRY( ERROR_CHECKSUM, DHTLIB_ERROR_CHECKSUM )
+  LROT_NUMENTRY( ERROR_TIMEOUT, DHTLIB_ERROR_TIMEOUT )
+LROT_END( dht, NULL, 0 )
 
-NODEMCU_MODULE(DHT, "dht", dht_map, NULL);
+
+NODEMCU_MODULE(DHT, "dht", dht, NULL);

+ 9 - 9
app/modules/encoder.c

@@ -153,12 +153,12 @@ static int do_func (lua_State *L, uint8 * (*conv_func)(lua_State *, const uint8
   DECLARE_FUNCTION(toHex);
 
 // Module function map
-static const LUA_REG_TYPE encoder_map[] = {
-  { LSTRKEY("fromBase64"), LFUNCVAL(encoder_fromBase64)  },
-  { LSTRKEY("toBase64"),   LFUNCVAL(encoder_toBase64) },
-  { LSTRKEY("fromHex"),    LFUNCVAL(encoder_fromHex)  },
-  { LSTRKEY("toHex"),      LFUNCVAL(encoder_toHex) },
-  { LNILKEY, LNILVAL }
-};
-
-NODEMCU_MODULE(ENCODER, "encoder", encoder_map, NULL);
+LROT_BEGIN(encoder)
+  LROT_FUNCENTRY( fromBase64, encoder_fromBase64 )
+  LROT_FUNCENTRY( toBase64, encoder_toBase64 )
+  LROT_FUNCENTRY( fromHex, encoder_fromHex )
+  LROT_FUNCENTRY( toHex, encoder_toHex )
+LROT_END( encoder, NULL, 0 )
+
+
+NODEMCU_MODULE(ENCODER, "encoder", encoder, NULL);

+ 8 - 8
app/modules/enduser_setup.c

@@ -1784,11 +1784,11 @@ static int enduser_setup_stop(lua_State* L)
 }
 
 
-static const LUA_REG_TYPE enduser_setup_map[] = {
-  { LSTRKEY( "manual" ), LFUNCVAL( enduser_setup_manual )},
-  { LSTRKEY( "start" ), LFUNCVAL( enduser_setup_start )},
-  { LSTRKEY( "stop" ),  LFUNCVAL( enduser_setup_stop  )},
-  { LNILKEY, LNILVAL}
-};
-
-NODEMCU_MODULE(ENDUSER_SETUP, "enduser_setup", enduser_setup_map, NULL);
+LROT_BEGIN(enduser_setup)
+  LROT_FUNCENTRY( manual, enduser_setup_manual )
+  LROT_FUNCENTRY( start, enduser_setup_start )
+  LROT_FUNCENTRY( stop, enduser_setup_stop )
+LROT_END( enduser_setup, NULL, 0 )
+
+
+NODEMCU_MODULE(ENDUSER_SETUP, "enduser_setup", enduser_setup, NULL);

+ 55 - 51
app/modules/file.c

@@ -644,64 +644,68 @@ static int file_vol_umount( lua_State *L )
 }
 
 
-static const LUA_REG_TYPE file_obj_map[] =
-{
-  { LSTRKEY( "close" ),     LFUNCVAL( file_close ) },
-  { LSTRKEY( "read" ),      LFUNCVAL( file_read ) },
-  { LSTRKEY( "readline" ),  LFUNCVAL( file_readline ) },
-  { LSTRKEY( "write" ),     LFUNCVAL( file_write ) },
-  { LSTRKEY( "writeline" ), LFUNCVAL( file_writeline ) },
-  { LSTRKEY( "seek" ),      LFUNCVAL( file_seek ) },
-  { LSTRKEY( "flush" ),     LFUNCVAL( file_flush ) },
-  { LSTRKEY( "__gc" ),      LFUNCVAL( file_obj_free ) },
-  { LSTRKEY( "__index" ),   LROVAL( file_obj_map ) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE file_vol_map[] =
-{
-  { LSTRKEY( "umount" ),   LFUNCVAL( file_vol_umount )},
-  //{ LSTRKEY( "getfree" ),  LFUNCVAL( file_vol_getfree )},
-  //{ LSTRKEY( "getlabel" ), LFUNCVAL( file_vol_getlabel )},
-  //{ LSTRKEY( "__gc" ),     LFUNCVAL( file_vol_free ) },
-  { LSTRKEY( "__index" ),  LROVAL( file_vol_map ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(file_obj)
+  LROT_FUNCENTRY( close, file_close )
+  LROT_FUNCENTRY( read, file_read )
+  LROT_FUNCENTRY( readline, file_readline )
+  LROT_FUNCENTRY( write, file_write )
+  LROT_FUNCENTRY( writeline, file_writeline )
+  LROT_FUNCENTRY( seek, file_seek )
+  LROT_FUNCENTRY( flush, file_flush )
+  LROT_FUNCENTRY( __gc, file_obj_free )
+  LROT_TABENTRY( __index, file_obj )
+LROT_END( file_obj, file_obj, LROT_MASK_GC_INDEX )
+
+
+LROT_BEGIN(file_vol)
+  LROT_FUNCENTRY( umount, file_vol_umount )
+  //  LROT_FUNCENTRY( getfree, file_vol_getfree )
+  //  LROT_FUNCENTRY( getlabel, file_vol_getlabel )
+  //  LROT_FUNCENTRY( __gc, file_vol_free )
+  LROT_TABENTRY( __index, file_vol )
+LROT_END( file_vol, file_vol, LROT_MASK_GC_INDEX )
 
-// Module function map
-static const LUA_REG_TYPE file_map[] = {
-  { LSTRKEY( "list" ),      LFUNCVAL( file_list ) },
-  { LSTRKEY( "open" ),      LFUNCVAL( file_open ) },
-  { LSTRKEY( "close" ),     LFUNCVAL( file_close ) },
-  { LSTRKEY( "write" ),     LFUNCVAL( file_write ) },
-  { LSTRKEY( "writeline" ), LFUNCVAL( file_writeline ) },
-  { LSTRKEY( "read" ),      LFUNCVAL( file_read ) },
-  { LSTRKEY( "readline" ),  LFUNCVAL( file_readline ) },
 #ifdef BUILD_SPIFFS
-  { LSTRKEY( "format" ),    LFUNCVAL( file_format ) },
-  { LSTRKEY( "fscfg" ),     LFUNCVAL( file_fscfg ) },
+#define LROT_FUNCENTRY_S(n,f) LROT_FUNCENTRY(n,f)
+#else
+#define LROT_FUNCENTRY_S(n,f) 
 #endif
-  { LSTRKEY( "remove" ),    LFUNCVAL( file_remove ) },
-  { LSTRKEY( "seek" ),      LFUNCVAL( file_seek ) },
-  { LSTRKEY( "flush" ),     LFUNCVAL( file_flush ) },
-  { LSTRKEY( "rename" ),    LFUNCVAL( file_rename ) },
-  { LSTRKEY( "exists" ),    LFUNCVAL( file_exists ) },
-  { LSTRKEY( "getcontents" ), LFUNCVAL( file_getfile ) },
-  { LSTRKEY( "putcontents" ), LFUNCVAL( file_putfile ) },
-  { LSTRKEY( "fsinfo" ),    LFUNCVAL( file_fsinfo ) },
-  { LSTRKEY( "on" ),        LFUNCVAL( file_on ) },
-  { LSTRKEY( "stat" ),      LFUNCVAL( file_stat ) },
 #ifdef BUILD_FATFS
-  { LSTRKEY( "mount" ),     LFUNCVAL( file_mount ) },
-  { LSTRKEY( "chdir" ),     LFUNCVAL( file_chdir ) },
+#define LROT_FUNCENTRY_F(n,f) LROT_FUNCENTRY(n,f)
+#else
+#define LROT_FUNCENTRY_F(n,f) 
 #endif
-  { LNILKEY, LNILVAL }
-};
+
+// Module function map
+LROT_BEGIN(file)
+  LROT_FUNCENTRY( list, file_list )
+  LROT_FUNCENTRY( open, file_open )
+  LROT_FUNCENTRY( close, file_close )
+  LROT_FUNCENTRY( write, file_write )
+  LROT_FUNCENTRY( writeline, file_writeline )
+  LROT_FUNCENTRY( read, file_read )
+  LROT_FUNCENTRY( readline, file_readline )
+  LROT_FUNCENTRY_S( format, file_format )
+  LROT_FUNCENTRY_S( fscfg, file_fscfg )
+  LROT_FUNCENTRY( remove, file_remove )
+  LROT_FUNCENTRY( seek, file_seek )
+  LROT_FUNCENTRY( flush, file_flush )
+  LROT_FUNCENTRY( rename, file_rename )
+  LROT_FUNCENTRY( exists, file_exists )
+  LROT_FUNCENTRY( getcontents, file_getfile )
+  LROT_FUNCENTRY( putcontents, file_putfile )
+  LROT_FUNCENTRY( fsinfo, file_fsinfo )
+  LROT_FUNCENTRY( on, file_on )
+  LROT_FUNCENTRY( stat, file_stat )
+  LROT_FUNCENTRY_F( mount, file_mount )
+  LROT_FUNCENTRY_F( chdir, file_chdir )
+LROT_END( file, NULL, 0 )
+
 
 int luaopen_file( lua_State *L ) {
-  luaL_rometatable( L, "file.vol",  (void *)file_vol_map );
-  luaL_rometatable( L, "file.obj",  (void *)file_obj_map );
+  luaL_rometatable( L, "file.vol",  LROT_TABLEREF(file_vol));
+  luaL_rometatable( L, "file.obj",  LROT_TABLEREF(file_obj));
   return 0;
 }
 
-NODEMCU_MODULE(FILE, "file", file_map, luaopen_file);
+NODEMCU_MODULE(FILE, "file", file, luaopen_file);

+ 7 - 7
app/modules/gdbstub.c

@@ -39,11 +39,11 @@ static int lgdbstub_open(lua_State *L) {
 }
 
 // Module function map
-static const LUA_REG_TYPE gdbstub_map[] = {
-  { LSTRKEY( "brk" ),    	LFUNCVAL( lgdbstub_break    ) },
-  { LSTRKEY( "gdboutput" ),    	LFUNCVAL( lgdbstub_gdboutput) },
-  { LSTRKEY( "open" ),    	LFUNCVAL( lgdbstub_open) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(gdbstub)
+  LROT_FUNCENTRY( brk, lgdbstub_break )
+  LROT_FUNCENTRY( gdboutput, lgdbstub_gdboutput )
+  LROT_FUNCENTRY( open, lgdbstub_open )
+LROT_END( gdbstub, NULL, 0 )
 
-NODEMCU_MODULE(GDBSTUB, "gdbstub", gdbstub_map, NULL);
+
+NODEMCU_MODULE(GDBSTUB, "gdbstub", gdbstub, NULL);

+ 19 - 19
app/modules/gpio.c

@@ -319,32 +319,32 @@ static int lgpio_serout( lua_State* L )
 #undef DELAY_TABLE_MAX_LEN
 
 #ifdef LUA_USE_MODULES_GPIO_PULSE
-extern const LUA_REG_TYPE gpio_pulse_map[];
+LROT_EXTERN(gpio_pulse);
 extern int gpio_pulse_init(lua_State *);
 #endif
 
 // Module function map
-static const LUA_REG_TYPE gpio_map[] = {
-  { LSTRKEY( "mode" ),   LFUNCVAL( lgpio_mode ) },
-  { LSTRKEY( "read" ),   LFUNCVAL( lgpio_read ) },
-  { LSTRKEY( "write" ),  LFUNCVAL( lgpio_write ) },
-  { LSTRKEY( "serout" ), LFUNCVAL( lgpio_serout ) },
+LROT_BEGIN(gpio)
+  LROT_FUNCENTRY( mode, lgpio_mode )
+  LROT_FUNCENTRY( read, lgpio_read )
+  LROT_FUNCENTRY( write, lgpio_write )
+  LROT_FUNCENTRY( serout, lgpio_serout )
 #ifdef LUA_USE_MODULES_GPIO_PULSE
-  { LSTRKEY( "pulse" ),  LROVAL( gpio_pulse_map ) }, //declared in gpio_pulse.c
+  LROT_TABENTRY( pulse, gpio_pulse )
 #endif
 #ifdef GPIO_INTERRUPT_ENABLE
-  { LSTRKEY( "trig" ),   LFUNCVAL( lgpio_trig ) },
-  { LSTRKEY( "INT" ),    LNUMVAL( INTERRUPT ) },
+  LROT_FUNCENTRY( trig, lgpio_trig )
+  LROT_NUMENTRY( INT, INTERRUPT )
 #endif
-  { LSTRKEY( "OUTPUT" ),    LNUMVAL( OUTPUT ) },
-  { LSTRKEY( "OPENDRAIN" ), LNUMVAL( OPENDRAIN ) },
-  { LSTRKEY( "INPUT" ),     LNUMVAL( INPUT ) },
-  { LSTRKEY( "HIGH" ),      LNUMVAL( HIGH ) },
-  { LSTRKEY( "LOW" ),       LNUMVAL( LOW ) },
-  { LSTRKEY( "FLOAT" ),     LNUMVAL( FLOAT ) },
-  { LSTRKEY( "PULLUP" ),    LNUMVAL( PULLUP ) },
-  { LNILKEY, LNILVAL }
-};
+  LROT_NUMENTRY( OUTPUT, OUTPUT )
+  LROT_NUMENTRY( OPENDRAIN, OPENDRAIN )
+  LROT_NUMENTRY( INPUT, INPUT )
+  LROT_NUMENTRY( HIGH, HIGH )
+  LROT_NUMENTRY( LOW, LOW )
+  LROT_NUMENTRY( FLOAT, FLOAT )
+  LROT_NUMENTRY( PULLUP, PULLUP )
+LROT_END( gpio, NULL, 0 )
+
 
 int luaopen_gpio( lua_State *L ) {
 #ifdef LUA_USE_MODULES_GPIO_PULSE
@@ -362,4 +362,4 @@ int luaopen_gpio( lua_State *L ) {
   return 0;
 }
 
-NODEMCU_MODULE(GPIO, "gpio", gpio_map, luaopen_gpio);
+NODEMCU_MODULE(GPIO, "gpio", gpio, luaopen_gpio);

+ 19 - 20
app/modules/gpio_pulse.c

@@ -467,31 +467,30 @@ static void gpio_pulse_task(os_param_t param, uint8_t prio)
   }
 }
 
-static const LUA_REG_TYPE pulse_map[] = {
-  { LSTRKEY( "getstate" ),            LFUNCVAL( gpio_pulse_getstate ) },
-  { LSTRKEY( "stop" ),                LFUNCVAL( gpio_pulse_stop ) },
-  { LSTRKEY( "cancel" ),              LFUNCVAL( gpio_pulse_cancel ) },
-  { LSTRKEY( "start" ),               LFUNCVAL( gpio_pulse_start ) },
-  { LSTRKEY( "adjust" ),              LFUNCVAL( gpio_pulse_adjust ) },
-  { LSTRKEY( "update" ),              LFUNCVAL( gpio_pulse_update ) },
-  { LSTRKEY( "__gc" ),                LFUNCVAL( gpio_pulse_delete ) },
-  { LSTRKEY( "__index" ),             LROVAL( pulse_map ) },
-  { LNILKEY, LNILVAL }
-};
-
-const LUA_REG_TYPE gpio_pulse_map[] =
-{
-  { LSTRKEY( "build" ),               LFUNCVAL( gpio_pulse_build ) },
-  { LSTRKEY( "__index" ),             LROVAL( gpio_pulse_map ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(pulse)
+  LROT_FUNCENTRY( getstate, gpio_pulse_getstate )
+  LROT_FUNCENTRY( stop, gpio_pulse_stop )
+  LROT_FUNCENTRY( cancel, gpio_pulse_cancel )
+  LROT_FUNCENTRY( start, gpio_pulse_start )
+  LROT_FUNCENTRY( adjust, gpio_pulse_adjust )
+  LROT_FUNCENTRY( update, gpio_pulse_update )
+  LROT_FUNCENTRY( __gc, gpio_pulse_delete )
+  LROT_TABENTRY( __index, pulse )
+LROT_END( pulse, pulse, LROT_MASK_GC_INDEX )
+
+
+LROT_PUBLIC_BEGIN(gpio_pulse)
+  LROT_FUNCENTRY( build, gpio_pulse_build )
+  LROT_TABENTRY( __index, gpio_pulse )
+LROT_END( gpio_pulse, gpio_pulse, LROT_MASK_INDEX )
+
 
 int gpio_pulse_init(lua_State *L)
 {
-  luaL_rometatable(L, "gpio.pulse", (void *)pulse_map);
+  luaL_rometatable(L, "gpio.pulse", LROT_TABLEREF(pulse));
   tasknumber = task_get_id(gpio_pulse_task);
   return 0;
 }
 
-//NODEMCU_MODULE(GPIOPULSE, "gpiopulse", gpio_pulse_map, gpio_pulse_init);
+NODEMCU_MODULE(GPIOPULSE, "gpiopulse", gpio_pulse, gpio_pulse_init);
 

+ 6 - 6
app/modules/hdc1080.c

@@ -99,10 +99,10 @@ static int hdc1080_read(lua_State* L) {
     return 2;
 }
 
-static const LUA_REG_TYPE hdc1080_map[] = {
-    { LSTRKEY( "read"  ),        LFUNCVAL( hdc1080_read )},
-    { LSTRKEY( "setup" ),        LFUNCVAL( hdc1080_setup )},
-    { LNILKEY, LNILVAL}
-};
+LROT_BEGIN(hdc1080)
+  LROT_FUNCENTRY( read, hdc1080_read )
+  LROT_FUNCENTRY( setup, hdc1080_setup )
+LROT_END( hdc1080, NULL, 0 )
 
-NODEMCU_MODULE(HDC1080, "hdc1080", hdc1080_map, NULL);
+
+NODEMCU_MODULE(HDC1080, "hdc1080", hdc1080, NULL);

+ 6 - 6
app/modules/hmc5883l.c

@@ -89,10 +89,10 @@ static int hmc5883_read(lua_State* L) {
     return 3;
 }
 
-static const LUA_REG_TYPE hmc5883_map[] = {
-    { LSTRKEY( "read" ),         LFUNCVAL( hmc5883_read )},
-    { LSTRKEY( "setup" ),        LFUNCVAL( hmc5883_setup )},
-    { LNILKEY, LNILVAL}
-};
+LROT_BEGIN(hmc5883)
+  LROT_FUNCENTRY( read, hmc5883_read )
+  LROT_FUNCENTRY( setup, hmc5883_setup )
+LROT_END( hmc5883, NULL, 0 )
 
-NODEMCU_MODULE(HMC5883L, "hmc5883l", hmc5883_map, NULL);
+
+NODEMCU_MODULE(HMC5883L, "hmc5883l", hmc5883, NULL);

+ 11 - 11
app/modules/http.c

@@ -269,17 +269,17 @@ static int http_lapi_get( lua_State *L )
 }
 
 // Module function map
-static const LUA_REG_TYPE http_map[] = {
-  { LSTRKEY( "request" ),         LFUNCVAL( http_lapi_request ) },
-  { LSTRKEY( "post" ),            LFUNCVAL( http_lapi_post ) },
-  { LSTRKEY( "put" ),             LFUNCVAL( http_lapi_put ) },
-  { LSTRKEY( "delete" ),          LFUNCVAL( http_lapi_delete ) },
-  { LSTRKEY( "get" ),             LFUNCVAL( http_lapi_get ) },
+LROT_BEGIN(http)
+  LROT_FUNCENTRY( request, http_lapi_request )
+  LROT_FUNCENTRY( post, http_lapi_post )
+  LROT_FUNCENTRY( put, http_lapi_put )
+  LROT_FUNCENTRY( delete, http_lapi_delete )
+  LROT_FUNCENTRY( get, http_lapi_get )
 
-  { LSTRKEY( "OK" ),              LNUMVAL( 0 ) },
-  { LSTRKEY( "ERROR" ),           LNUMVAL( HTTP_STATUS_GENERIC_ERROR ) },
+  LROT_NUMENTRY( OK, 0 )
+  LROT_NUMENTRY( ERROR, HTTP_STATUS_GENERIC_ERROR )
 
-  { LNILKEY, LNILVAL }
-};
+LROT_END( http, NULL, 0 )
 
-NODEMCU_MODULE(HTTP, "http", http_map, NULL);
+
+NODEMCU_MODULE(HTTP, "http", http, NULL);

+ 6 - 6
app/modules/hx711.c

@@ -66,15 +66,15 @@ static int ICACHE_FLASH_ATTR hx711_read(lua_State* L) {
 }
 
 // Module function map
-static const LUA_REG_TYPE hx711_map[] = {
-  { LSTRKEY( "init" ), LFUNCVAL( hx711_init )},
-  { LSTRKEY( "read" ), LFUNCVAL( hx711_read )},
-  { LNILKEY, LNILVAL}
-};
+LROT_BEGIN(hx711)
+  LROT_FUNCENTRY( init, hx711_init )
+  LROT_FUNCENTRY( read, hx711_read )
+LROT_END( hx711, NULL, 0 )
+
 
 int luaopen_hx711(lua_State *L) {
   // TODO: Make sure that the GPIO system is initialized
   return 0;
 }
 
-NODEMCU_MODULE(HX711, "hx711", hx711_map, luaopen_hx711);
+NODEMCU_MODULE(HX711, "hx711", hx711, luaopen_hx711);

+ 16 - 16
app/modules/i2c.c

@@ -146,19 +146,19 @@ static int i2c_read( lua_State *L )
 }
 
 // Module function map
-static const LUA_REG_TYPE i2c_map[] = {
-  { LSTRKEY( "setup" ),       LFUNCVAL( i2c_setup ) },
-  { LSTRKEY( "start" ),       LFUNCVAL( i2c_start ) },
-  { LSTRKEY( "stop" ),        LFUNCVAL( i2c_stop ) },
-  { LSTRKEY( "address" ),     LFUNCVAL( i2c_address ) },
-  { LSTRKEY( "write" ),       LFUNCVAL( i2c_write ) },
-  { LSTRKEY( "read" ),        LFUNCVAL( i2c_read ) },
-  { LSTRKEY( "FASTPLUS" ),    LNUMVAL( PLATFORM_I2C_SPEED_FASTPLUS ) },
-  { LSTRKEY( "FAST" ),        LNUMVAL( PLATFORM_I2C_SPEED_FAST ) },
-  { LSTRKEY( "SLOW" ),        LNUMVAL( PLATFORM_I2C_SPEED_SLOW ) },
-  { LSTRKEY( "TRANSMITTER" ), LNUMVAL( PLATFORM_I2C_DIRECTION_TRANSMITTER ) },
-  { LSTRKEY( "RECEIVER" ),    LNUMVAL( PLATFORM_I2C_DIRECTION_RECEIVER ) },
-  { LNILKEY, LNILVAL }
-};
-
-NODEMCU_MODULE(I2C, "i2c", i2c_map, NULL);
+LROT_BEGIN(i2c)
+  LROT_FUNCENTRY( setup, i2c_setup )
+  LROT_FUNCENTRY( start, i2c_start )
+  LROT_FUNCENTRY( stop, i2c_stop )
+  LROT_FUNCENTRY( address, i2c_address )
+  LROT_FUNCENTRY( write, i2c_write )
+  LROT_FUNCENTRY( read, i2c_read )
+  LROT_NUMENTRY( FASTPLUS, PLATFORM_I2C_SPEED_FASTPLUS )
+  LROT_NUMENTRY( FAST, PLATFORM_I2C_SPEED_FAST )
+  LROT_NUMENTRY( SLOW, PLATFORM_I2C_SPEED_SLOW )
+  LROT_NUMENTRY( TRANSMITTER, PLATFORM_I2C_DIRECTION_TRANSMITTER )
+  LROT_NUMENTRY( RECEIVER, PLATFORM_I2C_DIRECTION_RECEIVER )
+LROT_END( i2c, NULL, 0 )
+
+
+NODEMCU_MODULE(I2C, "i2c", i2c, NULL);

+ 6 - 6
app/modules/l3g4200d.c

@@ -79,10 +79,10 @@ static int l3g4200d_read(lua_State* L) {
     return 3;
 }
 
-static const LUA_REG_TYPE l3g4200d_map[] = {
-    { LSTRKEY( "read" ),         LFUNCVAL( l3g4200d_read )},
-    { LSTRKEY( "setup" ),        LFUNCVAL( l3g4200d_setup )},
-    { LNILKEY, LNILVAL}
-};
+LROT_BEGIN(l3g4200d)
+  LROT_FUNCENTRY( read, l3g4200d_read )
+  LROT_FUNCENTRY( setup, l3g4200d_setup )
+LROT_END( l3g4200d, NULL, 0 )
 
-NODEMCU_MODULE(L3G4200D, "l3g4200d", l3g4200d_map, NULL);
+
+NODEMCU_MODULE(L3G4200D, "l3g4200d", l3g4200d, NULL);

+ 11 - 11
app/modules/mcp4725.c

@@ -204,14 +204,14 @@ static int mcp4725_read(lua_State* L){
 }
 
 
-static const LUA_REG_TYPE mcp4725_map[] = {
-    { LSTRKEY( "write" ),      LFUNCVAL( mcp4725_write ) },
-    { LSTRKEY( "read" ),      LFUNCVAL( mcp4725_read ) },
-    { LSTRKEY( "PWRDN_NONE" ),    LNUMVAL(MCP4725_POWER_DOWN_NORMAL) },
-    { LSTRKEY( "PWRDN_1K" ),    LNUMVAL((MCP4725_POWER_DOWN_RES_1K)>>1) },
-    { LSTRKEY( "PWRDN_100K" ),    LNUMVAL((MCP4725_POWER_DOWN_RES_100K)>>1) },
-    { LSTRKEY( "PWRDN_500K" ),    LNUMVAL((MCP4725_POWER_DOWN_RES_500K)>>1) },
-    { LNILKEY, LNILVAL}
-};
-
-NODEMCU_MODULE(MCP4725, "mcp4725", mcp4725_map, NULL);
+LROT_BEGIN(mcp4725)
+  LROT_FUNCENTRY( write, mcp4725_write )
+  LROT_FUNCENTRY( read, mcp4725_read )
+  LROT_NUMENTRY( PWRDN_NONE, MCP4725_POWER_DOWN_NORMAL )
+  LROT_NUMENTRY( PWRDN_1K, MCP4725_POWER_DOWN_RES_1K>>1 )
+  LROT_NUMENTRY( PWRDN_100K, MCP4725_POWER_DOWN_RES_100K>>1 )
+  LROT_NUMENTRY( PWRDN_500K, MCP4725_POWER_DOWN_RES_500K>>1 )
+LROT_END( mcp4725, NULL, 0 )
+
+
+NODEMCU_MODULE(MCP4725, "mcp4725", mcp4725, NULL);

+ 6 - 6
app/modules/mdns.c

@@ -88,10 +88,10 @@ static int mdns_register(lua_State *L)
 }
 
 // Module function map
-static const LUA_REG_TYPE mdns_map[] = {
-  { LSTRKEY("register"),  LFUNCVAL(mdns_register)  },
-  { LSTRKEY("close"),     LFUNCVAL(mdns_close)     },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(mdns)
+  LROT_FUNCENTRY( register, mdns_register )
+  LROT_FUNCENTRY( close, mdns_close )
+LROT_END( mdns, NULL, 0 )
 
-NODEMCU_MODULE(MDNS, "mdns", mdns_map, NULL);
+
+NODEMCU_MODULE(MDNS, "mdns", mdns, NULL);

+ 34 - 34
app/modules/mqtt.c

@@ -1873,43 +1873,43 @@ static int mqtt_socket_lwt( lua_State* L )
 }
 
 // Module function map
-static const LUA_REG_TYPE mqtt_socket_map[] = {
-  { LSTRKEY( "connect" ),   LFUNCVAL( mqtt_socket_connect ) },
-  { LSTRKEY( "close" ),     LFUNCVAL( mqtt_socket_close ) },
-  { LSTRKEY( "publish" ),   LFUNCVAL( mqtt_socket_publish ) },
-  { LSTRKEY( "subscribe" ), LFUNCVAL( mqtt_socket_subscribe ) },
-  { LSTRKEY( "unsubscribe" ), LFUNCVAL( mqtt_socket_unsubscribe ) },
-  { LSTRKEY( "lwt" ),       LFUNCVAL( mqtt_socket_lwt ) },
-  { LSTRKEY( "on" ),        LFUNCVAL( mqtt_socket_on ) },
-  { LSTRKEY( "__gc" ),      LFUNCVAL( mqtt_delete ) },
-  { LSTRKEY( "__index" ),   LROVAL( mqtt_socket_map ) },
-  { LNILKEY, LNILVAL }
-};
-
-
-static const LUA_REG_TYPE mqtt_map[] = {
-  { LSTRKEY( "Client" ),                                LFUNCVAL( mqtt_socket_client ) },
-
-  { LSTRKEY( "CONN_FAIL_SERVER_NOT_FOUND" ),            LNUMVAL( MQTT_CONN_FAIL_SERVER_NOT_FOUND ) },
-  { LSTRKEY( "CONN_FAIL_NOT_A_CONNACK_MSG" ),           LNUMVAL( MQTT_CONN_FAIL_NOT_A_CONNACK_MSG ) },
-  { LSTRKEY( "CONN_FAIL_DNS" ),                         LNUMVAL( MQTT_CONN_FAIL_DNS ) },
-  { LSTRKEY( "CONN_FAIL_TIMEOUT_RECEIVING" ),           LNUMVAL( MQTT_CONN_FAIL_TIMEOUT_RECEIVING ) },
-  { LSTRKEY( "CONN_FAIL_TIMEOUT_SENDING" ),             LNUMVAL( MQTT_CONN_FAIL_TIMEOUT_SENDING ) },
-  { LSTRKEY( "CONNACK_ACCEPTED" ),                      LNUMVAL( MQTT_CONNACK_ACCEPTED ) },
-  { LSTRKEY( "CONNACK_REFUSED_PROTOCOL_VER" ),          LNUMVAL( MQTT_CONNACK_REFUSED_PROTOCOL_VER ) },
-  { LSTRKEY( "CONNACK_REFUSED_ID_REJECTED" ),           LNUMVAL( MQTT_CONNACK_REFUSED_ID_REJECTED ) },
-  { LSTRKEY( "CONNACK_REFUSED_SERVER_UNAVAILABLE" ),    LNUMVAL( MQTT_CONNACK_REFUSED_SERVER_UNAVAILABLE ) },
-  { LSTRKEY( "CONNACK_REFUSED_BAD_USER_OR_PASS" ),      LNUMVAL( MQTT_CONNACK_REFUSED_BAD_USER_OR_PASS ) },
-  { LSTRKEY( "CONNACK_REFUSED_NOT_AUTHORIZED" ),        LNUMVAL( MQTT_CONNACK_REFUSED_NOT_AUTHORIZED ) },
-
-  { LSTRKEY( "__metatable" ),                           LROVAL( mqtt_map ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(mqtt_socket)
+  LROT_FUNCENTRY( connect, mqtt_socket_connect )
+  LROT_FUNCENTRY( close, mqtt_socket_close )
+  LROT_FUNCENTRY( publish, mqtt_socket_publish )
+  LROT_FUNCENTRY( subscribe, mqtt_socket_subscribe )
+  LROT_FUNCENTRY( unsubscribe, mqtt_socket_unsubscribe )
+  LROT_FUNCENTRY( lwt, mqtt_socket_lwt )
+  LROT_FUNCENTRY( on, mqtt_socket_on )
+  LROT_FUNCENTRY( __gc, mqtt_delete )
+  LROT_TABENTRY( __index, mqtt_socket )
+LROT_END( mqtt_socket, mqtt_socket, 0 )
+
+
+
+LROT_BEGIN(mqtt)
+  LROT_FUNCENTRY( Client, mqtt_socket_client )
+
+  LROT_NUMENTRY( CONN_FAIL_SERVER_NOT_FOUND, MQTT_CONN_FAIL_SERVER_NOT_FOUND )
+  LROT_NUMENTRY( CONN_FAIL_NOT_A_CONNACK_MSG, MQTT_CONN_FAIL_NOT_A_CONNACK_MSG )
+  LROT_NUMENTRY( CONN_FAIL_DNS, MQTT_CONN_FAIL_DNS )
+  LROT_NUMENTRY( CONN_FAIL_TIMEOUT_RECEIVING, MQTT_CONN_FAIL_TIMEOUT_RECEIVING )
+  LROT_NUMENTRY( CONN_FAIL_TIMEOUT_SENDING, MQTT_CONN_FAIL_TIMEOUT_SENDING )
+  LROT_NUMENTRY( CONNACK_ACCEPTED, MQTT_CONNACK_ACCEPTED )
+  LROT_NUMENTRY( CONNACK_REFUSED_PROTOCOL_VER, MQTT_CONNACK_REFUSED_PROTOCOL_VER )
+  LROT_NUMENTRY( CONNACK_REFUSED_ID_REJECTED, MQTT_CONNACK_REFUSED_ID_REJECTED )
+  LROT_NUMENTRY( CONNACK_REFUSED_SERVER_UNAVAILABLE, MQTT_CONNACK_REFUSED_SERVER_UNAVAILABLE )
+  LROT_NUMENTRY( CONNACK_REFUSED_BAD_USER_OR_PASS, MQTT_CONNACK_REFUSED_BAD_USER_OR_PASS )
+  LROT_NUMENTRY( CONNACK_REFUSED_NOT_AUTHORIZED, MQTT_CONNACK_REFUSED_NOT_AUTHORIZED )
+
+  LROT_TABENTRY( __metatable, mqtt )
+LROT_END( mqtt, mqtt, 0 )
+
 
 int luaopen_mqtt( lua_State *L )
 {
-  luaL_rometatable(L, "mqtt.socket", (void *)mqtt_socket_map);  // create metatable for mqtt.socket
+  luaL_rometatable(L, "mqtt.socket", LROT_TABLEREF(mqtt_socket));
   return 0;
 }
 
-NODEMCU_MODULE(MQTT, "mqtt", mqtt_map, luaopen_mqtt);
+NODEMCU_MODULE(MQTT, "mqtt", mqtt, luaopen_mqtt);

+ 63 - 63
app/modules/net.c

@@ -968,79 +968,79 @@ static int net_getdnsserver( lua_State* L ) {
 #pragma mark - Tables
 
 #ifdef TLS_MODULE_PRESENT
-extern const LUA_REG_TYPE tls_cert_map[];
+LROT_EXTERN(tls_cert);
 #endif
 
 // Module function map
-static const LUA_REG_TYPE net_tcpserver_map[] = {
-  { LSTRKEY( "listen" ),  LFUNCVAL( net_listen ) },
-  { LSTRKEY( "getaddr" ), LFUNCVAL( net_getaddr ) },
-  { LSTRKEY( "close" ),   LFUNCVAL( net_close ) },
-  { LSTRKEY( "__gc" ),    LFUNCVAL( net_delete ) },
-  { LSTRKEY( "__index" ), LROVAL( net_tcpserver_map ) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE net_tcpsocket_map[] = {
-  { LSTRKEY( "connect" ), LFUNCVAL( net_connect ) },
-  { LSTRKEY( "close" ),   LFUNCVAL( net_close ) },
-  { LSTRKEY( "on" ),      LFUNCVAL( net_on ) },
-  { LSTRKEY( "send" ),    LFUNCVAL( net_send ) },
-  { LSTRKEY( "hold" ),    LFUNCVAL( net_hold ) },
-  { LSTRKEY( "unhold" ),  LFUNCVAL( net_unhold ) },
-  { LSTRKEY( "dns" ),     LFUNCVAL( net_dns ) },
-  { LSTRKEY( "ttl" ),     LFUNCVAL( net_ttl ) },
-  { LSTRKEY( "getpeer" ), LFUNCVAL( net_getpeer ) },
-  { LSTRKEY( "getaddr" ), LFUNCVAL( net_getaddr ) },
-  { LSTRKEY( "__gc" ),    LFUNCVAL( net_delete ) },
-  { LSTRKEY( "__index" ), LROVAL( net_tcpsocket_map ) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE net_udpsocket_map[] = {
-  { LSTRKEY( "listen" ),  LFUNCVAL( net_listen ) },
-  { LSTRKEY( "close" ),   LFUNCVAL( net_close ) },
-  { LSTRKEY( "on" ),      LFUNCVAL( net_on ) },
-  { LSTRKEY( "send" ),    LFUNCVAL( net_send ) },
-  { LSTRKEY( "dns" ),     LFUNCVAL( net_dns ) },
-  { LSTRKEY( "ttl" ),     LFUNCVAL( net_ttl ) },
-  { LSTRKEY( "getaddr" ), LFUNCVAL( net_getaddr ) },
-  { LSTRKEY( "__gc" ),    LFUNCVAL( net_delete ) },
-  { LSTRKEY( "__index" ), LROVAL( net_udpsocket_map ) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE net_dns_map[] = {
-  { LSTRKEY( "setdnsserver" ), LFUNCVAL( net_setdnsserver ) },
-  { LSTRKEY( "getdnsserver" ), LFUNCVAL( net_getdnsserver ) },
-  { LSTRKEY( "resolve" ),      LFUNCVAL( net_dns_static ) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE net_map[] = {
-  { LSTRKEY( "createServer" ),     LFUNCVAL( net_createServer ) },
-  { LSTRKEY( "createConnection" ), LFUNCVAL( net_createConnection ) },
-  { LSTRKEY( "createUDPSocket" ),  LFUNCVAL( net_createUDPSocket ) },
-  { LSTRKEY( "multicastJoin"),     LFUNCVAL( net_multicastJoin ) },
-  { LSTRKEY( "multicastLeave"),    LFUNCVAL( net_multicastLeave ) },
-  { LSTRKEY( "dns" ),              LROVAL( net_dns_map ) },
+LROT_BEGIN(net_tcpserver)
+  LROT_FUNCENTRY( listen, net_listen )
+  LROT_FUNCENTRY( getaddr, net_getaddr )
+  LROT_FUNCENTRY( close, net_close )
+  LROT_FUNCENTRY( __gc, net_delete )
+  LROT_TABENTRY( __index, net_tcpserver )
+LROT_END( net_tcpserver, net_tcpserver, 0 )
+
+
+LROT_BEGIN(net_tcpsocket)
+  LROT_FUNCENTRY( connect, net_connect )
+  LROT_FUNCENTRY( close, net_close )
+  LROT_FUNCENTRY( on, net_on )
+  LROT_FUNCENTRY( send, net_send )
+  LROT_FUNCENTRY( hold, net_hold )
+  LROT_FUNCENTRY( unhold, net_unhold )
+  LROT_FUNCENTRY( dns, net_dns )
+  LROT_FUNCENTRY( ttl, net_ttl )
+  LROT_FUNCENTRY( getpeer, net_getpeer )
+  LROT_FUNCENTRY( getaddr, net_getaddr )
+  LROT_FUNCENTRY( __gc, net_delete )
+  LROT_TABENTRY( __index, net_tcpsocket )
+LROT_END( net_tcpsocket, net_tcpsocket, 0 )
+
+
+LROT_BEGIN(net_udpsocket)
+  LROT_FUNCENTRY( listen, net_listen )
+  LROT_FUNCENTRY( close, net_close )
+  LROT_FUNCENTRY( on, net_on )
+  LROT_FUNCENTRY( send, net_send )
+  LROT_FUNCENTRY( dns, net_dns )
+  LROT_FUNCENTRY( ttl, net_ttl )
+  LROT_FUNCENTRY( getaddr, net_getaddr )
+  LROT_FUNCENTRY( __gc, net_delete )
+  LROT_TABENTRY( __index, net_udpsocket )
+LROT_END( net_udpsocket, net_udpsocket, 0 )
+
+
+LROT_BEGIN(net_dns)
+  LROT_FUNCENTRY( setdnsserver, net_setdnsserver )
+  LROT_FUNCENTRY( getdnsserver, net_getdnsserver )
+  LROT_FUNCENTRY( resolve, net_dns_static )
+LROT_END( net_dns, net_dns, 0 )
+
+
+LROT_BEGIN(net)
+  LROT_FUNCENTRY( createServer, net_createServer )
+  LROT_FUNCENTRY( createConnection, net_createConnection )
+  LROT_FUNCENTRY( createUDPSocket, net_createUDPSocket )
+  LROT_FUNCENTRY( multicastJoin, net_multicastJoin )
+  LROT_FUNCENTRY( multicastLeave, net_multicastLeave )
+  LROT_TABENTRY( dns, net_dns )
 #ifdef TLS_MODULE_PRESENT
-  { LSTRKEY( "cert" ),             LROVAL( tls_cert_map ) },
+  LROT_TABENTRY( cert, tls_cert )
 #endif
-  { LSTRKEY( "TCP" ),              LNUMVAL( TYPE_TCP ) },
-  { LSTRKEY( "UDP" ),              LNUMVAL( TYPE_UDP ) },
-  { LSTRKEY( "__metatable" ),      LROVAL( net_map ) },
-  { LNILKEY, LNILVAL }
-};
+  LROT_NUMENTRY( TCP, TYPE_TCP )
+  LROT_NUMENTRY( UDP, TYPE_UDP )
+  LROT_TABENTRY( __metatable, net )
+LROT_END( net, net, 0 )
+
 
 int luaopen_net( lua_State *L ) {
   igmp_init();
 
-  luaL_rometatable(L, NET_TABLE_TCP_SERVER, (void *)net_tcpserver_map);
-  luaL_rometatable(L, NET_TABLE_TCP_CLIENT, (void *)net_tcpsocket_map);
-  luaL_rometatable(L, NET_TABLE_UDP_SOCKET, (void *)net_udpsocket_map);
+  luaL_rometatable(L, NET_TABLE_TCP_SERVER, LROT_TABLEREF(net_tcpserver));
+  luaL_rometatable(L, NET_TABLE_TCP_CLIENT, LROT_TABLEREF(net_tcpsocket));
+  luaL_rometatable(L, NET_TABLE_UDP_SOCKET, LROT_TABLEREF(net_udpsocket));
 
   return 0;
 }
 
-NODEMCU_MODULE(NET, "net", net_map, luaopen_net);
+NODEMCU_MODULE(NET, "net", net, luaopen_net);

+ 58 - 61
app/modules/node.c

@@ -15,7 +15,6 @@
 #include "lundump.h"
 
 #include "platform.h"
-#include "lrodefs.h"
 #include "lflash.h"
 #include "c_types.h"
 #include "c_string.h"
@@ -593,13 +592,13 @@ static int node_writercr (lua_State *L) {
 
 typedef enum pt_t { lfs_addr=0, lfs_size, spiffs_addr, spiffs_size, max_pt} pt_t;
 
-static const LUA_REG_TYPE pt_map[] = {
-  { LSTRKEY( "lfs_addr" ),    LNUMVAL( lfs_addr ) },
-  { LSTRKEY( "lfs_size" ),    LNUMVAL( lfs_size ) },
-  { LSTRKEY( "spiffs_addr" ), LNUMVAL( spiffs_addr ) },
-  { LSTRKEY( "spiffs_size" ), LNUMVAL( spiffs_size ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(pt)
+  LROT_NUMENTRY( lfs_addr, lfs_addr )
+  LROT_NUMENTRY( lfs_size, lfs_size )
+  LROT_NUMENTRY( spiffs_addr, spiffs_addr )
+  LROT_NUMENTRY( spiffs_size, spiffs_size )
+LROT_END( pt, NULL, 0 )
+
 
 // Lua: ptinfo = node.getpartitiontable()
 static int node_getpartitiontable (lua_State *L) {
@@ -745,69 +744,67 @@ static int node_setpartitiontable (lua_State *L) {
 
 // Module function map
 
-static const LUA_REG_TYPE node_egc_map[] = {
-  { LSTRKEY( "meminfo" ),           LFUNCVAL( node_egc_meminfo ) },
-  { LSTRKEY( "setmode" ),           LFUNCVAL( node_egc_setmode ) },
-  { LSTRKEY( "NOT_ACTIVE" ),        LNUMVAL( EGC_NOT_ACTIVE ) },
-  { LSTRKEY( "ON_ALLOC_FAILURE" ),  LNUMVAL( EGC_ON_ALLOC_FAILURE ) },
-  { LSTRKEY( "ON_MEM_LIMIT" ),      LNUMVAL( EGC_ON_MEM_LIMIT ) },
-  { LSTRKEY( "ALWAYS" ),            LNUMVAL( EGC_ALWAYS ) },
-  { LNILKEY, LNILVAL }
-};
-static const LUA_REG_TYPE node_task_map[] = {
-  { LSTRKEY( "post" ),            LFUNCVAL( node_task_post ) },
-  { LSTRKEY( "LOW_PRIORITY" ),    LNUMVAL( TASK_PRIORITY_LOW ) },
-  { LSTRKEY( "MEDIUM_PRIORITY" ), LNUMVAL( TASK_PRIORITY_MEDIUM ) },
-  { LSTRKEY( "HIGH_PRIORITY" ),   LNUMVAL( TASK_PRIORITY_HIGH ) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE node_map[] =
-{
-  { LSTRKEY( "heap" ), LFUNCVAL( node_heap ) },
-  { LSTRKEY( "info" ), LFUNCVAL( node_info ) },
-  { LSTRKEY( "task" ), LROVAL( node_task_map ) },
-  { LSTRKEY( "flashreload" ), LFUNCVAL( luaN_reload_reboot ) },
-  { LSTRKEY( "flashindex" ), LFUNCVAL( luaN_index ) },
-  { LSTRKEY( "restart" ),   LFUNCVAL( node_restart ) },
-  { LSTRKEY( "dsleep" ),    LFUNCVAL( node_deepsleep ) },
-  { LSTRKEY( "dsleepMax" ), LFUNCVAL( dsleepMax ) },
-  { LSTRKEY( "sleep" ), LFUNCVAL( node_sleep ) },
+LROT_BEGIN(node_egc)
+  LROT_FUNCENTRY( meminfo, node_egc_meminfo )
+  LROT_FUNCENTRY( setmode, node_egc_setmode )
+  LROT_NUMENTRY( NOT_ACTIVE, EGC_NOT_ACTIVE )
+  LROT_NUMENTRY( ON_ALLOC_FAILURE, EGC_ON_ALLOC_FAILURE )
+  LROT_NUMENTRY( ON_MEM_LIMIT, EGC_ON_MEM_LIMIT )
+  LROT_NUMENTRY( ALWAYS, EGC_ALWAYS )
+LROT_END( node_egc, NULL, 0 )
+
+LROT_BEGIN(node_task)
+  LROT_FUNCENTRY( post, node_task_post )
+  LROT_NUMENTRY( LOW_PRIORITY, TASK_PRIORITY_LOW )
+  LROT_NUMENTRY( MEDIUM_PRIORITY, TASK_PRIORITY_MEDIUM )
+  LROT_NUMENTRY( HIGH_PRIORITY, TASK_PRIORITY_HIGH )
+LROT_END( node_task, NULL, 0 )
+
+LROT_BEGIN(node)
+  LROT_FUNCENTRY( heap, node_heap )
+  LROT_FUNCENTRY( info, node_info )
+  LROT_TABENTRY( task, node_task )
+  LROT_FUNCENTRY( flashreload, luaN_reload_reboot )
+  LROT_FUNCENTRY( flashindex, luaN_index )
+  LROT_FUNCENTRY( restart, node_restart )
+  LROT_FUNCENTRY( dsleep, node_deepsleep )
+  LROT_FUNCENTRY( dsleepMax, dsleepMax )
+  LROT_FUNCENTRY( sleep, node_sleep )
 #ifdef PMSLEEP_ENABLE
   PMSLEEP_INT_MAP,
 #endif
 #ifdef DEVELOPMENT_TOOLS
-  { LSTRKEY( "readrcr" ), LFUNCVAL( node_readrcr ) },
-  { LSTRKEY( "writercr" ), LFUNCVAL( node_writercr ) },
+  LROT_FUNCENTRY( readrcr, node_readrcr )
+  LROT_FUNCENTRY( writercr, node_writercr )
 #endif
-  { LSTRKEY( "chipid" ), LFUNCVAL( node_chipid ) },
-  { LSTRKEY( "flashid" ), LFUNCVAL( node_flashid ) },
-  { LSTRKEY( "flashsize" ), LFUNCVAL( node_flashsize) },
-  { LSTRKEY( "input" ), LFUNCVAL( node_input ) },
-  { LSTRKEY( "output" ), LFUNCVAL( node_output ) },
+  LROT_FUNCENTRY( chipid, node_chipid )
+  LROT_FUNCENTRY( flashid, node_flashid )
+  LROT_FUNCENTRY( flashsize, node_flashsize )
+  LROT_FUNCENTRY( input, node_input )
+  LROT_FUNCENTRY( output, node_output )
 // Moved to adc module, use adc.readvdd33()
-// { LSTRKEY( "readvdd33" ), LFUNCVAL( node_readvdd33) },
-  { LSTRKEY( "compile" ), LFUNCVAL( node_compile) },
-  { LSTRKEY( "CPU80MHZ" ), LNUMVAL( CPU80MHZ ) },
-  { LSTRKEY( "CPU160MHZ" ), LNUMVAL( CPU160MHZ ) },
-  { LSTRKEY( "setcpufreq" ), LFUNCVAL( node_setcpufreq) },
-  { LSTRKEY( "getcpufreq" ), LFUNCVAL( node_getcpufreq) },
-  { LSTRKEY( "bootreason" ), LFUNCVAL( node_bootreason) },
-  { LSTRKEY( "restore" ), LFUNCVAL( node_restore) },
-  { LSTRKEY( "random" ), LFUNCVAL( node_random) },
+//  LROT_FUNCENTRY( readvdd33, node_readvdd33 )
+  LROT_FUNCENTRY( compile, node_compile )
+  LROT_NUMENTRY( CPU80MHZ, CPU80MHZ )
+  LROT_NUMENTRY( CPU160MHZ, CPU160MHZ )
+  LROT_FUNCENTRY( setcpufreq, node_setcpufreq )
+  LROT_FUNCENTRY( getcpufreq, node_getcpufreq )
+  LROT_FUNCENTRY( bootreason, node_bootreason )
+  LROT_FUNCENTRY( restore, node_restore )
+  LROT_FUNCENTRY( random, node_random )
 #ifdef LUA_OPTIMIZE_DEBUG
-  { LSTRKEY( "stripdebug" ), LFUNCVAL( node_stripdebug ) },
+  LROT_FUNCENTRY( stripdebug, node_stripdebug )
 #endif
-  { LSTRKEY( "egc" ),  LROVAL( node_egc_map ) },
+  LROT_TABENTRY( egc, node_egc )
 #ifdef DEVELOPMENT_TOOLS
-  { LSTRKEY( "osprint" ), LFUNCVAL( node_osprint ) },
+  LROT_FUNCENTRY( osprint, node_osprint )
 #endif
-  { LSTRKEY( "getpartitiontable" ), LFUNCVAL( node_getpartitiontable ) },
-  { LSTRKEY( "setpartitiontable" ), LFUNCVAL( node_setpartitiontable ) },
+  LROT_FUNCENTRY( getpartitiontable, node_getpartitiontable )
+  LROT_FUNCENTRY( setpartitiontable, node_setpartitiontable )
 
 // Combined to dsleep(us, option)
-// { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) },
-  { LNILKEY, LNILVAL }
-};
+//  LROT_FUNCENTRY( dsleepsetoption, node_deepsleep_setoption )
+LROT_END( node, NULL, 0 )
+
 
-NODEMCU_MODULE(NODE, "node", node_map, NULL);
+NODEMCU_MODULE(NODE, "node", node, NULL);

+ 19 - 19
app/modules/ow.c

@@ -282,29 +282,29 @@ static int ow_crc16( lua_State *L )
 #endif
 
 // Module function map
-static const LUA_REG_TYPE ow_map[] = {
-  { LSTRKEY( "setup" ),         LFUNCVAL( ow_setup ) },
-  { LSTRKEY( "reset" ),         LFUNCVAL( ow_reset ) },
-  { LSTRKEY( "skip" ),          LFUNCVAL( ow_skip ) },
-  { LSTRKEY( "select" ),        LFUNCVAL( ow_select ) },
-  { LSTRKEY( "write" ),         LFUNCVAL( ow_write ) },
-  { LSTRKEY( "write_bytes" ),   LFUNCVAL( ow_write_bytes ) },
-  { LSTRKEY( "read" ),          LFUNCVAL( ow_read ) },
-  { LSTRKEY( "read_bytes" ),    LFUNCVAL( ow_read_bytes ) },
-  { LSTRKEY( "depower" ),       LFUNCVAL( ow_depower ) },
+LROT_BEGIN(ow)
+  LROT_FUNCENTRY( setup, ow_setup )
+  LROT_FUNCENTRY( reset, ow_reset )
+  LROT_FUNCENTRY( skip, ow_skip )
+  LROT_FUNCENTRY( select, ow_select )
+  LROT_FUNCENTRY( write, ow_write )
+  LROT_FUNCENTRY( write_bytes, ow_write_bytes )
+  LROT_FUNCENTRY( read, ow_read )
+  LROT_FUNCENTRY( read_bytes, ow_read_bytes )
+  LROT_FUNCENTRY( depower, ow_depower )
 #if ONEWIRE_SEARCH
-  { LSTRKEY( "reset_search" ),  LFUNCVAL( ow_reset_search ) },
-  { LSTRKEY( "target_search" ), LFUNCVAL( ow_target_search ) },
-  { LSTRKEY( "search" ),        LFUNCVAL( ow_search ) },
+  LROT_FUNCENTRY( reset_search, ow_reset_search )
+  LROT_FUNCENTRY( target_search, ow_target_search )
+  LROT_FUNCENTRY( search, ow_search )
 #endif
 #if ONEWIRE_CRC
-  { LSTRKEY( "crc8" ),          LFUNCVAL( ow_crc8 ) },
+  LROT_FUNCENTRY( crc8, ow_crc8 )
 #if ONEWIRE_CRC16
-  { LSTRKEY( "check_crc16" ),   LFUNCVAL( ow_check_crc16 ) },
-  { LSTRKEY( "crc16" ),         LFUNCVAL( ow_crc16 ) },
+  LROT_FUNCENTRY( check_crc16, ow_check_crc16 )
+  LROT_FUNCENTRY( crc16, ow_crc16 )
 #endif
 #endif
-  { LNILKEY, LNILVAL }
-};
+LROT_END( ow, NULL, 0 )
 
-NODEMCU_MODULE(OW, "ow", ow_map, NULL);
+
+NODEMCU_MODULE(OW, "ow", ow, NULL);

+ 25 - 25
app/modules/pcm.c

@@ -229,34 +229,34 @@ static int pcm_new( lua_State *L )
 }
 
 
-static const LUA_REG_TYPE pcm_driver_map[] = {
-  { LSTRKEY( "play" ),    LFUNCVAL( pcm_drv_play ) },
-  { LSTRKEY( "pause" ),   LFUNCVAL( pcm_drv_pause ) },
-  { LSTRKEY( "stop" ),    LFUNCVAL( pcm_drv_stop ) },
-  { LSTRKEY( "close" ),   LFUNCVAL( pcm_drv_close ) },
-  { LSTRKEY( "on" ),      LFUNCVAL( pcm_drv_on ) },
-  { LSTRKEY( "__gc" ),    LFUNCVAL( pcm_drv_free ) },
-  { LSTRKEY( "__index" ), LROVAL( pcm_driver_map ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(pcm_driver)
+  LROT_FUNCENTRY( play, pcm_drv_play )
+  LROT_FUNCENTRY( pause, pcm_drv_pause )
+  LROT_FUNCENTRY( stop, pcm_drv_stop )
+  LROT_FUNCENTRY( close, pcm_drv_close )
+  LROT_FUNCENTRY( on, pcm_drv_on )
+  LROT_FUNCENTRY( __gc, pcm_drv_free )
+  LROT_TABENTRY( __index, pcm_driver )
+LROT_END( pcm_driver, pcm_driver, LROT_MASK_GC_INDEX )
+
 
 // Module function map
-static const LUA_REG_TYPE pcm_map[] = {
-  { LSTRKEY( "new" ),      LFUNCVAL( pcm_new ) },
-  { LSTRKEY( "SD" ),       LNUMVAL( PCM_DRIVER_SD ) },
-  { LSTRKEY( "RATE_1K" ),  LNUMVAL( PCM_RATE_1K ) },
-  { LSTRKEY( "RATE_2K" ),  LNUMVAL( PCM_RATE_2K ) },
-  { LSTRKEY( "RATE_4K" ),  LNUMVAL( PCM_RATE_4K ) },
-  { LSTRKEY( "RATE_5K" ),  LNUMVAL( PCM_RATE_5K ) },
-  { LSTRKEY( "RATE_8K" ),  LNUMVAL( PCM_RATE_8K ) },
-  { LSTRKEY( "RATE_10K" ), LNUMVAL( PCM_RATE_10K ) },
-  { LSTRKEY( "RATE_12K" ), LNUMVAL( PCM_RATE_12K ) },
-  { LSTRKEY( "RATE_16K" ), LNUMVAL( PCM_RATE_16K ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(pcm)
+  LROT_FUNCENTRY( new, pcm_new )
+  LROT_NUMENTRY( SD, PCM_DRIVER_SD )
+  LROT_NUMENTRY( RATE_1K, PCM_RATE_1K )
+  LROT_NUMENTRY( RATE_2K, PCM_RATE_2K )
+  LROT_NUMENTRY( RATE_4K, PCM_RATE_4K )
+  LROT_NUMENTRY( RATE_5K, PCM_RATE_5K )
+  LROT_NUMENTRY( RATE_8K, PCM_RATE_8K )
+  LROT_NUMENTRY( RATE_10K, PCM_RATE_10K )
+  LROT_NUMENTRY( RATE_12K, PCM_RATE_12K )
+  LROT_NUMENTRY( RATE_16K, PCM_RATE_16K )
+LROT_END( pcm, NULL, 0 )
+
 
 int luaopen_pcm( lua_State *L ) {
-  luaL_rometatable( L, "pcm.driver", (void *)pcm_driver_map );  // create metatable
+  luaL_rometatable( L, "pcm.driver", LROT_TABLEREF(pcm_driver));
 
   pcm_data_vu_task    = task_get_id( pcm_data_vu );
   pcm_data_play_task  = task_get_id( pcm_data_play );
@@ -264,4 +264,4 @@ int luaopen_pcm( lua_State *L ) {
   return 0;
 }
 
-NODEMCU_MODULE(PCM, "pcm", pcm_map, luaopen_pcm);
+NODEMCU_MODULE(PCM, "pcm", pcm, luaopen_pcm);

+ 6 - 6
app/modules/perf.c

@@ -135,10 +135,10 @@ static int perf_stop(lua_State *L)
   return 4;
 }
 
-static const LUA_REG_TYPE perf_map[] = {
-  { LSTRKEY( "start" ),   LFUNCVAL( perf_start ) },
-  { LSTRKEY( "stop" ),    LFUNCVAL( perf_stop ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(perf)
+  LROT_FUNCENTRY( start, perf_start )
+  LROT_FUNCENTRY( stop, perf_stop )
+LROT_END( perf, NULL, 0 )
 
-NODEMCU_MODULE(PERF, "perf", perf_map, NULL);
+
+NODEMCU_MODULE(PERF, "perf", perf, NULL);

+ 13 - 13
app/modules/pwm.c

@@ -128,16 +128,16 @@ int lpwm_open( lua_State *L ) {
 }
 
 // Module function map
-static const LUA_REG_TYPE pwm_map[] = {
-  { LSTRKEY( "setup" ),    LFUNCVAL( lpwm_setup ) },
-  { LSTRKEY( "close" ),    LFUNCVAL( lpwm_close ) },
-  { LSTRKEY( "start" ),    LFUNCVAL( lpwm_start ) },
-  { LSTRKEY( "stop" ),     LFUNCVAL( lpwm_stop ) },
-  { LSTRKEY( "setclock" ), LFUNCVAL( lpwm_setclock ) },
-  { LSTRKEY( "getclock" ), LFUNCVAL( lpwm_getclock ) },
-  { LSTRKEY( "setduty" ),  LFUNCVAL( lpwm_setduty ) },
-  { LSTRKEY( "getduty" ),  LFUNCVAL( lpwm_getduty ) },
-  { LNILKEY, LNILVAL }
-};
-
-NODEMCU_MODULE(PWM, "pwm", pwm_map, lpwm_open);
+LROT_BEGIN(pwm)
+  LROT_FUNCENTRY( setup, lpwm_setup )
+  LROT_FUNCENTRY( close, lpwm_close )
+  LROT_FUNCENTRY( start, lpwm_start )
+  LROT_FUNCENTRY( stop, lpwm_stop )
+  LROT_FUNCENTRY( setclock, lpwm_setclock )
+  LROT_FUNCENTRY( getclock, lpwm_getclock )
+  LROT_FUNCENTRY( setduty, lpwm_setduty )
+  LROT_FUNCENTRY( getduty, lpwm_getduty )
+LROT_END( pwm, NULL, 0 )
+
+
+NODEMCU_MODULE(PWM, "pwm", pwm, lpwm_open);

+ 5 - 5
app/modules/rc.c

@@ -81,14 +81,14 @@ static int ICACHE_FLASH_ATTR rc_send(lua_State* L) {
 }
 
 // Module function map
-static const LUA_REG_TYPE rc_map[] = {
-  { LSTRKEY( "send" ), LFUNCVAL( rc_send )},
-  { LNILKEY, LNILVAL}
-};
+LROT_BEGIN(rc)
+  LROT_FUNCENTRY( send, rc_send )
+LROT_END( rc, NULL, 0 )
+
 
 int luaopen_rc(lua_State *L) {
   // TODO: Make sure that the GPIO system is initialized
   return 0;
 }
 
-NODEMCU_MODULE(RC, "rc", rc_map, luaopen_rc);
+NODEMCU_MODULE(RC, "rc", rc, luaopen_rc);

+ 5 - 6
app/modules/rfswitch.c

@@ -102,10 +102,9 @@ static int rfswitch_send( lua_State *L )
 }
 
 // Module function map
-static const LUA_REG_TYPE rfswitch_map[] =
-{
-  { LSTRKEY( "send" ),       LFUNCVAL( rfswitch_send ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(rfswitch)
+  LROT_FUNCENTRY( send, rfswitch_send )
+LROT_END( rfswitch, NULL, 0 )
+
 
-NODEMCU_MODULE(RFSWITCH, "rfswitch", rfswitch_map, NULL);
+NODEMCU_MODULE(RFSWITCH, "rfswitch", rfswitch, NULL);

+ 17 - 17
app/modules/rotary.c

@@ -395,20 +395,20 @@ static int rotary_open(lua_State *L)
 }
 
 // Module function map
-static const LUA_REG_TYPE rotary_map[] = {
-  { LSTRKEY( "setup" ),    LFUNCVAL( lrotary_setup ) },
-  { LSTRKEY( "close" ),    LFUNCVAL( lrotary_close ) },
-  { LSTRKEY( "on" ),       LFUNCVAL( lrotary_on    ) },
-  { LSTRKEY( "getpos" ),   LFUNCVAL( lrotary_getpos) },
-  { LSTRKEY( "TURN" ),     LNUMVAL( MASK(TURN)    ) },
-  { LSTRKEY( "PRESS" ),    LNUMVAL( MASK(PRESS)   ) },
-  { LSTRKEY( "RELEASE" ),  LNUMVAL( MASK(RELEASE) ) },
-  { LSTRKEY( "LONGPRESS" ),LNUMVAL( MASK(LONGPRESS) ) },
-  { LSTRKEY( "CLICK" ),    LNUMVAL( MASK(CLICK)   ) },
-  { LSTRKEY( "DBLCLICK" ), LNUMVAL( MASK(DBLCLICK)) },
-  { LSTRKEY( "ALL" ),      LNUMVAL( ROTARY_ALL     ) },
-
-  { LNILKEY, LNILVAL }
-};
-
-NODEMCU_MODULE(ROTARY, "rotary", rotary_map, rotary_open);
+LROT_BEGIN(rotary)
+  LROT_FUNCENTRY( setup, lrotary_setup )
+  LROT_FUNCENTRY( close, lrotary_close )
+  LROT_FUNCENTRY( on, lrotary_on )
+  LROT_FUNCENTRY( getpos, lrotary_getpos )
+  LROT_NUMENTRY( TURN, MASK(TURN) )
+  LROT_NUMENTRY( PRESS, MASK(PRESS) )
+  LROT_NUMENTRY( RELEASE, MASK(RELEASE) )
+  LROT_NUMENTRY( LONGPRESS, MASK(LONGPRESS) )
+  LROT_NUMENTRY( CLICK, MASK(CLICK) )
+  LROT_NUMENTRY( DBLCLICK, MASK(DBLCLICK) )
+  LROT_NUMENTRY( ALL, ROTARY_ALL )
+
+LROT_END( rotary, NULL, 0 )
+
+
+NODEMCU_MODULE(ROTARY, "rotary", rotary, rotary_open);

+ 12 - 12
app/modules/rtcfifo.c

@@ -165,18 +165,18 @@ static int rtcfifo_dsleep_until_sample (lua_State *L)
 #endif
 
 // Module function map
-static const LUA_REG_TYPE rtcfifo_map[] = {
-  { LSTRKEY("prepare"),             LFUNCVAL(rtcfifo_prepare) },
-  { LSTRKEY("ready"),               LFUNCVAL(rtcfifo_ready) },
-  { LSTRKEY("put"),                 LFUNCVAL(rtcfifo_put) },
-  { LSTRKEY("pop"),                 LFUNCVAL(rtcfifo_pop) },
-  { LSTRKEY("peek"),                LFUNCVAL(rtcfifo_peek) },
-  { LSTRKEY("drop"),                LFUNCVAL(rtcfifo_drop) },
-  { LSTRKEY("count"),               LFUNCVAL(rtcfifo_count) },
+LROT_BEGIN(rtcfifo)
+  LROT_FUNCENTRY( prepare, rtcfifo_prepare )
+  LROT_FUNCENTRY( ready, rtcfifo_ready )
+  LROT_FUNCENTRY( put, rtcfifo_put )
+  LROT_FUNCENTRY( pop, rtcfifo_pop )
+  LROT_FUNCENTRY( peek, rtcfifo_peek )
+  LROT_FUNCENTRY( drop, rtcfifo_drop )
+  LROT_FUNCENTRY( count, rtcfifo_count )
 #ifdef LUA_USE_MODULES_RTCTIME
-  { LSTRKEY("dsleep_until_sample"), LFUNCVAL(rtcfifo_dsleep_until_sample) },
+  LROT_FUNCENTRY( dsleep_until_sample, rtcfifo_dsleep_until_sample )
 #endif
-  { LNILKEY, LNILVAL }
-};
+LROT_END( rtcfifo, NULL, 0 )
 
-NODEMCU_MODULE(RTCFIFO, "rtcfifo", rtcfifo_map, NULL);
+
+NODEMCU_MODULE(RTCFIFO, "rtcfifo", rtcfifo, NULL);

+ 6 - 6
app/modules/rtcmem.c

@@ -41,10 +41,10 @@ static int rtcmem_write32 (lua_State *L)
 
 
 // Module function map
-static const LUA_REG_TYPE rtcmem_map[] = {
-  { LSTRKEY("read32"),  LFUNCVAL(rtcmem_read32)  },
-  { LSTRKEY("write32"), LFUNCVAL(rtcmem_write32) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(rtcmem)
+  LROT_FUNCENTRY( read32, rtcmem_read32 )
+  LROT_FUNCENTRY( write32, rtcmem_write32 )
+LROT_END( rtcmem, NULL, 0 )
 
-NODEMCU_MODULE(RTCMEM, "rtcmem", rtcmem_map, NULL);
+
+NODEMCU_MODULE(RTCMEM, "rtcmem", rtcmem, NULL);

+ 11 - 11
app/modules/rtctime.c

@@ -228,14 +228,14 @@ static int rtctime_epoch2cal (lua_State *L)
 }
 
 // Module function map
-static const LUA_REG_TYPE rtctime_map[] = {
-  { LSTRKEY("set"),            LFUNCVAL(rtctime_set) },
-  { LSTRKEY("get"),            LFUNCVAL(rtctime_get) },
-  { LSTRKEY("adjust_delta"),   LFUNCVAL(rtctime_adjust_delta) },
-  { LSTRKEY("dsleep"),         LFUNCVAL(rtctime_dsleep)  },
-  { LSTRKEY("dsleep_aligned"), LFUNCVAL(rtctime_dsleep_aligned) },
-  { LSTRKEY("epoch2cal"),      LFUNCVAL(rtctime_epoch2cal) },
-  { LNILKEY, LNILVAL }
-};
-
-NODEMCU_MODULE(RTCTIME, "rtctime", rtctime_map, NULL);
+LROT_BEGIN(rtctime)
+  LROT_FUNCENTRY( set, rtctime_set )
+  LROT_FUNCENTRY( get, rtctime_get )
+  LROT_FUNCENTRY( adjust_delta, rtctime_adjust_delta )
+  LROT_FUNCENTRY( dsleep, rtctime_dsleep )
+  LROT_FUNCENTRY( dsleep_aligned, rtctime_dsleep_aligned )
+  LROT_FUNCENTRY( epoch2cal, rtctime_epoch2cal )
+LROT_END( rtctime, NULL, 0 )
+
+
+NODEMCU_MODULE(RTCTIME, "rtctime", rtctime, NULL);

+ 16 - 16
app/modules/si7021.c

@@ -247,19 +247,19 @@ static int si7021_lua_firmware(lua_State* L) {
 	return 1;
 }
 
-static const LUA_REG_TYPE si7021_map[] = {
-	{	LSTRKEY( "setup" ),				LFUNCVAL(si7021_lua_setup)		},
-	{	LSTRKEY( "setting" ),			LFUNCVAL(si7021_lua_setting)	},
-	{	LSTRKEY( "read" ),				LFUNCVAL(si7021_lua_read)		},
-	{	LSTRKEY( "serial" ),			LFUNCVAL(si7021_lua_serial)		},
-	{	LSTRKEY( "firmware" ),			LFUNCVAL(si7021_lua_firmware)	},
-	{	LSTRKEY( "RH12_TEMP14" ),		LNUMVAL(SI7021_RH12_TEMP14)		},
-	{	LSTRKEY( "RH08_TEMP12" ),		LNUMVAL(SI7021_RH08_TEMP12)		},
-	{	LSTRKEY( "RH10_TEMP13" ),		LNUMVAL(SI7021_RH10_TEMP13)		},
-	{	LSTRKEY( "RH11_TEMP11" ),		LNUMVAL(SI7021_RH11_TEMP11)		},
-	{	LSTRKEY( "HEATER_ENABLE" ),		LNUMVAL(SI7021_HEATER_ENABLE)	},
-	{	LSTRKEY( "HEATER_DISABLE" ),	LNUMVAL(SI7021_HEATER_DISABLE)	},
-	{	LNILKEY, LNILVAL												}
-};
-
-NODEMCU_MODULE(SI7021, "si7021", si7021_map, NULL);
+LROT_BEGIN(si7021)
+  LROT_FUNCENTRY( setup, si7021_lua_setup )
+  LROT_FUNCENTRY( setting, si7021_lua_setting )
+  LROT_FUNCENTRY( read, si7021_lua_read )
+  LROT_FUNCENTRY( serial, si7021_lua_serial )
+  LROT_FUNCENTRY( firmware, si7021_lua_firmware )
+  LROT_NUMENTRY( RH12_TEMP14, SI7021_RH12_TEMP14 )
+  LROT_NUMENTRY( RH08_TEMP12, SI7021_RH08_TEMP12 )
+  LROT_NUMENTRY( RH10_TEMP13, SI7021_RH10_TEMP13 )
+  LROT_NUMENTRY( RH11_TEMP11, SI7021_RH11_TEMP11 )
+  LROT_NUMENTRY( HEATER_ENABLE, SI7021_HEATER_ENABLE )
+  LROT_NUMENTRY( HEATER_DISABLE, SI7021_HEATER_DISABLE )
+LROT_END( si7021, NULL, 0 )
+
+
+NODEMCU_MODULE(SI7021, "si7021", si7021, NULL);

+ 10 - 11
app/modules/sigma_delta.c

@@ -74,14 +74,13 @@ static int sigma_delta_settarget( lua_State *L )
 
 
 // Module function map
-static const LUA_REG_TYPE sigma_delta_map[] =
-{
-    { LSTRKEY( "setup" ),       LFUNCVAL( sigma_delta_setup ) },
-    { LSTRKEY( "close" ),       LFUNCVAL( sigma_delta_close ) },
-    { LSTRKEY( "setpwmduty" ),  LFUNCVAL( sigma_delta_setpwmduty ) },
-    { LSTRKEY( "setprescale" ), LFUNCVAL( sigma_delta_setprescale ) },
-    { LSTRKEY( "settarget" ),   LFUNCVAL( sigma_delta_settarget ) },
-    { LNILKEY, LNILVAL }
-};
-
-NODEMCU_MODULE(SIGMA_DELTA, "sigma_delta", sigma_delta_map, NULL);
+LROT_BEGIN(sigma_delta)
+  LROT_FUNCENTRY( setup, sigma_delta_setup )
+  LROT_FUNCENTRY( close, sigma_delta_close )
+  LROT_FUNCENTRY( setpwmduty, sigma_delta_setpwmduty )
+  LROT_FUNCENTRY( setprescale, sigma_delta_setprescale )
+  LROT_FUNCENTRY( settarget, sigma_delta_settarget )
+LROT_END( sigma_delta, NULL, 0 )
+
+
+NODEMCU_MODULE(SIGMA_DELTA, "sigma_delta", sigma_delta, NULL);

+ 25 - 66
app/modules/sjson.c

@@ -992,74 +992,33 @@ static int sjson_encoder_destructor(lua_State *L) {
   return 0;
 }
 
-#ifdef LOCAL_LUA
-static const luaL_Reg sjson_encoder_map[] = {
-  { "read", sjson_encoder_read },
-  { "__gc", sjson_encoder_destructor },
-  { NULL, NULL }
-};
-
-static const luaL_Reg sjson_decoder_map[] = {
-  { "write", sjson_decoder_write },
-  { "result", sjson_decoder_result },
-  { "__gc", sjson_decoder_destructor },
-  { NULL, NULL }
-};
-
-static const luaL_Reg sjsonlib[] = {
-  { "decode", sjson_decode },
-  { "decoder", sjson_decoder },
-  { "encode", sjson_encode },
-  { "encoder", sjson_encoder },
-  {NULL, NULL}
-};
-#else
-static const LUA_REG_TYPE sjson_encoder_map[] = {
-  { LSTRKEY( "read" ),                    LFUNCVAL( sjson_encoder_read ) },
-  { LSTRKEY( "__gc" ),                    LFUNCVAL( sjson_encoder_destructor ) },
-  { LSTRKEY( "__index" ),                 LROVAL( sjson_encoder_map ) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE sjson_decoder_map[] = {
-  { LSTRKEY( "write" ),                   LFUNCVAL( sjson_decoder_write ) },
-  { LSTRKEY( "result" ),                  LFUNCVAL( sjson_decoder_result ) },
-  { LSTRKEY( "__gc" ),                    LFUNCVAL( sjson_decoder_destructor ) },
-  { LSTRKEY( "__index" ),                 LROVAL( sjson_decoder_map ) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE sjson_map[] = {
-  { LSTRKEY( "encode" ),                  LFUNCVAL( sjson_encode ) },
-  { LSTRKEY( "decode" ),                  LFUNCVAL( sjson_decode ) },
-  { LSTRKEY( "encoder" ),                 LFUNCVAL( sjson_encoder ) },
-  { LSTRKEY( "decoder" ),                 LFUNCVAL( sjson_decoder ) },
-  { LSTRKEY( "NULL" ),                    LUDATA( 0 ) },
-  { LNILKEY, LNILVAL }
-};
-#endif
+LROT_BEGIN(sjson_encoder)
+  LROT_FUNCENTRY( read, sjson_encoder_read )
+  LROT_FUNCENTRY( __gc, sjson_encoder_destructor )
+  LROT_TABENTRY( __index, sjson_encoder )
+LROT_END( sjson_encoder, sjson_encoder, LROT_MASK_GC_INDEX )
+
+
+LROT_BEGIN(sjson_decoder)
+  LROT_FUNCENTRY( write, sjson_decoder_write )
+  LROT_FUNCENTRY( result, sjson_decoder_result )
+  LROT_FUNCENTRY( __gc, sjson_decoder_destructor )
+  LROT_TABENTRY( __index, sjson_decoder )
+LROT_END( sjson_decoder, sjson_decoder, LROT_MASK_GC_INDEX )
+
+
+LROT_BEGIN(sjson)
+  LROT_FUNCENTRY( encode, sjson_encode )
+  LROT_FUNCENTRY( decode, sjson_decode )
+  LROT_FUNCENTRY( encoder, sjson_encoder )
+  LROT_FUNCENTRY( decoder, sjson_decoder )
+  LROT_LUDENTRY( NULL, 0 )
+LROT_END( sjson, NULL, 0 )
 
 LUALIB_API int luaopen_sjson (lua_State *L) {
-#ifdef LOCAL_LUA
-  luaL_register(L, LUA_SJSONLIBNAME, sjsonlib);
-  lua_getglobal(L, LUA_SJSONLIBNAME);
-  lua_pushstring(L, "NULL");
-  lua_pushlightuserdata(L, 0);
-  lua_settable(L, -3);
-  lua_pop(L, 1);
-  luaL_newmetatable(L, "sjson.encoder");
-  luaL_register(L, NULL, sjson_encoder_map);
-  lua_setfield(L, -1, "__index");
-  luaL_newmetatable(L, "sjson.decoder");
-  luaL_register(L, NULL, sjson_decoder_map);
-  lua_setfield(L, -1, "__index");
-#else
-  luaL_rometatable(L, "sjson.decoder", (void *)sjson_decoder_map);
-  luaL_rometatable(L, "sjson.encoder", (void *)sjson_encoder_map);
-#endif
+  luaL_rometatable(L, "sjson.decoder", LROT_TABLEREF(sjson_decoder));
+  luaL_rometatable(L, "sjson.encoder", LROT_TABLEREF(sjson_encoder));
   return 1;
 }
 
-#ifndef LOCAL_LUA
-NODEMCU_MODULE(SJSON, "sjson", sjson_map, luaopen_sjson);
-#endif
+NODEMCU_MODULE(SJSON, "sjson", sjson, luaopen_sjson);

+ 7 - 7
app/modules/sntp.c

@@ -869,13 +869,13 @@ static int sntp_open(lua_State *L)
 
 
 // Module function map
-static const LUA_REG_TYPE sntp_map[] = {
-  { LSTRKEY("sync"),  LFUNCVAL(sntp_sync)  },
+LROT_BEGIN(sntp)
+  LROT_FUNCENTRY( sync, sntp_sync )
 #ifdef LUA_USE_MODULES_RTCTIME
-  { LSTRKEY("setoffset"),  LFUNCVAL(sntp_setoffset)  },
-  { LSTRKEY("getoffset"),  LFUNCVAL(sntp_getoffset)  },
+  LROT_FUNCENTRY( setoffset, sntp_setoffset )
+  LROT_FUNCENTRY( getoffset, sntp_getoffset )
 #endif
-  { LNILKEY, LNILVAL }
-};
+LROT_END( sntp, NULL, 0 )
 
-NODEMCU_MODULE(SNTP, "sntp", sntp_map, sntp_open);
+
+NODEMCU_MODULE(SNTP, "sntp", sntp, sntp_open);

+ 9 - 9
app/modules/somfy.c

@@ -231,18 +231,18 @@ static int somfy_lua_sendcommand(lua_State* L) { // pin, remote, command, rollin
     return 0;
 }
 
-static const LUA_REG_TYPE somfy_map[] = {
-    { LSTRKEY( "UP" ),    LNUMVAL( SOMFY_UP ) },
-    { LSTRKEY( "DOWN" ),    LNUMVAL( SOMFY_DOWN ) },
-    { LSTRKEY( "PROG" ),    LNUMVAL( SOMFY_PROG ) },
-    { LSTRKEY( "STOP" ),    LNUMVAL( SOMFY_STOP ) },
-    { LSTRKEY( "sendcommand" ), LFUNCVAL(somfy_lua_sendcommand)},
-    { LNILKEY, LNILVAL}
-};
+LROT_BEGIN(somfy)
+  LROT_NUMENTRY( UP, SOMFY_UP )
+  LROT_NUMENTRY( DOWN, SOMFY_DOWN )
+  LROT_NUMENTRY( PROG, SOMFY_PROG )
+  LROT_NUMENTRY( STOP, SOMFY_STOP )
+  LROT_FUNCENTRY( sendcommand, somfy_lua_sendcommand )
+LROT_END( somfy, NULL, 0 )
+
 
 int luaopen_somfy( lua_State *L ) {
     done_taskid = task_get_id((task_callback_t) somfy_transmissionDone);
     return 0;
 }
 
-NODEMCU_MODULE(SOMFY, "somfy", somfy_map, luaopen_somfy);
+NODEMCU_MODULE(SOMFY, "somfy", somfy, luaopen_somfy);

+ 21 - 21
app/modules/spi.c

@@ -319,24 +319,24 @@ static int spi_set_clock_div( lua_State *L )
 
 
 // Module function map
-static const LUA_REG_TYPE spi_map[] = {
-  { LSTRKEY( "setup" ),       LFUNCVAL( spi_setup ) },
-  { LSTRKEY( "send" ),        LFUNCVAL( spi_send_recv ) },
-  { LSTRKEY( "recv" ),        LFUNCVAL( spi_recv ) },
-  { LSTRKEY( "set_mosi" ),    LFUNCVAL( spi_set_mosi ) },
-  { LSTRKEY( "get_miso" ),    LFUNCVAL( spi_get_miso ) },
-  { LSTRKEY( "transaction" ), LFUNCVAL( spi_transaction ) },
-  { LSTRKEY( "set_clock_div" ), LFUNCVAL( spi_set_clock_div ) },
-  { LSTRKEY( "MASTER" ),      LNUMVAL( PLATFORM_SPI_MASTER ) },
-  { LSTRKEY( "SLAVE" ),       LNUMVAL( PLATFORM_SPI_SLAVE) },
-  { LSTRKEY( "CPHA_LOW" ),    LNUMVAL( PLATFORM_SPI_CPHA_LOW) },
-  { LSTRKEY( "CPHA_HIGH" ),   LNUMVAL( PLATFORM_SPI_CPHA_HIGH) },
-  { LSTRKEY( "CPOL_LOW" ),    LNUMVAL( PLATFORM_SPI_CPOL_LOW) },
-  { LSTRKEY( "CPOL_HIGH" ),   LNUMVAL( PLATFORM_SPI_CPOL_HIGH) },
-  { LSTRKEY( "DATABITS_8" ),  LNUMVAL( 8 ) },
-  { LSTRKEY( "HALFDUPLEX" ),  LNUMVAL( SPI_HALFDUPLEX ) },
-  { LSTRKEY( "FULLDUPLEX" ),  LNUMVAL( SPI_FULLDUPLEX ) },
-  { LNILKEY, LNILVAL }
-};
-
-NODEMCU_MODULE(SPI, "spi", spi_map, NULL);
+LROT_BEGIN(spi)
+  LROT_FUNCENTRY( setup, spi_setup )
+  LROT_FUNCENTRY( send, spi_send_recv )
+  LROT_FUNCENTRY( recv, spi_recv )
+  LROT_FUNCENTRY( set_mosi, spi_set_mosi )
+  LROT_FUNCENTRY( get_miso, spi_get_miso )
+  LROT_FUNCENTRY( transaction, spi_transaction )
+  LROT_FUNCENTRY( set_clock_div, spi_set_clock_div )
+  LROT_NUMENTRY( MASTER, PLATFORM_SPI_MASTER )
+  LROT_NUMENTRY( SLAVE, PLATFORM_SPI_SLAVE )
+  LROT_NUMENTRY( CPHA_LOW, PLATFORM_SPI_CPHA_LOW )
+  LROT_NUMENTRY( CPHA_HIGH, PLATFORM_SPI_CPHA_HIGH )
+  LROT_NUMENTRY( CPOL_LOW, PLATFORM_SPI_CPOL_LOW )
+  LROT_NUMENTRY( CPOL_HIGH, PLATFORM_SPI_CPOL_HIGH )
+  LROT_NUMENTRY( DATABITS_8, 8 )
+  LROT_NUMENTRY( HALFDUPLEX, SPI_HALFDUPLEX )
+  LROT_NUMENTRY( FULLDUPLEX, SPI_FULLDUPLEX )
+LROT_END( spi, NULL, 0 )
+
+
+NODEMCU_MODULE(SPI, "spi", spi, NULL);

+ 2 - 0
app/modules/sqlite3.c

@@ -25,6 +25,7 @@
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     *
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                *
 ************************************************************************/
+#if 0
 #define LSQLITE_VERSION "0.9.4"
 #define LSQLITE_OMIT_UPDATE_HOOK 1
 #define SQLITE_OMIT_PROGRESS_CALLBACK 1
@@ -2429,3 +2430,4 @@ LUALIB_API int luaopen_lsqlite3(lua_State *L) {
 }
 
 NODEMCU_MODULE(SQLITE3, "sqlite3", sqlitelib, luaopen_lsqlite3);
+#endif

+ 5 - 6
app/modules/struct.c

@@ -389,13 +389,12 @@ static int b_size (lua_State *L) {
 /* }====================================================== */
 
 
+LROT_BEGIN(thislib)
+  LROT_FUNCENTRY( pack, b_pack )
+  LROT_FUNCENTRY( unpack, b_unpack )
+  LROT_FUNCENTRY( size, b_size )
+LROT_END( thislib, NULL, 0 )
 
-static const LUA_REG_TYPE thislib[] = {
-  {LSTRKEY("pack"), LFUNCVAL(b_pack)},
-  {LSTRKEY("unpack"), LFUNCVAL(b_unpack)},
-  {LSTRKEY("size"), LFUNCVAL(b_size)},
-  {LNILKEY, LNILVAL}
-};
 
 
 NODEMCU_MODULE(STRUCT, "struct", thislib, NULL);

+ 10 - 10
app/modules/switec.c

@@ -196,17 +196,17 @@ static int switec_open(lua_State *L)
 
 
 // Module function map
-static const LUA_REG_TYPE switec_map[] = {
-  { LSTRKEY( "setup" ),    LFUNCVAL( lswitec_setup ) },
-  { LSTRKEY( "close" ),    LFUNCVAL( lswitec_close ) },
-  { LSTRKEY( "reset" ),    LFUNCVAL( lswitec_reset ) },
-  { LSTRKEY( "moveto" ),   LFUNCVAL( lswitec_moveto) },
-  { LSTRKEY( "getpos" ),   LFUNCVAL( lswitec_getpos) },
+LROT_BEGIN(switec)
+  LROT_FUNCENTRY( setup, lswitec_setup )
+  LROT_FUNCENTRY( close, lswitec_close )
+  LROT_FUNCENTRY( reset, lswitec_reset )
+  LROT_FUNCENTRY( moveto, lswitec_moveto )
+  LROT_FUNCENTRY( getpos, lswitec_getpos )
 #ifdef SQITEC_DEBUG
-  { LSTRKEY( "dequeue" ),  LFUNCVAL( lswitec_dequeue) },
+  LROT_FUNCENTRY( dequeue, lswitec_dequeue )
 #endif
 
-  { LNILKEY, LNILVAL }
-};
+LROT_END( switec, NULL, 0 )
 
-NODEMCU_MODULE(SWITEC, "switec", switec_map, switec_open);
+
+NODEMCU_MODULE(SWITEC, "switec", switec, switec_open);

+ 11 - 11
app/modules/tcs34725.c

@@ -342,14 +342,14 @@ uint8_t tcs34725GetRawData(lua_State* L)
 }
 
 
-static const LUA_REG_TYPE tcs34725_map[] = {
-	{ LSTRKEY( "setup" ), LFUNCVAL(tcs34725Setup)},
-	{ LSTRKEY( "enable" ),  LFUNCVAL(tcs34725Enable)},
-	{ LSTRKEY( "disable" ),  LFUNCVAL(tcs34725Disable)},
-	{ LSTRKEY( "raw" ),  LFUNCVAL(tcs34725GetRawData)},
-	{ LSTRKEY( "setGain" ),  LFUNCVAL(tcs34725LuaSetGain)},
-	{ LSTRKEY( "setIntegrationTime" ),  LFUNCVAL(tcs34725LuaSetIntegrationTime)},
-	{ LNILKEY, LNILVAL}
-};
-
-NODEMCU_MODULE(TCS34725, "tcs34725", tcs34725_map, NULL);
+LROT_BEGIN(tcs34725)
+  LROT_FUNCENTRY( setup, tcs34725Setup )
+  LROT_FUNCENTRY( enable, tcs34725Enable )
+  LROT_FUNCENTRY( disable, tcs34725Disable )
+  LROT_FUNCENTRY( raw, tcs34725GetRawData )
+  LROT_FUNCENTRY( setGain, tcs34725LuaSetGain )
+  LROT_FUNCENTRY( setIntegrationTime, tcs34725LuaSetIntegrationTime )
+LROT_END( tcs34725, NULL, 0 )
+
+
+NODEMCU_MODULE(TCS34725, "tcs34725", tcs34725, NULL);

+ 30 - 30
app/modules/tls.c

@@ -31,7 +31,7 @@ __attribute__((section(".servercert.flash"))) unsigned char tls_server_cert_area
 __attribute__((section(".clientcert.flash"))) unsigned char tls_client_cert_area[INTERNAL_FLASH_SECTOR_SIZE];
 
 extern int tls_socket_create( lua_State *L );
-extern const LUA_REG_TYPE tls_cert_map[];
+LROT_EXTERN(tls_cert);
 
 typedef struct {
   struct espconn *pesp_conn;
@@ -613,40 +613,40 @@ static int tls_set_debug_threshold(lua_State *L) {
 }
 #endif
 
-static const LUA_REG_TYPE tls_socket_map[] = {
-  { LSTRKEY( "connect" ), LFUNCVAL( tls_socket_connect ) },
-  { LSTRKEY( "close" ),   LFUNCVAL( tls_socket_close ) },
-  { LSTRKEY( "on" ),      LFUNCVAL( tls_socket_on ) },
-  { LSTRKEY( "send" ),    LFUNCVAL( tls_socket_send ) },
-  { LSTRKEY( "hold" ),    LFUNCVAL( tls_socket_hold ) },
-  { LSTRKEY( "unhold" ),  LFUNCVAL( tls_socket_unhold ) },
-  { LSTRKEY( "getpeer" ), LFUNCVAL( tls_socket_getpeer ) },
-  { LSTRKEY( "__gc" ),    LFUNCVAL( tls_socket_delete ) },
-  { LSTRKEY( "__index" ), LROVAL( tls_socket_map ) },
-  { LNILKEY, LNILVAL }
-};
-
-const LUA_REG_TYPE tls_cert_map[] = {
-  { LSTRKEY( "verify" ),           LFUNCVAL( tls_cert_verify ) },
-  { LSTRKEY( "auth" ),             LFUNCVAL( tls_cert_auth ) },
-  { LSTRKEY( "__index" ),          LROVAL( tls_cert_map ) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE tls_map[] = {
-  { LSTRKEY( "createConnection" ), LFUNCVAL( tls_socket_create ) },
+LROT_BEGIN(tls_socket)
+  LROT_FUNCENTRY( connect, tls_socket_connect )
+  LROT_FUNCENTRY( close, tls_socket_close )
+  LROT_FUNCENTRY( on, tls_socket_on )
+  LROT_FUNCENTRY( send, tls_socket_send )
+  LROT_FUNCENTRY( hold, tls_socket_hold )
+  LROT_FUNCENTRY( unhold, tls_socket_unhold )
+  LROT_FUNCENTRY( getpeer, tls_socket_getpeer )
+  LROT_FUNCENTRY( __gc, tls_socket_delete )
+  LROT_TABENTRY( __index, tls_socket )
+LROT_END( tls_socket, tls_socket, 0 )
+
+
+LROT_PUBLIC_BEGIN(tls_cert)
+  LROT_FUNCENTRY( verify, tls_cert_verify )
+  LROT_FUNCENTRY( auth, tls_cert_auth )
+  LROT_TABENTRY( __index, tls_cert )
+LROT_END( tls_cert, tls_cert, 0 )
+
+
+LROT_BEGIN(tls)
+  LROT_FUNCENTRY( createConnection, tls_socket_create )
 #if defined(MBEDTLS_DEBUG_C)
-  { LSTRKEY( "setDebug" ),         LFUNCVAL( tls_set_debug_threshold ) },
+  LROT_FUNCENTRY( setDebug, tls_set_debug_threshold )
 #endif
-  { LSTRKEY( "cert" ),             LROVAL( tls_cert_map ) },
-  { LSTRKEY( "__metatable" ),      LROVAL( tls_map ) },
-  { LNILKEY, LNILVAL }
-};
+  LROT_TABENTRY( cert, tls_cert )
+  LROT_TABENTRY( __metatable, tls )
+LROT_END( tls, tls, 0 )
+
 
 int luaopen_tls( lua_State *L ) {
-  luaL_rometatable(L, "tls.socket", (void *)tls_socket_map);  // create metatable for net.server
+  luaL_rometatable(L, "tls.socket", LROT_TABLEREF(tls_socket));
   return 0;
 }
 
-NODEMCU_MODULE(TLS, "tls", tls_map, luaopen_tls);
+NODEMCU_MODULE(TLS, "tls", tls, luaopen_tls);
 #endif

+ 5 - 6
app/modules/tm1829.c

@@ -100,15 +100,14 @@ static int ICACHE_FLASH_ATTR tm1829_write(lua_State* L)
   return 0;
 }
 
-static const LUA_REG_TYPE tm1829_map[] =
-{
-  { LSTRKEY( "write" ), LFUNCVAL( tm1829_write) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(tm1829)
+  LROT_FUNCENTRY( write, tm1829_write )
+LROT_END( tm1829, NULL, 0 )
+
 
 int luaopen_tm1829(lua_State *L) {
   // TODO: Make sure that the GPIO system is initialized
   return 0;
 }
 
-NODEMCU_MODULE(TM1829, "tm1829", tm1829_map, luaopen_tm1829);
+NODEMCU_MODULE(TM1829, "tm1829", tm1829, luaopen_tm1829);

+ 31 - 31
app/modules/tmr.c

@@ -369,43 +369,43 @@ static int tmr_create( lua_State *L ) {
 
 // Module function map
 
-static const LUA_REG_TYPE tmr_dyn_map[] = {
-	{ LSTRKEY( "register" ),    LFUNCVAL( tmr_register ) },
-	{ LSTRKEY( "alarm" ),       LFUNCVAL( tmr_alarm ) },
-	{ LSTRKEY( "start" ),       LFUNCVAL( tmr_start ) },
-	{ LSTRKEY( "stop" ),        LFUNCVAL( tmr_stop ) },
-	{ LSTRKEY( "unregister" ),  LFUNCVAL( tmr_unregister ) },
-	{ LSTRKEY( "state" ),       LFUNCVAL( tmr_state ) },
-	{ LSTRKEY( "interval" ),    LFUNCVAL( tmr_interval) },
+LROT_BEGIN(tmr_dyn)
+  LROT_FUNCENTRY( register, tmr_register )
+  LROT_FUNCENTRY( alarm, tmr_alarm )
+  LROT_FUNCENTRY( start, tmr_start )
+  LROT_FUNCENTRY( stop, tmr_stop )
+  LROT_FUNCENTRY( unregister, tmr_unregister )
+  LROT_FUNCENTRY( state, tmr_state )
+  LROT_FUNCENTRY( interval, tmr_interval )
 #ifdef TIMER_SUSPEND_ENABLE
-	{ LSTRKEY( "suspend" ),     LFUNCVAL( tmr_suspend ) },
-	{ LSTRKEY( "resume" ),      LFUNCVAL( tmr_resume ) },
+  LROT_FUNCENTRY( suspend, tmr_suspend )
+  LROT_FUNCENTRY( resume, tmr_resume )
 #endif
-	{ LSTRKEY( "__gc" ),        LFUNCVAL( tmr_unregister ) },
-	{ LSTRKEY( "__index" ),     LROVAL( tmr_dyn_map ) },
-	{ LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE tmr_map[] = {
-	{ LSTRKEY( "delay" ),        LFUNCVAL( tmr_delay ) },
-	{ LSTRKEY( "now" ),          LFUNCVAL( tmr_now ) },
-	{ LSTRKEY( "wdclr" ),        LFUNCVAL( tmr_wdclr ) },
-	{ LSTRKEY( "softwd" ),       LFUNCVAL( tmr_softwd ) },
-	{ LSTRKEY( "time" ),         LFUNCVAL( tmr_time ) },
+  LROT_FUNCENTRY( __gc, tmr_unregister )
+  LROT_TABENTRY( __index, tmr_dyn )
+LROT_END( tmr_dyn, tmr_dyn, LROT_MASK_GC_INDEX )
+
+
+LROT_BEGIN(tmr)
+  LROT_FUNCENTRY( delay, tmr_delay )
+  LROT_FUNCENTRY( now, tmr_now )
+  LROT_FUNCENTRY( wdclr, tmr_wdclr )
+  LROT_FUNCENTRY( softwd, tmr_softwd )
+  LROT_FUNCENTRY( time, tmr_time )
 #ifdef TIMER_SUSPEND_ENABLE
-	{ LSTRKEY( "suspend_all" ),  LFUNCVAL( tmr_suspend_all ) },
-	{ LSTRKEY( "resume_all" ),   LFUNCVAL( tmr_resume_all ) },
+  LROT_FUNCENTRY( suspend_all, tmr_suspend_all )
+  LROT_FUNCENTRY( resume_all, tmr_resume_all )
 #endif
-	{ LSTRKEY( "create" ),       LFUNCVAL( tmr_create ) },
-	{ LSTRKEY( "ALARM_SINGLE" ), LNUMVAL( TIMER_MODE_SINGLE ) },
-	{ LSTRKEY( "ALARM_SEMI" ),   LNUMVAL( TIMER_MODE_SEMI ) },
-	{ LSTRKEY( "ALARM_AUTO" ),   LNUMVAL( TIMER_MODE_AUTO ) },
-	{ LNILKEY, LNILVAL }
-};
+  LROT_FUNCENTRY( create, tmr_create )
+  LROT_NUMENTRY( ALARM_SINGLE, TIMER_MODE_SINGLE )
+  LROT_NUMENTRY( ALARM_SEMI, TIMER_MODE_SEMI )
+  LROT_NUMENTRY( ALARM_AUTO, TIMER_MODE_AUTO )
+LROT_END( tmr, NULL, 0 )
+
 
 #include "pm/swtimer.h"
 int luaopen_tmr( lua_State *L ){
-	luaL_rometatable(L, "tmr.timer", (void *)tmr_dyn_map);
+	luaL_rometatable(L, "tmr.timer", LROT_TABLEREF(tmr_dyn));
 
 	last_rtc_time=system_get_rtc_time(); // Right now is time 0
 	last_rtc_time_us=0;
@@ -425,4 +425,4 @@ int luaopen_tmr( lua_State *L ){
 	return 0;
 }
 
-NODEMCU_MODULE(TMR, "tmr", tmr_map, luaopen_tmr);
+NODEMCU_MODULE(TMR, "tmr", tmr, luaopen_tmr);

+ 23 - 23
app/modules/tsl2561.c

@@ -101,27 +101,27 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_getchannels(lua_State* L) {
 }
 
 // Module function map
-static const LUA_REG_TYPE tsl2561_map[] = {
-	{	LSTRKEY( "settiming" ),             LFUNCVAL( tsl2561_lua_settiming)},
-	{	LSTRKEY( "getlux" ),                LFUNCVAL( tsl2561_lua_calclux )},
-	{	LSTRKEY( "getrawchannels" ),        LFUNCVAL( tsl2561_lua_getchannels )},
-	{	LSTRKEY( "init" ),                  LFUNCVAL( tsl2561_init )},
-	{	LSTRKEY( "TSL2561_OK" ),            LNUMVAL( TSL2561_ERROR_OK )},
-	{	LSTRKEY( "TSL2561_ERROR_I2CINIT" ), LNUMVAL( TSL2561_ERROR_I2CINIT )},
-	{	LSTRKEY( "TSL2561_ERROR_I2CBUSY" ), LNUMVAL( TSL2561_ERROR_I2CBUSY )},
-	{	LSTRKEY( "TSL2561_ERROR_NOINIT" ),  LNUMVAL( TSL2561_ERROR_NOINIT )},
-	{	LSTRKEY( "TSL2561_ERROR_LAST" ),    LNUMVAL( TSL2561_ERROR_LAST )},
-	{	LSTRKEY( "INTEGRATIONTIME_13MS" ),  LNUMVAL( TSL2561_INTEGRATIONTIME_13MS )},
-	{	LSTRKEY( "INTEGRATIONTIME_101MS" ), LNUMVAL( TSL2561_INTEGRATIONTIME_101MS )},
-	{	LSTRKEY( "INTEGRATIONTIME_402MS" ), LNUMVAL( TSL2561_INTEGRATIONTIME_402MS )},
-	{	LSTRKEY( "GAIN_1X" ),               LNUMVAL( TSL2561_GAIN_1X )},
-	{	LSTRKEY( "GAIN_16X" ),              LNUMVAL( TSL2561_GAIN_16X )},
-	{	LSTRKEY( "PACKAGE_CS" ),            LNUMVAL( TSL2561_PACKAGE_CS )},
-	{	LSTRKEY( "PACKAGE_T_FN_CL" ),       LNUMVAL( TSL2561_PACKAGE_T_FN_CL )},
-	{	LSTRKEY( "ADDRESS_GND" ),           LNUMVAL( TSL2561_ADDRESS_GND )},
-	{	LSTRKEY( "ADDRESS_FLOAT" ),         LNUMVAL( TSL2561_ADDRESS_FLOAT )},
-	{	LSTRKEY( "ADDRESS_VDD" ),           LNUMVAL( TSL2561_ADDRESS_VDD )},
-	{	LNILKEY, LNILVAL}
-};
+LROT_BEGIN(tsl2561)
+  LROT_FUNCENTRY( settiming, tsl2561_lua_settiming )
+  LROT_FUNCENTRY( getlux, tsl2561_lua_calclux )
+  LROT_FUNCENTRY( getrawchannels, tsl2561_lua_getchannels )
+  LROT_FUNCENTRY( init, tsl2561_init )
+  LROT_NUMENTRY( TSL2561_OK, TSL2561_ERROR_OK )
+  LROT_NUMENTRY( TSL2561_ERROR_I2CINIT, TSL2561_ERROR_I2CINIT )
+  LROT_NUMENTRY( TSL2561_ERROR_I2CBUSY, TSL2561_ERROR_I2CBUSY )
+  LROT_NUMENTRY( TSL2561_ERROR_NOINIT, TSL2561_ERROR_NOINIT )
+  LROT_NUMENTRY( TSL2561_ERROR_LAST, TSL2561_ERROR_LAST )
+  LROT_NUMENTRY( INTEGRATIONTIME_13MS, TSL2561_INTEGRATIONTIME_13MS )
+  LROT_NUMENTRY( INTEGRATIONTIME_101MS, TSL2561_INTEGRATIONTIME_101MS )
+  LROT_NUMENTRY( INTEGRATIONTIME_402MS, TSL2561_INTEGRATIONTIME_402MS )
+  LROT_NUMENTRY( GAIN_1X, TSL2561_GAIN_1X )
+  LROT_NUMENTRY( GAIN_16X, TSL2561_GAIN_16X )
+  LROT_NUMENTRY( PACKAGE_CS, TSL2561_PACKAGE_CS )
+  LROT_NUMENTRY( PACKAGE_T_FN_CL, TSL2561_PACKAGE_T_FN_CL )
+  LROT_NUMENTRY( ADDRESS_GND, TSL2561_ADDRESS_GND )
+  LROT_NUMENTRY( ADDRESS_FLOAT, TSL2561_ADDRESS_FLOAT )
+  LROT_NUMENTRY( ADDRESS_VDD, TSL2561_ADDRESS_VDD )
+LROT_END( tsl2561, NULL, 0 )
 
-NODEMCU_MODULE(TSL2561, "tsl2561", tsl2561_map, NULL);
+
+NODEMCU_MODULE(TSL2561, "tsl2561", tsl2561, NULL);

+ 62 - 66
app/modules/u8g2.c

@@ -566,52 +566,51 @@ static int lu8g2_updateDisplayArea( lua_State *L )
 }
 
 
-static const LUA_REG_TYPE lu8g2_display_map[] = {
-  { LSTRKEY( "clearBuffer" ),        LFUNCVAL( lu8g2_clearBuffer ) },
-  { LSTRKEY( "drawBox" ),            LFUNCVAL( lu8g2_drawBox ) },
-  { LSTRKEY( "drawCircle" ),         LFUNCVAL( lu8g2_drawCircle ) },
-  { LSTRKEY( "drawDisc" ),           LFUNCVAL( lu8g2_drawDisc ) },
-  { LSTRKEY( "drawEllipse" ),        LFUNCVAL( lu8g2_drawEllipse ) },
-  { LSTRKEY( "drawFilledEllipse" ),  LFUNCVAL( lu8g2_drawFilledEllipse ) },
-  { LSTRKEY( "drawFrame" ),          LFUNCVAL( lu8g2_drawFrame ) },
-  { LSTRKEY( "drawGlyph" ),          LFUNCVAL( lu8g2_drawGlyph ) },
-  { LSTRKEY( "drawHLine" ),          LFUNCVAL( lu8g2_drawHLine ) },
-  { LSTRKEY( "drawLine" ),           LFUNCVAL( lu8g2_drawLine ) },
-  { LSTRKEY( "drawPixel" ),          LFUNCVAL( lu8g2_drawPixel ) },
-  { LSTRKEY( "drawRBox" ),           LFUNCVAL( lu8g2_drawRBox ) },
-  { LSTRKEY( "drawRFrame" ),         LFUNCVAL( lu8g2_drawRFrame ) },
-  { LSTRKEY( "drawStr" ),            LFUNCVAL( lu8g2_drawStr ) },
-  { LSTRKEY( "drawTriangle" ),       LFUNCVAL( lu8g2_drawTriangle ) },
-  { LSTRKEY( "drawUTF8" ),           LFUNCVAL( lu8g2_drawUTF8 ) },
-  { LSTRKEY( "drawVLine" ),          LFUNCVAL( lu8g2_drawVLine ) },
-  { LSTRKEY( "drawXBM" ),            LFUNCVAL( lu8g2_drawXBM ) },
-  { LSTRKEY( "getAscent" ),          LFUNCVAL( lu8g2_getAscent ) },
-  { LSTRKEY( "getDescent" ),         LFUNCVAL( lu8g2_getDescent ) },
-  { LSTRKEY( "getStrWidth" ),        LFUNCVAL( lu8g2_getStrWidth ) },
-  { LSTRKEY( "getUTF8Width" ),       LFUNCVAL( lu8g2_getUTF8Width ) },
-  { LSTRKEY( "sendBuffer" ),         LFUNCVAL( lu8g2_sendBuffer ) },
-  { LSTRKEY( "setBitmapMode" ),      LFUNCVAL( lu8g2_setBitmapMode ) },
-  { LSTRKEY( "setContrast" ),        LFUNCVAL( lu8g2_setContrast ) },
-  { LSTRKEY( "setDisplayRotation" ), LFUNCVAL( lu8g2_setDisplayRotation ) },
-  { LSTRKEY( "setDrawColor" ),       LFUNCVAL( lu8g2_setDrawColor ) },
-  { LSTRKEY( "setFlipMode" ),        LFUNCVAL( lu8g2_setFlipMode ) },
-  { LSTRKEY( "setFont" ),            LFUNCVAL( lu8g2_setFont ) },
-  { LSTRKEY( "setFontDirection" ),   LFUNCVAL( lu8g2_setFontDirection ) },
-  { LSTRKEY( "setFontMode" ),        LFUNCVAL( lu8g2_setFontMode ) },
-  { LSTRKEY( "setFontPosBaseline" ), LFUNCVAL( lu8g2_setFontPosBaseline ) },
-  { LSTRKEY( "setFontPosBottom" ),   LFUNCVAL( lu8g2_setFontPosBottom ) },
-  { LSTRKEY( "setFontPosTop" ),      LFUNCVAL( lu8g2_setFontPosTop ) },
-  { LSTRKEY( "setFontPosCenter" ),   LFUNCVAL( lu8g2_setFontPosCenter ) },
-  { LSTRKEY( "setFontRefHeightAll" ),          LFUNCVAL( lu8g2_setFontRefHeightAll ) },
-  { LSTRKEY( "setFontRefHeightExtendedText" ), LFUNCVAL( lu8g2_setFontRefHeightExtendedText ) },
-  { LSTRKEY( "setFontRefHeightText" ),         LFUNCVAL( lu8g2_setFontRefHeightText ) },
-  { LSTRKEY( "setPowerSave" ),       LFUNCVAL( lu8g2_setPowerSave ) },
-  { LSTRKEY( "updateDispla" ),       LFUNCVAL( lu8g2_updateDisplay ) },
-  { LSTRKEY( "updateDisplayArea" ),            LFUNCVAL( lu8g2_updateDisplayArea ) },
-  //{ LSTRKEY( "__gc" ),    LFUNCVAL( lu8g2_display_free ) },
-  { LSTRKEY( "__index" ), LROVAL( lu8g2_display_map ) },
-  {LNILKEY, LNILVAL}
-};
+LROT_BEGIN(lu8g2_display)
+  LROT_FUNCENTRY( clearBuffer, lu8g2_clearBuffer )
+  LROT_FUNCENTRY( drawBox, lu8g2_drawBox )
+  LROT_FUNCENTRY( drawCircle, lu8g2_drawCircle )
+  LROT_FUNCENTRY( drawDisc, lu8g2_drawDisc )
+  LROT_FUNCENTRY( drawEllipse, lu8g2_drawEllipse )
+  LROT_FUNCENTRY( drawFilledEllipse, lu8g2_drawFilledEllipse )
+  LROT_FUNCENTRY( drawFrame, lu8g2_drawFrame )
+  LROT_FUNCENTRY( drawGlyph, lu8g2_drawGlyph )
+  LROT_FUNCENTRY( drawHLine, lu8g2_drawHLine )
+  LROT_FUNCENTRY( drawLine, lu8g2_drawLine )
+  LROT_FUNCENTRY( drawPixel, lu8g2_drawPixel )
+  LROT_FUNCENTRY( drawRBox, lu8g2_drawRBox )
+  LROT_FUNCENTRY( drawRFrame, lu8g2_drawRFrame )
+  LROT_FUNCENTRY( drawStr, lu8g2_drawStr )
+  LROT_FUNCENTRY( drawTriangle, lu8g2_drawTriangle )
+  LROT_FUNCENTRY( drawUTF8, lu8g2_drawUTF8 )
+  LROT_FUNCENTRY( drawVLine, lu8g2_drawVLine )
+  LROT_FUNCENTRY( drawXBM, lu8g2_drawXBM )
+  LROT_FUNCENTRY( getAscent, lu8g2_getAscent )
+  LROT_FUNCENTRY( getDescent, lu8g2_getDescent )
+  LROT_FUNCENTRY( getStrWidth, lu8g2_getStrWidth )
+  LROT_FUNCENTRY( getUTF8Width, lu8g2_getUTF8Width )
+  LROT_FUNCENTRY( sendBuffer, lu8g2_sendBuffer )
+  LROT_FUNCENTRY( setBitmapMode, lu8g2_setBitmapMode )
+  LROT_FUNCENTRY( setContrast, lu8g2_setContrast )
+  LROT_FUNCENTRY( setDisplayRotation, lu8g2_setDisplayRotation )
+  LROT_FUNCENTRY( setDrawColor, lu8g2_setDrawColor )
+  LROT_FUNCENTRY( setFlipMode, lu8g2_setFlipMode )
+  LROT_FUNCENTRY( setFont, lu8g2_setFont )
+  LROT_FUNCENTRY( setFontDirection, lu8g2_setFontDirection )
+  LROT_FUNCENTRY( setFontMode, lu8g2_setFontMode )
+  LROT_FUNCENTRY( setFontPosBaseline, lu8g2_setFontPosBaseline )
+  LROT_FUNCENTRY( setFontPosBottom, lu8g2_setFontPosBottom )
+  LROT_FUNCENTRY( setFontPosTop, lu8g2_setFontPosTop )
+  LROT_FUNCENTRY( setFontPosCenter, lu8g2_setFontPosCenter )
+  LROT_FUNCENTRY( setFontRefHeightAll, lu8g2_setFontRefHeightAll )
+  LROT_FUNCENTRY( setFontRefHeightExtendedText, lu8g2_setFontRefHeightExtendedText )
+  LROT_FUNCENTRY( setFontRefHeightText, lu8g2_setFontRefHeightText )
+  LROT_FUNCENTRY( setPowerSave, lu8g2_setPowerSave )
+  LROT_FUNCENTRY( updateDispla, lu8g2_updateDisplay )
+  LROT_FUNCENTRY( updateDisplayArea, lu8g2_updateDisplayArea )
+  //  LROT_FUNCENTRY( __gc, lu8g2_display_free )
+  LROT_TABENTRY( __index, lu8g2_display )
+LROT_END( lu8g2_display, lu8g2_display, LROT_MASK_GC_INDEX )
 
 
 uint8_t u8x8_d_overlay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
@@ -808,36 +807,33 @@ U8G2_DISPLAY_TABLE_SPI
 
 #undef U8G2_FONT_TABLE_ENTRY
 #undef U8G2_DISPLAY_TABLE_ENTRY
-#define U8G2_DISPLAY_TABLE_ENTRY(function, binding) \
-  { LSTRKEY( #binding ),           LFUNCVAL( l ## binding ) },
-
-static const LUA_REG_TYPE lu8g2_map[] = {
+#define U8G2_DISPLAY_TABLE_ENTRY(function, binding) LROT_FUNCENTRY(#binding,l ## binding)
+LROT_BEGIN(lu8g2)
   U8G2_DISPLAY_TABLE_I2C
   U8G2_DISPLAY_TABLE_SPI
   //
   // Register fonts
-#define U8G2_FONT_TABLE_ENTRY(font) \
-  { LSTRKEY( #font ),              LUDATA( (void *)(u8g2_ ## font) ) },
+#define U8G2_FONT_TABLE_ENTRY(font) LROT_LUDENTRY(font, u8g2_ ## font)
   U8G2_FONT_TABLE
   //
-  { LSTRKEY( "DRAW_UPPER_RIGHT" ), LNUMVAL( U8G2_DRAW_UPPER_RIGHT ) },
-  { LSTRKEY( "DRAW_UPPER_LEFT" ),  LNUMVAL( U8G2_DRAW_UPPER_LEFT ) },
-  { LSTRKEY( "DRAW_LOWER_RIGHT" ), LNUMVAL( U8G2_DRAW_LOWER_RIGHT ) },
-  { LSTRKEY( "DRAW_LOWER_LEFT" ),  LNUMVAL( U8G2_DRAW_LOWER_LEFT ) },
-  { LSTRKEY( "DRAW_ALL" ),         LNUMVAL( U8G2_DRAW_ALL ) },
-  { LSTRKEY( "R0" ),               LUDATA( (void *)U8G2_R0 ) },
-  { LSTRKEY( "R1" ),               LUDATA( (void *)U8G2_R1 ) },
-  { LSTRKEY( "R2" ),               LUDATA( (void *)U8G2_R2 ) },
-  { LSTRKEY( "R3" ),               LUDATA( (void *)U8G2_R3 ) },
-  { LSTRKEY( "MIRROR" ),           LUDATA( (void *)U8G2_MIRROR ) },
-  {LNILKEY, LNILVAL}
-};
+  LROT_NUMENTRY( DRAW_UPPER_RIGHT, U8G2_DRAW_UPPER_RIGHT )
+  LROT_NUMENTRY( DRAW_UPPER_LEFT, U8G2_DRAW_UPPER_LEFT )
+  LROT_NUMENTRY( DRAW_LOWER_RIGHT, U8G2_DRAW_LOWER_RIGHT )
+  LROT_NUMENTRY( DRAW_LOWER_LEFT, U8G2_DRAW_LOWER_LEFT )
+  LROT_NUMENTRY( DRAW_ALL, U8G2_DRAW_ALL )
+  LROT_LUDENTRY( R0, U8G2_R0 )
+  LROT_LUDENTRY( R1, U8G2_R1 )
+  LROT_LUDENTRY( R2, U8G2_R2 )
+  LROT_LUDENTRY( R3, U8G2_R3 )
+  LROT_LUDENTRY( MIRROR, U8G2_MIRROR )
+LROT_END( lu8g2, NULL, 0 )
+
 
 int luaopen_u8g2( lua_State *L ) {
-  luaL_rometatable(L, "u8g2.display", (void *)lu8g2_display_map);
+  luaL_rometatable(L, "u8g2.display", LROT_TABLEREF(lu8g2_display));
   return 0;
 }
 
-NODEMCU_MODULE(U8G2, "u8g2", lu8g2_map, luaopen_u8g2);
+NODEMCU_MODULE(U8G2, "u8g2", lu8g2, luaopen_u8g2);
 
 #endif /* defined(LUA_USE_MODULES_U8G2) || defined(ESP_PLATFORM) */

+ 16 - 16
app/modules/uart.c

@@ -174,19 +174,19 @@ static int l_uart_write( lua_State* L )
 }
 
 // Module function map
-static const LUA_REG_TYPE uart_map[] =  {
-  { LSTRKEY( "setup" ), LFUNCVAL( l_uart_setup ) },
-  { LSTRKEY( "getconfig" ), LFUNCVAL( l_uart_getconfig ) },
-  { LSTRKEY( "write" ), LFUNCVAL( l_uart_write ) },
-  { LSTRKEY( "on" ),    LFUNCVAL( l_uart_on ) },
-  { LSTRKEY( "alt" ),   LFUNCVAL( l_uart_alt ) },
-  { LSTRKEY( "STOPBITS_1" ),   LNUMVAL( PLATFORM_UART_STOPBITS_1 ) },
-  { LSTRKEY( "STOPBITS_1_5" ), LNUMVAL( PLATFORM_UART_STOPBITS_1_5 ) },
-  { LSTRKEY( "STOPBITS_2" ),   LNUMVAL( PLATFORM_UART_STOPBITS_2 ) },
-  { LSTRKEY( "PARITY_NONE" ),  LNUMVAL( PLATFORM_UART_PARITY_NONE ) },
-  { LSTRKEY( "PARITY_EVEN" ),  LNUMVAL( PLATFORM_UART_PARITY_EVEN ) },
-  { LSTRKEY( "PARITY_ODD" ),   LNUMVAL( PLATFORM_UART_PARITY_ODD ) },
-  { LNILKEY, LNILVAL }
-};
-
-NODEMCU_MODULE(UART, "uart", uart_map, NULL);
+LROT_BEGIN(uart)
+  LROT_FUNCENTRY( setup, l_uart_setup )
+  LROT_FUNCENTRY( getconfig, l_uart_getconfig )
+  LROT_FUNCENTRY( write, l_uart_write )
+  LROT_FUNCENTRY( on, l_uart_on )
+  LROT_FUNCENTRY( alt, l_uart_alt )
+  LROT_NUMENTRY( STOPBITS_1, PLATFORM_UART_STOPBITS_1 )
+  LROT_NUMENTRY( STOPBITS_1_5, PLATFORM_UART_STOPBITS_1_5 )
+  LROT_NUMENTRY( STOPBITS_2, PLATFORM_UART_STOPBITS_2 )
+  LROT_NUMENTRY( PARITY_NONE, PLATFORM_UART_PARITY_NONE )
+  LROT_NUMENTRY( PARITY_EVEN, PLATFORM_UART_PARITY_EVEN )
+  LROT_NUMENTRY( PARITY_ODD, PLATFORM_UART_PARITY_ODD )
+LROT_END( uart, NULL, 0 )
+
+
+NODEMCU_MODULE(UART, "uart", uart, NULL);

+ 65 - 67
app/modules/ucg.c

@@ -690,89 +690,87 @@ UCG_DISPLAY_TABLE
 
 
 // Module function map
-static const LUA_REG_TYPE lucg_display_map[] =
-{
-  { LSTRKEY( "begin" ),              LFUNCVAL( lucg_begin ) },
-  { LSTRKEY( "clearScreen" ),        LFUNCVAL( lucg_clearScreen ) },
-  { LSTRKEY( "draw90Line" ),         LFUNCVAL( lucg_draw90Line ) },
-  { LSTRKEY( "drawBox" ),            LFUNCVAL( lucg_drawBox ) },
-  { LSTRKEY( "drawCircle" ),         LFUNCVAL( lucg_drawCircle ) },
-  { LSTRKEY( "drawDisc" ),           LFUNCVAL( lucg_drawDisc ) },
-  { LSTRKEY( "drawFrame" ),          LFUNCVAL( lucg_drawFrame ) },
-  { LSTRKEY( "drawGlyph" ),          LFUNCVAL( lucg_drawGlyph ) },
-  { LSTRKEY( "drawGradientBox" ),    LFUNCVAL( lucg_drawGradientBox ) },
-  { LSTRKEY( "drawGradientLine" ),   LFUNCVAL( lucg_drawGradientLine ) },
-  { LSTRKEY( "drawHLine" ),          LFUNCVAL( lucg_drawHLine ) },
-  { LSTRKEY( "drawLine" ),           LFUNCVAL( lucg_drawLine ) },
-  { LSTRKEY( "drawPixel" ),          LFUNCVAL( lucg_drawPixel ) },
-  { LSTRKEY( "drawRBox" ),           LFUNCVAL( lucg_drawRBox ) },
-  { LSTRKEY( "drawRFrame" ),         LFUNCVAL( lucg_drawRFrame ) },
-  { LSTRKEY( "drawString" ),         LFUNCVAL( lucg_drawString ) },
-  { LSTRKEY( "drawTetragon" ),       LFUNCVAL( lucg_drawTetragon ) },
-  { LSTRKEY( "drawTriangle" ),       LFUNCVAL( lucg_drawTriangle ) },
-  { LSTRKEY( "drawVLine" ),          LFUNCVAL( lucg_drawVLine ) },
-  { LSTRKEY( "getFontAscent" ),      LFUNCVAL( lucg_getFontAscent ) },
-  { LSTRKEY( "getFontDescent" ),     LFUNCVAL( lucg_getFontDescent ) },
-  { LSTRKEY( "getHeight" ),          LFUNCVAL( lucg_getHeight ) },
-  { LSTRKEY( "getStrWidth" ),        LFUNCVAL( lucg_getStrWidth ) },
-  { LSTRKEY( "getWidth" ),           LFUNCVAL( lucg_getWidth ) },
-  { LSTRKEY( "print" ),              LFUNCVAL( lucg_print ) },
-  { LSTRKEY( "setClipRange" ),       LFUNCVAL( lucg_setClipRange ) },
-  { LSTRKEY( "setColor" ),           LFUNCVAL( lucg_setColor ) },
-  { LSTRKEY( "setFont" ),            LFUNCVAL( lucg_setFont ) },
-  { LSTRKEY( "setFontMode" ),        LFUNCVAL( lucg_setFontMode ) },
-  { LSTRKEY( "setFontPosBaseline" ), LFUNCVAL( lucg_setFontPosBaseline ) },
-  { LSTRKEY( "setFontPosBottom" ),   LFUNCVAL( lucg_setFontPosBottom ) },
-  { LSTRKEY( "setFontPosCenter" ),   LFUNCVAL( lucg_setFontPosCenter ) },
-  { LSTRKEY( "setFontPosTop" ),      LFUNCVAL( lucg_setFontPosTop ) },
-  { LSTRKEY( "setMaxClipRange" ),    LFUNCVAL( lucg_setMaxClipRange ) },
-  { LSTRKEY( "setPrintDir" ),        LFUNCVAL( lucg_setPrintDir ) },
-  { LSTRKEY( "setPrintPos" ),        LFUNCVAL( lucg_setPrintPos ) },
-  { LSTRKEY( "setRotate90" ),        LFUNCVAL( lucg_setRotate90 ) },
-  { LSTRKEY( "setRotate180" ),       LFUNCVAL( lucg_setRotate180 ) },
-  { LSTRKEY( "setRotate270" ),       LFUNCVAL( lucg_setRotate270 ) },
-  { LSTRKEY( "setScale2x2" ),        LFUNCVAL( lucg_setScale2x2 ) },
-  { LSTRKEY( "undoClipRange" ),      LFUNCVAL( lucg_setMaxClipRange ) },
-  { LSTRKEY( "undoRotate" ),         LFUNCVAL( lucg_undoRotate ) },
-  { LSTRKEY( "undoScale" ),          LFUNCVAL( lucg_undoScale ) },
-
-  { LSTRKEY( "__gc" ),  LFUNCVAL( lucg_close_display ) },
-  { LSTRKEY( "__index" ), LROVAL ( lucg_display_map ) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE lucg_map[] =
-{
+LROT_BEGIN(lucg_display)
+  LROT_FUNCENTRY( begin, lucg_begin )
+  LROT_FUNCENTRY( clearScreen, lucg_clearScreen )
+  LROT_FUNCENTRY( draw90Line, lucg_draw90Line )
+  LROT_FUNCENTRY( drawBox, lucg_drawBox )
+  LROT_FUNCENTRY( drawCircle, lucg_drawCircle )
+  LROT_FUNCENTRY( drawDisc, lucg_drawDisc )
+  LROT_FUNCENTRY( drawFrame, lucg_drawFrame )
+  LROT_FUNCENTRY( drawGlyph, lucg_drawGlyph )
+  LROT_FUNCENTRY( drawGradientBox, lucg_drawGradientBox )
+  LROT_FUNCENTRY( drawGradientLine, lucg_drawGradientLine )
+  LROT_FUNCENTRY( drawHLine, lucg_drawHLine )
+  LROT_FUNCENTRY( drawLine, lucg_drawLine )
+  LROT_FUNCENTRY( drawPixel, lucg_drawPixel )
+  LROT_FUNCENTRY( drawRBox, lucg_drawRBox )
+  LROT_FUNCENTRY( drawRFrame, lucg_drawRFrame )
+  LROT_FUNCENTRY( drawString, lucg_drawString )
+  LROT_FUNCENTRY( drawTetragon, lucg_drawTetragon )
+  LROT_FUNCENTRY( drawTriangle, lucg_drawTriangle )
+  LROT_FUNCENTRY( drawVLine, lucg_drawVLine )
+  LROT_FUNCENTRY( getFontAscent, lucg_getFontAscent )
+  LROT_FUNCENTRY( getFontDescent, lucg_getFontDescent )
+  LROT_FUNCENTRY( getHeight, lucg_getHeight )
+  LROT_FUNCENTRY( getStrWidth, lucg_getStrWidth )
+  LROT_FUNCENTRY( getWidth, lucg_getWidth )
+  LROT_FUNCENTRY( print, lucg_print )
+  LROT_FUNCENTRY( setClipRange, lucg_setClipRange )
+  LROT_FUNCENTRY( setColor, lucg_setColor )
+  LROT_FUNCENTRY( setFont, lucg_setFont )
+  LROT_FUNCENTRY( setFontMode, lucg_setFontMode )
+  LROT_FUNCENTRY( setFontPosBaseline, lucg_setFontPosBaseline )
+  LROT_FUNCENTRY( setFontPosBottom, lucg_setFontPosBottom )
+  LROT_FUNCENTRY( setFontPosCenter, lucg_setFontPosCenter )
+  LROT_FUNCENTRY( setFontPosTop, lucg_setFontPosTop )
+  LROT_FUNCENTRY( setMaxClipRange, lucg_setMaxClipRange )
+  LROT_FUNCENTRY( setPrintDir, lucg_setPrintDir )
+  LROT_FUNCENTRY( setPrintPos, lucg_setPrintPos )
+  LROT_FUNCENTRY( setRotate90, lucg_setRotate90 )
+  LROT_FUNCENTRY( setRotate180, lucg_setRotate180 )
+  LROT_FUNCENTRY( setRotate270, lucg_setRotate270 )
+  LROT_FUNCENTRY( setScale2x2, lucg_setScale2x2 )
+  LROT_FUNCENTRY( undoClipRange, lucg_setMaxClipRange )
+  LROT_FUNCENTRY( undoRotate, lucg_undoRotate )
+  LROT_FUNCENTRY( undoScale, lucg_undoScale )
+
+  LROT_FUNCENTRY( __gc, lucg_close_display )
+  LROT_TABENTRY( __index, lucg_display )
+LROT_END( lucg_display, lucg_display, 0 )
+
+
+LROT_BEGIN(lucg)
 #undef UCG_DISPLAY_TABLE_ENTRY
-#define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension) { LSTRKEY( #binding ), LFUNCVAL ( l ## binding ) },
+#define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension) LROT_FUNCENTRY(binding,l ## binding)
   UCG_DISPLAY_TABLE
 
   // Register fonts
 #undef UCG_FONT_TABLE_ENTRY
-#define UCG_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(ucg_ ## font) ) },
+#define UCG_FONT_TABLE_ENTRY(font) LROT_LUDENTRY(font, ucg_ ## font )
   UCG_FONT_TABLE
 
   // Font modes
-  { LSTRKEY( "FONT_MODE_TRANSPARENT" ), LNUMVAL( UCG_FONT_MODE_TRANSPARENT ) },
-  { LSTRKEY( "FONT_MODE_SOLID" ),       LNUMVAL( UCG_FONT_MODE_SOLID ) },
+  LROT_NUMENTRY( FONT_MODE_TRANSPARENT, UCG_FONT_MODE_TRANSPARENT )
+  LROT_NUMENTRY( FONT_MODE_SOLID, UCG_FONT_MODE_SOLID )
 
   // Options for circle/ disc drawing
-  { LSTRKEY( "DRAW_UPPER_RIGHT" ), LNUMVAL( UCG_DRAW_UPPER_RIGHT ) },
-  { LSTRKEY( "DRAW_UPPER_LEFT" ),  LNUMVAL( UCG_DRAW_UPPER_LEFT ) },
-  { LSTRKEY( "DRAW_LOWER_RIGHT" ), LNUMVAL( UCG_DRAW_LOWER_RIGHT ) },
-  { LSTRKEY( "DRAW_LOWER_LEFT" ),  LNUMVAL( UCG_DRAW_LOWER_LEFT ) },
-  { LSTRKEY( "DRAW_ALL" ),         LNUMVAL( UCG_DRAW_ALL ) },
+  LROT_NUMENTRY( DRAW_UPPER_RIGHT, UCG_DRAW_UPPER_RIGHT )
+  LROT_NUMENTRY( DRAW_UPPER_LEFT, UCG_DRAW_UPPER_LEFT )
+  LROT_NUMENTRY( DRAW_LOWER_RIGHT, UCG_DRAW_LOWER_RIGHT )
+  LROT_NUMENTRY( DRAW_LOWER_LEFT, UCG_DRAW_LOWER_LEFT )
+  LROT_NUMENTRY( DRAW_ALL, UCG_DRAW_ALL )
+
+  LROT_TABENTRY( __metatable, lucg )
+LROT_END( lucg, lucg, 0 )
 
-  { LSTRKEY( "__metatable" ), LROVAL( lucg_map ) },
-  { LNILKEY, LNILVAL }
-};
 
 int luaopen_ucg( lua_State *L )
 {
-    luaL_rometatable(L, "ucg.display", (void *)lucg_display_map);  // create metatable
+    luaL_rometatable(L, "ucg.display", LROT_TABLEREF(lucg_display));
     return 0;
 }
 
-NODEMCU_MODULE(UCG, "ucg", lucg_map, luaopen_ucg);
+NODEMCU_MODULE(UCG, "ucg", lucg, luaopen_ucg);
 
 #endif /* LUA_USE_MODULES_UCG */

+ 17 - 19
app/modules/websocket.c

@@ -307,28 +307,26 @@ static int websocketclient_gc(lua_State *L) {
   return 0;
 }
 
-static const LUA_REG_TYPE websocket_map[] =
-{
-  { LSTRKEY("createClient"), LFUNCVAL(websocket_createClient) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE websocketclient_map[] =
-{
-  { LSTRKEY("on"), LFUNCVAL(websocketclient_on) },
-  { LSTRKEY("config"), LFUNCVAL(websocketclient_config) },
-  { LSTRKEY("connect"), LFUNCVAL(websocketclient_connect) },
-  { LSTRKEY("send"), LFUNCVAL(websocketclient_send) },
-  { LSTRKEY("close"), LFUNCVAL(websocketclient_close) },
-  { LSTRKEY("__gc" ), LFUNCVAL(websocketclient_gc) },
-  { LSTRKEY("__index"), LROVAL(websocketclient_map) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(websocket)
+  LROT_FUNCENTRY( createClient, websocket_createClient )
+LROT_END( websocket, NULL, 0 )
+
+
+LROT_BEGIN(websocketclient)
+  LROT_FUNCENTRY( on, websocketclient_on )
+  LROT_FUNCENTRY( config, websocketclient_config )
+  LROT_FUNCENTRY( connect, websocketclient_connect )
+  LROT_FUNCENTRY( send, websocketclient_send )
+  LROT_FUNCENTRY( close, websocketclient_close )
+  LROT_FUNCENTRY( __gc, websocketclient_gc )
+  LROT_TABENTRY( __index, websocketclient )
+LROT_END( websocketclient, websocketclient, LROT_MASK_GC_INDEX )
+
 
 int loadWebsocketModule(lua_State *L) {
-  luaL_rometatable(L, METATABLE_WSCLIENT, (void *) websocketclient_map);
+  luaL_rometatable(L, METATABLE_WSCLIENT, LROT_TABLEREF( websocketclient));
 
   return 0;
 }
 
-NODEMCU_MODULE(WEBSOCKET, "websocket", websocket_map, loadWebsocketModule);
+NODEMCU_MODULE(WEBSOCKET, "websocket", websocket, loadWebsocketModule);

+ 102 - 102
app/modules/wifi.c

@@ -1864,114 +1864,114 @@ static int wifi_ap_dhcp_stop( lua_State* L )
 
 
 // Module function map
-static const LUA_REG_TYPE wifi_station_map[] = {
-  { LSTRKEY( "autoconnect" ),      LFUNCVAL( wifi_station_setauto ) },
-  { LSTRKEY( "changeap" ),         LFUNCVAL( wifi_station_change_ap ) },
-  { LSTRKEY( "clearconfig"),       LFUNCVAL( wifi_station_clear_config ) },
-  { LSTRKEY( "config" ),           LFUNCVAL( wifi_station_config ) },
-  { LSTRKEY( "connect" ),          LFUNCVAL( wifi_station_connect4lua ) },
-  { LSTRKEY( "disconnect" ),       LFUNCVAL( wifi_station_disconnect4lua ) },
-  { LSTRKEY( "getap" ),            LFUNCVAL( wifi_station_listap ) },
-  { LSTRKEY( "getapindex" ),       LFUNCVAL( wifi_station_get_ap_index ) },
-  { LSTRKEY( "getapinfo" ),        LFUNCVAL( wifi_station_get_ap_info4lua ) },
-  { LSTRKEY( "getbroadcast" ),     LFUNCVAL( wifi_station_getbroadcast) },
-  { LSTRKEY( "getconfig" ),        LFUNCVAL( wifi_station_getconfig_current ) },
-  { LSTRKEY( "getdefaultconfig" ), LFUNCVAL( wifi_station_getconfig_default ) },
-  { LSTRKEY( "gethostname" ),      LFUNCVAL( wifi_sta_gethostname ) },
-  { LSTRKEY( "getip" ),            LFUNCVAL( wifi_station_getip ) },
-  { LSTRKEY( "getmac" ),           LFUNCVAL( wifi_station_getmac ) },
-  { LSTRKEY( "getrssi" ),          LFUNCVAL( wifi_station_getrssi ) },
-  { LSTRKEY( "setaplimit" ),       LFUNCVAL( wifi_station_ap_number_set4lua ) },
-  { LSTRKEY( "sethostname" ),      LFUNCVAL( wifi_sta_sethostname_lua ) },
-  { LSTRKEY( "setip" ),            LFUNCVAL( wifi_station_setip ) },
-  { LSTRKEY( "setmac" ),           LFUNCVAL( wifi_station_setmac ) },
-  { LSTRKEY( "sleeptype" ),        LFUNCVAL( wifi_station_sleeptype ) },
-  { LSTRKEY( "status" ),           LFUNCVAL( wifi_station_status ) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE wifi_ap_dhcp_map[] = {
-  { LSTRKEY( "config" ),  LFUNCVAL( wifi_ap_dhcp_config ) },
-  { LSTRKEY( "start" ),   LFUNCVAL( wifi_ap_dhcp_start ) },
-  { LSTRKEY( "stop" ),    LFUNCVAL( wifi_ap_dhcp_stop ) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE wifi_ap_map[] = {
-  { LSTRKEY( "config" ),              LFUNCVAL( wifi_ap_config ) },
-  { LSTRKEY( "deauth" ),              LFUNCVAL( wifi_ap_deauth ) },
-  { LSTRKEY( "getip" ),               LFUNCVAL( wifi_ap_getip ) },
-  { LSTRKEY( "setip" ),               LFUNCVAL( wifi_ap_setip ) },
-  { LSTRKEY( "getbroadcast" ),        LFUNCVAL( wifi_ap_getbroadcast) },
-  { LSTRKEY( "getmac" ),              LFUNCVAL( wifi_ap_getmac ) },
-  { LSTRKEY( "setmac" ),              LFUNCVAL( wifi_ap_setmac ) },
-  { LSTRKEY( "getclient" ),           LFUNCVAL( wifi_ap_listclient ) },
-  { LSTRKEY( "getconfig" ),           LFUNCVAL( wifi_ap_getconfig_current ) },
-  { LSTRKEY( "getdefaultconfig" ),    LFUNCVAL( wifi_ap_getconfig_default ) },
-  { LSTRKEY( "dhcp" ),                LROVAL( wifi_ap_dhcp_map ) },
-//{ LSTRKEY( "__metatable" ),         LROVAL( wifi_ap_map ) },
-  { LNILKEY, LNILVAL }
-};
-
-static const LUA_REG_TYPE wifi_map[] =  {
-  { LSTRKEY( "setmode" ),        LFUNCVAL( wifi_setmode ) },
-  { LSTRKEY( "getmode" ),        LFUNCVAL( wifi_getmode ) },
-  { LSTRKEY( "getdefaultmode" ), LFUNCVAL( wifi_getdefaultmode ) },
-  { LSTRKEY( "getchannel" ),     LFUNCVAL( wifi_getchannel ) },
-  { LSTRKEY( "getcountry" ),     LFUNCVAL( wifi_getcountry ) },
-  { LSTRKEY( "setcountry" ),     LFUNCVAL( wifi_setcountry ) },
-  { LSTRKEY( "setphymode" ),     LFUNCVAL( wifi_setphymode ) },
-  { LSTRKEY( "getphymode" ),     LFUNCVAL( wifi_getphymode ) },
-  { LSTRKEY( "setmaxtxpower" ),  LFUNCVAL( wifi_setmaxtxpower ) },
-  { LSTRKEY( "suspend" ),        LFUNCVAL( wifi_suspend ) },
-  { LSTRKEY( "resume" ),         LFUNCVAL( wifi_resume ) },
-  { LSTRKEY( "nullmodesleep" ),  LFUNCVAL( wifi_null_mode_auto_sleep ) },
+LROT_BEGIN(wifi_station)
+  LROT_FUNCENTRY( autoconnect, wifi_station_setauto )
+  LROT_FUNCENTRY( changeap, wifi_station_change_ap )
+  LROT_FUNCENTRY( clearconfig, wifi_station_clear_config )
+  LROT_FUNCENTRY( config, wifi_station_config )
+  LROT_FUNCENTRY( connect, wifi_station_connect4lua )
+  LROT_FUNCENTRY( disconnect, wifi_station_disconnect4lua )
+  LROT_FUNCENTRY( getap, wifi_station_listap )
+  LROT_FUNCENTRY( getapindex, wifi_station_get_ap_index )
+  LROT_FUNCENTRY( getapinfo, wifi_station_get_ap_info4lua )
+  LROT_FUNCENTRY( getbroadcast, wifi_station_getbroadcast )
+  LROT_FUNCENTRY( getconfig, wifi_station_getconfig_current )
+  LROT_FUNCENTRY( getdefaultconfig, wifi_station_getconfig_default )
+  LROT_FUNCENTRY( gethostname, wifi_sta_gethostname )
+  LROT_FUNCENTRY( getip, wifi_station_getip )
+  LROT_FUNCENTRY( getmac, wifi_station_getmac )
+  LROT_FUNCENTRY( getrssi, wifi_station_getrssi )
+  LROT_FUNCENTRY( setaplimit, wifi_station_ap_number_set4lua )
+  LROT_FUNCENTRY( sethostname, wifi_sta_sethostname_lua )
+  LROT_FUNCENTRY( setip, wifi_station_setip )
+  LROT_FUNCENTRY( setmac, wifi_station_setmac )
+  LROT_FUNCENTRY( sleeptype, wifi_station_sleeptype )
+  LROT_FUNCENTRY( status, wifi_station_status )
+LROT_END( wifi_station, wifi_station, 0 )
+
+
+LROT_BEGIN(wifi_ap_dhcp)
+  LROT_FUNCENTRY( config, wifi_ap_dhcp_config )
+  LROT_FUNCENTRY( start, wifi_ap_dhcp_start )
+  LROT_FUNCENTRY( stop, wifi_ap_dhcp_stop )
+LROT_END( wifi_ap_dhcp, wifi_ap_dhcp, 0 )
+
+
+LROT_BEGIN(wifi_ap)
+  LROT_FUNCENTRY( config, wifi_ap_config )
+  LROT_FUNCENTRY( deauth, wifi_ap_deauth )
+  LROT_FUNCENTRY( getip, wifi_ap_getip )
+  LROT_FUNCENTRY( setip, wifi_ap_setip )
+  LROT_FUNCENTRY( getbroadcast, wifi_ap_getbroadcast )
+  LROT_FUNCENTRY( getmac, wifi_ap_getmac )
+  LROT_FUNCENTRY( setmac, wifi_ap_setmac )
+  LROT_FUNCENTRY( getclient, wifi_ap_listclient )
+  LROT_FUNCENTRY( getconfig, wifi_ap_getconfig_current )
+  LROT_FUNCENTRY( getdefaultconfig, wifi_ap_getconfig_default )
+  LROT_TABENTRY( dhcp, wifi_ap_dhcp )
+//  LROT_TABENTRY( __metatable, wifi_ap )
+LROT_END( wifi_ap, wifi_ap, 0 )
+
+
+LROT_BEGIN(wifi)
+  LROT_FUNCENTRY( setmode, wifi_setmode )
+  LROT_FUNCENTRY( getmode, wifi_getmode )
+  LROT_FUNCENTRY( getdefaultmode, wifi_getdefaultmode )
+  LROT_FUNCENTRY( getchannel, wifi_getchannel )
+  LROT_FUNCENTRY( getcountry, wifi_getcountry )
+  LROT_FUNCENTRY( setcountry, wifi_setcountry )
+  LROT_FUNCENTRY( setphymode, wifi_setphymode )
+  LROT_FUNCENTRY( getphymode, wifi_getphymode )
+  LROT_FUNCENTRY( setmaxtxpower, wifi_setmaxtxpower )
+  LROT_FUNCENTRY( suspend, wifi_suspend )
+  LROT_FUNCENTRY( resume, wifi_resume )
+  LROT_FUNCENTRY( nullmodesleep, wifi_null_mode_auto_sleep )
 #ifdef WIFI_SMART_ENABLE
-  { LSTRKEY( "startsmart" ),     LFUNCVAL( wifi_start_smart ) },
-  { LSTRKEY( "stopsmart" ),      LFUNCVAL( wifi_exit_smart ) },
+  LROT_FUNCENTRY( startsmart, wifi_start_smart )
+  LROT_FUNCENTRY( stopsmart, wifi_exit_smart )
 #endif
-  { LSTRKEY( "sleeptype" ),      LFUNCVAL( wifi_station_sleeptype ) },
+  LROT_FUNCENTRY( sleeptype, wifi_station_sleeptype )
 
-  { LSTRKEY( "sta" ),            LROVAL( wifi_station_map ) },
-  { LSTRKEY( "ap" ),             LROVAL( wifi_ap_map ) },
+  LROT_TABENTRY( sta, wifi_station )
+  LROT_TABENTRY( ap, wifi_ap )
 #if defined(WIFI_SDK_EVENT_MONITOR_ENABLE)
-  { LSTRKEY( "eventmon" ),       LROVAL( wifi_event_monitor_map ) }, //declared in wifi_eventmon.c
+  LROT_TABENTRY( eventmon, wifi_event_monitor )
 #endif
 #if defined(LUA_USE_MODULES_WIFI_MONITOR)
-  { LSTRKEY( "monitor" ),        LROVAL( wifi_monitor_map ) }, //declared in wifi_monitor.c
+  LROT_TABENTRY( monitor, wifi_monitor )
 #endif
-  { LSTRKEY( "NULLMODE" ),       LNUMVAL( NULL_MODE ) },
-  { LSTRKEY( "STATION" ),        LNUMVAL( STATION_MODE ) },
-  { LSTRKEY( "SOFTAP" ),         LNUMVAL( SOFTAP_MODE ) },
-  { LSTRKEY( "STATIONAP" ),      LNUMVAL( STATIONAP_MODE ) },
-
-  { LSTRKEY( "PHYMODE_B" ),      LNUMVAL( PHY_MODE_11B ) },
-  { LSTRKEY( "PHYMODE_G" ),      LNUMVAL( PHY_MODE_11G ) },
-  { LSTRKEY( "PHYMODE_N" ),      LNUMVAL( PHY_MODE_11N ) },
-
-  { LSTRKEY( "NONE_SLEEP" ),     LNUMVAL( NONE_SLEEP_T ) },
-  { LSTRKEY( "LIGHT_SLEEP" ),    LNUMVAL( LIGHT_SLEEP_T ) },
-  { LSTRKEY( "MODEM_SLEEP" ),    LNUMVAL( MODEM_SLEEP_T ) },
-
-  { LSTRKEY( "OPEN" ),           LNUMVAL( AUTH_OPEN ) },
-//{ LSTRKEY( "WEP" ),            LNUMVAL( AUTH_WEP ) },
-  { LSTRKEY( "WPA_PSK" ),        LNUMVAL( AUTH_WPA_PSK ) },
-  { LSTRKEY( "WPA2_PSK" ),       LNUMVAL( AUTH_WPA2_PSK ) },
-  { LSTRKEY( "WPA_WPA2_PSK" ),   LNUMVAL( AUTH_WPA_WPA2_PSK ) },
-
-  { LSTRKEY( "STA_IDLE" ),       LNUMVAL( STATION_IDLE ) },
-  { LSTRKEY( "STA_CONNECTING" ), LNUMVAL( STATION_CONNECTING ) },
-  { LSTRKEY( "STA_WRONGPWD" ),   LNUMVAL( STATION_WRONG_PASSWORD ) },
-  { LSTRKEY( "STA_APNOTFOUND" ), LNUMVAL( STATION_NO_AP_FOUND ) },
-  { LSTRKEY( "STA_FAIL" ),       LNUMVAL( STATION_CONNECT_FAIL ) },
-  { LSTRKEY( "STA_GOTIP" ),      LNUMVAL( STATION_GOT_IP ) },
-
-  { LSTRKEY( "COUNTRY_AUTO" ),   LNUMVAL( WIFI_COUNTRY_POLICY_AUTO ) },
-  { LSTRKEY( "COUNTRY_MANUAL" ), LNUMVAL( WIFI_COUNTRY_POLICY_MANUAL ) },
-
-  { LSTRKEY( "__metatable" ),    LROVAL( wifi_map ) },
-  { LNILKEY, LNILVAL }
-};
+  LROT_NUMENTRY( NULLMODE, NULL_MODE )
+  LROT_NUMENTRY( STATION, STATION_MODE )
+  LROT_NUMENTRY( SOFTAP, SOFTAP_MODE )
+  LROT_NUMENTRY( STATIONAP, STATIONAP_MODE )
+
+  LROT_NUMENTRY( PHYMODE_B, PHY_MODE_11B )
+  LROT_NUMENTRY( PHYMODE_G, PHY_MODE_11G )
+  LROT_NUMENTRY( PHYMODE_N, PHY_MODE_11N )
+
+  LROT_NUMENTRY( NONE_SLEEP, NONE_SLEEP_T )
+  LROT_NUMENTRY( LIGHT_SLEEP, LIGHT_SLEEP_T )
+  LROT_NUMENTRY( MODEM_SLEEP, MODEM_SLEEP_T )
+
+  LROT_NUMENTRY( OPEN, AUTH_OPEN )
+//  LROT_NUMENTRY( WEP, AUTH_WEP )
+  LROT_NUMENTRY( WPA_PSK, AUTH_WPA_PSK )
+  LROT_NUMENTRY( WPA2_PSK, AUTH_WPA2_PSK )
+  LROT_NUMENTRY( WPA_WPA2_PSK, AUTH_WPA_WPA2_PSK )
+
+  LROT_NUMENTRY( STA_IDLE, STATION_IDLE )
+  LROT_NUMENTRY( STA_CONNECTING, STATION_CONNECTING )
+  LROT_NUMENTRY( STA_WRONGPWD, STATION_WRONG_PASSWORD )
+  LROT_NUMENTRY( STA_APNOTFOUND, STATION_NO_AP_FOUND )
+  LROT_NUMENTRY( STA_FAIL, STATION_CONNECT_FAIL )
+  LROT_NUMENTRY( STA_GOTIP, STATION_GOT_IP )
+
+  LROT_NUMENTRY( COUNTRY_AUTO, WIFI_COUNTRY_POLICY_AUTO )
+  LROT_NUMENTRY( COUNTRY_MANUAL, WIFI_COUNTRY_POLICY_MANUAL )
+
+  LROT_TABENTRY( __metatable, wifi )
+LROT_END( wifi, wifi, 0 )
+
 
 // Used by user_rf_pre_init(user_main.c)
 void wifi_change_default_host_name(void)
@@ -2024,4 +2024,4 @@ int luaopen_wifi( lua_State *L )
  return 0;
 }
 
-NODEMCU_MODULE(WIFI, "wifi", wifi_map, luaopen_wifi);
+NODEMCU_MODULE(WIFI, "wifi", wifi, luaopen_wifi);

+ 2 - 2
app/modules/wifi_common.h

@@ -58,13 +58,13 @@ enum wifi_suspension_state{
 
 
 #ifdef WIFI_SDK_EVENT_MONITOR_ENABLE
-  extern const LUA_REG_TYPE wifi_event_monitor_map[];
+  LROT_EXTERN(wifi_event_monitor);
   void wifi_eventmon_init();
   int wifi_event_monitor_register(lua_State* L);
 #endif
 
 #ifdef LUA_USE_MODULES_WIFI_MONITOR
-  extern const LUA_REG_TYPE wifi_monitor_map[];
+  LROT_EXTERN(wifi_monitor);
   int wifi_monitor_init(lua_State *L);
 #endif
 

+ 47 - 49
app/modules/wifi_eventmon.c

@@ -247,59 +247,57 @@ static void wifi_event_monitor_process_event_queue(task_param_t param, uint8 pri
 }
 
 #ifdef WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE
-static const LUA_REG_TYPE wifi_event_monitor_reason_map[] =
-{
-  { LSTRKEY( "UNSPECIFIED" ),              LNUMVAL( REASON_UNSPECIFIED ) },
-  { LSTRKEY( "AUTH_EXPIRE" ),              LNUMVAL( REASON_AUTH_EXPIRE ) },
-  { LSTRKEY( "AUTH_LEAVE" ),               LNUMVAL( REASON_AUTH_LEAVE ) },
-  { LSTRKEY( "ASSOC_EXPIRE" ),             LNUMVAL( REASON_ASSOC_EXPIRE ) },
-  { LSTRKEY( "ASSOC_TOOMANY" ),            LNUMVAL( REASON_ASSOC_TOOMANY ) },
-  { LSTRKEY( "NOT_AUTHED" ),               LNUMVAL( REASON_NOT_AUTHED ) },
-  { LSTRKEY( "NOT_ASSOCED" ),              LNUMVAL( REASON_NOT_ASSOCED ) },
-  { LSTRKEY( "ASSOC_LEAVE" ),              LNUMVAL( REASON_ASSOC_LEAVE ) },
-  { LSTRKEY( "ASSOC_NOT_AUTHED" ),         LNUMVAL( REASON_ASSOC_NOT_AUTHED ) },
-  { LSTRKEY( "DISASSOC_PWRCAP_BAD" ),      LNUMVAL( REASON_DISASSOC_PWRCAP_BAD ) },
-  { LSTRKEY( "DISASSOC_SUPCHAN_BAD" ),     LNUMVAL( REASON_DISASSOC_SUPCHAN_BAD ) },
-  { LSTRKEY( "IE_INVALID" ),               LNUMVAL( REASON_IE_INVALID ) },
-  { LSTRKEY( "MIC_FAILURE" ),              LNUMVAL( REASON_MIC_FAILURE ) },
-  { LSTRKEY( "4WAY_HANDSHAKE_TIMEOUT" ),   LNUMVAL( REASON_4WAY_HANDSHAKE_TIMEOUT ) },
-  { LSTRKEY( "GROUP_KEY_UPDATE_TIMEOUT" ), LNUMVAL( REASON_GROUP_KEY_UPDATE_TIMEOUT ) },
-  { LSTRKEY( "IE_IN_4WAY_DIFFERS" ),       LNUMVAL( REASON_IE_IN_4WAY_DIFFERS ) },
-  { LSTRKEY( "GROUP_CIPHER_INVALID" ),     LNUMVAL( REASON_GROUP_CIPHER_INVALID ) },
-  { LSTRKEY( "PAIRWISE_CIPHER_INVALID" ),  LNUMVAL( REASON_PAIRWISE_CIPHER_INVALID ) },
-  { LSTRKEY( "AKMP_INVALID" ),             LNUMVAL( REASON_AKMP_INVALID ) },
-  { LSTRKEY( "UNSUPP_RSN_IE_VERSION" ),    LNUMVAL( REASON_UNSUPP_RSN_IE_VERSION ) },
-  { LSTRKEY( "INVALID_RSN_IE_CAP" ),       LNUMVAL( REASON_INVALID_RSN_IE_CAP ) },
-  { LSTRKEY( "802_1X_AUTH_FAILED" ),       LNUMVAL( REASON_802_1X_AUTH_FAILED ) },
-  { LSTRKEY( "CIPHER_SUITE_REJECTED" ),    LNUMVAL( REASON_CIPHER_SUITE_REJECTED ) },
-  { LSTRKEY( "BEACON_TIMEOUT" ),           LNUMVAL( REASON_BEACON_TIMEOUT ) },
-  { LSTRKEY( "NO_AP_FOUND" ),              LNUMVAL( REASON_NO_AP_FOUND ) },
-  { LSTRKEY( "AUTH_FAIL" ),                LNUMVAL( REASON_AUTH_FAIL ) },
-  { LSTRKEY( "ASSOC_FAIL" ),               LNUMVAL( REASON_ASSOC_FAIL ) },
-  { LSTRKEY( "HANDSHAKE_TIMEOUT" ),        LNUMVAL( REASON_HANDSHAKE_TIMEOUT ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(wifi_event_monitor_reason)
+  LROT_NUMENTRY( UNSPECIFIED, REASON_UNSPECIFIED )
+  LROT_NUMENTRY( AUTH_EXPIRE, REASON_AUTH_EXPIRE )
+  LROT_NUMENTRY( AUTH_LEAVE, REASON_AUTH_LEAVE )
+  LROT_NUMENTRY( ASSOC_EXPIRE, REASON_ASSOC_EXPIRE )
+  LROT_NUMENTRY( ASSOC_TOOMANY, REASON_ASSOC_TOOMANY )
+  LROT_NUMENTRY( NOT_AUTHED, REASON_NOT_AUTHED )
+  LROT_NUMENTRY( NOT_ASSOCED, REASON_NOT_ASSOCED )
+  LROT_NUMENTRY( ASSOC_LEAVE, REASON_ASSOC_LEAVE )
+  LROT_NUMENTRY( ASSOC_NOT_AUTHED, REASON_ASSOC_NOT_AUTHED )
+  LROT_NUMENTRY( DISASSOC_PWRCAP_BAD, REASON_DISASSOC_PWRCAP_BAD )
+  LROT_NUMENTRY( DISASSOC_SUPCHAN_BAD, REASON_DISASSOC_SUPCHAN_BAD )
+  LROT_NUMENTRY( IE_INVALID, REASON_IE_INVALID )
+  LROT_NUMENTRY( MIC_FAILURE, REASON_MIC_FAILURE )
+  LROT_NUMENTRY( 4WAY_HANDSHAKE_TIMEOUT, REASON_4WAY_HANDSHAKE_TIMEOUT )
+  LROT_NUMENTRY( GROUP_KEY_UPDATE_TIMEOUT, REASON_GROUP_KEY_UPDATE_TIMEOUT )
+  LROT_NUMENTRY( IE_IN_4WAY_DIFFERS, REASON_IE_IN_4WAY_DIFFERS )
+  LROT_NUMENTRY( GROUP_CIPHER_INVALID, REASON_GROUP_CIPHER_INVALID )
+  LROT_NUMENTRY( PAIRWISE_CIPHER_INVALID, REASON_PAIRWISE_CIPHER_INVALID )
+  LROT_NUMENTRY( AKMP_INVALID, REASON_AKMP_INVALID )
+  LROT_NUMENTRY( UNSUPP_RSN_IE_VERSION, REASON_UNSUPP_RSN_IE_VERSION )
+  LROT_NUMENTRY( INVALID_RSN_IE_CAP, REASON_INVALID_RSN_IE_CAP )
+  LROT_NUMENTRY( 802_1X_AUTH_FAILED, REASON_802_1X_AUTH_FAILED )
+  LROT_NUMENTRY( CIPHER_SUITE_REJECTED, REASON_CIPHER_SUITE_REJECTED )
+  LROT_NUMENTRY( BEACON_TIMEOUT, REASON_BEACON_TIMEOUT )
+  LROT_NUMENTRY( NO_AP_FOUND, REASON_NO_AP_FOUND )
+  LROT_NUMENTRY( AUTH_FAIL, REASON_AUTH_FAIL )
+  LROT_NUMENTRY( ASSOC_FAIL, REASON_ASSOC_FAIL )
+  LROT_NUMENTRY( HANDSHAKE_TIMEOUT, REASON_HANDSHAKE_TIMEOUT )
+LROT_END( wifi_event_monitor_reason, NULL, 0 )
+
 #endif
 
-const LUA_REG_TYPE wifi_event_monitor_map[] =
-{
-  { LSTRKEY( "register" ),            LFUNCVAL( wifi_event_monitor_register ) },
-  { LSTRKEY( "unregister" ),          LFUNCVAL( wifi_event_monitor_register ) },
-  { LSTRKEY( "STA_CONNECTED" ),       LNUMVAL( EVENT_STAMODE_CONNECTED ) },
-  { LSTRKEY( "STA_DISCONNECTED" ),    LNUMVAL( EVENT_STAMODE_DISCONNECTED ) },
-  { LSTRKEY( "STA_AUTHMODE_CHANGE" ), LNUMVAL( EVENT_STAMODE_AUTHMODE_CHANGE ) },
-  { LSTRKEY( "STA_GOT_IP" ),          LNUMVAL( EVENT_STAMODE_GOT_IP ) },
-  { LSTRKEY( "STA_DHCP_TIMEOUT" ),    LNUMVAL( EVENT_STAMODE_DHCP_TIMEOUT ) },
-  { LSTRKEY( "AP_STACONNECTED" ),     LNUMVAL( EVENT_SOFTAPMODE_STACONNECTED ) },
-  { LSTRKEY( "AP_STADISCONNECTED" ),  LNUMVAL( EVENT_SOFTAPMODE_STADISCONNECTED ) },
-  { LSTRKEY( "AP_PROBEREQRECVED" ),   LNUMVAL( EVENT_SOFTAPMODE_PROBEREQRECVED ) },
-  { LSTRKEY( "WIFI_MODE_CHANGED" ),   LNUMVAL( EVENT_OPMODE_CHANGED ) },
-  { LSTRKEY( "EVENT_MAX" ),           LNUMVAL( EVENT_MAX ) },
+LROT_PUBLIC_BEGIN(wifi_event_monitor)
+  LROT_FUNCENTRY( register, wifi_event_monitor_register )
+  LROT_FUNCENTRY( unregister, wifi_event_monitor_register )
+  LROT_NUMENTRY( STA_CONNECTED, EVENT_STAMODE_CONNECTED )
+  LROT_NUMENTRY( STA_DISCONNECTED, EVENT_STAMODE_DISCONNECTED )
+  LROT_NUMENTRY( STA_AUTHMODE_CHANGE, EVENT_STAMODE_AUTHMODE_CHANGE )
+  LROT_NUMENTRY( STA_GOT_IP, EVENT_STAMODE_GOT_IP )
+  LROT_NUMENTRY( STA_DHCP_TIMEOUT, EVENT_STAMODE_DHCP_TIMEOUT )
+  LROT_NUMENTRY( AP_STACONNECTED, EVENT_SOFTAPMODE_STACONNECTED )
+  LROT_NUMENTRY( AP_STADISCONNECTED, EVENT_SOFTAPMODE_STADISCONNECTED )
+  LROT_NUMENTRY( AP_PROBEREQRECVED, EVENT_SOFTAPMODE_PROBEREQRECVED )
+  LROT_NUMENTRY( WIFI_MODE_CHANGED, EVENT_OPMODE_CHANGED )
+  LROT_NUMENTRY( EVENT_MAX, EVENT_MAX )
 #ifdef WIFI_EVENT_MONITOR_DISCONNECT_REASON_LIST_ENABLE
-  { LSTRKEY( "reason" ),              LROVAL( wifi_event_monitor_reason_map ) },
+  LROT_TABENTRY( reason, wifi_event_monitor_reason )
 #endif
-  { LNILKEY, LNILVAL }
-};
+LROT_END( wifi_event_monitor, NULL, 0 )
+
 
 void wifi_eventmon_init()
 {

+ 22 - 22
app/modules/wifi_monitor.c

@@ -276,7 +276,7 @@ typedef struct {
   uint8 buf[];
 } packet_t;
 
-static const LUA_REG_TYPE packet_function_map[];
+LROT_TABLE(packet_function)
 
 static void wifi_rx_cb(uint8 *buf, uint16 len) {
   if (len != sizeof(struct sniffer_buf2)) {
@@ -570,7 +570,7 @@ static int packet_map_lookup(lua_State *L) {
     }
 
     // Now search the packet function map
-    lua_pushrotable(L, (void *)packet_function_map);
+    lua_pushrotable(L, LROT_TABLEREF(packet_function));
     lua_getfield(L, -1, field);
     if (!lua_isnil(L, -1)) {
       return 1;
@@ -757,32 +757,32 @@ static int wifi_monitor_stop(lua_State *L) {
   return 0;
 }
 
-static const LUA_REG_TYPE packet_function_map[] = {
-  { LSTRKEY( "radio_byte" ),        LFUNCVAL( packet_radio_byte ) },
-  { LSTRKEY( "frame_byte" ),        LFUNCVAL( packet_frame_byte ) },
-  { LSTRKEY( "radio_sub" ),         LFUNCVAL( packet_radio_sub ) },
-  { LSTRKEY( "frame_sub" ),         LFUNCVAL( packet_frame_sub ) },
-  { LSTRKEY( "radio_subhex" ),      LFUNCVAL( packet_radio_subhex ) },
-  { LSTRKEY( "frame_subhex" ),      LFUNCVAL( packet_frame_subhex ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(packet_function)
+  LROT_FUNCENTRY( radio_byte, packet_radio_byte )
+  LROT_FUNCENTRY( frame_byte, packet_frame_byte )
+  LROT_FUNCENTRY( radio_sub, packet_radio_sub )
+  LROT_FUNCENTRY( frame_sub, packet_frame_sub )
+  LROT_FUNCENTRY( radio_subhex, packet_radio_subhex )
+  LROT_FUNCENTRY( frame_subhex, packet_frame_subhex )
+LROT_END( packet_function, packet_function, LROT_MASK_INDEX )
+
+
+LROT_BEGIN(packet)
+  LROT_FUNCENTRY( __index, packet_map_lookup )
+LROT_END( packet, packet, LROT_MASK_INDEX )
 
-static const LUA_REG_TYPE packet_map[] = {
-  { LSTRKEY( "__index" ),     LFUNCVAL( packet_map_lookup ) },
-  { LNILKEY, LNILVAL }
-};
 
 // Module function map
-const LUA_REG_TYPE wifi_monitor_map[] = {
-  { LSTRKEY( "start" ),      LFUNCVAL( wifi_monitor_start ) },
-  { LSTRKEY( "stop" ),       LFUNCVAL( wifi_monitor_stop ) },
-  { LSTRKEY( "channel" ),    LFUNCVAL( wifi_monitor_channel ) },
-  { LNILKEY, LNILVAL }
-};
+LROT_PUBLIC_BEGIN(wifi_monitor)
+  LROT_FUNCENTRY( start, wifi_monitor_start )
+  LROT_FUNCENTRY( stop, wifi_monitor_stop )
+  LROT_FUNCENTRY( channel, wifi_monitor_channel )
+LROT_END( wifi_monitor, NULL, 0 )
+
 
 int wifi_monitor_init(lua_State *L)
 {
-  luaL_rometatable(L, "wifi.packet", (void *)packet_map);
+  luaL_rometatable(L, "wifi.packet", LROT_TABLEREF(packet));
   tasknumber = task_get_id(monitor_task);
   eventmon_setup();
 

+ 12 - 12
app/modules/wps.c

@@ -52,22 +52,22 @@ static int ICACHE_FLASH_ATTR wps_start(lua_State* L)
 }
 
 // Module function map
-const LUA_REG_TYPE wps_map[] = {
-  { LSTRKEY( "disable" ),  LFUNCVAL( wps_disable ) },
-  { LSTRKEY( "enable" ),   LFUNCVAL( wps_enable ) },
-  { LSTRKEY( "start" ),    LFUNCVAL( wps_start ) },
-  { LSTRKEY( "SUCCESS" ),  LNUMVAL( WPS_CB_ST_SUCCESS ) },
-  { LSTRKEY( "FAILED" ),   LNUMVAL( WPS_CB_ST_FAILED ) },
-  { LSTRKEY( "TIMEOUT" ),  LNUMVAL( WPS_CB_ST_TIMEOUT ) },
-  { LSTRKEY( "WEP" ),      LNUMVAL( WPS_CB_ST_WEP ) },
-  { LSTRKEY( "SCAN_ERR" ), LNUMVAL( 4 ) }, // WPS_CB_ST_SCAN_ERR
-  { LNILKEY, LNILVAL }
-};
+LROT_BEGIN(wps)
+  LROT_FUNCENTRY( disable, wps_disable )
+  LROT_FUNCENTRY( enable, wps_enable )
+  LROT_FUNCENTRY( start, wps_start )
+  LROT_NUMENTRY( SUCCESS, WPS_CB_ST_SUCCESS )
+  LROT_NUMENTRY( FAILED, WPS_CB_ST_FAILED )
+  LROT_NUMENTRY( TIMEOUT, WPS_CB_ST_TIMEOUT )
+  LROT_NUMENTRY( WEP, WPS_CB_ST_WEP )
+  LROT_NUMENTRY( SCAN_ERR, 4 )
+LROT_END( wps, NULL, 0 )
+
 
 int luaopen_wps( lua_State *L )
 {
   return 0;
 }
 
-NODEMCU_MODULE(WPS, "wps", wps_map, luaopen_wps);
+NODEMCU_MODULE(WPS, "wps", wps, luaopen_wps);
 

+ 7 - 8
app/modules/ws2801.c

@@ -122,11 +122,10 @@ static int ICACHE_FLASH_ATTR ws2801_writergb(lua_State* L) {
     return 0;
 }
 
-static const LUA_REG_TYPE ws2801_map[] =
-{
-    { LSTRKEY( "write" ), LFUNCVAL( ws2801_writergb )},
-    { LSTRKEY( "init" ), LFUNCVAL( ws2801_init_lua )},
-    { LNILKEY, LNILVAL}
-};
-
-NODEMCU_MODULE(WS2801, "ws2801", ws2801_map, NULL);
+LROT_BEGIN(ws2801)
+  LROT_FUNCENTRY( write, ws2801_writergb )
+  LROT_FUNCENTRY( init, ws2801_init_lua )
+LROT_END( ws2801, NULL, 0 )
+
+
+NODEMCU_MODULE(WS2801, "ws2801", ws2801, NULL);

+ 33 - 35
app/modules/ws2812.c

@@ -591,44 +591,42 @@ static int ws2812_buffer_tostring(lua_State* L) {
 }
 
 
-static const LUA_REG_TYPE ws2812_buffer_map[] =
-{
-  { LSTRKEY( "dump" ),    LFUNCVAL( ws2812_buffer_dump )},
-  { LSTRKEY( "fade" ),    LFUNCVAL( ws2812_buffer_fade )},
-  { LSTRKEY( "fill" ),    LFUNCVAL( ws2812_buffer_fill_lua )},
-  { LSTRKEY( "get" ),     LFUNCVAL( ws2812_buffer_get )},
-  { LSTRKEY( "replace" ), LFUNCVAL( ws2812_buffer_replace )},
-  { LSTRKEY( "mix" ),     LFUNCVAL( ws2812_buffer_mix )},
-  { LSTRKEY( "power" ),   LFUNCVAL( ws2812_buffer_power )},
-  { LSTRKEY( "set" ),     LFUNCVAL( ws2812_buffer_set )},
-  { LSTRKEY( "shift" ),   LFUNCVAL( ws2812_buffer_shift_lua )},
-  { LSTRKEY( "size" ),    LFUNCVAL( ws2812_buffer_size )},
-  { LSTRKEY( "sub" ),     LFUNCVAL( ws2812_buffer_sub )},
-  { LSTRKEY( "__concat" ),LFUNCVAL( ws2812_buffer_concat )},
-  { LSTRKEY( "__index" ), LROVAL( ws2812_buffer_map )},
-  { LSTRKEY( "__tostring" ), LFUNCVAL( ws2812_buffer_tostring )},
-  { LNILKEY, LNILVAL}
-};
-
-
-static const LUA_REG_TYPE ws2812_map[] =
-{
-  { LSTRKEY( "init" ),           LFUNCVAL( ws2812_init )},
-  { LSTRKEY( "newBuffer" ),      LFUNCVAL( ws2812_new_buffer )},
-  { LSTRKEY( "write" ),          LFUNCVAL( ws2812_write )},
-  { LSTRKEY( "FADE_IN" ),        LNUMVAL( FADE_IN ) },
-  { LSTRKEY( "FADE_OUT" ),       LNUMVAL( FADE_OUT ) },
-  { LSTRKEY( "MODE_SINGLE" ),    LNUMVAL( MODE_SINGLE ) },
-  { LSTRKEY( "MODE_DUAL" ),      LNUMVAL( MODE_DUAL ) },
-  { LSTRKEY( "SHIFT_LOGICAL" ),  LNUMVAL( SHIFT_LOGICAL ) },
-  { LSTRKEY( "SHIFT_CIRCULAR" ), LNUMVAL( SHIFT_CIRCULAR ) },
-  { LNILKEY, LNILVAL}
-};
+LROT_BEGIN(ws2812_buffer)
+  LROT_FUNCENTRY( dump, ws2812_buffer_dump )
+  LROT_FUNCENTRY( fade, ws2812_buffer_fade )
+  LROT_FUNCENTRY( fill, ws2812_buffer_fill_lua )
+  LROT_FUNCENTRY( get, ws2812_buffer_get )
+  LROT_FUNCENTRY( replace, ws2812_buffer_replace )
+  LROT_FUNCENTRY( mix, ws2812_buffer_mix )
+  LROT_FUNCENTRY( power, ws2812_buffer_power )
+  LROT_FUNCENTRY( set, ws2812_buffer_set )
+  LROT_FUNCENTRY( shift, ws2812_buffer_shift_lua )
+  LROT_FUNCENTRY( size, ws2812_buffer_size )
+  LROT_FUNCENTRY( sub, ws2812_buffer_sub )
+  LROT_FUNCENTRY( __concat, ws2812_buffer_concat )
+  LROT_TABENTRY( __index, ws2812_buffer )
+  LROT_FUNCENTRY( __tostring, ws2812_buffer_tostring )
+LROT_END( ws2812_buffer, ws2812_buffer, LROT_MASK_INDEX )
+
+
+
+LROT_BEGIN(ws2812)
+  LROT_FUNCENTRY( init, ws2812_init )
+  LROT_FUNCENTRY( newBuffer, ws2812_new_buffer )
+  LROT_FUNCENTRY( write, ws2812_write )
+  LROT_NUMENTRY( FADE_IN, FADE_IN )
+  LROT_NUMENTRY( FADE_OUT, FADE_OUT )
+  LROT_NUMENTRY( MODE_SINGLE, MODE_SINGLE )
+  LROT_NUMENTRY( MODE_DUAL, MODE_DUAL )
+  LROT_NUMENTRY( SHIFT_LOGICAL, SHIFT_LOGICAL )
+  LROT_NUMENTRY( SHIFT_CIRCULAR, SHIFT_CIRCULAR )
+LROT_END( ws2812, NULL, 0 )
+
 
 int luaopen_ws2812(lua_State *L) {
   // TODO: Make sure that the GPIO system is initialized
-  luaL_rometatable(L, "ws2812.buffer", (void *)ws2812_buffer_map);  // create metatable for ws2812.buffer
+  luaL_rometatable(L, "ws2812.buffer", LROT_TABLEREF(ws2812_buffer));
   return 0;
 }
 
-NODEMCU_MODULE(WS2812, "ws2812", ws2812_map, luaopen_ws2812);
+NODEMCU_MODULE(WS2812, "ws2812", ws2812, luaopen_ws2812);

+ 17 - 18
app/modules/ws2812_effects.c

@@ -1038,23 +1038,22 @@ static int ws2812_effects_tostring(lua_State* L) {
   return 1;
 }
 
-static const LUA_REG_TYPE ws2812_effects_map[] =
-{
-  { LSTRKEY( "init" ),              LFUNCVAL( ws2812_effects_init )},
-  { LSTRKEY( "set_brightness" ),    LFUNCVAL( ws2812_effects_set_brightness )},
-  { LSTRKEY( "set_color" ),         LFUNCVAL( ws2812_effects_set_color )},
-  { LSTRKEY( "set_speed" ),         LFUNCVAL( ws2812_effects_set_speed )},
-  { LSTRKEY( "set_delay" ),         LFUNCVAL( ws2812_effects_set_delay )},
-  { LSTRKEY( "set_mode" ),          LFUNCVAL( ws2812_effects_set_mode )},
-  { LSTRKEY( "start" ),             LFUNCVAL( ws2812_effects_start )},
-  { LSTRKEY( "stop" ),              LFUNCVAL( ws2812_effects_stop )},
-  { LSTRKEY( "get_delay" ),         LFUNCVAL( ws2812_effects_get_delay )},
-  { LSTRKEY( "get_speed" ),         LFUNCVAL( ws2812_effects_get_speed )},
-
-  { LSTRKEY( "__index" ), LROVAL( ws2812_effects_map )},
-  { LSTRKEY( "__tostring" ), LFUNCVAL( ws2812_effects_tostring )},
-  { LNILKEY, LNILVAL}
-};
+LROT_BEGIN(ws2812_effects)
+  LROT_FUNCENTRY( init, ws2812_effects_init )
+  LROT_FUNCENTRY( set_brightness, ws2812_effects_set_brightness )
+  LROT_FUNCENTRY( set_color, ws2812_effects_set_color )
+  LROT_FUNCENTRY( set_speed, ws2812_effects_set_speed )
+  LROT_FUNCENTRY( set_delay, ws2812_effects_set_delay )
+  LROT_FUNCENTRY( set_mode, ws2812_effects_set_mode )
+  LROT_FUNCENTRY( start, ws2812_effects_start )
+  LROT_FUNCENTRY( stop, ws2812_effects_stop )
+  LROT_FUNCENTRY( get_delay, ws2812_effects_get_delay )
+  LROT_FUNCENTRY( get_speed, ws2812_effects_get_speed )
+
+  LROT_TABENTRY( __index, ws2812_effects )
+  LROT_FUNCENTRY( __tostring, ws2812_effects_tostring )
+LROT_END( ws2812_effects, ws2812_effects, LROT_MASK_INDEX )
+
 
 
-NODEMCU_MODULE(WS2812_EFFECTS, "ws2812_effects", ws2812_effects_map, NULL);
+NODEMCU_MODULE(WS2812_EFFECTS, "ws2812_effects", ws2812_effects, NULL);

+ 12 - 12
app/modules/xpt2046.c

@@ -203,15 +203,15 @@ static int xpt2046_getPositionAvg( lua_State* L ) {
 }
 
 // Module function map
-static const LUA_REG_TYPE xpt2046_map[] = {
-  { LSTRKEY( "isTouched"),      LFUNCVAL(xpt2046_isTouched)  },
-  { LSTRKEY( "getRaw"   ),      LFUNCVAL(xpt2046_getRaw)     },
-  { LSTRKEY( "getPosition"),    LFUNCVAL(xpt2046_getPosition)},
-  { LSTRKEY( "getPositionAvg"), LFUNCVAL(xpt2046_getPositionAvg)},
-  { LSTRKEY( "setCalibration"), LFUNCVAL(xpt2046_setCalibration)},
-  { LSTRKEY( "init"    ),       LFUNCVAL(xpt2046_init)      },
-  { LNILKEY, LNILVAL }
-};
-
-
-NODEMCU_MODULE(XPT2046, "xpt2046", xpt2046_map, NULL);
+LROT_BEGIN(xpt2046)
+  LROT_FUNCENTRY( isTouched, xpt2046_isTouched )
+  LROT_FUNCENTRY( getRaw, xpt2046_getRaw )
+  LROT_FUNCENTRY( getPosition, xpt2046_getPosition )
+  LROT_FUNCENTRY( getPositionAvg, xpt2046_getPositionAvg )
+  LROT_FUNCENTRY( setCalibration, xpt2046_setCalibration )
+  LROT_FUNCENTRY( init, xpt2046_init )
+LROT_END( xpt2046, NULL, 0 )
+
+
+
+NODEMCU_MODULE(XPT2046, "xpt2046", xpt2046, NULL);

+ 9 - 9
app/pm/swtimer.c

@@ -530,15 +530,15 @@ int resume_timers_lua(lua_State* L){
   return 0;
 }
 
-static const LUA_REG_TYPE test_swtimer_debug_map[] = {
-    { LSTRKEY( "timer_list" ),   LFUNCVAL( print_timer_list ) },
-    { LSTRKEY( "susp_timer_list" ),   LFUNCVAL( print_susp_timer_list ) },
-    { LSTRKEY( "suspend" ),      LFUNCVAL( suspend_timers_lua ) },
-    { LSTRKEY( "resume" ),      LFUNCVAL( resume_timers_lua ) },
-    { LNILKEY, LNILVAL }
-};
-
-NODEMCU_MODULE(SWTMR_DBG, "SWTMR_DBG", test_swtimer_debug_map, NULL);
+LROT_BEGIN(test_swtimer_debug)
+  LROT_FUNCENTRY( timer_list, print_timer_list )
+  LROT_FUNCENTRY( susp_timer_list, print_susp_timer_list )
+  LROT_FUNCENTRY( suspend, suspend_timers_lua )
+  LROT_FUNCENTRY( resume, resume_timers_lua )
+LROT_END( test_swtimer_debug, NULL, 0 )
+
+
+NODEMCU_MODULE(SWTMR_DBG, "SWTMR_DBG", test_swtimer_debug, NULL);
 
 #endif