Fixes to support a wider range of field kinds

- Rename api.checkvalue() to api.checkValue() and swap argument order for consistency
- Add kind argument to api.checkValue() to identify which segment is being tested
- Limit wildcard test in remove() to string values
- Return error message from field.new() instead of raising error internally
This commit is contained in:
Jason Perkins 2014-07-14 12:00:30 -04:00
parent 7158f623b9
commit 5614bfcd17
5 changed files with 26 additions and 16 deletions

View File

@ -291,8 +291,8 @@
--
function vstudio.archFromPlatform(platform)
local system = premake.api.checkvalue(platform, premake.fields.system)
local arch = premake.api.checkvalue(platform, premake.fields.architecture)
local system = premake.api.checkValue(premake.fields.system, platform)
local arch = premake.api.checkValue(premake.fields.architecture, platform)
return architecture(system, arch)
end

View File

@ -91,7 +91,11 @@
end
-- add this new field to my master list
field = premake.field.new(field)
field, err = premake.field.new(field)
if not field then
error(err)
end
-- Flag fields which contain filesystem paths. The context object will
-- use this information when expanding tokens, to ensure that the paths
@ -357,7 +361,7 @@
table.insert(removes, value)
else
local value, err, additional = api.checkvalue(value, field)
local value, err, additional = api.checkValue(field, value)
if err then
error { msg=err }
end
@ -382,17 +386,21 @@
--
-- Check to see if a value is valid for a particular field.
--
-- @param value
-- The value to check.
-- @param field
-- The field to check against.
-- @param value
-- The value to check.
-- @param kind
-- The kind of data currently being checked, corresponding to
-- one segment of the field's kind string (e.g. "string"). If
-- not set, defaults to "string".
-- @return
-- If the value is valid for this field, the canonical version
-- of that value is returned. If the value is not valid two
-- values are returned: nil, and an error message.
--
function api.checkvalue(value, field)
function api.checkValue(field, value, kind)
if not field.allowed then
return value
end
@ -406,7 +414,7 @@
if not canonical then
if type(field.allowed) == "function" then
canonical = field.allowed(value)
canonical = field.allowed(value, kind or "string")
else
canonical = field.allowed[lowerValue]
end
@ -754,7 +762,7 @@
if value ~= nil then
local err
value, err = api.checkvalue(value, field)
value, err = api.checkValue(field, value)
if err then
error { msg=err }
end

View File

@ -332,7 +332,9 @@
values = premake.field.remove(field, {}, values)
for i, value in ipairs(values) do
values[i] = path.wildcards(value):lower()
if type(value) == "string" then
values[i] = path.wildcards(value):lower()
end
end
-- add a list of removed values to the block

View File

@ -83,7 +83,7 @@
-- All fields must have a valid store() function
if not field.accessor(f, "store") then
error("invalid field kind '" .. f._kind .. "'")
return nil, "invalid field kind '" .. f._kind .. "'"
end
field._list[f.name] = f
@ -186,8 +186,8 @@
end
-- Split off the first piece from the rest of the kind. If the
-- incoming kind is "list:key:string", thisKind will "list" and
-- nextKind will be "key:string".
-- incoming kind is "list:key:string", thisKind will be "list"
-- and nextKind will be "key:string".
local thisKind = kind:match('(.-):') or kind
local nextKind = kind:sub(#thisKind + 2)
@ -197,7 +197,7 @@
local functions = field._kinds[thisKind]
if not functions then
error("Invalid field kind '" .. thisKind .. "'")
return nil, "Invalid field kind '" .. thisKind .. "'"
end
local processor = functions[method]

View File

@ -441,8 +441,8 @@
local architecture = nil
if platform then
system = premake.api.checkvalue(platform, premake.fields.system) or system
architecture = premake.api.checkvalue(platform, premake.fields.architecture) or architecture
system = premake.api.checkValue(premake.fields.system, platform) or system
architecture = premake.api.checkValue(premake.fields.architecture, platform) or architecture
end
-- Wrap the projects's configuration set (which contains all of the information