lua: split getopt_string/getopt_lstring; fix mouse corner

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-25 17:33:05 +02:00
parent d5ed48ffdd
commit db88877587
8 changed files with 26 additions and 25 deletions

View File

@ -978,7 +978,7 @@ luaA_client_border_set(lua_State *L)
{
client_t **c = luaA_checkudata(L, 1, "client");
int width = luaA_getopt_number(L, 2, "width", (*c)->border);
const char *colorstr = luaA_getopt_string(L, 2, "color", NULL, NULL);
const char *colorstr = luaA_getopt_string(L, 2, "color", NULL);
xcolor_t color;
client_setborder(*c, width);

4
lua.c
View File

@ -397,10 +397,10 @@ luaA_colors_set(lua_State *L)
{
const char *fg, *bg;
luaA_checktable(L, 1);
if((fg = luaA_getopt_string(L, 1, "fg", NULL, NULL)))
if((fg = luaA_getopt_string(L, 1, "fg", NULL)))
xcolor_new(globalconf.connection, globalconf.default_screen,
fg, &globalconf.colors.fg);
if((bg = luaA_getopt_string(L, 1, "bg", NULL, NULL)))
if((bg = luaA_getopt_string(L, 1, "bg", NULL)))
xcolor_new(globalconf.connection, globalconf.default_screen,
bg, &globalconf.colors.bg);
return 0;

14
lua.h
View File

@ -140,27 +140,27 @@ luaA_optboolean(lua_State *L, int idx, bool def)
static inline lua_Number
luaA_getopt_number(lua_State *L, int idx, const char *name, lua_Number def)
{
/* assume that table is first on stack */
lua_getfield(L, idx, name);
/* return luaL_optnumber result */
return luaL_optnumber(L, -1, def);
}
static inline const char *
luaA_getopt_string(lua_State *L, int idx, const char *name, const char *def, size_t *len)
luaA_getopt_lstring(lua_State *L, int idx, const char *name, const char *def, size_t *len)
{
/* assume that table is first on stack */
lua_getfield(L, idx, name);
/* return luaL_optnumber result */
return luaL_optlstring(L, -1, def, len);
}
static inline const char *
luaA_getopt_string(lua_State *L, int idx, const char *name, const char *def)
{
return luaA_getopt_lstring(L, idx, name, def, NULL);
}
static inline bool
luaA_getopt_boolean(lua_State *L, int idx, const char *name, bool def)
{
/* assume that table is first on stack */
lua_getfield(L, idx, name);
/* return luaL_optnumber result */
return luaA_optboolean(L, -1, def);
}

View File

@ -1058,11 +1058,13 @@ luaA_client_mouse_resize(lua_State *L)
corner_t corner = AutoCorner;
bool infobox = true;
size_t len;
const char *buf;
if(lua_gettop(L) == 2 && !lua_isnil(L, 2))
{
luaA_checktable(L, 2);
corner = a_strtocorner(luaA_getopt_string(L, 2, "corner", "auto", &len), len);
buf = luaA_getopt_lstring(L, 2, "corner", "auto", &len);
corner = a_strtocorner(buf, len);
infobox = luaA_getopt_boolean(L, 2, "infobox", true);
}

View File

@ -517,7 +517,7 @@ luaA_statusbar_new(lua_State *L)
else
sb->colors.bg = globalconf.colors.bg;
buf = luaA_getopt_string(L, 1, "align", "left", &len);
buf = luaA_getopt_lstring(L, 1, "align", "left", &len);
sb->align = draw_align_fromstr(buf, len);
sb->width = luaA_getopt_number(L, 1, "width", 0);
@ -528,7 +528,7 @@ luaA_statusbar_new(lua_State *L)
/* 1.5 as default factor, it fits nice but no one knows why */
sb->height = 1.5 * globalconf.font->height;
buf = luaA_getopt_string(L, 1, "position", "top", &len);
buf = luaA_getopt_lstring(L, 1, "position", "top", &len);
sb->position = position_fromstr(buf, len);
return luaA_statusbar_userdata_new(L, sb);

2
tag.c
View File

@ -338,7 +338,7 @@ luaA_tag_new(lua_State *L)
mwfact = luaA_getopt_number(L, 1, "mwfact", 0.5);
ncol = luaA_getopt_number(L, 1, "ncol", 1);
nmaster = luaA_getopt_number(L, 1, "nmaster", 1);
lay = luaA_getopt_string(L, 1, "layout", "tile", NULL);
lay = luaA_getopt_string(L, 1, "layout", "tile");
layout = name_func_lookup(lay, LayoutList);

View File

@ -304,7 +304,7 @@ luaA_titlebar_new(lua_State *L)
tb = p_new(titlebar_t, 1);
buf = luaA_getopt_string(L, 1, "align", "left", &len);
buf = luaA_getopt_lstring(L, 1, "align", "left", &len);
tb->align = draw_align_fromstr(buf, len);
tb->width = luaA_getopt_number(L, 1, "width", 0);
@ -313,22 +313,22 @@ luaA_titlebar_new(lua_State *L)
/* 1.5 as default factor, it fits nice but no one knows why */
tb->height = 1.5 * globalconf.font->height;
buf = luaA_getopt_string(L, 1, "position", "top", &len);
buf = luaA_getopt_lstring(L, 1, "position", "top", &len);
tb->position = position_fromstr(buf, len);
if((buf = luaA_getopt_string(L, -1, "fg", NULL, NULL)))
if((buf = luaA_getopt_string(L, -1, "fg", NULL)))
xcolor_new(globalconf.connection, globalconf.default_screen,
buf, &tb->colors.fg);
else
tb->colors.fg = globalconf.colors.fg;
if((buf = luaA_getopt_string(L, 1, "bg", NULL, NULL)))
if((buf = luaA_getopt_string(L, 1, "bg", NULL)))
xcolor_new(globalconf.connection, globalconf.default_screen,
buf, &tb->colors.bg);
else
tb->colors.bg = globalconf.colors.bg;
if((buf = luaA_getopt_string(L, 1, "border_color", NULL, NULL)))
if((buf = luaA_getopt_string(L, 1, "border_color", NULL)))
xcolor_new(globalconf.connection, globalconf.default_screen,
buf, &tb->border.color);
@ -431,11 +431,11 @@ luaA_titlebar_colors_set(lua_State *L)
luaA_checktable(L, 2);
if((color = luaA_getopt_string(L, 2, "fg", NULL, NULL)))
if((color = luaA_getopt_string(L, 2, "fg", NULL)))
xcolor_new(globalconf.connection, globalconf.default_screen,
color, &(*tb)->colors.fg);
if((color = luaA_getopt_string(L, 2, "bg", NULL, NULL)))
if((color = luaA_getopt_string(L, 2, "bg", NULL)))
xcolor_new(globalconf.connection, globalconf.default_screen,
color, &(*tb)->colors.bg);
@ -462,7 +462,7 @@ luaA_titlebar_border_set(lua_State *L)
luaA_checktable(L, 2);
if((color = luaA_getopt_string(L, 2, "color", NULL, NULL)))
if((color = luaA_getopt_string(L, 2, "color", NULL)))
{
xcolor_new(globalconf.connection, globalconf.default_screen,
color, &(*tb)->border.color);

View File

@ -313,10 +313,10 @@ luaA_widget_new(lua_State *L)
size_t len;
luaA_checktable(L, 1);
buf = luaA_getopt_string(L, 1, "align", "left", &len);
buf = luaA_getopt_lstring(L, 1, "align", "left", &len);
align = draw_align_fromstr(buf, len);
type = luaA_getopt_string(L, 1, "type", NULL, NULL);
type = luaA_getopt_string(L, 1, "type", NULL);
if((wc = name_func_lookup(type, WidgetList)))
w = wc(align);
@ -513,7 +513,6 @@ luaA_widget_visible_get(lua_State *L)
static int
luaA_widget_index(lua_State *L)
{
widget_t **widget = luaA_checkudata(L, 1, "widget");
size_t len;
const char *str = luaL_checklstring(L, 2, &len);