Ardour  8.7-14-g57a6773833
LuaRef Class Reference

#include <LuaRef.h>

Classes

struct  FromStack
 
class  Proxy
 
class  StackPop
 

Public Member Functions

 LuaRef (lua_State *L)
 
template<class T >
 LuaRef (lua_State *L, T v)
 
 LuaRef (Proxy const &v)
 
 LuaRef (LuaRef const &other)
 
 ~LuaRef ()
 
template<class T >
LuaRefoperator= (T rhs)
 
LuaRefoperator= (LuaRef const &rhs)
 
std::string tostring () const
 
void print (std::ostream &os) const
 
lua_Statestate () const
 
void push (lua_State *L) const
 
void pop (lua_State *L)
 
template<class T >
cast () const
 
template<class T >
 operator T () const
 
template<class T >
void append (T v) const
 
int length () const
 
template<class T >
Proxy operator[] (T key) const
 
int type () const
 
bool isNil () const
 
bool isBoolean () const
 
bool isNumber () const
 
bool isString () const
 
bool isTable () const
 
bool isFunction () const
 
bool isUserdata () const
 
bool isThread () const
 
bool isLightUserdata () const
 
template<class T >
bool operator== (T rhs) const
 
template<class T >
bool operator< (T rhs) const
 
template<class T >
bool operator<= (T rhs) const
 
template<class T >
bool operator> (T rhs) const
 
template<class T >
bool operator>= (T rhs) const
 
template<class T >
bool rawequal (T rhs) const
 
LuaRef const operator() () const
 
template<class P1 >
LuaRef const operator() (P1 p1) const
 
template<class P1 , class P2 >
LuaRef const operator() (P1 p1, P2 p2) const
 
template<class P1 , class P2 , class P3 >
LuaRef const operator() (P1 p1, P2 p2, P3 p3) const
 
template<class P1 , class P2 , class P3 , class P4 >
LuaRef const operator() (P1 p1, P2 p2, P3 p3, P4 p4) const
 
template<class P1 , class P2 , class P3 , class P4 , class P5 >
LuaRef const operator() (P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) const
 
template<class P1 , class P2 , class P3 , class P4 , class P5 , class P6 >
LuaRef const operator() (P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) const
 
template<class P1 , class P2 , class P3 , class P4 , class P5 , class P6 , class P7 >
LuaRef const operator() (P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) const
 
template<class P1 , class P2 , class P3 , class P4 , class P5 , class P6 , class P7 , class P8 >
LuaRef const operator() (P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) const
 

Static Public Member Functions

static LuaRef fromStack (lua_State *L, int index)
 
static LuaRef newTable (lua_State *L)
 
static LuaRef getGlobal (lua_State *L, char const *name)
 

Private Member Functions

 LuaRef (lua_State *L, FromStack)
 
 LuaRef (lua_State *L, int index, FromStack)
 
template<class T >
 LuaRef (T)
 
int createRef () const
 

Private Attributes

lua_Statem_L
 
int m_ref
 

Friends

struct Stack< Proxy >
 
struct Stack< LuaRef >
 

Detailed Description

Lightweight reference to a Lua object.

The reference is maintained for the lifetime of the C++ object.

Definition at line 51 of file LuaRef.h.

Constructor & Destructor Documentation

◆ LuaRef() [1/7]

LuaRef::LuaRef ( lua_State L,
FromStack   
)
inlineprivate

Create a reference to an object at the top of the Lua stack and pop it.

This constructor is private and not invoked directly. Instead, use the fromStack function.

Note
The object is popped.

Definition at line 555 of file LuaRef.h.

◆ LuaRef() [2/7]

LuaRef::LuaRef ( lua_State L,
int  index,
FromStack   
)
inlineprivate

Create a reference to an object on the Lua stack.

This constructor is private and not invoked directly. Instead, use the fromStack function.

Note
The object is not popped.

Definition at line 570 of file LuaRef.h.

◆ LuaRef() [3/7]

template<class T >
LuaRef::LuaRef ( )
inlineprivate

Definition at line 582 of file LuaRef.h.

◆ LuaRef() [4/7]

LuaRef::LuaRef ( lua_State L)
inline

Create a nil reference.

The LuaRef may be assigned later.

Definition at line 612 of file LuaRef.h.

◆ LuaRef() [5/7]

template<class T >
LuaRef::LuaRef ( lua_State L,
v 
)
inline

Create a reference to a value.

Definition at line 623 of file LuaRef.h.

◆ LuaRef() [6/7]

LuaRef::LuaRef ( Proxy const &  v)
inline

Create a reference to a table value.

Definition at line 634 of file LuaRef.h.

