Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
Weak Table reference

Detailed Description

Functions designed to be similar to using luaL_ref(L, LUA_REGISTRYINDEX), lua_rawgeti(L, LUA_REGISTRYINDEX, ix), and luaL_unref(L, LUA_REGISTRYINDEX, ix), but with weak references.

Weak references allow the Lua garbage collector to collect values even if they are still referenced in the weak table.

Collaboration diagram for Weak Table reference:

Functions

BA_API int balua_wkRef (lua_State *L)
 Creates and returns a reference in the weak table, for the object on the top of the stack (and pops the object). More...
 
BA_API int balua_wkRefIx (lua_State *L, int index)
 Create a weak reference without popping the referenced value. More...
 
BA_API void balua_wkPush (lua_State *L, int reference)
 Pushes the value associated with the key 'index' on top of the stack. More...
 
BA_API void balua_wkUnref (lua_State *L, int reference)
 Releases the reference ref from the weak table. More...
 

Function Documentation

◆ balua_wkPush()

BA_API void balua_wkPush ( lua_State *  L,
int  reference 
)

Pushes the value associated with the key 'index' on top of the stack.

Pushes Lua nil if the reference was removed or its value collected.

Parameters
Lthe state
referencethe reference returned by balua_wkRef

◆ balua_wkRef()

BA_API int balua_wkRef ( lua_State *  L)

Creates and returns a reference in the weak table, for the object on the top of the stack (and pops the object).

Parameters
LRequired BAS state with a value on top.
Returns
Integer weak reference; it does not keep the value alive.

◆ balua_wkRefIx()

BA_API int balua_wkRefIx ( lua_State *  L,
int  index 
)

Create a weak reference without popping the referenced value.

Parameters
LRequired initialized BAS state.
indexNegative stack index relative to the stack before the call.
Returns
Integer reference for balua_wkPush/balua_wkUnref. Stack is unchanged. The reference does not prevent collection.

◆ balua_wkUnref()

BA_API void balua_wkUnref ( lua_State *  L,
int  reference 
)

Releases the reference ref from the weak table.

Parameters
Lthe state
referencethe reference returned by balua_wkRef