From db88877587635c562e2cbea41a807c7d1b5e8760 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 25 Jun 2008 17:33:05 +0200 Subject: [PATCH] lua: split getopt_string/getopt_lstring; fix mouse corner Signed-off-by: Julien Danjou --- client.c | 2 +- lua.c | 4 ++-- lua.h | 14 +++++++------- mouse.c | 4 +++- statusbar.c | 4 ++-- tag.c | 2 +- titlebar.c | 16 ++++++++-------- widget.c | 5 ++--- 8 files changed, 26 insertions(+), 25 deletions(-) diff --git a/client.c b/client.c index 6e8320da..88e646ad 100644 --- a/client.c +++ b/client.c @@ -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); diff --git a/lua.c b/lua.c index 20551794..0d321de9 100644 --- a/lua.c +++ b/lua.c @@ -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; diff --git a/lua.h b/lua.h index 0e4ec402..4cbae724 100644 --- a/lua.h +++ b/lua.h @@ -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); } diff --git a/mouse.c b/mouse.c index 536750da..80a1cc16 100644 --- a/mouse.c +++ b/mouse.c @@ -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); } diff --git a/statusbar.c b/statusbar.c index 6cead3ed..3a7fb9f8 100644 --- a/statusbar.c +++ b/statusbar.c @@ -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); diff --git a/tag.c b/tag.c index 6dd73c92..8fa990d8 100644 --- a/tag.c +++ b/tag.c @@ -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); diff --git a/titlebar.c b/titlebar.c index cec1d84d..e52d28d6 100644 --- a/titlebar.c +++ b/titlebar.c @@ -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); diff --git a/widget.c b/widget.c index 3753e242..eac1f49e 100644 --- a/widget.c +++ b/widget.c @@ -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);