Jason McKesson avatar Jason McKesson committed de893e3

Front-end to code generator works. We process all the options we need.

Comments (0)

Files changed (2)

_CmdLineOptions.lua

 		optional = optional,
 		 --self is the destination table, where the data goes
 		proc = function(self, param, iter)
-			assert(param, "This option needs a parameter")
+			assert(param, "This option needs a single parameter")
 			assert(not self[tblName], "Cannot specify the option twice")
 			self[tblName] = param
 			return 1
 	}
 end
 
+--Stores its data in an array, but it only takes one parameter.
+function group:array_single(optName, tblName, desc, modifier, optional)
+	table.insert(self._doc_order, optName)
+	self._procs[optName] = {
+		desc = desc,
+		tableName = tblName,
+		optional = optional,
+		proc = function(self, param, iter)
+			assert(param, "This option needs a single parameter")
+			self[tblName] = self[tblName] or {}
+
+			if(modifier) then
+				param = modifier(param)
+			end
+			table.insert(self[tblName], param)
+			return 1
+		end,
+		
+		document = function(self)
+			local docs = ExtractDescArray(self.desc)
+			docs[#docs + 1] = "Can be used multiple times."
+			return docs
+		end,
+	}
+end
+
 function group:pos_opt(index, tblName, desc, optName, default, optional)
 	assert(not self._pos_opts[index],
 		"Positional argument " .. index .. " is already in use")
 	return optGroup
 end
 
-
-
-
-
-
 return modTbl
 -		core:
 -		compatibility:
 - extensions: A list of OpenGL extensions to export.
-- extfiles: A list of files to load extensions from.
 - outname: The base filename of the file to create.
 - style: A string containing the particular style of binding. This can be:
 -		pointer_c: The default. The functions will be stored in pointers exposed to the user. #defines will be used to rename the pointers to the core GL function names.
 	{"A list of extensions to export."},
 	FixupExtensionName,
 	true)
-parseOpts:array(
+parseOpts:array_single(
+	"ext",
+	"extensions",
+	{"A single extension name to export."},
+	FixupExtensionName,
+	true)
+parseOpts:array_single(
+	"extfile",
 	"extfiles",
-	"extfiles",
-	{"A list of files to load extensions from."},
+	{"A file to load extensions from."},
 	nil,
 	true)
 parseOpts:value(
 	1,
 	"outname",
 	"Base filename (sans extension",
-	"outname",
-	nil,
-	true)
+	"outname")
 	
-function GetOptions(cmd_line)
+local function LoadExtFile(extensions, extfilename)
+	hFile = assert(io.open(extfilename, "rt"), "Could not find the file " .. extfilename)
+	
+	for line in hFile:lines() do
+		local ext = line:match("(%S+)")
+		if(ext) then
+			table.insert(extensions, ext)
+		end
+	end
+	
+	hFile:close()
+end
+
+local function FixupExtname(ext)
+	--Cull the (W)GL(X)_ part of the name, if any.
+	
+	local bareName = ext:match("W?GLX?_(.+)")
+	
+	return bareName or ext
+end
+
+local optTbl = {}
+
+function optTbl.GetOptions(cmd_line)
 	local options, pos_args = parseOpts:ProcessCmdLine(cmd_line)
 	
 	if(options.spec == "gl") then
 		parseOpts:AssertParse(not options.version, "Versions cannot be specified for wgl/glX")
 		parseOpts:AssertParse(not options.profile, "Profiles cannot be specified for wgl/glX")
 	end
+	
+	options.extensions = options.extensions or {}
+	options.extfiles = options.extfiles or {}
+	
+	for _, file in ipairs(options.extfiles) do
+		LoadExtFile(options.extensions, file)
+	end
+	
+	--Fixup names and remove duplicates.
+	local dups = {}
+	local exts = {}
+	for _, ext in ipairs(options.extensions) do
+		local fixExt = FixupExtname(ext)
+		if(not dups[fixExt]) then
+			exts[#exts + 1] = fixExt
+			dups[fixExt] = true
+		end
+	end
+	
+	options.extensions = exts
+	options.extfiles = nil
 
 	return options
+end
 
---[[
-	local options = {}
-	
-	local status, posOpts = 
-		pcall(cmd.CmdLineOptions, cmd_line, procs, options)
-		
-	AssertParse(status, posOpts)
-
-	AssertParse(posOpts[1], "You did not specify an output filename.")
-	
-	options.spec = options.spec or "gl"
-	options.func_style = options.func_style or "pointer"
-	options.language = options.language or "c"
-	
-	
-	return options
-	]]
-end
+return optTbl
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.