lua-users home
lua-l archive

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

> Is it legal to throw an error (e.g. call luaL_error(L, "some error"))
> within a __gc metamethod?

Yes, although not a good practice.

> What will happen to the table in this case, will it be free'd correctly?
> And especially what will be the behavior of lua_close(L)? Will the
> finallization of the Lua state be complete, or the error will interrupt it?

When closing a state, all finalizers are called in protected mode.
Therefore, any errors there only interrupt that specific finalizer;
everything else goes on normally. (In particular, the table itself is
free'd correctly. The two operations are unrelated.)  Until 5.3, these
errors are just ignored. Lua 5.4 will have a warning system that will
generate warnings in this case (without changing the current behavior).

-- Roberto