diff --git a/app/lua/lrodefs.h b/app/lua/lrodefs.h index fb6fabfb..384be3ee 100644 --- a/app/lua/lrodefs.h +++ b/app/lua/lrodefs.h @@ -21,6 +21,7 @@ #define LNUMKEY LRO_NUMKEY #define LNILKEY LRO_NILKEY #define LFUNCVAL LRO_FUNCVAL +#define LUDATA LRO_LUDATA #define LNUMVAL LRO_NUMVAL #define LROVAL LRO_ROVAL #define LNILVAL LRO_NILVAL diff --git a/app/lua/lrotable.h b/app/lua/lrotable.h index 27de84a0..e8963e3b 100644 --- a/app/lua/lrotable.h +++ b/app/lua/lrotable.h @@ -11,6 +11,7 @@ /* Macros one can use to define rotable entries */ #ifndef LUA_PACK_VALUE #define LRO_FUNCVAL(v) {{.p = v}, LUA_TLIGHTFUNCTION} +#define LRO_LUDATA(v) {{.p = v}, LUA_TLIGHTUSERDATA} #define LRO_NUMVAL(v) {{.n = v}, LUA_TNUMBER} #define LRO_ROVAL(v) {{.p = (void*)v}, LUA_TROTABLE} #define LRO_NILVAL {{.p = NULL}, LUA_TNIL} @@ -18,10 +19,12 @@ #define LRO_NUMVAL(v) {.value.n = v} #ifdef ELUA_ENDIAN_LITTLE #define LRO_FUNCVAL(v) {{(int)v, add_sig(LUA_TLIGHTFUNCTION)}} +#define LRO_LUDATA(v) {{(int)v, add_sig(LUA_TLIGHTUSERDATA)}} #define LRO_ROVAL(v) {{(int)v, add_sig(LUA_TROTABLE)}} #define LRO_NILVAL {{0, add_sig(LUA_TNIL)}} #else // #ifdef ELUA_ENDIAN_LITTLE #define LRO_FUNCVAL(v) {{add_sig(LUA_TLIGHTFUNCTION), (int)v}} +#define LRO_LUDATA(v) {{add_sig(LUA_TLIGHTUSERDATA), (int)v}} #define LRO_ROVAL(v) {{add_sig(LUA_TROTABLE), (int)v}} #define LRO_NILVAL {{add_sig(LUA_TNIL), 0}} #endif // #ifdef ELUA_ENDIAN_LITTLE diff --git a/app/modules/auxmods.h b/app/modules/auxmods.h index 1823d300..175a1f2b 100644 --- a/app/modules/auxmods.h +++ b/app/modules/auxmods.h @@ -95,5 +95,9 @@ LUALIB_API int ( luaopen_ow )( lua_State *L ); 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 diff --git a/app/modules/u8g.c b/app/modules/u8g.c index 0fb26fd3..3595bf18 100644 --- a/app/modules/u8g.c +++ b/app/modules/u8g.c @@ -26,13 +26,13 @@ typedef struct _lu8g_userdata_t lu8g_userdata_t; // Font look-up array -static const u8g_fntpgm_uint8_t *font_array[] = -{ -#undef U8G_FONT_TABLE_ENTRY -#define U8G_FONT_TABLE_ENTRY(font) u8g_ ## font , - U8G_FONT_TABLE - NULL -}; +//static const u8g_fntpgm_uint8_t *font_array[] = +//{ +//#undef U8G_FONT_TABLE_ENTRY +//#define U8G_FONT_TABLE_ENTRY(font) u8g_ ## font , +// U8G_FONT_TABLE +// NULL +//}; static uint32_t *u8g_pgm_cached_iadr = NULL; @@ -102,9 +102,9 @@ static int lu8g_setFont( lua_State *L ) if ((lud = get_lud( L )) == NULL) return 0; - lua_Integer fontnr = luaL_checkinteger( L, 2 ); - if ((fontnr >= 0) && (fontnr < (sizeof( font_array ) / sizeof( u8g_fntpgm_uint8_t )))) - u8g_SetFont( LU8G, font_array[fontnr] ); + u8g_fntpgm_uint8_t *font = (u8g_fntpgm_uint8_t *)lua_touserdata( L, 2 ); + if (font != NULL) + u8g_SetFont( LU8G, font ); return 0; } @@ -1128,7 +1128,7 @@ const LUA_REG_TYPE lu8g_map[] = // Register fonts #undef U8G_FONT_TABLE_ENTRY -#define U8G_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LNUMVAL( __COUNTER__ ) }, +#define U8G_FONT_TABLE_ENTRY(font) { LSTRKEY( #font ), LUDATA( (void *)(u8g_ ## font) ) }, U8G_FONT_TABLE // Options for circle/ ellipse drwing @@ -1164,7 +1164,7 @@ LUALIB_API int luaopen_u8g( lua_State *L ) // Register fonts #undef U8G_FONT_TABLE_ENTRY -#define U8G_FONT_TABLE_ENTRY(font) MOD_REG_NUMBER( L, #font, __COUNTER__ ); +#define U8G_FONT_TABLE_ENTRY(font) MOD_REG_LUDATA( L, #font, (void *)(u8g_ ## font) ); U8G_FONT_TABLE // Options for circle/ ellipse drawing