GL XML Specs / _util.lua

Jason McKesson f6db273 






































































Jason McKesson 797e0c3 
Jason McKesson f6db273 


Jason McKesson 797e0c3 
Jason McKesson f6db273 


Jason McKesson 797e0c3 
Jason McKesson f6db273 


Jason McKesson 797e0c3 
Jason McKesson f6db273 














































--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
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.