lua_gc not documented as possibly raising errors

69 views
Skip to first unread message

Edoardo Lolletti

unread,
May 23, 2025, 12:44:39 PMMay 23
to lu...@googlegroups.com
Currently the reference manual lists lua_gc as not raising any error,
but it can indeed raise them as it can end up calling a __gc metamethod,
thus running arbitary lua code and possibly raising errors.

Sainan

unread,
May 23, 2025, 12:49:24 PMMay 23
to lu...@googlegroups.com
No, errors raised in __gc metamethods are special in that such errors are demoted to warnings, e.g.:

setmetatable({}, {
__gc = function() error("oops") end
})

will exit successfully, and if you enable warnings, it'll print:

warning: error in __gc (index.pluto:2: oops)

-- Sainan

Edoardo Lolletti

unread,
May 23, 2025, 1:09:18 PMMay 23
to 'Sainan' via lua-l
I see, I had forgotten about that detail, thanks
Reply all
Reply to author
Forward
0 new messages