diff --git a/library/include/LuaTools.h b/library/include/LuaTools.h index c8237eb56..e1d828271 100644 --- a/library/include/LuaTools.h +++ b/library/include/LuaTools.h @@ -341,6 +341,14 @@ namespace DFHack {namespace Lua { DFHACK_EXPORT int PushPosXYZ(lua_State *state, df::coord pos); DFHACK_EXPORT int PushPosXY(lua_State *state, df::coord2d pos); + template + inline void TableInsert(lua_State *state, T_Key key, T_Value value) + { + Lua::Push(state, key); + Lua::Push(state, value); + lua_settable(state, -3); + } + DFHACK_EXPORT void CheckPen(lua_State *L, Screen::Pen *pen, int index, bool allow_nil = false, bool allow_color = true); DFHACK_EXPORT bool IsCoreContext(lua_State *state); diff --git a/plugins/confirm.cpp b/plugins/confirm.cpp index 3ea5d540c..b9927f4ea 100644 --- a/plugins/confirm.cpp +++ b/plugins/confirm.cpp @@ -176,19 +176,12 @@ namespace conf_lua { { Lua::Push(l_state, val); } - template - void table_set (lua_State *L, KeyType k, ValueType v) - { - Lua::Push(L, k); - Lua::Push(L, v); - lua_settable(L, -3); - } namespace api { int get_ids (lua_State *L) { lua_newtable(L); for (auto it = confirmations.begin(); it != confirmations.end(); ++it) - table_set(L, it->first, true); + Lua::TableInsert(L, it->first, true); return 1; } int get_conf_data (lua_State *L) @@ -199,8 +192,8 @@ namespace conf_lua { { Lua::Push(L, i++); lua_newtable(L); - table_set(L, "id", it->first); - table_set(L, "enabled", it->second->is_enabled()); + Lua::TableInsert(L, "id", it->first); + Lua::TableInsert(L, "enabled", it->second->is_enabled()); lua_settable(L, -3); } return 1; diff --git a/plugins/dwarfmonitor.cpp b/plugins/dwarfmonitor.cpp index 8e2a88611..2c78c0854 100644 --- a/plugins/dwarfmonitor.cpp +++ b/plugins/dwarfmonitor.cpp @@ -187,14 +187,6 @@ namespace dm_lua { return safe_call(nargs); } - template - void table_set (lua_State *L, KeyType k, ValueType v) - { - Lua::Push(L, k); - Lua::Push(L, v); - lua_settable(L, -3); - } - namespace api { int monitor_state (lua_State *L) { @@ -229,7 +221,7 @@ namespace dm_lua { } } lua_newtable(L); - #define WTYPE(type, name) dm_lua::table_set(L, #type, type); + #define WTYPE(type, name) Lua::TableInsert(L, #type, type); WEATHER_TYPES #undef WTYPE #undef WEATHER_TYPES @@ -242,9 +234,9 @@ namespace dm_lua { { Lua::Push(L, i); lua_newtable(L); - dm_lua::table_set(L, "value", misery[i]); - dm_lua::table_set(L, "color", monitor_colors[i]); - dm_lua::table_set(L, "last", (i == 6)); + Lua::TableInsert(L, "value", misery[i]); + Lua::TableInsert(L, "color", monitor_colors[i]); + Lua::TableInsert(L, "last", (i == 6)); lua_settable(L, -3); } return 1;