From f6451345cd014ff1147d8b04f7f3b8d33a32b933 Mon Sep 17 00:00:00 2001 From: NullBite Date: Sun, 25 Jun 2023 00:42:03 -0400 Subject: [PATCH] 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" --- sharedstate.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sharedstate.lua b/sharedstate.lua index 1845cb4..dc4d5b4 100644 --- a/sharedstate.lua +++ b/sharedstate.lua @@ -8,6 +8,10 @@ get_value, resolve_key, resolve_index --schema: similar to state_table, nested table only contains value 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 -- code again. -- this section is purely for making sure the tables are in a consistent state @@ -90,7 +94,7 @@ do entry["callback"]=callback else - entry["value"]=value or entry["value"] + entry["value"]=ternary(value ~= nil, value, entry["value"]) callback_value(key) entry["callback"]=callback or entry["callback"] entry["old_value"]=value