1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-29 12:20:41 +00:00
OpenMW/apps/openmw/mwlua/idcollectionbindings.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
668 B
C++
Raw Normal View History

2024-02-28 16:20:46 +00:00
#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