Commit 1462d00e authored by Terry Ellison's avatar Terry Ellison
Browse files

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

Cleanup: LTR module registration
parents 4708b2ac 9003d3e8
// Module for U8glib // Module for U8glib
#include "lualib.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_stdlib.h" #include "c_stdlib.h"
...@@ -1027,11 +1025,7 @@ U8G_DISPLAY_TABLE_SPI ...@@ -1027,11 +1025,7 @@ U8G_DISPLAY_TABLE_SPI
// Module function map // Module function map
#define MIN_OPT_LEVEL 2 static const LUA_REG_TYPE lu8g_display_map[] = {
#include "lrodefs.h"
static const LUA_REG_TYPE lu8g_display_map[] =
{
{ LSTRKEY( "begin" ), LFUNCVAL( lu8g_begin ) }, { LSTRKEY( "begin" ), LFUNCVAL( lu8g_begin ) },
{ LSTRKEY( "drawBitmap" ), LFUNCVAL( lu8g_drawBitmap ) }, { LSTRKEY( "drawBitmap" ), LFUNCVAL( lu8g_drawBitmap ) },
{ LSTRKEY( "drawBox" ), LFUNCVAL( lu8g_drawBox ) }, { LSTRKEY( "drawBox" ), LFUNCVAL( lu8g_drawBox ) },
...@@ -1083,82 +1077,38 @@ static const LUA_REG_TYPE lu8g_display_map[] = ...@@ -1083,82 +1077,38 @@ static const LUA_REG_TYPE lu8g_display_map[] =
{ LSTRKEY( "undoRotation" ), LFUNCVAL( lu8g_undoRotation ) }, { LSTRKEY( "undoRotation" ), LFUNCVAL( lu8g_undoRotation ) },
{ LSTRKEY( "undoScale" ), LFUNCVAL( lu8g_undoScale ) }, { LSTRKEY( "undoScale" ), LFUNCVAL( lu8g_undoScale ) },
{ LSTRKEY( "__gc" ), LFUNCVAL( lu8g_close_display ) }, { LSTRKEY( "__gc" ), LFUNCVAL( lu8g_close_display ) },
#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( "__index" ), LROVAL( lu8g_display_map ) },
{ LSTRKEY( "__index" ), LROVAL ( lu8g_display_map ) },
#endif
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
const LUA_REG_TYPE lu8g_map[] =
{
#undef U8G_DISPLAY_TABLE_ENTRY #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_I2C
U8G_DISPLAY_TABLE_SPI U8G_DISPLAY_TABLE_SPI
// Register fonts
#if LUA_OPTIMIZE_MEMORY > 0 #define U8G_FONT_TABLE_ENTRY(font) \
{ LSTRKEY( #font ), LUDATA( (void *)(u8g_ ## font) ) },
// Register fonts
#undef U8G_FONT_TABLE_ENTRY
#define U8G_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(u8g_ ## font) ) },
U8G_FONT_TABLE U8G_FONT_TABLE
// Options for circle/ ellipse drawing // Options for circle/ ellipse drawing
{ LSTRKEY( "DRAW_UPPER_RIGHT" ), LNUMVAL( U8G_DRAW_UPPER_RIGHT ) }, { LSTRKEY( "DRAW_UPPER_RIGHT" ), LNUMVAL( U8G_DRAW_UPPER_RIGHT ) },
{ LSTRKEY( "DRAW_UPPER_LEFT" ), LNUMVAL( U8G_DRAW_UPPER_LEFT ) }, { LSTRKEY( "DRAW_UPPER_LEFT" ), LNUMVAL( U8G_DRAW_UPPER_LEFT ) },
{ LSTRKEY( "DRAW_LOWER_RIGHT" ), LNUMVAL( U8G_DRAW_LOWER_RIGHT ) }, { LSTRKEY( "DRAW_LOWER_RIGHT" ), LNUMVAL( U8G_DRAW_LOWER_RIGHT ) },
{ LSTRKEY( "DRAW_LOWER_LEFT" ), LNUMVAL( U8G_DRAW_LOWER_LEFT ) }, { LSTRKEY( "DRAW_LOWER_LEFT" ), LNUMVAL( U8G_DRAW_LOWER_LEFT ) },
{ LSTRKEY( "DRAW_ALL" ), LNUMVAL( U8G_DRAW_ALL ) }, { LSTRKEY( "DRAW_ALL" ), LNUMVAL( U8G_DRAW_ALL ) },
// Display modes // Display modes
{ LSTRKEY( "MODE_BW" ), LNUMVAL( U8G_MODE_BW ) }, { LSTRKEY( "MODE_BW" ), LNUMVAL( U8G_MODE_BW ) },
{ LSTRKEY( "MODE_GRAY2BIT" ), LNUMVAL( U8G_MODE_GRAY2BIT ) }, { LSTRKEY( "MODE_GRAY2BIT" ), LNUMVAL( U8G_MODE_GRAY2BIT ) },
{ LSTRKEY( "__metatable" ), LROVAL( lu8g_map ) }, { LSTRKEY( "__metatable" ), LROVAL( lu8g_map ) },
#endif
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
LUALIB_API int luaopen_u8g( lua_State *L ) int luaopen_u8g( lua_State *L ) {
{
#if LUA_OPTIMIZE_MEMORY > 0
luaL_rometatable(L, "u8g.display", (void *)lu8g_display_map); // create metatable luaL_rometatable(L, "u8g.display", (void *)lu8g_display_map); // create metatable
return 0; 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);
// Module for interfacing with serial // Module for interfacing with serial
//#include "lua.h" #include "module.h"
#include "lualib.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_types.h" #include "c_types.h"
#include "c_string.h" #include "c_string.h"
...@@ -158,29 +155,12 @@ static int uart_write( lua_State* L ) ...@@ -158,29 +155,12 @@ static int uart_write( lua_State* L )
} }
// Module function map // Module function map
#define MIN_OPT_LEVEL 2 static const LUA_REG_TYPE uart_map[] = {
#include "lrodefs.h"
const LUA_REG_TYPE uart_map[] =
{
{ LSTRKEY( "setup" ), LFUNCVAL( uart_setup ) }, { LSTRKEY( "setup" ), LFUNCVAL( uart_setup ) },
{ LSTRKEY( "write" ), LFUNCVAL( uart_write ) }, { LSTRKEY( "write" ), LFUNCVAL( uart_write ) },
{ LSTRKEY( "on" ), LFUNCVAL( uart_on ) }, { LSTRKEY( "on" ), LFUNCVAL( uart_on ) },
{ LSTRKEY( "alt" ), LFUNCVAL( uart_alt ) }, { LSTRKEY( "alt" ), LFUNCVAL( uart_alt ) },
#if LUA_OPTIMIZE_MEMORY > 0
#endif
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
LUALIB_API int luaopen_uart( lua_State *L ) NODEMCU_MODULE(UART, "uart", uart_map, NULL);
{
#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
}
// Module for Ucglib // Module for Ucglib
#include "lualib.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_stdlib.h" #include "c_stdlib.h"
...@@ -876,9 +874,6 @@ UCG_DISPLAY_TABLE ...@@ -876,9 +874,6 @@ UCG_DISPLAY_TABLE
// Module function map // Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
static const LUA_REG_TYPE lucg_display_map[] = static const LUA_REG_TYPE lucg_display_map[] =
{ {
{ LSTRKEY( "begin" ), LFUNCVAL( lucg_begin ) }, { LSTRKEY( "begin" ), LFUNCVAL( lucg_begin ) },
...@@ -926,20 +921,16 @@ static const LUA_REG_TYPE lucg_display_map[] = ...@@ -926,20 +921,16 @@ static const LUA_REG_TYPE lucg_display_map[] =
{ LSTRKEY( "undoScale" ), LFUNCVAL( lucg_undoScale ) }, { LSTRKEY( "undoScale" ), LFUNCVAL( lucg_undoScale ) },
{ LSTRKEY( "__gc" ), LFUNCVAL( lucg_close_display ) }, { LSTRKEY( "__gc" ), LFUNCVAL( lucg_close_display ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "__index" ), LROVAL ( lucg_display_map ) }, { LSTRKEY( "__index" ), LROVAL ( lucg_display_map ) },
#endif
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
const LUA_REG_TYPE lucg_map[] = static const LUA_REG_TYPE lucg_map[] =
{ {
#undef UCG_DISPLAY_TABLE_ENTRY #undef UCG_DISPLAY_TABLE_ENTRY
#define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension) { LSTRKEY( #binding ), LFUNCVAL ( lucg_ ##binding ) }, #define UCG_DISPLAY_TABLE_ENTRY(binding, device, extension) { LSTRKEY( #binding ), LFUNCVAL ( lucg_ ##binding ) },
UCG_DISPLAY_TABLE UCG_DISPLAY_TABLE
#if LUA_OPTIMIZE_MEMORY > 0
// Register fonts // Register fonts
#undef UCG_FONT_TABLE_ENTRY #undef UCG_FONT_TABLE_ENTRY
#define UCG_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(ucg_ ## font) ) }, #define UCG_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(ucg_ ## font) ) },
...@@ -957,50 +948,13 @@ const LUA_REG_TYPE lucg_map[] = ...@@ -957,50 +948,13 @@ const LUA_REG_TYPE lucg_map[] =
{ LSTRKEY( "DRAW_ALL" ), LNUMVAL( UCG_DRAW_ALL ) }, { LSTRKEY( "DRAW_ALL" ), LNUMVAL( UCG_DRAW_ALL ) },
{ LSTRKEY( "__metatable" ), LROVAL( lucg_map ) }, { LSTRKEY( "__metatable" ), LROVAL( lucg_map ) },
#endif
{ LNILKEY, LNILVAL } { 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 luaL_rometatable(L, "ucg.display", (void *)lucg_display_map); // create metatable
return 0; 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);
// Module for interfacing with WIFI // Module for interfacing with WIFI
//#include "lua.h" #include "module.h"
#include "lualib.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_string.h" #include "c_string.h"
#include "c_stdlib.h" #include "c_stdlib.h"
...@@ -1340,56 +1337,47 @@ static int wifi_ap_dhcp_stop( lua_State* L ) ...@@ -1340,56 +1337,47 @@ static int wifi_ap_dhcp_stop( lua_State* L )
} }
// Module function map // Module function map
#define MIN_OPT_LEVEL 2 static const LUA_REG_TYPE wifi_station_map[] = {
#include "lrodefs.h" { LSTRKEY( "getconfig" ), LFUNCVAL( wifi_station_getconfig ) },
static const LUA_REG_TYPE wifi_station_map[] = { LSTRKEY( "config" ), LFUNCVAL( wifi_station_config ) },
{ { LSTRKEY( "connect" ), LFUNCVAL( wifi_station_connect4lua ) },
{ LSTRKEY( "getconfig" ), LFUNCVAL ( wifi_station_getconfig ) }, { LSTRKEY( "disconnect" ), LFUNCVAL( wifi_station_disconnect4lua ) },
{ LSTRKEY( "config" ), LFUNCVAL ( wifi_station_config ) }, { LSTRKEY( "autoconnect" ), LFUNCVAL( wifi_station_setauto ) },
{ LSTRKEY( "connect" ), LFUNCVAL ( wifi_station_connect4lua ) }, { LSTRKEY( "getip" ), LFUNCVAL( wifi_station_getip ) },
{ LSTRKEY( "disconnect" ), LFUNCVAL ( wifi_station_disconnect4lua ) }, { LSTRKEY( "setip" ), LFUNCVAL( wifi_station_setip ) },
{ LSTRKEY( "autoconnect" ), LFUNCVAL ( wifi_station_setauto ) }, { LSTRKEY( "getbroadcast" ), LFUNCVAL( wifi_station_getbroadcast) },
{ LSTRKEY( "getip" ), LFUNCVAL ( wifi_station_getip ) }, { LSTRKEY( "getmac" ), LFUNCVAL( wifi_station_getmac ) },
{ LSTRKEY( "setip" ), LFUNCVAL ( wifi_station_setip ) }, { LSTRKEY( "setmac" ), LFUNCVAL( wifi_station_setmac ) },
{ LSTRKEY( "getbroadcast" ), LFUNCVAL ( wifi_station_getbroadcast) }, { LSTRKEY( "getap" ), LFUNCVAL( wifi_station_listap ) },
{ LSTRKEY( "getmac" ), LFUNCVAL ( wifi_station_getmac ) }, { LSTRKEY( "status" ), LFUNCVAL( wifi_station_status ) },
{ LSTRKEY( "setmac" ), LFUNCVAL ( wifi_station_setmac ) }, { LSTRKEY( "eventMonReg" ), LFUNCVAL( wifi_station_event_mon_reg ) },
{ LSTRKEY( "getap" ), LFUNCVAL ( wifi_station_listap ) }, { LSTRKEY( "eventMonStart" ), LFUNCVAL( wifi_station_event_mon_start ) },
{ LSTRKEY( "status" ), LFUNCVAL ( wifi_station_status ) }, { LSTRKEY( "eventMonStop" ), LFUNCVAL( wifi_station_event_mon_stop ) },
{ LSTRKEY( "eventMonReg" ), LFUNCVAL ( wifi_station_event_mon_reg ) },
{ LSTRKEY( "eventMonStart" ), LFUNCVAL ( wifi_station_event_mon_start ) },
{ LSTRKEY( "eventMonStop" ), LFUNCVAL ( wifi_station_event_mon_stop ) },
{ LNILKEY, LNILVAL } { 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( "config" ), LFUNCVAL( wifi_ap_dhcp_config ) },
{ LSTRKEY( "start" ), LFUNCVAL( wifi_ap_dhcp_start ) }, { LSTRKEY( "start" ), LFUNCVAL( wifi_ap_dhcp_start ) },
{ LSTRKEY( "stop" ), LFUNCVAL( wifi_ap_dhcp_stop ) }, { LSTRKEY( "stop" ), LFUNCVAL( wifi_ap_dhcp_stop ) },
{ LNILKEY, LNILVAL } { 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( "config" ), LFUNCVAL( wifi_ap_config ) },
{ LSTRKEY( "getip" ), LFUNCVAL ( wifi_ap_getip ) }, { LSTRKEY( "getip" ), LFUNCVAL( wifi_ap_getip ) },
{ LSTRKEY( "setip" ), LFUNCVAL ( wifi_ap_setip ) }, { LSTRKEY( "setip" ), LFUNCVAL( wifi_ap_setip ) },
{ LSTRKEY( "getbroadcast" ), LFUNCVAL ( wifi_ap_getbroadcast) }, { LSTRKEY( "getbroadcast" ), LFUNCVAL( wifi_ap_getbroadcast) },
{ LSTRKEY( "getmac" ), LFUNCVAL ( wifi_ap_getmac ) }, { LSTRKEY( "getmac" ), LFUNCVAL( wifi_ap_getmac ) },
{ LSTRKEY( "setmac" ), LFUNCVAL ( wifi_ap_setmac ) }, { LSTRKEY( "setmac" ), LFUNCVAL( wifi_ap_setmac ) },
{ LSTRKEY( "getclient" ), LFUNCVAL ( wifi_ap_listclient ) }, { LSTRKEY( "getclient" ), LFUNCVAL( wifi_ap_listclient ) },
{ LSTRKEY( "getconfig" ), LFUNCVAL( wifi_ap_getconfig ) }, { LSTRKEY( "getconfig" ), LFUNCVAL( wifi_ap_getconfig ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "dhcp" ), LROVAL( wifi_ap_dhcp_map ) }, { LSTRKEY( "dhcp" ), LROVAL( wifi_ap_dhcp_map ) },
//{ LSTRKEY( "__metatable" ), LROVAL( wifi_ap_map ) },
// { LSTRKEY( "__metatable" ), LROVAL( wifi_ap_map ) },
#endif
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
const LUA_REG_TYPE wifi_map[] = static const LUA_REG_TYPE wifi_map[] = {
{
{ LSTRKEY( "setmode" ), LFUNCVAL( wifi_setmode ) }, { LSTRKEY( "setmode" ), LFUNCVAL( wifi_setmode ) },
{ LSTRKEY( "getmode" ), LFUNCVAL( wifi_getmode ) }, { LSTRKEY( "getmode" ), LFUNCVAL( wifi_getmode ) },
{ LSTRKEY( "getchannel" ), LFUNCVAL( wifi_getchannel ) }, { LSTRKEY( "getchannel" ), LFUNCVAL( wifi_getchannel ) },
...@@ -1399,7 +1387,7 @@ const LUA_REG_TYPE wifi_map[] = ...@@ -1399,7 +1387,7 @@ const LUA_REG_TYPE wifi_map[] =
{ LSTRKEY( "startsmart" ), LFUNCVAL( wifi_start_smart ) }, { LSTRKEY( "startsmart" ), LFUNCVAL( wifi_start_smart ) },
{ LSTRKEY( "stopsmart" ), LFUNCVAL( wifi_exit_smart ) }, { LSTRKEY( "stopsmart" ), LFUNCVAL( wifi_exit_smart ) },
{ LSTRKEY( "sleeptype" ), LFUNCVAL( wifi_sleeptype ) }, { LSTRKEY( "sleeptype" ), LFUNCVAL( wifi_sleeptype ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "sta" ), LROVAL( wifi_station_map ) }, { LSTRKEY( "sta" ), LROVAL( wifi_station_map ) },
{ LSTRKEY( "ap" ), LROVAL( wifi_ap_map ) }, { LSTRKEY( "ap" ), LROVAL( wifi_ap_map ) },
...@@ -1417,7 +1405,7 @@ const LUA_REG_TYPE wifi_map[] = ...@@ -1417,7 +1405,7 @@ const LUA_REG_TYPE wifi_map[] =
{ LSTRKEY( "MODEM_SLEEP" ), LNUMVAL( MODEM_SLEEP_T ) }, { LSTRKEY( "MODEM_SLEEP" ), LNUMVAL( MODEM_SLEEP_T ) },
{ LSTRKEY( "OPEN" ), LNUMVAL( AUTH_OPEN ) }, { LSTRKEY( "OPEN" ), LNUMVAL( AUTH_OPEN ) },
// { LSTRKEY( "WEP" ), LNUMVAL( AUTH_WEP ) }, //{ LSTRKEY( "WEP" ), LNUMVAL( AUTH_WEP ) },
{ LSTRKEY( "WPA_PSK" ), LNUMVAL( AUTH_WPA_PSK ) }, { LSTRKEY( "WPA_PSK" ), LNUMVAL( AUTH_WPA_PSK ) },
{ LSTRKEY( "WPA2_PSK" ), LNUMVAL( AUTH_WPA2_PSK ) }, { LSTRKEY( "WPA2_PSK" ), LNUMVAL( AUTH_WPA2_PSK ) },
{ LSTRKEY( "WPA_WPA2_PSK" ), LNUMVAL( AUTH_WPA_WPA2_PSK ) }, { LSTRKEY( "WPA_WPA2_PSK" ), LNUMVAL( AUTH_WPA_WPA2_PSK ) },
...@@ -1430,58 +1418,7 @@ const LUA_REG_TYPE wifi_map[] = ...@@ -1430,58 +1418,7 @@ const LUA_REG_TYPE wifi_map[] =
{ LSTRKEY( "STA_GOTIP" ), LNUMVAL( STATION_GOT_IP ) }, { LSTRKEY( "STA_GOTIP" ), LNUMVAL( STATION_GOT_IP ) },
{ LSTRKEY( "__metatable" ), LROVAL( wifi_map ) }, { LSTRKEY( "__metatable" ), LROVAL( wifi_map ) },
#endif
{ LNILKEY, LNILVAL } { LNILKEY, LNILVAL }
}; };
LUALIB_API int luaopen_wifi( lua_State *L ) NODEMCU_MODULE(WIFI, "wifi", wifi_map, NULL);
{
#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
}
#include "lualib.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_stdlib.h" #include "c_stdlib.h"
#include "c_string.h" #include "c_string.h"
...@@ -124,17 +122,11 @@ static int ICACHE_FLASH_ATTR ws2801_writergb(lua_State* L) { ...@@ -124,17 +122,11 @@ static int ICACHE_FLASH_ATTR ws2801_writergb(lua_State* L) {
return 0; return 0;
} }
#define MIN_OPT_LEVEL 2 static const LUA_REG_TYPE ws2801_map[] =
#include "lrodefs.h"
const LUA_REG_TYPE ws2801_map[] =
{ {
{ LSTRKEY( "write" ), LFUNCVAL( ws2801_writergb )}, { LSTRKEY( "write" ), LFUNCVAL( ws2801_writergb )},
{ LSTRKEY( "init" ), LFUNCVAL( ws2801_init_lua )}, { LSTRKEY( "init" ), LFUNCVAL( ws2801_init_lua )},
{ LNILKEY, LNILVAL} { LNILKEY, LNILVAL}
}; };
LUALIB_API int luaopen_ws2801(lua_State *L) { NODEMCU_MODULE(WS2801, "ws2801", ws2801_map, NULL);
LREGISTER(L, "ws2801", ws2801_map);
return 1;
}
#include "lualib.h" #include "module.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "platform.h" #include "platform.h"
#include "auxmods.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"
...@@ -127,17 +125,16 @@ static int ICACHE_FLASH_ATTR ws2812_writegrb(lua_State* L) { ...@@ -127,17 +125,16 @@ static int ICACHE_FLASH_ATTR ws2812_writegrb(lua_State* L) {
return 0; return 0;
} }
#define MIN_OPT_LEVEL 2 static const LUA_REG_TYPE ws2812_map[] =
#include "lrodefs.h"
const LUA_REG_TYPE ws2812_map[] =
{ {
{ LSTRKEY( "writergb" ), LFUNCVAL( ws2812_writergb )}, { LSTRKEY( "writergb" ), LFUNCVAL( ws2812_writergb )},
{ LSTRKEY( "write" ), LFUNCVAL( ws2812_writegrb )}, { LSTRKEY( "write" ), LFUNCVAL( ws2812_writegrb )},
{ LNILKEY, LNILVAL} { 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 // TODO: Make sure that the GPIO system is initialized
LREGISTER(L, "ws2812", ws2812_map); return 0;
return 1;
} }
NODEMCU_MODULE(WS2812, "ws2812", ws2812_map, luaopen_ws2812);
...@@ -253,4 +253,20 @@ uint32_t platform_flash_mapped2phys (uint32_t mapped_addr); ...@@ -253,4 +253,20 @@ uint32_t platform_flash_mapped2phys (uint32_t mapped_addr);
void* platform_get_first_free_ram( unsigned id ); void* platform_get_first_free_ram( unsigned id );
void* platform_get_last_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 #endif
...@@ -79,6 +79,16 @@ SECTIONS ...@@ -79,6 +79,16 @@ SECTIONS
*(.rodata*) *(.rodata*)
*(.sdk.version) *(.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 */ /* 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-isalnum.o(.text* .literal*)
*/libc.a:lib_a-isalpha.o(.text* .literal*) */libc.a:lib_a-isalpha.o(.text* .literal*)
......
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