diff --git a/app/Makefile b/app/Makefile index bc0bfa9e..62819e9d 100644 --- a/app/Makefile +++ b/app/Makefile @@ -134,9 +134,11 @@ 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 + -DEBUF_LWIP \ DEFINES += \ $(UNIVERSAL_TARGET_DEFINES) \ diff --git a/app/lua/lbaselib.c b/app/lua/lbaselib.c index 7c05a6ea..02dad463 100644 --- a/app/lua/lbaselib.c +++ b/app/lua/lbaselib.c @@ -489,6 +489,7 @@ static int luaB_newproxy (lua_State *L) { {LSTRKEY("xpcall"), LFUNCVAL(luaB_xpcall)} #if LUA_OPTIMIZE_MEMORY == 2 +#undef MIN_OPT_LEVEL #define MIN_OPT_LEVEL 2 #include "lrodefs.h" const LUA_REG_TYPE base_funcs_list[] = { diff --git a/app/lua/ldblib.c b/app/lua/ldblib.c index c9eaa644..10978970 100644 --- a/app/lua/ldblib.c +++ b/app/lua/ldblib.c @@ -383,6 +383,7 @@ 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[] = { diff --git a/app/lua/liolib.c b/app/lua/liolib.c index b6e377ff..654dd6fa 100644 --- a/app/lua/liolib.c +++ b/app/lua/liolib.c @@ -538,6 +538,7 @@ static int f_flush (lua_State *L) { return pushresult(L, fs_flush(tofile(L)) == 0, NULL); } +#undef MIN_OPT_LEVEL #define MIN_OPT_LEVEL 2 #include "lrodefs.h" #if LUA_OPTIMIZE_MEMORY == 2 diff --git a/app/lua/lmathlib.c b/app/lua/lmathlib.c index 42ab2b8a..e3fda445 100644 --- a/app/lua/lmathlib.c +++ b/app/lua/lmathlib.c @@ -311,6 +311,7 @@ static int math_randomseed (lua_State *L) { +#undef MIN_OPT_LEVEL #define MIN_OPT_LEVEL 1 #include "lrodefs.h" const LUA_REG_TYPE math_map[] = { diff --git a/app/lua/loadlib.c b/app/lua/loadlib.c index 00e8f8dd..6a0aaf17 100644 --- a/app/lua/loadlib.c +++ b/app/lua/loadlib.c @@ -646,6 +646,7 @@ 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[] = { diff --git a/app/lua/lstrlib.c b/app/lua/lstrlib.c index 58f702ac..4271c282 100644 --- a/app/lua/lstrlib.c +++ b/app/lua/lstrlib.c @@ -825,6 +825,7 @@ 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[] = { diff --git a/app/lua/ltablib.c b/app/lua/ltablib.c index a7182b00..8b0a810b 100644 --- a/app/lua/ltablib.c +++ b/app/lua/ltablib.c @@ -266,6 +266,7 @@ static int sort (lua_State *L) { /* }====================================================== */ +#undef MIN_OPT_LEVEL #define MIN_OPT_LEVEL 1 #include "lrodefs.h" const LUA_REG_TYPE tab_funcs[] = { diff --git a/app/lua/luac_cross/loslib.c b/app/lua/luac_cross/loslib.c index 5bff693b..a35d2941 100644 --- a/app/lua/luac_cross/loslib.c +++ b/app/lua/luac_cross/loslib.c @@ -221,6 +221,7 @@ 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[] = { diff --git a/app/modules/adc.c b/app/modules/adc.c index 2c646870..a0d24870 100644 --- a/app/modules/adc.c +++ b/app/modules/adc.c @@ -1,11 +1,9 @@ // Module for interfacing with adc -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_types.h" #include "user_interface.h" @@ -28,26 +26,14 @@ static int adc_readvdd33( lua_State* L ) } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE adc_map[] = { { LSTRKEY( "read" ), LFUNCVAL( adc_sample ) }, { LSTRKEY( "readvdd33" ), LFUNCVAL( adc_readvdd33) }, -#if LUA_OPTIMIZE_MEMORY > 0 - -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_adc( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_ADC, adc_map ); - // Add constants - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/auxmods.h b/app/modules/auxmods.h index 602da99a..12a67f41 100644 --- a/app/modules/auxmods.h +++ b/app/modules/auxmods.h @@ -5,95 +5,6 @@ #ifndef __AUXMODS_H__ #define __AUXMODS_H__ -#include "lua.h" - -#define AUXLIB_GPIO "gpio" -LUALIB_API int ( luaopen_gpio )( lua_State *L ); - -#define AUXLIB_SPI "spi" -LUALIB_API int ( luaopen_spi )( lua_State *L ); - -#define AUXLIB_CAN "can" -LUALIB_API int ( luaopen_can )( lua_State *L ); - -#define AUXLIB_TMR "tmr" -LUALIB_API int ( luaopen_tmr )( lua_State *L ); - -#define AUXLIB_PD "pd" -LUALIB_API int ( luaopen_pd )( lua_State *L ); - -#define AUXLIB_UART "uart" -LUALIB_API int ( luaopen_uart )( lua_State *L ); - -#define AUXLIB_TERM "term" -LUALIB_API int ( luaopen_term )( lua_State *L ); - -#define AUXLIB_PWM "pwm" -LUALIB_API int ( luaopen_pwm )( lua_State *L ); - -#define AUXLIB_PACK "pack" -LUALIB_API int ( luaopen_pack )( lua_State *L ); - -#define AUXLIB_BIT "bit" -LUALIB_API int ( luaopen_bit )( lua_State *L ); - -#define AUXLIB_NET "net" -LUALIB_API int ( luaopen_net )( lua_State *L ); - -#define AUXLIB_CPU "cpu" -LUALIB_API int ( luaopen_cpu )( lua_State* L ); - -#define AUXLIB_ADC "adc" -LUALIB_API int ( luaopen_adc )( lua_State *L ); - -#define AUXLIB_RPC "rpc" -LUALIB_API int ( luaopen_rpc )( lua_State *L ); - -#define AUXLIB_BITARRAY "bitarray" -LUALIB_API int ( luaopen_bitarray )( lua_State *L ); - -#define AUXLIB_ELUA "elua" -LUALIB_API int ( luaopen_elua )( lua_State *L ); - -#define AUXLIB_I2C "i2c" -LUALIB_API int ( luaopen_i2c )( lua_State *L ); - -#define AUXLIB_WIFI "wifi" -LUALIB_API int ( luaopen_wifi )( lua_State *L ); - -#define AUXLIB_COAP "coap" -LUALIB_API int ( luaopen_coap )( lua_State *L ); - -#define AUXLIB_MQTT "mqtt" -LUALIB_API int ( luaopen_mqtt )( lua_State *L ); - -#define AUXLIB_U8G "u8g" -LUALIB_API int ( luaopen_u8g )( lua_State *L ); - -#define AUXLIB_UCG "ucg" -LUALIB_API int ( luaopen_ucg )( lua_State *L ); - -#define AUXLIB_NODE "node" -LUALIB_API int ( luaopen_node )( lua_State *L ); - -#define AUXLIB_FILE "file" -LUALIB_API int ( luaopen_file )( lua_State *L ); - -#define AUXLIB_OW "ow" -LUALIB_API int ( luaopen_ow )( lua_State *L ); - -#define AUXLIB_CJSON "cjson" -LUALIB_API int ( luaopen_cjson )( lua_State *L ); - -#define AUXLIB_CRYPTO "crypto" -LUALIB_API int ( luaopen_crypto )( lua_State *L ); - -#define AUXLIB_RC "rc" -LUALIB_API int ( luaopen_rc )( lua_State *L ); - -#define AUXLIB_DHT "dht" -LUALIB_API int ( luaopen_dht )( lua_State *L ); - // Helper macros #define MOD_CHECK_ID( mod, id )\ if( !platform_ ## mod ## _exists( id ) )\ @@ -109,13 +20,4 @@ LUALIB_API int ( luaopen_dht )( lua_State *L ); if( !platform_ ## mod ## _check_ ## resmod ## _id( id, resid ) )\ return luaL_error( L, #resmod" %d not valid with " #mod " %d", ( unsigned )resid, ( unsigned )id ) -#define MOD_REG_NUMBER( L, name, val )\ - lua_pushnumber( L, val );\ - lua_setfield( L, -2, name ) - -#define MOD_REG_LUDATA( L, name, val )\ - lua_pushlightuserdata( L, val );\ - lua_setfield( L, -2, name ) - #endif - diff --git a/app/modules/bit.c b/app/modules/bit.c index ac2d19ba..31ae96d3 100644 --- a/app/modules/bit.c +++ b/app/modules/bit.c @@ -7,11 +7,8 @@ #include "c_limits.h" -//#include "lua.h" #include "lauxlib.h" -#include "auxmods.h" -// #include "type.h" -#include "lrotable.h" +#include "lrodefs.h" /* FIXME: Assume size_t is an unsigned lua_Integer */ typedef size_t lua_UInteger; @@ -122,8 +119,6 @@ static int bit_clear( lua_State* L ) return 1; } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE bit_map[] = { { LSTRKEY( "bnot" ), LFUNCVAL( bit_bnot ) }, { LSTRKEY( "band" ), LFUNCVAL( bit_band ) }, @@ -141,5 +136,5 @@ const LUA_REG_TYPE bit_map[] = { }; LUALIB_API int luaopen_bit (lua_State *L) { - LREGISTER( L, "bit", bit_map ); + return 0; } diff --git a/app/modules/bmp085.c b/app/modules/bmp085.c index 31b7d6af..d75379e8 100644 --- a/app/modules/bmp085.c +++ b/app/modules/bmp085.c @@ -1,8 +1,6 @@ -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_stdlib.h" #include "c_string.h" @@ -185,8 +183,6 @@ static int ICACHE_FLASH_ATTR bmp085_lua_pressure(lua_State* L) { return 1; } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE bmp085_map[] = { { LSTRKEY( "temperature" ), LFUNCVAL( bmp085_lua_temperature )}, @@ -197,7 +193,6 @@ const LUA_REG_TYPE bmp085_map[] = }; LUALIB_API int luaopen_bmp085(lua_State *L) { - LREGISTER(L, "bmp085", bmp085_map); - return 1; + return 0; } diff --git a/app/modules/cjson.c b/app/modules/cjson.c index 2fb10c6c..73a49dbf 100644 --- a/app/modules/cjson.c +++ b/app/modules/cjson.c @@ -40,8 +40,8 @@ #include "c_string.h" #include "c_math.h" #include "c_limits.h" -#include "lua.h" #include "lauxlib.h" +#include "lrodefs.h" #include "flash_api.h" #include "strbuf.h" @@ -1531,8 +1531,6 @@ static int json_protect_conversion(lua_State *l) #endif // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE cjson_map[] = { { LSTRKEY( "encode" ), LFUNCVAL( json_encode ) }, @@ -1545,9 +1543,6 @@ const LUA_REG_TYPE cjson_map[] = // { LSTRKEY( "encode_invalid_numbers" ), LFUNCVAL( json_cfg_encode_invalid_numbers ) }, // { LSTRKEY( "decode_invalid_numbers" ), LFUNCVAL( json_cfg_decode_invalid_numbers ) }, // { LSTRKEY( "new" ), LFUNCVAL( lua_cjson_new ) }, -#if LUA_OPTIMIZE_MEMORY > 0 - -#endif { LNILKEY, LNILVAL } }; @@ -1560,18 +1555,7 @@ LUALIB_API int luaopen_cjson( lua_State *L ) if(-1==cfg_init(&_cfg)){ return luaL_error(L, "BUG: Unable to init config for cjson");; } -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_CJSON, cjson_map ); - // Add constants - /* Set cjson.null */ - lua_pushlightuserdata(l, NULL); - lua_setfield(l, -2, "null"); - - /* Return cjson table */ - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } #if 0 diff --git a/app/modules/coap.c b/app/modules/coap.c index 72502ebc..6da5cb4f 100644 --- a/app/modules/coap.c +++ b/app/modules/coap.c @@ -1,11 +1,8 @@ // Module for coapwork -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_string.h" #include "c_stdlib.h" @@ -561,8 +558,6 @@ static int coap_client_delete( lua_State* L ) } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" static const LUA_REG_TYPE coap_server_map[] = { { LSTRKEY( "listen" ), LFUNCVAL ( coap_server_listen ) }, @@ -570,9 +565,7 @@ static const LUA_REG_TYPE coap_server_map[] = { LSTRKEY( "var" ), LFUNCVAL ( coap_server_var ) }, { LSTRKEY( "func" ), LFUNCVAL ( coap_server_func ) }, { LSTRKEY( "__gc" ), LFUNCVAL ( coap_server_delete ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL ( coap_server_map ) }, -#endif { LNILKEY, LNILVAL } }; @@ -583,9 +576,7 @@ static const LUA_REG_TYPE coap_client_map[] = { LSTRKEY( "put" ), LFUNCVAL ( coap_client_put ) }, { LSTRKEY( "delete" ), LFUNCVAL ( coap_client_delete ) }, { LSTRKEY( "__gc" ), LFUNCVAL ( coap_client_gcdelete ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL ( coap_client_map ) }, -#endif { LNILKEY, LNILVAL } }; @@ -593,7 +584,6 @@ const LUA_REG_TYPE coap_map[] = { { LSTRKEY( "Server" ), LFUNCVAL ( coap_createServer ) }, { LSTRKEY( "Client" ), LFUNCVAL ( coap_createClient ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "CON" ), LNUMVAL( COAP_TYPE_CON ) }, { LSTRKEY( "NON" ), LNUMVAL( COAP_TYPE_NONCON ) }, { LSTRKEY( "TEXT_PLAIN"), LNUMVAL( COAP_CONTENTTYPE_TEXT_PLAIN ) }, @@ -604,56 +594,13 @@ const LUA_REG_TYPE coap_map[] = { LSTRKEY( "JSON"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_JSON) }, { LSTRKEY( "__metatable" ), LROVAL( coap_map ) }, -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_coap( lua_State *L ) { endpoint_setup(); -#if LUA_OPTIMIZE_MEMORY > 0 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 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - int n; - luaL_register( L, AUXLIB_COAP, coap_map ); - - // Set it as its own metatable - lua_pushvalue( L, -1 ); - lua_setmetatable( L, -2 ); - - // Module constants - MOD_REG_NUMBER( L, "CON", COAP_TYPE_CON ); - MOD_REG_NUMBER( L, "NON", COAP_TYPE_NONCON ); - MOD_REG_NUMBER( L, "TEXT_PLAIN", COAP_CONTENTTYPE_TEXT_PLAIN ); - MOD_REG_NUMBER( L, "LINKFORMAT", COAP_CONTENTTYPE_APPLICATION_LINKFORMAT ); - MOD_REG_NUMBER( L, "XML", COAP_CONTENTTYPE_APPLICATION_XML); - MOD_REG_NUMBER( L, "OCTET_STREAM", COAP_CONTENTTYPE_APPLICATION_OCTET_STREAM); - MOD_REG_NUMBER( L, "EXI", COAP_CONTENTTYPE_APPLICATION_EXI); - MOD_REG_NUMBER( L, "JSON", COAP_CONTENTTYPE_APPLICATION_JSON); - - n = lua_gettop(L); - - // create metatable - luaL_newmetatable(L, "coap_server"); - // metatable.__index = metatable - lua_pushliteral(L, "__index"); - lua_pushvalue(L,-2); - lua_rawset(L,-3); - // Setup the methods inside metatable - luaL_register( L, NULL, coap_server_map ); - - lua_settop(L, n); - // create metatable - luaL_newmetatable(L, "coap_client"); - // metatable.__index = metatable - lua_pushliteral(L, "__index"); - lua_pushvalue(L,-2); - lua_rawset(L,-3); - // Setup the methods inside metatable - luaL_register( L, NULL, coap_client_map ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/crypto.c b/app/modules/crypto.c index 3639e436..7557dd14 100644 --- a/app/modules/crypto.c +++ b/app/modules/crypto.c @@ -1,11 +1,8 @@ // Module for cryptography -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_types.h" #include "c_stdlib.h" #include "../crypto/digests.h" @@ -153,8 +150,6 @@ static int crypto_lhmac (lua_State *L) // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE crypto_map[] = { { LSTRKEY( "sha1" ), LFUNCVAL( crypto_sha1 ) }, @@ -163,21 +158,10 @@ const LUA_REG_TYPE crypto_map[] = { LSTRKEY( "mask" ), LFUNCVAL( crypto_mask ) }, { LSTRKEY( "hash" ), LFUNCVAL( crypto_lhash ) }, { LSTRKEY( "hmac" ), LFUNCVAL( crypto_lhmac ) }, - -#if LUA_OPTIMIZE_MEMORY > 0 - -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_crypto( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_CRYPTO, crypto_map ); - // Add constants - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/dht.c b/app/modules/dht.c index fcbf5fdb..3d7067ec 100644 --- a/app/modules/dht.c +++ b/app/modules/dht.c @@ -1,9 +1,8 @@ // Module for interfacing with the DHTxx sensors (xx = 11-21-22-33-44). -#include "lualib.h" #include "lauxlib.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "cpu_esp8266.h" #include "dht.h" @@ -100,30 +99,18 @@ static int dht_lapi_readxx( lua_State *L ) // } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE dht_map[] = { { LSTRKEY( "read" ), LFUNCVAL( dht_lapi_read ) }, { LSTRKEY( "read11" ), LFUNCVAL( dht_lapi_read11 ) }, { LSTRKEY( "readxx" ), LFUNCVAL( dht_lapi_readxx ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "OK" ), LNUMVAL( DHTLIB_OK ) }, { LSTRKEY( "ERROR_CHECKSUM" ), LNUMVAL( DHTLIB_ERROR_CHECKSUM ) }, { LSTRKEY( "ERROR_TIMEOUT" ), LNUMVAL( DHTLIB_ERROR_TIMEOUT ) }, -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_dht( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_DHT, dht_map ); - - // Add the constants - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/enduser_setup.c b/app/modules/enduser_setup.c index 19825284..d1cb83b5 100644 --- a/app/modules/enduser_setup.c +++ b/app/modules/enduser_setup.c @@ -32,11 +32,9 @@ */ -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_stdlib.h" #include "c_string.h" #include "user_interface.h" @@ -929,8 +927,6 @@ static int enduser_setup_stop(lua_State* L) } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE enduser_setup_map[] = { { LSTRKEY( "start" ), LFUNCVAL( enduser_setup_start )}, @@ -939,7 +935,6 @@ const LUA_REG_TYPE enduser_setup_map[] = }; LUALIB_API int luaopen_enduser_setup(lua_State *L) { - LREGISTER(L, "enduser_setup", enduser_setup_map); - return 1; + return 0; } diff --git a/app/modules/file.c b/app/modules/file.c index b4a9cfa0..e41e4841 100644 --- a/app/modules/file.c +++ b/app/modules/file.c @@ -1,11 +1,8 @@ // Module for interfacing with file system -#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_types.h" #include "flash_fs.h" @@ -299,8 +296,6 @@ static int file_writeline( lua_State* L ) } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE file_map[] = { { LSTRKEY( "list" ), LFUNCVAL( file_list ) }, @@ -319,22 +314,11 @@ const LUA_REG_TYPE file_map[] = // { LSTRKEY( "check" ), LFUNCVAL( file_check ) }, { LSTRKEY( "rename" ), LFUNCVAL( file_rename ) }, { LSTRKEY( "fsinfo" ), LFUNCVAL( file_fsinfo ) }, -#endif - -#if LUA_OPTIMIZE_MEMORY > 0 - #endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_file( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_FILE, file_map ); - // Add constants - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/gpio.c b/app/modules/gpio.c index 69875050..49b1507c 100644 --- a/app/modules/gpio.c +++ b/app/modules/gpio.c @@ -1,11 +1,9 @@ // Module for interfacing with GPIO -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" -#include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "platform.h" +#include "lrodefs.h" #include "c_types.h" #include "c_string.h" @@ -223,8 +221,6 @@ static int lgpio_serout( lua_State* L ) #undef DELAY_TABLE_MAX_LEN // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE gpio_map[] = { { LSTRKEY( "mode" ), LFUNCVAL( lgpio_mode ) }, @@ -233,9 +229,6 @@ const LUA_REG_TYPE gpio_map[] = { LSTRKEY( "serout" ), LFUNCVAL( lgpio_serout ) }, #ifdef GPIO_INTERRUPT_ENABLE { LSTRKEY( "trig" ), LFUNCVAL( lgpio_trig ) }, -#endif -#if LUA_OPTIMIZE_MEMORY > 0 -#ifdef GPIO_INTERRUPT_ENABLE { LSTRKEY( "INT" ), LNUMVAL( INTERRUPT ) }, #endif { LSTRKEY( "OUTPUT" ), LNUMVAL( OUTPUT ) }, @@ -244,7 +237,6 @@ const LUA_REG_TYPE gpio_map[] = { LSTRKEY( "LOW" ), LNUMVAL( LOW ) }, { LSTRKEY( "FLOAT" ), LNUMVAL( FLOAT ) }, { LSTRKEY( "PULLUP" ), LNUMVAL( PULLUP ) }, -#endif { LNILKEY, LNILVAL } }; @@ -257,21 +249,5 @@ LUALIB_API int luaopen_gpio( lua_State *L ) } platform_gpio_init(gpio_intr_callback); #endif - -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_GPIO, gpio_map ); - // Add constants -#ifdef GPIO_INTERRUPT_ENABLE - MOD_REG_NUMBER( L, "INT", INTERRUPT ); -#endif - MOD_REG_NUMBER( L, "OUTPUT", OUTPUT ); - MOD_REG_NUMBER( L, "INPUT", INPUT ); - MOD_REG_NUMBER( L, "HIGH", HIGH ); - MOD_REG_NUMBER( L, "LOW", LOW ); - MOD_REG_NUMBER( L, "FLOAT", FLOAT ); - MOD_REG_NUMBER( L, "PULLUP", PULLUP ); - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/hx711.c b/app/modules/hx711.c index e172643b..37e59ad7 100644 --- a/app/modules/hx711.c +++ b/app/modules/hx711.c @@ -1,11 +1,10 @@ // Module for HX711 load cell amplifier // https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_stdlib.h" #include "c_string.h" #include "user_interface.h" @@ -67,8 +66,6 @@ static int ICACHE_FLASH_ATTR hx711_read(lua_State* L) { return 1; } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE hx711_map[] = { { LSTRKEY( "init" ), LFUNCVAL( hx711_init )}, @@ -77,8 +74,6 @@ const LUA_REG_TYPE hx711_map[] = }; LUALIB_API int luaopen_hx711(lua_State *L) { - // TODO: the below todo was inherited from the ws2812 code but is still valid. // TODO: Make sure that the GPIO system is initialized - LREGISTER(L, "hx711", hx711_map); - return 1; + return 0; } diff --git a/app/modules/i2c.c b/app/modules/i2c.c index c231aeec..0b241d2d 100644 --- a/app/modules/i2c.c +++ b/app/modules/i2c.c @@ -1,11 +1,9 @@ // Module for interfacing with the I2C interface -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" // Lua: speed = i2c.setup( id, sda, scl, speed ) static int i2c_setup( lua_State *L ) @@ -143,8 +141,6 @@ static int i2c_read( lua_State *L ) } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE i2c_map[] = { { LSTRKEY( "setup" ), LFUNCVAL( i2c_setup ) }, @@ -153,29 +149,15 @@ const LUA_REG_TYPE i2c_map[] = { LSTRKEY( "address" ), LFUNCVAL( i2c_address ) }, { LSTRKEY( "write" ), LFUNCVAL( i2c_write ) }, { LSTRKEY( "read" ), LFUNCVAL( i2c_read ) }, -#if LUA_OPTIMIZE_MEMORY > 0 // { 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 ) }, -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_i2c( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_I2C, i2c_map ); - - // Add the stop bits and parity constants (for i2c.setup) - // MOD_REG_NUMBER( L, "FAST", PLATFORM_I2C_SPEED_FAST ); - MOD_REG_NUMBER( L, "SLOW", PLATFORM_I2C_SPEED_SLOW ); - MOD_REG_NUMBER( L, "TRANSMITTER", PLATFORM_I2C_DIRECTION_TRANSMITTER ); - MOD_REG_NUMBER( L, "RECEIVER", PLATFORM_I2C_DIRECTION_RECEIVER ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/mqtt.c b/app/modules/mqtt.c index 0741cb6d..1cf595a9 100644 --- a/app/modules/mqtt.c +++ b/app/modules/mqtt.c @@ -1,11 +1,9 @@ // Module for mqtt -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_string.h" #include "c_stdlib.h" @@ -1392,9 +1390,6 @@ static int mqtt_socket_lwt( lua_State* L ) } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" - static const LUA_REG_TYPE mqtt_socket_map[] = { { LSTRKEY( "connect" ), LFUNCVAL ( mqtt_socket_connect ) }, @@ -1404,47 +1399,19 @@ static const LUA_REG_TYPE mqtt_socket_map[] = { LSTRKEY( "lwt" ), LFUNCVAL ( mqtt_socket_lwt ) }, { LSTRKEY( "on" ), LFUNCVAL ( mqtt_socket_on ) }, { LSTRKEY( "__gc" ), LFUNCVAL ( mqtt_delete ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL ( mqtt_socket_map ) }, -#endif { LNILKEY, LNILVAL } }; const LUA_REG_TYPE mqtt_map[] = { { LSTRKEY( "Client" ), LFUNCVAL ( mqtt_socket_client ) }, -#if LUA_OPTIMIZE_MEMORY > 0 - { LSTRKEY( "__metatable" ), LROVAL( mqtt_map ) }, -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_mqtt( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 luaL_rometatable(L, "mqtt.socket", (void *)mqtt_socket_map); // create metatable for mqtt.socket return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - int n; - luaL_register( L, AUXLIB_MQTT, mqtt_map ); - - // Set it as its own metatable - lua_pushvalue( L, -1 ); - lua_setmetatable( L, -2 ); - - // Module constants - // MOD_REG_NUMBER( L, "TCP", TCP ); - - // create metatable - luaL_newmetatable(L, "mqtt.socket"); - // metatable.__index = metatable - lua_pushliteral(L, "__index"); - lua_pushvalue(L,-2); - lua_rawset(L,-3); - // Setup the methods inside metatable - luaL_register( L, NULL, mqtt_socket_map ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/net.c b/app/modules/net.c index 73afe2b3..6aeed291 100644 --- a/app/modules/net.c +++ b/app/modules/net.c @@ -1,11 +1,9 @@ // Module for network -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_string.h" #include "c_stdlib.h" @@ -1508,8 +1506,6 @@ static int expose_array(lua_State* L, char *array, unsigned short len) { #endif // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" static const LUA_REG_TYPE net_server_map[] = { { LSTRKEY( "listen" ), LFUNCVAL ( net_server_listen ) }, @@ -1518,9 +1514,7 @@ static const LUA_REG_TYPE net_server_map[] = { LSTRKEY( "send" ), LFUNCVAL ( net_udpserver_send ) }, // { LSTRKEY( "delete" ), LFUNCVAL ( net_server_delete ) }, { LSTRKEY( "__gc" ), LFUNCVAL ( net_server_delete ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL ( net_server_map ) }, -#endif { LNILKEY, LNILVAL } }; @@ -1536,9 +1530,7 @@ static const LUA_REG_TYPE net_socket_map[] = { LSTRKEY( "getpeer" ), LFUNCVAL ( net_socket_getpeer ) }, // { LSTRKEY( "delete" ), LFUNCVAL ( net_socket_delete ) }, { LSTRKEY( "__gc" ), LFUNCVAL ( net_socket_delete ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL ( net_socket_map ) }, -#endif { LNILKEY, LNILVAL } }; #if 0 @@ -1564,13 +1556,11 @@ const LUA_REG_TYPE net_map[] = { LSTRKEY( "createConnection" ), LFUNCVAL ( net_createConnection ) }, { LSTRKEY( "multicastJoin"), LFUNCVAL( net_multicastJoin ) }, { LSTRKEY( "multicastLeave"), LFUNCVAL( net_multicastLeave ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "dns" ), LROVAL( net_dns_map ) }, { LSTRKEY( "TCP" ), LNUMVAL( TCP ) }, { LSTRKEY( "UDP" ), LNUMVAL( UDP ) }, { LSTRKEY( "__metatable" ), LROVAL( net_map ) }, -#endif { LNILKEY, LNILVAL } }; @@ -1582,58 +1572,10 @@ LUALIB_API int luaopen_net( lua_State *L ) socket[i] = LUA_NOREF; } -#if LUA_OPTIMIZE_MEMORY > 0 luaL_rometatable(L, "net.server", (void *)net_server_map); // create metatable for net.server luaL_rometatable(L, "net.socket", (void *)net_socket_map); // create metatable for net.socket #if 0 luaL_rometatable(L, "net.array", (void *)net_array_map); // create metatable for net.array #endif return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - int n; - luaL_register( L, AUXLIB_NET, net_map ); - - // Set it as its own metatable - lua_pushvalue( L, -1 ); - lua_setmetatable( L, -2 ); - - // Module constants - MOD_REG_NUMBER( L, "TCP", TCP ); - MOD_REG_NUMBER( L, "UDP", UDP ); - - n = lua_gettop(L); - - // create metatable - luaL_newmetatable(L, "net.server"); - // metatable.__index = metatable - lua_pushliteral(L, "__index"); - lua_pushvalue(L,-2); - lua_rawset(L,-3); - // Setup the methods inside metatable - luaL_register( L, NULL, net_server_map ); - - lua_settop(L, n); - // create metatable - luaL_newmetatable(L, "net.socket"); - // metatable.__index = metatable - lua_pushliteral(L, "__index"); - lua_pushvalue(L,-2); - lua_rawset(L,-3); - // Setup the methods inside metatable - luaL_register( L, NULL, net_socket_map ); -#if 0 - lua_settop(L, n); - // create metatable - luaL_newmetatable(L, "net.array"); - // Setup the methods inside metatable - luaL_register( L, NULL, net_array_map ); -#endif - - lua_settop(L, n); - lua_newtable( L ); - luaL_register( L, NULL, net_dns_map ); - lua_setfield( L, -2, "dns" ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/node.c b/app/modules/node.c index d3154746..2b4869c9 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -1,6 +1,5 @@ // Module for interfacing with system -#include "lua.h" #include "lauxlib.h" #include "ldebug.h" @@ -15,14 +14,12 @@ #include "lundump.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_types.h" #include "romfs.h" #include "c_string.h" #include "driver/uart.h" -//#include "spi_flash.h" #include "user_interface.h" #include "flash_api.h" #include "flash_fs.h" @@ -550,8 +547,6 @@ static int node_stripdebug (lua_State *L) { #endif // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE node_map[] = { { LSTRKEY( "restart" ), LFUNCVAL( node_restart ) }, @@ -581,20 +576,10 @@ const LUA_REG_TYPE node_map[] = // Combined to dsleep(us, option) // { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) }, -#if LUA_OPTIMIZE_MEMORY > 0 - -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_node( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_NODE, node_map ); - // Add constants - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/ow.c b/app/modules/ow.c index c9cbfa1a..be92bb6b 100644 --- a/app/modules/ow.c +++ b/app/modules/ow.c @@ -1,10 +1,8 @@ // Module for interfacing with the OneWire interface -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "driver/onewire.h" // Lua: ow.setup( id ) @@ -282,8 +280,6 @@ static int ow_crc16( lua_State *L ) #endif // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE ow_map[] = { { LSTRKEY( "setup" ), LFUNCVAL( ow_setup ) }, @@ -306,22 +302,11 @@ const LUA_REG_TYPE ow_map[] = { LSTRKEY( "check_crc16" ), LFUNCVAL( ow_check_crc16 ) }, { LSTRKEY( "crc16" ), LFUNCVAL( ow_crc16 ) }, #endif -#endif -#if LUA_OPTIMIZE_MEMORY > 0 - #endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_ow( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_OW, ow_map ); - - // Add the constants - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/pwm.c b/app/modules/pwm.c index fbf29fe4..b88a2dd8 100644 --- a/app/modules/pwm.c +++ b/app/modules/pwm.c @@ -1,11 +1,9 @@ // Module for interfacing with PWM -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_types.h" @@ -125,8 +123,6 @@ static int lpwm_getduty( lua_State* L ) } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE pwm_map[] = { { LSTRKEY( "setup" ), LFUNCVAL( lpwm_setup ) }, @@ -137,18 +133,10 @@ const LUA_REG_TYPE pwm_map[] = { LSTRKEY( "getclock" ), LFUNCVAL( lpwm_getclock ) }, { LSTRKEY( "setduty" ), LFUNCVAL( lpwm_setduty ) }, { LSTRKEY( "getduty" ), LFUNCVAL( lpwm_getduty ) }, -#if LUA_OPTIMIZE_MEMORY > 0 - -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_pwm( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_PWM, pwm_map ); - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/rc.c b/app/modules/rc.c index 964896c4..24df4a10 100644 --- a/app/modules/rc.c +++ b/app/modules/rc.c @@ -1,8 +1,6 @@ -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" //#include "driver/easygpio.h" //static Ping_Data pingA; #define defPulseLen 185 @@ -80,8 +78,7 @@ static int ICACHE_FLASH_ATTR rc_send(lua_State* L) { return 1; } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" + const LUA_REG_TYPE rc_map[] = { { LSTRKEY( "send" ), LFUNCVAL( rc_send )}, @@ -91,6 +88,5 @@ const LUA_REG_TYPE rc_map[] = //LUALIB_API int luaopen_ultra(lua_State *L) { LUALIB_API int luaopen_rc(lua_State *L) { // TODO: Make sure that the GPIO system is initialized - LREGISTER(L, "rc", rc_map); - return 1; + return 0; } diff --git a/app/modules/rtcfifo.c b/app/modules/rtcfifo.c index 20492ffa..c347c635 100644 --- a/app/modules/rtcfifo.c +++ b/app/modules/rtcfifo.c @@ -1,6 +1,7 @@ // Module for RTC sample FIFO storage #include "lauxlib.h" +#include "lrodefs.h" #include "user_modules.h" #include "rtc/rtctime.h" #define RTCTIME_SLEEP_ALIGNED rtctime_deep_sleep_until_aligned_us @@ -164,8 +165,6 @@ static int rtcfifo_dsleep_until_sample (lua_State *L) #endif // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE rtcfifo_map[] = { { LSTRKEY("prepare"), LFUNCVAL(rtcfifo_prepare) }, @@ -183,10 +182,5 @@ const LUA_REG_TYPE rtcfifo_map[] = LUALIB_API int luaopen_rtcfifo (lua_State *L) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else - luaL_register (L, AUXLIB_RTCFIFO, rtcfifo_map); - return 1; -#endif } diff --git a/app/modules/rtcmem.c b/app/modules/rtcmem.c index 4baa9c68..db03e515 100644 --- a/app/modules/rtcmem.c +++ b/app/modules/rtcmem.c @@ -1,6 +1,7 @@ // Module for RTC user memory access #include "lauxlib.h" +#include "lrodefs.h" #include "rtc/rtcaccess.h" static int rtcmem_read32 (lua_State *L) @@ -40,8 +41,6 @@ static int rtcmem_write32 (lua_State *L) // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE rtcmem_map[] = { { LSTRKEY("read32"), LFUNCVAL(rtcmem_read32) }, @@ -51,10 +50,5 @@ const LUA_REG_TYPE rtcmem_map[] = LUALIB_API int luaopen_rtcmem (lua_State *L) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else - luaL_register (L, AUXLIB_RTCMEM, rtcmem_map); - return 1; -#endif } diff --git a/app/modules/rtctime.c b/app/modules/rtctime.c index 2ee298dd..fdb223ac 100644 --- a/app/modules/rtctime.c +++ b/app/modules/rtctime.c @@ -1,6 +1,7 @@ // Module for RTC time keeping #include "lauxlib.h" +#include "lrodefs.h" #include "rtc/rtctime_internal.h" #include "rtc/rtctime.h" @@ -115,8 +116,6 @@ static int rtctime_dsleep_aligned (lua_State *L) // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE rtctime_map[] = { { LSTRKEY("set"), LFUNCVAL(rtctime_set) }, @@ -128,10 +127,5 @@ const LUA_REG_TYPE rtctime_map[] = LUALIB_API int luaopen_rtctime (lua_State *L) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else - luaL_register (L, AUXLIB_RTCTIME, rtctime_map); - return 1; -#endif } diff --git a/app/modules/sntp.c b/app/modules/sntp.c index 0f08301c..3ae5e1a9 100644 --- a/app/modules/sntp.c +++ b/app/modules/sntp.c @@ -34,6 +34,7 @@ // Module for Simple Network Time Protocol (SNTP) #include "lauxlib.h" +#include "lrodefs.h" #include "os_type.h" #include "osapi.h" #include "lwip/udp.h" @@ -375,8 +376,6 @@ error: // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE sntp_map[] = { { LSTRKEY("sync"), LFUNCVAL(sntp_sync) }, @@ -385,10 +384,5 @@ const LUA_REG_TYPE sntp_map[] = LUALIB_API int luaopen_sntp (lua_State *L) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else - luaL_register (L, AUXLIB_SNTP, sntp_map); - return 1; -#endif } diff --git a/app/modules/spi.c b/app/modules/spi.c index 6074ec82..40e9ee53 100644 --- a/app/modules/spi.c +++ b/app/modules/spi.c @@ -1,11 +1,9 @@ // Module for interfacing with the SPI interface -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #define SPI_HALFDUPLEX 0 #define SPI_FULLDUPLEX 1 @@ -309,8 +307,6 @@ static int spi_transaction( lua_State *L ) // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE spi_map[] = { { LSTRKEY( "setup" ), LFUNCVAL( spi_setup ) }, @@ -319,7 +315,6 @@ const LUA_REG_TYPE spi_map[] = { LSTRKEY( "set_mosi" ), LFUNCVAL( spi_set_mosi ) }, { LSTRKEY( "get_miso" ), LFUNCVAL( spi_get_miso ) }, { LSTRKEY( "transaction" ), LFUNCVAL( spi_transaction ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "MASTER" ), LNUMVAL( PLATFORM_SPI_MASTER ) }, { LSTRKEY( "SLAVE" ), LNUMVAL( PLATFORM_SPI_SLAVE) }, { LSTRKEY( "CPHA_LOW" ), LNUMVAL( PLATFORM_SPI_CPHA_LOW) }, @@ -329,28 +324,10 @@ const LUA_REG_TYPE spi_map[] = { LSTRKEY( "DATABITS_8" ), LNUMVAL( 8 ) }, { LSTRKEY( "HALFDUPLEX" ), LNUMVAL( SPI_HALFDUPLEX ) }, { LSTRKEY( "FULLDUPLEX" ), LNUMVAL( SPI_FULLDUPLEX ) }, -#endif // #if LUA_OPTIMIZE_MEMORY > 0 { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_spi( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_SPI, spi_map ); - - // Add constants - MOD_REG_NUMBER( L, "MASTER", PLATFORM_SPI_MASTER); - MOD_REG_NUMBER( L, "SLAVE", PLATFORM_SPI_SLAVE); - MOD_REG_NUMBER( L, "CPHA_LOW" , PLATFORM_SPI_CPHA_LOW); - MOD_REG_NUMBER( L, "CPHA_HIGH", PLATFORM_SPI_CPHA_HIGH); - MOD_REG_NUMBER( L, "CPOL_LOW" , PLATFORM_SPI_CPOL_LOW); - MOD_REG_NUMBER( L, "CPOL_HIGH", PLATFORM_SPI_CPOL_HIGH); - MOD_REG_NUMBER( L, "DATABITS_8", 8 ); - MOD_REG_NUMBER( L, "HALFDUPLEX", SPI_HALFDUPLEX ); - MOD_REG_NUMBER( L, "FULLDUPLEX", SPI_FULLDUPLEX ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/tmr.c b/app/modules/tmr.c index cad2e8dd..c49d5169 100755 --- a/app/modules/tmr.c +++ b/app/modules/tmr.c @@ -48,13 +48,9 @@ tmr.softwd(int) the timer units are seconds */ -#define MIN_OPT_LEVEL 2 - -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" #include "lrodefs.h" #include "c_types.h" @@ -324,11 +320,9 @@ const LUA_REG_TYPE tmr_map[] = { { LSTRKEY( "unregister" ), LFUNCVAL ( tmr_unregister ) }, { LSTRKEY( "state" ), LFUNCVAL ( tmr_state ) }, { LSTRKEY( "interval" ), LFUNCVAL ( tmr_interval) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "ALARM_SINGLE" ), LNUMVAL( TIMER_MODE_SINGLE ) }, { LSTRKEY( "ALARM_SEMI" ), LNUMVAL( TIMER_MODE_SEMI ) }, { LSTRKEY( "ALARM_AUTO" ), LNUMVAL( TIMER_MODE_AUTO ) }, -#endif { LNILKEY, LNILVAL } }; @@ -344,16 +338,6 @@ LUALIB_API int luaopen_tmr( lua_State *L ){ ets_timer_setfn(&rtc_timer, rtc_callback, NULL); ets_timer_arm_new(&rtc_timer, 1000, 1, 1); -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else - luaL_register( L, AUXLIB_TMR, tmr_map ); - lua_pushvalue( L, -1 ); - lua_setmetatable( L, -2 ); - MOD_REG_NUMBER( L, "ALARM_SINGLE", TIMER_MODE_SINGLE ); - MOD_REG_NUMBER( L, "ALARM_SEMI", TIMER_MODE_SEMI ); - MOD_REG_NUMBER( L, "ALARM_AUTO", TIMER_MODE_AUTO ); - return 1; -#endif } diff --git a/app/modules/tsl2561.c b/app/modules/tsl2561.c index a0abbb96..6c8fd96c 100644 --- a/app/modules/tsl2561.c +++ b/app/modules/tsl2561.c @@ -4,11 +4,9 @@ * Created on: Aug 21, 2015 * Author: Michael Lucas (Aeprox @github) */ -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "../tsl2561/tsl2561.h" static uint16_t ch0; @@ -102,8 +100,6 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_getchannels(lua_State* L) { return 3; } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE tsl2561_map[] = { { LSTRKEY( "settiming" ), LFUNCVAL( tsl2561_lua_settiming)}, @@ -134,6 +130,5 @@ const LUA_REG_TYPE tsl2561_map[] = }; LUALIB_API int luaopen_tsl2561(lua_State *L) { - LREGISTER(L, "tsl2561", tsl2561_map); - return 1; + return 0; } diff --git a/app/modules/u8g.c b/app/modules/u8g.c index 0397e23a..32102f51 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -1,10 +1,8 @@ // Module for U8glib -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_stdlib.h" @@ -1027,9 +1025,6 @@ U8G_DISPLAY_TABLE_SPI // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" - static const LUA_REG_TYPE lu8g_display_map[] = { { LSTRKEY( "begin" ), LFUNCVAL( lu8g_begin ) }, @@ -1083,9 +1078,7 @@ static const LUA_REG_TYPE lu8g_display_map[] = { LSTRKEY( "undoRotation" ), LFUNCVAL( lu8g_undoRotation ) }, { LSTRKEY( "undoScale" ), LFUNCVAL( lu8g_undoScale ) }, { LSTRKEY( "__gc" ), LFUNCVAL( lu8g_close_display ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL ( lu8g_display_map ) }, -#endif { LNILKEY, LNILVAL } }; @@ -1096,8 +1089,6 @@ const LUA_REG_TYPE lu8g_map[] = U8G_DISPLAY_TABLE_I2C U8G_DISPLAY_TABLE_SPI -#if LUA_OPTIMIZE_MEMORY > 0 - // Register fonts #undef U8G_FONT_TABLE_ENTRY #define U8G_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(u8g_ ## font) ) }, @@ -1115,50 +1106,11 @@ const LUA_REG_TYPE lu8g_map[] = { LSTRKEY( "MODE_GRAY2BIT" ), LNUMVAL( U8G_MODE_GRAY2BIT ) }, { LSTRKEY( "__metatable" ), LROVAL( lu8g_map ) }, -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_u8g( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 luaL_rometatable(L, "u8g.display", (void *)lu8g_display_map); // create metatable return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - int n; - luaL_register( L, AUXLIB_U8G, lu8g_map ); - - // Set it as its own metatable - lua_pushvalue( L, -1 ); - lua_setmetatable( L, -2 ); - - // Module constants - - // Register fonts -#undef U8G_FONT_TABLE_ENTRY -#define U8G_FONT_TABLE_ENTRY(font) MOD_REG_LUDATA( L, #font, (void *)(u8g_ ## font) ); - U8G_FONT_TABLE - - // Options for circle/ ellipse drawing - MOD_REG_NUMBER( L, "DRAW_UPPER_RIGHT", U8G_DRAW_UPPER_RIGHT ); - MOD_REG_NUMBER( L, "DRAW_UPPER_LEFT", U8G_DRAW_UPPER_LEFT ); - MOD_REG_NUMBER( L, "DRAW_LOWER_RIGHT", U8G_DRAW_LOWER_RIGHT ); - MOD_REG_NUMBER( L, "DRAW_LOWER_LEFT", U8G_DRAW_LOWER_LEFT ); - MOD_REG_NUMBER( L, "DRAW_ALL", U8G_DRAW_ALL ); - - // Display modes - MOD_REG_NUMBER( L, "MODE_BW", U8G_MODE_BW ); - MOD_REG_NUMBER( L, "MODE_GRAY2BIT", U8G_MODE_GRAY2BIT ); - - // create metatable - luaL_newmetatable(L, "u8g.display"); - // metatable.__index = metatable - lua_pushliteral(L, "__index"); - lua_pushvalue(L,-2); - lua_rawset(L,-3); - // Setup the methods inside metatable - luaL_register( L, NULL, u8g_display_map ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/uart.c b/app/modules/uart.c index c4fdcc6f..d5d81bd7 100755 --- a/app/modules/uart.c +++ b/app/modules/uart.c @@ -1,11 +1,9 @@ // Module for interfacing with serial -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" #include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_types.h" #include "c_string.h" @@ -158,29 +156,16 @@ static int uart_write( lua_State* L ) } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE uart_map[] = { { LSTRKEY( "setup" ), LFUNCVAL( uart_setup ) }, { LSTRKEY( "write" ), LFUNCVAL( uart_write ) }, { LSTRKEY( "on" ), LFUNCVAL( uart_on ) }, { LSTRKEY( "alt" ), LFUNCVAL( uart_alt ) }, - -#if LUA_OPTIMIZE_MEMORY > 0 - -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_uart( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_UART, uart_map ); - // Add constants - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/ucg.c b/app/modules/ucg.c index 3d51265f..82fc3067 100644 --- a/app/modules/ucg.c +++ b/app/modules/ucg.c @@ -1,10 +1,8 @@ // Module for Ucglib -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_stdlib.h" @@ -876,9 +874,6 @@ UCG_DISPLAY_TABLE // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" - static const LUA_REG_TYPE lucg_display_map[] = { { LSTRKEY( "begin" ), LFUNCVAL( lucg_begin ) }, @@ -926,9 +921,7 @@ static const LUA_REG_TYPE lucg_display_map[] = { LSTRKEY( "undoScale" ), LFUNCVAL( lucg_undoScale ) }, { LSTRKEY( "__gc" ), LFUNCVAL( lucg_close_display ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL ( lucg_display_map ) }, -#endif { LNILKEY, LNILVAL } }; @@ -938,8 +931,6 @@ const LUA_REG_TYPE lucg_map[] = #define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension) { LSTRKEY( #binding ), LFUNCVAL ( lucg_ ##binding ) }, UCG_DISPLAY_TABLE -#if LUA_OPTIMIZE_MEMORY > 0 - // Register fonts #undef UCG_FONT_TABLE_ENTRY #define UCG_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(ucg_ ## font) ) }, @@ -957,50 +948,11 @@ const LUA_REG_TYPE lucg_map[] = { LSTRKEY( "DRAW_ALL" ), LNUMVAL( UCG_DRAW_ALL ) }, { LSTRKEY( "__metatable" ), LROVAL( lucg_map ) }, -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_ucg( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 luaL_rometatable(L, "ucg.display", (void *)lucg_display_map); // create metatable return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - int n; - luaL_register( L, AUXLIB_UCG, lucg_map ); - - // Set it as its own metatable - lua_pushvalue( L, -1 ); - lua_setmetatable( L, -2 ); - - // Module constants - - // Register fonts -#undef UCG_FONT_TABLE_ENTRY -#define UCG_FONT_TABLE_ENTRY(font) MOD_REG_LUDATA( L, #font, (void *)(ucg_ ## font) ); - UCG_FONT_TABLE - - // Font modes - MOD_REG_NUMBER( L, "FONT_MODE_TRANSPARENT", UCG_FONT_MODE_TRANSPARENT ); - MOD_REG_NUMBER( L, "FONT_MODE_SOLID", UCG_FONT_MODE_SOLID ); - - // Options for circle/ disc drawing - MOD_REG_NUMBER( L, "DRAW_UPPER_RIGHT", UCG_DRAW_UPPER_RIGHT ); - MOD_REG_NUMBER( L, "DRAW_UPPER_LEFT", UCG_DRAW_UPPER_LEFT ); - MOD_REG_NUMBER( L, "DRAW_LOWER_RIGHT", UCG_DRAW_LOWER_RIGHT ); - MOD_REG_NUMBER( L, "DRAW_LOWER_LEFT", UCG_DRAW_LOWER_LEFT ); - MOD_REG_NUMBER( L, "DRAW_ALL", UCG_DRAW_ALL ); - - // create metatable - luaL_newmetatable(L, "ucg.display"); - // metatable.__index = metatable - lua_pushliteral(L, "__index"); - lua_pushvalue(L,-2); - lua_rawset(L,-3); - // Setup the methods inside metatable - luaL_register( L, NULL, lucg_display_map ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/wifi.c b/app/modules/wifi.c index 9d84ce50..2b076b8f 100644 --- a/app/modules/wifi.c +++ b/app/modules/wifi.c @@ -1,11 +1,8 @@ // Module for interfacing with WIFI -//#include "lua.h" -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_string.h" #include "c_stdlib.h" @@ -1340,8 +1337,6 @@ static int wifi_ap_dhcp_stop( lua_State* L ) } // Module function map -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" static const LUA_REG_TYPE wifi_station_map[] = { { LSTRKEY( "getconfig" ), LFUNCVAL ( wifi_station_getconfig ) }, @@ -1380,11 +1375,9 @@ static const LUA_REG_TYPE wifi_ap_map[] = { LSTRKEY( "setmac" ), LFUNCVAL ( wifi_ap_setmac ) }, { LSTRKEY( "getclient" ), LFUNCVAL ( wifi_ap_listclient ) }, { LSTRKEY( "getconfig" ), LFUNCVAL( wifi_ap_getconfig ) }, -#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "dhcp" ), LROVAL( wifi_ap_dhcp_map ) }, // { LSTRKEY( "__metatable" ), LROVAL( wifi_ap_map ) }, -#endif { LNILKEY, LNILVAL } }; @@ -1399,7 +1392,7 @@ const LUA_REG_TYPE wifi_map[] = { LSTRKEY( "startsmart" ), LFUNCVAL( wifi_start_smart ) }, { LSTRKEY( "stopsmart" ), LFUNCVAL( wifi_exit_smart ) }, { LSTRKEY( "sleeptype" ), LFUNCVAL( wifi_sleeptype ) }, -#if LUA_OPTIMIZE_MEMORY > 0 + { LSTRKEY( "sta" ), LROVAL( wifi_station_map ) }, { LSTRKEY( "ap" ), LROVAL( wifi_ap_map ) }, @@ -1430,58 +1423,10 @@ const LUA_REG_TYPE wifi_map[] = { LSTRKEY( "STA_GOTIP" ), LNUMVAL( STATION_GOT_IP ) }, { LSTRKEY( "__metatable" ), LROVAL( wifi_map ) }, -#endif { LNILKEY, LNILVAL } }; LUALIB_API int luaopen_wifi( lua_State *L ) { -#if LUA_OPTIMIZE_MEMORY > 0 return 0; -#else // #if LUA_OPTIMIZE_MEMORY > 0 - luaL_register( L, AUXLIB_WIFI, wifi_map ); - - // Set it as its own metatable - lua_pushvalue( L, -1 ); - lua_setmetatable( L, -2 ); - - // Module constants - // MOD_REG_NUMBER( L, "NULLMODE", NULL_MODE ); - MOD_REG_NUMBER( L, "STATION", STATION_MODE ); - MOD_REG_NUMBER( L, "SOFTAP", SOFTAP_MODE ); - MOD_REG_NUMBER( L, "STATIONAP", STATIONAP_MODE ); - - MOD_REG_NUMBER( L, "NONE_SLEEP", NONE_SLEEP_T ); - MOD_REG_NUMBER( L, "LIGHT_SLEEP", LIGHT_SLEEP_T ); - MOD_REG_NUMBER( L, "MODEM_SLEEP", MODEM_SLEEP_T ); - - MOD_REG_NUMBER( L, "OPEN", AUTH_OPEN ); - // MOD_REG_NUMBER( L, "WEP", AUTH_WEP ); - MOD_REG_NUMBER( L, "WPA_PSK", AUTH_WPA_PSK ); - MOD_REG_NUMBER( L, "WPA2_PSK", AUTH_WPA2_PSK ); - MOD_REG_NUMBER( L, "WPA_WPA2_PSK", AUTH_WPA_WPA2_PSK ); - - // MOD_REG_NUMBER( L, "STA_IDLE", STATION_IDLE ); - // MOD_REG_NUMBER( L, "STA_CONNECTING", STATION_CONNECTING ); - // MOD_REG_NUMBER( L, "STA_WRONGPWD", STATION_WRONG_PASSWORD ); - // MOD_REG_NUMBER( L, "STA_APNOTFOUND", STATION_NO_AP_FOUND ); - // MOD_REG_NUMBER( L, "STA_FAIL", STATION_CONNECT_FAIL ); - // MOD_REG_NUMBER( L, "STA_GOTIP", STATION_GOT_IP ); - - // Setup the new tables (station and ap) inside wifi - lua_newtable( L ); - luaL_register( L, NULL, wifi_station_map ); - lua_setfield( L, -2, "sta" ); - - lua_newtable( L ); - luaL_register( L, NULL, wifi_ap_map ); - lua_setfield( L, -2, "ap" ); - - // Setup the new table (dhcp) inside ap - lua_newtable( L ); - luaL_register( L, NULL, wifi_ap_dhcp_map ); - lua_setfield( L, -1, "dhcp" ); - - return 1; -#endif // #if LUA_OPTIMIZE_MEMORY > 0 } diff --git a/app/modules/ws2801.c b/app/modules/ws2801.c index 6ba2199e..9fe04c86 100644 --- a/app/modules/ws2801.c +++ b/app/modules/ws2801.c @@ -1,8 +1,6 @@ -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_stdlib.h" #include "c_string.h" @@ -124,8 +122,6 @@ static int ICACHE_FLASH_ATTR ws2801_writergb(lua_State* L) { return 0; } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE ws2801_map[] = { { LSTRKEY( "write" ), LFUNCVAL( ws2801_writergb )}, @@ -134,7 +130,6 @@ const LUA_REG_TYPE ws2801_map[] = }; LUALIB_API int luaopen_ws2801(lua_State *L) { - LREGISTER(L, "ws2801", ws2801_map); - return 1; + return 0; } diff --git a/app/modules/ws2812.c b/app/modules/ws2812.c index 6875416d..e23a4b95 100644 --- a/app/modules/ws2812.c +++ b/app/modules/ws2812.c @@ -1,8 +1,6 @@ -#include "lualib.h" #include "lauxlib.h" #include "platform.h" -#include "auxmods.h" -#include "lrotable.h" +#include "lrodefs.h" #include "c_stdlib.h" #include "c_string.h" #include "user_interface.h" @@ -127,8 +125,6 @@ static int ICACHE_FLASH_ATTR ws2812_writegrb(lua_State* L) { return 0; } -#define MIN_OPT_LEVEL 2 -#include "lrodefs.h" const LUA_REG_TYPE ws2812_map[] = { { LSTRKEY( "writergb" ), LFUNCVAL( ws2812_writergb )}, @@ -138,6 +134,5 @@ const LUA_REG_TYPE ws2812_map[] = LUALIB_API int luaopen_ws2812(lua_State *L) { // TODO: Make sure that the GPIO system is initialized - LREGISTER(L, "ws2812", ws2812_map); - return 1; + return 0; }