[lua] Check for object validity

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-04 18:27:10 +02:00
parent 0a44e90cb6
commit 98119d5d3f
8 changed files with 97 additions and 81 deletions

View File

@ -900,7 +900,7 @@ client_setborder(client_t *c, uint32_t width)
static int static int
luaA_client_border_set(lua_State *L) luaA_client_border_set(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
uint32_t width = luaA_getopt_number(L, 2, "width", 0); uint32_t width = luaA_getopt_number(L, 2, "width", 0);
const char *colorstr = luaA_getopt_string(L, 2, "color", NULL); const char *colorstr = luaA_getopt_string(L, 2, "color", NULL);
xcolor_t color; xcolor_t color;
@ -918,7 +918,7 @@ luaA_client_border_set(lua_State *L)
static int static int
luaA_client_screen_set(lua_State *L) luaA_client_screen_set(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
int screen = luaL_checknumber(L, 2) - 1; int screen = luaL_checknumber(L, 2) - 1;
luaA_checkscreen(screen); luaA_checkscreen(screen);
move_client_to_screen(*c, screen, true); move_client_to_screen(*c, screen, true);
@ -928,7 +928,7 @@ luaA_client_screen_set(lua_State *L)
static int static int
luaA_client_screen_get(lua_State *L) luaA_client_screen_get(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
lua_pushnumber(L, 1 + (*c)->screen); lua_pushnumber(L, 1 + (*c)->screen);
return 1; return 1;
} }
@ -937,8 +937,8 @@ luaA_client_screen_get(lua_State *L)
static int static int
luaA_client_tag(lua_State *L) luaA_client_tag(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
tag_t **tag = luaL_checkudata(L, 2, "tag"); tag_t **tag = luaA_checkudata(L, 2, "tag");
bool tag_the_client = luaA_checkboolean(L, 3); bool tag_the_client = luaA_checkboolean(L, 3);
if((*tag)->screen != (*c)->screen) if((*tag)->screen != (*c)->screen)
@ -955,8 +955,8 @@ luaA_client_tag(lua_State *L)
static int static int
luaA_client_istagged(lua_State *L) luaA_client_istagged(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
tag_t **tag = luaL_checkudata(L, 2, "tag"); tag_t **tag = luaA_checkudata(L, 2, "tag");
lua_pushboolean(L, is_client_tagged(*c, *tag)); lua_pushboolean(L, is_client_tagged(*c, *tag));
return 1; return 1;
} }
@ -964,7 +964,7 @@ luaA_client_istagged(lua_State *L)
static int static int
luaA_client_coords_get(lua_State *L) luaA_client_coords_get(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
lua_newtable(L); lua_newtable(L);
lua_pushnumber(L, (*c)->geometry.width); lua_pushnumber(L, (*c)->geometry.width);
lua_setfield(L, -2, "width"); lua_setfield(L, -2, "width");
@ -980,7 +980,7 @@ luaA_client_coords_get(lua_State *L)
static int static int
luaA_client_coords_set(lua_State *L) luaA_client_coords_set(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
area_t geometry; area_t geometry;
if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating) if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
@ -999,7 +999,7 @@ luaA_client_coords_set(lua_State *L)
static int static int
luaA_client_opacity_set(lua_State *L) luaA_client_opacity_set(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
double opacity = luaL_checknumber(L, 2); double opacity = luaL_checknumber(L, 2);
if(opacity == -1 || (opacity >= 0 && opacity <= 100)) if(opacity == -1 || (opacity >= 0 && opacity <= 100))
@ -1010,7 +1010,7 @@ luaA_client_opacity_set(lua_State *L)
static int static int
luaA_client_kill(lua_State *L) luaA_client_kill(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
client_kill(*c); client_kill(*c);
return 0; return 0;
} }
@ -1018,8 +1018,8 @@ luaA_client_kill(lua_State *L)
static int static int
luaA_client_swap(lua_State *L) luaA_client_swap(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
client_t **swap = luaL_checkudata(L, 2, "client"); client_t **swap = luaA_checkudata(L, 2, "client");
client_list_swap(&globalconf.clients, *swap, *c); client_list_swap(&globalconf.clients, *swap, *c);
globalconf.screens[(*c)->screen].need_arrange = true; globalconf.screens[(*c)->screen].need_arrange = true;
globalconf.screens[(*swap)->screen].need_arrange = true; globalconf.screens[(*swap)->screen].need_arrange = true;
@ -1031,7 +1031,7 @@ luaA_client_swap(lua_State *L)
static int static int
luaA_client_focus_set(lua_State *L) luaA_client_focus_set(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
client_focus(*c, (*c)->screen); client_focus(*c, (*c)->screen);
return 0; return 0;
} }
@ -1041,7 +1041,7 @@ luaA_client_focus_set(lua_State *L)
static int static int
luaA_client_raise(lua_State *L) luaA_client_raise(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
client_raise(*c); client_raise(*c);
return 0; return 0;
} }
@ -1049,7 +1049,7 @@ luaA_client_raise(lua_State *L)
static int static int
luaA_client_floating_set(lua_State *L) luaA_client_floating_set(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
bool f = luaA_checkboolean(L, 2); bool f = luaA_checkboolean(L, 2);
client_setfloating(*c, f, (*c)->layer == LAYER_FLOAT ? LAYER_TILE : LAYER_FLOAT); client_setfloating(*c, f, (*c)->layer == LAYER_FLOAT ? LAYER_TILE : LAYER_FLOAT);
return 0; return 0;
@ -1058,7 +1058,7 @@ luaA_client_floating_set(lua_State *L)
static int static int
luaA_client_floating_get(lua_State *L) luaA_client_floating_get(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
lua_pushboolean(L, (*c)->isfloating); lua_pushboolean(L, (*c)->isfloating);
return 1; return 1;
} }
@ -1066,8 +1066,8 @@ luaA_client_floating_get(lua_State *L)
static int static int
luaA_client_eq(lua_State *L) luaA_client_eq(lua_State *L)
{ {
client_t **c1 = luaL_checkudata(L, 1, "client"); client_t **c1 = luaA_checkudata(L, 1, "client");
client_t **c2 = luaL_checkudata(L, 2, "client"); client_t **c2 = luaA_checkudata(L, 2, "client");
lua_pushboolean(L, (*c1 == *c2)); lua_pushboolean(L, (*c1 == *c2));
return 1; return 1;
} }
@ -1075,7 +1075,7 @@ luaA_client_eq(lua_State *L)
static int static int
luaA_client_redraw(lua_State *L) luaA_client_redraw(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
xcb_unmap_window(globalconf.connection, (*c)->win); xcb_unmap_window(globalconf.connection, (*c)->win);
xcb_map_window(globalconf.connection, (*c)->win); xcb_map_window(globalconf.connection, (*c)->win);
return 0; return 0;
@ -1084,7 +1084,7 @@ luaA_client_redraw(lua_State *L)
static int static int
luaA_client_tostring(lua_State *L) luaA_client_tostring(lua_State *L)
{ {
client_t **p = luaL_checkudata(L, 1, "client"); client_t **p = luaA_checkudata(L, 1, "client");
lua_pushfstring(L, "[client udata(%p) name(%s)]", *p, (*p)->name); lua_pushfstring(L, "[client udata(%p) name(%s)]", *p, (*p)->name);
return 1; return 1;
} }
@ -1092,7 +1092,7 @@ luaA_client_tostring(lua_State *L)
static int static int
luaA_client_icon_set(lua_State *L) luaA_client_icon_set(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
const char *icon = luaL_optstring(L, 2, NULL); const char *icon = luaL_optstring(L, 2, NULL);
p_delete(&(*c)->icon_path); p_delete(&(*c)->icon_path);
@ -1107,7 +1107,7 @@ luaA_client_icon_set(lua_State *L)
static int static int
luaA_client_name_get(lua_State *L) luaA_client_name_get(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
lua_pushstring(L, (*c)->name); lua_pushstring(L, (*c)->name);
return 1; return 1;
} }
@ -1118,7 +1118,7 @@ luaA_client_name_get(lua_State *L)
static int static int
luaA_client_name_set(lua_State *L) luaA_client_name_set(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
const char *name = luaL_checkstring(L, 2); const char *name = luaL_checkstring(L, 2);
p_delete(&(*c)->name); p_delete(&(*c)->name);
(*c)->name = a_strdup(name); (*c)->name = a_strdup(name);
@ -1131,8 +1131,8 @@ luaA_client_name_set(lua_State *L)
static int static int
luaA_client_titlebar_set(lua_State *L) luaA_client_titlebar_set(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
titlebar_t **t = luaL_checkudata(L, 2, "titlebar"); titlebar_t **t = luaA_checkudata(L, 2, "titlebar");
if(client_getbytitlebar(*t)) if(client_getbytitlebar(*t))
luaL_error(L, "titlebar is already used by another client"); luaL_error(L, "titlebar is already used by another client");
@ -1160,7 +1160,7 @@ luaA_client_titlebar_set(lua_State *L)
static int static int
luaA_client_titlebar_get(lua_State *L) luaA_client_titlebar_get(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
if((*c)->titlebar) if((*c)->titlebar)
return luaA_titlebar_userdata_new((*c)->titlebar); return luaA_titlebar_userdata_new((*c)->titlebar);
@ -1173,7 +1173,7 @@ luaA_client_titlebar_get(lua_State *L)
static int static int
luaA_client_unmanage(lua_State *L) luaA_client_unmanage(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
client_unmanage(*c); client_unmanage(*c);
return 0; return 0;
} }

View File

@ -88,7 +88,7 @@ luaA_keybinding_new(lua_State *L)
static int static int
luaA_keybinding_add(lua_State *L) luaA_keybinding_add(lua_State *L)
{ {
keybinding_t *key, **k = luaL_checkudata(L, 1, "keybinding"); keybinding_t *key, **k = luaA_checkudata(L, 1, "keybinding");
/* Check that the keybinding has not been already added. */ /* Check that the keybinding has not been already added. */
for(key = globalconf.keys; key; key = key->next) for(key = globalconf.keys; key; key = key->next)
@ -109,7 +109,7 @@ luaA_keybinding_add(lua_State *L)
static int static int
luaA_keybinding_remove(lua_State *L) luaA_keybinding_remove(lua_State *L)
{ {
keybinding_t **k = luaL_checkudata(L, 1, "keybinding"); keybinding_t **k = luaA_checkudata(L, 1, "keybinding");
keybinding_list_detach(&globalconf.keys, *k); keybinding_list_detach(&globalconf.keys, *k);
@ -125,7 +125,7 @@ luaA_keybinding_remove(lua_State *L)
static int static int
luaA_keybinding_gc(lua_State *L) luaA_keybinding_gc(lua_State *L)
{ {
keybinding_t **keybinding = luaL_checkudata(L, 1, "keybinding"); keybinding_t **keybinding = luaA_checkudata(L, 1, "keybinding");
keybinding_unref(keybinding); keybinding_unref(keybinding);
keybinding = NULL; keybinding = NULL;
return 0; return 0;
@ -137,7 +137,7 @@ luaA_keybinding_gc(lua_State *L)
static int static int
luaA_keybinding_tostring(lua_State *L) luaA_keybinding_tostring(lua_State *L)
{ {
keybinding_t **p = luaL_checkudata(L, 1, "keybinding"); keybinding_t **p = luaA_checkudata(L, 1, "keybinding");
lua_pushfstring(L, "[keybinding udata(%p)]", *p); lua_pushfstring(L, "[keybinding udata(%p)]", *p);
return 1; return 1;
} }

16
lua.h
View File

@ -69,6 +69,22 @@ typedef int luaA_function;
luaL_error(L, "invalid screen number: %d\n", screen); \ luaL_error(L, "invalid screen number: %d\n", screen); \
} while(0) } while(0)
/** Check that an object is not a NULL reference.
* \param L The Lua state.
* \param ud The index of the object in the stack.
* \param tname The type name.
* \return A pointer to the object.
*/
static inline void *
luaA_checkudata(lua_State *L, int ud, const char *tname)
{
void **p = luaL_checkudata(L, ud, tname);
if(*p)
return p;
luaL_error(L, "invalid object");
return NULL;
}
static inline lua_Number static inline lua_Number
luaA_getopt_number(lua_State *L, int idx, const char *name, lua_Number def) luaA_getopt_number(lua_State *L, int idx, const char *name, lua_Number def)
{ {

View File

@ -476,7 +476,7 @@ luaA_mouse_coords_set(lua_State *L)
int int
luaA_client_mouse_resize(lua_State *L) luaA_client_mouse_resize(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
mouse_client_resize(*c); mouse_client_resize(*c);
return 0; return 0;
} }
@ -487,7 +487,7 @@ luaA_client_mouse_resize(lua_State *L)
int int
luaA_client_mouse_move(lua_State *L) luaA_client_mouse_move(lua_State *L)
{ {
client_t **c = luaL_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
int snap = luaL_optnumber(L, 2, 8); int snap = luaL_optnumber(L, 2, 8);
mouse_client_move(*c, snap); mouse_client_move(*c, snap);
return 0; return 0;

View File

@ -282,8 +282,8 @@ statusbar_position_update(statusbar_t *statusbar, position_t position)
static int static int
luaA_statusbar_eq(lua_State *L) luaA_statusbar_eq(lua_State *L)
{ {
statusbar_t **t1 = luaL_checkudata(L, 1, "statusbar"); statusbar_t **t1 = luaA_checkudata(L, 1, "statusbar");
statusbar_t **t2 = luaL_checkudata(L, 2, "statusbar"); statusbar_t **t2 = luaA_checkudata(L, 2, "statusbar");
lua_pushboolean(L, (*t1 == *t2)); lua_pushboolean(L, (*t1 == *t2));
return 1; return 1;
} }
@ -294,7 +294,7 @@ luaA_statusbar_eq(lua_State *L)
static int static int
luaA_statusbar_position_set(lua_State *L) luaA_statusbar_position_set(lua_State *L)
{ {
statusbar_t *s, **sb = luaL_checkudata(L, 1, "statusbar"); statusbar_t *s, **sb = luaA_checkudata(L, 1, "statusbar");
const char *pos = luaL_checkstring(L, 2); const char *pos = luaL_checkstring(L, 2);
position_t position = position_get_from_str(pos); position_t position = position_get_from_str(pos);
@ -314,7 +314,7 @@ luaA_statusbar_position_set(lua_State *L)
static int static int
luaA_statusbar_position_get(lua_State *L) luaA_statusbar_position_get(lua_State *L)
{ {
statusbar_t **sb = luaL_checkudata(L, 1, "statusbar"); statusbar_t **sb = luaA_checkudata(L, 1, "statusbar");
lua_pushstring(L, position_to_str((*sb)->position)); lua_pushstring(L, position_to_str((*sb)->position));
return 1; return 1;
} }
@ -325,7 +325,7 @@ luaA_statusbar_position_get(lua_State *L)
static int static int
luaA_statusbar_align_set(lua_State *L) luaA_statusbar_align_set(lua_State *L)
{ {
statusbar_t **sb = luaL_checkudata(L, 1, "statusbar"); statusbar_t **sb = luaA_checkudata(L, 1, "statusbar");
const char *al = luaL_checkstring(L, 2); const char *al = luaL_checkstring(L, 2);
alignment_t align = draw_align_get_from_str(al); alignment_t align = draw_align_get_from_str(al);
@ -340,7 +340,7 @@ luaA_statusbar_align_set(lua_State *L)
static int static int
luaA_statusbar_tostring(lua_State *L) luaA_statusbar_tostring(lua_State *L)
{ {
statusbar_t **p = luaL_checkudata(L, 1, "statusbar"); statusbar_t **p = luaA_checkudata(L, 1, "statusbar");
lua_pushfstring(L, "[statusbar udata(%p) name(%s)]", *p, (*p)->name); lua_pushfstring(L, "[statusbar udata(%p) name(%s)]", *p, (*p)->name);
return 1; return 1;
} }
@ -351,8 +351,8 @@ luaA_statusbar_tostring(lua_State *L)
static int static int
luaA_statusbar_widget_add(lua_State *L) luaA_statusbar_widget_add(lua_State *L)
{ {
statusbar_t **sb = luaL_checkudata(L, 1, "statusbar"); statusbar_t **sb = luaA_checkudata(L, 1, "statusbar");
widget_t **widget = luaL_checkudata(L, 2, "widget"); widget_t **widget = luaA_checkudata(L, 2, "widget");
widget_node_t *w = p_new(widget_node_t, 1); widget_node_t *w = p_new(widget_node_t, 1);
(*sb)->need_update = true; (*sb)->need_update = true;
@ -369,7 +369,7 @@ luaA_statusbar_widget_add(lua_State *L)
static int static int
luaA_statusbar_add(lua_State *L) luaA_statusbar_add(lua_State *L)
{ {
statusbar_t *s, **sb = luaL_checkudata(L, 1, "statusbar"); statusbar_t *s, **sb = luaA_checkudata(L, 1, "statusbar");
int i, screen = luaL_checknumber(L, 2) - 1; int i, screen = luaL_checknumber(L, 2) - 1;
luaA_checkscreen(screen); luaA_checkscreen(screen);
@ -404,7 +404,7 @@ luaA_statusbar_add(lua_State *L)
static int static int
luaA_statusbar_remove(lua_State *L) luaA_statusbar_remove(lua_State *L)
{ {
statusbar_t *s, **sb = luaL_checkudata(L, 1, "statusbar"); statusbar_t *s, **sb = luaA_checkudata(L, 1, "statusbar");
int i; int i;
for(i = 0; i < globalconf.screens_info->nscreen; i++) for(i = 0; i < globalconf.screens_info->nscreen; i++)
@ -479,7 +479,7 @@ luaA_statusbar_new(lua_State *L)
static int static int
luaA_statusbar_widget_get(lua_State *L) luaA_statusbar_widget_get(lua_State *L)
{ {
statusbar_t **sb = luaL_checkudata(L, 1, "statusbar"); statusbar_t **sb = luaA_checkudata(L, 1, "statusbar");
widget_node_t *widget; widget_node_t *widget;
int i = 1; int i = 1;
@ -501,7 +501,7 @@ luaA_statusbar_widget_get(lua_State *L)
static int static int
luaA_statusbar_gc(lua_State *L) luaA_statusbar_gc(lua_State *L)
{ {
statusbar_t **sb = luaL_checkudata(L, 1, "statusbar"); statusbar_t **sb = luaA_checkudata(L, 1, "statusbar");
statusbar_unref(sb); statusbar_unref(sb);
*sb = NULL; *sb = NULL;
return 0; return 0;

34
tag.c
View File

@ -242,8 +242,8 @@ tag_view_only_byindex(int screen, int dindex)
static int static int
luaA_tag_eq(lua_State *L) luaA_tag_eq(lua_State *L)
{ {
tag_t **t1 = luaL_checkudata(L, 1, "tag"); tag_t **t1 = luaA_checkudata(L, 1, "tag");
tag_t **t2 = luaL_checkudata(L, 2, "tag"); tag_t **t2 = luaA_checkudata(L, 2, "tag");
lua_pushboolean(L, (*t1 == *t2)); lua_pushboolean(L, (*t1 == *t2));
return 1; return 1;
} }
@ -254,7 +254,7 @@ luaA_tag_eq(lua_State *L)
static int static int
luaA_tag_tostring(lua_State *L) luaA_tag_tostring(lua_State *L)
{ {
tag_t **p = luaL_checkudata(L, 1, "tag"); tag_t **p = luaA_checkudata(L, 1, "tag");
lua_pushfstring(L, "[tag udata(%p) name(%s)]", *p, (*p)->name); lua_pushfstring(L, "[tag udata(%p) name(%s)]", *p, (*p)->name);
return 1; return 1;
} }
@ -265,7 +265,7 @@ luaA_tag_tostring(lua_State *L)
static int static int
luaA_tag_add(lua_State *L) luaA_tag_add(lua_State *L)
{ {
tag_t *t, **tag = luaL_checkudata(L, 1, "tag"); tag_t *t, **tag = luaA_checkudata(L, 1, "tag");
int i, screen = luaL_checknumber(L, 2) - 1; int i, screen = luaL_checknumber(L, 2) - 1;
luaA_checkscreen(screen); luaA_checkscreen(screen);
@ -340,7 +340,7 @@ luaA_tag_new(lua_State *L)
static int static int
luaA_tag_view(lua_State *L) luaA_tag_view(lua_State *L)
{ {
tag_t **tag = luaL_checkudata(L, 1, "tag"); tag_t **tag = luaA_checkudata(L, 1, "tag");
bool view = luaA_checkboolean(L, 2); bool view = luaA_checkboolean(L, 2);
tag_view(*tag, view); tag_view(*tag, view);
return 0; return 0;
@ -352,7 +352,7 @@ luaA_tag_view(lua_State *L)
static int static int
luaA_tag_isselected(lua_State *L) luaA_tag_isselected(lua_State *L)
{ {
tag_t **tag = luaL_checkudata(L, 1, "tag"); tag_t **tag = luaA_checkudata(L, 1, "tag");
lua_pushboolean(L, (*tag)->selected); lua_pushboolean(L, (*tag)->selected);
return 1; return 1;
} }
@ -364,7 +364,7 @@ luaA_tag_isselected(lua_State *L)
static int static int
luaA_tag_mwfact_set(lua_State *L) luaA_tag_mwfact_set(lua_State *L)
{ {
tag_t **tag = luaL_checkudata(L, 1, "tag"); tag_t **tag = luaA_checkudata(L, 1, "tag");
double mwfact = luaL_checknumber(L, 2); double mwfact = luaL_checknumber(L, 2);
if(mwfact < 1 && mwfact > 0) if(mwfact < 1 && mwfact > 0)
@ -384,7 +384,7 @@ luaA_tag_mwfact_set(lua_State *L)
static int static int
luaA_tag_mwfact_get(lua_State *L) luaA_tag_mwfact_get(lua_State *L)
{ {
tag_t **tag = luaL_checkudata(L, 1, "tag"); tag_t **tag = luaA_checkudata(L, 1, "tag");
lua_pushnumber(L, (*tag)->mwfact); lua_pushnumber(L, (*tag)->mwfact);
return 1; return 1;
} }
@ -396,7 +396,7 @@ luaA_tag_mwfact_get(lua_State *L)
static int static int
luaA_tag_ncol_set(lua_State *L) luaA_tag_ncol_set(lua_State *L)
{ {
tag_t **tag = luaL_checkudata(L, 1, "tag"); tag_t **tag = luaA_checkudata(L, 1, "tag");
int ncol = luaL_checknumber(L, 2); int ncol = luaL_checknumber(L, 2);
if(ncol >= 1) if(ncol >= 1)
@ -416,7 +416,7 @@ luaA_tag_ncol_set(lua_State *L)
static int static int
luaA_tag_ncol_get(lua_State *L) luaA_tag_ncol_get(lua_State *L)
{ {
tag_t **tag = luaL_checkudata(L, 1, "tag"); tag_t **tag = luaA_checkudata(L, 1, "tag");
lua_pushnumber(L, (*tag)->ncol); lua_pushnumber(L, (*tag)->ncol);
return 1; return 1;
} }
@ -428,7 +428,7 @@ luaA_tag_ncol_get(lua_State *L)
static int static int
luaA_tag_nmaster_set(lua_State *L) luaA_tag_nmaster_set(lua_State *L)
{ {
tag_t **tag = luaL_checkudata(L, 1, "tag"); tag_t **tag = luaA_checkudata(L, 1, "tag");
int nmaster = luaL_checknumber(L, 2); int nmaster = luaL_checknumber(L, 2);
if(nmaster >= 0) if(nmaster >= 0)
@ -448,7 +448,7 @@ luaA_tag_nmaster_set(lua_State *L)
static int static int
luaA_tag_nmaster_get(lua_State *L) luaA_tag_nmaster_get(lua_State *L)
{ {
tag_t **tag = luaL_checkudata(L, 1, "tag"); tag_t **tag = luaA_checkudata(L, 1, "tag");
lua_pushnumber(L, (*tag)->nmaster); lua_pushnumber(L, (*tag)->nmaster);
return 1; return 1;
} }
@ -459,7 +459,7 @@ luaA_tag_nmaster_get(lua_State *L)
static int static int
luaA_tag_name_get(lua_State *L) luaA_tag_name_get(lua_State *L)
{ {
tag_t **tag = luaL_checkudata(L, 1, "tag"); tag_t **tag = luaA_checkudata(L, 1, "tag");
lua_pushstring(L, (*tag)->name); lua_pushstring(L, (*tag)->name);
return 1; return 1;
} }
@ -470,7 +470,7 @@ luaA_tag_name_get(lua_State *L)
static int static int
luaA_tag_name_set(lua_State *L) luaA_tag_name_set(lua_State *L)
{ {
tag_t **tag = luaL_checkudata(L, 1, "tag"); tag_t **tag = luaA_checkudata(L, 1, "tag");
const char *name = luaL_checkstring(L, 2); const char *name = luaL_checkstring(L, 2);
p_delete(&(*tag)->name); p_delete(&(*tag)->name);
(*tag)->name = a_strdup(name); (*tag)->name = a_strdup(name);
@ -482,7 +482,7 @@ luaA_tag_name_set(lua_State *L)
static int static int
luaA_tag_gc(lua_State *L) luaA_tag_gc(lua_State *L)
{ {
tag_t **tag = luaL_checkudata(L, 1, "tag"); tag_t **tag = luaA_checkudata(L, 1, "tag");
tag_unref(tag); tag_unref(tag);
*tag = NULL; *tag = NULL;
return 0; return 0;
@ -494,7 +494,7 @@ luaA_tag_gc(lua_State *L)
static int static int
luaA_tag_layout_get(lua_State *L) luaA_tag_layout_get(lua_State *L)
{ {
tag_t **tag = luaL_checkudata(L, 1, "tag"); tag_t **tag = luaA_checkudata(L, 1, "tag");
const char *name = a_strdup(name_func_rlookup((*tag)->layout, LayoutList)); const char *name = a_strdup(name_func_rlookup((*tag)->layout, LayoutList));
lua_pushstring(L, name); lua_pushstring(L, name);
return 1; return 1;
@ -506,7 +506,7 @@ luaA_tag_layout_get(lua_State *L)
static int static int
luaA_tag_layout_set(lua_State *L) luaA_tag_layout_set(lua_State *L)
{ {
tag_t **tag = luaL_checkudata(L, 1, "tag"); tag_t **tag = luaA_checkudata(L, 1, "tag");
const char *name = luaL_checkstring(L, 2); const char *name = luaL_checkstring(L, 2);
layout_t *l = name_func_lookup(name, LayoutList); layout_t *l = name_func_lookup(name, LayoutList);

View File

@ -452,8 +452,8 @@ luaA_titlebar_new(lua_State *L)
static int static int
luaA_titlebar_widget_add(lua_State *L) luaA_titlebar_widget_add(lua_State *L)
{ {
titlebar_t **tb = luaL_checkudata(L, 1, "titlebar"); titlebar_t **tb = luaA_checkudata(L, 1, "titlebar");
widget_t **widget = luaL_checkudata(L, 2, "widget"); widget_t **widget = luaA_checkudata(L, 2, "widget");
widget_node_t *w = p_new(widget_node_t, 1); widget_node_t *w = p_new(widget_node_t, 1);
client_t *c; client_t *c;
@ -477,7 +477,7 @@ luaA_titlebar_widget_add(lua_State *L)
static int static int
luaA_titlebar_widget_get(lua_State *L) luaA_titlebar_widget_get(lua_State *L)
{ {
titlebar_t **tb = luaL_checkudata(L, 1, "titlebar"); titlebar_t **tb = luaA_checkudata(L, 1, "titlebar");
widget_node_t *widget; widget_node_t *widget;
int i = 1; int i = 1;
@ -501,7 +501,7 @@ luaA_titlebar_widget_get(lua_State *L)
static int static int
luaA_titlebar_client_get(lua_State *L) luaA_titlebar_client_get(lua_State *L)
{ {
titlebar_t **titlebar = luaL_checkudata(L, 1, "titlebar"); titlebar_t **titlebar = luaA_checkudata(L, 1, "titlebar");
client_t *c; client_t *c;
if((c = client_getbytitlebar(*titlebar))) if((c = client_getbytitlebar(*titlebar)))
@ -525,7 +525,7 @@ luaA_titlebar_userdata_new(titlebar_t *t)
static int static int
luaA_titlebar_gc(lua_State *L) luaA_titlebar_gc(lua_State *L)
{ {
titlebar_t **titlebar = luaL_checkudata(L, 1, "titlebar"); titlebar_t **titlebar = luaA_checkudata(L, 1, "titlebar");
titlebar_unref(titlebar); titlebar_unref(titlebar);
*titlebar = NULL; *titlebar = NULL;
return 0; return 0;
@ -534,7 +534,7 @@ luaA_titlebar_gc(lua_State *L)
static int static int
luaA_titlebar_tostring(lua_State *L) luaA_titlebar_tostring(lua_State *L)
{ {
titlebar_t **p = luaL_checkudata(L, 1, "titlebar"); titlebar_t **p = luaA_checkudata(L, 1, "titlebar");
lua_pushfstring(L, "[titlebar udata(%p)]", *p); lua_pushfstring(L, "[titlebar udata(%p)]", *p);
return 1; return 1;
} }
@ -542,8 +542,8 @@ luaA_titlebar_tostring(lua_State *L)
static int static int
luaA_titlebar_eq(lua_State *L) luaA_titlebar_eq(lua_State *L)
{ {
titlebar_t **t1 = luaL_checkudata(L, 1, "titlebar"); titlebar_t **t1 = luaA_checkudata(L, 1, "titlebar");
titlebar_t **t2 = luaL_checkudata(L, 2, "titlebar"); titlebar_t **t2 = luaA_checkudata(L, 2, "titlebar");
lua_pushboolean(L, (*t1 == *t2)); lua_pushboolean(L, (*t1 == *t2));
return 1; return 1;
} }

View File

@ -347,7 +347,7 @@ luaA_widget_mouse(lua_State *L)
{ {
size_t i, len; size_t i, len;
/* arg 1 is object */ /* arg 1 is object */
widget_t **widget = luaL_checkudata(L, 1, "widget"); widget_t **widget = luaA_checkudata(L, 1, "widget");
int b; int b;
button_t *button; button_t *button;
@ -419,7 +419,7 @@ widget_tell_managestatus(widget_t *widget, widget_tell_status_t status, const ch
static int static int
luaA_widget_set(lua_State *L) luaA_widget_set(lua_State *L)
{ {
widget_t **widget = luaL_checkudata(L, 1, "widget"); widget_t **widget = luaA_checkudata(L, 1, "widget");
const char *property, *value; const char *property, *value;
widget_tell_status_t status; widget_tell_status_t status;
@ -436,7 +436,7 @@ luaA_widget_set(lua_State *L)
static int static int
luaA_widget_gc(lua_State *L) luaA_widget_gc(lua_State *L)
{ {
widget_t **widget = luaL_checkudata(L, 1, "widget"); widget_t **widget = luaA_checkudata(L, 1, "widget");
widget_unref(widget); widget_unref(widget);
*widget = NULL; *widget = NULL;
return 0; return 0;
@ -447,7 +447,7 @@ luaA_widget_gc(lua_State *L)
static int static int
luaA_widget_tostring(lua_State *L) luaA_widget_tostring(lua_State *L)
{ {
widget_t **p = luaL_checkudata(L, 1, "widget"); widget_t **p = luaA_checkudata(L, 1, "widget");
lua_pushfstring(L, "[widget udata(%p) name(%s)]", *p, (*p)->name); lua_pushfstring(L, "[widget udata(%p) name(%s)]", *p, (*p)->name);
return 1; return 1;
} }
@ -458,8 +458,8 @@ luaA_widget_tostring(lua_State *L)
static int static int
luaA_widget_eq(lua_State *L) luaA_widget_eq(lua_State *L)
{ {
widget_t **t1 = luaL_checkudata(L, 1, "widget"); widget_t **t1 = luaA_checkudata(L, 1, "widget");
widget_t **t2 = luaL_checkudata(L, 2, "widget"); widget_t **t2 = luaA_checkudata(L, 2, "widget");
lua_pushboolean(L, (*t1 == *t2)); lua_pushboolean(L, (*t1 == *t2));
return 1; return 1;
} }
@ -470,7 +470,7 @@ luaA_widget_eq(lua_State *L)
static int static int
luaA_widget_name_set(lua_State *L) luaA_widget_name_set(lua_State *L)
{ {
widget_t **widget = luaL_checkudata(L, 1, "widget"); widget_t **widget = luaA_checkudata(L, 1, "widget");
const char *name = luaL_checkstring(L, 2); const char *name = luaL_checkstring(L, 2);
p_delete(&(*widget)->name); p_delete(&(*widget)->name);
(*widget)->name = a_strdup(name); (*widget)->name = a_strdup(name);
@ -483,7 +483,7 @@ luaA_widget_name_set(lua_State *L)
static int static int
luaA_widget_name_get(lua_State *L) luaA_widget_name_get(lua_State *L)
{ {
widget_t **widget = luaL_checkudata(L, 1, "widget"); widget_t **widget = luaA_checkudata(L, 1, "widget");
lua_pushstring(L, (*widget)->name); lua_pushstring(L, (*widget)->name);
return 1; return 1;
} }
@ -495,7 +495,7 @@ luaA_widget_name_get(lua_State *L)
static int static int
luaA_widget_visible_set(lua_State *L) luaA_widget_visible_set(lua_State *L)
{ {
widget_t **widget = luaL_checkudata(L, 1, "widget"); widget_t **widget = luaA_checkudata(L, 1, "widget");
(*widget)->isvisible = luaA_checkboolean(L, 2); (*widget)->isvisible = luaA_checkboolean(L, 2);
widget_invalidate_bywidget(*widget); widget_invalidate_bywidget(*widget);
return 0; return 0;
@ -507,7 +507,7 @@ luaA_widget_visible_set(lua_State *L)
static int static int
luaA_widget_visible_get(lua_State *L) luaA_widget_visible_get(lua_State *L)
{ {
widget_t **widget = luaL_checkudata(L, 1, "widget"); widget_t **widget = luaA_checkudata(L, 1, "widget");
lua_pushboolean(L, (*widget)->isvisible); lua_pushboolean(L, (*widget)->isvisible);
return 1; return 1;
} }