[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Does it need to check the return value of non-void return value C APIs?
- From: Daurnimator <quae@...>
- Date: Wed, 15 Jul 2015 13:25:20 +1000
On 15 July 2015 at 13:17, Nan Xiao <firstname.lastname@example.org> wrote:
> Hi all,
> As a C programmer, I am a little confused whether need to check the return
> values of Lua C APIs.
> For example, I know if "lua_pcall" returns non-zero value, it means failed.
> But as other non-void return
> value functions, such as "lua_getglobal", doesn't it need to check the
> return value?
> I try to refer the manual, But the manual doesn't seem to give answers about
> whether need to check
> the return values of APIs.
> Best Regards
> Nan Xiao
You only need to check the return values if you care about the results :P
Nearly all lua C API functions will longjmp in case of error.
lua(L)_newstate and lua_pcall being notable exceptions.
Regarding lua_getglobal: With lua 5.3, most of the lua_get* functions
now return the type (they used to return void).
This is just 'free' information that will save you from calling
`lua_type` straight after.