sharedstate: fix issue with falsy values

Setting a shared value to false would retain the old value since the
logic uses lua's fake "ternary"
This commit is contained in:
NullBite 2023-06-25 00:42:03 -04:00
parent ebd217dcc2
commit f6451345cd
Signed by: nullbite
GPG Key ID: 6C4D545385D4925A

View File

@ -8,6 +8,10 @@ get_value, resolve_key, resolve_index
--schema: similar to state_table, nested table only contains value --schema: similar to state_table, nested table only contains value
local state_queue={} local state_queue={}
local function ternary(condition, val_if_true, val_if_false)
if condition then return val_if_true else return val_if_false end
end
-- we're protecting internal variables here, i'm *that* scared of writing bad -- we're protecting internal variables here, i'm *that* scared of writing bad
-- code again. -- code again.
-- this section is purely for making sure the tables are in a consistent state -- this section is purely for making sure the tables are in a consistent state
@ -90,7 +94,7 @@ do
entry["callback"]=callback entry["callback"]=callback
else else
entry["value"]=value or entry["value"] entry["value"]=ternary(value ~= nil, value, entry["value"])
callback_value(key) callback_value(key)
entry["callback"]=callback or entry["callback"] entry["callback"]=callback or entry["callback"]
entry["old_value"]=value entry["old_value"]=value