Merge pull request #842 from jmattsson/module-ltr-cleanup

Cleanup: LTR module registration
This commit is contained in:
Terry Ellison 2015-12-19 23:22:18 +00:00
commit 1462d00e9f
48 changed files with 616 additions and 1644 deletions

View File

@ -86,8 +86,13 @@ COMPONENTS_eagle.app.v6 = \
crypto/libcrypto.a \
dhtlib/libdhtlib.a \
tsl2561/tsl2561lib.a \
modules/libmodules.a
modules/libmodules.a \
# Inspect the modules library and work out which modules need to be linked.
# For each enabled module, a symbol name of the form XYZ_module_selected is
# returned. At link time those names are declared undefined, so those (and
# only those) modules are pulled in.
SELECTED_MODULE_SYMS=$(filter %_module_selected %module_selected1,$(shell $(NM) modules/.output/$(TARGET)/$(FLAVOR)/lib/libmodules.a))
LINKFLAGS_eagle.app.v6 = \
-Wl,--gc-sections \
@ -98,6 +103,7 @@ LINKFLAGS_eagle.app.v6 = \
-Wl,--no-check-sections \
-Wl,--wrap=_xtos_set_exception_handler \
-Wl,-static \
$(addprefix -u , $(SELECTED_MODULE_SYMS)) \
-Wl,--start-group \
-lc \
-lgcc \
@ -134,9 +140,11 @@ DEPENDS_eagle.app.v6 = \
# -DWLAN_CONFIG_CCX
CONFIGURATION_DEFINES = -D__ets__ \
-DICACHE_FLASH \
-DLUA_OPTIMIZE_MEMORY=2 \
-DMIN_OPT_LEVEL=2 \
-DLWIP_OPEN_SRC \
-DPBUF_RSV_FOR_WLAN \
-DEBUF_LWIP
-DEBUF_LWIP \
DEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \

74
app/include/module.h Normal file
View File

@ -0,0 +1,74 @@
#ifndef __MODULE_H__
#define __MODULE_H__
#include "user_modules.h"
#include "lrodefs.h"
/* Registering a module within NodeMCU is really easy these days!
*
* Most of the work is done by a combination of pre-processor, compiler
* and linker "magic". Gone are the days of needing to update 4+ separate
* files just to register a module!
*
* You will need:
* - to include this header
* - a name for the module
* - a LUA_REG_TYPE module map
* - optionally, an init function
*
* Then simply put a line like this at the bottom of your module file:
*
* NODEMCU_MODULE(MYNAME, "myname", myname_map, luaopen_myname);
*
* or perhaps
*
* NODEMCU_MODULE(MYNAME, "myname", myname_map, NULL);
*
* if you don't need an init function.
*
* When you've done this, the module can be enabled in user_modules.h with:
*
* #define LUA_USE_MODULES_MYNAME
*
* and within NodeMCU you access it with myname.foo(), assuming you have
* a foo function in your module.
*/
#define MODULE_EXPAND_(x) x
#define MODULE_PASTE_(x,y) x##y
#define MODULE_EXPAND_PASTE_(x,y) MODULE_PASTE_(x,y)
#define LOCK_IN_SECTION(s) __attribute__((used,unused,section(s)))
/* For the ROM table, we name the variable according to ( | denotes concat):
* cfgname | _module_selected | LUA_USE_MODULES_##cfgname
* where the LUA_USE_MODULES_XYZ macro is first expanded to yield either
* an empty string (or 1) if the module has been enabled, or the literal
* LUA_USE_MOUDLE_XYZ in the case it hasn't. Thus, the name of the variable
* ends up looking either like XYZ_module_enabled, or if not enabled,
* XYZ_module_enabledLUA_USE_MODULES_XYZ. This forms the basis for
* letting the build system detect automatically (via nm) which modules need
* to be linked in.
*/
#define NODEMCU_MODULE(cfgname, luaname, map, initfunc) \
const LOCK_IN_SECTION(".lua_libs") \
luaL_Reg MODULE_PASTE_(lua_lib_,cfgname) = { luaname, initfunc }; \
const LOCK_IN_SECTION(".lua_rotable") \
luaR_table MODULE_EXPAND_PASTE_(cfgname,MODULE_EXPAND_PASTE_(_module_selected,MODULE_PASTE_(LUA_USE_MODULES_,cfgname))) \
= { luaname, map }
/* System module registration support, not using LUA_USE_MODULES_XYZ. */
#define BUILTIN_LIB_INIT(name, luaname, initfunc) \
const LOCK_IN_SECTION(".lua_libs") \
luaL_Reg MODULE_PASTE_(lua_lib_,name) = { luaname, initfunc }
#define BUILTIN_LIB(name, luaname, map) \
const LOCK_IN_SECTION(".lua_rotable") \
luaR_table MODULE_PASTE_(lua_rotable_,name) = { luaname, map }
#if !(MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2)
# error "NodeMCU modules must be built with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
#endif

View File

@ -12,9 +12,7 @@
#define LUA_USE_BUILTIN_DEBUG_MINIMAL // for debug.getregistry() and debug.traceback()
#ifndef LUA_CROSS_COMPILER
#define LUA_USE_MODULES
#ifdef LUA_USE_MODULES
#define LUA_USE_MODULES_ADC
#define LUA_USE_MODULES_BIT
//#define LUA_USE_MODULES_BMP085
@ -47,7 +45,6 @@
//#define LUA_USE_MODULES_WS2801
#define LUA_USE_MODULES_WS2812
#endif /* LUA_USE_MODULES */
#endif
#endif /* LUA_CROSS_COMPILER */
#endif /* __USER_MODULES_H__ */

View File

