Luwra
Minimal-overhead Lua wrapper for C++
Public Member Functions | Public Attributes | List of all members
luwra::Reference Struct Reference

Handle for a reference. More...

#include <reference.hpp>

Public Member Functions

template<typename Type >
 operator Type () const
 
template<typename Type >
Type read () const
 Read the value that is being referenced.
 
 Reference (State *state)
 Create a reference using the value on top of the stack. Consumes the value.
 
 Reference (State *state, int index)
 Create a reference to a value on the stack. Does not consume the value.
 

Public Attributes

std::shared_ptr< const RefLifecyclelife
 Smart pointer to the reference's lifecycle manager.
 

Detailed Description

Handle for a reference.

Constructor & Destructor Documentation

◆ Reference() [1/2]

luwra::Reference::Reference ( State state)
inline

Create a reference using the value on top of the stack. Consumes the value.

◆ Reference() [2/2]

luwra::Reference::Reference ( State state,
int  index 
)
inline

Create a reference to a value on the stack. Does not consume the value.

Member Function Documentation

◆ operator Type()

template<typename Type >
luwra::Reference::operator Type ( ) const
inline

◆ read()

template<typename Type >
Type luwra::Reference::read ( ) const
inline

Read the value that is being referenced.

Member Data Documentation

◆ life

std::shared_ptr<const RefLifecycle> luwra::Reference::life

Smart pointer to the reference's lifecycle manager.

Why a smart pointer? Copying RefLifecycle creates new Lua references, which we want to avoid. Therefore we use shared_ptr which gives us cheap reference counting.