diff --git a/src/base/api.lua b/src/base/api.lua index 67fe607b..f0d5573b 100644 --- a/src/base/api.lua +++ b/src/base/api.lua @@ -74,6 +74,36 @@ end +-- +-- Add a new value to a field's list of allowed values. +-- +-- @param fieldName +-- The name of the field to which to add the value. +-- @param value +-- The value to add. May be a single string value, or an array +-- of values. +-- + + function api.addAllowed(fieldName, value) + local field = premake.fields[fieldName] + if not field then + error("No such field: " .. fieldName, 2) + end + + if not field.allowed then + field.allowed = {} + end + + if type(value) == "table" then + field.allowed = table.join(field.allowed, value) + else + table.insert(field.allowed, value) + end + + table.sort(field.allowed) + end + + -- -- Find the right target object for a given scope. --