Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
cLuaState::cTrackedRef Class Reference

Represents a reference to a Lua object that has a tracked lifetime -. More...

#include <LuaState.h>

Inheritance diagram for cLuaState::cTrackedRef:
Inheritance graph
[legend]
Collaboration diagram for cLuaState::cTrackedRef:
Collaboration graph
[legend]

Public Member Functions

void Clear (void)
 Frees the contained reference, if any. More...
 
 cTrackedRef (void)
 Creates an unbound ref instance. More...
 
bool IsSameLuaState (cLuaState &a_LuaState)
 Returns true if the reference resides in the specified Lua state. More...
 
bool IsValid (void)
 Returns true if the contained reference is valid. More...
 
bool RefStack (cLuaState &a_LuaState, int a_StackPos)
 Set the contained reference to the object at the specified Lua state's stack position. More...
 
 ~cTrackedRef ()
 

Protected Member Functions

 cTrackedRef (const cTrackedRef &)=delete
 This class cannot be copied, because it is tracked in the LuaState by-ptr. More...
 
 cTrackedRef (cTrackedRef &&)=delete
 This class cannot be moved, because it is tracked in the LuaState by-ptr. More...
 
cRefGetRef ()
 Returns the internal reference. More...
 
void Invalidate (void)
 Invalidates the callback, without untracking it from the cLuaState. More...
 

Protected Attributes

std::atomic< cCriticalSection * > m_CS
 The mutex protecting m_Ref against multithreaded access. More...
 
cRef m_Ref
 Reference to the Lua callback. More...
 

Friends

class ::cLuaState
 
class cLuaState
 

Detailed Description

Represents a reference to a Lua object that has a tracked lifetime -.

Definition at line 215 of file LuaState.h.

Constructor & Destructor Documentation

◆ cTrackedRef() [1/3]

cLuaState::cTrackedRef::cTrackedRef ( void  )

Creates an unbound ref instance.

Definition at line 194 of file LuaState.cpp.

◆ ~cTrackedRef()

cLuaState::cTrackedRef::~cTrackedRef ( )
inline

Definition at line 222 of file LuaState.h.

◆ cTrackedRef() [2/3]

cLuaState::cTrackedRef::cTrackedRef ( const cTrackedRef )
protecteddelete

This class cannot be copied, because it is tracked in the LuaState by-ptr.

Use a smart pointer for a copyable object.

◆ cTrackedRef() [3/3]

cLuaState::cTrackedRef::cTrackedRef ( cTrackedRef &&  )
protecteddelete

This class cannot be moved, because it is tracked in the LuaState by-ptr.

Use a smart pointer for a copyable object.

Member Function Documentation

◆ Clear()

void cLuaState::cTrackedRef::Clear ( void  )

Frees the contained reference, if any.

Untracks the reference from its canon Lua state.

Definition at line 222 of file LuaState.cpp.

◆ GetRef()

cRef& cLuaState::cTrackedRef::GetRef ( )
inlineprotected

Returns the internal reference.

Only to be used when the cLuaState's CS is held and the cLuaState is known to be valid.

Definition at line 262 of file LuaState.h.

◆ Invalidate()

void cLuaState::cTrackedRef::Invalidate ( void  )
protected

Invalidates the callback, without untracking it from the cLuaState.

Called only from cLuaState when closing the Lua state.

Definition at line 292 of file LuaState.cpp.

◆ IsSameLuaState()

bool cLuaState::cTrackedRef::IsSameLuaState ( cLuaState a_LuaState)

Returns true if the reference resides in the specified Lua state.

Internally, compares the reference's canon Lua state. (Note that depending on this value is not thread-safe, another thread may modify the ref in the meantime. It is meant for quick ASSERTs only).

Definition at line 268 of file LuaState.cpp.

◆ IsValid()

bool cLuaState::cTrackedRef::IsValid ( void  )

Returns true if the contained reference is valid.

(Note that depending on this value is not thread-safe, another thread may invalidate the ref in the meantime. It is meant for quick ASSERTs only).

Definition at line 253 of file LuaState.cpp.

◆ RefStack()

bool cLuaState::cTrackedRef::RefStack ( cLuaState a_LuaState,
int  a_StackPos 
)

Set the contained reference to the object at the specified Lua state's stack position.

If another reference has been previously contained, it is Clear()-ed first.

Definition at line 203 of file LuaState.cpp.

Friends And Related Function Documentation

◆ ::cLuaState

friend class ::cLuaState
friend

Definition at line 217 of file LuaState.h.

◆ cLuaState

friend class cLuaState
friend

Definition at line 245 of file LuaState.h.

Member Data Documentation

◆ m_CS

std::atomic<cCriticalSection *> cLuaState::cTrackedRef::m_CS
protected

The mutex protecting m_Ref against multithreaded access.

Actually points to the canon Lua state's m_CriticalSection. Is nullptr when ref is empty (not bound).

Definition at line 250 of file LuaState.h.

◆ m_Ref

cRef cLuaState::cTrackedRef::m_Ref
protected

Reference to the Lua callback.

Definition at line 253 of file LuaState.h.


The documentation for this class was generated from the following files: