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 @@
#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
}
// 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[] = {
};
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
}
......@@ -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
}
......@@ -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:
*/
......@@ -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
}
......@@ -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
}
// 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
}
......@@ -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
}
......@@ -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
}
// 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
}
......@@ -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
}
......@@ -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
}
......@@ -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
}
......@@ -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
}
// 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
}
......@@ -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
}
......@@ -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
}
......@@ -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
}
......@@ -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
}
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