diff options
author | Vitaliy <numzer0@yandex.ru> | 2020-09-21 22:32:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-21 22:32:25 +0300 |
commit | 6921909100050c7d9509a2bcddc0ca178a7e0e37 (patch) | |
tree | 5b4d951ba443617f1886b61a2e41732e2f153317 /mesecons/util.lua | |
parent | 3202bf6786d855566b06ce04719c25822dcd7328 (diff) | |
download | mesecons-6921909100050c7d9509a2bcddc0ca178a7e0e37.tar mesecons-6921909100050c7d9509a2bcddc0ca178a7e0e37.tar.gz mesecons-6921909100050c7d9509a2bcddc0ca178a7e0e37.tar.bz2 mesecons-6921909100050c7d9509a2bcddc0ca178a7e0e37.tar.xz mesecons-6921909100050c7d9509a2bcddc0ca178a7e0e37.zip |
Restrict Lua controller interrupt IDs (#534)
* Deprecate non-string IIDs
* Restrict tabular IIDs to proper trees
Fixes crash on recursive interrupt ID (#473)
Diffstat (limited to 'mesecons/util.lua')
-rw-r--r-- | mesecons/util.lua | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/mesecons/util.lua b/mesecons/util.lua index 7485cac..f1f88d6 100644 --- a/mesecons/util.lua +++ b/mesecons/util.lua @@ -193,14 +193,23 @@ function mesecon.tablecopy(obj) -- deep copy return obj end +-- Returns whether two values are equal. +-- In tables, keys are compared for identity but values are compared recursively. +-- There is no protection from infinite recursion. function mesecon.cmpAny(t1, t2) if type(t1) ~= type(t2) then return false end - if type(t1) ~= "table" and type(t2) ~= "table" then return t1 == t2 end + if type(t1) ~= "table" then return t1 == t2 end + -- Check that for each key of `t1` both tables have the same value for i, e in pairs(t1) do if not mesecon.cmpAny(e, t2[i]) then return false end end + -- Check that all keys of `t2` are also keys of `t1` so were checked in the previous loop + for i, _ in pairs(t2) do + if t1[i] == nil then return false end + end + return true end |