lua-users home
lua-l archive

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


Peter Loveday wrote:
> 
> I'm getting an intermitant crash in Lua 5 Beta attempting to retrieve an
> upvalue that does not exist.
> 
> The code that is a problem in this case is:
> 
>     ptr = lua_touserdata(L, lua_upvalueindex(2))
> 
> I only have 1 upvalue in this case (though at times I might have 2); I had
> assumed this would return NULL, but it doesn't seem to do so reliably.
> 
> Is there a fix for this, or, alternatively, can I tell how many upvalues I
> was passed so as to prevent my code querying the second value if it isn't
> present?
 

My idea would be to pass the amount of upvalues in lua_upvalueindex(1),
and then use that for checking... I think the whole idea of 
upvalues was built around the idea that the amount of upvalues is known
at compile time, though I might be mistaken there. 

-- 
"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer 
bjorn.demeyer@pandora.be