Fix a "table expected instead of nil" error

It seems like with lots of bad luck, the garbage collector manages to "steal"
the table with the buttons right after we decided to use it. Evil collector!

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-09-16 19:02:15 +02:00
parent abf329d7d8
commit 71b15d292c
1 changed files with 9 additions and 5 deletions

View File

@ -73,8 +73,12 @@ function common.list_update(w, buttons, label, data, template, objects)
end
if buttons then
if not data[o] then
data[o] = { }
-- Use a local variable so that the garbage collector doesn't strike
-- between now and the :buttons() call.
local btns = data[o]
if not btns then
btns = {}
data[o] = btns
for kb, b in ipairs(buttons) do
-- Create a proxy button object: it will receive the real
-- press and release events, and will propagate them the the
@ -83,11 +87,11 @@ function common.list_update(w, buttons, label, data, template, objects)
local btn = capi.button { modifiers = b.modifiers, button = b.button }
btn:connect_signal("press", function () b:emit_signal("press", o) end)
btn:connect_signal("release", function () b:emit_signal("release", o) end)
data[o][#data[o] + 1] = btn
btns[#btns + 1] = btn
end
end
ib:buttons(data[o])
tb:buttons(data[o])
ib:buttons(btns)
tb:buttons(btns)
end
local text, bg, bg_image, icon = label(o)