luaa: add {new,}index to awesome lib, use for font

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-11-13 15:06:42 +01:00
parent 1c376b7f27
commit 590077004a
3 changed files with 74 additions and 30 deletions

View File

@ -25,6 +25,7 @@ fg
flex flex
floating floating
focus focus
font
fullscreen fullscreen
gap gap
geometry geometry

View File

@ -73,7 +73,7 @@ function init(path)
util.spawn(value, s) util.spawn(value, s)
end end
elseif key == "font" then elseif key == "font" then
capi.awesome.font(value) capi.awesome.font = value
elseif key == "fg_normal" then elseif key == "fg_normal" then
capi.awesome.colors({ fg = value }) capi.awesome.colors({ fg = value })
elseif key == "bg_normal" then elseif key == "bg_normal" then

101
luaa.c
View File

@ -143,32 +143,6 @@ luaA_restart(lua_State *L __attribute__ ((unused)))
return 0; return 0;
} }
/** Set or get default font. (DEPRECATED)
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \luastack
* \lparam An optional string with a font name in Pango format.
* \lreturn The font used, in Pango format.
*/
static int
luaA_font(lua_State *L)
{
char *font;
if(lua_gettop(L) == 1)
{
const char *newfont = luaL_checkstring(L, 1);
draw_font_delete(&globalconf.font);
globalconf.font = draw_font_new(newfont);
}
font = pango_font_description_to_string(globalconf.font->desc);
lua_pushstring(L, font);
g_free(font);
return 1;
}
/** Set default font. (DEPRECATED) /** Set default font. (DEPRECATED)
* \param L The Lua VM state. * \param L The Lua VM state.
* \return The number of elements pushed on stack. * \return The number of elements pushed on stack.
@ -179,7 +153,17 @@ static int
luaA_font_set(lua_State *L) luaA_font_set(lua_State *L)
{ {
deprecate(L); deprecate(L);
return luaA_font(L); if(lua_gettop(L) == 1)
{
const char *newfont = luaL_checkstring(L, 1);
draw_font_delete(&globalconf.font);
globalconf.font = draw_font_new(newfont);
}
char *font = pango_font_description_to_string(globalconf.font->desc);
lua_pushstring(L, font);
g_free(font);
return 0;
} }
/** Get configuration file path used by awesome. /** Get configuration file path used by awesome.
@ -761,6 +745,64 @@ luaA_mouse_add(lua_State *L)
return 0; return 0;
} }
/** awesome global table.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
*/
static int
luaA_awesome_index(lua_State *L)
{
if(luaA_usemetatable(L, 1, 2))
return 1;
size_t len;
const char *buf = luaL_checklstring(L, 2, &len);
switch(a_tokenize(buf, len))
{
case A_TK_FONT:
{
char *font = pango_font_description_to_string(globalconf.font->desc);
lua_pushstring(L, font);
g_free(font);
}
break;
default:
return 0;
}
return 1;
}
/** Newindex function for the awesome global table.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
*/
static int
luaA_awesome_newindex(lua_State *L)
{
if(luaA_usemetatable(L, 1, 2))
return 1;
size_t len;
const char *buf = luaL_checklstring(L, 2, &len);
switch(a_tokenize(buf, len))
{
case A_TK_FONT:
{
const char *newfont = luaL_checkstring(L, 3);
draw_font_delete(&globalconf.font);
globalconf.font = draw_font_new(newfont);
}
break;
default:
return 0;
}
return 0;
}
/** Initialize the Lua VM /** Initialize the Lua VM
*/ */
void void
@ -788,9 +830,10 @@ luaA_init(void)
{ "buttons", luaA_buttons }, { "buttons", luaA_buttons },
{ "font_set", luaA_font_set }, { "font_set", luaA_font_set },
{ "colors_set", luaA_colors_set }, { "colors_set", luaA_colors_set },
{ "font", luaA_font },
{ "colors", luaA_colors }, { "colors", luaA_colors },
{ "conffile", luaA_conffile }, { "conffile", luaA_conffile },
{ "__index", luaA_awesome_index },
{ "__newindex", luaA_awesome_newindex },
/* deprecated */ /* deprecated */
{ "mouse_add", luaA_mouse_add }, { "mouse_add", luaA_mouse_add },
{ NULL, NULL } { NULL, NULL }
@ -803,7 +846,7 @@ luaA_init(void)
luaA_fixups(L); luaA_fixups(L);
/* Export awesome lib */ /* Export awesome lib */
luaL_register(L, "awesome", awesome_lib); luaA_openlib(L, "awesome", awesome_lib, awesome_lib);
/* Export hooks lib */ /* Export hooks lib */
luaL_register(L, "hooks", awesome_hooks_lib); luaL_register(L, "hooks", awesome_hooks_lib);