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.
|
| 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...
|
| |
◆ 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
-
| L | the state |
| reference | the 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
-
| L | Required 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
-
| L | Required initialized BAS state. |
| index | Negative 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
-
| L | the state |
| reference | the reference returned by balua_wkRef |