forked from premake/premake-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal.lua
More file actions
113 lines (87 loc) · 2.11 KB
/
global.lua
File metadata and controls
113 lines (87 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
-- global.lua
-- The global container holds workspaces and rules.
-- Copyright (c) 2014-2015 Jason Perkins and the Premake project
---
local p = premake
p.global = p.api.container("global")
local global = p.global
---
-- Create a new global container instance.
---
function global.new(name)
return p.container.new(p.global, name)
end
---
-- Bakes the global scope.
---
function global.bake(self)
p.container.bakeChildren(self)
end
---
-- Iterate over the collection of rules in a session.
--
-- @returns
-- An iterator function.
---
function global.eachRule()
local root = p.api.rootContainer()
return p.container.eachChild(root, p.rule)
end
---
-- Iterate over the collection of workspaces in a session.
--
-- @returns
-- A workspace iterator function.
---
function global.eachWorkspace()
local root = p.api.rootContainer()
return p.container.eachChild(root, p.workspace)
end
p.alias(global, "eachWorkspace", "eachSolution")
---
-- Retrieve a rule by name or index.
--
-- @param key
-- The rule key, either a string name or integer index.
-- @returns
-- The rule with the provided key.
---
function global.getRule(key)
local root = p.api.rootContainer()
return root.rules[key]
end
---
-- Retrieve the rule to applies to the provided file name, if any such
-- rule exists.
--
-- @param fname
-- The name of the file.
-- @param rules
-- A list of rule names to be included in the search. If not specified,
-- all rules will be checked.
-- @returns
-- The rule, is one has been registered, or nil.
---
function global.getRuleForFile(fname, rules)
for rule in global.eachRule() do
if not rules or table.contains(rules, rule.name) then
if path.hasextension(fname, rule.fileextension) then
return rule
end
end
end
end
---
-- Retrieve a workspace by name or index.
--
-- @param key
-- The workspace key, either a string name or integer index.
-- @returns
-- The workspace with the provided key.
---
function global.getWorkspace(key)
local root = p.api.rootContainer()
return root.workspaces[key]
end
p.alias(global, "getWorkspace", "getSolution")