luaa: Stop using a_tokenize()

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-09-02 19:08:08 +02:00
parent 56fd77139e
commit f2e9767434
1 changed files with 37 additions and 52 deletions

55
luaa.c
View File

@ -310,13 +310,12 @@ luaA_wtable_ipairs(lua_State *L)
static int static int
luaA_wtable_index(lua_State *L) luaA_wtable_index(lua_State *L)
{ {
size_t len;
const char *buf; const char *buf;
lua_pushvalue(L, 2); lua_pushvalue(L, 2);
/* check for size, waiting lua 5.2 and __len on tables */ /* check for size, waiting lua 5.2 and __len on tables */
if((buf = lua_tolstring(L, -1, &len))) if((buf = lua_tostring(L, -1)))
if(a_tokenize(buf, len) == A_TK_LEN) if(a_strcmp(buf, "len") == 0)
{ {
lua_pushnumber(L, lua_objlen(L, lua_upvalueindex(1))); lua_pushnumber(L, lua_objlen(L, lua_upvalueindex(1)));
return 1; return 1;
@ -529,39 +528,28 @@ luaA_awesome_index(lua_State *L)
if(luaA_usemetatable(L, 1, 2)) if(luaA_usemetatable(L, 1, 2))
return 1; return 1;
size_t len; const char *buf = luaL_checkstring(L, 2);
const char *buf = luaL_checklstring(L, 2, &len);
switch(a_tokenize(buf, len)) if(a_strcmp(buf, "font") == 0)
{
case A_TK_FONT:
{ {
char *font = pango_font_description_to_string(globalconf.font->desc); char *font = pango_font_description_to_string(globalconf.font->desc);
lua_pushstring(L, font); lua_pushstring(L, font);
g_free(font); g_free(font);
} }
break; else if(a_strcmp(buf, "font_height") == 0)
case A_TK_FONT_HEIGHT:
lua_pushnumber(L, globalconf.font->height); lua_pushnumber(L, globalconf.font->height);
break; else if(a_strcmp(buf, "conffile") == 0)
case A_TK_CONFFILE:
lua_pushstring(L, conffile); lua_pushstring(L, conffile);
break; else if(a_strcmp(buf, "fg") == 0)
case A_TK_FG:
luaA_pushxcolor(L, globalconf.colors.fg); luaA_pushxcolor(L, globalconf.colors.fg);
break; else if(a_strcmp(buf, "bg") == 0)
case A_TK_BG:
luaA_pushxcolor(L, globalconf.colors.bg); luaA_pushxcolor(L, globalconf.colors.bg);
break; else if(a_strcmp(buf, "version") == 0)
case A_TK_VERSION:
lua_pushliteral(L, AWESOME_VERSION); lua_pushliteral(L, AWESOME_VERSION);
break; else if(a_strcmp(buf, "release") == 0)
case A_TK_RELEASE:
lua_pushliteral(L, AWESOME_RELEASE); lua_pushliteral(L, AWESOME_RELEASE);
break; else
default:
return 0; return 0;
}
return 1; return 1;
} }
@ -576,12 +564,9 @@ luaA_awesome_newindex(lua_State *L)
if(luaA_usemetatable(L, 1, 2)) if(luaA_usemetatable(L, 1, 2))
return 1; return 1;
size_t len; const char *buf = luaL_checkstring(L, 2);
const char *buf = luaL_checklstring(L, 2, &len);
switch(a_tokenize(buf, len)) if(a_strcmp(buf, "font") == 0)
{
case A_TK_FONT:
{ {
const char *newfont = luaL_checkstring(L, 3); const char *newfont = luaL_checkstring(L, 3);
font_delete(&globalconf.font); font_delete(&globalconf.font);
@ -590,17 +575,17 @@ luaA_awesome_newindex(lua_State *L)
foreach(wibox, globalconf.wiboxes) foreach(wibox, globalconf.wiboxes)
(*wibox)->need_update = true; (*wibox)->need_update = true;
} }
break; else if(a_strcmp(buf, "fg") == 0)
case A_TK_FG: {
size_t len;
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
xcolor_init_reply(xcolor_init_unchecked(&globalconf.colors.fg, buf, len)); xcolor_init_reply(xcolor_init_unchecked(&globalconf.colors.fg, buf, len));
break; }
case A_TK_BG: else if(a_strcmp(buf, "bg") == 0)
{
size_t len;
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
xcolor_init_reply(xcolor_init_unchecked(&globalconf.colors.bg, buf, len)); xcolor_init_reply(xcolor_init_unchecked(&globalconf.colors.bg, buf, len));
break;
default:
return 0;
} }
return 0; return 0;