lua-users home
lua-l archive

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


--- Roberto Ierusalimschy wrote:
> > Is it guaranteed, for lua 4.0.1, that the return value of lua_ref
(L, 1)
> > is always >0?
> 
> No. Particularly, lua_ref of a nil value always returns -1. But Lua
> ensures that the return value of lua_ref is always different from
> LUA_NOREF. (It is the same in 5.0.)

I'm wrapping a third-party application's API with lua and sometimes I 
have to return a handle which has type long, and which is a lua ref'd 
table inside the wrap code. Returning 0 means error to the API and I 
would like to return the ref direct, avoiding the creation of a 
pointer to a long and return that pointer.

I saw in lua.h that ref #0 is LUA_REFREGISTRY, so can I assume that 0 
(I don't care about negative values as I always call lua_ref on newly 
created tables) will never be returned by lua_ref, at least in lua-
4.0.1?