[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to find out whether there is a specific key for a given Lua table besides traversing the whole table?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 14 Jan 2021 11:08:59 -0300
> One more way with lua_isnil.
>
> lua_pushstring(L, "key");
> lua_rawget(L, 1); // Assuming table is at index 1
> if (lua_isnil(L, -1)) {
> // It's nil
> } else {
> // It's something else
> }
Or else:
lua_pushstring(L, "key");
if (lua_rawget(L, 1) == LUA_TNIL) { // Assuming table is at index 1
// It's nil
} else {
// It's something else
}
-- Roberto