mirror of https://github.com/rusefi/lua.git
Tracebacks recognize metamethods '__close'
This commit is contained in:
parent
f645d31573
commit
fe040633a1
3
ldebug.c
3
ldebug.c
|
@ -651,6 +651,9 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
|
||||||
case OP_SHRI: case OP_SHLI:
|
case OP_SHRI: case OP_SHLI:
|
||||||
*name = "shift";
|
*name = "shift";
|
||||||
return "metamethod";
|
return "metamethod";
|
||||||
|
case OP_CLOSE: case OP_RETURN:
|
||||||
|
*name = "close";
|
||||||
|
return "metamethod";
|
||||||
default:
|
default:
|
||||||
return NULL; /* cannot find a reasonable name */
|
return NULL; /* cannot find a reasonable name */
|
||||||
}
|
}
|
||||||
|
|
|
@ -316,14 +316,27 @@ do -- errors in __close
|
||||||
assert(log[1] == 5 and log[2] == 4 and log[3] == 4 and log[4] == 4
|
assert(log[1] == 5 and log[2] == 4 and log[3] == 4 and log[4] == 4
|
||||||
and #log == 4)
|
and #log == 4)
|
||||||
|
|
||||||
-- error in toclose in vararg function
|
-- error leaving a block
|
||||||
function foo (...)
|
local function foo (...)
|
||||||
local x123 <close> = 10
|
do
|
||||||
|
local x1 <close> = func2close(function () error("Y") end)
|
||||||
|
local x123 <close> = func2close(function () error("X") end)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local st, msg = pcall(foo)
|
local st, msg = xpcall(foo, debug.traceback)
|
||||||
assert(string.find(msg, "'x123'"))
|
assert(string.match(msg, "^[^ ]* X"))
|
||||||
|
assert(string.find(msg, "in metamethod 'close'"))
|
||||||
|
|
||||||
|
-- error in toclose in vararg function
|
||||||
|
local function foo (...)
|
||||||
|
local x123 <close> = func2close(function () error("X") end)
|
||||||
|
end
|
||||||
|
|
||||||
|
local st, msg = xpcall(foo, debug.traceback)
|
||||||
|
assert(string.match(msg, "^[^ ]* X"))
|
||||||
|
|
||||||
|
assert(string.find(msg, "in metamethod 'close'"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue