Merge pull request #146 from starkos/solution-hasproject
Add new convenience function solution.hasProject()
This commit is contained in:
commit
52eeed6a0b
@ -202,6 +202,32 @@
|
||||
|
||||
|
||||
|
||||
---
|
||||
-- Return true if a container class is or inherits from the
|
||||
-- specified class.
|
||||
--
|
||||
-- @param class
|
||||
-- The container class to be tested.
|
||||
-- @param scope
|
||||
-- The name of the class to be checked against. If the container
|
||||
-- class matches this scope (i.e. class is a project and the
|
||||
-- scope is "project"), or if it is a parent object of it (i.e.
|
||||
-- class is a solution and scope is "project"), then returns
|
||||
-- true.
|
||||
---
|
||||
|
||||
function container.classIsA(class, scope)
|
||||
while class do
|
||||
if class.name == scope then
|
||||
return true
|
||||
end
|
||||
class = class.parent
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
|
||||
---
|
||||
-- Enumerate all of the registered child classes of a specific container class.
|
||||
--
|
||||
@ -284,27 +310,26 @@
|
||||
|
||||
|
||||
---
|
||||
-- Return true if a container class is or inherits from the
|
||||
-- specified class.
|
||||
-- Determine if the container contains a child of the specified class which
|
||||
-- meets the criteria of a testing function.
|
||||
--
|
||||
-- @param self
|
||||
-- The container to be queried.
|
||||
-- @param class
|
||||
-- The container class to be tested.
|
||||
-- @param scope
|
||||
-- The name of the class to be checked against. If the container
|
||||
-- class matches this scope (i.e. class is a project and the
|
||||
-- scope is "project"), or if it is a parent object of it (i.e.
|
||||
-- class is a solution and scope is "project"), then returns
|
||||
-- true.
|
||||
-- The class of the child containers to be enumerated.
|
||||
-- @param func
|
||||
-- A function that takes a child container as its only argument, and
|
||||
-- returns true if it meets the selection criteria for the call.
|
||||
-- @return
|
||||
-- True if the test function returns true for any child.
|
||||
---
|
||||
|
||||
function container.classIsA(class, scope)
|
||||
while class do
|
||||
if class.name == scope then
|
||||
function container.hasChild(self, class, func)
|
||||
for child in container.eachChild(self, class) do
|
||||
if func(child) then
|
||||
return true
|
||||
end
|
||||
class = class.parent
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
---
|
||||
-- solution.lua
|
||||
-- Work with the list of solutions loaded from the script.
|
||||
-- Copyright (c) 2002-2014 Jason Perkins and the Premake project
|
||||
-- Copyright (c) 2002-2015 Jason Perkins and the Premake project
|
||||
---
|
||||
|
||||
local p = premake
|
||||
@ -140,3 +140,21 @@
|
||||
sln = premake.oven.bakeSolution(sln)
|
||||
return sln.projects[idx]
|
||||
end
|
||||
|
||||
|
||||
|
||||
---
|
||||
-- Determines if the solution contains a project that meets certain criteria.
|
||||
--
|
||||
-- @param self
|
||||
-- The solution.
|
||||
-- @param func
|
||||
-- A test function. Receives a project as its only argument and returns a
|
||||
-- boolean indicating whether it meets to matching criteria.
|
||||
-- @return
|
||||
-- True if the test function returned true.
|
||||
---
|
||||
|
||||
function solution.hasProject(self, func)
|
||||
return p.container.hasChild(self, p.project, func)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user