-- =================================================================== -- /processes.lua -- Process-related functions for Modular Politics -- Called by modpol.lua -- TKTK may need to create high-level modpol.processes table to hold ongoing processes -- TKTK in order to enable async processes. Rewrite all this as listeners -- =================================================================== -- Function: modpol.consent -- Params: org (string), proposal (string) -- Outputs: boolean - true if consent achieved or false; nil on error -- Also includes a table of responses -- This is the default decision-making routine for Modular Politics -- Stops at the first "No" vote modpol.consent = function(org, query) -- Check that org exists if modpol.orgs[org] == nil then return nil, "Error: Org does not exist" end -- Poll all members local responses = {} for index, value in ipairs(modpol.orgs[org]["members"]) do local response = modpol.binary_poll_user(value, query) responses[value] = response if response == "No" then return false, responses end end return true, responses end -- TKTK exploring modpol.initiate functions, which have no args -- Need to properly document these modpol.initiate = {} modpol.initiate.consent = function(org) print("What is your query?") local query = io.read() return modpol.consent(org, query) end -- Function: modpol.switchboard -- Params: org (string), routine (string) -- Outputs: Checks the org for any policies related to a given function; -- Calls the modpol.initiate.* function(org) based on policy -- Defaults to modpol.initiate.consent() modpol.switchboard = function(org, routine) if modpol.orgs[org]["policies"] and modpol.orgs[org]["policies"][routine] then -- TKTK if there exists a policy else modpol.initiate.consent(org) end end