Commits

Jason McKesson committed 35a13a4

Started to move modules to the `modules` directory.
Keeps the root clean.

  • Participants
  • Parent commits ec5a2ef

Comments (0)

Files changed (8)

 --[[Useful style utility functions. This file will contain commonly useful strings and functions that generate useful data.]]
 
 local TabbedFile = require "_TabbedFile"
-require "_util"
+local util = require "util"
 
 local common = {}
 
 end
 
 function common.GetStdTypedefs()
-	return dofile(GetDataFilePath() .. "style_commontypedefs.lua")
+	return dofile(util.GetDataFilePath() .. "style_commontypedefs.lua")
 end
 
 function common.WritePassthruData(hFile, strArray)
+assert(arg and arg[0], "You ran this script incorrectly.")
+
+--Get the location of our modules relative to here.
+local baseDir = arg[0]:match("^(.*[\\/])")
+baseDir = baseDir or "./"
+assert(baseDir, arg[0] .. " No directory")
+
+--Fixup the package path to be relative to this directory.
+package.path = baseDir .. "modules/?.lua;" .. package.path
+
+--Make a function to get the correct directory name.
+function FixupPath(relativePath)
+	return baseDir .. relativePath
+end
 
 local Specs = require "_Specs"
 local Styles = require "_Styles"
-require "_LoadLuaSpec"
-require "_util"
+local LoadSpec = require "LoadLuaSpec"
+local util = require "util"
 
 local function WriteEnumsFromList(hFile, enumList, enumSeen, listName,
 	options, spec, style, specData)
 		hdrFilename)
 end
 
-local function LoadSpec(options)
-	local specfile =
-	{
-		gl = "glspec.lua",
-		glX = "glxspec.lua",
-		wgl = "wglspec.lua",
-	}
-	
-	local specFileLoc = GetSpecFilePath();
-	return LoadLuaSpec(specFileLoc .. specfile[options.spec])
-end
-
-
-
 return
 {
 	Generate = Generate,
-	LoadSpec = LoadSpec,
 }

_LoadLuaSpec.lua

