19 #include <lua/LazyTable.h> 23 #include <momemta/Logging.h> 24 #include <momemta/Unused.h> 26 #include <lua/utils.h> 30 LazyTableField::LazyTableField(lua_State *L,
const std::string& table_name,
const std::string& key) :
32 this->table_name = table_name;
36 void LazyTableField::ensure_created() {
38 int type = lua_getglobal(L, table_name.c_str());
49 lua_setglobal(L, table_name.c_str());
53 LOG(trace) <<
"[LazyTableField::operator()] >> stack size = " << lua_gettop(L);
56 lua_getglobal(L, table_name.c_str());
59 lua_getfield(L, -1, key.c_str());
63 std::tie(value, lazy) =
to_any(L, -1);
69 LOG(trace) <<
"[LazyTableField::operator()] << stack size = " << lua_gettop(L);
75 LOG(trace) <<
"[LazyTableField::set] >> stack size = " << lua_gettop(L);
78 lua_getglobal(L, table_name.c_str());
84 lua_setfield(L, -2, key.c_str());
89 LOG(trace) <<
"[LazyTableField::set] << stack size = " << lua_gettop(L);
92 LazyTable::LazyTable(std::shared_ptr<lua_State> L,
const std::string& name):
97 bool LazyTable::lazy()
const {
101 void LazyTable::create(
const std::string& name,
const momemta::any& value) {
105 lazyField.
set(value);
107 m_set.emplace(name,
Element(lazyField,
true));
110 void LazyTable::setInternal(
const std::string& name,
Element& element,
const momemta::any& value) {
118 assert(element.lazy);
124 void LazyTable::freeze() {
125 ParameterSet::freeze();
A specialization of ParameterSet for lazy loading of lua tables.
Lazy table field in lua (delayed table access)
A small wrapper around a momemta::any value.
Type type(lua_State *L, int index)
Extract the type of a lua value.
void push_any(lua_State *L, const momemta::any &value)
Convert a momemta::any to a lua type, and push it to the top of the stack.
A class encapsulating a lua table.
void set(const momemta::any &value)
Replace the value of the table field by a new one.
std::pair< momemta::any, bool > to_any(lua_State *L, int index)
Convert a lua type to momemta::any.
void ensure_created()
Ensure the global table referenced by this struct exist. If not, create it.
Utility functions related to lua configuration file parsing.