◆ LuaRef() [7/7]

LuaRef::LuaRef ( LuaRef const &  other)
inline

Create a new reference to an existing reference.

Definition at line 644 of file LuaRef.h.

◆ ~LuaRef()

LuaRef::~LuaRef ( )
inline

Destroy a reference.

The corresponding Lua registry reference will be released.

Note
If the state refers to a thread, it is the responsibility of the caller to ensure that the thread still exists when the LuaRef is destroyed.

Definition at line 660 of file LuaRef.h.

Member Function Documentation

◆ append()

template<class T >
void LuaRef::append ( v) const
inline

Append a value to the table.

If the table is a sequence this will add another element to it.

Definition at line 978 of file LuaRef.h.

◆ cast()

template<class T >
T LuaRef::cast ( ) const
inline

Perform an explicit conversion.

Definition at line 873 of file LuaRef.h.

◆ createRef()

int LuaRef::createRef ( ) const
inlineprivate

Create a reference to this ref.

This is used internally.

Definition at line 592 of file LuaRef.h.

◆ fromStack()

static LuaRef LuaRef::fromStack ( lua_State L,
int  index 
)
inlinestatic

Return a LuaRef from a stack item.

The stack item is not popped.

Definition at line 671 of file LuaRef.h.

◆ getGlobal()

static LuaRef LuaRef::getGlobal ( lua_State L,
char const *  name 
)
inlinestatic

Return a reference to a named global.

It is also possible to use the free function getGlobal.

See also
getGlobal

Definition at line 699 of file LuaRef.h.

◆ isBoolean()

bool LuaRef::isBoolean ( ) const
inline

Definition at line 858 of file LuaRef.h.

◆ isFunction()

bool LuaRef::isFunction ( ) const
inline

Definition at line 862 of file LuaRef.h.

◆ isLightUserdata()

bool LuaRef::isLightUserdata ( ) const
inline

Definition at line 865 of file LuaRef.h.

◆ isNil()

bool LuaRef::isNil ( ) const
inline

Definition at line 857 of file LuaRef.h.

◆ isNumber()

bool LuaRef::isNumber ( ) const
inline

Definition at line 859 of file LuaRef.h.

◆ isString()

bool LuaRef::isString ( ) const
inline

Definition at line 860 of file LuaRef.h.

◆ isTable()

bool LuaRef::isTable ( ) const
inline

Definition at line 861 of file LuaRef.h.

◆ isThread()

bool LuaRef::isThread ( ) const
inline

Definition at line 864 of file LuaRef.h.

◆ isUserdata()

bool LuaRef::isUserdata ( ) const
inline

Definition at line 863 of file LuaRef.h.

◆ length()

int LuaRef::length ( ) const
inline

Call the length operator.

This is identical to applying the Lua # operator.

Definition at line 992 of file LuaRef.h.

◆ newTable()

static LuaRef LuaRef::newTable ( lua_State L)
inlinestatic

Create a new empty table and return a reference to it.

It is also possible to use the free function newTable.

See also
getGlobal

Definition at line 685 of file LuaRef.h.

◆ operator T()

template<class T >
LuaRef::operator T ( ) const
inline

Universal implicit conversion operator.

NOTE: Visual Studio 2010 and 2012 have a bug where this function is not used. See:

http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/e30b2664-a92d-445c-9db2-e8e0fbde2014 https://connect.microsoft.com/VisualStudio/feedback/details/771509/correct-code-doesnt-compile

// This code snippet fails to compile in vs2010,vs2012
struct S {
template <class T> inline operator T () const { return T (); }
};
int main () {
S () || false;
return 0;
}

Definition at line 906 of file LuaRef.h.

◆ operator()() [1/9]

LuaRef const LuaRef::operator() ( ) const
inline

Call Lua code.

These overloads allow Lua code to be called with up to 8 parameters. The return value is provided as a LuaRef (which may be LUA_REFNIL). If an error occurs, a LuaException is thrown.

Definition at line 1021 of file LuaRef.h.

◆ operator()() [2/9]

template<class P1 >
LuaRef const LuaRef::operator() ( P1  p1) const
inline

Definition at line 1029 of file LuaRef.h.

◆ operator()() [3/9]

template<class P1 , class P2 >
LuaRef const LuaRef::operator() ( P1  p1,
P2  p2 
) const
inline

Definition at line 1038 of file LuaRef.h.

◆ operator()() [4/9]

template<class P1 , class P2 , class P3 >
LuaRef const LuaRef::operator() ( P1  p1,
P2  p2,
P3  p3 
) const
inline

Definition at line 1048 of file LuaRef.h.

