1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-28 18:18:52 +00:00
OpenMW/apps/openmw/mwlua/idcollectionbindings.hpp
2024-02-28 17:20:46 +01:00

26 lines
668 B
C++

#ifndef MWLUA_IDCOLLECTIONBINDINGS_H
#define MWLUA_IDCOLLECTIONBINDINGS_H
#include <functional>
#include <components/esm/refid.hpp>
#include <components/lua/luastate.hpp>
namespace MWLua
{
template <class C, class P = std::identity>
sol::table createReadOnlyRefIdTable(const sol::state_view& lua, const C& container, P projection = {})
{
sol::table res(lua, sol::create);
for (const auto& element : container)
{
ESM::RefId id = projection(element);
if (!id.empty())
res.add(id.serializeText());
}
return LuaUtil::makeReadOnly(res);
}
}
#endif