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

Major cleanup of module registration.

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

With this change modules/auxmods.h no longer needs to be updated for
every new module, nor do module writers need to cater for a hypothetical
LUA_OPTIMIZE_MEMORY < 2 scenario.
parent 68eadaaf
// Module for HX711 load cell amplifier
// https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
#include "c_stdlib.h"
#include "c_string.h"
#include "user_interface.h"
......@@ -67,8 +66,6 @@ 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[] =
{
{ LSTRKEY( "init" ), LFUNCVAL( hx711_init )},
......@@ -77,8 +74,6 @@ const LUA_REG_TYPE hx711_map[] =
};
LUALIB_API int luaopen_hx711(lua_State *L) {
// TODO: the below todo was inherited from the ws2812 code but is still valid.
// TODO: Make sure that the GPIO system is initialized
LREGISTER(L, "hx711", hx711_map);
return 1;
return 0;
}
// Module for interfacing with the I2C interface
//#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
// Lua: speed = i2c.setup( id, sda, scl, speed )
static int i2c_setup( lua_State *L )
......@@ -143,8 +141,6 @@ static int i2c_read( lua_State *L )
}
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE i2c_map[] =
{
{ LSTRKEY( "setup" ), LFUNCVAL( i2c_setup ) },
......@@ -153,29 +149,15 @@ const LUA_REG_TYPE i2c_map[] =
{ 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
}
// Module for mqtt
//#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
#include "c_string.h"
#include "c_stdlib.h"
......@@ -1392,9 +1390,6 @@ 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[] =
{
{ LSTRKEY( "connect" ), LFUNCVAL ( mqtt_socket_connect ) },
......@@ -1404,47 +1399,19 @@ 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[] =
{
{ 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 )
{
#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
}
// Module for network
//#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
#include "c_string.h"
#include "c_stdlib.h"
......@@ -1508,8 +1506,6 @@ 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[] =
{
{ LSTRKEY( "listen" ), LFUNCVAL ( net_server_listen ) },
......@@ -1518,9 +1514,7 @@ static const LUA_REG_TYPE net_server_map[] =
{ 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 }
};
......@@ -1536,9 +1530,7 @@ 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
......@@ -1564,13 +1556,11 @@ const LUA_REG_TYPE net_map[] =
{ 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 }
};
......@@ -1582,58 +1572,10 @@ LUALIB_API int luaopen_net( lua_State *L )
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
}
// Module for interfacing with system
#include "lua.h"
#include "lauxlib.h"
#include "ldebug.h"
......@@ -15,14 +14,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,8 +547,6 @@ 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[] =
{
{ LSTRKEY( "restart" ), LFUNCVAL( node_restart ) },
......@@ -581,20 +576,10 @@ 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
}
// Module for interfacing with the OneWire interface
//#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
#include "driver/onewire.h"
// Lua: ow.setup( id )
......@@ -282,8 +280,6 @@ 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[] =
{
{ LSTRKEY( "setup" ), LFUNCVAL( ow_setup ) },
......@@ -306,22 +302,11 @@ 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
}
// Module for interfacing with PWM
//#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
#include "c_types.h"
......@@ -125,8 +123,6 @@ static int lpwm_getduty( lua_State* L )
}
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE pwm_map[] =
{
{ LSTRKEY( "setup" ), LFUNCVAL( lpwm_setup ) },
......@@ -137,18 +133,10 @@ 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
}
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
//#include "driver/easygpio.h"
//static Ping_Data pingA;
#define defPulseLen 185
......@@ -80,8 +78,7 @@ 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[] =
{
{ LSTRKEY( "send" ), LFUNCVAL( rc_send )},
......@@ -91,6 +88,5 @@ const LUA_REG_TYPE rc_map[] =
//LUALIB_API int luaopen_ultra(lua_State *L) {
LUALIB_API int luaopen_rc(lua_State *L) {
// TODO: Make sure that the GPIO system is initialized
LREGISTER(L, "rc", rc_map);
return 1;
return 0;
}
// Module for RTC sample FIFO storage
#include "lauxlib.h"
#include "lrodefs.h"
#include "user_modules.h"
#include "rtc/rtctime.h"
#define RTCTIME_SLEEP_ALIGNED rtctime_deep_sleep_until_aligned_us
......@@ -164,8 +165,6 @@ 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[] =
{
{ LSTRKEY("prepare"), LFUNCVAL(rtcfifo_prepare) },
......@@ -183,10 +182,5 @@ const LUA_REG_TYPE rtcfifo_map[] =
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
}
// Module for RTC user memory access
#include "lauxlib.h"
#include "lrodefs.h"
#include "rtc/rtcaccess.h"
static int rtcmem_read32 (lua_State *L)
......@@ -40,8 +41,6 @@ static int rtcmem_write32 (lua_State *L)
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE rtcmem_map[] =
{
{ LSTRKEY("read32"), LFUNCVAL(rtcmem_read32) },
......@@ -51,10 +50,5 @@ const LUA_REG_TYPE rtcmem_map[] =
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
}
// Module for RTC time keeping
#include "lauxlib.h"
#include "lrodefs.h"
#include "rtc/rtctime_internal.h"
#include "rtc/rtctime.h"
......@@ -115,8 +116,6 @@ 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[] =
{
{ LSTRKEY("set"), LFUNCVAL(rtctime_set) },
......@@ -128,10 +127,5 @@ const LUA_REG_TYPE rtctime_map[] =
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
}
......@@ -34,6 +34,7 @@
// Module for Simple Network Time Protocol (SNTP)
#include "lauxlib.h"
#include "lrodefs.h"
#include "os_type.h"
#include "osapi.h"
#include "lwip/udp.h"
......@@ -375,8 +376,6 @@ error:
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE sntp_map[] =
{
{ LSTRKEY("sync"), LFUNCVAL(sntp_sync) },
......@@ -385,10 +384,5 @@ const LUA_REG_TYPE sntp_map[] =
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
}
// Module for interfacing with the SPI interface
//#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
#define SPI_HALFDUPLEX 0
#define SPI_FULLDUPLEX 1
......@@ -309,8 +307,6 @@ static int spi_transaction( lua_State *L )
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const LUA_REG_TYPE spi_map[] =
{
{ LSTRKEY( "setup" ), LFUNCVAL( spi_setup ) },
......@@ -319,7 +315,6 @@ const LUA_REG_TYPE spi_map[] =
{ 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) },
......@@ -329,28 +324,10 @@ 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
}
......@@ -48,13 +48,9 @@ tmr.softwd(int)
the timer units are seconds
*/
#define MIN_OPT_LEVEL 2
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
#include "c_types.h"
......@@ -324,11 +320,9 @@ 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 }
};
......@@ -344,16 +338,6 @@ LUALIB_API int luaopen_tmr( lua_State *L ){
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
}
......@@ -4,11 +4,9 @@
* Created on: Aug 21, 2015
* Author: Michael Lucas (Aeprox @github)
*/
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
#include "../tsl2561/tsl2561.h"
static uint16_t ch0;
......@@ -102,8 +100,6 @@ 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[] =
{
{ LSTRKEY( "settiming" ), LFUNCVAL( tsl2561_lua_settiming)},
......@@ -134,6 +130,5 @@ const LUA_REG_TYPE tsl2561_map[] =
};
LUALIB_API int luaopen_tsl2561(lua_State *L) {
LREGISTER(L, "tsl2561", tsl2561_map);
return 1;
return 0;
}
// Module for U8glib
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
#include "c_stdlib.h"
......@@ -1027,9 +1025,6 @@ U8G_DISPLAY_TABLE_SPI
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
static const LUA_REG_TYPE lu8g_display_map[] =
{
{ LSTRKEY( "begin" ), LFUNCVAL( lu8g_begin ) },
......@@ -1083,9 +1078,7 @@ 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 }
};
......@@ -1096,8 +1089,6 @@ const LUA_REG_TYPE lu8g_map[] =
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) ) },
......@@ -1115,50 +1106,11 @@ const LUA_REG_TYPE lu8g_map[] =
{ 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
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
}
// Module for interfacing with serial
//#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
#include "c_types.h"
#include "c_string.h"
......@@ -158,29 +156,16 @@ static int uart_write( lua_State* L )
}
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
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
}
// Module for Ucglib
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.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,9 +921,7 @@ 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 }
};
......@@ -938,8 +931,6 @@ const LUA_REG_TYPE lucg_map[] =
#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,11 @@ 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 )
{
#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
}
// Module for interfacing with WIFI
//#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
#include "c_string.h"
#include "c_stdlib.h"
......@@ -1340,8 +1337,6 @@ 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[] =
{
{ LSTRKEY( "getconfig" ), LFUNCVAL ( wifi_station_getconfig ) },
......@@ -1380,11 +1375,9 @@ 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 }
};
......@@ -1399,7 +1392,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 +1423,10 @@ 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
}
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "lrodefs.h"
#include "c_stdlib.h"
#include "c_string.h"
......@@ -124,8 +122,6 @@ 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[] =
{
{ LSTRKEY( "write" ), LFUNCVAL( ws2801_writergb )},
......@@ -134,7 +130,6 @@ const LUA_REG_TYPE ws2801_map[] =
};
LUALIB_API int luaopen_ws2801(lua_State *L) {
LREGISTER(L, "ws2801", ws2801_map);
return 1;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment