Lua : How to check if one of the values associated with the specified key of a table is nil, from ap

Posted by felace on Stack Overflow See other posts from Stack Overflow or by felace
Published on 2010-04-24T18:32:11Z Indexed on 2010/04/24 18:33 UTC
Read the original article Hit count: 154

Filed under:

In lua, it's legal to do this :

table={}
bar
if(table[key]==nil)
foo

However, using C API, I couldn't find way to check if there's a nil value on the specified position.

lua_getglobal(L,"table");
lua_gettable(L,key);

If there's a nil value stored in table[key], lua_gettable would give me the "unprotected error in call to Lua API (attempt to index a nil value)" message.

Is there any way to check if there's actually something associated with that key, before actually pushing the key to do so ?

© Stack Overflow or respective owner

Related posts about lua