From 8ee05af6efa0260457a87bff05333a9a858180ac Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Tue, 7 Feb 2023 15:11:17 -0800 Subject: [PATCH 01/13] update logo to crisper version provided by TaxiService --- data/art/dfhack.png | Bin 1465 -> 372 bytes docs/changelog.txt | 1 + 2 files changed, 1 insertion(+) diff --git a/data/art/dfhack.png b/data/art/dfhack.png index 17719f084a45a3b037bab5fd4355d5f76f674fbd..7cbb5dbf6201a921aae295aa71fbfa45297636fb 100644 GIT binary patch delta 356 zcmV-q0h|803-khz8Gix*003u+ueAUG02y>eSaefwW^{L9a%BKPWN%_+AW3auXJt}l zVPtu6$z?nM008_+L_t(|+Qe5u4#Xe`ti-?WrO)Z5uXUSkVhDpMR=Olj3_+j+jG9U* zTcqUcJB~BR`@Vm2T`l*1=S^F%ga^oVl~S@zYddr;xiO)tC4bd#`H66cN(CZyn;OGT zobOs+1CbMXH_R7#P%e}(q=3#1QTHc!wcHR*qaRXaj6s9Azeg3`rlQdFJ8g=tCuYJ; zcBo+t``Cb@`2ZgQVyu z)K`E305ylW-7c57cK`qY4rN$LW=%~1DgXcg2mk;800000(o>TF0000R{AK$GU=4uJ=cBK$ zkEy9C#>dA=CX?9hb`@l`TG8wOi`8T@aq!?lnwpwevt|td@87@Y?c2A6!(ry;=7>Zh z#N%=Net+JHo12?Cefl)W|LoPPR|06Ry1F_!ckZ0#z0GEmg@uL8aQX4$ht$>8<;>C9 z*(r^Ujal!UPJgF}h$sLeB5iGLn!z5AM-~?s<>t+s8ed;u-}2$|`0-;+%!?NpWn}>D+qVzD-%n|2X?`VKIaw|eO-@c~Vlq`(w{Bf7 zj;Z^Vlm8KbWHPDl)9EyWgM(RqlgUI)O-)_^@p$~tdqFT5T(tr&my6!s-Yoz1>(|x9 zxt1pui~Tu(PoF+%0=!-?0Dixp_V#v-zrMacXMeRaR!~sz`(^~NxVXr`zC+%x7%fD zX-Pyxd_JG__xH>0-Ma;l!-o$`b#=8G*VEG@A3uJ~5}=IfL`3H2=U0`?!oorf1_MP! zMSnS2p3#AVf&xlPO3>@|h=^Je5m7l-n(qH`CQK%i7z_q=UdUJ^64C6GtcXx3#Kgpe zN|H*YlyB$Gos^fC<8rx(#bU}=RaM1~9XoKjTzvoj9k18R-Me?WeEBkEWo3B1UYeSk za5|lIcX#vr`SbkED4kAAZ*Q*va_7z+)qh@FTU#ZSN{NU_XJ=;?FMK|qYCY&I*2jz**0xN#$^syPp(nVuex#}&EK=`;W%BO`b`9)D~$ z8&y?RSq*3V_U%+wRuYTFsIRYQ{rdGvdXFDJPFGhKwY9aBl$7M>Kn6KLTU#63wrvAY zs2@Ij2*BC1XPKOw#N+W0jYb(B9_GM-1L*a7YHDh**=!US7pq)n&YWRpW(KR(N+1wW z%}c|9j3xlm(a|Aq-n(64=dNVr>92%`TY5_ z3=ItlAQKZ4`8lw>B_BI>jOyxYrIMjgNb$t&b~7|Iq~aSI8kAfwxAO9GH6~N~mCC3A zkU3N&5(xz+9*?U|`SRsU#>U2|sHjlewXv~L{U78yPbQN|)u^J;=;{D6#DDwx^{XOZ zC=^mEXt7vmZf@q(sZ#*_`t=L5*^JR> Date: Tue, 7 Feb 2023 15:40:23 -0800 Subject: [PATCH 02/13] add light AA --- data/art/dfhack.png | Bin 372 -> 997 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/data/art/dfhack.png b/data/art/dfhack.png index 7cbb5dbf6201a921aae295aa71fbfa45297636fb..133dc5aaf8c98921bcc0203ebd986d4915c726cd 100644 GIT binary patch delta 906 zcmV;519klL0_6vgNPh!uNklIMuJ-o!v_=t}TK@FQbar-Dencvj z!dNbsrOxQ+Xp5lg4mvwKVuhlhuM ztZb{*sz`>1hX)4--EMa%6heXNG+KS4a4AVf6_Mj;G=KW;93UX8tE)T>1Ogb_+S;U! zGJT%|e6^fTPfu$TMsT9zKvAOU*4CChJ`zX?pqMb3OeTG>J3T#>3&4rp-Cb!N(Vv-_ zA^!02P%0}$RR!!6Y>@_JMUaX`pHBK%RG$b-lF1}7OzZ3GRYJ76 zxruKC9Dgw~gGXerDgy!`kQuQeO&Xm}C#^!xSX~pYVH74L2uoy!GrkM}-6T9XIN)1B z>p%@rM@I);ji?!7VzC&nK0Q6{@9(3uu!=8cROf!4n3w?iqBmC0_YV-5+Hk*xF8o+wK0M5_PF^-RqQ!8CxUo$|#0a*t_`a?rQ0|Ns(&lW-g9G?o2 z;)68a-QAI0ATt=qv8p^|AVCb3>qyOk#bV(TF%^qN+6e;g)5Wr}vB3(2-U>je4({*o zF@HWjK5Eh5<#HiPtTQz=Mb(wd<>X#=Aff3`h){fhHo6fxM2m}yNH|V+c6Meqn@NsF zMS&h29c^!Kqim4>_V#wj=_oxtJu3En1dHTzhzQM0ZHTAQN3lq@7!#g3D6QAmSAH6O g)$6)(|3R7?{TJ$|00RKEP1L&_iGFGT0FzJwBvOyD5&!@I delta 275 zcmV+u0qp+e2lN7vNPhtQNklpPA!$osy3a$PO=e&u5fhrM(!ILoC~>82Y#lgA?%Yd@eB5k0J_jn%(!&A9 zBTpnmPf|wohPsH`856YfLo+t``Cb@`2Z ZgQVyu)K`E300=dQxZN(7xObDk119bWfv^Ao From c1b9de87d2303acecd763d71c020d70046049dc8 Mon Sep 17 00:00:00 2001 From: Robob27 Date: Mon, 6 Feb 2023 22:40:59 -0500 Subject: [PATCH 03/13] Add case_sensitive attr to FilteredList --- library/lua/gui/widgets.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index d8c605b93..61cd92cfa 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -1866,6 +1866,7 @@ end FilteredList = defclass(FilteredList, Widget) FilteredList.ATTRS { + case_sensitive = true, edit_below = false, edit_key = DEFAULT_NIL, edit_ignore_keys = DEFAULT_NIL, @@ -2026,11 +2027,17 @@ function FilteredList:setFilter(filter, pos) -- start matches at non-space or non-punctuation. this allows -- punctuation itself to be matched if that is useful (e.g. -- filenames or parameter names) - if key ~= '' and + if key ~= '' then + if self.case_sensitive and not search_key:match('%f[^%p\x00]'..key) and not search_key:match('%f[^%s\x00]'..key) then - ok = false - break + ok = false + break + elseif not string.lower(search_key):match('%f[^%p\x00]'..string.lower(key)) and + not string.lower(search_key):match('%f[^%s\x00]'..string.lower(key)) then + ok = false + break + end end end if ok then From 13440d18a85f4fb2de4f0d4f71137ff84f76dd9c Mon Sep 17 00:00:00 2001 From: Robob27 Date: Mon, 6 Feb 2023 22:48:18 -0500 Subject: [PATCH 04/13] Add case_sensitive to FilteredList docs --- docs/dev/Lua API.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 503f4bece..3580b5244 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -4958,6 +4958,7 @@ construction that allows filtering the list by subwords of its items. In addition to passing through all attributes supported by List, it supports: +:case_sensitive: If true, matching is case sensitive. Defaults to true. :edit_pen: If specified, used instead of ``cursor_pen`` for the edit field. :edit_below: If true, the edit field is placed below the list instead of above. :edit_key: If specified, the edit field is disabled until this key is pressed. From 54560bc5dbab1b0b1ddaf26d5e73487aaf8f15fa Mon Sep 17 00:00:00 2001 From: Robob27 Date: Wed, 8 Feb 2023 02:02:50 -0500 Subject: [PATCH 05/13] Don't duplicate regex --- library/lua/gui/widgets.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index 61cd92cfa..c249b579f 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -2028,15 +2028,15 @@ function FilteredList:setFilter(filter, pos) -- punctuation itself to be matched if that is useful (e.g. -- filenames or parameter names) if key ~= '' then - if self.case_sensitive and - not search_key:match('%f[^%p\x00]'..key) and + if not self.case_sensitive then + search_key = string.lower(search_key) + key = string.lower(key) + end + + if not search_key:match('%f[^%p\x00]'..key) and not search_key:match('%f[^%s\x00]'..key) then ok = false break - elseif not string.lower(search_key):match('%f[^%p\x00]'..string.lower(key)) and - not string.lower(search_key):match('%f[^%s\x00]'..string.lower(key)) then - ok = false - break end end end From dd10451c2f66b16f0097ef622290803151dd0919 Mon Sep 17 00:00:00 2001 From: Janeene Beeforth Date: Wed, 8 Feb 2023 17:42:42 +1100 Subject: [PATCH 06/13] Remove library/military silver crossbow work-order It is not possible to create a work-order for making silver crossbows, so the silver crossbow recipe belongs in the alternative military library with other artifact/non-craftable weapon recipes. It's already present in the library/military_include_artifact_materials work-orders, so simply needed removal from the vanilla library/military orders version. --- data/orders/military.json | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/data/orders/military.json b/data/orders/military.json index 5b7604dac..0d06dd124 100644 --- a/data/orders/military.json +++ b/data/orders/military.json @@ -1138,42 +1138,6 @@ "job" : "MakeWeapon", "material" : "INORGANIC:SILVER" }, - { - "amount_left" : 1, - "amount_total" : 1, - "frequency" : "Daily", - "id" : 64, - "is_active" : false, - "is_validated" : false, - "item_conditions" : - [ - { - "condition" : "AtLeast", - "item_type" : "BAR", - "material" : "INORGANIC:SILVER", - "value" : 20 - }, - { - "condition" : "AtLeast", - "item_type" : "BAR", - "material" : "COAL", - "value" : 100 - }, - { - "condition" : "AtMost", - "flags" : - [ - "metal" - ], - "item_subtype" : "ITEM_WEAPON_CROSSBOW", - "item_type" : "WEAPON", - "value" : 10 - } - ], - "item_subtype" : "ITEM_WEAPON_CROSSBOW", - "job" : "MakeWeapon", - "material" : "INORGANIC:SILVER" - }, { "amount_left" : 1, "amount_total" : 1, From 24827eabe268df2d762e4403f0261e2cf376b1c5 Mon Sep 17 00:00:00 2001 From: Janeene Beeforth Date: Wed, 8 Feb 2023 20:25:52 +1100 Subject: [PATCH 07/13] Remove checks for silver from library/military for crossbows. --- data/orders/military.json | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/data/orders/military.json b/data/orders/military.json index 0d06dd124..0e53747b6 100644 --- a/data/orders/military.json +++ b/data/orders/military.json @@ -1620,12 +1620,6 @@ "item_type" : "WEAPON", "material" : "INORGANIC:STEEL", "value" : 10 - }, - { - "condition" : "LessThan", - "item_type" : "BAR", - "material" : "INORGANIC:SILVER", - "value" : 5 } ], "item_subtype" : "ITEM_WEAPON_CROSSBOW", @@ -2321,12 +2315,6 @@ "material" : "INORGANIC:STEEL", "value" : 30 }, - { - "condition" : "LessThan", - "item_type" : "BAR", - "material" : "INORGANIC:SILVER", - "value" : 5 - }, { "condition" : "AtMost", "flags" : @@ -3032,12 +3020,6 @@ "material" : "INORGANIC:STEEL", "value" : 30 }, - { - "condition" : "LessThan", - "item_type" : "BAR", - "material" : "INORGANIC:SILVER", - "value" : 5 - }, { "condition" : "AtMost", "flags" : @@ -3820,12 +3802,6 @@ "material" : "INORGANIC:STEEL", "value" : 30 }, - { - "condition" : "LessThan", - "item_type" : "BAR", - "material" : "INORGANIC:SILVER", - "value" : 5 - }, { "condition" : "AtMost", "flags" : @@ -4698,12 +4674,6 @@ "material" : "INORGANIC:STEEL", "value" : 30 }, - { - "condition" : "LessThan", - "item_type" : "BAR", - "material" : "INORGANIC:SILVER", - "value" : 5 - }, { "condition" : "AtMost", "flags" : From 1f38b294cbdb34b0eedd6be503d0b034bbe559f3 Mon Sep 17 00:00:00 2001 From: Janeene Beeforth Date: Wed, 8 Feb 2023 20:32:32 +1100 Subject: [PATCH 08/13] Add note in changelog about silver crossbows --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index ece6f04e1..9faa0ab4f 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -49,6 +49,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `clean`: new hotkey for `spotclean`: Ctrl-C - `autobutcher`: changed defaults from 5 females / 1 male to 4 females / 2 males so a single unfortunate accident doesn't leave players without a mating pair - `autobutcher`: now immediately loads races available at game start into the watchlist +- `orders`: recipe for silver crossbows removed from ``library/military`` as it is not a vanilla recipe, but is available in ``library/military_include_artifact_materials`` ## Documentation From 22b31bd7f1d970e65397edb5cde72dc3c4b82a24 Mon Sep 17 00:00:00 2001 From: Robob27 Date: Wed, 8 Feb 2023 12:37:35 -0500 Subject: [PATCH 09/13] Update changelog --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index ece6f04e1..fbc26f062 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -57,6 +57,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Lua - `overlay`: overlay widgets can now specify focus paths for the viewscreens they attach to so they only appear in specific contexts. see `overlay-dev-guide` for details. - ``widgets.CycleHotkeyLabel``: Added ``key_back`` optional parameter to cycle backwards. +- ``widgets.FilteredList``: Added ``case_sensitive`` optional paramter to determine if filtering is case sensitive. ## Removed From b950b569267888a6f0a61c81adc08406c805d9a5 Mon Sep 17 00:00:00 2001 From: Robob27 Date: Wed, 8 Feb 2023 13:00:13 -0500 Subject: [PATCH 10/13] Add methods to HotkeyLabel --- docs/changelog.txt | 2 ++ docs/dev/Lua API.rst | 10 ++++++++++ library/lua/gui/widgets.lua | 14 ++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index ece6f04e1..7ba027f76 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -57,6 +57,8 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Lua - `overlay`: overlay widgets can now specify focus paths for the viewscreens they attach to so they only appear in specific contexts. see `overlay-dev-guide` for details. - ``widgets.CycleHotkeyLabel``: Added ``key_back`` optional parameter to cycle backwards. +- ``widgets.HotkeyLabel``: Added ``setLabel`` method to allow easily updating the label text without mangling the keyboard shortcut. +- ``widgets.HotkeyLabel``: Added ``setOnActivate`` method to allow easily updating the ``on_activate`` callback. ## Removed diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 503f4bece..43ed9c935 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -4808,6 +4808,16 @@ It has the following attributes: :on_activate: If specified, it is the callback that will be called whenever the hotkey is pressed or the label is clicked. +The HotkeyLabel widget implements the following methods: + +* ``hotkeylabel:setLabel(label)`` + + Updates the label without altering the hotkey text. + +* ``hotkeylabel:setOnActivate(on_activate)`` + + Updates the on_activate callback. + CycleHotkeyLabel class ---------------------- diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index d8c605b93..580273dc8 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -1419,6 +1419,20 @@ HotkeyLabel.ATTRS{ } function HotkeyLabel:init() + self:initializeLabel() +end + +function HotkeyLabel:setOnActivate(on_activate) + self.on_activate = on_activate + self:initializeLabel() +end + +function HotkeyLabel:setLabel(label) + self.label = label + self:initializeLabel() +end + +function HotkeyLabel:initializeLabel() self:setText{{key=self.key, key_sep=self.key_sep, text=self.label, on_activate=self.on_activate}} end From 5d8d378917c75c61fed72a6e37009838edee4ec5 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Wed, 8 Feb 2023 12:03:40 -0800 Subject: [PATCH 11/13] Implements plugin: channel-safely v1.2.3 - Revises a few log lines - Adds d_assert macro to replace assert usage - prints an error to indicate d_assert failed in Release builds as well as Debug builds - could be added to the Debug utilities to allow use of assertions on necessary code without needing to buffer the results for use in the assert statement - Fixes bug wherein designations are never put into marker mode (related to the assert statements) --- plugins/channel-safely/channel-manager.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/plugins/channel-safely/channel-manager.cpp b/plugins/channel-safely/channel-manager.cpp index c22bd8a8e..aa7a24461 100644 --- a/plugins/channel-safely/channel-manager.cpp +++ b/plugins/channel-safely/channel-manager.cpp @@ -5,7 +5,17 @@ #include //hash function for df::coord #include +#define NUMARGS(...) std::tuple_size::value +#define d_assert(condition, ...) \ + static_assert(NUMARGS(__VA_ARGS__) >= 1, "d_assert(condition, format, ...) requires at least up to format as arguments"); \ + if (!condition) { \ + DFHack::Core::getInstance().getConsole().printerr(__VA_ARGS__); \ + assert(0); \ + } + + df::unit* find_dwarf(const df::coord &map_pos) { + df::unit* nearest = nullptr; uint32_t distance; for (auto unit : df::global::world->units.active) { @@ -57,6 +67,7 @@ void ChannelManager::manage_group(const Group &group, bool set_marker_mode, bool // cavein prevention bool cavein_possible = false; uint8_t least_access = 100; + std::unordered_map cavein_candidates; if (!marker_mode) { /* To prevent cave-ins we're looking at accessibility of tiles with open space below them @@ -111,7 +122,7 @@ void ChannelManager::manage_group(const Group &group, bool set_marker_mode, bool // if no cave-in is possible [or we don't check for], we'll just execute normally and move on if (!cavein_possible) { TRACE(manager).print("cave-in evaluated false\n"); - assert(manage_one(pos, true, marker_mode)); + d_assert(manage_one(pos, true, marker_mode), "manage_one() is failing under !cavein"); continue; } // cavein is only possible if marker_mode is false @@ -136,16 +147,16 @@ void ChannelManager::manage_group(const Group &group, bool set_marker_mode, bool evT->priority[Coord(local)] = v; } } - assert(manage_one(pos, true, false)); + d_assert(manage_one(pos, true, false), "manage_one() is failing for cavein "); continue; } // cavein possible, but we failed to meet the criteria for activation if (cavein_candidates.count(pos)) { - DEBUG(manager).print("cave-in evaluated true and no dignow and (%d > %d)\n", cavein_candidates[pos], least_access+OFFSET); + DEBUG(manager).print("cave-in evaluated true and the cavein candidate's accessibility check was made as (%d <= %d)\n", cavein_candidates[pos], least_access+OFFSET); } else { - DEBUG(manager).print("cave-in evaluated true and no dignow and pos is not a candidate\n"); + DEBUG(manager).print("cave-in evaluated true and the position was not a candidate, nor was it set for dignow\n"); } - assert(manage_one(pos, true, true)); + d_assert(manage_one(pos, true, true), "manage_one() is failing to set a cave-in causing designation to marker mode"); } INFO(manager).print("manage_group() is done\n"); } From caeb6d2f84786b953b1d7400669cc9306b5879af Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Wed, 8 Feb 2023 12:09:32 -0800 Subject: [PATCH 12/13] Updates changelog --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index ece6f04e1..f8d8e041b 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -39,6 +39,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - ``Units::isFortControlled``: Account for agitated wildlife - Fix right click sometimes closing both a DFHack window and a vanilla panel - Fixed issue with scrollable lists having some data off-screen if they were scrolled before being made visible +- `channel-safely`: fixed bug resulting in marker mode never being set for any designation ## Misc Improvements - `automelt`: is now more resistent to savegame corruption From cd12f95849be5c519b83a15cc8bf1ceb6a64cea0 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 8 Feb 2023 12:15:19 -0800 Subject: [PATCH 13/13] add const & to Push overloads; remove circular def --- library/LuaApi.cpp | 2 +- library/LuaTools.cpp | 8 ++++---- library/include/LuaTools.h | 39 +++++++++++++++++++++----------------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 45ea7d84d..69d43821e 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -478,7 +478,7 @@ static void OpenPersistent(lua_State *state) static int DFHACK_MATINFO_TOKEN = 0; -void Lua::Push(lua_State *state, MaterialInfo &info) +void Lua::Push(lua_State *state, const MaterialInfo &info) { if (!info.isValid()) { diff --git a/library/LuaTools.cpp b/library/LuaTools.cpp index b4d009c7b..ed0b0699d 100644 --- a/library/LuaTools.cpp +++ b/library/LuaTools.cpp @@ -101,7 +101,7 @@ void DFHack::Lua::Push(lua_State *state, const Units::NoblePosition &pos) lua_setfield(state, -2, "position"); } -void DFHack::Lua::Push(lua_State *state, df::coord pos) +void DFHack::Lua::Push(lua_State *state, const df::coord &pos) { lua_createtable(state, 0, 3); lua_pushinteger(state, pos.x); @@ -112,7 +112,7 @@ void DFHack::Lua::Push(lua_State *state, df::coord pos) lua_setfield(state, -2, "z"); } -void DFHack::Lua::Push(lua_State *state, df::coord2d pos) +void DFHack::Lua::Push(lua_State *state, const df::coord2d &pos) { lua_createtable(state, 0, 2); lua_pushinteger(state, pos.x); @@ -191,7 +191,7 @@ void DFHack::Lua::PushInterfaceKeys(lua_State *L, } } -int DFHack::Lua::PushPosXYZ(lua_State *state, df::coord pos) +int DFHack::Lua::PushPosXYZ(lua_State *state, const df::coord &pos) { if (!pos.isValid()) { @@ -207,7 +207,7 @@ int DFHack::Lua::PushPosXYZ(lua_State *state, df::coord pos) } } -int DFHack::Lua::PushPosXY(lua_State *state, df::coord2d pos) +int DFHack::Lua::PushPosXY(lua_State *state, const df::coord2d &pos) { if (!pos.isValid()) { diff --git a/library/include/LuaTools.h b/library/include/LuaTools.h index ca9aac788..86d3d0c7e 100644 --- a/library/include/LuaTools.h +++ b/library/include/LuaTools.h @@ -325,10 +325,10 @@ namespace DFHack {namespace Lua { inline void Push(lua_State *state, const std::string &str) { lua_pushlstring(state, str.data(), str.size()); } - DFHACK_EXPORT void Push(lua_State *state, df::coord obj); - DFHACK_EXPORT void Push(lua_State *state, df::coord2d obj); + DFHACK_EXPORT void Push(lua_State *state, const df::coord &obj); + DFHACK_EXPORT void Push(lua_State *state, const df::coord2d &obj); void Push(lua_State *state, const Units::NoblePosition &pos); - DFHACK_EXPORT void Push(lua_State *state, MaterialInfo &info); + DFHACK_EXPORT void Push(lua_State *state, const MaterialInfo &info); DFHACK_EXPORT void Push(lua_State *state, const Screen::Pen &info); template inline void Push(lua_State *state, T *ptr) { PushDFObject(state, ptr); @@ -361,29 +361,34 @@ namespace DFHack {namespace Lua { DFHACK_EXPORT void GetVector(lua_State *state, std::vector &pvec); - 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 int PushPosXYZ(lua_State *state, const df::coord &pos); + DFHACK_EXPORT int PushPosXY(lua_State *state, const df::coord2d &pos); template void Push(lua_State *L, const std::map &pmap) { lua_createtable(L, 0, pmap.size()); - for (auto &entry : pmap) - TableInsert(L, entry.first, entry.second); + for (auto &entry : pmap) { + Lua::Push(L, entry.first); + Lua::Push(L, entry.second); + lua_settable(L, -3); + } } template void Push(lua_State *L, const std::unordered_map &pmap) { lua_createtable(L, 0, pmap.size()); - for (auto &entry : pmap) - TableInsert(L, entry.first, entry.second); + for (auto &entry : pmap) { + Lua::Push(L, entry.first); + Lua::Push(L, entry.second); + lua_settable(L, -3); + } + } + + template + inline void TableInsert(lua_State *state, const T_Key &key, const 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);