handle font data as light userdata
This commit is contained in:
parent
7ae293d566
commit
32774d428c
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue