Medial Code Documentation
Loading...
Searching...
No Matches
Public Member Functions | Friends
dmlc::LuaRef Class Reference

an reference to lua object More...

#include <lua.h>

Public Member Functions

 LuaRef ()=default
 construct an nil ref
 
 LuaRef (LuaRef &&other)
 move constructor from another LuaRef
 
 LuaRef (const LuaRef &other)
 copy constructor
 
LuaRefoperator= (LuaRef &&other)
 assign operator from other
 
LuaRefoperator= (const LuaRef &other)
 assign operator from other
 
 ~LuaRef ()
 destructor
 
void swap (LuaRef &other)
 swap content with another ref
 
template<typename T >
Get () const
 Get content out as type T.
 
template<typename T >
T * GetUDataPtr () const
 Get user data pointer from LuaRef.
 
bool is_nil () const
 
template<typename... Args>
LuaRef operator() (Args &&...args) const
 invoke the LuaRef as function
 
LuaRef operator[] (const std::string &key) const
 Get field from the lua table. The reference must be a table.
 
LuaRef operator[] (size_t index) const
 Get field from the lua array The reference must be a array.
 
template<typename T >
LuaRefSetField (const std::string &key, const T &value)
 Set field of lua table. The reference must be a table.
 
void SetByPopStack_ (LuaState *s)
 Set LuaRef to the value on top of the stack. This state must be nil. This is API used by developer.
 

Friends

struct lua_stack::Handler< LuaRef >
 
class LuaState
 
std::ostream & operator<< (std::ostream &os, const LuaRef &r)
 

Detailed Description

an reference to lua object

Constructor & Destructor Documentation

◆ LuaRef() [1/2]

dmlc::LuaRef::LuaRef ( LuaRef &&  other)
inline

move constructor from another LuaRef

Parameters
otherThe other LuaRef to be moved

◆ LuaRef() [2/2]

dmlc::LuaRef::LuaRef ( const LuaRef other)
inline

copy constructor

Parameters
otherThe other LuaRef to be copied

Member Function Documentation

◆ Get()

template<typename T >
T dmlc::LuaRef::Get ( ) const
inline

Get content out as type T.

Template Parameters
Tthe type to be fetched.
Returns
the corresponding c type.

◆ GetUDataPtr()

template<typename T >
T * dmlc::LuaRef::GetUDataPtr ( ) const
inline

Get user data pointer from LuaRef.

CAREFUL when getting userdata(e.g. pointer to Tensor's storage) from LuaRef. Remember they are managed by Lua, and can get deleted when all the LuaRef to the userdata destructs. A good practice is always use a LuaRef to keep the userdata alive when you need them from C++ side.

Template Parameters
Tthe type of pointer to be fetched.
Returns
the corresponding c type.

◆ is_nil()

bool dmlc::LuaRef::is_nil ( ) const
inline
Returns
whether the value is nil

◆ operator()()

template<typename... Args>
LuaRef dmlc::LuaRef::operator() ( Args &&...  args) const
inline

invoke the LuaRef as function

Parameters
argsArguments to be passed.
Template Parameters
Argsarguments to be passed.
Returns
The first return value.

◆ operator=() [1/2]

LuaRef & dmlc::LuaRef::operator= ( const LuaRef other)
inline

assign operator from other

Parameters
otherThe other LuaRef to be copy or moved.
Returns
self

◆ operator=() [2/2]

LuaRef & dmlc::LuaRef::operator= ( LuaRef &&  other)
inline

assign operator from other

Parameters
otherThe other LuaRef to be copy or moved.
Returns
self

◆ operator[]() [1/2]

LuaRef dmlc::LuaRef::operator[] ( const std::string &  key) const
inline

Get field from the lua table. The reference must be a table.

Parameters
keyThe key to the table
Returns
a new ref to the corresponding field.

◆ operator[]() [2/2]

LuaRef dmlc::LuaRef::operator[] ( size_t  index) const
inline

Get field from the lua array The reference must be a array.

Parameters
indexThe index to the array, Note: the index convention follows lua table, starts from 1
Returns
a new ref to the corresponding field.

◆ SetByPopStack_()

void dmlc::LuaRef::SetByPopStack_ ( LuaState s)
inline

Set LuaRef to the value on top of the stack. This state must be nil. This is API used by developer.

Parameters
sthe corresponding lua state.

◆ SetField()

template<typename T >
LuaRef & dmlc::LuaRef::SetField ( const std::string &  key,
const T &  value 
)
inline

Set field of lua table. The reference must be a table.

Parameters
keyThe key to the table
valueLua convertable value to be setted.
Returns
self.

◆ swap()

void dmlc::LuaRef::swap ( LuaRef other)
inline

swap content with another ref

Parameters
otheranother LuaRef to be swaped.

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