lua: replace .new() by __call meth

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-30 14:01:55 +02:00
parent f2d2a10d9b
commit 45b0a2df80
8 changed files with 121 additions and 117 deletions

View File

@ -65,7 +65,7 @@ for s = 1, screen.count() do
tags[s] = {} tags[s] = {}
-- Create 9 tags per screen -- Create 9 tags per screen
for tagnumber = 1, 9 do for tagnumber = 1, 9 do
tags[s][tagnumber] = tag.new({ name = tagnumber, layout = layouts[1] }) tags[s][tagnumber] = tag({ name = tagnumber, layout = layouts[1] })
-- Add tags to screen one by one -- Add tags to screen one by one
tags[s][tagnumber]:mwfact_set(0.618033988769) tags[s][tagnumber]:mwfact_set(0.618033988769)
tags[s][tagnumber]:add(s) tags[s][tagnumber]:add(s)
@ -77,51 +77,51 @@ end
-- {{{ Statusbar -- {{{ Statusbar
-- Create a taglist widget -- Create a taglist widget
mytaglist = widget.new({ type = "taglist", name = "mytaglist" }) mytaglist = widget({ type = "taglist", name = "mytaglist" })
mytaglist:mouse_add(mouse.new({}, 1, function (object, tag) awful.tag.viewonly(tag) end)) mytaglist:mouse_add(mouse({}, 1, function (object, tag) awful.tag.viewonly(tag) end))
mytaglist:mouse_add(mouse.new({ modkey }, 1, function (object, tag) awful.client.movetotag(tag) end)) mytaglist:mouse_add(mouse({ modkey }, 1, function (object, tag) awful.client.movetotag(tag) end))
mytaglist:mouse_add(mouse.new({}, 3, function (object, tag) tag:view(not tag:isselected()) end)) mytaglist:mouse_add(mouse({}, 3, function (object, tag) tag:view(not tag:isselected()) end))
mytaglist:mouse_add(mouse.new({ modkey }, 3, function (object, tag) awful.client.toggletag(tag) end)) mytaglist:mouse_add(mouse({ modkey }, 3, function (object, tag) awful.client.toggletag(tag) end))
mytaglist:mouse_add(mouse.new({ }, 4, awful.tag.viewnext)) mytaglist:mouse_add(mouse({ }, 4, awful.tag.viewnext))
mytaglist:mouse_add(mouse.new({ }, 5, awful.tag.viewprev)) mytaglist:mouse_add(mouse({ }, 5, awful.tag.viewprev))
mytaglist.text_focus = "<bg color='"..bg_focus.."'/> <span color='"..fg_focus.."'><title/></span> " mytaglist.text_focus = "<bg color='"..bg_focus.."'/> <span color='"..fg_focus.."'><title/></span> "
-- Create a tasklist widget -- Create a tasklist widget
mytasklist = widget.new({ type = "tasklist", name = "mytasklist" }) mytasklist = widget({ type = "tasklist", name = "mytasklist" })
mytasklist:mouse_add(mouse.new({ }, 1, function (object, c) c:focus_set(); c:raise() end)) mytasklist:mouse_add(mouse({ }, 1, function (object, c) c:focus_set(); c:raise() end))
mytasklist:mouse_add(mouse.new({ }, 4, function () awful.client.focus(1) end)) mytasklist:mouse_add(mouse({ }, 4, function () awful.client.focus(1) end))
mytasklist:mouse_add(mouse.new({ }, 5, function () awful.client.focus(-1) end)) mytasklist:mouse_add(mouse({ }, 5, function () awful.client.focus(-1) end))
mytasklist.text_focus = "<bg color='"..bg_focus.."'/> <span color='"..fg_focus.."'><title/></span> " mytasklist.text_focus = "<bg color='"..bg_focus.."'/> <span color='"..fg_focus.."'><title/></span> "
-- Create a textbox widget -- Create a textbox widget
mytextbox = widget.new({ type = "textbox", name = "mytextbox", align = "right" }) mytextbox = widget({ type = "textbox", name = "mytextbox", align = "right" })
-- Set the default text in textbox -- Set the default text in textbox
mytextbox.text = "<b><small> awesome " .. AWESOME_VERSION .. " </small></b>" mytextbox.text = "<b><small> awesome " .. AWESOME_VERSION .. " </small></b>"
mypromptbox = widget.new({ type = "textbox", name = "mypromptbox", align = "left" }) mypromptbox = widget({ type = "textbox", name = "mypromptbox", align = "left" })
-- Create an iconbox widget -- Create an iconbox widget
myiconbox = widget.new({ type = "textbox", name = "myiconbox", align = "left" }) myiconbox = widget({ type = "textbox", name = "myiconbox", align = "left" })
myiconbox.text = "<bg image=\"@AWESOME_ICON_PATH@/awesome16.png\" resize=\"true\"/>" myiconbox.text = "<bg image=\"@AWESOME_ICON_PATH@/awesome16.png\" resize=\"true\"/>"
-- Create a systray -- Create a systray
mysystray = widget.new({ type = "systray", name = "mysystray", align = "right" }) mysystray = widget({ type = "systray", name = "mysystray", align = "right" })
-- Create an iconbox widget which will contains an icon indicating which layout we're using. -- Create an iconbox widget which will contains an icon indicating which layout we're using.
-- We need one layoutbox per screen. -- We need one layoutbox per screen.
mylayoutbox = {} mylayoutbox = {}
for s = 1, screen.count() do for s = 1, screen.count() do
mylayoutbox[s] = widget.new({ type = "textbox", name = "mylayoutbox", align = "right" }) mylayoutbox[s] = widget({ type = "textbox", name = "mylayoutbox", align = "right" })
mylayoutbox[s]:mouse_add(mouse.new({ }, 1, function () awful.layout.inc(layouts, 1) end)) mylayoutbox[s]:mouse_add(mouse({ }, 1, function () awful.layout.inc(layouts, 1) end))
mylayoutbox[s]:mouse_add(mouse.new({ }, 3, function () awful.layout.inc(layouts, -1) end)) mylayoutbox[s]:mouse_add(mouse({ }, 3, function () awful.layout.inc(layouts, -1) end))
mylayoutbox[s]:mouse_add(mouse.new({ }, 4, function () awful.layout.inc(layouts, 1) end)) mylayoutbox[s]:mouse_add(mouse({ }, 4, function () awful.layout.inc(layouts, 1) end))
mylayoutbox[s]:mouse_add(mouse.new({ }, 5, function () awful.layout.inc(layouts, -1) end)) mylayoutbox[s]:mouse_add(mouse({ }, 5, function () awful.layout.inc(layouts, -1) end))
mylayoutbox[s].text = "<bg image=\"@AWESOME_ICON_PATH@/layouts/tilew.png\" resize=\"true\"/>" mylayoutbox[s].text = "<bg image=\"@AWESOME_ICON_PATH@/layouts/tilew.png\" resize=\"true\"/>"
end end
-- Create a statusbar for each screen and add it -- Create a statusbar for each screen and add it
mystatusbar = {} mystatusbar = {}
for s = 1, screen.count() do for s = 1, screen.count() do
mystatusbar[s] = statusbar.new({ position = "top", name = "mystatusbar" .. s, mystatusbar[s] = statusbar({ position = "top", name = "mystatusbar" .. s,
fg = fg_normal, bg = bg_normal }) fg = fg_normal, bg = bg_normal })
-- Add widgets to the statusbar - order matters -- Add widgets to the statusbar - order matters
mystatusbar[s]:widget_add(mytaglist) mystatusbar[s]:widget_add(mytaglist)
@ -136,9 +136,9 @@ mystatusbar[screen.count()]:widget_add(mysystray)
-- }}} -- }}}
-- {{{ Mouse bindings -- {{{ Mouse bindings
awesome.mouse_add(mouse.new({ }, 3, function () awful.spawn(terminal) end)) awesome.mouse_add(mouse({ }, 3, function () awful.spawn(terminal) end))
awesome.mouse_add(mouse.new({ }, 4, awful.tag.viewnext)) awesome.mouse_add(mouse({ }, 4, awful.tag.viewnext))
awesome.mouse_add(mouse.new({ }, 5, awful.tag.viewprev)) awesome.mouse_add(mouse({ }, 5, awful.tag.viewprev))
-- }}} -- }}}
-- {{{ Key bindings -- {{{ Key bindings
@ -151,28 +151,28 @@ for s = 1, screen.count() do
end end
for i = 1, keynumber do for i = 1, keynumber do
keybinding.new({ modkey }, i, keybinding({ modkey }, i,
function () function ()
local screen = mouse.screen_get() local screen = mouse.screen_get()
if tags[screen][i] then if tags[screen][i] then
awful.tag.viewonly(tags[screen][i]) awful.tag.viewonly(tags[screen][i])
end end
end):add() end):add()
keybinding.new({ modkey, "Control" }, i, keybinding({ modkey, "Control" }, i,
function () function ()
local screen = mouse.screen_get() local screen = mouse.screen_get()
if tags[screen][i] then if tags[screen][i] then
tags[screen][i]:view(not tags[screen][i]:isselected()) tags[screen][i]:view(not tags[screen][i]:isselected())
end end
end):add() end):add()
keybinding.new({ modkey, "Shift" }, i, keybinding({ modkey, "Shift" }, i,
function () function ()
local screen = mouse.screen_get() local screen = mouse.screen_get()
if tags[screen][i] then if tags[screen][i] then
awful.client.movetotag(tags[screen][i]) awful.client.movetotag(tags[screen][i])
end end
end):add() end):add()
keybinding.new({ modkey, "Control", "Shift" }, i, keybinding({ modkey, "Control", "Shift" }, i,
function () function ()
local screen = mouse.screen_get() local screen = mouse.screen_get()
if tags[screen][i] then if tags[screen][i] then
@ -181,47 +181,47 @@ for i = 1, keynumber do
end):add() end):add()
end end
keybinding.new({ modkey }, "Left", awful.tag.viewprev):add() keybinding({ modkey }, "Left", awful.tag.viewprev):add()
keybinding.new({ modkey }, "Right", awful.tag.viewnext):add() keybinding({ modkey }, "Right", awful.tag.viewnext):add()
-- Standard program -- Standard program
keybinding.new({ modkey }, "Return", function () awful.spawn(terminal) end):add() keybinding({ modkey }, "Return", function () awful.spawn(terminal) end):add()
keybinding.new({ modkey, "Control" }, "r", awesome.restart):add() keybinding({ modkey, "Control" }, "r", awesome.restart):add()
keybinding.new({ modkey, "Shift" }, "q", awesome.quit):add() keybinding({ modkey, "Shift" }, "q", awesome.quit):add()
-- Client manipulation -- Client manipulation
keybinding.new({ modkey, "Shift" }, "c", function () client.focus_get():kill() end):add() keybinding({ modkey, "Shift" }, "c", function () client.focus_get():kill() end):add()
keybinding.new({ modkey }, "j", function () awful.client.focus(1); client.focus_get():raise() end):add() keybinding({ modkey }, "j", function () awful.client.focus(1); client.focus_get():raise() end):add()
keybinding.new({ modkey }, "k", function () awful.client.focus(-1); client.focus_get():raise() end):add() keybinding({ modkey }, "k", function () awful.client.focus(-1); client.focus_get():raise() end):add()
keybinding.new({ modkey, "Shift" }, "j", function () awful.client.swap(1) end):add() keybinding({ modkey, "Shift" }, "j", function () awful.client.swap(1) end):add()
keybinding.new({ modkey, "Shift" }, "k", function () awful.client.swap(-1) end):add() keybinding({ modkey, "Shift" }, "k", function () awful.client.swap(-1) end):add()
keybinding.new({ modkey, "Control" }, "j", function () awful.screen.focus(1) end):add() keybinding({ modkey, "Control" }, "j", function () awful.screen.focus(1) end):add()
keybinding.new({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end):add() keybinding({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end):add()
keybinding.new({ modkey, "Control" }, "space", awful.client.togglefloating):add() keybinding({ modkey, "Control" }, "space", awful.client.togglefloating):add()
keybinding.new({ modkey, "Control" }, "Return", function () client.focus_get():swap(awful.client.master()) end):add() keybinding({ modkey, "Control" }, "Return", function () client.focus_get():swap(awful.client.master()) end):add()
keybinding.new({ modkey }, "o", awful.client.movetoscreen):add() keybinding({ modkey }, "o", awful.client.movetoscreen):add()
-- Layout manipulation -- Layout manipulation
keybinding.new({ modkey }, "l", function () awful.tag.incmwfact(0.05) end):add() keybinding({ modkey }, "l", function () awful.tag.incmwfact(0.05) end):add()
keybinding.new({ modkey }, "h", function () awful.tag.incmwfact(-0.05) end):add() keybinding({ modkey }, "h", function () awful.tag.incmwfact(-0.05) end):add()
keybinding.new({ modkey, "Shift" }, "h", function () awful.tag.incnmaster(1) end):add() keybinding({ modkey, "Shift" }, "h", function () awful.tag.incnmaster(1) end):add()
keybinding.new({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end):add() keybinding({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end):add()
keybinding.new({ modkey, "Control" }, "h", function () awful.tag.incncol(1) end):add() keybinding({ modkey, "Control" }, "h", function () awful.tag.incncol(1) end):add()
keybinding.new({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end):add() keybinding({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end):add()
keybinding.new({ modkey }, "space", function () awful.layout.inc(layouts, 1) end):add() keybinding({ modkey }, "space", function () awful.layout.inc(layouts, 1) end):add()
keybinding.new({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end):add() keybinding({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end):add()
-- Prompt -- Prompt
keybinding.new({ modkey }, "F1", function () keybinding({ modkey }, "F1", function ()
awful.prompt({ prompt = "Run: ", cursor_fg = fg_focus, cursor_bg = bg_focus }, mypromptbox, awful.spawn, awful.completion.bash) awful.prompt({ prompt = "Run: ", cursor_fg = fg_focus, cursor_bg = bg_focus }, mypromptbox, awful.spawn, awful.completion.bash)
end):add() end):add()
keybinding.new({ modkey }, "F4", function () keybinding({ modkey }, "F4", function ()
awful.prompt({ prompt = "Run Lua code: ", cursor_fg = fg_focus, cursor_bg = bg_focus }, mypromptbox, awful.eval, awful.prompt.bash) awful.prompt({ prompt = "Run Lua code: ", cursor_fg = fg_focus, cursor_bg = bg_focus }, mypromptbox, awful.eval, awful.prompt.bash)
end):add() end):add()
--- Tabulous, tab manipulation --- Tabulous, tab manipulation
keybinding.new({ modkey, "Control" }, "y", function () keybinding({ modkey, "Control" }, "y", function ()
local tabbedview = tabulous.tabindex_get() local tabbedview = tabulous.tabindex_get()
local nextclient = awful.client.next(1) local nextclient = awful.client.next(1)
@ -239,9 +239,9 @@ keybinding.new({ modkey, "Control" }, "y", function ()
end end
end):add() end):add()
keybinding.new({ modkey, "Shift" }, "y", tabulous.untab):add() keybinding({ modkey, "Shift" }, "y", tabulous.untab):add()
keybinding.new({ modkey }, "y", function () keybinding({ modkey }, "y", function ()
local tabbedview = tabulous.tabindex_get() local tabbedview = tabulous.tabindex_get()
if tabbedview ~= nil then if tabbedview ~= nil then
@ -251,8 +251,8 @@ keybinding.new({ modkey }, "y", function ()
end):add() end):add()
-- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
keybinding.new({ modkey }, "t", awful.client.togglemarked):add() keybinding({ modkey }, "t", awful.client.togglemarked):add()
keybinding.new({ modkey, 'Shift' }, "t", function () keybinding({ modkey, 'Shift' }, "t", function ()
local tabbedview = tabulous.tabindex_get() local tabbedview = tabulous.tabindex_get()
local clients = awful.client.getmarked() local clients = awful.client.getmarked()
@ -268,7 +268,7 @@ keybinding.new({ modkey, 'Shift' }, "t", function ()
end):add() end):add()
for i = 1, keynumber do for i = 1, keynumber do
keybinding.new({ modkey, "Shift" }, "F" .. i, keybinding({ modkey, "Shift" }, "F" .. i,
function () function ()
local screen = mouse.screen_get() local screen = mouse.screen_get()
if tags[screen][i] then if tags[screen][i] then
@ -316,9 +316,9 @@ end
-- Hook function to execute when a new client appears. -- Hook function to execute when a new client appears.
function hook_manage(c) function hook_manage(c)
-- Add mouse bindings -- Add mouse bindings
c:mouse_add(mouse.new({ }, 1, function (c) c:focus_set(); c:raise() end)) c:mouse_add(mouse({ }, 1, function (c) c:focus_set(); c:raise() end))
c:mouse_add(mouse.new({ modkey }, 1, function (c) c:mouse_move() end)) c:mouse_add(mouse({ modkey }, 1, function (c) c:mouse_move() end))
c:mouse_add(mouse.new({ modkey }, 3, function (c) c:mouse_resize() end)) c:mouse_add(mouse({ modkey }, 3, function (c) c:mouse_resize() end))
-- New client may not receive focus -- New client may not receive focus
-- if they're not focusable, so set border anyway. -- if they're not focusable, so set border anyway.
c:border_set({ width = border_width, color = border_normal }) c:border_set({ width = border_width, color = border_normal })

View File

@ -70,10 +70,12 @@ for i, line in ipairs(ilines) do
else else
local fctname, fctdef local fctname, fctdef
_, _, fctname, fctdef = line:find("\"(.+)\", (.+) },?") _, _, fctname, fctdef = line:find("\"(.+)\", (.+) },?")
if fctname and not fctname:find("^__") then if fctname and (not fctname:find("^__") or fctname:find("^__call")) then
if function_doc[fctdef] then if function_doc[fctdef] then
fctname = "." .. fctname
fctname = fctname:gsub("^.__call", "")
print(function_doc[fctdef]:comment_translate()) print(function_doc[fctdef]:comment_translate())
print("function " .. libname .. "." .. fctname .. "()") print("function " .. libname .. fctname .. "()")
print("end"); print("end");
else else
print("This function is not yet documented.") print("This function is not yet documented.")

View File

@ -184,22 +184,22 @@ luaA_keybinding_new(lua_State *L)
keybinding_t *k; keybinding_t *k;
const char *key; const char *key;
/* arg 1 is key mod table */ /* arg 2 is key mod table */
luaA_checktable(L, 1); luaA_checktable(L, 2);
/* arg 2 is key */ /* arg 3 is key */
key = luaL_checkstring(L, 2); key = luaL_checkstring(L, 3);
/* arg 3 is cmd to run */ /* arg 4 is cmd to run */
luaA_checkfunction(L, 3); luaA_checkfunction(L, 4);
/* get the last arg as function */ /* get the last arg as function */
k = p_new(keybinding_t, 1); k = p_new(keybinding_t, 1);
__luaA_keystore(k, key); __luaA_keystore(k, key);
k->fct = luaL_ref(L, LUA_REGISTRYINDEX); k->fct = luaL_ref(L, LUA_REGISTRYINDEX);
len = lua_objlen(L, 1); len = lua_objlen(L, 2);
for(i = 1; i <= len; i++) for(i = 1; i <= len; i++)
{ {
lua_rawgeti(L, 1, i); lua_rawgeti(L, 2, i);
k->mod |= xutil_keymask_fromstr(luaL_checkstring(L, -1)); k->mod |= xutil_keymask_fromstr(luaL_checkstring(L, -1));
} }
@ -248,7 +248,7 @@ luaA_keybinding_tostring(lua_State *L)
const struct luaL_reg awesome_keybinding_methods[] = const struct luaL_reg awesome_keybinding_methods[] =
{ {
{ "new", luaA_keybinding_new }, { "__call", luaA_keybinding_new },
{ NULL, NULL } { NULL, NULL }
}; };
const struct luaL_reg awesome_keybinding_meta[] = const struct luaL_reg awesome_keybinding_meta[] =

12
mouse.c
View File

@ -1136,20 +1136,20 @@ luaA_mouse_new(lua_State *L)
int i, len; int i, len;
button_t *button; button_t *button;
luaA_checktable(L, 1); luaA_checktable(L, 2);
/* arg 3 is mouse button */ /* arg 3 is mouse button */
i = luaL_checknumber(L, 2); i = luaL_checknumber(L, 3);
/* arg 4 is cmd to run */ /* arg 4 is cmd to run */
luaA_checkfunction(L, 3); luaA_checkfunction(L, 4);
button = p_new(button_t, 1); button = p_new(button_t, 1);
button->button = xutil_button_fromint(i); button->button = xutil_button_fromint(i);
button->fct = luaL_ref(L, LUA_REGISTRYINDEX); button->fct = luaL_ref(L, LUA_REGISTRYINDEX);
len = lua_objlen(L, 1); len = lua_objlen(L, 2);
for(i = 1; i <= len; i++) for(i = 1; i <= len; i++)
{ {
lua_rawgeti(L, 1, i); lua_rawgeti(L, 2, i);
button->mod |= xutil_keymask_fromstr(luaL_checkstring(L, -1)); button->mod |= xutil_keymask_fromstr(luaL_checkstring(L, -1));
} }
@ -1158,7 +1158,7 @@ luaA_mouse_new(lua_State *L)
const struct luaL_reg awesome_mouse_methods[] = const struct luaL_reg awesome_mouse_methods[] =
{ {
{ "new", luaA_mouse_new }, { "__call", luaA_mouse_new },
{ "screen_get", luaA_mouse_screen_get }, { "screen_get", luaA_mouse_screen_get },
{ "coords_set", luaA_mouse_coords_set }, { "coords_set", luaA_mouse_coords_set },
{ "coords_get", luaA_mouse_coords_get }, { "coords_get", luaA_mouse_coords_get },

View File

@ -538,37 +538,37 @@ luaA_statusbar_new(lua_State *L)
const char *buf; const char *buf;
size_t len; size_t len;
luaA_checktable(L, 1); luaA_checktable(L, 2);
if(!(buf = luaA_getopt_string(L, 1, "name", NULL))) if(!(buf = luaA_getopt_string(L, 2, "name", NULL)))
luaL_error(L, "object statusbar must have a name"); luaL_error(L, "object statusbar must have a name");
sb = p_new(statusbar_t, 1); sb = p_new(statusbar_t, 1);
sb->name = a_strdup(buf); sb->name = a_strdup(buf);
if(!(buf = luaA_getopt_string(L, 1, "fg", NULL)) if(!(buf = luaA_getopt_string(L, 2, "fg", NULL))
|| !xcolor_new(globalconf.connection, globalconf.default_screen, || !xcolor_new(globalconf.connection, globalconf.default_screen,
buf, &sb->colors.fg)) buf, &sb->colors.fg))
sb->colors.fg = xcolor_copy(&globalconf.colors.fg); sb->colors.fg = xcolor_copy(&globalconf.colors.fg);
if(!(buf = luaA_getopt_string(L, 1, "bg", NULL)) if(!(buf = luaA_getopt_string(L, 2, "bg", NULL))
|| !xcolor_new(globalconf.connection, globalconf.default_screen, || !xcolor_new(globalconf.connection, globalconf.default_screen,
buf, &sb->colors.bg)) buf, &sb->colors.bg))
sb->colors.bg = xcolor_copy(&globalconf.colors.bg); sb->colors.bg = xcolor_copy(&globalconf.colors.bg);
buf = luaA_getopt_lstring(L, 1, "align", "left", &len); buf = luaA_getopt_lstring(L, 2, "align", "left", &len);
sb->align = draw_align_fromstr(buf, len); sb->align = draw_align_fromstr(buf, len);
sb->width = luaA_getopt_number(L, 1, "width", 0); sb->width = luaA_getopt_number(L, 2, "width", 0);
if(sb->width > 0) if(sb->width > 0)
sb->width_user = true; sb->width_user = true;
sb->height = luaA_getopt_number(L, 1, "height", 0); sb->height = luaA_getopt_number(L, 2, "height", 0);
if(sb->height <= 0) if(sb->height <= 0)
/* 1.5 as default factor, it fits nice but no one knows why */ /* 1.5 as default factor, it fits nice but no one knows why */
sb->height = 1.5 * globalconf.font->height; sb->height = 1.5 * globalconf.font->height;
buf = luaA_getopt_lstring(L, 1, "position", "top", &len); buf = luaA_getopt_lstring(L, 2, "position", "top", &len);
sb->position = position_fromstr(buf, len); sb->position = position_fromstr(buf, len);
return luaA_statusbar_userdata_new(L, sb); return luaA_statusbar_userdata_new(L, sb);
@ -603,7 +603,7 @@ luaA_statusbar_widget_get(lua_State *L)
const struct luaL_reg awesome_statusbar_methods[] = const struct luaL_reg awesome_statusbar_methods[] =
{ {
{ "new", luaA_statusbar_new }, { "__call", luaA_statusbar_new },
{ NULL, NULL } { NULL, NULL }
}; };
const struct luaL_reg awesome_statusbar_meta[] = const struct luaL_reg awesome_statusbar_meta[] =

14
tag.c
View File

@ -314,15 +314,15 @@ luaA_tag_new(lua_State *L)
double mwfact; double mwfact;
layout_t *layout; layout_t *layout;
luaA_checktable(L, 1); luaA_checktable(L, 2);
if(!(name = luaA_getopt_string(L, 1, "name", NULL))) if(!(name = luaA_getopt_string(L, 2, "name", NULL)))
luaL_error(L, "object tag must have a name"); luaL_error(L, "object tag must have a name");
mwfact = luaA_getopt_number(L, 1, "mwfact", 0.5); mwfact = luaA_getopt_number(L, 2, "mwfact", 0.5);
ncol = luaA_getopt_number(L, 1, "ncol", 1); ncol = luaA_getopt_number(L, 2, "ncol", 1);
nmaster = luaA_getopt_number(L, 1, "nmaster", 1); nmaster = luaA_getopt_number(L, 2, "nmaster", 1);
lay = luaA_getopt_string(L, 1, "layout", "tile"); lay = luaA_getopt_string(L, 2, "layout", "tile");
layout = name_func_lookup(lay, LayoutList); layout = name_func_lookup(lay, LayoutList);
@ -560,7 +560,7 @@ luaA_tag_layout_set(lua_State *L)
const struct luaL_reg awesome_tag_methods[] = const struct luaL_reg awesome_tag_methods[] =
{ {
{ "new", luaA_tag_new }, { "__call", luaA_tag_new },
{ "get", luaA_tag_get }, { "get", luaA_tag_get },
{ "geti", luaA_tag_geti }, { "geti", luaA_tag_geti },
{ NULL, NULL } { NULL, NULL }

View File

@ -298,38 +298,38 @@ luaA_titlebar_new(lua_State *L)
const char *buf; const char *buf;
size_t len; size_t len;
luaA_checktable(L, 1); luaA_checktable(L, 2);
tb = p_new(titlebar_t, 1); tb = p_new(titlebar_t, 1);
buf = luaA_getopt_lstring(L, 1, "align", "left", &len); buf = luaA_getopt_lstring(L, 2, "align", "left", &len);
tb->align = draw_align_fromstr(buf, len); tb->align = draw_align_fromstr(buf, len);
tb->width = luaA_getopt_number(L, 1, "width", 0); tb->width = luaA_getopt_number(L, 2, "width", 0);
tb->height = luaA_getopt_number(L, 1, "height", 0); tb->height = luaA_getopt_number(L, 2, "height", 0);
if(tb->height <= 0) if(tb->height <= 0)
/* 1.5 as default factor, it fits nice but no one knows why */ /* 1.5 as default factor, it fits nice but no one knows why */
tb->height = 1.5 * globalconf.font->height; tb->height = 1.5 * globalconf.font->height;
buf = luaA_getopt_lstring(L, 1, "position", "top", &len); buf = luaA_getopt_lstring(L, 2, "position", "top", &len);
tb->position = position_fromstr(buf, len); tb->position = position_fromstr(buf, len);
if(!(buf = luaA_getopt_string(L, 1, "fg", NULL)) if(!(buf = luaA_getopt_string(L, 2, "fg", NULL))
|| !xcolor_new(globalconf.connection, globalconf.default_screen, || !xcolor_new(globalconf.connection, globalconf.default_screen,
buf, &tb->colors.fg)) buf, &tb->colors.fg))
tb->colors.fg = xcolor_copy(&globalconf.colors.fg); tb->colors.fg = xcolor_copy(&globalconf.colors.fg);
if(!(buf = luaA_getopt_string(L, 1, "bg", NULL)) if(!(buf = luaA_getopt_string(L, 2, "bg", NULL))
|| !xcolor_new(globalconf.connection, globalconf.default_screen, || !xcolor_new(globalconf.connection, globalconf.default_screen,
buf, &tb->colors.bg)) buf, &tb->colors.bg))
tb->colors.bg = xcolor_copy(&globalconf.colors.bg); tb->colors.bg = xcolor_copy(&globalconf.colors.bg);
if(!(buf = luaA_getopt_string(L, 1, "border_color", NULL)) if(!(buf = luaA_getopt_string(L, 2, "border_color", NULL))
|| !xcolor_new(globalconf.connection, globalconf.default_screen, || !xcolor_new(globalconf.connection, globalconf.default_screen,
buf, &tb->border.color)) buf, &tb->border.color))
tb->border.color = xcolor_copy(&globalconf.colors.fg); tb->border.color = xcolor_copy(&globalconf.colors.fg);
tb->border.width = luaA_getopt_number(L, 1, "border_width", 0); tb->border.width = luaA_getopt_number(L, 2, "border_width", 0);
return luaA_titlebar_userdata_new(globalconf.L, tb); return luaA_titlebar_userdata_new(globalconf.L, tb);
} }
@ -502,7 +502,7 @@ luaA_titlebar_tostring(lua_State *L)
const struct luaL_reg awesome_titlebar_methods[] = const struct luaL_reg awesome_titlebar_methods[] =
{ {
{ "new", luaA_titlebar_new }, { "__call", luaA_titlebar_new },
{ NULL, NULL } { NULL, NULL }
}; };
const struct luaL_reg awesome_titlebar_meta[] = const struct luaL_reg awesome_titlebar_meta[] =

View File

@ -264,21 +264,21 @@ widget_invalidate_bywidget(widget_t *widget)
static int static int
luaA_widget_new(lua_State *L) luaA_widget_new(lua_State *L)
{ {
const char *type, *buf; const char *buf, *type;
widget_t *w = NULL; widget_t *w = NULL;
widget_constructor_t *wc; widget_constructor_t *wc;
alignment_t align; alignment_t align;
size_t len; size_t len;
luaA_checktable(L, 1); luaA_checktable(L, 2);
buf = luaA_getopt_lstring(L, 1, "align", "left", &len); buf = luaA_getopt_lstring(L, 2, "align", "left", &len);
align = draw_align_fromstr(buf, len); align = draw_align_fromstr(buf, len);
if(!(buf = luaA_getopt_string(L, 1, "name", NULL))) if(!(buf = luaA_getopt_string(L, 2, "name", NULL)))
luaL_error(L, "object widget must have a name"); luaL_error(L, "object widget must have a name");
type = luaA_getopt_string(L, 1, "type", NULL); type = luaA_getopt_string(L, 2, "type", NULL);
if((wc = name_func_lookup(type, WidgetList))) if((wc = name_func_lookup(type, WidgetList)))
w = wc(align); w = wc(align);
@ -422,14 +422,16 @@ luaA_widget_index(lua_State *L)
{ {
widget_t **widget = luaA_checkudata(L, 1, "widget"); widget_t **widget = luaA_checkudata(L, 1, "widget");
lua_getmetatable(L, 1); /* 1 */ lua_getmetatable(L, 1);
lua_pushvalue(L, 2); /* 2 */ lua_pushvalue(L, 2);
lua_rawget(L, -2); /* 2 */ lua_rawget(L, -2);
if (!lua_isnil(L, -1)) { if (!lua_isnil(L, -1))
lua_remove(L, -2); /* 1 */ {
lua_remove(L, -2);
return 1; return 1;
} }
lua_pop(L, 2); lua_pop(L, 2);
return (*widget)->index ? (*widget)->index(L) : 0; return (*widget)->index ? (*widget)->index(L) : 0;
} }
@ -450,7 +452,7 @@ luaA_widget_newindex(lua_State *L)
const struct luaL_reg awesome_widget_methods[] = const struct luaL_reg awesome_widget_methods[] =
{ {
{ "new", luaA_widget_new }, { "__call", luaA_widget_new },
{ NULL, NULL } { NULL, NULL }
}; };
const struct luaL_reg awesome_widget_meta[] = const struct luaL_reg awesome_widget_meta[] =