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,138 +1025,90 @@ U8G_DISPLAY_TABLE_SPI ...@@ -1027,138 +1025,90 @@ 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" { LSTRKEY( "begin" ), LFUNCVAL( lu8g_begin ) },
{ LSTRKEY( "drawBitmap" ), LFUNCVAL( lu8g_drawBitmap ) },
static const LUA_REG_TYPE lu8g_display_map[] = { LSTRKEY( "drawBox" ), LFUNCVAL( lu8g_drawBox ) },
{ { LSTRKEY( "drawCircle" ), LFUNCVAL( lu8g_drawCircle ) },
{ LSTRKEY( "begin" ), LFUNCVAL( lu8g_begin ) }, { LSTRKEY( "drawDisc" ), LFUNCVAL( lu8g_drawDisc ) },
{ LSTRKEY( "drawBitmap" ), LFUNCVAL( lu8g_drawBitmap ) }, { LSTRKEY( "drawEllipse" ), LFUNCVAL( lu8g_drawEllipse ) },
{ LSTRKEY( "drawBox" ), LFUNCVAL( lu8g_drawBox ) }, { LSTRKEY( "drawFilledEllipse" ), LFUNCVAL( lu8g_drawFilledEllipse ) },
{ LSTRKEY( "drawCircle" ), LFUNCVAL( lu8g_drawCircle ) }, { LSTRKEY( "drawFrame" ), LFUNCVAL( lu8g_drawFrame ) },
{ LSTRKEY( "drawDisc" ), LFUNCVAL( lu8g_drawDisc ) }, { LSTRKEY( "drawHLine" ), LFUNCVAL( lu8g_drawHLine ) },
{ LSTRKEY( "drawEllipse" ), LFUNCVAL( lu8g_drawEllipse ) }, { LSTRKEY( "drawLine" ), LFUNCVAL( lu8g_drawLine ) },
{ LSTRKEY( "drawFilledEllipse" ), LFUNCVAL( lu8g_drawFilledEllipse ) }, { LSTRKEY( "drawPixel" ), LFUNCVAL( lu8g_drawPixel ) },
{ LSTRKEY( "drawFrame" ), LFUNCVAL( lu8g_drawFrame ) }, { LSTRKEY( "drawRBox" ), LFUNCVAL( lu8g_drawRBox ) },
{ LSTRKEY( "drawHLine" ), LFUNCVAL( lu8g_drawHLine ) }, { LSTRKEY( "drawRFrame" ), LFUNCVAL( lu8g_drawRFrame ) },
{ LSTRKEY( "drawLine" ), LFUNCVAL( lu8g_drawLine ) }, { LSTRKEY( "drawStr" ), LFUNCVAL( lu8g_drawStr ) },
{ LSTRKEY( "drawPixel" ), LFUNCVAL( lu8g_drawPixel ) }, { LSTRKEY( "drawStr90" ), LFUNCVAL( lu8g_drawStr90 ) },
{ LSTRKEY( "drawRBox" ), LFUNCVAL( lu8g_drawRBox ) }, { LSTRKEY( "drawStr180" ), LFUNCVAL( lu8g_drawStr180 ) },
{ LSTRKEY( "drawRFrame" ), LFUNCVAL( lu8g_drawRFrame ) }, { LSTRKEY( "drawStr270" ), LFUNCVAL( lu8g_drawStr270 ) },
{ LSTRKEY( "drawStr" ), LFUNCVAL( lu8g_drawStr ) }, { LSTRKEY( "drawTriangle" ), LFUNCVAL( lu8g_drawTriangle ) },
{ LSTRKEY( "drawStr90" ), LFUNCVAL( lu8g_drawStr90 ) }, { LSTRKEY( "drawVLine" ), LFUNCVAL( lu8g_drawVLine ) },
{ LSTRKEY( "drawStr180" ), LFUNCVAL( lu8g_drawStr180 ) }, { LSTRKEY( "drawXBM" ), LFUNCVAL( lu8g_drawXBM ) },
{ LSTRKEY( "drawStr270" ), LFUNCVAL( lu8g_drawStr270 ) }, { LSTRKEY( "firstPage" ), LFUNCVAL( lu8g_firstPage ) },
{ LSTRKEY( "drawTriangle" ), LFUNCVAL( lu8g_drawTriangle ) }, { LSTRKEY( "getColorIndex" ), LFUNCVAL( lu8g_getColorIndex ) },
{ LSTRKEY( "drawVLine" ), LFUNCVAL( lu8g_drawVLine ) }, { LSTRKEY( "getFontAscent" ), LFUNCVAL( lu8g_getFontAscent ) },
{ LSTRKEY( "drawXBM" ), LFUNCVAL( lu8g_drawXBM ) }, { LSTRKEY( "getFontDescent" ), LFUNCVAL( lu8g_getFontDescent ) },
{ LSTRKEY( "firstPage" ), LFUNCVAL( lu8g_firstPage ) }, { LSTRKEY( "getFontLineSpacing" ), LFUNCVAL( lu8g_getFontLineSpacing ) },
{ LSTRKEY( "getColorIndex" ), LFUNCVAL( lu8g_getColorIndex ) }, { LSTRKEY( "getHeight" ), LFUNCVAL( lu8g_getHeight ) },
{ LSTRKEY( "getFontAscent" ), LFUNCVAL( lu8g_getFontAscent ) }, { LSTRKEY( "getMode" ), LFUNCVAL( lu8g_getMode ) },
{ LSTRKEY( "getFontDescent" ), LFUNCVAL( lu8g_getFontDescent ) }, { LSTRKEY( "getStrWidth" ), LFUNCVAL( lu8g_getStrWidth ) },
{ LSTRKEY( "getFontLineSpacing" ), LFUNCVAL( lu8g_getFontLineSpacing ) }, { LSTRKEY( "getWidth" ), LFUNCVAL( lu8g_getWidth ) },
{ LSTRKEY( "getHeight" ), LFUNCVAL( lu8g_getHeight ) }, { LSTRKEY( "nextPage" ), LFUNCVAL( lu8g_nextPage ) },
{ LSTRKEY( "getMode" ), LFUNCVAL( lu8g_getMode ) }, { LSTRKEY( "setColorIndex" ), LFUNCVAL( lu8g_setColorIndex ) },
{ LSTRKEY( "getStrWidth" ), LFUNCVAL( lu8g_getStrWidth ) }, { LSTRKEY( "setDefaultBackgroundColor" ), LFUNCVAL( lu8g_setDefaultBackgroundColor ) },
{ LSTRKEY( "getWidth" ), LFUNCVAL( lu8g_getWidth ) }, { LSTRKEY( "setDefaultForegroundColor" ), LFUNCVAL( lu8g_setDefaultForegroundColor ) },
{ LSTRKEY( "nextPage" ), LFUNCVAL( lu8g_nextPage ) }, { LSTRKEY( "setFont" ), LFUNCVAL( lu8g_setFont ) },
{ LSTRKEY( "setColorIndex" ), LFUNCVAL( lu8g_setColorIndex ) }, { LSTRKEY( "setFontLineSpacingFactor" ), LFUNCVAL( lu8g_setFontLineSpacingFactor ) },
{ LSTRKEY( "setDefaultBackgroundColor" ), LFUNCVAL( lu8g_setDefaultBackgroundColor ) }, { LSTRKEY( "setFontPosBaseline" ), LFUNCVAL( lu8g_setFontPosBaseline ) },
{ LSTRKEY( "setDefaultForegroundColor" ), LFUNCVAL( lu8g_setDefaultForegroundColor ) }, { LSTRKEY( "setFontPosBottom" ), LFUNCVAL( lu8g_setFontPosBottom ) },
{ LSTRKEY( "setFont" ), LFUNCVAL( lu8g_setFont ) }, { LSTRKEY( "setFontPosCenter" ), LFUNCVAL( lu8g_setFontPosCenter ) },
{ LSTRKEY( "setFontLineSpacingFactor" ), LFUNCVAL( lu8g_setFontLineSpacingFactor ) }, { LSTRKEY( "setFontPosTop" ), LFUNCVAL( lu8g_setFontPosTop ) },
{ LSTRKEY( "setFontPosBaseline" ), LFUNCVAL( lu8g_setFontPosBaseline ) }, { LSTRKEY( "setFontRefHeightAll" ), LFUNCVAL( lu8g_setFontRefHeightAll ) },
{ LSTRKEY( "setFontPosBottom" ), LFUNCVAL( lu8g_setFontPosBottom ) }, { LSTRKEY( "setFontRefHeightExtendedText" ), LFUNCVAL( lu8g_setFontRefHeightExtendedText ) },
{ LSTRKEY( "setFontPosCenter" ), LFUNCVAL( lu8g_setFontPosCenter ) }, { LSTRKEY( "setFontRefHeightText" ), LFUNCVAL( lu8g_setFontRefHeightText ) },
{ LSTRKEY( "setFontPosTop" ), LFUNCVAL( lu8g_setFontPosTop ) }, { LSTRKEY( "setRot90" ), LFUNCVAL( lu8g_setRot90 ) },
{ LSTRKEY( "setFontRefHeightAll" ), LFUNCVAL( lu8g_setFontRefHeightAll ) }, { LSTRKEY( "setRot180" ), LFUNCVAL( lu8g_setRot180 ) },
{ LSTRKEY( "setFontRefHeightExtendedText" ), LFUNCVAL( lu8g_setFontRefHeightExtendedText ) }, { LSTRKEY( "setRot270" ), LFUNCVAL( lu8g_setRot270 ) },
{ LSTRKEY( "setFontRefHeightText" ), LFUNCVAL( lu8g_setFontRefHeightText ) }, { LSTRKEY( "setScale2x2" ), LFUNCVAL( lu8g_setScale2x2 ) },
{ LSTRKEY( "setRot90" ), LFUNCVAL( lu8g_setRot90 ) }, { LSTRKEY( "sleepOff" ), LFUNCVAL( lu8g_sleepOff ) },
{ LSTRKEY( "setRot180" ), LFUNCVAL( lu8g_setRot180 ) }, { LSTRKEY( "sleepOn" ), LFUNCVAL( lu8g_sleepOn ) },
{ LSTRKEY( "setRot270" ), LFUNCVAL( lu8g_setRot270 ) }, { LSTRKEY( "undoRotation" ), LFUNCVAL( lu8g_undoRotation ) },
{ LSTRKEY( "setScale2x2" ), LFUNCVAL( lu8g_setScale2x2 ) }, { LSTRKEY( "undoScale" ), LFUNCVAL( lu8g_undoScale ) },
{ LSTRKEY( "sleepOff" ), LFUNCVAL( lu8g_sleepOff ) }, { LSTRKEY( "__gc" ), LFUNCVAL( lu8g_close_display ) },
{ LSTRKEY( "sleepOn" ), LFUNCVAL( lu8g_sleepOn ) }, { LSTRKEY( "__index" ), LROVAL( lu8g_display_map ) },
{ LSTRKEY( "undoRotation" ), LFUNCVAL( lu8g_undoRotation ) }, { LNILKEY, LNILVAL }
{ 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 #undef U8G_DISPLAY_TABLE_ENTRY
#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 #undef U8G_FONT_TABLE_ENTRY
#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 ) static const LUA_REG_TYPE lu8g_map[] = {
{ #define U8G_DISPLAY_TABLE_ENTRY(device) \
#if LUA_OPTIMIZE_MEMORY > 0 { LSTRKEY( #device ), LFUNCVAL ( lu8g_ ##device ) },
luaL_rometatable(L, "u8g.display", (void *)lu8g_display_map); // create metatable U8G_DISPLAY_TABLE_I2C
return 0; U8G_DISPLAY_TABLE_SPI
#else // #if LUA_OPTIMIZE_MEMORY > 0 // Register fonts
int n; #define U8G_FONT_TABLE_ENTRY(font) \
luaL_register( L, AUXLIB_U8G, lu8g_map ); { LSTRKEY( #font ), LUDATA( (void *)(u8g_ ## font) ) },
U8G_FONT_TABLE
// Set it as its own metatable // Options for circle/ ellipse drawing
lua_pushvalue( L, -1 ); { LSTRKEY( "DRAW_UPPER_RIGHT" ), LNUMVAL( U8G_DRAW_UPPER_RIGHT ) },
lua_setmetatable( L, -2 ); { LSTRKEY( "DRAW_UPPER_LEFT" ), LNUMVAL( U8G_DRAW_UPPER_LEFT ) },
{ LSTRKEY( "DRAW_LOWER_RIGHT" ), LNUMVAL( U8G_DRAW_LOWER_RIGHT ) },
// Module constants { LSTRKEY( "DRAW_LOWER_LEFT" ), LNUMVAL( U8G_DRAW_LOWER_LEFT ) },
{ LSTRKEY( "DRAW_ALL" ), LNUMVAL( U8G_DRAW_ALL ) },
// Register fonts // Display modes
#undef U8G_FONT_TABLE_ENTRY { LSTRKEY( "MODE_BW" ), LNUMVAL( U8G_MODE_BW ) },
#define U8G_FONT_TABLE_ENTRY(font) MOD_REG_LUDATA( L, #font, (void *)(u8g_ ## font) ); { LSTRKEY( "MODE_GRAY2BIT" ), LNUMVAL( U8G_MODE_GRAY2BIT ) },
U8G_FONT_TABLE { LSTRKEY( "__metatable" ), LROVAL( lu8g_map ) },
{ LNILKEY, LNILVAL }
// 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; int luaopen_u8g( lua_State *L ) {
#endif // #if LUA_OPTIMIZE_MEMORY > 0 luaL_rometatable(L, "u8g.display", (void *)lu8g_display_map); // create metatable
return 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,148 +1337,88 @@ static int wifi_ap_dhcp_stop( lua_State* L ) ...@@ -1340,148 +1337,88 @@ 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 ) }, { LSTRKEY( "dhcp" ), LROVAL( wifi_ap_dhcp_map ) },
#if LUA_OPTIMIZE_MEMORY > 0 //{ LSTRKEY( "__metatable" ), LROVAL( wifi_ap_map ) },
{ LSTRKEY( "dhcp" ), LROVAL( wifi_ap_dhcp_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 ) }, { LSTRKEY( "setphymode" ), LFUNCVAL( wifi_setphymode ) },
{ LSTRKEY( "setphymode" ), LFUNCVAL( wifi_setphymode ) }, { LSTRKEY( "getphymode" ), LFUNCVAL( wifi_getphymode ) },
{ LSTRKEY( "getphymode" ), LFUNCVAL( wifi_getphymode ) }, { LSTRKEY( "sleep" ), LFUNCVAL( wifi_sleep ) },
{ LSTRKEY( "sleep" ), LFUNCVAL( wifi_sleep ) }, { 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 ) },
{ LSTRKEY( "NULLMODE" ), LNUMVAL( NULL_MODE ) },
{ LSTRKEY( "NULLMODE" ), LNUMVAL( NULL_MODE ) }, { LSTRKEY( "STATION" ), LNUMVAL( STATION_MODE ) },
{ LSTRKEY( "STATION" ), LNUMVAL( STATION_MODE ) }, { LSTRKEY( "SOFTAP" ), LNUMVAL( SOFTAP_MODE ) },
{ LSTRKEY( "SOFTAP" ), LNUMVAL( SOFTAP_MODE ) }, { LSTRKEY( "STATIONAP" ), LNUMVAL( STATIONAP_MODE ) },
{ LSTRKEY( "STATIONAP" ), LNUMVAL( STATIONAP_MODE ) },
{ LSTRKEY( "PHYMODE_B" ), LNUMVAL( PHY_MODE_11B ) },
{ LSTRKEY( "PHYMODE_B" ), LNUMVAL( PHY_MODE_11B ) }, { LSTRKEY( "PHYMODE_G" ), LNUMVAL( PHY_MODE_11G ) },
{ LSTRKEY( "PHYMODE_G" ), LNUMVAL( PHY_MODE_11G ) }, { LSTRKEY( "PHYMODE_N" ), LNUMVAL( PHY_MODE_11N ) },
{ LSTRKEY( "PHYMODE_N" ), LNUMVAL( PHY_MODE_11N ) },
{ LSTRKEY( "NONE_SLEEP" ), LNUMVAL( NONE_SLEEP_T ) },
{ LSTRKEY( "NONE_SLEEP" ), LNUMVAL( NONE_SLEEP_T ) }, { LSTRKEY( "LIGHT_SLEEP" ), LNUMVAL( LIGHT_SLEEP_T ) },
{ LSTRKEY( "LIGHT_SLEEP" ), LNUMVAL( LIGHT_SLEEP_T ) }, { 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 ) },
{ LSTRKEY( "STA_IDLE" ), LNUMVAL( STATION_IDLE ) },
{ LSTRKEY( "STA_IDLE" ), LNUMVAL( STATION_IDLE ) }, { LSTRKEY( "STA_CONNECTING" ), LNUMVAL( STATION_CONNECTING ) },
{ LSTRKEY( "STA_CONNECTING" ), LNUMVAL( STATION_CONNECTING ) }, { LSTRKEY( "STA_WRONGPWD" ), LNUMVAL( STATION_WRONG_PASSWORD ) },
{ LSTRKEY( "STA_WRONGPWD" ), LNUMVAL( STATION_WRONG_PASSWORD ) }, { LSTRKEY( "STA_APNOTFOUND" ), LNUMVAL( STATION_NO_AP_FOUND ) },
{ LSTRKEY( "STA_APNOTFOUND" ), LNUMVAL( STATION_NO_AP_FOUND ) }, { LSTRKEY( "STA_FAIL" ), LNUMVAL( STATION_CONNECT_FAIL ) },
{ LSTRKEY( "STA_FAIL" ), LNUMVAL( STATION_CONNECT_FAIL ) }, { 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