Commit b773290b authored by TerryE's avatar TerryE Committed by Johny Mattsson
Browse files

Major cleanup of module registration pass 2.

carrying on Johny's edits as per my comments on #810
parent 6b6456be
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h"
#include "lrodefs.h" #include "lrodefs.h"
#include "c_types.h" #include "c_types.h"
...@@ -26,14 +25,16 @@ static int adc_readvdd33( lua_State* L ) ...@@ -26,14 +25,16 @@ static int adc_readvdd33( lua_State* L )
} }
// Module function map // Module function map
const LUA_REG_TYPE adc_map[] = const LUA_REG_TYPE adc_map[] = {
{ { LSTRKEY( "read" ), LFUNCVAL( adc_sample ) },
{ LSTRKEY( "read" ), LFUNCVAL( adc_sample ) },
{ LSTRKEY( "readvdd33" ), LFUNCVAL( adc_readvdd33) }, { LSTRKEY( "readvdd33" ), LFUNCVAL( adc_readvdd33) },
{ LNILKEY, LNILVAL } { 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; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
// 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
...@@ -136,5 +136,9 @@ const LUA_REG_TYPE bit_map[] = { ...@@ -136,5 +136,9 @@ const LUA_REG_TYPE bit_map[] = {
}; };
LUALIB_API int luaopen_bit (lua_State *L) { LUALIB_API int luaopen_bit (lua_State *L) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
...@@ -183,16 +183,18 @@ static int ICACHE_FLASH_ATTR bmp085_lua_pressure(lua_State* L) { ...@@ -183,16 +183,18 @@ static int ICACHE_FLASH_ATTR bmp085_lua_pressure(lua_State* L) {
return 1; return 1;
} }
const LUA_REG_TYPE bmp085_map[] = const LUA_REG_TYPE bmp085_map[] = {
{ { LSTRKEY( "temperature" ), LFUNCVAL( bmp085_lua_temperature )},
{ LSTRKEY( "temperature" ), LFUNCVAL( bmp085_lua_temperature )}, { LSTRKEY( "pressure" ), LFUNCVAL( bmp085_lua_pressure )},
{ LSTRKEY( "pressure" ), LFUNCVAL( bmp085_lua_pressure )},
{ LSTRKEY( "pressure_raw" ), LFUNCVAL( bmp085_lua_pressure_raw )}, { LSTRKEY( "pressure_raw" ), LFUNCVAL( bmp085_lua_pressure_raw )},
{ LSTRKEY( "init" ), LFUNCVAL( bmp085_init )}, { LSTRKEY( "init" ), LFUNCVAL( bmp085_init )},
{ LNILKEY, LNILVAL} { LNILKEY, LNILVAL}
}; };
LUALIB_API int luaopen_bmp085(lua_State *L) { LUALIB_API int luaopen_bmp085(lua_State *L) {
return 0; #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
} }
...@@ -1528,37 +1528,7 @@ static int json_protect_conversion(lua_State *l) ...@@ -1528,37 +1528,7 @@ static int json_protect_conversion(lua_State *l)
* errors are memory related */ * errors are memory related */
return luaL_error(l, "Memory allocation error in CJSON protected call"); 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 */ /* Return cjson module table */
static int lua_cjson_new(lua_State *l) static int lua_cjson_new(lua_State *l)
{ {
...@@ -1628,5 +1598,36 @@ int luaopen_cjson_safe(lua_State *l) ...@@ -1628,5 +1598,36 @@ int luaopen_cjson_safe(lua_State *l)
return 1; return 1;
} }
#endif #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: /* vi:ai et sw=4 ts=4:
*/ */
...@@ -558,41 +558,38 @@ static int coap_client_delete( lua_State* L ) ...@@ -558,41 +558,38 @@ static int coap_client_delete( lua_State* L )
} }
// Module function map // Module function map
static const LUA_REG_TYPE coap_server_map[] = static const LUA_REG_TYPE coap_server_map[] = {
{ { LSTRKEY( "listen" ), LFUNCVAL( coap_server_listen ) },
{ LSTRKEY( "listen" ), LFUNCVAL ( coap_server_listen ) }, { LSTRKEY( "close" ), LFUNCVAL( coap_server_close ) },
{ LSTRKEY( "close" ), LFUNCVAL ( coap_server_close ) }, { LSTRKEY( "var" ), LFUNCVAL( coap_server_var ) },
{ LSTRKEY( "var" ), LFUNCVAL ( coap_server_var ) }, { LSTRKEY( "func" ), LFUNCVAL( coap_server_func ) },
{ LSTRKEY( "func" ), LFUNCVAL ( coap_server_func ) }, { LSTRKEY( "__gc" ), LFUNCVAL( coap_server_delete ) },
{ LSTRKEY( "__gc" ), LFUNCVAL ( coap_server_delete ) }, { LSTRKEY( "__index" ), LROVAL( coap_server_map ) },
{ LSTRKEY( "__index" ), LROVAL ( coap_server_map ) },
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
static const LUA_REG_TYPE coap_client_map[] = static const LUA_REG_TYPE coap_client_map[] = {
{ { LSTRKEY( "get" ), LFUNCVAL( coap_client_get ) },
{ LSTRKEY( "get" ), LFUNCVAL ( coap_client_get ) }, { LSTRKEY( "post" ), LFUNCVAL( coap_client_post ) },
{ LSTRKEY( "post" ), LFUNCVAL ( coap_client_post ) }, { LSTRKEY( "put" ), LFUNCVAL( coap_client_put ) },
{ LSTRKEY( "put" ), LFUNCVAL ( coap_client_put ) }, { LSTRKEY( "delete" ), LFUNCVAL( coap_client_delete ) },
{ LSTRKEY( "delete" ), LFUNCVAL ( coap_client_delete ) }, { LSTRKEY( "__gc" ), LFUNCVAL( coap_client_gcdelete ) },
{ LSTRKEY( "__gc" ), LFUNCVAL ( coap_client_gcdelete ) }, { LSTRKEY( "__index" ), LROVAL( coap_client_map ) },
{ LSTRKEY( "__index" ), LROVAL ( coap_client_map ) },
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
const LUA_REG_TYPE coap_map[] = const LUA_REG_TYPE coap_map[] =
{ {
{ LSTRKEY( "Server" ), LFUNCVAL ( coap_createServer ) }, { LSTRKEY( "Server" ), LFUNCVAL( coap_createServer ) },
{ LSTRKEY( "Client" ), LFUNCVAL ( coap_createClient ) }, { LSTRKEY( "Client" ), LFUNCVAL( coap_createClient ) },
{ LSTRKEY( "CON" ), LNUMVAL( COAP_TYPE_CON ) }, { LSTRKEY( "CON" ), LNUMVAL( COAP_TYPE_CON ) },
{ LSTRKEY( "NON" ), LNUMVAL( COAP_TYPE_NONCON ) }, { LSTRKEY( "NON" ), LNUMVAL( COAP_TYPE_NONCON ) },
{ LSTRKEY( "TEXT_PLAIN"), LNUMVAL( COAP_CONTENTTYPE_TEXT_PLAIN ) }, { LSTRKEY( "TEXT_PLAIN"), LNUMVAL( COAP_CONTENTTYPE_TEXT_PLAIN ) },
{ LSTRKEY( "LINKFORMAT"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_LINKFORMAT ) }, { LSTRKEY( "LINKFORMAT"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_LINKFORMAT ) },
{ LSTRKEY( "XML"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_XML ) }, { LSTRKEY( "XML"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_XML ) },
{ LSTRKEY( "OCTET_STREAM"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_OCTET_STREAM ) }, { LSTRKEY( "OCTET_STREAM"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_OCTET_STREAM ) },
{ LSTRKEY( "EXI"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_EXI ) }, { LSTRKEY( "EXI"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_EXI ) },
{ LSTRKEY( "JSON"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_JSON) }, { LSTRKEY( "JSON"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_JSON) },
{ LSTRKEY( "__metatable" ), LROVAL( coap_map ) }, { LSTRKEY( "__metatable" ), LROVAL( coap_map ) },
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
...@@ -602,5 +599,9 @@ LUALIB_API int luaopen_coap( lua_State *L ) ...@@ -602,5 +599,9 @@ LUALIB_API int luaopen_coap( lua_State *L )
endpoint_setup(); endpoint_setup();
luaL_rometatable(L, "coap_server", (void *)coap_server_map); // create metatable for coap_server 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_client", (void *)coap_client_map); // create metatable for coap_client
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
...@@ -150,18 +150,20 @@ static int crypto_lhmac (lua_State *L) ...@@ -150,18 +150,20 @@ static int crypto_lhmac (lua_State *L)
// Module function map // Module function map
const LUA_REG_TYPE crypto_map[] = const LUA_REG_TYPE crypto_map[] = {
{ { LSTRKEY( "sha1" ), LFUNCVAL( crypto_sha1 ) },
{ LSTRKEY( "sha1" ), LFUNCVAL( crypto_sha1 ) },
{ LSTRKEY( "toBase64" ), LFUNCVAL( crypto_base64_encode ) }, { LSTRKEY( "toBase64" ), LFUNCVAL( crypto_base64_encode ) },
{ LSTRKEY( "toHex" ), LFUNCVAL( crypto_hex_encode ) }, { LSTRKEY( "toHex" ), LFUNCVAL( crypto_hex_encode ) },
{ LSTRKEY( "mask" ), LFUNCVAL( crypto_mask ) }, { LSTRKEY( "mask" ), LFUNCVAL( crypto_mask ) },
{ LSTRKEY( "hash" ), LFUNCVAL( crypto_lhash ) }, { LSTRKEY( "hash" ), LFUNCVAL( crypto_lhash ) },
{ LSTRKEY( "hmac" ), LFUNCVAL( crypto_lhmac ) }, { LSTRKEY( "hmac" ), LFUNCVAL( crypto_lhmac ) },
{ LNILKEY, LNILVAL } { 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; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
// Module for interfacing with the DHTxx sensors (xx = 11-21-22-33-44). // Module for interfacing with the DHTxx sensors (xx = 11-21-22-33-44).
#include "lauxlib.h" #include "lauxlib.h"
#include "auxmods.h"
#include "lrodefs.h" #include "lrodefs.h"
#include "platform.h"
#include "cpu_esp8266.h" #include "cpu_esp8266.h"
#include "dht.h" #include "dht.h"
...@@ -99,18 +99,20 @@ static int dht_lapi_readxx( lua_State *L ) ...@@ -99,18 +99,20 @@ static int dht_lapi_readxx( lua_State *L )
// } // }
// Module function map // Module function map
const LUA_REG_TYPE dht_map[] = const LUA_REG_TYPE dht_map[] = {
{ { LSTRKEY( "read" ), LFUNCVAL( dht_lapi_read ) },
{ LSTRKEY( "read" ), LFUNCVAL( dht_lapi_read ) }, { LSTRKEY( "read11" ), LFUNCVAL( dht_lapi_read11 ) },
{ LSTRKEY( "read11" ), LFUNCVAL( dht_lapi_read11 ) }, { LSTRKEY( "readxx" ), LFUNCVAL( dht_lapi_readxx ) },
{ LSTRKEY( "readxx" ), LFUNCVAL( dht_lapi_readxx ) }, { LSTRKEY( "OK" ), LNUMVAL( DHTLIB_OK ) },
{ LSTRKEY( "OK" ), LNUMVAL( DHTLIB_OK ) },
{ LSTRKEY( "ERROR_CHECKSUM" ), LNUMVAL( DHTLIB_ERROR_CHECKSUM ) }, { LSTRKEY( "ERROR_CHECKSUM" ), LNUMVAL( DHTLIB_ERROR_CHECKSUM ) },
{ LSTRKEY( "ERROR_TIMEOUT" ), LNUMVAL( DHTLIB_ERROR_TIMEOUT ) }, { LSTRKEY( "ERROR_TIMEOUT" ), LNUMVAL( DHTLIB_ERROR_TIMEOUT ) },
{ LNILKEY, LNILVAL } { 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; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
...@@ -927,14 +927,17 @@ static int enduser_setup_stop(lua_State* L) ...@@ -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( "start" ), LFUNCVAL( enduser_setup_start )},
{ LSTRKEY( "stop" ), LFUNCVAL( enduser_setup_stop )}, { LSTRKEY( "stop" ), LFUNCVAL( enduser_setup_stop )},
{ LNILKEY, LNILVAL} { LNILKEY, LNILVAL}
}; };
LUALIB_API int luaopen_enduser_setup(lua_State *L) { LUALIB_API int luaopen_enduser_setup(lua_State *L) {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
...@@ -296,29 +296,30 @@ static int file_writeline( lua_State* L ) ...@@ -296,29 +296,30 @@ static int file_writeline( lua_State* L )
} }
// Module function map // Module function map
const LUA_REG_TYPE file_map[] = const LUA_REG_TYPE file_map[] = {
{ { LSTRKEY( "list" ), LFUNCVAL( file_list ) },
{ LSTRKEY( "list" ), LFUNCVAL( file_list ) }, { LSTRKEY( "open" ), LFUNCVAL( file_open ) },
{ LSTRKEY( "open" ), LFUNCVAL( file_open ) }, { LSTRKEY( "close" ), LFUNCVAL( file_close ) },
{ LSTRKEY( "close" ), LFUNCVAL( file_close ) }, { LSTRKEY( "write" ), LFUNCVAL( file_write ) },
{ LSTRKEY( "write" ), LFUNCVAL( file_write ) },
{ LSTRKEY( "writeline" ), LFUNCVAL( file_writeline ) }, { LSTRKEY( "writeline" ), LFUNCVAL( file_writeline ) },
{ LSTRKEY( "read" ), LFUNCVAL( file_read ) }, { LSTRKEY( "read" ), LFUNCVAL( file_read ) },
{ LSTRKEY( "readline" ), LFUNCVAL( file_readline ) }, { LSTRKEY( "readline" ), LFUNCVAL( file_readline ) },
{ LSTRKEY( "format" ), LFUNCVAL( file_format ) }, { LSTRKEY( "format" ), LFUNCVAL( file_format ) },
#if defined(BUILD_WOFS) #if defined(BUILD_SPIFFS) && !defined(BUILD_WOFS)
#elif defined(BUILD_SPIFFS) { LSTRKEY( "remove" ), LFUNCVAL( file_remove ) },
{ LSTRKEY( "remove" ), LFUNCVAL( file_remove ) }, { LSTRKEY( "seek" ), LFUNCVAL( file_seek ) },
{ LSTRKEY( "seek" ), LFUNCVAL( file_seek ) }, { LSTRKEY( "flush" ), LFUNCVAL( file_flush ) },
{ LSTRKEY( "flush" ), LFUNCVAL( file_flush ) }, //{ LSTRKEY( "check" ), LFUNCVAL( file_check ) },
// { LSTRKEY( "check" ), LFUNCVAL( file_check ) }, { LSTRKEY( "rename" ), LFUNCVAL( file_rename ) },
{ LSTRKEY( "rename" ), LFUNCVAL( file_rename ) }, { LSTRKEY( "fsinfo" ), LFUNCVAL( file_fsinfo ) },
{ LSTRKEY( "fsinfo" ), LFUNCVAL( file_fsinfo ) },
#endif #endif
{ LNILKEY, LNILVAL } { 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; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
// Module for interfacing with GPIO // Module for interfacing with GPIO
#include "lauxlib.h" #include "lauxlib.h"
#include "auxmods.h"
#include "platform.h" #include "platform.h"
#include "lrodefs.h" #include "lrodefs.h"
...@@ -221,27 +220,25 @@ static int lgpio_serout( lua_State* L ) ...@@ -221,27 +220,25 @@ static int lgpio_serout( lua_State* L )
#undef DELAY_TABLE_MAX_LEN #undef DELAY_TABLE_MAX_LEN
// Module function map // Module function map
const LUA_REG_TYPE gpio_map[] = const LUA_REG_TYPE gpio_map[] = {
{ { LSTRKEY( "mode" ), LFUNCVAL( lgpio_mode ) },
{ LSTRKEY( "mode" ), LFUNCVAL( lgpio_mode ) }, { LSTRKEY( "read" ), LFUNCVAL( lgpio_read ) },
{ LSTRKEY( "read" ), LFUNCVAL( lgpio_read ) }, { LSTRKEY( "write" ), LFUNCVAL( lgpio_write ) },
{ LSTRKEY( "write" ), LFUNCVAL( lgpio_write ) },
{ LSTRKEY( "serout" ), LFUNCVAL( lgpio_serout ) }, { LSTRKEY( "serout" ), LFUNCVAL( lgpio_serout ) },
#ifdef GPIO_INTERRUPT_ENABLE #ifdef GPIO_INTERRUPT_ENABLE
{ LSTRKEY( "trig" ), LFUNCVAL( lgpio_trig ) }, { LSTRKEY( "trig" ), LFUNCVAL( lgpio_trig ) },
{ LSTRKEY( "INT" ), LNUMVAL( INTERRUPT ) }, { LSTRKEY( "INT" ), LNUMVAL( INTERRUPT ) },
#endif #endif
{ LSTRKEY( "OUTPUT" ), LNUMVAL( OUTPUT ) }, { LSTRKEY( "OUTPUT" ), LNUMVAL( OUTPUT ) },
{ LSTRKEY( "INPUT" ), LNUMVAL( INPUT ) }, { LSTRKEY( "INPUT" ), LNUMVAL( INPUT ) },
{ LSTRKEY( "HIGH" ), LNUMVAL( HIGH ) }, { LSTRKEY( "HIGH" ), LNUMVAL( HIGH ) },
{ LSTRKEY( "LOW" ), LNUMVAL( LOW ) }, { LSTRKEY( "LOW" ), LNUMVAL( LOW ) },
{ LSTRKEY( "FLOAT" ), LNUMVAL( FLOAT ) }, { LSTRKEY( "FLOAT" ), LNUMVAL( FLOAT ) },
{ LSTRKEY( "PULLUP" ), LNUMVAL( PULLUP ) }, { LSTRKEY( "PULLUP" ), LNUMVAL( PULLUP ) },
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
LUALIB_API int luaopen_gpio( lua_State *L ) LUALIB_API int luaopen_gpio( lua_State *L ) {
{
#ifdef GPIO_INTERRUPT_ENABLE #ifdef GPIO_INTERRUPT_ENABLE
int i; int i;
for(i=0;i<GPIO_PIN_NUM;i++){ for(i=0;i<GPIO_PIN_NUM;i++){
...@@ -249,5 +246,10 @@ LUALIB_API int luaopen_gpio( lua_State *L ) ...@@ -249,5 +246,10 @@ LUALIB_API int luaopen_gpio( lua_State *L )
} }
platform_gpio_init(gpio_intr_callback); platform_gpio_init(gpio_intr_callback);
#endif #endif
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h"
#include "lrodefs.h" #include "lrodefs.h"
#include "c_stdlib.h" #include "c_stdlib.h"
#include "c_string.h" #include "c_string.h"
...@@ -66,8 +65,8 @@ static int ICACHE_FLASH_ATTR hx711_read(lua_State* L) { ...@@ -66,8 +65,8 @@ static int ICACHE_FLASH_ATTR hx711_read(lua_State* L) {
return 1; return 1;
} }
const LUA_REG_TYPE hx711_map[] = // Module function map
{ const LUA_REG_TYPE hx711_map[] = {
{ LSTRKEY( "init" ), LFUNCVAL( hx711_init )}, { LSTRKEY( "init" ), LFUNCVAL( hx711_init )},
{ LSTRKEY( "read" ), LFUNCVAL( hx711_read )}, { LSTRKEY( "read" ), LFUNCVAL( hx711_read )},
{ LNILKEY, LNILVAL} { LNILKEY, LNILVAL}
...@@ -75,5 +74,9 @@ const LUA_REG_TYPE hx711_map[] = ...@@ -75,5 +74,9 @@ const LUA_REG_TYPE hx711_map[] =
LUALIB_API int luaopen_hx711(lua_State *L) { LUALIB_API int luaopen_hx711(lua_State *L) {
// TODO: Make sure that the GPIO system is initialized // TODO: Make sure that the GPIO system is initialized
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h"
#include "lrodefs.h" #include "lrodefs.h"
// Lua: speed = i2c.setup( id, sda, scl, speed ) // Lua: speed = i2c.setup( id, sda, scl, speed )
...@@ -141,23 +140,25 @@ static int i2c_read( lua_State *L ) ...@@ -141,23 +140,25 @@ static int i2c_read( lua_State *L )
} }
// Module function map // Module function map
const LUA_REG_TYPE i2c_map[] = const LUA_REG_TYPE i2c_map[] = {
{ { LSTRKEY( "setup" ), LFUNCVAL( i2c_setup ) },
{ LSTRKEY( "setup" ), LFUNCVAL( i2c_setup ) }, { LSTRKEY( "start" ), LFUNCVAL( i2c_start ) },
{ LSTRKEY( "start" ), LFUNCVAL( i2c_start ) }, { LSTRKEY( "stop" ), LFUNCVAL( i2c_stop ) },
{ LSTRKEY( "stop" ), LFUNCVAL( i2c_stop ) }, { LSTRKEY( "address" ), LFUNCVAL( i2c_address ) },
{ LSTRKEY( "address" ), LFUNCVAL( i2c_address ) }, { LSTRKEY( "write" ), LFUNCVAL( i2c_write ) },
{ LSTRKEY( "write" ), LFUNCVAL( i2c_write ) }, { LSTRKEY( "read" ), LFUNCVAL( i2c_read ) },
{ 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( "SLOW" ), LNUMVAL( PLATFORM_I2C_SPEED_SLOW ) },
{ LSTRKEY( "TRANSMITTER" ), LNUMVAL( PLATFORM_I2C_DIRECTION_TRANSMITTER ) }, { LSTRKEY( "TRANSMITTER" ), LNUMVAL( PLATFORM_I2C_DIRECTION_TRANSMITTER ) },
{ LSTRKEY( "RECEIVER" ), LNUMVAL( PLATFORM_I2C_DIRECTION_RECEIVER ) }, { LSTRKEY( "RECEIVER" ), LNUMVAL( PLATFORM_I2C_DIRECTION_RECEIVER ) },
{ LNILKEY, LNILVAL } { 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; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h"
#include "lrodefs.h" #include "lrodefs.h"
#include "c_string.h" #include "c_string.h"
...@@ -1390,22 +1389,20 @@ static int mqtt_socket_lwt( lua_State* L ) ...@@ -1390,22 +1389,20 @@ static int mqtt_socket_lwt( lua_State* L )
} }
// Module function map // Module function map
static const LUA_REG_TYPE mqtt_socket_map[] = static const LUA_REG_TYPE mqtt_socket_map[] = {
{ { LSTRKEY( "connect" ), LFUNCVAL( mqtt_socket_connect ) },
{ LSTRKEY( "connect" ), LFUNCVAL ( mqtt_socket_connect ) }, { LSTRKEY( "close" ), LFUNCVAL( mqtt_socket_close ) },
{ LSTRKEY( "close" ), LFUNCVAL ( mqtt_socket_close ) }, { LSTRKEY( "publish" ), LFUNCVAL( mqtt_socket_publish ) },
{ LSTRKEY( "publish" ), LFUNCVAL ( mqtt_socket_publish ) }, { LSTRKEY( "subscribe" ), LFUNCVAL( mqtt_socket_subscribe ) },
{ LSTRKEY( "subscribe" ), LFUNCVAL ( mqtt_socket_subscribe ) }, { LSTRKEY( "lwt" ), LFUNCVAL( mqtt_socket_lwt ) },
{ LSTRKEY( "lwt" ), LFUNCVAL ( mqtt_socket_lwt ) }, { LSTRKEY( "on" ), LFUNCVAL( mqtt_socket_on ) },
{ LSTRKEY( "on" ), LFUNCVAL ( mqtt_socket_on ) }, { LSTRKEY( "__gc" ), LFUNCVAL( mqtt_delete ) },
{ LSTRKEY( "__gc" ), LFUNCVAL ( mqtt_delete ) }, { LSTRKEY( "__index" ), LROVAL( mqtt_socket_map ) },
{ LSTRKEY( "__index" ), LROVAL ( mqtt_socket_map ) },
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
const LUA_REG_TYPE mqtt_map[] = const LUA_REG_TYPE mqtt_map[] = {
{ { LSTRKEY( "Client" ), LFUNCVAL( mqtt_socket_client ) },
{ LSTRKEY( "Client" ), LFUNCVAL ( mqtt_socket_client ) },
{ LSTRKEY( "__metatable" ), LROVAL( mqtt_map ) }, { LSTRKEY( "__metatable" ), LROVAL( mqtt_map ) },
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
...@@ -1413,5 +1410,9 @@ const LUA_REG_TYPE mqtt_map[] = ...@@ -1413,5 +1410,9 @@ const LUA_REG_TYPE mqtt_map[] =
LUALIB_API int luaopen_mqtt( lua_State *L ) LUALIB_API 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", (void *)mqtt_socket_map); // create metatable for mqtt.socket
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h"
#include "lrodefs.h" #include "lrodefs.h"
#include "c_string.h" #include "c_string.h"
...@@ -1506,66 +1505,59 @@ static int expose_array(lua_State* L, char *array, unsigned short len) { ...@@ -1506,66 +1505,59 @@ static int expose_array(lua_State* L, char *array, unsigned short len) {
#endif #endif
// Module function map // Module function map
static const LUA_REG_TYPE net_server_map[] = static const LUA_REG_TYPE net_server_map[] = {
{ { LSTRKEY( "listen" ), LFUNCVAL( net_server_listen ) },
{ LSTRKEY( "listen" ), LFUNCVAL ( net_server_listen ) }, { LSTRKEY( "close" ), LFUNCVAL( net_server_close ) },
{ LSTRKEY( "close" ), LFUNCVAL ( net_server_close ) }, { LSTRKEY( "on" ), LFUNCVAL( net_udpserver_on ) },
{ LSTRKEY( "on" ), LFUNCVAL ( net_udpserver_on ) }, { LSTRKEY( "send" ), LFUNCVAL( net_udpserver_send ) },
{ LSTRKEY( "send" ), LFUNCVAL ( net_udpserver_send ) }, //{ LSTRKEY( "delete" ), LFUNCVAL( net_server_delete ) },
// { LSTRKEY( "delete" ), LFUNCVAL ( net_server_delete ) }, { LSTRKEY( "__gc" ), LFUNCVAL( net_server_delete ) },
{ LSTRKEY( "__gc" ), LFUNCVAL ( net_server_delete ) }, { LSTRKEY( "__index" ), LROVAL( net_server_map ) },
{ LSTRKEY( "__index" ), LROVAL ( net_server_map ) },
{ LNILKEY, LNILVAL } { 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( "connect" ), LFUNCVAL( net_socket_connect ) },
{ LSTRKEY( "close" ), LFUNCVAL ( net_socket_close ) }, { LSTRKEY( "close" ), LFUNCVAL( net_socket_close ) },
{ LSTRKEY( "on" ), LFUNCVAL ( net_socket_on ) }, { LSTRKEY( "on" ), LFUNCVAL( net_socket_on ) },
{ LSTRKEY( "send" ), LFUNCVAL ( net_socket_send ) }, { LSTRKEY( "send" ), LFUNCVAL( net_socket_send ) },
{ LSTRKEY( "hold" ), LFUNCVAL ( net_socket_hold ) }, { LSTRKEY( "hold" ), LFUNCVAL( net_socket_hold ) },
{ LSTRKEY( "unhold" ), LFUNCVAL ( net_socket_unhold ) }, { LSTRKEY( "unhold" ), LFUNCVAL( net_socket_unhold ) },
{ LSTRKEY( "dns" ), LFUNCVAL ( net_socket_dns ) }, { LSTRKEY( "dns" ), LFUNCVAL( net_socket_dns ) },
{ LSTRKEY( "getpeer" ), LFUNCVAL ( net_socket_getpeer ) }, { LSTRKEY( "getpeer" ), LFUNCVAL( net_socket_getpeer ) },
// { LSTRKEY( "delete" ), LFUNCVAL ( net_socket_delete ) }, //{ LSTRKEY( "delete" ), LFUNCVAL( net_socket_delete ) },
{ LSTRKEY( "__gc" ), LFUNCVAL ( net_socket_delete ) }, { LSTRKEY( "__gc" ), LFUNCVAL( net_socket_delete ) },
{ LSTRKEY( "__index" ), LROVAL ( net_socket_map ) }, { LSTRKEY( "__index" ), LROVAL( net_socket_map ) },
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
#if 0 #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( "__index" ), LFUNCVAL( net_array_index ) },
{ LSTRKEY( "__newindex" ), LFUNCVAL( net_array_newindex ) }, { LSTRKEY( "__newindex" ), LFUNCVAL( net_array_newindex ) },
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
#endif #endif
static const LUA_REG_TYPE net_dns_map[] = static const LUA_REG_TYPE net_dns_map[] = {
{ { LSTRKEY( "setdnsserver" ), LFUNCVAL( net_setdnsserver ) },
{ LSTRKEY( "setdnsserver" ), LFUNCVAL ( net_setdnsserver ) }, { LSTRKEY( "getdnsserver" ), LFUNCVAL( net_getdnsserver ) },
{ LSTRKEY( "getdnsserver" ), LFUNCVAL ( net_getdnsserver ) }, { LSTRKEY( "resolve" ), LFUNCVAL( net_dns_static ) },
{ LSTRKEY( "resolve" ), LFUNCVAL ( net_dns_static ) },
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
const LUA_REG_TYPE net_map[] = const LUA_REG_TYPE net_map[] = {
{ { LSTRKEY( "createServer" ), LFUNCVAL( net_createServer ) },
{ LSTRKEY( "createServer" ), LFUNCVAL ( net_createServer ) }, { LSTRKEY( "createConnection" ), LFUNCVAL( net_createConnection ) },
{ LSTRKEY( "createConnection" ), LFUNCVAL ( net_createConnection ) }, { LSTRKEY( "multicastJoin"), LFUNCVAL( net_multicastJoin ) },
{ LSTRKEY( "multicastJoin"), LFUNCVAL( net_multicastJoin ) }, { LSTRKEY( "multicastLeave"), LFUNCVAL( net_multicastLeave ) },
{ LSTRKEY( "multicastLeave"), LFUNCVAL( net_multicastLeave ) }, { LSTRKEY( "dns" ), LROVAL( net_dns_map ) },
{ LSTRKEY( "dns" ), LROVAL( net_dns_map ) }, { LSTRKEY( "TCP" ), LNUMVAL( TCP ) },
{ LSTRKEY( "TCP" ), LNUMVAL( TCP ) }, { LSTRKEY( "UDP" ), LNUMVAL( UDP ) },
{ LSTRKEY( "UDP" ), LNUMVAL( UDP ) }, { LSTRKEY( "__metatable" ), LROVAL( net_map ) },
{ LSTRKEY( "__metatable" ), LROVAL( net_map ) },
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
LUALIB_API int luaopen_net( lua_State *L ) LUALIB_API int luaopen_net( lua_State *L ) {
{
int i; int i;
for(i=0;i<MAX_SOCKET;i++) for(i=0;i<MAX_SOCKET;i++)
{ {
...@@ -1575,7 +1567,12 @@ LUALIB_API int luaopen_net( lua_State *L ) ...@@ -1575,7 +1567,12 @@ LUALIB_API int luaopen_net( lua_State *L )
luaL_rometatable(L, "net.server", (void *)net_server_map); // create metatable for net.server 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 luaL_rometatable(L, "net.socket", (void *)net_socket_map); // create metatable for net.socket
#if 0 #if 0
luaL_rometatable(L, "net.array", (void *)net_array_map); // create metatable for net.array luaL_rometatable(L, "net.array", (void *)net_array_map); // create metatable for net.array
#endif #endif
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
// Module for interfacing with the OneWire interface // Module for interfacing with the OneWire interface
#include "lauxlib.h" #include "lauxlib.h"
#include "auxmods.h"
#include "lrodefs.h" #include "lrodefs.h"
#include "platform.h"
#include "driver/onewire.h" #include "driver/onewire.h"
// Lua: ow.setup( id ) // Lua: ow.setup( id )
...@@ -280,33 +280,35 @@ static int ow_crc16( lua_State *L ) ...@@ -280,33 +280,35 @@ static int ow_crc16( lua_State *L )
#endif #endif
// Module function map // Module function map
const LUA_REG_TYPE ow_map[] = const LUA_REG_TYPE ow_map[] = {
{ { LSTRKEY( "setup" ), LFUNCVAL( ow_setup ) },
{ LSTRKEY( "setup" ), LFUNCVAL( ow_setup ) }, { LSTRKEY( "reset" ), LFUNCVAL( ow_reset ) },
{ LSTRKEY( "reset" ), LFUNCVAL( ow_reset ) }, { LSTRKEY( "skip" ), LFUNCVAL( ow_skip ) },
{ LSTRKEY( "skip" ), LFUNCVAL( ow_skip ) }, { LSTRKEY( "select" ), LFUNCVAL( ow_select ) },
{ LSTRKEY( "select" ), LFUNCVAL( ow_select ) }, { LSTRKEY( "write" ), LFUNCVAL( ow_write ) },
{ LSTRKEY( "write" ), LFUNCVAL( ow_write ) }, { LSTRKEY( "write_bytes" ), LFUNCVAL( ow_write_bytes ) },
{ LSTRKEY( "write_bytes" ), LFUNCVAL( ow_write_bytes ) }, { LSTRKEY( "read" ), LFUNCVAL( ow_read ) },
{ LSTRKEY( "read" ), LFUNCVAL( ow_read ) }, { LSTRKEY( "read_bytes" ), LFUNCVAL( ow_read_bytes ) },
{ LSTRKEY( "read_bytes" ), LFUNCVAL( ow_read_bytes ) }, { LSTRKEY( "depower" ), LFUNCVAL( ow_depower ) },
{ LSTRKEY( "depower" ), LFUNCVAL( ow_depower ) },
#if ONEWIRE_SEARCH #if ONEWIRE_SEARCH
{ LSTRKEY( "reset_search" ), LFUNCVAL( ow_reset_search ) }, { LSTRKEY( "reset_search" ), LFUNCVAL( ow_reset_search ) },
{ LSTRKEY( "target_search" ), LFUNCVAL( ow_target_search ) }, { LSTRKEY( "target_search" ), LFUNCVAL( ow_target_search ) },
{ LSTRKEY( "search" ), LFUNCVAL( ow_search ) }, { LSTRKEY( "search" ), LFUNCVAL( ow_search ) },
#endif #endif
#if ONEWIRE_CRC #if ONEWIRE_CRC
{ LSTRKEY( "crc8" ), LFUNCVAL( ow_crc8 ) }, { LSTRKEY( "crc8" ), LFUNCVAL( ow_crc8 ) },
#if ONEWIRE_CRC16 #if ONEWIRE_CRC16
{ LSTRKEY( "check_crc16" ), LFUNCVAL( ow_check_crc16 ) }, { LSTRKEY( "check_crc16" ), LFUNCVAL( ow_check_crc16 ) },
{ LSTRKEY( "crc16" ), LFUNCVAL( ow_crc16 ) }, { LSTRKEY( "crc16" ), LFUNCVAL( ow_crc16 ) },
#endif #endif
#endif #endif
{ LNILKEY, LNILVAL } { 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; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h"
#include "lrodefs.h" #include "lrodefs.h"
#include "c_types.h" #include "c_types.h"
...@@ -123,20 +122,22 @@ static int lpwm_getduty( lua_State* L ) ...@@ -123,20 +122,22 @@ static int lpwm_getduty( lua_State* L )
} }
// Module function map // Module function map
const LUA_REG_TYPE pwm_map[] = const LUA_REG_TYPE pwm_map[] = {
{ { LSTRKEY( "setup" ), LFUNCVAL( lpwm_setup ) },
{ LSTRKEY( "setup" ), LFUNCVAL( lpwm_setup ) }, { LSTRKEY( "close" ), LFUNCVAL( lpwm_close ) },
{ LSTRKEY( "close" ), LFUNCVAL( lpwm_close ) }, { LSTRKEY( "start" ), LFUNCVAL( lpwm_start ) },
{ LSTRKEY( "start" ), LFUNCVAL( lpwm_start ) }, { LSTRKEY( "stop" ), LFUNCVAL( lpwm_stop ) },
{ LSTRKEY( "stop" ), LFUNCVAL( lpwm_stop ) },
{ LSTRKEY( "setclock" ), LFUNCVAL( lpwm_setclock ) }, { LSTRKEY( "setclock" ), LFUNCVAL( lpwm_setclock ) },
{ LSTRKEY( "getclock" ), LFUNCVAL( lpwm_getclock ) }, { LSTRKEY( "getclock" ), LFUNCVAL( lpwm_getclock ) },
{ LSTRKEY( "setduty" ), LFUNCVAL( lpwm_setduty ) }, { LSTRKEY( "setduty" ), LFUNCVAL( lpwm_setduty ) },
{ LSTRKEY( "getduty" ), LFUNCVAL( lpwm_getduty ) }, { LSTRKEY( "getduty" ), LFUNCVAL( lpwm_getduty ) },
{ LNILKEY, LNILVAL } { 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; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
...@@ -79,8 +79,8 @@ static int ICACHE_FLASH_ATTR rc_send(lua_State* L) { ...@@ -79,8 +79,8 @@ static int ICACHE_FLASH_ATTR rc_send(lua_State* L) {
return 1; return 1;
} }
const LUA_REG_TYPE rc_map[] = // Module function map
{ const LUA_REG_TYPE rc_map[] = {
{ LSTRKEY( "send" ), LFUNCVAL( rc_send )}, { LSTRKEY( "send" ), LFUNCVAL( rc_send )},
{ LNILKEY, LNILVAL} { LNILKEY, LNILVAL}
}; };
...@@ -88,5 +88,9 @@ const LUA_REG_TYPE rc_map[] = ...@@ -88,5 +88,9 @@ const LUA_REG_TYPE rc_map[] =
//LUALIB_API int luaopen_ultra(lua_State *L) { //LUALIB_API int luaopen_ultra(lua_State *L) {
LUALIB_API int luaopen_rc(lua_State *L) { LUALIB_API int luaopen_rc(lua_State *L) {
// TODO: Make sure that the GPIO system is initialized // TODO: Make sure that the GPIO system is initialized
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
...@@ -165,8 +165,7 @@ static int rtcfifo_dsleep_until_sample (lua_State *L) ...@@ -165,8 +165,7 @@ static int rtcfifo_dsleep_until_sample (lua_State *L)
#endif #endif
// Module function map // Module function map
const LUA_REG_TYPE rtcfifo_map[] = const LUA_REG_TYPE rtcfifo_map[] = {
{
{ LSTRKEY("prepare"), LFUNCVAL(rtcfifo_prepare) }, { LSTRKEY("prepare"), LFUNCVAL(rtcfifo_prepare) },
{ LSTRKEY("ready"), LFUNCVAL(rtcfifo_ready) }, { LSTRKEY("ready"), LFUNCVAL(rtcfifo_ready) },
{ LSTRKEY("put"), LFUNCVAL(rtcfifo_put) }, { LSTRKEY("put"), LFUNCVAL(rtcfifo_put) },
...@@ -182,5 +181,9 @@ const LUA_REG_TYPE rtcfifo_map[] = ...@@ -182,5 +181,9 @@ const LUA_REG_TYPE rtcfifo_map[] =
LUALIB_API int luaopen_rtcfifo (lua_State *L) LUALIB_API int luaopen_rtcfifo (lua_State *L)
{ {
#if MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2
return 0; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
...@@ -41,14 +41,16 @@ static int rtcmem_write32 (lua_State *L) ...@@ -41,14 +41,16 @@ static int rtcmem_write32 (lua_State *L)
// Module function map // Module function map
const LUA_REG_TYPE rtcmem_map[] = const LUA_REG_TYPE rtcmem_map[] = {
{
{ LSTRKEY("read32"), LFUNCVAL(rtcmem_read32) }, { LSTRKEY("read32"), LFUNCVAL(rtcmem_read32) },
{ LSTRKEY("write32"), LFUNCVAL(rtcmem_write32) }, { LSTRKEY("write32"), LFUNCVAL(rtcmem_write32) },
{ LNILKEY, LNILVAL } { 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; return 0;
#else
# error "NodeMCU modules must be build with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment