mxnet
Classes | Namespaces
lua.h File Reference

C++11 header only interface to easily interact with Lua and Torch. This code is evolved from torch plugin code for MXNet. More...

#include <lua.h>
#include <luaT.h>
#include <lualib.h>
#include <string>
#include <stdexcept>
#include <tuple>
#include <mutex>
#include <memory>
#include <vector>
#include <utility>
#include <algorithm>
#include <unordered_map>
#include <type_traits>
#include "./base.h"
#include "./logging.h"
#include "./thread_local.h"
Include dependency graph for lua.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  dmlc::lua_stack::Handler< T >
 
class  dmlc::LuaRef
 an reference to lua object More...
 
class  dmlc::LuaState
 A Lua state. More...
 

Namespaces

 dmlc
 namespace for dmlc
 
 dmlc::lua_stack
 

Detailed Description

C++11 header only interface to easily interact with Lua and Torch. This code is evolved from torch plugin code for MXNet.

Copyright (c) 2016 by Contributors

This header will require Torch and Lua to be presented, do not include.

Author
Junyuan Xie, Min Lin, Tianqi Chen
// Example code to use the lua module.
// vectors converts automatically to lua table.
auto tbl = lua->Convert(std::vector<int>{1,2,3});
// use eval to get lua reference, this is a function
auto print = lua->Eval("return function(x) print(x) end");
// lua function can be directly called from c++, arguments are converted.
print(100);
// set field in the table.
tbl.SetField("square", lua->Eval("return function(x) x*x end"));
// call the function, covert back to C++ values.
int x = tbl["square"](100).Get<int>();