lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Tue, 01 Jan 2019 23:51:04 +0000
 Andrew Gierth <> wrote:
<> writes:

temp> setmetatable ({}, {__gc = function() print(1) error("error") print(2) end}) temp> It looks like at the end, garbage collector also collects something required by error() function first. So there is no error message from the code above, lua 5.3.5.

"at the end"? If you mean when calling lua_close on the state, then the error() thrown is just ignored. __gc metamethods are always called via a pcall; in normal operation any error caught by that pcall is rethrown, interrupting the current round of finalization calls, but while closing the state it would be pointless to propagate the error (propagate it to what?) so it gets ignored instead.

I just wanted to use it as a hook to the "end of the script".
And find out that error() function does not work as usual.
I supposed it should be equal to automatic starting garbage collector as last step.

t = {}
setmetatable (t, {__gc = function() print(1) error("error") print(2) end})

t = nil