Compare commits

..

No commits in common. "ad783d8a7e5361642406d3bcd51ce1b0accd78a9" and "ebd217dcc201b7adf07a0604a2704ef834009161" have entirely different histories.

View File

@ -8,10 +8,6 @@ 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
@ -85,7 +81,7 @@ do
---@param value any value ---@param value any value
---@param callback? function callback function ---@param callback? function callback function
function set_value(key, value, callback) function set_value(key, value, callback)
logging.debug("sharedstate: key " .. tostring(key) .. " set to " .. tostring(value)) logging.trace("set_value", key, value, callback)
local initialized=init_key(key) local initialized=init_key(key)
local entry=state_table[key] local entry=state_table[key]
if initialized then if initialized then
@ -94,7 +90,7 @@ do
entry["callback"]=callback entry["callback"]=callback
else else
entry["value"]=ternary(value ~= nil, value, entry["value"]) entry["value"]=value or 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
@ -183,11 +179,8 @@ function sharedstate.set(key, value)
local errormsg="sharedstate: Key " .. key .. " has not been initialized." local errormsg="sharedstate: Key " .. key .. " has not been initialized."
error(errormsg) error(errormsg)
end end
-- don't bother sending unchanged values pings.sharedstate_recv(resolve_index(key), value)
if value ~= get_value(key) then -- pings.sharedstate_recv_named(key, value)
-- pings.sharedstate_recv(resolve_index(key), value)
pings.sharedstate_recv_named(key, value)
end
end end
---Queue entries for sending ---Queue entries for sending