Permalink
Browse files

add u8g module stubs

  • Loading branch information...
devsaurus committed Jan 29, 2015
1 parent 055c55a commit 33601462efdcea189f1f20f2cece66581ee57951
Showing with 114 additions and 1 deletion.
  1. +1 −0 app/include/user_config.h
  2. +1 −0 app/modules/Makefile
  3. +3 −0 app/modules/auxmods.h
  4. +10 −1 app/modules/modules.h
  5. +99 −0 app/modules/u8g.c
@@ -65,6 +65,7 @@
#define LUA_USE_MODULES_OW
#define LUA_USE_MODULES_BIT
#define LUA_USE_MODULES_MQTT
#define LUA_USE_MODULES_U8G
#endif /* LUA_USE_MODULES */
// #define LUA_NUMBER_INTEGRAL
View
@@ -40,6 +40,7 @@ INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
INCLUDES += -I ../libc
INCLUDES += -I ../mqtt
INCLUDES += -I ../u8g
INCLUDES += -I ../lua
INCLUDES += -I ../platform
INCLUDES += -I ../wofs
View
@@ -64,6 +64,9 @@ LUALIB_API int ( luaopen_wifi )( 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_NODE "node"
LUALIB_API int ( luaopen_node )( lua_State *L );
View
@@ -45,6 +45,14 @@
#define ROM_MODULES_MQTT
#endif
#if defined(LUA_USE_MODULES_U8G)
#define MODULES_U8G "u8g"
#define ROM_MODULES_U8G \
_ROM(MODULES_U8G, luaopen_u8g, u8g_map)
#else
#define ROM_MODULES_MQTT
#endif
#if defined(LUA_USE_MODULES_I2C)
#define MODULES_I2C "i2c"
#define ROM_MODULES_I2C \
@@ -121,7 +129,8 @@
ROM_MODULES_GPIO \
ROM_MODULES_PWM \
ROM_MODULES_WIFI \
ROM_MODULES_MQTT \
ROM_MODULES_MQTT \
ROM_MODULES_U8G \
ROM_MODULES_I2C \
ROM_MODULES_SPI \
ROM_MODULES_TMR \
View
@@ -0,0 +1,99 @@
// Module for U8glib
//#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "platform.h"
#include "auxmods.h"
#include "lrotable.h"
#include "c_string.h"
#include "c_stdlib.h"
#include "c_types.h"
#include "mem.h"
#include "espconn.h"
typedef struct lu8g_userdata
{
int some_data;
} lu8g_userdata_t;
static int lu8g_new( lua_State *L )
{
lu8g_userdata_t *userdata = (lu8g_userdata_t *) lua_newuserdata( L, sizeof( lu8g_userdata_t ) );
userdata->some_data = 100;
// set its metatable
luaL_getmetatable(L, "u8g.display");
lua_setmetatable(L, -2);
return 1;
}
// Lua: u8g.setup( self, id )
static int lu8g_setup( lua_State *L )
{
unsigned id = luaL_checkinteger( L, 2 );
//MOD_CHECK_ID( u8g, id );
if (id == 0)
return luaL_error( L, "ID 0 not supported!" );
return 0;
}
// Module function map
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
static const LUA_REG_TYPE u8g_display_map[] =
{
{ LSTRKEY( "setup" ), LFUNCVAL( lu8g_setup ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "__index" ), LROVAL ( u8g_display_map ) },
#endif
{ LNILKEY, LNILVAL }
};
const LUA_REG_TYPE u8g_map[] =
{
{ LSTRKEY( "new" ), LFUNCVAL ( lu8g_new ) },
#if LUA_OPTIMIZE_MEMORY > 0
{ LSTRKEY( "__metatable" ), LROVAL( u8g_map ) },
#endif
{ LNILKEY, LNILVAL }
};
LUALIB_API int ICACHE_FLASH_ATTR luaopen_u8g( lua_State *L )
{
#if LUA_OPTIMIZE_MEMORY > 0
luaL_rometatable(L, "u8g.display", (void *)u8g_display_map); // create metatable
return 0;
#else // #if LUA_OPTIMIZE_MEMORY > 0
int n;
luaL_register( L, AUXLIB_U8G, u8g_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, "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
}

0 comments on commit 3360146

Please sign in to comment.