sharedstate: cleanup, fix doc
This commit is contained in:
parent
b79ec7db1f
commit
34cd1f5956
@ -40,7 +40,8 @@ do
|
|||||||
local function init_key(key)
|
local function init_key(key)
|
||||||
logging.trace('init_key', key)
|
logging.trace('init_key', key)
|
||||||
if key == nil then
|
if key == nil then
|
||||||
error("sharedstate: A key name is required")
|
local errormsg="sharedstate: A key name is required"
|
||||||
|
error(errormsg)
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_initialized(key) then
|
if is_initialized(key) then
|
||||||
@ -127,11 +128,13 @@ end
|
|||||||
---initialization.
|
---initialization.
|
||||||
---@param key string key name
|
---@param key string key name
|
||||||
---@param value any initial value
|
---@param value any initial value
|
||||||
---@param callback function Callback function to run on value change
|
---@param callback? function Callback function to run on value change
|
||||||
function sharedstate.add(key, value, callback)
|
function sharedstate.add(key, value, callback)
|
||||||
logging.trace("sharedstate.add", key, value, callback)
|
logging.trace("sharedstate.add", key, value, callback)
|
||||||
set_value(key, value, callback)
|
set_value(key, value, callback)
|
||||||
end
|
end
|
||||||
|
-- alias so i can decide what feels better
|
||||||
|
sharedstate.init=sharedstate.add
|
||||||
|
|
||||||
--- Internal; transfer value over network
|
--- Internal; transfer value over network
|
||||||
---Ping used to transfer a value over the network, should not be called
|
---Ping used to transfer a value over the network, should not be called
|
||||||
@ -150,7 +153,9 @@ end
|
|||||||
function sharedstate.set(key, value)
|
function sharedstate.set(key, value)
|
||||||
logging.trace("sharedstate.set", key, value)
|
logging.trace("sharedstate.set", key, value)
|
||||||
if not is_initialized(key) then
|
if not is_initialized(key) then
|
||||||
error("sharedstate: Key " .. key .. " has not been initialized.")
|
-- this makes the error traceback less confusing
|
||||||
|
local errormsg="sharedstate: Key " .. key .. " has not been initialized."
|
||||||
|
error(errormsg)
|
||||||
end
|
end
|
||||||
pings.sharedstate_transfer(resolve_index(key), value)
|
pings.sharedstate_transfer(resolve_index(key), value)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user