mxnet
Public Member Functions | Friends | List of all members
dmlc::LuaRef Class Reference

an reference to lua object More...

#include <lua.h>

Collaboration diagram for dmlc::LuaRef:
Collaboration graph

Public Member Functions

 LuaRef ()=default
 construct an nil ref More...
 
 LuaRef (LuaRef &&other)
 move constructor from another LuaRef More...
 
 LuaRef (const LuaRef &other)
 copy constructor More...
 
LuaRefoperator= (LuaRef &&other)
 assign operator from other More...
 
LuaRefoperator= (const LuaRef &other)
 assign operator from other More...
 
 ~LuaRef ()
 destructor More...
 
void swap (LuaRef &other)
 swap content with another ref More...
 
template<typename T >
Get () const
 Get content out as type T. More...
 
template<typename T >
T * GetUDataPtr () const
 Get user data pointer from LuaRef. More...
 
bool is_nil () const
 
template<typename... Args>
LuaRef operator() (Args &&...args) const
 invoke the LuaRef as function More...
 
LuaRef operator[] (const std::string &key) const
 Get field from the lua table. The reference must be a table. More...
 
LuaRef operator[] (size_t index) const
 Get field from the lua array The reference must be a array. More...
 
template<typename T >
LuaRefSetField (const std::string &key, const T &value)
 Set field of lua table. The reference must be a table. More...
 
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. More...
 

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

dmlc::LuaRef::LuaRef ( )
default

construct an nil ref

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

move constructor from another LuaRef

Parameters
otherThe other LuaRef to be moved
dmlc::LuaRef::LuaRef ( const LuaRef other)
inline

copy constructor

Parameters
otherThe other LuaRef to be copied
dmlc::LuaRef::~LuaRef ( )
inline

destructor

Member Function Documentation

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.
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.
bool dmlc::LuaRef::is_nil ( ) const
inline
Returns
whether the value is nil
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.
LuaRef& dmlc::LuaRef::operator= ( LuaRef &&  other)
inline

assign operator from other

Parameters
otherThe other LuaRef to be copy or moved.
Returns
self
LuaRef& dmlc::LuaRef::operator= ( const LuaRef other)
inline

assign operator from other

Parameters
otherThe other LuaRef to be copy or moved.
Returns
self
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.
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.
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.
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.
void dmlc::LuaRef::swap ( LuaRef other)
inline

swap content with another ref

Parameters
otheranother LuaRef to be swaped.

Friends And Related Function Documentation

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

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