@ -489,6 +489,7 @@ static int luaB_newproxy (lua_State *L) {
{LSTRKEY("xpcall"), LFUNCVAL(luaB_xpcall)}
#if LUA_OPTIMIZE_MEMORY == 2
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE base_funcs_list[] = {

View File

@ -383,6 +383,7 @@ static int db_errorfb (lua_State *L) {
return 1;
}
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE dblib[] = {

View File

@ -538,6 +538,7 @@ static int f_flush (lua_State *L) {
return pushresult(L, fs_flush(tofile(L)) == 0, NULL);
}
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
#if LUA_OPTIMIZE_MEMORY == 2

View File

@ -311,6 +311,7 @@ static int math_randomseed (lua_State *L) {
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE math_map[] = {

View File

@ -646,6 +646,7 @@ static const lua_CFunction loaders[] =
{loader_preload, loader_Lua, loader_C, loader_Croot, NULL};
#if LUA_OPTIMIZE_MEMORY > 0
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE lmt[] = {

View File

@ -16,7 +16,7 @@
#undef LREGISTER
#if (MIN_OPT_LEVEL > 0) && (LUA_OPTIMIZE_MEMORY >= MIN_OPT_LEVEL)
#define LUA_REG_TYPE luaR_entry ICACHE_RODATA_ATTR
#define LUA_REG_TYPE luaR_entry
#define LSTRKEY LRO_STRKEY
#define LNUMKEY LRO_NUMKEY
#define LNILKEY LRO_NILKEY

View File

@ -825,6 +825,7 @@ static int str_format (lua_State *L) {
return 1;
}
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE strlib[] = {

View File

@ -266,6 +266,7 @@ static int sort (lua_State *L) {
/* }====================================================== */
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE tab_funcs[] = {

View File

@ -221,6 +221,7 @@ static int os_exit (lua_State *L) {
c_exit(luaL_optint(L, 1, EXIT_SUCCESS));
}
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE syslib[] = {

View File

@ -1,11 +1,8 @@
// Module for interfacing with adc
//#include "lua.h"
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_types.h"
#include "user_interface.h"
@ -28,26 +25,10 @@ static int adc_readvdd33( lua_State* L )
}
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE adc_map[] =
{
static const LUA_REG_TYPE adc_map[] = {
{ LSTRKEY( "read" ), LFUNCVAL( adc_sample ) },
{ LSTRKEY( "readvdd33" ), LFUNCVAL( adc_readvdd33) },
#if LUA_OPTIMIZE_MEMORY > 0
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_adc( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_ADC, adc_map );
// Add constants
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(ADC, "adc", adc_map, NULL);

View File

@ -1,121 +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__
#include "lua.h"
#define AUXLIB_GPIO "gpio"
LUALIB_API int ( luaopen_gpio )( lua_State *L );
#define AUXLIB_SPI "spi"
LUALIB_API int ( luaopen_spi )( lua_State *L );
#define AUXLIB_CAN "can"
LUALIB_API int ( luaopen_can )( lua_State *L );
#define AUXLIB_TMR "tmr"
LUALIB_API int ( luaopen_tmr )( lua_State *L );
#define AUXLIB_PD "pd"
LUALIB_API int ( luaopen_pd )( lua_State *L );
#define AUXLIB_UART "uart"
LUALIB_API int ( luaopen_uart )( lua_State *L );
#define AUXLIB_TERM "term"
LUALIB_API int ( luaopen_term )( lua_State *L );
#define AUXLIB_PWM "pwm"
LUALIB_API int ( luaopen_pwm )( lua_State *L );
#define AUXLIB_PACK "pack"
LUALIB_API int ( luaopen_pack )( lua_State *L );
#define AUXLIB_BIT "bit"
LUALIB_API int ( luaopen_bit )( lua_State *L );
#define AUXLIB_NET "net"
LUALIB_API int ( luaopen_net )( lua_State *L );
#define AUXLIB_CPU "cpu"
LUALIB_API int ( luaopen_cpu )( lua_State* L );
#define AUXLIB_ADC "adc"
LUALIB_API int ( luaopen_adc )( lua_State *L );
#define AUXLIB_RPC "rpc"
LUALIB_API int ( luaopen_rpc )( lua_State *L );
#define AUXLIB_BITARRAY "bitarray"
LUALIB_API int ( luaopen_bitarray )( lua_State *L );
#define AUXLIB_ELUA "elua"
LUALIB_API int ( luaopen_elua )( lua_State *L );
#define AUXLIB_I2C "i2c"
LUALIB_API int ( luaopen_i2c )( lua_State *L );
#define AUXLIB_WIFI "wifi"
LUALIB_API int ( luaopen_wifi )( lua_State *L );
#define AUXLIB_COAP "coap"
LUALIB_API int ( luaopen_coap )( lua_State *L );
#define AUXLIB_MQTT "mqtt"
LUALIB_API int ( luaopen_mqtt )( lua_State *L );
#define AUXLIB_U8G "u8g"
LUALIB_API int ( luaopen_u8g )( lua_State *L );
#define AUXLIB_UCG "ucg"
LUALIB_API int ( luaopen_ucg )( lua_State *L );
#define AUXLIB_NODE "node"
LUALIB_API int ( luaopen_node )( lua_State *L );
#define AUXLIB_FILE "file"
LUALIB_API int ( luaopen_file )( lua_State *L );
#define AUXLIB_OW "ow"
LUALIB_API int ( luaopen_ow )( lua_State *L );
#define AUXLIB_CJSON "cjson"
LUALIB_API int ( luaopen_cjson )( lua_State *L );
#define AUXLIB_CRYPTO "crypto"
LUALIB_API int ( luaopen_crypto )( lua_State *L );
#define AUXLIB_RC "rc"
LUALIB_API int ( luaopen_rc )( lua_State *L );
#define AUXLIB_DHT "dht"
LUALIB_API int ( luaopen_dht )( lua_State *L );
// Helper macros
#define MOD_CHECK_ID( mod, id )\
if( !platform_ ## mod ## _exists( id ) )\
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 )
#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

View File

@ -5,13 +5,10 @@
// Modified by BogdanM for eLua
#include "module.h"
#include "c_limits.h"
//#include "lua.h"
#include "lauxlib.h"
#include "auxmods.h"
// #include "type.h"
#include "lrotable.h"
/* FIXME: Assume size_t is an unsigned lua_Integer */
typedef size_t lua_UInteger;
@ -122,9 +119,7 @@ static int bit_clear( lua_State* L )
return 1;
}
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE bit_map[] = {
static const LUA_REG_TYPE bit_map[] = {
{ LSTRKEY( "bnot" ), LFUNCVAL( bit_bnot ) },
{ LSTRKEY( "band" ), LFUNCVAL( bit_band ) },
{ LSTRKEY( "bor" ), LFUNCVAL( bit_bor ) },
@ -140,6 +135,4 @@ const LUA_REG_TYPE bit_map[] = {
{ LNILKEY, LNILVAL}
};
LUALIB_API int luaopen_bit (lua_State *L) {
LREGISTER( L, "bit", bit_map );
}
NODEMCU_MODULE(BIT, "bit", bit_map, NULL);

View File

@ -1,8 +1,6 @@
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_stdlib.h"
#include "c_string.h"
@ -185,10 +183,7 @@ static int ICACHE_FLASH_ATTR bmp085_lua_pressure(lua_State* L) {
return 1;
}
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE bmp085_map[] =
{
static 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 )},
@ -196,8 +191,4 @@ const LUA_REG_TYPE bmp085_map[] =
{ LNILKEY, LNILVAL}
};
LUALIB_API int luaopen_bmp085(lua_State *L) {
LREGISTER(L, "bmp085", bmp085_map);
return 1;
}
NODEMCU_MODULE(BMP085, "bmp085", bmp085_map, NULL);

View File

@ -37,10 +37,10 @@
*/
// #include <assert.h>
#include "module.h"
#include "c_string.h"
#include "c_math.h"
#include "c_limits.h"
#include "lua.h"
#include "lauxlib.h"
#include "flash_api.h"
@ -1528,53 +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
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
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 ) },
#if LUA_OPTIMIZE_MEMORY > 0
#endif
{ 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 LUA_OPTIMIZE_MEMORY > 0
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_CJSON, cjson_map );
// Add constants
/* Set cjson.null */
lua_pushlightuserdata(l, NULL);
lua_setfield(l, -2, "null");
/* Return cjson table */
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
#if 0
/* Return cjson module table */
static int lua_cjson_new(lua_State *l)
{
@ -1644,5 +1598,34 @@ int luaopen_cjson_safe(lua_State *l)
return 1;
}
#endif
// Module function map
static 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 }
};
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;
}
NODEMCU_MODULE(CJSON, "cjson", cjson_map, luaopen_cjson);
/* vi:ai et sw=4 ts=4:
*/

View File

@ -1,11 +1,8 @@
// Module for coapwork
//#include "lua.h"
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_string.h"
#include "c_stdlib.h"
@ -561,39 +558,30 @@ static int coap_client_delete( lua_State* L )
}
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
static const LUA_REG_TYPE coap_server_map[] =
{
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 ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "__index" ), LROVAL( coap_server_map ) },
#endif
{ 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( "post" ), LFUNCVAL( coap_client_post ) },
{ LSTRKEY( "put" ), LFUNCVAL( coap_client_put ) },
{ LSTRKEY( "delete" ), LFUNCVAL( coap_client_delete ) },
{ LSTRKEY( "__gc" ), LFUNCVAL( coap_client_gcdelete ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "__index" ), LROVAL( coap_client_map ) },
#endif
{ LNILKEY, LNILVAL }
};
const LUA_REG_TYPE coap_map[] =
static const LUA_REG_TYPE coap_map[] =
{
{ LSTRKEY( "Server" ), LFUNCVAL( coap_createServer ) },
{ LSTRKEY( "Client" ), LFUNCVAL( coap_createClient ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "CON" ), LNUMVAL( COAP_TYPE_CON ) },
{ LSTRKEY( "NON" ), LNUMVAL( COAP_TYPE_NONCON ) },
{ LSTRKEY( "TEXT_PLAIN"), LNUMVAL( COAP_CONTENTTYPE_TEXT_PLAIN ) },
@ -602,58 +590,16 @@ 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 ) },
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_coap( lua_State *L )
int luaopen_coap( lua_State *L )
{
endpoint_setup();
#if LUA_OPTIMIZE_MEMORY > 0
luaL_rometatable(L, "coap_server", (void *)coap_server_map); // create metatable for coap_server
luaL_rometatable(L, "coap_client", (void *)coap_client_map); // create metatable for coap_client
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
int n;
luaL_register( L, AUXLIB_COAP, coap_map );
// Set it as its own metatable
lua_pushvalue( L, -1 );
lua_setmetatable( L, -2 );
// Module constants
MOD_REG_NUMBER( L, "CON", COAP_TYPE_CON );
MOD_REG_NUMBER( L, "NON", COAP_TYPE_NONCON );
MOD_REG_NUMBER( L, "TEXT_PLAIN", COAP_CONTENTTYPE_TEXT_PLAIN );
MOD_REG_NUMBER( L, "LINKFORMAT", COAP_CONTENTTYPE_APPLICATION_LINKFORMAT );
MOD_REG_NUMBER( L, "XML", COAP_CONTENTTYPE_APPLICATION_XML);
MOD_REG_NUMBER( L, "OCTET_STREAM", COAP_CONTENTTYPE_APPLICATION_OCTET_STREAM);
MOD_REG_NUMBER( L, "EXI", COAP_CONTENTTYPE_APPLICATION_EXI);
MOD_REG_NUMBER( L, "JSON", COAP_CONTENTTYPE_APPLICATION_JSON);
n = lua_gettop(L);
// create metatable
luaL_newmetatable(L, "coap_server");
// metatable.__index = metatable
lua_pushliteral(L, "__index");
lua_pushvalue(L,-2);
lua_rawset(L,-3);
// Setup the methods inside metatable
luaL_register( L, NULL, coap_server_map );
lua_settop(L, n);
// create metatable
luaL_newmetatable(L, "coap_client");
// metatable.__index = metatable
lua_pushliteral(L, "__index");
lua_pushvalue(L,-2);
lua_rawset(L,-3);
// Setup the methods inside metatable
luaL_register( L, NULL, coap_client_map );
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(COAP, "coap", coap_map, luaopen_coap);

View File

@ -1,11 +1,8 @@
// Module for cryptography
//#include "lua.h"
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_types.h"
#include "c_stdlib.h"
#include "../crypto/digests.h"
@ -153,31 +150,14 @@ static int crypto_lhmac (lua_State *L)
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE crypto_map[] =
{
static const LUA_REG_TYPE crypto_map[] = {
{ LSTRKEY( "sha1" ), LFUNCVAL( crypto_sha1 ) },
{ LSTRKEY( "toBase64" ), LFUNCVAL( crypto_base64_encode ) },
{ LSTRKEY( "toHex" ), LFUNCVAL( crypto_hex_encode ) },
{ LSTRKEY( "mask" ), LFUNCVAL( crypto_mask ) },
{ LSTRKEY( "hash" ), LFUNCVAL( crypto_lhash ) },
{ LSTRKEY( "hmac" ), LFUNCVAL( crypto_lhmac ) },
#if LUA_OPTIMIZE_MEMORY > 0
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_crypto( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_CRYPTO, crypto_map );
// Add constants
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(CRYPTO, "crypto", crypto_map, NULL);

View File

@ -1,9 +1,8 @@
// Module for interfacing with the DHTxx sensors (xx = 11-21-22-33-44).
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "auxmods.h"
#include "lrotable.h"
#include "platform.h"
#include "cpu_esp8266.h"
#include "dht.h"
@ -100,30 +99,14 @@ static int dht_lapi_readxx( lua_State *L )
// }
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE dht_map[] =
{
static const LUA_REG_TYPE dht_map[] = {
{ LSTRKEY( "read" ), LFUNCVAL( dht_lapi_read ) },
{ LSTRKEY( "read11" ), LFUNCVAL( dht_lapi_read11 ) },
{ LSTRKEY( "readxx" ), LFUNCVAL( dht_lapi_readxx ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "OK" ), LNUMVAL( DHTLIB_OK ) },
{ LSTRKEY( "ERROR_CHECKSUM" ), LNUMVAL( DHTLIB_ERROR_CHECKSUM ) },
{ LSTRKEY( "ERROR_TIMEOUT" ), LNUMVAL( DHTLIB_ERROR_TIMEOUT ) },
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_dht( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_DHT, dht_map );
// Add the constants
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(DHT, "dht", dht_map, NULL);

View File

@ -31,12 +31,9 @@
* @author Robert Foss <dev@robertfoss.se>
*/
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_stdlib.h"
#include "c_string.h"
#include "user_interface.h"
@ -929,17 +926,10 @@ static int enduser_setup_stop(lua_State* L)
}
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE enduser_setup_map[] =
{
static 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) {
LREGISTER(L, "enduser_setup", enduser_setup_map);
return 1;
}
NODEMCU_MODULE(ENDUSER_SETUP, "enduser_setup", enduser_setup_map, NULL);

View File

@ -1,11 +1,8 @@
// Module for interfacing with file system
#include "lua.h"
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_types.h"
#include "flash_fs.h"
@ -299,10 +296,7 @@ static int file_writeline( lua_State* L )
}
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE file_map[] =
{
static const LUA_REG_TYPE file_map[] = {
{ LSTRKEY( "list" ), LFUNCVAL( file_list ) },
{ LSTRKEY( "open" ), LFUNCVAL( file_open ) },
{ LSTRKEY( "close" ), LFUNCVAL( file_close ) },
@ -311,30 +305,15 @@ 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( "rename" ), LFUNCVAL( file_rename ) },
{ LSTRKEY( "fsinfo" ), LFUNCVAL( file_fsinfo ) },
#endif
#if LUA_OPTIMIZE_MEMORY > 0
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_file( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_FILE, file_map );
// Add constants
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(FILE, "file", file_map, NULL);

View File

@ -1,11 +1,8 @@
// Module for interfacing with GPIO
//#include "lua.h"
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_types.h"
#include "c_string.h"
@ -223,19 +220,13 @@ static int lgpio_serout( lua_State* L )
#undef DELAY_TABLE_MAX_LEN
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE gpio_map[] =
{
static const LUA_REG_TYPE gpio_map[] = {
{ LSTRKEY( "mode" ), LFUNCVAL( lgpio_mode ) },
{ LSTRKEY( "read" ), LFUNCVAL( lgpio_read ) },
{ LSTRKEY( "write" ), LFUNCVAL( lgpio_write ) },
{ LSTRKEY( "serout" ), LFUNCVAL( lgpio_serout ) },
#ifdef GPIO_INTERRUPT_ENABLE
{ LSTRKEY( "trig" ), LFUNCVAL( lgpio_trig ) },
#endif
#if LUA_OPTIMIZE_MEMORY > 0
#ifdef GPIO_INTERRUPT_ENABLE
{ LSTRKEY( "INT" ), LNUMVAL( INTERRUPT ) },
#endif
{ LSTRKEY( "OUTPUT" ), LNUMVAL( OUTPUT ) },
@ -244,12 +235,10 @@ const LUA_REG_TYPE gpio_map[] =
{ LSTRKEY( "LOW" ), LNUMVAL( LOW ) },
{ LSTRKEY( "FLOAT" ), LNUMVAL( FLOAT ) },
{ LSTRKEY( "PULLUP" ), LNUMVAL( PULLUP ) },
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_gpio( lua_State *L )
{
int luaopen_gpio( lua_State *L ) {
#ifdef GPIO_INTERRUPT_ENABLE
int i;
for(i=0;i<GPIO_PIN_NUM;i++){
@ -257,21 +246,7 @@ LUALIB_API int luaopen_gpio( lua_State *L )
}
platform_gpio_init(gpio_intr_callback);
#endif
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_GPIO, gpio_map );
// Add constants
#ifdef GPIO_INTERRUPT_ENABLE
MOD_REG_NUMBER( L, "INT", INTERRUPT );
#endif
MOD_REG_NUMBER( L, "OUTPUT", OUTPUT );
MOD_REG_NUMBER( L, "INPUT", INPUT );
MOD_REG_NUMBER( L, "HIGH", HIGH );
MOD_REG_NUMBER( L, "LOW", LOW );
MOD_REG_NUMBER( L, "FLOAT", FLOAT );
MOD_REG_NUMBER( L, "PULLUP", PULLUP );
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(GPIO, "gpio", gpio_map, luaopen_gpio);

View File

@ -1,11 +1,9 @@
// Module for HX711 load cell amplifier
// https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_stdlib.h"
#include "c_string.h"
#include "user_interface.h"
@ -67,18 +65,16 @@ static int ICACHE_FLASH_ATTR hx711_read(lua_State* L) {
return 1;
}
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE hx711_map[] =
{
// Module function map
static const LUA_REG_TYPE hx711_map[] = {
{ LSTRKEY( "init" ), LFUNCVAL( hx711_init )},
{ LSTRKEY( "read" ), LFUNCVAL( hx711_read )},
{ LNILKEY, LNILVAL}
};
LUALIB_API int luaopen_hx711(lua_State *L) {
// TODO: the below todo was inherited from the ws2812 code but is still valid.
int luaopen_hx711(lua_State *L) {
// TODO: Make sure that the GPIO system is initialized
LREGISTER(L, "hx711", hx711_map);
return 1;
return 0;
}
NODEMCU_MODULE(HX711, "hx711", hx711_map, luaopen_hx711);

View File

@ -1,11 +1,8 @@
// Module for interfacing with the I2C interface
//#include "lua.h"
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
// Lua: speed = i2c.setup( id, sda, scl, speed )
static int i2c_setup( lua_State *L )
@ -143,39 +140,18 @@ static int i2c_read( lua_State *L )
}
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE i2c_map[] =
{
static 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 ) },
#if LUA_OPTIMIZE_MEMORY > 0
//{ LSTRKEY( "FAST" ), LNUMVAL( PLATFORM_I2C_SPEED_FAST ) },
{ LSTRKEY( "SLOW" ), LNUMVAL( PLATFORM_I2C_SPEED_SLOW ) },
{ LSTRKEY( "TRANSMITTER" ), LNUMVAL( PLATFORM_I2C_DIRECTION_TRANSMITTER ) },
{ LSTRKEY( "RECEIVER" ), LNUMVAL( PLATFORM_I2C_DIRECTION_RECEIVER ) },
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_i2c( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_I2C, i2c_map );
// Add the stop bits and parity constants (for i2c.setup)
// MOD_REG_NUMBER( L, "FAST", PLATFORM_I2C_SPEED_FAST );
MOD_REG_NUMBER( L, "SLOW", PLATFORM_I2C_SPEED_SLOW );
MOD_REG_NUMBER( L, "TRANSMITTER", PLATFORM_I2C_DIRECTION_TRANSMITTER );
MOD_REG_NUMBER( L, "RECEIVER", PLATFORM_I2C_DIRECTION_RECEIVER );
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(I2C, "i2c", i2c_map, NULL);

View File

@ -13,124 +13,61 @@
#include "lualib.h"
#include "lauxlib.h"
#include "lrotable.h"
#include "luaconf.h"
#include "module.h"
#include "user_modules.h"
#if defined(LUA_USE_MODULES)
#include "modules.h"
#endif
BUILTIN_LIB_INIT( BASE, "", luaopen_base);
BUILTIN_LIB_INIT( LOADLIB, LUA_LOADLIBNAME, luaopen_package);
#if defined(LUA_MODULES_ROM)
#undef _ROM
#define _ROM( name, openf, table ) extern int openf(lua_State *);
LUA_MODULES_ROM
#endif
static const luaL_Reg lualibs[] = {
{"", luaopen_base},
{LUA_LOADLIBNAME, luaopen_package},
#if defined(LUA_USE_BUILTIN_IO)
{LUA_IOLIBNAME, luaopen_io},
BUILTIN_LIB_INIT( IO, LUA_IOLIBNAME, luaopen_io);
#endif
#if defined(LUA_USE_BUILTIN_STRING)
{LUA_STRLIBNAME, luaopen_string},
#endif
#if LUA_OPTIMIZE_MEMORY == 0
#if defined(LUA_USE_BUILTIN_MATH)
{LUA_MATHLIBNAME, luaopen_math},
#endif
#if defined(LUA_USE_BUILTIN_TABLE)
{LUA_TABLIBNAME, luaopen_table},
#endif
#if defined(LUA_USE_BUILTIN_DEBUG) || defined(LUA_USE_BUILTIN_DEBUG_MINIMAL)
{LUA_DBLIBNAME, luaopen_debug},
#endif
#endif
#if defined(LUA_MODULES_ROM)
#undef _ROM
#define _ROM( name, openf, table ) { name, openf },
LUA_MODULES_ROM
#endif
{NULL, NULL}
};
#if defined (LUA_USE_BUILTIN_STRING)
extern const luaR_entry strlib[];
#endif
#if defined(LUA_USE_BUILTIN_OS)
extern const luaR_entry syslib[];
BUILTIN_LIB_INIT( STRING, LUA_STRLIBNAME, luaopen_string);
BUILTIN_LIB( STRING, LUA_STRLIBNAME, strlib);
#endif
#if defined(LUA_USE_BUILTIN_TABLE)
extern const luaR_entry tab_funcs[];
BUILTIN_LIB_INIT( TABLE, LUA_TABLIBNAME, luaopen_table);
BUILTIN_LIB( TABLE, LUA_TABLIBNAME, tab_funcs);
#endif
#if defined(LUA_USE_BUILTIN_DEBUG) || defined(LUA_USE_BUILTIN_DEBUG_MINIMAL)
extern const luaR_entry dblib[];
BUILTIN_LIB_INIT( DBG, LUA_DBLIBNAME, luaopen_debug);
BUILTIN_LIB( DBG, LUA_DBLIBNAME, dblib);
#endif
#if defined(LUA_USE_BUILTIN_OS)
extern const luaR_entry syslib[];
BUILTIN_LIB( OS, LUA_OSLIBNAME, syslib);
#endif
#if defined(LUA_USE_BUILTIN_COROUTINE)
extern const luaR_entry co_funcs[];
BUILTIN_LIB( CO, LUA_COLIBNAME, co_funcs);
#endif
#if defined(LUA_USE_BUILTIN_MATH)
extern const luaR_entry math_map[];
BUILTIN_LIB( MATH, LUA_MATHLIBNAME, math_map);
#endif
#if defined(LUA_MODULES_ROM) && LUA_OPTIMIZE_MEMORY == 2
#undef _ROM
#define _ROM( name, openf, table ) extern const luaR_entry table[];
LUA_MODULES_ROM
#endif
const luaR_table lua_rotable[] =
extern const luaL_Reg lua_libs[];
void luaL_openlibs (lua_State *L) {
const luaL_Reg *lib = lua_libs;
for (; lib->name; lib++) {
if (lib->func)
{
#if LUA_OPTIMIZE_MEMORY > 0
#if defined(LUA_USE_BUILTIN_STRING)
{LUA_STRLIBNAME, strlib},
#endif
#if defined(LUA_USE_BUILTIN_TABLE)
{LUA_TABLIBNAME, tab_funcs},
#endif
#if defined(LUA_USE_BUILTIN_DEBUG) || defined(LUA_USE_BUILTIN_DEBUG_MINIMAL)
{LUA_DBLIBNAME, dblib},
#endif
#if defined(LUA_USE_BUILTIN_COROUTINE)
{LUA_COLIBNAME, co_funcs},
#endif
#if defined(LUA_USE_BUILTIN_MATH)
{LUA_MATHLIBNAME, math_map},
#endif
#if defined(LUA_USE_BUILTIN_OS)
{LUA_OSLIBNAME, syslib},
#endif
#if defined(LUA_MODULES_ROM) && LUA_OPTIMIZE_MEMORY == 2
#undef _ROM
#define _ROM( name, openf, table ) { name, table },
LUA_MODULES_ROM
#endif
#endif
{NULL, NULL}
};
LUALIB_API void luaL_openlibs (lua_State *L) {
const luaL_Reg *lib = lualibs;
for (; lib->func; lib++) {
lua_pushcfunction(L, lib->func);
lua_pushstring(L, lib->name);
lua_call(L, 1, 0);
}
}
}

View File

@ -1,289 +0,0 @@
/**
* External modules library
*/
#ifndef __MODULES_H__
#define __MODULES_H__
#if defined(LUA_USE_MODULES_GPIO)
#define MODULES_GPIO "gpio"
#define ROM_MODULES_GPIO \
_ROM(MODULES_GPIO, luaopen_gpio, gpio_map)
#else
#define ROM_MODULES_GPIO
#endif
#if defined(LUA_USE_MODULES_PWM)
#define MODULES_PWM "pwm"
#define ROM_MODULES_PWM \
_ROM(MODULES_PWM, luaopen_pwm, pwm_map)
#else
#define ROM_MODULES_PWM
#endif
#if defined(LUA_USE_MODULES_WIFI)
#define MODULES_WIFI "wifi"
#define ROM_MODULES_WIFI \
_ROM(MODULES_WIFI, luaopen_wifi, wifi_map)
#else
#define ROM_MODULES_WIFI
#endif
#if defined(LUA_USE_MODULES_NET)
#define MODULES_NET "net"
#define ROM_MODULES_NET \
_ROM(MODULES_NET, luaopen_net, net_map)
#else
#define ROM_MODULES_NET
#endif
#if defined(LUA_USE_MODULES_COAP)
#define MODULES_COAP "coap"
#define ROM_MODULES_COAP \
_ROM(MODULES_COAP, luaopen_coap, coap_map)
#else
#define ROM_MODULES_COAP
#endif
#if defined(LUA_USE_MODULES_MQTT)
#define MODULES_MQTT "mqtt"
#define ROM_MODULES_MQTT \
_ROM(MODULES_MQTT, luaopen_mqtt, mqtt_map)
#else
#define ROM_MODULES_MQTT
#endif
#if defined(LUA_USE_MODULES_U8G)
#define MODULES_U8G "u8g"
#define ROM_MODULES_U8G \
_ROM(MODULES_U8G, luaopen_u8g, lu8g_map)
#else
#define ROM_MODULES_U8G
#endif
#if defined(LUA_USE_MODULES_UCG)
#define MODULES_UCG "ucg"
#define ROM_MODULES_UCG \
_ROM(MODULES_UCG, luaopen_ucg, lucg_map)
#else
#define ROM_MODULES_UCG
#endif
#if defined(LUA_USE_MODULES_I2C)
#define MODULES_I2C "i2c"
#define ROM_MODULES_I2C \
_ROM(MODULES_I2C, luaopen_i2c, i2c_map)
#else
#define ROM_MODULES_I2C
#endif
#if defined(LUA_USE_MODULES_SPI)
#define MODULES_SPI "spi"
#define ROM_MODULES_SPI \
_ROM(MODULES_SPI, luaopen_spi, spi_map)
#else
#define ROM_MODULES_SPI
#endif
#if defined(LUA_USE_MODULES_TMR)
#define MODULES_TMR "tmr"
#define ROM_MODULES_TMR \
_ROM(MODULES_TMR, luaopen_tmr, tmr_map)
#else
#define ROM_MODULES_TMR
#endif
#if defined(LUA_USE_MODULES_NODE)
#define MODULES_NODE "node"
#define ROM_MODULES_NODE \
_ROM(MODULES_NODE, luaopen_node, node_map)
#else
#define ROM_MODULES_NODE
#endif
#if defined(LUA_USE_MODULES_FILE)
#define MODULES_FILE "file"
#define ROM_MODULES_FILE \
_ROM(MODULES_FILE, luaopen_file, file_map)
#else
#define ROM_MODULES_FILE
#endif
#if defined(LUA_USE_MODULES_ADC)
#define MODULES_ADC "adc"
#define ROM_MODULES_ADC \
_ROM(MODULES_ADC, luaopen_adc, adc_map)
#else
#define ROM_MODULES_ADC
#endif
#if defined(LUA_USE_MODULES_UART)
#define MODULES_UART "uart"
#define ROM_MODULES_UART \
_ROM(MODULES_UART, luaopen_uart, uart_map)
#else
#define ROM_MODULES_UART
#endif
#if defined(LUA_USE_MODULES_OW)
#define MODULES_OW "ow"
#define ROM_MODULES_OW \
_ROM(MODULES_OW, luaopen_ow, ow_map)
#else
#define ROM_MODULES_OW
#endif
#if defined(LUA_USE_MODULES_BIT)
#define MODULES_BIT "bit"
#define ROM_MODULES_BIT \
_ROM(MODULES_BIT, luaopen_bit, bit_map)
#else
#define ROM_MODULES_BIT
#endif
#if defined(LUA_USE_MODULES_WS2801)
#define MODULES_WS2801 "ws2801"
#define ROM_MODULES_WS2801 \
_ROM(MODULES_WS2801, luaopen_ws2801, ws2801_map)
#else
#define ROM_MODULES_WS2801
#endif
#if defined(LUA_USE_MODULES_WS2812)
#define MODULES_WS2812 "ws2812"
#define ROM_MODULES_WS2812 \
_ROM(MODULES_WS2812, luaopen_ws2812, ws2812_map)
#else
#define ROM_MODULES_WS2812
#endif
#if defined(LUA_USE_MODULES_ENDUSER_SETUP)
#define MODULES_ENDUSER_SETUP "enduser_setup"
#define ROM_MODULES_ENDUSER_SETUP \
_ROM(MODULES_ENDUSER_SETUP, luaopen_enduser_setup, enduser_setup_map)
#else
#define ROM_MODULES_ENDUSER_SETUP
#endif
#if defined(LUA_USE_MODULES_CJSON)
#define MODULES_CJSON "cjson"
#define ROM_MODULES_CJSON \
_ROM(MODULES_CJSON, luaopen_cjson, cjson_map)
#else
#define ROM_MODULES_CJSON
#endif
#if defined(LUA_USE_MODULES_CRYPTO)
#define MODULES_CRYPTO "crypto"
#define ROM_MODULES_CRYPTO \
_ROM(MODULES_CRYPTO, luaopen_crypto, crypto_map)
#else
#define ROM_MODULES_CRYPTO
#endif
#if defined(LUA_USE_MODULES_RC)
#define MODULES_RC "rc"
#define ROM_MODULES_RC \
_ROM(MODULES_RC, luaopen_rc, rc_map)
#else
#define ROM_MODULES_RC
#endif
#if defined(LUA_USE_MODULES_DHT)
#define MODULES_DHT "dht"
#define ROM_MODULES_DHT \
_ROM(MODULES_DHT, luaopen_dht, dht_map)
#else
#define ROM_MODULES_DHT
#endif
#if defined(LUA_USE_MODULES_RTCMEM)
#define MODULES_RTCMEM "rtcmem"
#define ROM_MODULES_RTCMEM \
_ROM(MODULES_RTCMEM, luaopen_rtcmem, rtcmem_map)
#else
#define ROM_MODULES_RTCMEM
#endif
#if defined(LUA_USE_MODULES_RTCTIME)
#define MODULES_RTCTIME "rtctime"
#define ROM_MODULES_RTCTIME \
_ROM(MODULES_RTCTIME, luaopen_rtctime, rtctime_map)
#else
#define ROM_MODULES_RTCTIME
#endif
#if defined(LUA_USE_MODULES_RTCFIFO)
#define MODULES_RTCFIFO "rtcfifo"
#define ROM_MODULES_RTCFIFO \
_ROM(MODULES_RTCFIFO, luaopen_rtcfifo, rtcfifo_map)
#else
#define ROM_MODULES_RTCFIFO
#endif
#if defined(LUA_USE_MODULES_SNTP)
#define MODULES_SNTP "sntp"
#define ROM_MODULES_SNTP \
_ROM(MODULES_SNTP, luaopen_sntp, sntp_map)
#else
#define ROM_MODULES_SNTP
#endif
#if defined(LUA_USE_MODULES_BMP085)
#define MODULES_BMP085 "bmp085"
#define ROM_MODULES_BMP085 \
_ROM(MODULES_BMP085, luaopen_bmp085, bmp085_map)
#else
#define ROM_MODULES_BMP085
#endif
#if defined(LUA_USE_MODULES_TSL2561)
#define MODULES_TSL2561 "tsl2561"
#define ROM_MODULES_TSL2561 \
_ROM(MODULES_TSL2561, luaopen_tsl2561, tsl2561_map)
#else
#define ROM_MODULES_TSL2561
#endif
#if defined(LUA_USE_MODULES_HX711)
#define MODULES_HX711 "hx711"
#define ROM_MODULES_HX711 \
_ROM(MODULES_HX711, luaopen_hx711, hx711_map)
#else
#define ROM_MODULES_HX711
#endif
#define LUA_MODULES_ROM \
ROM_MODULES_GPIO \
ROM_MODULES_PWM \
ROM_MODULES_WIFI \
ROM_MODULES_COAP \
ROM_MODULES_MQTT \
ROM_MODULES_U8G \
ROM_MODULES_UCG \
ROM_MODULES_I2C \
ROM_MODULES_SPI \
ROM_MODULES_TMR \
ROM_MODULES_NODE \
ROM_MODULES_FILE \
ROM_MODULES_NET \
ROM_MODULES_ADC \
ROM_MODULES_UART \
ROM_MODULES_OW \
ROM_MODULES_BIT \
ROM_MODULES_ENDUSER_SETUP \
ROM_MODULES_WS2801 \
ROM_MODULES_WS2812 \
ROM_MODULES_CJSON \
ROM_MODULES_CRYPTO \
ROM_MODULES_RC \
ROM_MODULES_DHT \
ROM_MODULES_RTCMEM \
ROM_MODULES_RTCTIME \
ROM_MODULES_RTCFIFO \
ROM_MODULES_SNTP \
ROM_MODULES_BMP085 \
ROM_MODULES_TSL2561 \
ROM_MODULES_HX711
#endif

View File

@ -1,11 +1,8 @@
// Module for mqtt
//#include "lua.h"
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_string.h"
#include "c_stdlib.h"
@ -1392,11 +1389,7 @@ static int mqtt_socket_lwt( lua_State* L )
}
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
static const LUA_REG_TYPE mqtt_socket_map[] =
{
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 ) },
@ -1404,47 +1397,20 @@ static const LUA_REG_TYPE mqtt_socket_map[] =
{ LSTRKEY( "lwt" ), LFUNCVAL( mqtt_socket_lwt ) },
{ LSTRKEY( "on" ), LFUNCVAL( mqtt_socket_on ) },
{ LSTRKEY( "__gc" ), LFUNCVAL( mqtt_delete ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "__index" ), LROVAL( mqtt_socket_map ) },
#endif
{ LNILKEY, LNILVAL }
};
const LUA_REG_TYPE mqtt_map[] =
{
static const LUA_REG_TYPE mqtt_map[] = {
{ LSTRKEY( "Client" ), LFUNCVAL( mqtt_socket_client ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "__metatable" ), LROVAL( mqtt_map ) },
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_mqtt( lua_State *L )
int luaopen_mqtt( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
luaL_rometatable(L, "mqtt.socket", (void *)mqtt_socket_map); // create metatable for mqtt.socket
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
int n;
luaL_register( L, AUXLIB_MQTT, mqtt_map );
// Set it as its own metatable
lua_pushvalue( L, -1 );
lua_setmetatable( L, -2 );
// Module constants
// MOD_REG_NUMBER( L, "TCP", TCP );
// create metatable
luaL_newmetatable(L, "mqtt.socket");
// metatable.__index = metatable
lua_pushliteral(L, "__index");
lua_pushvalue(L,-2);
lua_rawset(L,-3);
// Setup the methods inside metatable
luaL_register( L, NULL, mqtt_socket_map );
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(MQTT, "mqtt", mqtt_map, luaopen_mqtt);

View File

@ -1,11 +1,8 @@
// Module for network
//#include "lua.h"
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_string.h"
#include "c_stdlib.h"
@ -1508,24 +1505,18 @@ static int expose_array(lua_State* L, char *array, unsigned short len) {
#endif
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
static const LUA_REG_TYPE net_server_map[] =
{
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 ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "__index" ), LROVAL( net_server_map ) },
#endif
{ 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 ) },
@ -1536,104 +1527,50 @@ static const LUA_REG_TYPE net_socket_map[] =
{ LSTRKEY( "getpeer" ), LFUNCVAL( net_socket_getpeer ) },
//{ LSTRKEY( "delete" ), LFUNCVAL( net_socket_delete ) },
{ LSTRKEY( "__gc" ), LFUNCVAL( net_socket_delete ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "__index" ), LROVAL( net_socket_map ) },
#endif
{ LNILKEY, LNILVAL }
};
#if 0
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[] =
{
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[] =
{
static 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 ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "dns" ), LROVAL( net_dns_map ) },
{ LSTRKEY( "TCP" ), LNUMVAL( TCP ) },
{ LSTRKEY( "UDP" ), LNUMVAL( UDP ) },
{ LSTRKEY( "__metatable" ), LROVAL( net_map ) },
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_net( lua_State *L )
{
int luaopen_net( lua_State *L ) {
int i;
for(i=0;i<MAX_SOCKET;i++)
{
socket[i] = LUA_NOREF;
}
#if LUA_OPTIMIZE_MEMORY > 0
luaL_rometatable(L, "net.server", (void *)net_server_map); // create metatable for net.server
luaL_rometatable(L, "net.socket", (void *)net_socket_map); // create metatable for net.socket
#if 0
luaL_rometatable(L, "net.array", (void *)net_array_map); // create metatable for net.array
#endif
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
int n;
luaL_register( L, AUXLIB_NET, net_map );
// Set it as its own metatable
lua_pushvalue( L, -1 );
lua_setmetatable( L, -2 );
// Module constants
MOD_REG_NUMBER( L, "TCP", TCP );
MOD_REG_NUMBER( L, "UDP", UDP );
n = lua_gettop(L);
// create metatable
luaL_newmetatable(L, "net.server");
// metatable.__index = metatable
lua_pushliteral(L, "__index");
lua_pushvalue(L,-2);
lua_rawset(L,-3);
// Setup the methods inside metatable
luaL_register( L, NULL, net_server_map );
lua_settop(L, n);
// create metatable
luaL_newmetatable(L, "net.socket");
// metatable.__index = metatable
lua_pushliteral(L, "__index");
lua_pushvalue(L,-2);
lua_rawset(L,-3);
// Setup the methods inside metatable
luaL_register( L, NULL, net_socket_map );
#if 0
lua_settop(L, n);
// create metatable
luaL_newmetatable(L, "net.array");
// Setup the methods inside metatable
luaL_register( L, NULL, net_array_map );
#endif
lua_settop(L, n);
lua_newtable( L );
luaL_register( L, NULL, net_dns_map );
lua_setfield( L, -2, "dns" );
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(NET, "net", net_map, luaopen_net);

View File

@ -1,6 +1,6 @@
// Module for interfacing with system
#include "lua.h"
#include "module.h"
#include "lauxlib.h"
#include "ldebug.h"
@ -15,14 +15,12 @@
#include "lundump.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
#include "c_types.h"
#include "romfs.h"
#include "c_string.h"
#include "driver/uart.h"
//#include "spi_flash.h"
#include "user_interface.h"
#include "flash_api.h"
#include "flash_fs.h"
@ -550,9 +548,7 @@ static int node_stripdebug (lua_State *L) {
#endif
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE node_map[] =
static const LUA_REG_TYPE node_map[] =
{
{ LSTRKEY( "restart" ), LFUNCVAL( node_restart ) },
{ LSTRKEY( "dsleep" ), LFUNCVAL( node_deepsleep ) },
@ -581,20 +577,7 @@ const LUA_REG_TYPE node_map[] =
// Combined to dsleep(us, option)
// { LSTRKEY( "dsleepsetoption" ), LFUNCVAL( node_deepsleep_setoption) },
#if LUA_OPTIMIZE_MEMORY > 0
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_node( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_NODE, node_map );
// Add constants
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(NODE, "node", node_map, NULL);

View File

@ -1,10 +1,8 @@
// Module for interfacing with the OneWire interface
//#include "lua.h"
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "auxmods.h"
#include "lrotable.h"
#include "platform.h"
#include "driver/onewire.h"
// Lua: ow.setup( id )
@ -282,10 +280,7 @@ static int ow_crc16( lua_State *L )
#endif
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE ow_map[] =
{
static const LUA_REG_TYPE ow_map[] = {
{ LSTRKEY( "setup" ), LFUNCVAL( ow_setup ) },
{ LSTRKEY( "reset" ), LFUNCVAL( ow_reset ) },
{ LSTRKEY( "skip" ), LFUNCVAL( ow_skip ) },
@ -306,22 +301,8 @@ const LUA_REG_TYPE ow_map[] =
{ LSTRKEY( "check_crc16" ), LFUNCVAL( ow_check_crc16 ) },
{ LSTRKEY( "crc16" ), LFUNCVAL( ow_crc16 ) },
#endif
#endif
#if LUA_OPTIMIZE_MEMORY > 0
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_ow( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_OW, ow_map );
// Add the constants
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(OW, "ow", ow_map, NULL);

View File

@ -1,12 +1,8 @@
// Module for interfacing with PWM
//#include "lua.h"
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_types.h"
// Lua: realfrequency = setup( id, frequency, duty )
@ -125,10 +121,7 @@ static int lpwm_getduty( lua_State* L )
}
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE pwm_map[] =
{
static const LUA_REG_TYPE pwm_map[] = {
{ LSTRKEY( "setup" ), LFUNCVAL( lpwm_setup ) },
{ LSTRKEY( "close" ), LFUNCVAL( lpwm_close ) },
{ LSTRKEY( "start" ), LFUNCVAL( lpwm_start ) },
@ -137,18 +130,7 @@ const LUA_REG_TYPE pwm_map[] =
{ LSTRKEY( "getclock" ), LFUNCVAL( lpwm_getclock ) },
{ LSTRKEY( "setduty" ), LFUNCVAL( lpwm_setduty ) },
{ LSTRKEY( "getduty" ), LFUNCVAL( lpwm_getduty ) },
#if LUA_OPTIMIZE_MEMORY > 0
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_pwm( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_PWM, pwm_map );
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(PWM, "pwm", pwm_map, NULL);

View File

@ -1,8 +1,6 @@
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
//#include "driver/easygpio.h"
//static Ping_Data pingA;
#define defPulseLen 185
@ -80,17 +78,16 @@ static int ICACHE_FLASH_ATTR rc_send(lua_State* L) {
return 1;
}
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE rc_map[] =
{
// Module function map
static const LUA_REG_TYPE rc_map[] = {
{ LSTRKEY( "send" ), LFUNCVAL( rc_send )},
{ LNILKEY, LNILVAL}
};
//LUALIB_API int luaopen_ultra(lua_State *L) {
LUALIB_API int luaopen_rc(lua_State *L) {
int luaopen_rc(lua_State *L) {
// TODO: Make sure that the GPIO system is initialized
LREGISTER(L, "rc", rc_map);
return 1;
return 0;
}
NODEMCU_MODULE(RC, "rc", rc_map, luaopen_rc);

View File

@ -1,5 +1,6 @@
// Module for RTC sample FIFO storage
#include "module.h"
#include "lauxlib.h"
#include "user_modules.h"
#include "rtc/rtctime.h"
@ -164,10 +165,7 @@ static int rtcfifo_dsleep_until_sample (lua_State *L)
#endif
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE rtcfifo_map[] =
{
static const LUA_REG_TYPE rtcfifo_map[] = {
{ LSTRKEY("prepare"), LFUNCVAL(rtcfifo_prepare) },
{ LSTRKEY("ready"), LFUNCVAL(rtcfifo_ready) },
{ LSTRKEY("put"), LFUNCVAL(rtcfifo_put) },
@ -181,12 +179,4 @@ const LUA_REG_TYPE rtcfifo_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_rtcfifo (lua_State *L)
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else
luaL_register (L, AUXLIB_RTCFIFO, rtcfifo_map);
return 1;
#endif
}
NODEMCU_MODULE(RTCFIFO, "rtcfifo", rtcfifo_map, NULL);

View File

@ -1,5 +1,6 @@
// Module for RTC user memory access
#include "module.h"
#include "lauxlib.h"
#include "rtc/rtcaccess.h"
@ -40,21 +41,10 @@ static int rtcmem_write32 (lua_State *L)
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE rtcmem_map[] =
{
static 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)
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else
luaL_register (L, AUXLIB_RTCMEM, rtcmem_map);
return 1;
#endif
}
NODEMCU_MODULE(RTCMEM, "rtcmem", rtcmem_map, NULL);

View File

@ -1,5 +1,6 @@
// Module for RTC time keeping
#include "module.h"
#include "lauxlib.h"
#include "rtc/rtctime_internal.h"
@ -115,10 +116,7 @@ static int rtctime_dsleep_aligned (lua_State *L)
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE rtctime_map[] =
{
static const LUA_REG_TYPE rtctime_map[] = {
{ LSTRKEY("set"), LFUNCVAL(rtctime_set) },
{ LSTRKEY("get"), LFUNCVAL(rtctime_get) },
{ LSTRKEY("dsleep"), LFUNCVAL(rtctime_dsleep) },
@ -126,12 +124,4 @@ const LUA_REG_TYPE rtctime_map[] =
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_rtctime (lua_State *L)
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else
luaL_register (L, AUXLIB_RTCTIME, rtctime_map);
return 1;
#endif
}
NODEMCU_MODULE(RTCTIME, "rtctime", rtctime_map, NULL);

View File

@ -33,6 +33,7 @@
// Module for Simple Network Time Protocol (SNTP)
#include "module.h"
#include "lauxlib.h"
#include "os_type.h"
#include "osapi.h"
@ -375,20 +376,9 @@ error:
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE sntp_map[] =
{
static const LUA_REG_TYPE sntp_map[] = {
{ LSTRKEY("sync"), LFUNCVAL(sntp_sync) },
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_sntp (lua_State *L)
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else
luaL_register (L, AUXLIB_SNTP, sntp_map);
return 1;
#endif
}
NODEMCU_MODULE(SNTP, "sntp", sntp_map, NULL);

View File

@ -1,11 +1,8 @@
// Module for interfacing with the SPI interface
//#include "lua.h"
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#define SPI_HALFDUPLEX 0
#define SPI_FULLDUPLEX 1
@ -313,17 +310,13 @@ static int spi_transaction( lua_State *L )
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE spi_map[] =
{
static const LUA_REG_TYPE spi_map[] = {
{ LSTRKEY( "setup" ), LFUNCVAL( spi_setup ) },
{ LSTRKEY( "send" ), LFUNCVAL( spi_send_recv ) },
{ LSTRKEY( "recv" ), LFUNCVAL( spi_recv ) },
{ LSTRKEY( "set_mosi" ), LFUNCVAL( spi_set_mosi ) },
{ LSTRKEY( "get_miso" ), LFUNCVAL( spi_get_miso ) },
{ LSTRKEY( "transaction" ), LFUNCVAL( spi_transaction ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "MASTER" ), LNUMVAL( PLATFORM_SPI_MASTER ) },
{ LSTRKEY( "SLAVE" ), LNUMVAL( PLATFORM_SPI_SLAVE) },
{ LSTRKEY( "CPHA_LOW" ), LNUMVAL( PLATFORM_SPI_CPHA_LOW) },
@ -333,28 +326,7 @@ const LUA_REG_TYPE spi_map[] =
{ LSTRKEY( "DATABITS_8" ), LNUMVAL( 8 ) },
{ LSTRKEY( "HALFDUPLEX" ), LNUMVAL( SPI_HALFDUPLEX ) },
{ LSTRKEY( "FULLDUPLEX" ), LNUMVAL( SPI_FULLDUPLEX ) },
#endif // #if LUA_OPTIMIZE_MEMORY > 0
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_spi( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_SPI, spi_map );
// Add constants
MOD_REG_NUMBER( L, "MASTER", PLATFORM_SPI_MASTER);
MOD_REG_NUMBER( L, "SLAVE", PLATFORM_SPI_SLAVE);
MOD_REG_NUMBER( L, "CPHA_LOW" , PLATFORM_SPI_CPHA_LOW);
MOD_REG_NUMBER( L, "CPHA_HIGH", PLATFORM_SPI_CPHA_HIGH);
MOD_REG_NUMBER( L, "CPOL_LOW" , PLATFORM_SPI_CPOL_LOW);
MOD_REG_NUMBER( L, "CPOL_HIGH", PLATFORM_SPI_CPOL_HIGH);
MOD_REG_NUMBER( L, "DATABITS_8", 8 );
MOD_REG_NUMBER( L, "HALFDUPLEX", SPI_HALFDUPLEX );
MOD_REG_NUMBER( L, "FULLDUPLEX", SPI_FULLDUPLEX );
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(SPI, "spi", spi_map, NULL);

View File

@ -48,14 +48,9 @@ tmr.softwd(int)
the timer units are seconds
*/
#define MIN_OPT_LEVEL 2
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
#include "c_types.h"
#define TIMER_MODE_OFF 3
@ -311,7 +306,7 @@ static int tmr_softwd( lua_State* L ){
// Module function map
const LUA_REG_TYPE tmr_map[] = {
static const LUA_REG_TYPE tmr_map[] = {
{ LSTRKEY( "delay" ), LFUNCVAL( tmr_delay ) },
{ LSTRKEY( "now" ), LFUNCVAL( tmr_now ) },
{ LSTRKEY( "wdclr" ), LFUNCVAL( tmr_wdclr ) },
@ -324,15 +319,13 @@ const LUA_REG_TYPE tmr_map[] = {
{ LSTRKEY( "unregister" ), LFUNCVAL( tmr_unregister ) },
{ LSTRKEY( "state" ), LFUNCVAL( tmr_state ) },
{ LSTRKEY( "interval" ), LFUNCVAL( tmr_interval) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "ALARM_SINGLE" ), LNUMVAL( TIMER_MODE_SINGLE ) },
{ LSTRKEY( "ALARM_SEMI" ), LNUMVAL( TIMER_MODE_SEMI ) },
{ LSTRKEY( "ALARM_AUTO" ), LNUMVAL( TIMER_MODE_AUTO ) },
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_tmr( lua_State *L ){
int luaopen_tmr( lua_State *L ){
int i;
for(i=0; i<NUM_TMR; i++){
alarm_timers[i].lua_ref = LUA_NOREF;
@ -343,17 +336,7 @@ LUALIB_API int luaopen_tmr( lua_State *L ){
ets_timer_disarm(&rtc_timer);
ets_timer_setfn(&rtc_timer, rtc_callback, NULL);
ets_timer_arm_new(&rtc_timer, 1000, 1, 1);
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else
luaL_register( L, AUXLIB_TMR, tmr_map );
lua_pushvalue( L, -1 );
lua_setmetatable( L, -2 );
MOD_REG_NUMBER( L, "ALARM_SINGLE", TIMER_MODE_SINGLE );
MOD_REG_NUMBER( L, "ALARM_SEMI", TIMER_MODE_SEMI );
MOD_REG_NUMBER( L, "ALARM_AUTO", TIMER_MODE_AUTO );
return 1;
#endif
}
NODEMCU_MODULE(TMR, "tmr", tmr_map, luaopen_tmr);

View File

@ -4,11 +4,9 @@
* Created on: Aug 21, 2015
* Author: Michael Lucas (Aeprox @github)
*/
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "../tsl2561/tsl2561.h"
static uint16_t ch0;
@ -102,38 +100,28 @@ static int ICACHE_FLASH_ATTR tsl2561_lua_getchannels(lua_State* L) {
return 3;
}
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE tsl2561_map[] =
{
// Module function map
static 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) {
LREGISTER(L, "tsl2561", tsl2561_map);
return 1;
}
NODEMCU_MODULE(TSL2561, "tsl2561", tsl2561_map, NULL);

View File

@ -1,10 +1,8 @@
// Module for U8glib
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_stdlib.h"
@ -1027,11 +1025,7 @@ U8G_DISPLAY_TABLE_SPI
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
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 ) },
@ -1083,82 +1077,38 @@ static const LUA_REG_TYPE lu8g_display_map[] =
{ LSTRKEY( "undoRotation" ), LFUNCVAL( lu8g_undoRotation ) },
{ LSTRKEY( "undoScale" ), LFUNCVAL( lu8g_undoScale ) },
{ LSTRKEY( "__gc" ), LFUNCVAL( lu8g_close_display ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "__index" ), LROVAL( lu8g_display_map ) },
#endif
{ LNILKEY, LNILVAL }
};
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
static 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
#if LUA_OPTIMIZE_MEMORY > 0
// Register fonts
#undef U8G_FONT_TABLE_ENTRY
#define U8G_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(u8g_ ## font) ) },
#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 ) },
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_u8g( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
int luaopen_u8g( lua_State *L ) {
luaL_rometatable(L, "u8g.display", (void *)lu8g_display_map); // create metatable
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
int n;
luaL_register( L, AUXLIB_U8G, lu8g_map );
// Set it as its own metatable
lua_pushvalue( L, -1 );
lua_setmetatable( L, -2 );
// Module constants
// Register fonts
#undef U8G_FONT_TABLE_ENTRY
#define U8G_FONT_TABLE_ENTRY(font) MOD_REG_LUDATA( L, #font, (void *)(u8g_ ## font) );
U8G_FONT_TABLE
// Options for circle/ ellipse drawing
MOD_REG_NUMBER( L, "DRAW_UPPER_RIGHT", U8G_DRAW_UPPER_RIGHT );
MOD_REG_NUMBER( L, "DRAW_UPPER_LEFT", U8G_DRAW_UPPER_LEFT );
MOD_REG_NUMBER( L, "DRAW_LOWER_RIGHT", U8G_DRAW_LOWER_RIGHT );
MOD_REG_NUMBER( L, "DRAW_LOWER_LEFT", U8G_DRAW_LOWER_LEFT );
MOD_REG_NUMBER( L, "DRAW_ALL", U8G_DRAW_ALL );
// Display modes
MOD_REG_NUMBER( L, "MODE_BW", U8G_MODE_BW );
MOD_REG_NUMBER( L, "MODE_GRAY2BIT", U8G_MODE_GRAY2BIT );
// create metatable
luaL_newmetatable(L, "u8g.display");
// metatable.__index = metatable
lua_pushliteral(L, "__index");
lua_pushvalue(L,-2);
lua_rawset(L,-3);
// Setup the methods inside metatable
luaL_register( L, NULL, u8g_display_map );
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(U8G, "u8g", lu8g_map, luaopen_u8g);

View File

@ -1,11 +1,8 @@
// Module for interfacing with serial
//#include "lua.h"
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_types.h"
#include "c_string.h"
@ -158,29 +155,12 @@ static int uart_write( lua_State* L )
}
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE uart_map[] =
{
static const LUA_REG_TYPE uart_map[] = {
{ LSTRKEY( "setup" ), LFUNCVAL( uart_setup ) },
{ LSTRKEY( "write" ), LFUNCVAL( uart_write ) },
{ LSTRKEY( "on" ), LFUNCVAL( uart_on ) },
{ LSTRKEY( "alt" ), LFUNCVAL( uart_alt ) },
#if LUA_OPTIMIZE_MEMORY > 0
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_uart( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_UART, uart_map );
// Add constants
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(UART, "uart", uart_map, NULL);

View File

@ -1,10 +1,8 @@
// Module for Ucglib
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_stdlib.h"
@ -876,9 +874,6 @@ UCG_DISPLAY_TABLE
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
static const LUA_REG_TYPE lucg_display_map[] =
{
{ LSTRKEY( "begin" ), LFUNCVAL( lucg_begin ) },
@ -926,20 +921,16 @@ static const LUA_REG_TYPE lucg_display_map[] =
{ LSTRKEY( "undoScale" ), LFUNCVAL( lucg_undoScale ) },
{ LSTRKEY( "__gc" ), LFUNCVAL( lucg_close_display ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "__index" ), LROVAL ( lucg_display_map ) },
#endif
{ LNILKEY, LNILVAL }
};
const LUA_REG_TYPE lucg_map[] =
static const LUA_REG_TYPE lucg_map[] =
{
#undef UCG_DISPLAY_TABLE_ENTRY
#define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension) { LSTRKEY( #binding ), LFUNCVAL ( lucg_ ##binding ) },
UCG_DISPLAY_TABLE
#if LUA_OPTIMIZE_MEMORY > 0
// Register fonts
#undef UCG_FONT_TABLE_ENTRY
#define UCG_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(ucg_ ## font) ) },
@ -957,50 +948,13 @@ const LUA_REG_TYPE lucg_map[] =
{ LSTRKEY( "DRAW_ALL" ), LNUMVAL( UCG_DRAW_ALL ) },
{ LSTRKEY( "__metatable" ), LROVAL( lucg_map ) },
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_ucg( lua_State *L )
int luaopen_ucg( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
luaL_rometatable(L, "ucg.display", (void *)lucg_display_map); // create metatable
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
int n;
luaL_register( L, AUXLIB_UCG, lucg_map );
// Set it as its own metatable
lua_pushvalue( L, -1 );
lua_setmetatable( L, -2 );
// Module constants
// Register fonts
#undef UCG_FONT_TABLE_ENTRY
#define UCG_FONT_TABLE_ENTRY(font) MOD_REG_LUDATA( L, #font, (void *)(ucg_ ## font) );
UCG_FONT_TABLE
// Font modes
MOD_REG_NUMBER( L, "FONT_MODE_TRANSPARENT", UCG_FONT_MODE_TRANSPARENT );
MOD_REG_NUMBER( L, "FONT_MODE_SOLID", UCG_FONT_MODE_SOLID );
// Options for circle/ disc drawing
MOD_REG_NUMBER( L, "DRAW_UPPER_RIGHT", UCG_DRAW_UPPER_RIGHT );
MOD_REG_NUMBER( L, "DRAW_UPPER_LEFT", UCG_DRAW_UPPER_LEFT );
MOD_REG_NUMBER( L, "DRAW_LOWER_RIGHT", UCG_DRAW_LOWER_RIGHT );
MOD_REG_NUMBER( L, "DRAW_LOWER_LEFT", UCG_DRAW_LOWER_LEFT );
MOD_REG_NUMBER( L, "DRAW_ALL", UCG_DRAW_ALL );
// create metatable
luaL_newmetatable(L, "ucg.display");
// metatable.__index = metatable
lua_pushliteral(L, "__index");
lua_pushvalue(L,-2);
lua_rawset(L,-3);
// Setup the methods inside metatable
luaL_register( L, NULL, lucg_display_map );
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(UCG, "ucg", lucg_map, luaopen_ucg);

View File

@ -1,11 +1,8 @@
// Module for interfacing with WIFI
//#include "lua.h"
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_string.h"
#include "c_stdlib.h"
@ -1340,10 +1337,7 @@ static int wifi_ap_dhcp_stop( lua_State* L )
}
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
static const LUA_REG_TYPE wifi_station_map[] =
{
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 ) },
@ -1362,16 +1356,14 @@ static const LUA_REG_TYPE wifi_station_map[] =
{ 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 ) },
@ -1380,16 +1372,12 @@ static const LUA_REG_TYPE wifi_ap_map[] =
{ LSTRKEY( "setmac" ), LFUNCVAL( wifi_ap_setmac ) },
{ LSTRKEY( "getclient" ), LFUNCVAL( wifi_ap_listclient ) },
{ LSTRKEY( "getconfig" ), LFUNCVAL( wifi_ap_getconfig ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "dhcp" ), LROVAL( wifi_ap_dhcp_map ) },
//{ LSTRKEY( "__metatable" ), LROVAL( wifi_ap_map ) },
#endif
{ LNILKEY, LNILVAL }
};
const LUA_REG_TYPE wifi_map[] =
{
static const LUA_REG_TYPE wifi_map[] = {
{ LSTRKEY( "setmode" ), LFUNCVAL( wifi_setmode ) },
{ LSTRKEY( "getmode" ), LFUNCVAL( wifi_getmode ) },
{ LSTRKEY( "getchannel" ), LFUNCVAL( wifi_getchannel ) },
@ -1399,7 +1387,7 @@ const LUA_REG_TYPE wifi_map[] =
{ LSTRKEY( "startsmart" ), LFUNCVAL( wifi_start_smart ) },
{ LSTRKEY( "stopsmart" ), LFUNCVAL( wifi_exit_smart ) },
{ LSTRKEY( "sleeptype" ), LFUNCVAL( wifi_sleeptype ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "sta" ), LROVAL( wifi_station_map ) },
{ LSTRKEY( "ap" ), LROVAL( wifi_ap_map ) },
@ -1430,58 +1418,7 @@ const LUA_REG_TYPE wifi_map[] =
{ LSTRKEY( "STA_GOTIP" ), LNUMVAL( STATION_GOT_IP ) },
{ LSTRKEY( "__metatable" ), LROVAL( wifi_map ) },
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int luaopen_wifi( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
luaL_register( L, AUXLIB_WIFI, wifi_map );
// Set it as its own metatable
lua_pushvalue( L, -1 );
lua_setmetatable( L, -2 );
// Module constants
// MOD_REG_NUMBER( L, "NULLMODE", NULL_MODE );
MOD_REG_NUMBER( L, "STATION", STATION_MODE );
MOD_REG_NUMBER( L, "SOFTAP", SOFTAP_MODE );
MOD_REG_NUMBER( L, "STATIONAP", STATIONAP_MODE );
MOD_REG_NUMBER( L, "NONE_SLEEP", NONE_SLEEP_T );
MOD_REG_NUMBER( L, "LIGHT_SLEEP", LIGHT_SLEEP_T );
MOD_REG_NUMBER( L, "MODEM_SLEEP", MODEM_SLEEP_T );
MOD_REG_NUMBER( L, "OPEN", AUTH_OPEN );
// MOD_REG_NUMBER( L, "WEP", AUTH_WEP );
MOD_REG_NUMBER( L, "WPA_PSK", AUTH_WPA_PSK );
MOD_REG_NUMBER( L, "WPA2_PSK", AUTH_WPA2_PSK );
MOD_REG_NUMBER( L, "WPA_WPA2_PSK", AUTH_WPA_WPA2_PSK );
// MOD_REG_NUMBER( L, "STA_IDLE", STATION_IDLE );
// MOD_REG_NUMBER( L, "STA_CONNECTING", STATION_CONNECTING );
// MOD_REG_NUMBER( L, "STA_WRONGPWD", STATION_WRONG_PASSWORD );
// MOD_REG_NUMBER( L, "STA_APNOTFOUND", STATION_NO_AP_FOUND );
// MOD_REG_NUMBER( L, "STA_FAIL", STATION_CONNECT_FAIL );
// MOD_REG_NUMBER( L, "STA_GOTIP", STATION_GOT_IP );
// Setup the new tables (station and ap) inside wifi
lua_newtable( L );
luaL_register( L, NULL, wifi_station_map );
lua_setfield( L, -2, "sta" );
lua_newtable( L );
luaL_register( L, NULL, wifi_ap_map );
lua_setfield( L, -2, "ap" );
// Setup the new table (dhcp) inside ap
lua_newtable( L );
luaL_register( L, NULL, wifi_ap_dhcp_map );
lua_setfield( L, -1, "dhcp" );
return 1;
#endif // #if LUA_OPTIMIZE_MEMORY > 0
}
NODEMCU_MODULE(WIFI, "wifi", wifi_map, NULL);

View File

@ -1,8 +1,6 @@
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_stdlib.h"
#include "c_string.h"
@ -124,17 +122,11 @@ static int ICACHE_FLASH_ATTR ws2801_writergb(lua_State* L) {
return 0;
}
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE ws2801_map[] =
static const LUA_REG_TYPE ws2801_map[] =
{
{ LSTRKEY( "write" ), LFUNCVAL( ws2801_writergb )},
{ LSTRKEY( "init" ), LFUNCVAL( ws2801_init_lua )},
{ LNILKEY, LNILVAL}
};
LUALIB_API int luaopen_ws2801(lua_State *L) {
LREGISTER(L, "ws2801", ws2801_map);
return 1;
}
NODEMCU_MODULE(WS2801, "ws2801", ws2801_map, NULL);

View File

@ -1,8 +1,6 @@
#include "lualib.h"
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_stdlib.h"
#include "c_string.h"
#include "user_interface.h"
@ -127,17 +125,16 @@ static int ICACHE_FLASH_ATTR ws2812_writegrb(lua_State* L) {
return 0;
}
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE ws2812_map[] =
static const LUA_REG_TYPE ws2812_map[] =
{
{ LSTRKEY( "writergb" ), LFUNCVAL( ws2812_writergb )},
{ LSTRKEY( "write" ), LFUNCVAL( ws2812_writegrb )},
{ LNILKEY, LNILVAL}
};
LUALIB_API int luaopen_ws2812(lua_State *L) {
int luaopen_ws2812(lua_State *L) {
// TODO: Make sure that the GPIO system is initialized
LREGISTER(L, "ws2812", ws2812_map);
return 1;
return 0;
}
NODEMCU_MODULE(WS2812, "ws2812", ws2812_map, luaopen_ws2812);

View File

@ -253,4 +253,20 @@ uint32_t platform_flash_mapped2phys (uint32_t mapped_addr);
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

View File

@ -79,6 +79,16 @@ SECTIONS
*(.rodata*)
*(.sdk.version)
/* Link-time arrays containing the defs for the included modules */
. = ALIGN(4);
lua_libs = ABSOLUTE(.);
/* Allow either empty define or defined-to-1 to include the module */
KEEP(*(.lua_libs))
LONG(0) LONG(0) /* Null-terminate the array */
lua_rotable = ABSOLUTE(.);
KEEP(*(.lua_rotable))
LONG(0) LONG(0) /* Null-terminate the array */
/* These are *only* pulled in by Lua, and therefore safe to put in flash */
*/libc.a:lib_a-isalnum.o(.text* .literal*)
*/libc.a:lib_a-isalpha.o(.text* .literal*)