◆ operator()() [5/9]

template<class P1 , class P2 , class P3 , class P4 >
LuaRef const LuaRef::operator() ( P1  p1,
P2  p2,
P3  p3,
P4  p4 
) const
inline

Definition at line 1059 of file LuaRef.h.

◆ operator()() [6/9]

template<class P1 , class P2 , class P3 , class P4 , class P5 >
LuaRef const LuaRef::operator() ( P1  p1,
P2  p2,
P3  p3,
P4  p4,
P5  p5 
) const
inline

Definition at line 1071 of file LuaRef.h.

◆ operator()() [7/9]

template<class P1 , class P2 , class P3 , class P4 , class P5 , class P6 >
LuaRef const LuaRef::operator() ( P1  p1,
P2  p2,
P3  p3,
P4  p4,
P5  p5,
P6  p6 
) const
inline

Definition at line 1084 of file LuaRef.h.

◆ operator()() [8/9]

template<class P1 , class P2 , class P3 , class P4 , class P5 , class P6 , class P7 >
LuaRef const LuaRef::operator() ( P1  p1,
P2  p2,
P3  p3,
P4  p4,
P5  p5,
P6  p6,
P7  p7 
) const
inline

Definition at line 1098 of file LuaRef.h.

◆ operator()() [9/9]

template<class P1 , class P2 , class P3 , class P4 , class P5 , class P6 , class P7 , class P8 >
LuaRef const LuaRef::operator() ( P1  p1,
P2  p2,
P3  p3,
P4  p4,
P5  p5,
P6  p6,
P7  p7,
P8  p8 
) const
inline

Definition at line 1113 of file LuaRef.h.

◆ operator<()

template<class T >
bool LuaRef::operator< ( rhs) const
inline

Definition at line 926 of file LuaRef.h.

◆ operator<=()

template<class T >
bool LuaRef::operator<= ( rhs) const
inline

Definition at line 935 of file LuaRef.h.

◆ operator=() [1/2]

LuaRef& LuaRef::operator= ( LuaRef const &  rhs)
inline

Assign another LuaRef to this LuaRef.

Definition at line 722 of file LuaRef.h.

◆ operator=() [2/2]

template<class T >
LuaRef& LuaRef::operator= ( rhs)
inline

Assign a different value to this LuaRef.

Definition at line 710 of file LuaRef.h.

◆ operator==()

template<class T >
bool LuaRef::operator== ( rhs) const
inline

Universal comparison operators.

Definition at line 917 of file LuaRef.h.

◆ operator>()

template<class T >
bool LuaRef::operator> ( rhs) const
inline

Definition at line 944 of file LuaRef.h.

◆ operator>=()

template<class T >
bool LuaRef::operator>= ( rhs) const
inline

Definition at line 953 of file LuaRef.h.

◆ operator[]()

template<class T >
Proxy LuaRef::operator[] ( key) const
inline

Access a table value using a key.

This invokes metamethods.

Definition at line 1006 of file LuaRef.h.

◆ pop()

void LuaRef::pop ( lua_State L)
inline

Pop the top of Lua stack and assign the ref to m_ref

Definition at line 823 of file LuaRef.h.

◆ print()

void LuaRef::print ( std::ostream &  os) const
inline

Print a text description of the value to a stream.

This is used for diagnostics.

Definition at line 751 of file LuaRef.h.

◆ push()

void LuaRef::push ( lua_State L) const
inline

Place the object onto the Lua stack.

Definition at line 813 of file LuaRef.h.

◆ rawequal()

template<class T >
bool LuaRef::rawequal ( rhs) const
inline

Definition at line 962 of file LuaRef.h.

◆ state()

lua_State* LuaRef::state ( void  ) const
inline

Retrieve the lua_State associated with the reference.

Definition at line 804 of file LuaRef.h.

◆ tostring()

std::string LuaRef::tostring ( ) const
inline

converts to a string using luas tostring function

Definition at line 735 of file LuaRef.h.

◆ type()

int LuaRef::type ( ) const
inline

Determine the object type.

The return values are the same as for lua_type.

Definition at line 837 of file LuaRef.h.

Friends And Related Function Documentation

◆ Stack< LuaRef >

friend struct Stack< LuaRef >
friend

Definition at line 1226 of file LuaRef.h.

◆ Stack< Proxy >

friend struct Stack< Proxy >
friend

Definition at line 1226 of file LuaRef.h.

Member Data Documentation

◆ m_L

lua_State* LuaRef::m_L
private

Definition at line 1132 of file LuaRef.h.

◆ m_ref

int LuaRef::m_ref
private

Definition at line 1133 of file LuaRef.h.


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