---[[
-The function, LoadLuaSpec exposed here will load a spec.lua file. It takes a filename
-pointing to a spec.lua file.
-
-This function will also add some features to the object before returning it.
-
-The format will be as defined in ConvertAllSpecFilesToLua, except for the following:
-
-- extdefs: This is a table of extensions, indexed by extension name.
-	Each entry contains:
--- enums: An array of enumerators. These enumerators are the entries in the main enum array.
--- funcs: An array of functions. These functions are the entries in the main funcData array.
-- coredefs: This is a table of core versions, indexed by version name string
-	"1.1" is the first.
--- enums: An array of enumerators. These enumerators are the entries in the main enum array.
--- funcs: An array of functions. These functions are the entries in the main funcData array.
-- enumtable: A table of enumerators, indexed by their names.
-- coreexts: A table of core extensions, indexed by extension name. The value of these entries are:
--- name: The core extension's name.
--- version: the version that extension became core in. The version is a string.
-
-
-All enumerators and functions are found in one of these two lists. Some of them are in both.
-
-Other changes are:
-- All functions that would have the 1.0 version have it changed to 1.1. This makes the data match the enums.
-- The "void" type in the typemap maps to "void".
-- Fixes for certain extensions. Certain extensions are non-core, but the enums and functions
-	have no suffixes as if they were core.
-]]
-
-local listOfCoreVersions = dofile("data/listOfCoreVersions.lua");
-
-local listOfNonCoreFixes = 
-{
---	"ARB_sample_shading",
---	"ARB_draw_buffers_blend",
---	"ARB_texture_cube_map_array",
-};
-
-local listOfExtensionsToRemove =
-{
-    "SGIX_video_source",
-    "SGIX_dmbuffer",
-    "SGIX_hyperpipe",
-};
-
-function LoadLuaSpec(luaFilename)
-	local specData = dofile(luaFilename);
-
-	specData.extdefs = {};
-	specData.coredefs = {};
-	specData.enumtable = {};
-	local extdefs = specData.extdefs;
-	local coredefs = specData.coredefs;
-	local enumtable = specData.enumtable;
-	
-	--HACK! Change 1.0 version in functions to 1.1, to match enums.
-	for i, func in ipairs(specData.funcData.functions) do
-		if(func.version == "1.0") then func.version = "1.1"; end;
-	end
-	
-	--HACK! Change "void" in the typemap to map to "void".
-	specData.typemap.void = "void";
-	
-	--HACK! Add suffixes to functions and enums for these extensions.
-	for i, extName in ipairs(listOfNonCoreFixes) do
-		for j, func in ipairs(specData.funcData.functions) do
-			if(func.category == extName) then
-				func.name = func.name .. "ARB";
-			end
-		end
-		for j, enum in ipairs(specData.enumerations) do
-			if(enum.extensions) then
-				for k, enumExt in ipairs(enum.extensions) do
-					if(enumExt == extName) then
-						enum.name = enum.name .. "_ARB";
-					end
-				end
-			end
-		end
-	end
-	
-	--HACK! Remove certain offensive extensions.
-	local toRemove = {}
-	for i, ext in ipairs(specData.extensions) do
-	    for j, test in ipairs(listOfExtensionsToRemove) do
-	        if(ext == test) then
-	            table.insert(toRemove, 1, i);
-	            break;
-	        end
-	    end
-	end
-	
-	for i, index in ipairs(toRemove) do
-	    table.remove(specData.extensions, index);
-	end
-	
-	toRemove = {}
-	for i, enum in ipairs(specData.enumerations) do
-		if(enum.extensions) then
-		    for j, enumExt in ipairs(enum.extensions) do
-		        local bBreak = false;
-	            for k, test in ipairs(listOfExtensionsToRemove) do
-	                if(enumExt == test) then
-	                    table.insert(toRemove, 1, i);
-	                    bBreak = true;
-	                    break;
-	                end
-	            end
-	            if(bBreak) then break; end
-		    end
-		end
-	end
-	
-	for i, index in ipairs(toRemove) do
-	    table.remove(specData.enumerations, index);
-	end
-	
-	toRemove = {}
-    for i, func in ipairs(specData.funcData.functions) do
-	    for j, test in ipairs(listOfExtensionsToRemove) do
-	        if(ext == func.category) then
-	            table.insert(toRemove, 1, i);
-	            break;
-	        end
-	    end
-    end
-
-	for i, index in ipairs(toRemove) do
-	    table.remove(specData.funcData.functions, index);
-	end
-	
-	
-	
-	
-	local function GetCore(version)
-		if(not coredefs[version]) then
-			local coredef = {};
-			coredefs[version] = coredef;
-			coredef.enums = {};
-			coredef.funcs = {};
-		end
-		
-		return coredefs[version];
-	end
-	
-	local function GetExt(extName)
-		if(not extdefs[extName]) then
-			local extdef = {};
-			extdefs[extName] = extdef;
-			extdef.enums = {};
-			extdef.funcs = {};
-		end
-		
-		return extdefs[extName];
-	end
-
-	--Add all extensions to the extdefs.
-	for	i, extName in ipairs(specData.extensions) do
-		GetExt(extName);
-	end
-	
-	for i, enum in ipairs(specData.enumerations) do
-		enumtable[enum.name] = enum;
-		
-		if(enum.extensions) then
-			for k, extName in ipairs(enum.extensions) do
-				table.insert(GetExt(extName).enums, enum);
-			end
-		end
-		
-		if(enum.version) then
-			table.insert(GetCore(enum.version).enums, enum);
-		end
-	end
-
-	for i, func in ipairs(specData.funcData.functions) do
-		--This is here to make sure that the category is an actual extension,
-		--not a verison number.
-		if(extdefs[func.category]) then
-			table.insert(GetExt(func.category).funcs, func);
-		end
-	
-		if(func.version) then
-			if(not func.category or string.match(func.category, "^VERSION")) then
-				local versionVal = string.gsub(func.category, "VERSION_(%d+)_(%d+).*", "%1%.%2");
-				--HACK!
-				if(versionVal == "1.0") then versionVal = "1.1" end;
-				table.insert(GetCore(versionVal).funcs, func);
-			end
-		end
-	end
-	
-	specData.coreexts = dofile(GetDataFilePath() .. "coreExtList.lua");
-
-	return specData;
-end
-
 - DeclPrefix: nullary function that returns the name of a prefix string for declarations.
 ]]
 
-require "_util"
+local util = require "util"
+local LoadSpec = require "LoadLuaSpec"
+
 
 local gl_spec = {}
 local wgl_spec = {}
 -- Spec-specific functions.
 
 
+function gl_spec.LoadSpec() return LoadSpec(util.GetSpecFilePath() .. "glspec.lua") end
+function wgl_spec.LoadSpec() return LoadSpec(util.GetSpecFilePath() .. "wglspec.lua") end
+function glx_spec.LoadSpec() return LoadSpec(util.GetSpecFilePath() .. "glxspec.lua") end
+
 ---FilePrefix
 function gl_spec.FilePrefix() return "gl_" end
 function wgl_spec.FilePrefix() return "wgl_" end
 function glx_spec.FilePrefix() return "glx_" end
 
