Skip to content

Commit

Permalink
Repair LabelCallback and CmdLineAction error handling when no window …
Browse files Browse the repository at this point in the history
…is found (#4834)
  • Loading branch information
Edru2 committed Feb 20, 2021
1 parent 940585d commit 3ab8e63
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/TLuaInterpreter.cpp
Expand Up @@ -4056,7 +4056,7 @@ int TLuaInterpreter::setLabelCallback(lua_State* L, const QString& funcName)
return warnArgumentValue(L, __func__, QStringLiteral("'%1' is not a known function name - bug in Mudlet, please report it").arg(funcName));
}

if (lua_result) {
if (!lua_result) {
return warnArgumentValue(L, __func__, QStringLiteral("label name '%1' not found").arg(labelName));
}
lua_pushboolean(L, true);
Expand Down
48 changes: 8 additions & 40 deletions src/mudlet-lua/lua/GUIUtils.lua
Expand Up @@ -2285,13 +2285,13 @@ end
-- This wrapper gives callback functions the possibility to be used like
-- setCallBackFunction (name,function as string,args)
-- it is used by setLabelCallBack functions and setCmdLineAction
local function setActionCallback(callbackFunc, name, func, ...)
local function setActionCallback(callbackFunc, funcName, name, func, ...)
local nr = arg.n + 1
arg.n = arg.n + 1
if type(func) == "string" then
func = loadstring("return "..func.."(...)")
end
assert(type(func) == 'function', '<setActionCallback: bad argument #2 type (function expected, got '..type(func)..'!)>')
assert(type(func) == 'function', string.format('<%s: bad argument #2 type (function expected, got %s!)>', funcName, type(func)))
if nr > 1 then
return callbackFunc(name,
function(event)
Expand All @@ -2302,47 +2302,15 @@ local function setActionCallback(callbackFunc, name, func, ...)
func(unpack_w_nil(arg))
end )
end
callbackFunc(name, func)
return callbackFunc(name, func)
end

local setLC = setLC or setLabelClickCallback
function setLabelClickCallback (...)
setActionCallback(setLC, ...)
end

local setLDC = setLDC or setLabelDoubleClickCallback
function setLabelDoubleClickCallback (...)
setActionCallback(setLDC, ...)
end

local setLRC = setLRC or setLabelReleaseCallback
function setLabelReleaseCallback(...)
setActionCallback(setLRC, ...)
end

local setLMC = setLMC or setLabelMoveCallback
function setLabelMoveCallback(...)
setActionCallback(setLMC, ...)
end

local setLWC = setLWC or setLabelWheelCallback
function setLabelWheelCallback(...)
setActionCallback(setLWC, ...)
end

local setOnE = setOnE or setLabelOnEnter
function setLabelOnEnter(...)
setActionCallback(setOnE, ...)
end

local setOnL = setOnL or setLabelOnLeave
function setLabelOnLeave(...)
setActionCallback(setOnL,...)
end
local callBackFunc ={"setLabelClickCallback", "setLabelReleaseCallback", "setLabelMoveCallback", "setLabelWheelCallback", "setLabelOnEnter", "setLabelOnLeave", "setCmdLineAction"}

local setCmdLA = setCmdLA or setCmdLineAction
function setCmdLineAction(...)
setActionCallback(setCmdLA,...)
for i = 1, #callBackFunc do
local funcName = callBackFunc[i]
local callBackFunction = _G[funcName]
_G[funcName] = function(...) return setActionCallback(callBackFunction, funcName, ...) end
end

function resetUserWindowTitle(windowname)
Expand Down

0 comments on commit 3ab8e63

Please sign in to comment.