Major cleanup of module registration pass 2.

carrying on Johny's edits as per my comments on #810
This commit is contained in:
TerryE 2015-12-13 02:29:37 +00:00 committed by Johny Mattsson
parent 6b6456be47
commit b773290b8c
29 changed files with 515 additions and 483 deletions

View File

@ -2,7 +2,6 @@
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrodefs.h"
#include "c_types.h"
@ -26,14 +25,16 @@ static int adc_readvdd33( lua_State* L )
}
// Module function map
const LUA_REG_TYPE adc_map[] =
{
const LUA_REG_TYPE adc_map[] = {
{ LSTRKEY( "read" ), LFUNCVAL( adc_sample ) },
{ LSTRKEY( "readvdd33" ), LFUNCVAL( adc_readvdd33) },
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_adc( lua_State *L )
{
LUALIB_API int luaopen_adc( lua_State *L ) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -1,23 +0,0 @@
// Auxiliary Lua modules. All of them are declared here, then each platform
// decides what module(s) to register in the src/platform/xxxxx/platform_conf.h file
// FIXME: no longer platform_conf.h - either CPU header file, or board file
#ifndef __AUXMODS_H__
#define __AUXMODS_H__
// Helper macros
#define MOD_CHECK_ID( mod, id )\
if( !platform_ ## mod ## _exists( id ) )\
return luaL_error( L, #mod" %d does not exist", ( unsigned )id )
#define MOD_CHECK_TIMER( id )\
if( id == PLATFORM_TIMER_SYS_ID && !platform_timer_sys_available() )\
return luaL_error( L, "the system timer is not available on this platform" );\
if( !platform_timer_exists( id ) )\
return luaL_error( L, "timer %d does not exist", ( unsigned )id )\
#define MOD_CHECK_RES_ID( mod, id, resmod, resid )\
if( !platform_ ## mod ## _check_ ## resmod ## _id( id, resid ) )\
return luaL_error( L, #resmod" %d not valid with " #mod " %d", ( unsigned )resid, ( unsigned )id )
#endif

View File

@ -136,5 +136,9 @@ const LUA_REG_TYPE bit_map[] = {
};
LUALIB_API int luaopen_bit (lua_State *L) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -183,8 +183,7 @@ static int ICACHE_FLASH_ATTR bmp085_lua_pressure(lua_State* L) {
return 1;
}
const LUA_REG_TYPE bmp085_map[] =
{
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 )},
@ -193,6 +192,9 @@ const LUA_REG_TYPE bmp085_map[] =
};
LUALIB_API int luaopen_bmp085(lua_State *L) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -1528,37 +1528,7 @@ static int json_protect_conversion(lua_State *l)
* errors are memory related */
return luaL_error(l, "Memory allocation error in CJSON protected call");
}
#endif
// Module function map
const LUA_REG_TYPE cjson_map[] =
{
{ LSTRKEY( "encode" ), LFUNCVAL( json_encode ) },
{ LSTRKEY( "decode" ), LFUNCVAL( json_decode ) },
// { LSTRKEY( "encode_sparse_array" ), LFUNCVAL( json_cfg_encode_sparse_array ) },
// { LSTRKEY( "encode_max_depth" ), LFUNCVAL( json_cfg_encode_max_depth ) },
// { LSTRKEY( "decode_max_depth" ), LFUNCVAL( json_cfg_decode_max_depth ) },
// { LSTRKEY( "encode_number_precision" ), LFUNCVAL( json_cfg_encode_number_precision ) },
// { LSTRKEY( "encode_keep_buffer" ), LFUNCVAL( json_cfg_encode_keep_buffer ) },
// { 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 ) },
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_cjson( lua_State *L )
{
cjson_mem_setlua (L);
/* Initialise number conversions */
// fpconv_init(); // not needed for a specific cpu.
if(-1==cfg_init(&_cfg)){
return luaL_error(L, "BUG: Unable to init config for cjson");;
}
return 0;
}
#if 0
/* Return cjson module table */
static int lua_cjson_new(lua_State *l)
{
@ -1628,5 +1598,36 @@ int luaopen_cjson_safe(lua_State *l)
return 1;
}
#endif
// Module function map
const LUA_REG_TYPE cjson_map[] = {
{ LSTRKEY( "encode" ), LFUNCVAL( json_encode ) },
{ LSTRKEY( "decode" ), LFUNCVAL( json_decode ) },
//{ LSTRKEY( "encode_sparse_array" ), LFUNCVAL( json_cfg_encode_sparse_array ) },
//{ LSTRKEY( "encode_max_depth" ), LFUNCVAL( json_cfg_encode_max_depth ) },
//{ LSTRKEY( "decode_max_depth" ), LFUNCVAL( json_cfg_decode_max_depth ) },
//{ LSTRKEY( "encode_number_precision" ), LFUNCVAL( json_cfg_encode_number_precision ) },
//{ LSTRKEY( "encode_keep_buffer" ), LFUNCVAL( json_cfg_encode_keep_buffer ) },
//{ 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 ) },
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_cjson( lua_State *L )
{
cjson_mem_setlua (L);
/* Initialise number conversions */
// fpconv_init(); // not needed for a specific cpu.
if(-1==cfg_init(&_cfg)){
return luaL_error(L, "BUG: Unable to init config for cjson");;
}
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}
/* vi:ai et sw=4 ts=4:
*/

View File

@ -558,32 +558,30 @@ 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 ) },
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 ) },
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 }
};
const LUA_REG_TYPE coap_map[] =
{
{ LSTRKEY( "Server" ), LFUNCVAL ( coap_createServer ) },
{ LSTRKEY( "Client" ), LFUNCVAL ( coap_createClient ) },
{ 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 ) },
@ -592,7 +590,6 @@ const LUA_REG_TYPE coap_map[] =
{ 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 }
};
@ -602,5 +599,9 @@ LUALIB_API 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
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -150,8 +150,7 @@ static int crypto_lhmac (lua_State *L)
// Module function map
const LUA_REG_TYPE crypto_map[] =
{
const LUA_REG_TYPE crypto_map[] = {
{ LSTRKEY( "sha1" ), LFUNCVAL( crypto_sha1 ) },
{ LSTRKEY( "toBase64" ), LFUNCVAL( crypto_base64_encode ) },
{ LSTRKEY( "toHex" ), LFUNCVAL( crypto_hex_encode ) },
@ -161,7 +160,10 @@ const LUA_REG_TYPE crypto_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_crypto( lua_State *L )
{
LUALIB_API int luaopen_crypto( lua_State *L ) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -1,8 +1,8 @@
// Module for interfacing with the DHTxx sensors (xx = 11-21-22-33-44).
#include "lauxlib.h"
#include "auxmods.h"
#include "lrodefs.h"
#include "platform.h"
#include "cpu_esp8266.h"
#include "dht.h"
@ -99,8 +99,7 @@ static int dht_lapi_readxx( lua_State *L )
// }
// Module function map
const LUA_REG_TYPE dht_map[] =
{
const LUA_REG_TYPE dht_map[] = {
{ LSTRKEY( "read" ), LFUNCVAL( dht_lapi_read ) },
{ LSTRKEY( "read11" ), LFUNCVAL( dht_lapi_read11 ) },
{ LSTRKEY( "readxx" ), LFUNCVAL( dht_lapi_readxx ) },
@ -110,7 +109,10 @@ const LUA_REG_TYPE dht_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_dht( lua_State *L )
{
LUALIB_API int luaopen_dht( lua_State *L ) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -927,14 +927,17 @@ static int enduser_setup_stop(lua_State* L)
}
const LUA_REG_TYPE enduser_setup_map[] =
{
const LUA_REG_TYPE enduser_setup_map[] = {
{ LSTRKEY( "start" ), LFUNCVAL( enduser_setup_start )},
{ LSTRKEY( "stop" ), LFUNCVAL( enduser_setup_stop )},
{ LNILKEY, LNILVAL}
};
LUALIB_API int luaopen_enduser_setup(lua_State *L) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -296,8 +296,7 @@ static int file_writeline( lua_State* L )
}
// Module function map
const LUA_REG_TYPE file_map[] =
{
const LUA_REG_TYPE file_map[] = {
{ LSTRKEY( "list" ), LFUNCVAL( file_list ) },
{ LSTRKEY( "open" ), LFUNCVAL( file_open ) },
{ LSTRKEY( "close" ), LFUNCVAL( file_close ) },
@ -306,19 +305,21 @@ const LUA_REG_TYPE file_map[] =
{ LSTRKEY( "read" ), LFUNCVAL( file_read ) },
{ LSTRKEY( "readline" ), LFUNCVAL( file_readline ) },
{ LSTRKEY( "format" ), LFUNCVAL( file_format ) },
#if defined(BUILD_WOFS)
#elif defined(BUILD_SPIFFS)
#if defined(BUILD_SPIFFS) && !defined(BUILD_WOFS)
{ LSTRKEY( "remove" ), LFUNCVAL( file_remove ) },
{ LSTRKEY( "seek" ), LFUNCVAL( file_seek ) },
{ LSTRKEY( "flush" ), LFUNCVAL( file_flush ) },
// { LSTRKEY( "check" ), LFUNCVAL( file_check ) },
//{ LSTRKEY( "check" ), LFUNCVAL( file_check ) },
{ LSTRKEY( "rename" ), LFUNCVAL( file_rename ) },
{ LSTRKEY( "fsinfo" ), LFUNCVAL( file_fsinfo ) },
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_file( lua_State *L )
{
LUALIB_API int luaopen_file( lua_State *L ) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -1,7 +1,6 @@
// Module for interfacing with GPIO
#include "lauxlib.h"
#include "auxmods.h"
#include "platform.h"
#include "lrodefs.h"
@ -221,8 +220,7 @@ static int lgpio_serout( lua_State* L )
#undef DELAY_TABLE_MAX_LEN
// Module function map
const LUA_REG_TYPE gpio_map[] =
{
const LUA_REG_TYPE gpio_map[] = {
{ LSTRKEY( "mode" ), LFUNCVAL( lgpio_mode ) },
{ LSTRKEY( "read" ), LFUNCVAL( lgpio_read ) },
{ LSTRKEY( "write" ), LFUNCVAL( lgpio_write ) },
@ -240,8 +238,7 @@ const LUA_REG_TYPE gpio_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_gpio( lua_State *L )
{
LUALIB_API int luaopen_gpio( lua_State *L ) {
#ifdef GPIO_INTERRUPT_ENABLE
int i;
for(i=0;i<GPIO_PIN_NUM;i++){
@ -249,5 +246,10 @@ LUALIB_API int luaopen_gpio( lua_State *L )
}
platform_gpio_init(gpio_intr_callback);
#endif
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -3,7 +3,6 @@
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrodefs.h"
#include "c_stdlib.h"
#include "c_string.h"
@ -66,8 +65,8 @@ static int ICACHE_FLASH_ATTR hx711_read(lua_State* L) {
return 1;
}
const LUA_REG_TYPE hx711_map[] =
{
// Module function map
const LUA_REG_TYPE hx711_map[] = {
{ LSTRKEY( "init" ), LFUNCVAL( hx711_init )},
{ LSTRKEY( "read" ), LFUNCVAL( hx711_read )},
{ LNILKEY, LNILVAL}
@ -75,5 +74,9 @@ const LUA_REG_TYPE hx711_map[] =
LUALIB_API int luaopen_hx711(lua_State *L) {
// TODO: Make sure that the GPIO system is initialized
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -2,7 +2,6 @@
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrodefs.h"
// Lua: speed = i2c.setup( id, sda, scl, speed )
@ -141,23 +140,25 @@ static int i2c_read( lua_State *L )
}
// Module function map
const LUA_REG_TYPE i2c_map[] =
{
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( "FAST" ), LNUMVAL( PLATFORM_I2C_SPEED_FAST ) },
//{ 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 }
};
LUALIB_API int luaopen_i2c( lua_State *L )
{
LUALIB_API int luaopen_i2c( lua_State *L ) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -2,7 +2,6 @@
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrodefs.h"
#include "c_string.h"
@ -1390,22 +1389,20 @@ 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( "lwt" ), LFUNCVAL ( mqtt_socket_lwt ) },
{ LSTRKEY( "on" ), LFUNCVAL ( mqtt_socket_on ) },
{ LSTRKEY( "__gc" ), LFUNCVAL ( mqtt_delete ) },
{ LSTRKEY( "__index" ), LROVAL ( mqtt_socket_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( "lwt" ), LFUNCVAL( mqtt_socket_lwt ) },
{ LSTRKEY( "on" ), LFUNCVAL( mqtt_socket_on ) },
{ LSTRKEY( "__gc" ), LFUNCVAL( mqtt_delete ) },
{ LSTRKEY( "__index" ), LROVAL( mqtt_socket_map ) },
{ LNILKEY, LNILVAL }
};
const LUA_REG_TYPE mqtt_map[] =
{
{ LSTRKEY( "Client" ), LFUNCVAL ( mqtt_socket_client ) },
const LUA_REG_TYPE mqtt_map[] = {
{ LSTRKEY( "Client" ), LFUNCVAL( mqtt_socket_client ) },
{ LSTRKEY( "__metatable" ), LROVAL( mqtt_map ) },
{ LNILKEY, LNILVAL }
};
@ -1413,5 +1410,9 @@ const LUA_REG_TYPE mqtt_map[] =
LUALIB_API int luaopen_mqtt( lua_State *L )
{
luaL_rometatable(L, "mqtt.socket", (void *)mqtt_socket_map); // create metatable for mqtt.socket
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -2,7 +2,6 @@
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrodefs.h"
#include "c_string.h"
@ -1506,66 +1505,59 @@ static int expose_array(lua_State* L, char *array, unsigned short len) {
#endif
// Module function map
static const LUA_REG_TYPE net_server_map[] =
{
{ LSTRKEY( "listen" ), LFUNCVAL ( net_server_listen ) },
{ LSTRKEY( "close" ), LFUNCVAL ( net_server_close ) },
{ LSTRKEY( "on" ), LFUNCVAL ( net_udpserver_on ) },
{ LSTRKEY( "send" ), LFUNCVAL ( net_udpserver_send ) },
// { LSTRKEY( "delete" ), LFUNCVAL ( net_server_delete ) },
{ LSTRKEY( "__gc" ), LFUNCVAL ( net_server_delete ) },
{ LSTRKEY( "__index" ), LROVAL ( net_server_map ) },
static const LUA_REG_TYPE net_server_map[] = {
{ LSTRKEY( "listen" ), LFUNCVAL( net_server_listen ) },
{ LSTRKEY( "close" ), LFUNCVAL( net_server_close ) },
{ LSTRKEY( "on" ), LFUNCVAL( net_udpserver_on ) },
{ LSTRKEY( "send" ), LFUNCVAL( net_udpserver_send ) },
//{ LSTRKEY( "delete" ), LFUNCVAL( net_server_delete ) },
{ LSTRKEY( "__gc" ), LFUNCVAL( net_server_delete ) },
{ LSTRKEY( "__index" ), LROVAL( net_server_map ) },
{ LNILKEY, LNILVAL }
};
static const LUA_REG_TYPE net_socket_map[] =
{
static const LUA_REG_TYPE net_socket_map[] = {
{ LSTRKEY( "connect" ), LFUNCVAL( net_socket_connect ) },
{ LSTRKEY( "close" ), LFUNCVAL ( net_socket_close ) },
{ LSTRKEY( "on" ), LFUNCVAL ( net_socket_on ) },
{ LSTRKEY( "send" ), LFUNCVAL ( net_socket_send ) },
{ LSTRKEY( "hold" ), LFUNCVAL ( net_socket_hold ) },
{ LSTRKEY( "unhold" ), LFUNCVAL ( net_socket_unhold ) },
{ LSTRKEY( "dns" ), LFUNCVAL ( net_socket_dns ) },
{ LSTRKEY( "getpeer" ), LFUNCVAL ( net_socket_getpeer ) },
// { LSTRKEY( "delete" ), LFUNCVAL ( net_socket_delete ) },
{ LSTRKEY( "__gc" ), LFUNCVAL ( net_socket_delete ) },
{ LSTRKEY( "__index" ), LROVAL ( net_socket_map ) },
{ LSTRKEY( "close" ), LFUNCVAL( net_socket_close ) },
{ LSTRKEY( "on" ), LFUNCVAL( net_socket_on ) },
{ LSTRKEY( "send" ), LFUNCVAL( net_socket_send ) },
{ LSTRKEY( "hold" ), LFUNCVAL( net_socket_hold ) },
{ LSTRKEY( "unhold" ), LFUNCVAL( net_socket_unhold ) },
{ LSTRKEY( "dns" ), LFUNCVAL( net_socket_dns ) },
{ LSTRKEY( "getpeer" ), LFUNCVAL( net_socket_getpeer ) },
//{ LSTRKEY( "delete" ), LFUNCVAL( net_socket_delete ) },
{ LSTRKEY( "__gc" ), LFUNCVAL( net_socket_delete ) },
{ LSTRKEY( "__index" ), LROVAL( net_socket_map ) },
{ LNILKEY, LNILVAL }
};
#if 0
static const LUA_REG_TYPE net_array_map[] =
{
static const LUA_REG_TYPE net_array_map[] = {
{ LSTRKEY( "__index" ), LFUNCVAL( net_array_index ) },
{ LSTRKEY( "__newindex" ), LFUNCVAL( net_array_newindex ) },
{ LNILKEY, LNILVAL }
};
#endif
static const LUA_REG_TYPE net_dns_map[] =
{
{ LSTRKEY( "setdnsserver" ), LFUNCVAL ( net_setdnsserver ) },
{ LSTRKEY( "getdnsserver" ), LFUNCVAL ( net_getdnsserver ) },
{ LSTRKEY( "resolve" ), LFUNCVAL ( net_dns_static ) },
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 }
};
const LUA_REG_TYPE net_map[] =
{
{ LSTRKEY( "createServer" ), LFUNCVAL ( net_createServer ) },
{ LSTRKEY( "createConnection" ), LFUNCVAL ( net_createConnection ) },
const LUA_REG_TYPE net_map[] = {
{ LSTRKEY( "createServer" ), LFUNCVAL( net_createServer ) },
{ LSTRKEY( "createConnection" ), LFUNCVAL( net_createConnection ) },
{ LSTRKEY( "multicastJoin"), LFUNCVAL( net_multicastJoin ) },
{ LSTRKEY( "multicastLeave"), LFUNCVAL( net_multicastLeave ) },
{ LSTRKEY( "dns" ), LROVAL( net_dns_map ) },
{ LSTRKEY( "TCP" ), LNUMVAL( TCP ) },
{ LSTRKEY( "UDP" ), LNUMVAL( UDP ) },
{ LSTRKEY( "__metatable" ), LROVAL( net_map ) },
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_net( lua_State *L )
{
LUALIB_API int luaopen_net( lua_State *L ) {
int i;
for(i=0;i<MAX_SOCKET;i++)
{
@ -1577,5 +1569,10 @@ LUALIB_API int luaopen_net( lua_State *L )
#if 0
luaL_rometatable(L, "net.array", (void *)net_array_map); // create metatable for net.array
#endif
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -1,8 +1,8 @@
// Module for interfacing with the OneWire interface
#include "lauxlib.h"
#include "auxmods.h"
#include "lrodefs.h"
#include "platform.h"
#include "driver/onewire.h"
// Lua: ow.setup( id )
@ -280,8 +280,7 @@ static int ow_crc16( lua_State *L )
#endif
// Module function map
const LUA_REG_TYPE ow_map[] =
{
const LUA_REG_TYPE ow_map[] = {
{ LSTRKEY( "setup" ), LFUNCVAL( ow_setup ) },
{ LSTRKEY( "reset" ), LFUNCVAL( ow_reset ) },
{ LSTRKEY( "skip" ), LFUNCVAL( ow_skip ) },
@ -306,7 +305,10 @@ const LUA_REG_TYPE ow_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_ow( lua_State *L )
{
LUALIB_API int luaopen_ow( lua_State *L ) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -2,7 +2,6 @@
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrodefs.h"
#include "c_types.h"
@ -123,8 +122,7 @@ static int lpwm_getduty( lua_State* L )
}
// Module function map
const LUA_REG_TYPE pwm_map[] =
{
const LUA_REG_TYPE pwm_map[] = {
{ LSTRKEY( "setup" ), LFUNCVAL( lpwm_setup ) },
{ LSTRKEY( "close" ), LFUNCVAL( lpwm_close ) },
{ LSTRKEY( "start" ), LFUNCVAL( lpwm_start ) },
@ -136,7 +134,10 @@ const LUA_REG_TYPE pwm_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_pwm( lua_State *L )
{
LUALIB_API int luaopen_pwm( lua_State *L ) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -79,8 +79,8 @@ static int ICACHE_FLASH_ATTR rc_send(lua_State* L) {
return 1;
}
const LUA_REG_TYPE rc_map[] =
{
// Module function map
const LUA_REG_TYPE rc_map[] = {
{ LSTRKEY( "send" ), LFUNCVAL( rc_send )},
{ LNILKEY, LNILVAL}
};
@ -88,5 +88,9 @@ 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
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -165,8 +165,7 @@ static int rtcfifo_dsleep_until_sample (lua_State *L)
#endif
// Module function map
const LUA_REG_TYPE rtcfifo_map[] =
{
const LUA_REG_TYPE rtcfifo_map[] = {
{ LSTRKEY("prepare"), LFUNCVAL(rtcfifo_prepare) },
{ LSTRKEY("ready"), LFUNCVAL(rtcfifo_ready) },
{ LSTRKEY("put"), LFUNCVAL(rtcfifo_put) },
@ -182,5 +181,9 @@ const LUA_REG_TYPE rtcfifo_map[] =
LUALIB_API int luaopen_rtcfifo (lua_State *L)
{
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -41,14 +41,16 @@ static int rtcmem_write32 (lua_State *L)
// Module function map
const LUA_REG_TYPE rtcmem_map[] =
{
const LUA_REG_TYPE rtcmem_map[] = {
{ LSTRKEY("read32"), LFUNCVAL(rtcmem_read32) },
{ LSTRKEY("write32"), LFUNCVAL(rtcmem_write32) },
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_rtcmem (lua_State *L)
{
LUALIB_API int luaopen_rtcmem (lua_State *L) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -116,8 +116,7 @@ static int rtctime_dsleep_aligned (lua_State *L)
// Module function map
const LUA_REG_TYPE rtctime_map[] =
{
const LUA_REG_TYPE rtctime_map[] = {
{ LSTRKEY("set"), LFUNCVAL(rtctime_set) },
{ LSTRKEY("get"), LFUNCVAL(rtctime_get) },
{ LSTRKEY("dsleep"), LFUNCVAL(rtctime_dsleep) },
@ -125,7 +124,10 @@ const LUA_REG_TYPE rtctime_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_rtctime (lua_State *L)
{
LUALIB_API int luaopen_rtctime (lua_State *L) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -376,13 +376,15 @@ error:
// Module function map
const LUA_REG_TYPE sntp_map[] =
{
const LUA_REG_TYPE sntp_map[] = {
{ LSTRKEY("sync"), LFUNCVAL(sntp_sync) },
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_sntp (lua_State *L)
{
LUALIB_API int luaopen_sntp (lua_State *L) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -2,7 +2,6 @@
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrodefs.h"
#define SPI_HALFDUPLEX 0
@ -307,8 +306,7 @@ static int spi_transaction( lua_State *L )
// Module function map
const LUA_REG_TYPE spi_map[] =
{
const LUA_REG_TYPE spi_map[] = {
{ LSTRKEY( "setup" ), LFUNCVAL( spi_setup ) },
{ LSTRKEY( "send" ), LFUNCVAL( spi_send_recv ) },
{ LSTRKEY( "recv" ), LFUNCVAL( spi_recv ) },
@ -327,7 +325,10 @@ const LUA_REG_TYPE spi_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_spi( lua_State *L )
{
LUALIB_API int luaopen_spi( lua_State *L ) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -50,7 +50,6 @@ tmr.softwd(int)
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrodefs.h"
#include "c_types.h"
@ -313,13 +312,13 @@ const LUA_REG_TYPE tmr_map[] = {
{ LSTRKEY( "wdclr" ), LFUNCVAL( tmr_wdclr ) },
{ LSTRKEY( "softwd" ), LFUNCVAL( tmr_softwd ) },
{ LSTRKEY( "time" ), LFUNCVAL( tmr_time ) },
{ LSTRKEY( "register" ), LFUNCVAL ( tmr_register ) },
{ 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) },
{ 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) },
{ LSTRKEY( "ALARM_SINGLE" ), LNUMVAL( TIMER_MODE_SINGLE ) },
{ LSTRKEY( "ALARM_SEMI" ), LNUMVAL( TIMER_MODE_SEMI ) },
{ LSTRKEY( "ALARM_AUTO" ), LNUMVAL( TIMER_MODE_AUTO ) },
@ -338,6 +337,9 @@ 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 MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -100,35 +100,34 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_getchannels(lua_State* L) {
return 3;
}
const LUA_REG_TYPE tsl2561_map[] =
{
// Module function map
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}
};
LUALIB_API int luaopen_tsl2561(lua_State *L) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -1025,8 +1025,7 @@ U8G_DISPLAY_TABLE_SPI
// Module function map
static const LUA_REG_TYPE lu8g_display_map[] =
{
static const LUA_REG_TYPE lu8g_display_map[] = {
{ LSTRKEY( "begin" ), LFUNCVAL( lu8g_begin ) },
{ LSTRKEY( "drawBitmap" ), LFUNCVAL( lu8g_drawBitmap ) },
{ LSTRKEY( "drawBox" ), LFUNCVAL( lu8g_drawBox ) },
@ -1078,39 +1077,40 @@ static const LUA_REG_TYPE lu8g_display_map[] =
{ LSTRKEY( "undoRotation" ), LFUNCVAL( lu8g_undoRotation ) },
{ LSTRKEY( "undoScale" ), LFUNCVAL( lu8g_undoScale ) },
{ LSTRKEY( "__gc" ), LFUNCVAL( lu8g_close_display ) },
{ LSTRKEY( "__index" ), LROVAL ( lu8g_display_map ) },
{ LSTRKEY( "__index" ), LROVAL( lu8g_display_map ) },
{ LNILKEY, LNILVAL }
};
const LUA_REG_TYPE lu8g_map[] =
{
#undef U8G_DISPLAY_TABLE_ENTRY
#define U8G_DISPLAY_TABLE_ENTRY(device) { LSTRKEY( #device ), LFUNCVAL ( lu8g_ ##device ) },
#undef U8G_FONT_TABLE_ENTRY
const LUA_REG_TYPE lu8g_map[] = {
#define U8G_DISPLAY_TABLE_ENTRY(device) \
{ LSTRKEY( #device ), LFUNCVAL ( lu8g_ ##device ) },
U8G_DISPLAY_TABLE_I2C
U8G_DISPLAY_TABLE_SPI
// Register fonts
#undef U8G_FONT_TABLE_ENTRY
#define U8G_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(u8g_ ## font) ) },
// Register fonts
#define U8G_FONT_TABLE_ENTRY(font) \
{ LSTRKEY( #font ), LUDATA( (void *)(u8g_ ## font) ) },
U8G_FONT_TABLE
// Options for circle/ ellipse drawing
{ LSTRKEY( "DRAW_UPPER_RIGHT" ), LNUMVAL( U8G_DRAW_UPPER_RIGHT ) },
{ LSTRKEY( "DRAW_UPPER_LEFT" ), LNUMVAL( U8G_DRAW_UPPER_LEFT ) },
{ LSTRKEY( "DRAW_LOWER_RIGHT" ), LNUMVAL( U8G_DRAW_LOWER_RIGHT ) },
{ LSTRKEY( "DRAW_LOWER_LEFT" ), LNUMVAL( U8G_DRAW_LOWER_LEFT ) },
{ LSTRKEY( "DRAW_ALL" ), LNUMVAL( U8G_DRAW_ALL ) },
// Display modes
{ LSTRKEY( "MODE_BW" ), LNUMVAL( U8G_MODE_BW ) },
{ LSTRKEY( "MODE_GRAY2BIT" ), LNUMVAL( U8G_MODE_GRAY2BIT ) },
{ LSTRKEY( "__metatable" ), LROVAL( lu8g_map ) },
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_u8g( lua_State *L )
{
LUALIB_API int luaopen_u8g( lua_State *L ) {
luaL_rometatable(L, "u8g.display", (void *)lu8g_display_map); // create metatable
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -2,7 +2,6 @@
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrodefs.h"
#include "c_types.h"
@ -156,8 +155,7 @@ static int uart_write( lua_State* L )
}
// Module function map
const LUA_REG_TYPE uart_map[] =
{
const LUA_REG_TYPE uart_map[] = {
{ LSTRKEY( "setup" ), LFUNCVAL( uart_setup ) },
{ LSTRKEY( "write" ), LFUNCVAL( uart_write ) },
{ LSTRKEY( "on" ), LFUNCVAL( uart_on ) },
@ -165,7 +163,10 @@ const LUA_REG_TYPE uart_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_uart( lua_State *L )
{
LUALIB_API int luaopen_uart( lua_State *L ) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -1337,52 +1337,47 @@ static int wifi_ap_dhcp_stop( lua_State* L )
}
// Module function map
static const LUA_REG_TYPE wifi_station_map[] =
{
{ LSTRKEY( "getconfig" ), LFUNCVAL ( wifi_station_getconfig ) },
{ LSTRKEY( "config" ), LFUNCVAL ( wifi_station_config ) },
{ LSTRKEY( "connect" ), LFUNCVAL ( wifi_station_connect4lua ) },
{ LSTRKEY( "disconnect" ), LFUNCVAL ( wifi_station_disconnect4lua ) },
{ LSTRKEY( "autoconnect" ), LFUNCVAL ( wifi_station_setauto ) },
{ LSTRKEY( "getip" ), LFUNCVAL ( wifi_station_getip ) },
{ LSTRKEY( "setip" ), LFUNCVAL ( wifi_station_setip ) },
{ LSTRKEY( "getbroadcast" ), LFUNCVAL ( wifi_station_getbroadcast) },
{ LSTRKEY( "getmac" ), LFUNCVAL ( wifi_station_getmac ) },
{ LSTRKEY( "setmac" ), LFUNCVAL ( wifi_station_setmac ) },
{ LSTRKEY( "getap" ), LFUNCVAL ( wifi_station_listap ) },
{ LSTRKEY( "status" ), LFUNCVAL ( wifi_station_status ) },
{ LSTRKEY( "eventMonReg" ), LFUNCVAL ( wifi_station_event_mon_reg ) },
{ LSTRKEY( "eventMonStart" ), LFUNCVAL ( wifi_station_event_mon_start ) },
{ LSTRKEY( "eventMonStop" ), LFUNCVAL ( wifi_station_event_mon_stop ) },
static const LUA_REG_TYPE wifi_station_map[] = {
{ LSTRKEY( "getconfig" ), LFUNCVAL( wifi_station_getconfig ) },
{ LSTRKEY( "config" ), LFUNCVAL( wifi_station_config ) },
{ LSTRKEY( "connect" ), LFUNCVAL( wifi_station_connect4lua ) },
{ LSTRKEY( "disconnect" ), LFUNCVAL( wifi_station_disconnect4lua ) },
{ LSTRKEY( "autoconnect" ), LFUNCVAL( wifi_station_setauto ) },
{ LSTRKEY( "getip" ), LFUNCVAL( wifi_station_getip ) },
{ LSTRKEY( "setip" ), LFUNCVAL( wifi_station_setip ) },
{ LSTRKEY( "getbroadcast" ), LFUNCVAL( wifi_station_getbroadcast) },
{ LSTRKEY( "getmac" ), LFUNCVAL( wifi_station_getmac ) },
{ LSTRKEY( "setmac" ), LFUNCVAL( wifi_station_setmac ) },
{ LSTRKEY( "getap" ), LFUNCVAL( wifi_station_listap ) },
{ LSTRKEY( "status" ), LFUNCVAL( wifi_station_status ) },
{ LSTRKEY( "eventMonReg" ), LFUNCVAL( wifi_station_event_mon_reg ) },
{ LSTRKEY( "eventMonStart" ), LFUNCVAL( wifi_station_event_mon_start ) },
{ LSTRKEY( "eventMonStop" ), LFUNCVAL( wifi_station_event_mon_stop ) },
{ LNILKEY, LNILVAL }
};
static const LUA_REG_TYPE wifi_ap_dhcp_map[] =
{
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[] =
{
static const LUA_REG_TYPE wifi_ap_map[] = {
{ LSTRKEY( "config" ), LFUNCVAL( wifi_ap_config ) },
{ 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( "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 ) },
{ LSTRKEY( "dhcp" ), LROVAL( wifi_ap_dhcp_map ) },
// { LSTRKEY( "__metatable" ), LROVAL( wifi_ap_map ) },
//{ LSTRKEY( "__metatable" ), LROVAL( wifi_ap_map ) },
{ LNILKEY, LNILVAL }
};
const LUA_REG_TYPE wifi_map[] =
{
const LUA_REG_TYPE wifi_map[] = {
{ LSTRKEY( "setmode" ), LFUNCVAL( wifi_setmode ) },
{ LSTRKEY( "getmode" ), LFUNCVAL( wifi_getmode ) },
{ LSTRKEY( "getchannel" ), LFUNCVAL( wifi_getchannel ) },
@ -1410,7 +1405,7 @@ const LUA_REG_TYPE wifi_map[] =
{ LSTRKEY( "MODEM_SLEEP" ), LNUMVAL( MODEM_SLEEP_T ) },
{ LSTRKEY( "OPEN" ), LNUMVAL( AUTH_OPEN ) },
// { LSTRKEY( "WEP" ), LNUMVAL( AUTH_WEP ) },
//{ 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 ) },
@ -1428,5 +1423,9 @@ const LUA_REG_TYPE wifi_map[] =
LUALIB_API int luaopen_wifi( lua_State *L )
{
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
}

View File

@ -243,4 +243,20 @@ int platform_flash_erase_sector( uint32_t sector_id );
void* platform_get_first_free_ram( unsigned id );
void* platform_get_last_free_ram( unsigned id );
// *****************************************************************************
// Helper macros
#define MOD_CHECK_ID( mod, id )\
if( !platform_ ## mod ## _exists( id ) )\
return luaL_error( L, #mod" %d does not exist", ( unsigned )id )
#define MOD_CHECK_TIMER( id )\
if( id == PLATFORM_TIMER_SYS_ID && !platform_timer_sys_available() )\
return luaL_error( L, "the system timer is not available on this platform" );\
if( !platform_timer_exists( id ) )\
return luaL_error( L, "timer %d does not exist", ( unsigned )id )\
#define MOD_CHECK_RES_ID( mod, id, resmod, resid )\
if( !platform_ ## mod ## _check_ ## resmod ## _id( id, resid ) )\
return luaL_error( L, #resmod" %d not valid with " #mod " %d", ( unsigned )resid, ( unsigned )id )
#endif