-local function LoadRun(spec, name)
-	return dofile(GetDataFilePath() .. spec.FilePrefix() .. name .. ".lua")
-end
-
 --Include-guard string.
 function gl_spec.GetIncludeGuardString() return "OPENGL" end
 function wgl_spec.GetIncludeGuardString() return "WINDOWSGL" end

_util.lua

-
---Works like the regular pairs, but returns the key/value pairs in a key-sorted order.
---sortFunc is the function used to compare them.
-function sortPairs(theTable, sortFunc)
-	local keyTable = {};
-	
-	for key, value in pairs(theTable) do
-		table.insert(keyTable, key);
-	end
-	
-	table.sort(keyTable, sortFunc);
-	
-	local currIndex = 1;
-	local lenTable = #keyTable;
-	
-	return function()
-		local currKey = keyTable[currIndex];
-		currIndex = currIndex + 1;
-		return currKey, theTable[currKey];
-	end
-end
-
---Works like ipairs, but returns the list as through it were in a sorted order.
---It even returns the "wrong" indices.
---sortFunc is the function used to compare them.
-function isortPairs(theTable, sortFunc)
-	local tempTable = {};
-	
-	for i, value in ipairs(theTable) do
-		table.insert(tempTable, value);
-	end
-	
-	table.sort(tempTable, sortFunc);
-	
-	local currIndex = 1;
-	local lenTable = #tempTable;
-	
-	return function()
-		local tempIndex = currIndex;
-		currIndex = currIndex + 1;
-		return tempIndex, theTable[tempIndex];
-	end
-end
-
---ipairs in reverse order.
-function ripairs(theTable)
-	local currIndex = #theTable;
-
-	return function()
-		local tempIndex = currIndex;
-		currIndex = currIndex - 1;
-		if(currIndex < 0) then return nil, nil; end;
-		return tempIndex, theTable[tempIndex];
-	end
-end
-
---Standard lessthan compare function. For use with the above.
-function CompLess(key1, key2)
-	return key1 < key2;
-end
-
---A combined printf and hFile:write.
-function WriteFormatted(hFile, strFormat, ...)
-	hFile:write(string.format(strFormat, ...));
-end
-
-function WriteForm(hFile, strFormat, ...)
-	hFile:write(string.format(strFormat, ...));
-end
-
-function GetIncludePath()
-	return "../include/glload/";
-end
-
-function GetSourcePath()
-	return "../source/";
-end
-
-function GetSpecFilePath()
-	return "glspecs/";
-end
-
-function GetDataFilePath()
-	return "data/";
-end
-
---This returns the starting part of a header's includeguard. Takes the name of the define.
-function GetFileIncludeGuardStart(defineName)
-	return string.format([[
-#ifndef %s
-#define %s
-
-]], defineName, defineName);
-end
-
---This returns the ending part of a header's includeguard. Takes the name of the define.
-function GetFileIncludeGuardEnd(defineName)
-	return string.format([[
-#endif //%s
-
-]], defineName);
-end
-
---Retrieves the beginning of the extern C block
-function GetExternCStart()
-	return [[
-#ifdef __cplusplus
-extern "C" {
-#endif //__cplusplus
-
-]]
-end
-
---Retrieves the end of the extern C block.
-function GetExternCEnd()
-	return [[
-#ifdef __cplusplus
-}
-#endif //__cplusplus
-
-]]
-end
-
---Retrieves a string for a C-style heading. Takes the name of the heading.
-function GetSectionHeading(headingName)
-	return string.format(
-[[/******************************
-* %s
-******************************/
-]], headingName);
-end
-

modules/LoadLuaSpec.lua

