Fix menubar under Lua 5.1 (#1838)

LGI's async support was trying to yield inside a protected call. Lua 5.1
cannot do that. Work around this by reverting to the behaviour before
commit 50cfa6c: Only call the callback in a protected context.

Fixes: https://github.com/awesomeWM/awesome/issues/1837
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2017-06-13 01:59:30 +02:00 committed by Daniel Hahler
parent ef1d7d8396
commit bcc3de469e
1 changed files with 24 additions and 2 deletions

View File

@ -43,6 +43,28 @@ utils.wm_name = "awesome"
-- Private section
local do_protected_call, call_callback
do
-- Lua 5.1 cannot yield across a protected call. Instead of hardcoding a
-- check, we check for this problem: The following coroutine yields true on
-- success (so resume() returns true, true). On failure, pcall returns
-- false and a message, so resume() returns true, false, message.
local _, has_yieldable_pcall = coroutine.resume(coroutine.create(function()
return pcall(coroutine.yield, true)
end))
if has_yieldable_pcall then
do_protected_call = protected_call.call
call_callback = function(callback, ...)
return callback(...)
end
else
do_protected_call = function(f, ...)
return f(...)
end
call_callback = protected_call.call
end
end
local all_icon_sizes = {
'128x128' ,
'96x96',
@ -298,10 +320,10 @@ function utils.parse_dir(dir_path, callback)
enum:async_close()
end
gio.Async.start(protected_call.call)(function()
gio.Async.start(do_protected_call)(function()
local result = {}
parser(gio.File.new_for_path(dir_path), result)
callback(result)
call_callback(callback, result)
end)
end