Local rules; include() and replace().
This commit is contained in:
		
							parent
							
								
									d805052205
								
							
						
					
					
						commit
						7f7005bac5
					
				
					 1 changed files with 17 additions and 2 deletions
				
			
		|  | @ -144,6 +144,14 @@ local function dirname(collection) | ||||||
| 	) | 	) | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
|  | local function replace(collection, pattern, repl) | ||||||
|  | 	return dotocollection(collection, | ||||||
|  | 		function(filename) | ||||||
|  | 			return filename:gsub(pattern, repl) | ||||||
|  | 		end | ||||||
|  | 	) | ||||||
|  | end | ||||||
|  | 
 | ||||||
| local function fpairs(collection) | local function fpairs(collection) | ||||||
| 	if (type(collection) == "string") or collection.is then | 	if (type(collection) == "string") or collection.is then | ||||||
| 		return fpairs({collection}) | 		return fpairs({collection}) | ||||||
|  | @ -345,7 +353,7 @@ local typeconverters = { | ||||||
| } | } | ||||||
| 	 | 	 | ||||||
| local function definerule(rulename, types, cb) | local function definerule(rulename, types, cb) | ||||||
| 	if rules[rulename] then | 	if rulename and rules[rulename] then | ||||||
| 		error(string.format("rule '%s' is already defined", rulename)) | 		error(string.format("rule '%s' is already defined", rulename)) | ||||||
| 	end | 	end | ||||||
| 
 | 
 | ||||||
|  | @ -358,7 +366,7 @@ local function definerule(rulename, types, cb) | ||||||
| 		end | 		end | ||||||
| 	end | 	end | ||||||
| 
 | 
 | ||||||
| 	rules[rulename] = function(e) | 	local rule = function(e) | ||||||
| 		local args = {} | 		local args = {} | ||||||
| 		for propname, typespec in pairs(types) do | 		for propname, typespec in pairs(types) do | ||||||
| 			if not e[propname] then | 			if not e[propname] then | ||||||
|  | @ -388,6 +396,11 @@ local function definerule(rulename, types, cb) | ||||||
| 		targets[result.fullname] = result | 		targets[result.fullname] = result | ||||||
| 		return result | 		return result | ||||||
| 	end | 	end | ||||||
|  | 
 | ||||||
|  | 	if rulename then	 | ||||||
|  | 		rules[rulename] = rule | ||||||
|  | 	end | ||||||
|  | 	return rule | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ||||||
|  | @ -595,7 +608,9 @@ globals = { | ||||||
| 	emit = emit, | 	emit = emit, | ||||||
| 	environment = environment, | 	environment = environment, | ||||||
| 	filenamesof = filenamesof, | 	filenamesof = filenamesof, | ||||||
|  | 	include = loadbuildfile, | ||||||
| 	inherit = inherit, | 	inherit = inherit, | ||||||
|  | 	replace = replace, | ||||||
| 	selectof = selectof, | 	selectof = selectof, | ||||||
| 	startswith = startswith, | 	startswith = startswith, | ||||||
| 	fpairs = fpairs, | 	fpairs = fpairs, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue