add Lua::Push for sets

develop
Myk Taylor 2023-03-15 00:28:18 -07:00
parent 7edc686753
commit c47f068769
No known key found for this signature in database
1 changed files with 21 additions and 0 deletions

@ -31,6 +31,7 @@ distribution.
#include <map>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include "df/interfacest.h"
@ -364,6 +365,26 @@ namespace DFHack {namespace Lua {
DFHACK_EXPORT int PushPosXYZ(lua_State *state, const df::coord &pos);
DFHACK_EXPORT int PushPosXY(lua_State *state, const df::coord2d &pos);
template<typename T>
void Push(lua_State *L, const std::set<T> &pset) {
lua_createtable(L, 0, pset.size());
for (auto &entry : pset) {
Lua::Push(L, entry);
Lua::Push(L, true);
lua_settable(L, -3);
}
}
template<typename T_Key, typename T_Hash>
void Push(lua_State *L, const std::unordered_set<T_Key, T_Hash> &pset) {
lua_createtable(L, 0, pset.size());
for (auto &entry : pset) {
Lua::Push(L, entry);
Lua::Push(L, true);
lua_settable(L, -3);
}
}
template<typename T_Key, typename T_Value>
void Push(lua_State *L, const std::map<T_Key, T_Value> &pmap) {
lua_createtable(L, 0, pmap.size());