[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: lua_ref's... how to?
- From: RLake@...
- Date: Wed, 15 Oct 2003 15:37:41 -0500
> Can someone give me a quick overview (or direct me to a page) that
> describes what lua_refs can do? I've been looking for details on them,
> but most web pages mention them without giving a "here's what and how"
> about them...
> They're also not in the 5.0 manual (that I was able to find).
A very abbreviated description is at:
To fill in the blanks a bit, "t" is generally "LUA_REGISTRYINDEX" and "r"
is an integer which acts as a handle for the ref. luaL_ref() returns "r"
and luaL_getref() and luaL_unref() take "r" as an argument.
lua_ref(), lua_getref() and lua_unref() still exist as compatibility
You have it almost right, as long as myCPPObject-> ref is an int:
> myCPPObject->luaRef = lua_ref(L, true); // take whats on the top
> lua_getref(myCPPObject->luaRef); // push the contents of the ref
> lua_unref(myCPPObject->luaRef); // drop the ref
The "new way" would be:
myCPPObject->luaRef = luaL_ref(L, LUA_REGISTRYINDEX);
luaL_getref(L, LUA_REGISTRYINDEX, myCPPObject->luaRef);
luaL_unref(L, LUA_REGISTRYINDEX, myCPPObject->luaRef);