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 217 of file LuaState.h.

Constructor & Destructor Documentation

cLuaState::cTrackedRef::cTrackedRef ( void  )

Creates an unbound ref instance.

Definition at line 197 of file LuaState.cpp.

cLuaState::cTrackedRef::~cTrackedRef ( )
inline

Definition at line 224 of file LuaState.h.

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.

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

void cLuaState::cTrackedRef::Clear ( void  )

Frees the contained reference, if any.

Untracks the reference from its canon Lua state.

Definition at line 225 of file LuaState.cpp.

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 264 of file LuaState.h.

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 295 of file LuaState.cpp.

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 271 of file LuaState.cpp.

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 256 of file LuaState.cpp.

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 206 of file LuaState.cpp.

Friends And Related Function Documentation

friend class ::cLuaState
friend

Definition at line 219 of file LuaState.h.

friend class cLuaState
friend

Definition at line 247 of file LuaState.h.

Member Data Documentation

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 252 of file LuaState.h.

cRef cLuaState::cTrackedRef::m_Ref
protected

Reference to the Lua callback.

Definition at line 255 of file LuaState.h.


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