115 explicit LuaTable(lua_State *l,
int array_s,
int hash_s) :
118 lua_createtable(
m_lua, array_s, hash_s);
132 template <
class Value,
class Key>
133 Value
Get(
const Key &key)
const;
136 template <
class Value,
class Key>
137 Value
Get(
const Key &key, Value default_value)
const;
138 template <
class Value,
class Key>
139 LuaTable Set(
const Key &key,
const Value &value)
const;
141 template <
class Ret,
class Key,
class... Args>
142 Ret
Call(
const Key &key,
const Args &... args)
const;
143 template <
class Key,
class... Args>
144 void Call(
const Key &key,
const Args &... args)
const
146 Call<bool>(key, args...);
148 template <
class Ret1,
class Ret2,
class... Ret,
class Key,
class... Args>
149 std::tuple<Ret1, Ret2, Ret...>
Call(
const Key &key,
const Args &... args)
const;
151 template <
class Key,
class... Args>
154 Call<bool>(key, *
this, args...);
156 template <
class Ret,
class Key,
class... Args>
159 return Call<Ret>(key, *
this, args...);
161 template <
class Ret1,
class Ret2,
class... Ret,
class Key,
class... Args>
162 std::tuple<Ret1, Ret2, Ret...>
CallMethod(
const Key &key,
const Args &... args)
const
164 return Call<Ret1, Ret2, Ret...>(key, *
this, args...);
167 template <
class PairIterator>
169 template <
class ValueIterator>
172 template <
class Key,
class Value>
173 std::map<Key, Value>
GetMap()
const;
188 template <
class Value>
189 class VecIter :
public std::iterator<std::input_iterator_tag, Value> {
195 m_dirtyCache(true) {}
199 m_currentIndex(currentIndex),
201 m_dirtyCache(true) {}
203 m_table(copy.m_table),
204 m_currentIndex(copy.m_currentIndex),
206 m_dirtyCache(true) {}
210 m_table = copy.m_table;
211 m_currentIndex = copy.m_currentIndex;
233 if (m_table) --m_currentIndex;
239 if (m_table) --m_currentIndex;
243 bool operator==(
const VecIter &other)
const {
return (m_table == other.m_table && m_currentIndex == other.m_currentIndex); }
244 bool operator!=(
const VecIter &other)
const {
return (m_table != other.m_table || m_currentIndex != other.m_currentIndex); }
257 void CleanCache() { m_dirtyCache =
true; }
261 m_cache = m_table->
Get<Value>(m_currentIndex);
262 m_dirtyCache =
false;
271 template <
class Value>
273 template <
class Value>
325template <
class Value,
class Key>
335template <
class Value,
class Key>
339 if (!(lua_isnil(
m_lua, -1)))
342 return default_value;
345template <
class Value,
class Key>
354template <
class Key,
class Value>
358 std::map<Key, Value> ret;
374template <
class PairIterator>
377 for (PairIterator it = beg; it != end; ++it)
378 Set(it->first, it->second);
382template <
class ValueIterator>
386 int i = lua_tointeger(
m_lua, -1) + 1;
388 for (ValueIterator it = beg; it != end; ++it, ++i)
393template <
class Ret,
class Key,
class... Args>
399 lua_checkstack(
m_lua,
sizeof...(args) + 3);
409template <
class Ret1,
class Ret2,
class... Ret,
class Key,
class... Args>
410std::tuple<Ret1, Ret2, Ret...>
LuaTable::Call(
const Key &key,
const Args &... args)
const
413 lua_checkstack(
m_lua,
sizeof...(args) + 3);
418 lua_pop(
m_lua,
static_cast<int>(
sizeof...(Ret)) + 2);
420 return return_values;
427 m_cache = m_table->Sub(m_currentIndex);
428 m_dirtyCache =
false;
434 if (!m_dirtyCache && m_cache.GetLua()) {
435 lua_remove(m_cache.GetLua(), m_cache.GetIndex());
void pi_lua_generic_pull(lua_State *l, int index, Color4ub *&out)
Definition LuaColor.cpp:12
bool pi_lua_strict_pull(lua_State *l, int index, Color4ub &out)
Definition LuaColor.h:27
std::tuple< Types... > pi_lua_multiple_pull(lua_State *l, int beg)
Definition LuaPushPull.h:237
void pi_lua_multiple_push(lua_State *l, Types... args)
void pi_lua_generic_push(lua_State *l, const LuaTable &value)
Definition LuaTable.h:440
#define LUA_DEBUG_START(luaptr)
Definition LuaUtils.h:103
#define LUA_DEBUG_END(luaptr, expectedStackDiff)
Definition LuaUtils.h:104
void pi_lua_protected_call(lua_State *L, int nargs, int nresults)
Definition Sandbox.cpp:248
lua_State * GetLua() const
Definition LuaRef.h:26
void PushCopyToStack() const
Definition LuaRef.cpp:89
Definition LuaTable.h:189
VecIter operator--()
Definition LuaTable.h:231
VecIter(const VecIter ©)
Definition LuaTable.h:202
VecIter operator++(int)
Definition LuaTable.h:222
Value operator*()
Definition LuaTable.h:245
VecIter operator--(int)
Definition LuaTable.h:236
bool operator!=(const VecIter &other) const
Definition LuaTable.h:244
void operator=(const VecIter ©)
Definition LuaTable.h:207
~VecIter()
Definition LuaTable.h:196
VecIter()
Definition LuaTable.h:191
bool operator==(const VecIter &other) const
Definition LuaTable.h:243
VecIter(LuaTable *t, int currentIndex)
Definition LuaTable.h:197
VecIter operator++()
Definition LuaTable.h:214
const Value * operator->()
Definition LuaTable.h:250
Value Get(const Key &key) const
Definition LuaTable.h:326
lua_State * m_lua
Definition LuaTable.h:280
LuaTable PushValueToStack(const Key &key) const
Definition LuaTable.h:311
int GetIndex() const
Definition LuaTable.h:176
LuaTable(const LuaTable &ref)
Definition LuaTable.h:102
void Call(const Key &key, const Args &... args) const
Definition LuaTable.h:144
std::tuple< Ret1, Ret2, Ret... > CallMethod(const Key &key, const Args &... args) const
Definition LuaTable.h:162
LuaTable Set(const Key &key, const Value &value) const
Definition LuaTable.h:346
VecIter< Value > End()
Definition LuaTable.h:274
~LuaTable()
Definition LuaTable.h:122
std::map< Key, Value > GetMap() const
Definition LuaTable.h:355
LuaTable LoadVector(ValueIterator beg, ValueIterator end) const
Definition LuaTable.h:383
LuaTable(lua_State *l)
Definition LuaTable.h:108
Ret Call(const Key &key, const Args &... args) const
Definition LuaTable.h:394
Ret CallMethod(const Key &key, const Args &... args) const
Definition LuaTable.h:157
LuaTable(lua_State *l, int index)
Definition LuaTable.h:105
int m_index
Definition LuaTable.h:281
VecIter< Value > Begin()
Definition LuaTable.h:272
LuaTable(lua_State *l, int array_s, int hash_s)
Definition LuaTable.h:115
lua_State * GetLua() const
Definition LuaTable.h:175
size_t Size() const
Definition LuaTable.h:177
LuaTable()
Definition LuaTable.h:277
LuaTable LoadMap(PairIterator beg, PairIterator end) const
Definition LuaTable.h:375
const LuaTable & operator=(const LuaTable &ref)
Definition LuaTable.h:124
LuaTable Sub(const Key &key) const
Definition LuaTable.h:319
void CallMethod(const Key &key, const Args &... args) const
Definition LuaTable.h:152
Definition LuaTable.h:284
ScopedTable(lua_State *l)
Definition LuaTable.h:294
ScopedTable(const LuaTable &t)
Definition LuaTable.h:286
ScopedTable(const LuaRef &r)
Definition LuaTable.h:296
~ScopedTable()
Definition LuaTable.h:303
IMGUI_API void Value(const char *prefix, const std::string &str)
Definition PerfInfo.cpp:181