Add luaA_pushcolor() for pushing color_t*
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
99b521b2c7
commit
7f663ad563
23
luaa.c
23
luaa.c
|
@ -848,4 +848,27 @@ luaA_pushxcolor(lua_State *L, const xcolor_t *c)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Push a color as a string onto the stack
|
||||||
|
* \param L The Lua VM state.
|
||||||
|
* \param c The color to push.
|
||||||
|
* \return The number of elements pushed on stack.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
luaA_pushcolor(lua_State *L, const color_t *c)
|
||||||
|
{
|
||||||
|
uint8_t r = c->red;
|
||||||
|
uint8_t g = c->green;
|
||||||
|
uint8_t b = c->blue;
|
||||||
|
uint8_t a = c->alpha;
|
||||||
|
char s[10];
|
||||||
|
int len;
|
||||||
|
/* do not print alpha if it's full */
|
||||||
|
if(a == 0xff)
|
||||||
|
len = snprintf(s, sizeof(s), "#%02x%02x%02x", r, g, b);
|
||||||
|
else
|
||||||
|
len = snprintf(s, sizeof(s), "#%02x%02x%02x%02x", r, g, b, a);
|
||||||
|
lua_pushlstring(L, s, len);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||||
|
|
1
luaa.h
1
luaa.h
|
@ -332,6 +332,7 @@ void luaA_init(xdgHandle);
|
||||||
bool luaA_parserc(xdgHandle, const char *, bool);
|
bool luaA_parserc(xdgHandle, const char *, bool);
|
||||||
void luaA_on_timer(EV_P_ ev_timer *, int);
|
void luaA_on_timer(EV_P_ ev_timer *, int);
|
||||||
int luaA_pushxcolor(lua_State *, const xcolor_t *);
|
int luaA_pushxcolor(lua_State *, const xcolor_t *);
|
||||||
|
int luaA_pushcolor(lua_State *, const color_t *);
|
||||||
bool luaA_hasitem(lua_State *, const void *);
|
bool luaA_hasitem(lua_State *, const void *);
|
||||||
void luaA_table2wtable(lua_State *);
|
void luaA_table2wtable(lua_State *);
|
||||||
int luaA_next(lua_State *, int);
|
int luaA_next(lua_State *, int);
|
||||||
|
|
Loading…
Reference in New Issue