[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: luaL_newstate's panicf uses lua_tostring which can fail, is it safe in theory?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 22 Nov 2023 09:35:24 -0300
> Lua doc states that lua_tostring can fail on memory allocation: [-0,
> +0, m] (when it converts number to string?).
> In Lua doc §4.4 there's a complicated description, which if I got it
> correctly, implies that the panic function should use only API calls
> that cannot raise errors.
Yes, lua_tostring can fail only when it converts a number to a string.
So you are right, panic should not call it without ensuring that the
value is indeed a string.
> However when a memory allocation error occurs (is it LUA_ERRMEM?), doc
> states that for such errors Lua does not call the message handler.
> Is panic function a message handler?
No. Message handlers are associated with protected environments; see the
documentation for lua_pcall. Panic is called when there is no protected
environment and, therefore, no message handler.
-- Roberto