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 (void)
 Creates an unbound reference object. 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...
 
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 161 of file LuaState.h.

Constructor & Destructor Documentation

cLuaState::cRef::cRef ( void  )

Creates an unbound reference object.

Definition at line 2435 of file LuaState.cpp.

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

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

cLuaState::cRef::~cRef ( )

Definition at line 2468 of file LuaState.cpp.

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

Member Function Documentation

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

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

Returns the Lua state associated with the value.

Definition at line 190 of file LuaState.h.

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

Returns true if the reference is valid.

Definition at line 184 of file LuaState.h.

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

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

void cLuaState::cRef::UnRef ( void  )

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

Definition at line 2497 of file LuaState.cpp.

Member Data Documentation

lua_State* cLuaState::cRef::m_LuaState
protected

Definition at line 202 of file LuaState.h.

int cLuaState::cRef::m_Ref
protected

Definition at line 203 of file LuaState.h.


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