+--[[
+The function, LoadLuaSpec exposed here will load a spec.lua file. It takes a filename
+pointing to a spec.lua file.
+
+This function will also add some features to the object before returning it.
+
+The format will be as defined in ConvertAllSpecFilesToLua, except for the following:
+
+- extdefs: This is a table of extensions, indexed by extension name.
+	Each entry contains:
+-- enums: An array of enumerators. These enumerators are the entries in the main enum array.
+-- funcs: An array of functions. These functions are the entries in the main funcData array.
+- coredefs: This is a table of core versions, indexed by version name string
+	"1.1" is the first.
+-- enums: An array of enumerators. These enumerators are the entries in the main enum array.
+-- funcs: An array of functions. These functions are the entries in the main funcData array.
+- enumtable: A table of enumerators, indexed by their names.
+- coreexts: A table of core extensions, indexed by extension name. The value of these entries are:
+-- name: The core extension's name.
+-- version: the version that extension became core in. The version is a string.
+
+
+All enumerators and functions are found in one of these two lists. Some of them are in both.
+
+Other changes are:
+- All functions that would have the 1.0 version have it changed to 1.1. This makes the data match the enums.
+- The "void" type in the typemap maps to "void".
+- Fixes for certain extensions. Certain extensions are non-core, but the enums and functions
+	have no suffixes as if they were core.
+]]
+
+local util = require "util"
+
+
+local listOfCoreVersions = dofile(util.GetDataFilePath() .. "listOfCoreVersions.lua");
+
+local listOfNonCoreFixes = 
+{
+--	"ARB_sample_shading",
+--	"ARB_draw_buffers_blend",
+--	"ARB_texture_cube_map_array",
+};
+
+local listOfExtensionsToRemove =
+{
+    "SGIX_video_source",
+    "SGIX_dmbuffer",
+    "SGIX_hyperpipe",
+};
+
+local load = {}
+
+function load.LoadLuaSpec(luaFilename)
+	local specData = dofile(luaFilename);
+
+	specData.extdefs = {};
+	specData.coredefs = {};
+	specData.enumtable = {};
+	local extdefs = specData.extdefs;
+	local coredefs = specData.coredefs;
+	local enumtable = specData.enumtable;
+	
+	--HACK! Change 1.0 version in functions to 1.1, to match enums.
+	for i, func in ipairs(specData.funcData.functions) do
+		if(func.version == "1.0") then func.version = "1.1"; end;
+	end
+	
+	--HACK! Change "void" in the typemap to map to "void".
+	specData.typemap.void = "void";
+	
+	--HACK! Add suffixes to functions and enums for these extensions.
+	for i, extName in ipairs(listOfNonCoreFixes) do
+		for j, func in ipairs(specData.funcData.functions) do
+			if(func.category == extName) then
+				func.name = func.name .. "ARB";
+			end
+		end
+		for j, enum in ipairs(specData.enumerations) do
+			if(enum.extensions) then
+				for k, enumExt in ipairs(enum.extensions) do
+					if(enumExt == extName) then
+						enum.name = enum.name .. "_ARB";
+					end
+				end
+			end
+		end
+	end
+	
+	--HACK! Remove certain offensive extensions.
+	local toRemove = {}
+	for i, ext in ipairs(specData.extensions) do
+	    for j, test in ipairs(listOfExtensionsToRemove) do
+	        if(ext == test) then
+	            table.insert(toRemove, 1, i);
+	            break;
+	        end
+	    end
+	end
+	
+	for i, index in ipairs(toRemove) do
+	    table.remove(specData.extensions, index);
+	end
+	
+	toRemove = {}
+	for i, enum in ipairs(specData.enumerations) do
+		if(enum.extensions) then
+		    for j, enumExt in ipairs(enum.extensions) do
+		        local bBreak = false;
+	            for k, test in ipairs(listOfExtensionsToRemove) do
+	                if(enumExt == test) then
+	                    table.insert(toRemove, 1, i);
+	                    bBreak = true;
+	                    break;
+	                end
+	            end
+	            if(bBreak) then break; end
+		    end
+		end
+	end
+	
+	for i, index in ipairs(toRemove) do
+	    table.remove(specData.enumerations, index);
+	end
+	
+	toRemove = {}
+    for i, func in ipairs(specData.funcData.functions) do
+	    for j, test in ipairs(listOfExtensionsToRemove) do
+	        if(ext == func.category) then
+	            table.insert(toRemove, 1, i);
+	            break;
+	        end
+	    end
+    end
+
+	for i, index in ipairs(toRemove) do
+	    table.remove(specData.funcData.functions, index);
+	end
+	
+	
+	
+	
+	local function GetCore(version)
+		if(not coredefs[version]) then
+			local coredef = {};
+			coredefs[version] = coredef;
+			coredef.enums = {};
+			coredef.funcs = {};
+		end
+		
+		return coredefs[version];
+	end
+	
+	local function GetExt(extName)
+		if(not extdefs[extName]) then
+			local extdef = {};
+			extdefs[extName] = extdef;
+			extdef.enums = {};
+			extdef.funcs = {};
+		end
+		
+		return extdefs[extName];
+	end
+
+	--Add all extensions to the extdefs.
+	for	i, extName in ipairs(specData.extensions) do
+		GetExt(extName);
+	end
+	
+	for i, enum in ipairs(specData.enumerations) do
+		enumtable[enum.name] = enum;
+		
+		if(enum.extensions) then
+			for k, extName in ipairs(enum.extensions) do
+				table.insert(GetExt(extName).enums, enum);
+			end
+		end
+		
+		if(enum.version) then
+			table.insert(GetCore(enum.version).enums, enum);
+		end
+	end
+
+	for i, func in ipairs(specData.funcData.functions) do
+		--This is here to make sure that the category is an actual extension,
+		--not a verison number.
+		if(extdefs[func.category]) then
+			table.insert(GetExt(func.category).funcs, func);
+		end
+	
+		if(func.version) then
+			if(not func.category or string.match(func.category, "^VERSION")) then
+				local versionVal = string.gsub(func.category, "VERSION_(%d+)_(%d+).*", "%1%.%2");
+				--HACK!
+				if(versionVal == "1.0") then versionVal = "1.1" end;
+				table.insert(GetCore(versionVal).funcs, func);
+			end
+		end
+	end
+	
+	specData.coreexts = dofile(util.GetDataFilePath() .. "coreExtList.lua");
+
+	return specData;
+end
+
+return load
+
+
+local util = {}
+
+function util.GetSpecFilePath()
+	return FixupPath("glspecs/");
+end
+
+function util.GetDataFilePath()
+	return FixupPath("data/");
+end
+
+
+--Works like the regular pairs, but returns the key/value pairs in a key-sorted order.
+--sortFunc is the function used to compare them.
+function sortPairs(theTable, sortFunc)
+	local keyTable = {};
+	
+	for key, value in pairs(theTable) do
+		table.insert(keyTable, key);
+	end
+	
+	table.sort(keyTable, sortFunc);
+	
+	local currIndex = 1;
+	local lenTable = #keyTable;
+	
+	return function()
+		local currKey = keyTable[currIndex];
+		currIndex = currIndex + 1;
+		return currKey, theTable[currKey];
+	end
+end
+
+--Works like ipairs, but returns the list as through it were in a sorted order.
+--It even returns the "wrong" indices.
+--sortFunc is the function used to compare them.
+function isortPairs(theTable, sortFunc)
+	local tempTable = {};
+	
+	for i, value in ipairs(theTable) do
+		table.insert(tempTable, value);
+	end
+	
+	table.sort(tempTable, sortFunc);
+	
+	local currIndex = 1;
+	local lenTable = #tempTable;
+	
+	return function()
+		local tempIndex = currIndex;
+		currIndex = currIndex + 1;
+		return tempIndex, theTable[tempIndex];
+	end
+end
+
+--ipairs in reverse order.
+function ripairs(theTable)
+	local currIndex = #theTable;
+
+	return function()
+		local tempIndex = currIndex;
+		currIndex = currIndex - 1;
+		if(currIndex < 0) then return nil, nil; end;
+		return tempIndex, theTable[tempIndex];
+	end
+end
+
+--Standard lessthan compare function. For use with the above.
+function CompLess(key1, key2)
+	return key1 < key2;
+end
+
+--A combined printf and hFile:write.
+function WriteFormatted(hFile, strFormat, ...)
+	hFile:write(string.format(strFormat, ...));
+end
+
+function WriteForm(hFile, strFormat, ...)
+	hFile:write(string.format(strFormat, ...));
+end
+
+function GetIncludePath()
+	return "../include/glload/";
+end
+
+function GetSourcePath()
+	return "../source/";
+end
+
+--This returns the starting part of a header's includeguard. Takes the name of the define.
+function GetFileIncludeGuardStart(defineName)
+	return string.format([[
+#ifndef %s
+#define %s
+
+]], defineName, defineName);
+end
+
+--This returns the ending part of a header's includeguard. Takes the name of the define.
+function GetFileIncludeGuardEnd(defineName)
+	return string.format([[
+#endif //%s
+
+]], defineName);
+end
+
+--Retrieves the beginning of the extern C block
+function GetExternCStart()
+	return [[
+#ifdef __cplusplus
+extern "C" {
+#endif //__cplusplus
+
+]]
+end
+
+--Retrieves the end of the extern C block.
+function GetExternCEnd()
+	return [[
+#ifdef __cplusplus
+}
+#endif //__cplusplus
+
+]]
+end
+
+--Retrieves a string for a C-style heading. Takes the name of the heading.
+function GetSectionHeading(headingName)
+	return string.format(
+[[/******************************
+* %s
+******************************/
+]], headingName);
+end
+