A Lua state.
More...
#include <lua.h>
options to be provided in lua state
Enumerator |
---|
kNoThreadProtect |
|
kThreadLocal |
|
kLocking |
|
dmlc::LuaState::~LuaState |
( |
| ) |
|
|
inline |
dmlc::LuaState::LuaState |
( |
| ) |
|
|
inlineprotected |
template<typename T >
LuaRef dmlc::LuaState::Convert |
( |
const T & |
value | ) |
|
|
inline |
convert a C++ type to lua type
- Parameters
-
value | The data to be converted. vector, map will be converted to table. |
- Returns
- a converted value.
- Template Parameters
-
T | the type to be converted. |
Create a new lua state.
- Note
- It is highly recommended to use ThreadLocalState instead.
Most Lua program assumes it only runs from the same thread. Some Lua code that wraps C library(e.g. Torch) could rely on thread_local storage to store global state such as random number generator. This means if the code is invoked by another thread, the thread_local might become inavailable, depending on the implementation.
If the global state is stored only in Lua's global table, then it is safe to use kLocking mode and call the code from multiple thread. Never-the-less, using ThreadLocalState removes the need to lock, and is the desirable usecase in most times.
- See also
- ThreadLocalState
- Parameters
-
option | The option to use the state. |
- Returns
- a newly created lua state
LuaRef dmlc::LuaState::Eval |
( |
const char * |
lua_code | ) |
|
|
inline |
evaluate a piece of lua code, return the first result.
- Parameters
-
- Returns
- A LuaRef object of the first returned result, Can be nil if the code did not return LuaRefthing.
LuaRef dmlc::LuaState::Eval |
( |
const std::string & |
lua_code | ) |
|
|
inline |
evaluate a piece of lua code, return the first result.
- Parameters
-
- Returns
- A LuaRef object of the first returned result, Can be nil if the code did not return anything.
LuaRef dmlc::LuaState::operator[] |
( |
const std::string & |
key | ) |
|
|
inline |
get global field from the state
- Parameters
-
key | The key to the global field. |
- Returns
- The global field value.
template<typename F >
void dmlc::LuaState::PRun_ |
( |
F |
f | ) |
|
|
inline |
protected run f, this is used by API developers. always call this to access lua state f must not destruct LuaRef, or access the mutex
- Parameters
-
f | the function to be called. |
- Template Parameters
-
F | the function to be called, signiture (lua_State *L) |
bool dmlc::LuaState::SameLuaState |
( |
lua_State * |
L | ) |
const |
|
inline |
- Parameters
-
- Returns
- if the internal lua state is same as L
void dmlc::LuaState::SetGlobalField |
( |
const std::string & |
key, |
|
|
const LuaRef & |
value |
|
) |
| |
|
inline |
Set the value to the global table.
- Parameters
-
key | The key of the global field. |
value | The value to the set. |
static LuaState* dmlc::LuaState::ThreadLocalState |
( |
| ) |
|
|
inlinestatic |
Get a thread local version of lua state. The LuaState runs in thread local mode, all the LuaRef can only be run on the current thread. This is the recommended behavior when invoking Lua.
- Returns
- a threadlocal version of lua state.
lua_State* dmlc::LuaState::L_ |
|
protected |
std::mutex dmlc::LuaState::mutex_ |
|
protected |
internal lock about the state
internal option, default to thread local
The documentation for this class was generated from the following file:
- /work/mxnet/3rdparty/dmlc-core/include/dmlc/lua.h