diff --git a/sharedstate.lua b/sharedstate.lua index 018e4cd..e0ca2cf 100644 --- a/sharedstate.lua +++ b/sharedstate.lua @@ -40,7 +40,8 @@ do local function init_key(key) logging.trace('init_key', key) if key == nil then - error("sharedstate: A key name is required") + local errormsg="sharedstate: A key name is required" + error(errormsg) end if is_initialized(key) then @@ -127,11 +128,13 @@ end ---initialization. ---@param key string key name ---@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) logging.trace("sharedstate.add", key, value, callback) set_value(key, value, callback) end +-- alias so i can decide what feels better +sharedstate.init=sharedstate.add --- Internal; transfer value over network ---Ping used to transfer a value over the network, should not be called @@ -150,7 +153,9 @@ end function sharedstate.set(key, value) logging.trace("sharedstate.set", key, value) 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 pings.sharedstate_transfer(resolve_index(key), value) end