Commit 6b6456be authored by Johny Mattsson's avatar Johny Mattsson
Browse files

Major cleanup of module registration.

As per #810 & #796, only LUA_OPTIMIZE_MEMORY=2 & MIN_OPT_LEVEL=2 are
supported when building. This commit effects that limitation.

With this change modules/auxmods.h no longer needs to be updated for
every new module, nor do module writers need to cater for a hypothetical
LUA_OPTIMIZE_MEMORY < 2 scenario.
parent 68eadaaf
...@@ -134,9 +134,11 @@ DEPENDS_eagle.app.v6 = \ ...@@ -134,9 +134,11 @@ DEPENDS_eagle.app.v6 = \
# -DWLAN_CONFIG_CCX # -DWLAN_CONFIG_CCX
CONFIGURATION_DEFINES = -D__ets__ \ CONFIGURATION_DEFINES = -D__ets__ \
-DICACHE_FLASH \ -DICACHE_FLASH \
-DLUA_OPTIMIZE_MEMORY=2 \
-DMIN_OPT_LEVEL=2 \
-DLWIP_OPEN_SRC \ -DLWIP_OPEN_SRC \
-DPBUF_RSV_FOR_WLAN \ -DPBUF_RSV_FOR_WLAN \
-DEBUF_LWIP -DEBUF_LWIP \
DEFINES += \ DEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \ $(UNIVERSAL_TARGET_DEFINES) \
......
...@@ -489,6 +489,7 @@ static int luaB_newproxy (lua_State *L) { ...@@ -489,6 +489,7 @@ static int luaB_newproxy (lua_State *L) {
{LSTRKEY("xpcall"), LFUNCVAL(luaB_xpcall)} {LSTRKEY("xpcall"), LFUNCVAL(luaB_xpcall)}
#if LUA_OPTIMIZE_MEMORY == 2 #if LUA_OPTIMIZE_MEMORY == 2
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 2 #define MIN_OPT_LEVEL 2
#include "lrodefs.h" #include "lrodefs.h"
const LUA_REG_TYPE base_funcs_list[] = { const LUA_REG_TYPE base_funcs_list[] = {
......
...@@ -383,6 +383,7 @@ static int db_errorfb (lua_State *L) { ...@@ -383,6 +383,7 @@ static int db_errorfb (lua_State *L) {
return 1; return 1;
} }
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1 #define MIN_OPT_LEVEL 1
#include "lrodefs.h" #include "lrodefs.h"
const LUA_REG_TYPE dblib[] = { const LUA_REG_TYPE dblib[] = {
......
...@@ -538,6 +538,7 @@ static int f_flush (lua_State *L) { ...@@ -538,6 +538,7 @@ static int f_flush (lua_State *L) {
return pushresult(L, fs_flush(tofile(L)) == 0, NULL); return pushresult(L, fs_flush(tofile(L)) == 0, NULL);
} }
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 2 #define MIN_OPT_LEVEL 2
#include "lrodefs.h" #include "lrodefs.h"
#if LUA_OPTIMIZE_MEMORY == 2 #if LUA_OPTIMIZE_MEMORY == 2
......
...@@ -311,6 +311,7 @@ static int math_randomseed (lua_State *L) { ...@@ -311,6 +311,7 @@ static int math_randomseed (lua_State *L) {
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1 #define MIN_OPT_LEVEL 1
#include "lrodefs.h" #include "lrodefs.h"
const LUA_REG_TYPE math_map[] = { const LUA_REG_TYPE math_map[] = {
......
...@@ -646,6 +646,7 @@ static const lua_CFunction loaders[] = ...@@ -646,6 +646,7 @@ static const lua_CFunction loaders[] =
{loader_preload, loader_Lua, loader_C, loader_Croot, NULL}; {loader_preload, loader_Lua, loader_C, loader_Croot, NULL};
#if LUA_OPTIMIZE_MEMORY > 0 #if LUA_OPTIMIZE_MEMORY > 0
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1 #define MIN_OPT_LEVEL 1
#include "lrodefs.h" #include "lrodefs.h"
const LUA_REG_TYPE lmt[] = { const LUA_REG_TYPE lmt[] = {
......
...@@ -825,6 +825,7 @@ static int str_format (lua_State *L) { ...@@ -825,6 +825,7 @@ static int str_format (lua_State *L) {
return 1; return 1;
} }
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1 #define MIN_OPT_LEVEL 1
#include "lrodefs.h" #include "lrodefs.h"
const LUA_REG_TYPE strlib[] = { const LUA_REG_TYPE strlib[] = {
......
...@@ -266,6 +266,7 @@ static int sort (lua_State *L) { ...@@ -266,6 +266,7 @@ static int sort (lua_State *L) {
/* }====================================================== */ /* }====================================================== */
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1 #define MIN_OPT_LEVEL 1
#include "lrodefs.h" #include "lrodefs.h"
const LUA_REG_TYPE tab_funcs[] = { const LUA_REG_TYPE tab_funcs[] = {
......
...@@ -221,6 +221,7 @@ static int os_exit (lua_State *L) { ...@@ -221,6 +221,7 @@ static int os_exit (lua_State *L) {
c_exit(luaL_optint(L, 1, EXIT_SUCCESS)); c_exit(luaL_optint(L, 1, EXIT_SUCCESS));
} }
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1 #define MIN_OPT_LEVEL 1
#include "lrodefs.h" #include "lrodefs.h"
const LUA_REG_TYPE syslib[] = { const LUA_REG_TYPE syslib[] = {
......
// Module for interfacing with adc // Module for interfacing with adc
//#include "lua.h"
#include "lualib.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h" #include "auxmods.h"
#include "lrotable.h" #include "lrodefs.h"
#include "c_types.h" #include "c_types.h"
#include "user_interface.h" #include "user_interface.h"
...@@ -28,26 +26,14 @@ static int adc_readvdd33( lua_State* L ) ...@@ -28,26 +26,14 @@ static int adc_readvdd33( lua_State* L )
} }
// Module function map // Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
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) },
#if LUA_OPTIMIZE_MEMORY > 0
#endif
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
LUALIB_API int luaopen_adc( lua_State *L ) LUALIB_API int luaopen_adc( lua_State *L )
{ {
#if LUA_OPTIMIZE_MEMORY > 0
return 0; return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_ADC, adc_map );
// Add constants
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
} }
...@@ -5,95 +5,6 @@ ...@@ -5,95 +5,6 @@
#ifndef __AUXMODS_H__ #ifndef __AUXMODS_H__
#define __AUXMODS_H__ #define __AUXMODS_H__
#include "lua.h"
#define AUXLIB_GPIO "gpio"
LUALIB_API int ( luaopen_gpio )( lua_State *L );
#define AUXLIB_SPI "spi"
LUALIB_API int ( luaopen_spi )( lua_State *L );
#define AUXLIB_CAN "can"
LUALIB_API int ( luaopen_can )( lua_State *L );
#define AUXLIB_TMR "tmr"
LUALIB_API int ( luaopen_tmr )( lua_State *L );
#define AUXLIB_PD "pd"
LUALIB_API int ( luaopen_pd )( lua_State *L );
#define AUXLIB_UART "uart"
LUALIB_API int ( luaopen_uart )( lua_State *L );
#define AUXLIB_TERM "term"
LUALIB_API int ( luaopen_term )( lua_State *L );
#define AUXLIB_PWM "pwm"
LUALIB_API int ( luaopen_pwm )( lua_State *L );
#define AUXLIB_PACK "pack"
LUALIB_API int ( luaopen_pack )( lua_State *L );
#define AUXLIB_BIT "bit"
LUALIB_API int ( luaopen_bit )( lua_State *L );
#define AUXLIB_NET "net"
LUALIB_API int ( luaopen_net )( lua_State *L );
#define AUXLIB_CPU "cpu"
LUALIB_API int ( luaopen_cpu )( lua_State* L );
#define AUXLIB_ADC "adc"
LUALIB_API int ( luaopen_adc )( lua_State *L );
#define AUXLIB_RPC "rpc"
LUALIB_API int ( luaopen_rpc )( lua_State *L );
#define AUXLIB_BITARRAY "bitarray"
LUALIB_API int ( luaopen_bitarray )( lua_State *L );
#define AUXLIB_ELUA "elua"
LUALIB_API int ( luaopen_elua )( lua_State *L );
#define AUXLIB_I2C "i2c"
LUALIB_API int ( luaopen_i2c )( lua_State *L );
#define AUXLIB_WIFI "wifi"
LUALIB_API int ( luaopen_wifi )( lua_State *L );
#define AUXLIB_COAP "coap"
LUALIB_API int ( luaopen_coap )( lua_State *L );
#define AUXLIB_MQTT "mqtt"
LUALIB_API int ( luaopen_mqtt )( lua_State *L );
#define AUXLIB_U8G "u8g"
LUALIB_API int ( luaopen_u8g )( lua_State *L );
#define AUXLIB_UCG "ucg"
LUALIB_API int ( luaopen_ucg )( lua_State *L );
#define AUXLIB_NODE "node"
LUALIB_API int ( luaopen_node )( lua_State *L );
#define AUXLIB_FILE "file"
LUALIB_API int ( luaopen_file )( lua_State *L );
#define AUXLIB_OW "ow"
LUALIB_API int ( luaopen_ow )( lua_State *L );
#define AUXLIB_CJSON "cjson"
LUALIB_API int ( luaopen_cjson )( lua_State *L );
#define AUXLIB_CRYPTO "crypto"
LUALIB_API int ( luaopen_crypto )( lua_State *L );
#define AUXLIB_RC "rc"
LUALIB_API int ( luaopen_rc )( lua_State *L );
#define AUXLIB_DHT "dht"
LUALIB_API int ( luaopen_dht )( lua_State *L );
// Helper macros // Helper macros
#define MOD_CHECK_ID( mod, id )\ #define MOD_CHECK_ID( mod, id )\
if( !platform_ ## mod ## _exists( id ) )\ if( !platform_ ## mod ## _exists( id ) )\
...@@ -109,13 +20,4 @@ LUALIB_API int ( luaopen_dht )( lua_State *L ); ...@@ -109,13 +20,4 @@ LUALIB_API int ( luaopen_dht )( lua_State *L );
if( !platform_ ## mod ## _check_ ## resmod ## _id( id, resid ) )\ if( !platform_ ## mod ## _check_ ## resmod ## _id( id, resid ) )\
return luaL_error( L, #resmod" %d not valid with " #mod " %d", ( unsigned )resid, ( unsigned )id ) return luaL_error( L, #resmod" %d not valid with " #mod " %d", ( unsigned )resid, ( unsigned )id )
#define MOD_REG_NUMBER( L, name, val )\
lua_pushnumber( L, val );\
lua_setfield( L, -2, name )
#define MOD_REG_LUDATA( L, name, val )\
lua_pushlightuserdata( L, val );\
lua_setfield( L, -2, name )
#endif #endif
...@@ -7,11 +7,8 @@ ...@@ -7,11 +7,8 @@
#include "c_limits.h" #include "c_limits.h"
//#include "lua.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "auxmods.h" #include "lrodefs.h"
// #include "type.h"
#include "lrotable.h"
/* FIXME: Assume size_t is an unsigned lua_Integer */ /* FIXME: Assume size_t is an unsigned lua_Integer */
typedef size_t lua_UInteger; typedef size_t lua_UInteger;
...@@ -122,8 +119,6 @@ static int bit_clear( lua_State* L ) ...@@ -122,8 +119,6 @@ static int bit_clear( lua_State* L )
return 1; return 1;
} }
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE bit_map[] = { const LUA_REG_TYPE bit_map[] = {
{ LSTRKEY( "bnot" ), LFUNCVAL( bit_bnot ) }, { LSTRKEY( "bnot" ), LFUNCVAL( bit_bnot ) },
{ LSTRKEY( "band" ), LFUNCVAL( bit_band ) }, { LSTRKEY( "band" ), LFUNCVAL( bit_band ) },
...@@ -141,5 +136,5 @@ const LUA_REG_TYPE bit_map[] = { ...@@ -141,5 +136,5 @@ const LUA_REG_TYPE bit_map[] = {
}; };
LUALIB_API int luaopen_bit (lua_State *L) { LUALIB_API int luaopen_bit (lua_State *L) {
LREGISTER( L, "bit", bit_map ); return 0;
} }
#include "lualib.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h" #include "lrodefs.h"
#include "lrotable.h"
#include "c_stdlib.h" #include "c_stdlib.h"
#include "c_string.h" #include "c_string.h"
...@@ -185,8 +183,6 @@ static int ICACHE_FLASH_ATTR bmp085_lua_pressure(lua_State* L) { ...@@ -185,8 +183,6 @@ static int ICACHE_FLASH_ATTR bmp085_lua_pressure(lua_State* L) {
return 1; return 1;
} }
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE bmp085_map[] = const LUA_REG_TYPE bmp085_map[] =
{ {
{ LSTRKEY( "temperature" ), LFUNCVAL( bmp085_lua_temperature )}, { LSTRKEY( "temperature" ), LFUNCVAL( bmp085_lua_temperature )},
...@@ -197,7 +193,6 @@ const LUA_REG_TYPE bmp085_map[] = ...@@ -197,7 +193,6 @@ const LUA_REG_TYPE bmp085_map[] =
}; };
LUALIB_API int luaopen_bmp085(lua_State *L) { LUALIB_API int luaopen_bmp085(lua_State *L) {
LREGISTER(L, "bmp085", bmp085_map); return 0;
return 1;
} }
...@@ -40,8 +40,8 @@ ...@@ -40,8 +40,8 @@
#include "c_string.h" #include "c_string.h"
#include "c_math.h" #include "c_math.h"
#include "c_limits.h" #include "c_limits.h"
#include "lua.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "lrodefs.h"
#include "flash_api.h" #include "flash_api.h"
#include "strbuf.h" #include "strbuf.h"
...@@ -1531,8 +1531,6 @@ static int json_protect_conversion(lua_State *l) ...@@ -1531,8 +1531,6 @@ static int json_protect_conversion(lua_State *l)
#endif #endif
// Module function map // Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE cjson_map[] = const LUA_REG_TYPE cjson_map[] =
{ {
{ LSTRKEY( "encode" ), LFUNCVAL( json_encode ) }, { LSTRKEY( "encode" ), LFUNCVAL( json_encode ) },
...@@ -1545,9 +1543,6 @@ const LUA_REG_TYPE cjson_map[] = ...@@ -1545,9 +1543,6 @@ const LUA_REG_TYPE cjson_map[] =
// { LSTRKEY( "encode_invalid_numbers" ), LFUNCVAL( json_cfg_encode_invalid_numbers ) }, // { LSTRKEY( "encode_invalid_numbers" ), LFUNCVAL( json_cfg_encode_invalid_numbers ) },
// { LSTRKEY( "decode_invalid_numbers" ), LFUNCVAL( json_cfg_decode_invalid_numbers ) }, // { LSTRKEY( "decode_invalid_numbers" ), LFUNCVAL( json_cfg_decode_invalid_numbers ) },
// { LSTRKEY( "new" ), LFUNCVAL( lua_cjson_new ) }, // { LSTRKEY( "new" ), LFUNCVAL( lua_cjson_new ) },
#if LUA_OPTIMIZE_MEMORY > 0
#endif
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
...@@ -1560,18 +1555,7 @@ LUALIB_API int luaopen_cjson( lua_State *L ) ...@@ -1560,18 +1555,7 @@ LUALIB_API int luaopen_cjson( lua_State *L )
if(-1==cfg_init(&_cfg)){ if(-1==cfg_init(&_cfg)){
return luaL_error(L, "BUG: Unable to init config for cjson");; return luaL_error(L, "BUG: Unable to init config for cjson");;
} }
#if LUA_OPTIMIZE_MEMORY > 0
return 0; return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_CJSON, cjson_map );
// Add constants
/* Set cjson.null */
lua_pushlightuserdata(l, NULL);
lua_setfield(l, -2, "null");
/* Return cjson table */
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
} }
#if 0 #if 0
......
// Module for coapwork // Module for coapwork
//#include "lua.h"
#include "lualib.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h" #include "lrodefs.h"
#include "lrotable.h"
#include "c_string.h" #include "c_string.h"
#include "c_stdlib.h" #include "c_stdlib.h"
...@@ -561,8 +558,6 @@ static int coap_client_delete( lua_State* L ) ...@@ -561,8 +558,6 @@ static int coap_client_delete( lua_State* L )
} }
// Module function map // Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
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 ) },
...@@ -570,9 +565,7 @@ static const LUA_REG_TYPE coap_server_map[] = ...@@ -570,9 +565,7 @@ static const LUA_REG_TYPE coap_server_map[] =
{ 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 ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "__index" ), LROVAL ( coap_server_map ) }, { LSTRKEY( "__index" ), LROVAL ( coap_server_map ) },
#endif
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
...@@ -583,9 +576,7 @@ static const LUA_REG_TYPE coap_client_map[] = ...@@ -583,9 +576,7 @@ static const LUA_REG_TYPE coap_client_map[] =
{ 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 ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "__index" ), LROVAL ( coap_client_map ) }, { LSTRKEY( "__index" ), LROVAL ( coap_client_map ) },
#endif
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
...@@ -593,7 +584,6 @@ const LUA_REG_TYPE coap_map[] = ...@@ -593,7 +584,6 @@ 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 ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ 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 ) },
...@@ -604,56 +594,13 @@ const LUA_REG_TYPE coap_map[] = ...@@ -604,56 +594,13 @@ const LUA_REG_TYPE coap_map[] =
{ LSTRKEY( "JSON"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_JSON) }, { LSTRKEY( "JSON"), LNUMVAL( COAP_CONTENTTYPE_APPLICATION_JSON) },
{ LSTRKEY( "__metatable" ), LROVAL( coap_map ) }, { LSTRKEY( "__metatable" ), LROVAL( coap_map ) },
#endif
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
LUALIB_API int luaopen_coap( lua_State *L ) LUALIB_API int luaopen_coap( lua_State *L )
{ {
endpoint_setup(); endpoint_setup();
#if LUA_OPTIMIZE_MEMORY > 0
luaL_rometatable(L, "coap_server", (void *)coap_server_map); // create metatable for coap_server luaL_rometatable(L, "coap_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
return 0; return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
int n;
luaL_register( L, AUXLIB_COAP, coap_map );
// Set it as its own metatable
lua_pushvalue( L, -1 );
lua_setmetatable( L, -2 );
// Module constants
MOD_REG_NUMBER( L, "CON", COAP_TYPE_CON );
MOD_REG_NUMBER( L, "NON", COAP_TYPE_NONCON );
MOD_REG_NUMBER( L, "TEXT_PLAIN", COAP_CONTENTTYPE_TEXT_PLAIN );
MOD_REG_NUMBER( L, "LINKFORMAT", COAP_CONTENTTYPE_APPLICATION_LINKFORMAT );
MOD_REG_NUMBER( L, "XML", COAP_CONTENTTYPE_APPLICATION_XML);
MOD_REG_NUMBER( L, "OCTET_STREAM", COAP_CONTENTTYPE_APPLICATION_OCTET_STREAM);
MOD_REG_NUMBER( L, "EXI", COAP_CONTENTTYPE_APPLICATION_EXI);
MOD_REG_NUMBER( L, "JSON", COAP_CONTENTTYPE_APPLICATION_JSON);
n = lua_gettop(L);
// create metatable
luaL_newmetatable(L, "coap_server");
// metatable.__index = metatable
lua_pushliteral(L, "__index");
lua_pushvalue(L,-2);
lua_rawset(L,-3);
// Setup the methods inside metatable
luaL_register( L, NULL, coap_server_map );
lua_settop(L, n);
// create metatable
luaL_newmetatable(L, "coap_client");
// metatable.__index = metatable
lua_pushliteral(L, "__index");
lua_pushvalue(L,-2);
lua_rawset(L,-3);
// Setup the methods inside metatable
luaL_register( L, NULL, coap_client_map );
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
} }
// Module for cryptography // Module for cryptography
//#include "lua.h"
#include "lualib.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h" #include "lrodefs.h"
#include "lrotable.h"
#include "c_types.h" #include "c_types.h"
#include "c_stdlib.h" #include "c_stdlib.h"
#include "../crypto/digests.h" #include "../crypto/digests.h"
...@@ -153,8 +150,6 @@ static int crypto_lhmac (lua_State *L) ...@@ -153,8 +150,6 @@ static int crypto_lhmac (lua_State *L)
// Module function map // Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE crypto_map[] = const LUA_REG_TYPE crypto_map[] =
{ {
{ LSTRKEY( "sha1" ), LFUNCVAL( crypto_sha1 ) }, { LSTRKEY( "sha1" ), LFUNCVAL( crypto_sha1 ) },
...@@ -163,21 +158,10 @@ const LUA_REG_TYPE crypto_map[] = ...@@ -163,21 +158,10 @@ const LUA_REG_TYPE crypto_map[] =
{ 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 ) },
#if LUA_OPTIMIZE_MEMORY > 0
#endif
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
LUALIB_API int luaopen_crypto( lua_State *L ) LUALIB_API int luaopen_crypto( lua_State *L )
{ {
#if LUA_OPTIMIZE_MEMORY > 0
return 0; return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_CRYPTO, crypto_map );
// Add constants
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
} }
// 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 "lualib.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "auxmods.h" #include "auxmods.h"
#include "lrotable.h" #include "lrodefs.h"
#include "cpu_esp8266.h" #include "cpu_esp8266.h"
#include "dht.h" #include "dht.h"
...@@ -100,30 +99,18 @@ static int dht_lapi_readxx( lua_State *L ) ...@@ -100,30 +99,18 @@ static int dht_lapi_readxx( lua_State *L )
// } // }
// Module function map // Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
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 ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ 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 ) },
#endif
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
LUALIB_API int luaopen_dht( lua_State *L ) LUALIB_API int luaopen_dht( lua_State *L )
{ {
#if LUA_OPTIMIZE_MEMORY > 0
return 0; return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_DHT, dht_map );
// Add the constants
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
} }
...@@ -32,11 +32,9 @@ ...@@ -32,11 +32,9 @@
*/ */
#include "lualib.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h" #include "lrodefs.h"
#include "lrotable.h"
#include "c_stdlib.h" #include "c_stdlib.h"
#include "c_string.h" #include "c_string.h"
#include "user_interface.h" #include "user_interface.h"
...@@ -929,8 +927,6 @@ static int enduser_setup_stop(lua_State* L) ...@@ -929,8 +927,6 @@ static int enduser_setup_stop(lua_State* L)
} }
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE enduser_setup_map[] = const LUA_REG_TYPE enduser_setup_map[] =
{ {
{ LSTRKEY( "start" ), LFUNCVAL( enduser_setup_start )}, { LSTRKEY( "start" ), LFUNCVAL( enduser_setup_start )},
...@@ -939,7 +935,6 @@ const LUA_REG_TYPE enduser_setup_map[] = ...@@ -939,7 +935,6 @@ const LUA_REG_TYPE enduser_setup_map[] =
}; };
LUALIB_API int luaopen_enduser_setup(lua_State *L) { LUALIB_API int luaopen_enduser_setup(lua_State *L) {
LREGISTER(L, "enduser_setup", enduser_setup_map); return 0;
return 1;
} }
// Module for interfacing with file system // Module for interfacing with file system
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h" #include "lrodefs.h"
#include "lrotable.h"
#include "c_types.h" #include "c_types.h"
#include "flash_fs.h" #include "flash_fs.h"
...@@ -299,8 +296,6 @@ static int file_writeline( lua_State* L ) ...@@ -299,8 +296,6 @@ static int file_writeline( lua_State* L )
} }
// Module function map // Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE file_map[] = const LUA_REG_TYPE file_map[] =
{ {
{ LSTRKEY( "list" ), LFUNCVAL( file_list ) }, { LSTRKEY( "list" ), LFUNCVAL( file_list ) },
...@@ -319,22 +314,11 @@ const LUA_REG_TYPE file_map[] = ...@@ -319,22 +314,11 @@ const LUA_REG_TYPE file_map[] =
// { 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
#if LUA_OPTIMIZE_MEMORY > 0
#endif #endif
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
LUALIB_API int luaopen_file( lua_State *L ) LUALIB_API int luaopen_file( lua_State *L )
{ {
#if LUA_OPTIMIZE_MEMORY > 0
return 0; return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_FILE, file_map );
// Add constants
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
} }
// Module for interfacing with GPIO // Module for interfacing with GPIO
//#include "lua.h"
#include "lualib.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h"
#include "auxmods.h" #include "auxmods.h"
#include "lrotable.h" #include "platform.h"
#include "lrodefs.h"
#include "c_types.h" #include "c_types.h"
#include "c_string.h" #include "c_string.h"
...@@ -223,8 +221,6 @@ static int lgpio_serout( lua_State* L ) ...@@ -223,8 +221,6 @@ static int lgpio_serout( lua_State* L )
#undef DELAY_TABLE_MAX_LEN #undef DELAY_TABLE_MAX_LEN
// Module function map // Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE gpio_map[] = const LUA_REG_TYPE gpio_map[] =
{ {
{ LSTRKEY( "mode" ), LFUNCVAL( lgpio_mode ) }, { LSTRKEY( "mode" ), LFUNCVAL( lgpio_mode ) },
...@@ -233,9 +229,6 @@ const LUA_REG_TYPE gpio_map[] = ...@@ -233,9 +229,6 @@ const LUA_REG_TYPE gpio_map[] =
{ 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 ) },
#endif
#if LUA_OPTIMIZE_MEMORY > 0
#ifdef GPIO_INTERRUPT_ENABLE
{ LSTRKEY( "INT" ), LNUMVAL( INTERRUPT ) }, { LSTRKEY( "INT" ), LNUMVAL( INTERRUPT ) },
#endif #endif
{ LSTRKEY( "OUTPUT" ), LNUMVAL( OUTPUT ) }, { LSTRKEY( "OUTPUT" ), LNUMVAL( OUTPUT ) },
...@@ -244,7 +237,6 @@ const LUA_REG_TYPE gpio_map[] = ...@@ -244,7 +237,6 @@ const LUA_REG_TYPE gpio_map[] =
{ LSTRKEY( "LOW" ), LNUMVAL( LOW ) }, { LSTRKEY( "LOW" ), LNUMVAL( LOW ) },
{ LSTRKEY( "FLOAT" ), LNUMVAL( FLOAT ) }, { LSTRKEY( "FLOAT" ), LNUMVAL( FLOAT ) },
{ LSTRKEY( "PULLUP" ), LNUMVAL( PULLUP ) }, { LSTRKEY( "PULLUP" ), LNUMVAL( PULLUP ) },
#endif
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
...@@ -257,21 +249,5 @@ LUALIB_API int luaopen_gpio( lua_State *L ) ...@@ -257,21 +249,5 @@ LUALIB_API int luaopen_gpio( lua_State *L )
} }
platform_gpio_init(gpio_intr_callback); platform_gpio_init(gpio_intr_callback);
#endif #endif
#if LUA_OPTIMIZE_MEMORY > 0
return 0; return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_GPIO, gpio_map );
// Add constants
#ifdef GPIO_INTERRUPT_ENABLE
MOD_REG_NUMBER( L, "INT", INTERRUPT );
#endif
MOD_REG_NUMBER( L, "OUTPUT", OUTPUT );
MOD_REG_NUMBER( L, "INPUT", INPUT );
MOD_REG_NUMBER( L, "HIGH", HIGH );
MOD_REG_NUMBER( L, "LOW", LOW );
MOD_REG_NUMBER( L, "FLOAT", FLOAT );
MOD_REG_NUMBER( L, "PULLUP", PULLUP );
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
} }
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