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

Used for storing references to object in the global registry. More...

#include <LuaState.h>

Public Member Functions

template<typename T >
void CreateFromObject (cLuaState &a_LuaState, T &&a_Object)
 Creates a Lua reference to the specified object instance in the specified Lua state. More...
 
 cRef (cLuaState &a_LuaState, int a_StackPos)
 Creates a reference in the specified LuaState for object at the specified StackPos. More...
 
 cRef (cRef &&a_FromRef)
 Moves the reference from the specified instance into a newly created instance. More...
 
 cRef (void)
 Creates an unbound reference object. More...
 
lua_State * GetLuaState (void)
 Returns the Lua state associated with the value. More...
 
bool IsValid (void) const
 Returns true if the reference is valid. More...
 
 operator int (void) const
 Allows to use this class wherever an int (i. More...
 
void RefStack (cLuaState &a_LuaState, int a_StackPos)
 Creates a reference to Lua object at the specified stack pos, binds this object to it. More...
 
void UnRef (void)
 Removes the bound reference, resets the object to Unbound state. More...
 
 ~cRef ()
 

Protected Member Functions

 cRef (const cRef &)=delete
 

Protected Attributes

lua_State * m_LuaState
 
int m_Ref
 

Detailed Description

Used for storing references to object in the global registry.

Can be bound (contains a reference) or unbound (doesn't contain reference). The reference can also be reset by calling RefStack().

Definition at line 159 of file LuaState.h.

Constructor & Destructor Documentation

◆ cRef() [1/4]

cLuaState::cRef::cRef ( void  )

Creates an unbound reference object.

Definition at line 2588 of file LuaState.cpp.

◆ cRef() [2/4]

cLuaState::cRef::cRef ( cLuaState a_LuaState,
int  a_StackPos 
)

Creates a reference in the specified LuaState for object at the specified StackPos.

Definition at line 2598 of file LuaState.cpp.

◆ cRef() [3/4]

cLuaState::cRef::cRef ( cRef &&  a_FromRef)

Moves the reference from the specified instance into a newly created instance.

The old instance is then "!IsValid()".

Definition at line 2609 of file LuaState.cpp.

◆ ~cRef()

cLuaState::cRef::~cRef ( )

Definition at line 2621 of file LuaState.cpp.

◆ cRef() [4/4]

cLuaState::cRef::cRef ( const cRef )
protecteddelete

Member Function Documentation

◆ CreateFromObject()

template<typename T >
void cLuaState::cRef::CreateFromObject ( cLuaState a_LuaState,
T &&  a_Object 
)
inline

Creates a Lua reference to the specified object instance in the specified Lua state.

This is useful to make anti-GC references for objects that were created by Lua and need to stay alive longer than Lua GC would normally guarantee.

Definition at line 192 of file LuaState.h.

◆ GetLuaState()

lua_State* cLuaState::cRef::GetLuaState ( void  )
inline

Returns the Lua state associated with the value.

Definition at line 188 of file LuaState.h.

◆ IsValid()

bool cLuaState::cRef::IsValid ( void  ) const
inline

Returns true if the reference is valid.

Definition at line 182 of file LuaState.h.

◆ operator int()

cLuaState::cRef::operator int ( void  ) const
inlineexplicit

Allows to use this class wherever an int (i.

e. ref) is to be used

Definition at line 185 of file LuaState.h.

◆ RefStack()

void cLuaState::cRef::RefStack ( cLuaState a_LuaState,
int  a_StackPos 
)

Creates a reference to Lua object at the specified stack pos, binds this object to it.

Calls UnRef() first if previously bound to another reference.

Definition at line 2633 of file LuaState.cpp.

◆ UnRef()

void cLuaState::cRef::UnRef ( void  )

Removes the bound reference, resets the object to Unbound state.

Definition at line 2650 of file LuaState.cpp.

Member Data Documentation

◆ m_LuaState

lua_State* cLuaState::cRef::m_LuaState
protected

Definition at line 200 of file LuaState.h.

◆ m_Ref

int cLuaState::cRef::m_Ref
protected

Definition at line 201 of file LuaState.h.


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