MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / tableIterate

Method tableIterate

source/core/StarLua.cpp:867–890  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

865}
866
867void LuaEngine::tableIterate(int handleIndex, function<bool(LuaValue key, LuaValue value)> iterator) {
868 lua_checkstack(m_state, 4);
869
870 pushHandle(m_state, handleIndex);
871 lua_pushnil(m_state);
872 while (lua_next(m_state, -2) != 0) {
873 lua_pushvalue(m_state, -2);
874 LuaValue key = popLuaValue(m_state);
875 LuaValue value = popLuaValue(m_state);
876 bool cont = false;
877 try {
878 cont = iterator(std::move(key), std::move(value));
879 } catch (...) {
880 lua_pop(m_state, 2);
881 throw;
882 }
883 if (!cont) {
884 lua_pop(m_state, 1);
885 break;
886 }
887 }
888
889 lua_pop(m_state, 1);
890}
891
892Maybe<LuaTable> LuaEngine::tableGetMetatable(int handleIndex) {
893 lua_checkstack(m_state, 2);

Callers 2

iterateMethod · 0.80
iterateWithSignatureMethod · 0.80

Calls 5

lua_checkstackFunction · 0.85
lua_pushnilFunction · 0.85
lua_nextFunction · 0.85
lua_pushvalueFunction · 0.85
iteratorClass · 0.70

Tested by

no test coverage detected