Jason McKesson avatar Jason McKesson committed 075152f

Better style naming scheme.

Comments (0)

Files changed (13)

modules/NoloadCpp_Struct.lua

+
+local struct = require "Structure"
+local common = require "CommonStruct"
+
+
+local sys_functions =
+{ type="block", name="System(hFile, spec, options)",
+	{type="write", name="SetupFunction(hFile, specData, spec, options)", },
+	{type="blank", cond="version-iter" },
+	{type="write", name="VersionFunctions(hFile, specData, spec, options)", cond="version-iter"},
+}
+
+local my_struct =
+{
+	{ type="file", style="hdr", name="GetFilename(basename, spec, options)",
+		{ type="write", name="FilePreamble", optional=true} ,
+		{ type="block", name="IncludeGuard",
+			{ type="blank"},
+			{ type="write", name="Guards(hFile, spec, options)",},
+			{ type="blank"},
+			{ type="write", name="Typedefs(hFile, specData, spec, options)",},
+			{ type="blank"},
+			
+			{ type="block", name="MainNamespace(hFile, spec, options)",
+				{ type="write", name="LargeHeader(hFile, value, options)", value="Extension Variables", },
+				{ type="block", name="ExtVariables(hFile, spec, options)",
+					common.Extensions(),
+				},
+				{ type="blank"},
+				{ type="block", name="Enumerators(hFile, spec, options)",
+					common.Enumerators(),
+				},
+				{ type="blank"},
+				common.Functions(),
+				sys_functions,
+			},
+		},
+	},
+	
+	{ type="file", style="src", name="GetFilename(basename, spec, options)",
+		{ type="write", name="Includes(hFile, basename, spec, options)", },
+		{ type="blank"},
+		{ type="write", name="LoaderFunc(hFile, spec, options)", },
+		{ type="blank"},
+		{ type="block", name="MainNamespace(hFile, spec, options)",
+			{ type="block", name="ExtVariables(hFile, spec, options)",
+				common.Extensions(),
+			},
+			{ type="blank"},
+			{ type="group", style="typedefs",
+				common.Functions(),
+			},
+			{ type="blank"},
+			{ type="group", style="defs",
+				common.Functions(),
+			},
+			{ type="blank"},
+			{ type="group", style="switch",
+				common.Functions(),
+			},
+			{ type="blank"},
+			{ type="block", name="Struct(hFile, spec, options)", style="init",
+				common.Functions(),
+			},
+			{ type="blank"},
+			sys_functions,
+		},
+	},
+}
+
+my_struct = struct.BuildStructure(my_struct)
+return my_struct

modules/NoloadCpp_Style.lua

+local util = require "util"
+local struct = require "NoloadCpp_Struct"
+local common = require "CommonStyle"
+
+--------------------------------------
+-- Common functions.
+local function GetIncludeGuard(spec, options)
+	local temp = 
+		options.prefix .. spec.GetIncludeGuardString() .. "_NOLOAD_STYLE_HPP"
+	return temp:upper()
+end
+
+local function GetFuncPtrName(func, spec, options)
+	return func.name
+end
+
+local function GetFuncPtrTypedefName(func, spec, options)
+	return "PFN" .. GetFuncPtrName(func, spec, options):upper() .. "PROC"
+end
+
+local function WriteFuncPtrTypedefStmt(hFile, func, typemap, spec, options)
+	hFile:fmt("typedef %s (%s *%s)(%s);\n",
+		common.GetFuncReturnType(func, typemap),
+		spec.GetCodegenPtrType(),
+		GetFuncPtrTypedefName(func, spec, options),
+		common.GetFuncParamList(func, typemap))
+end
+
+local function GetFuncPtrDefDirect(func, typemap, spec, options)
+	return string.format("%s (%s *%s)(%s)",
+		common.GetFuncReturnType(func, typemap),
+		spec.GetCodegenPtrType(),
+		GetFuncPtrName(func, spec, options),
+		common.GetFuncParamList(func, typemap, true))
+end
+
+local function GetFuncPtrDefTypedef(func, typemap, spec, options)
+	return string.format("%s %s",
+		GetFuncPtrTypedefName(func, spec, options),
+		GetFuncPtrName(func, spec, options))
+end
+
+--------------------------------------
+-- All style functions.
+local my_style = {}
+
+function my_style.WriteLargeHeader(hFile, value, options)
+	local len = #value
+	hFile:write("///", string.rep("/", len), "///\n")
+	hFile:write("// ", value, "\n")
+end
+
+function my_style.WriteSmallHeader(hFile, value, options)
+	hFile:write("// ", value, "\n")
+end
+
+function my_style.WriteBlockBeginMainNamespace(hFile, spec, options)
+	if(#options.prefix > 0) then
+		common.WriteNamespaceBegin(hFile, options.prefix)
+	end
+	
+	common.WriteNamespaceBegin(hFile, spec.FuncNamePrefix())
+end
+
+function my_style.WriteBlockEndMainNamespace(hFile, spec, options)
+	common.WriteNamespaceEnd(hFile, spec.FuncNamePrefix())
+	
+	if(#options.prefix > 0) then
+		common.WriteNamespaceEnd(hFile, options.prefix)
+	end
+end
+
+function my_style.WriteBlockBeginExtVariables(hFile, spec, options)
+	common.WriteNamespaceBegin(hFile, "exts")
+end
+
+function my_style.WriteBlockEndExtVariables(hFile, spec, options)
+	common.WriteNamespaceEnd(hFile, "exts")
+end
+
+function my_style.WriteBlockBeginSystem(hFile, spec, options)
+	common.WriteNamespaceBegin(hFile, "sys")
+end
+
+function my_style.WriteBlockEndSystem(hFile, spec, options)
+	common.WriteNamespaceEnd(hFile, "sys")
+end
+
+
+---------------------------------------------
+-- Header functions.
+local hdr = {}
+my_style.hdr = hdr
+
+function hdr.GetFilename(basename, spec, options)
+	return basename .. ".hpp"
+end
+
+function hdr.WriteBlockBeginIncludeGuard(hFile, spec, options)
+	local guard = GetIncludeGuard(spec, options)
+	hFile:fmt("#ifndef %s\n", guard)
+	hFile:fmt("#define %s\n", guard)
+end
+
+function hdr.WriteBlockEndIncludeGuard(hFile, spec, options)
+	hFile:fmt("#endif //%s\n", GetIncludeGuard(spec, options))
+end
+
+function hdr.WriteGuards(hFile, spec, options)
+	hFile:rawwrite(spec.GetHeaderInit())
+end
+
+function hdr.WriteTypedefs(hFile, specData, spec, options)
+	local defArray = common.GetStdTypedefs()
+	
+	--Use include-guards for the typedefs, since they're common among
+	--headers in this style.
+	hFile:write("#ifndef GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS\n")
+	hFile:write("#define GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS\n")
+	hFile:write("\n")
+	hFile:inc()
+	
+	for _, def in ipairs(defArray) do
+		hFile:write(def)
+	end
+	
+	hFile:dec()
+	hFile:write("\n")
+	hFile:write("#endif /*GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS*/\n")
+	hFile:write("\n")
+
+	common.WritePassthruData(hFile, specData.funcData.passthru)
+end
+
+function hdr.WriteExtension(hFile, extName, spec, options)
+	hFile:fmt("extern bool var_%s;\n", extName)
+end
+
+function hdr.WriteBlockBeginEnumerators(hFile, spec, options)
+	hFile:writeblock("enum\n{\n")
+	hFile:inc()
+end
+
+function hdr.WriteBlockEndEnumerators(hFile, spec, options)
+	hFile:dec()
+	hFile:write("};\n")
+end
+
+function hdr.WriteEnumerator(hFile, enum, enumTable, spec, options, enumSeen)
+	if(enumSeen[enum.name]) then
+		hFile:fmt("//%s seen in %s\n", enum.name, enumSeen[enum.name])
+	else
+		local name = common.GetCppEnumName(enum)
+		hFile:fmt("%s%s= %s,\n",
+			name,
+			common.GetNameLengthPadding(name, 33),
+			common.ResolveEnumValue(enum, enumTable))
+	end
+end
+
+function hdr.WriteFunction(hFile, func, typemap, spec, options, funcSeen)
+	if(funcSeen[func.name]) then return end
+	
+	hFile:write("extern ", GetFuncPtrDefDirect(func, typemap, spec, options), ";\n")
+end
+
+function hdr.WriteSetupFunction(hFile, specData, spec, options)
+	hFile:fmt("void CheckExtensions(%s);\n", spec.GetLoaderParams())
+end
+
+function hdr.WriteVersionFunctions(hFile, specData, spec, options)
+end
+
+
+----------------------------------------
+-- Source file.
+local src = {}
+my_style.src = src
+
+function src.GetFilename(basename, spec, options)
+	return basename .. ".cpp"
+end
+
+function src.WriteIncludes(hFile, basename, spec, options)
+	hFile:writeblock([[
+#include <algorithm>
+#include <string.h>
+#include <stddef.h>
+]])
+
+	local base = util.ParsePath(hdr.GetFilename(basename, spec, options))
+	hFile:fmt('#include "%s"\n', base)
+
+end
+
+function src.WriteLoaderFunc(hFile, spec, options)
+	hFile:writeblock(spec.GetLoaderFunc())
+end
+
+function src.WriteExtension(hFile, extName, spec, options)
+	hFile:fmt("bool var_%s = false;\n", extName)
+end
+
+function src.WriteSetupFunction(hFile, specData, spec, options)
+	common.WriteNamespaceBegin(hFile, "")
+	
+	hFile:write "void ClearExtensionVariables()\n"
+	hFile:write "{\n"
+	hFile:inc()
+	
+	for _, extName in ipairs(options.extensions) do
+		hFile:fmt("exts::var_%s = false;\n", extName)
+	end
+	
+	hFile:dec()
+	hFile:write "}\n"
+	hFile:write "\n"
+	
+	hFile:writeblock[[
+struct MapEntry
+{
+	const char *extName;
+	bool *extVariable;
+};
+
+struct MapCompare
+{
+	MapCompare(const char *test_) : test(test_) {}
+	bool operator()(const MapEntry &other) { return strcmp(test, other.extName) == 0; }
+	const char *test;
+};
+
+struct ClearEntry
+{
+  void operator()(MapEntry &entry) { *(entry.extVariable) = false;}
+};
+
+]]
+	local arrayLength = #options.extensions
+	if(arrayLength == 0) then arrayLength = 1 end
+
+	hFile:fmt("MapEntry g_mappingTable[%i] =\n", arrayLength)
+	hFile:write "{\n"
+	hFile:inc()
+	for _, extName in ipairs(options.extensions) do
+		hFile:fmt('{"%s%s", &exts::var_%s},\n',
+			spec.ExtNamePrefix(),
+			extName,
+			extName)
+	end
+	hFile:dec()
+	hFile:write "};\n"
+	
+	hFile:write "\n"
+	hFile:fmtblock([[
+void LoadExtByName(const char *extensionName)
+{
+	MapEntry *tableEnd = &g_mappingTable[%i];
+	MapEntry *entry = std::find_if(&g_mappingTable[0], tableEnd, MapCompare(extensionName));
+	
+	if(entry != tableEnd)
+		*(entry->extVariable) = true;
+}
+]], #options.extensions)
+
+	hFile:write "\n"
+	
+	local indexed = spec.GetIndexedExtStringFunc(options);
+	if(indexed) then
+		indexed[1] = specData.functable[indexed[1]]
+		indexed[3] = specData.functable[indexed[3]]
+		for _, enum in ipairs(specData.enumerations) do
+			if(indexed[2] == enum.name) then
+				indexed[2] = enum
+			end
+			if(indexed[4] == enum.name) then
+				indexed[4] = enum
+			end
+		end
+
+		hFile:writeblock([[
+void ProcExtsFromExtList()
+{
+	GLint iLoop;
+	GLint iNumExtensions = 0;
+	]] .. indexed[1].name
+	.. [[(]] .. indexed[2].name
+	.. [[, &iNumExtensions);
+
+	for(iLoop = 0; iLoop < iNumExtensions; iLoop++)
+	{
+		const char *strExtensionName = (const char *)]] ..
+		indexed[3].name ..
+		[[(]] .. indexed[4].name .. [[, iLoop);
+		LoadExtByName(strExtensionName);
+	}
+}
+]])
+	else
+		hFile:writeblock(
+			common.GetProcessExtsFromStringFunc("LoadExtByName(%s)"))
+	end
+
+	common.WriteNamespaceEnd(hFile, "")
+	
+	hFile:fmt("void CheckExtensions(%s)\n", spec.GetLoaderParams())
+	hFile:write "{\n"
+	hFile:inc()
+	hFile:write "ClearExtensionVariables();\n"
+	hFile:fmt("std::for_each(&g_mappingTable[0], &g_mappingTable[%i], ClearEntry());\n", #options.extensions)
+	hFile:write "\n"
+	if(indexed) then
+		hFile:write("ProcExtsFromExtList();\n")
+	else
+		--First, check if the GetExtStringFuncName is in the specData.
+		local funcName = spec.GetExtStringFuncName()
+		if(specData.functable[funcName]) then
+			--Create a function pointer and load it.
+			local func = specData.functable[funcName]
+			local typemap = specData.typemap
+			funcName = "InternalGetExtensionString"
+
+			hFile:fmt("typedef %s (%s *MYGETEXTSTRINGPROC)(%s);\n",
+				common.GetFuncReturnType(func, typemap),
+				spec.GetCodegenPtrType(),
+				common.GetFuncParamList(func, typemap))
+			hFile:fmt('MYGETEXTSTRINGPROC %s = (MYGETEXTSTRINGPROC)%s("%s%s");\n',
+				funcName,
+				spec.GetPtrLoaderFuncName(),
+				spec.FuncNamePrefix(),
+				func.name)
+			hFile:fmt("if(!%s) return;\n", funcName)
+			hFile:write "\n"
+		end
+		
+		hFile:fmt("ProcExtsFromExtString((const char *)%s(%s));\n",
+			funcName,
+			spec.GetExtStringParamList(
+				function (name) return spec.FuncNamePrefix() .. "::" .. name end))
+	end
+	hFile:dec()
+	hFile:write "}\n"
+end
+
+function src.WriteVersionFunctions(hFile, specData, spec, options)
+end
+
+local typedefs = {}
+src.typedefs = typedefs
+
+function typedefs.WriteFunction(hFile, func, typemap, spec, options, funcSeen)
+	WriteFuncPtrTypedefStmt(hFile, func, typemap, spec, options)
+end
+
+local defs = {}
+src.defs = defs
+
+function defs.WriteFunction(hFile, func, typemap, spec, options, funcSeen)
+	hFile:write(GetFuncPtrDefTypedef(func, typemap, spec, options), ";\n")
+end
+
+local switch = {}
+src.switch = switch
+
+function switch.WriteFunction(hFile, func, typemap, spec, options, funcSeen)
+	hFile:fmt("static %s %s Switch_%s(%s)\n",
+		common.GetFuncReturnType(func, typemap),
+		spec.GetCodegenPtrType(),
+		func.name,
+		common.GetFuncParamList(func, typemap, true))
+	hFile:write "{\n"
+	hFile:inc()
+	hFile:fmt('%s = (%s)%s("%s%s");\n',
+		GetFuncPtrName(func, spec, options),
+		GetFuncPtrTypedefName(func, spec, options),
+		spec.GetPtrLoaderFuncName(),
+		spec.FuncNamePrefix(),
+		func.name)
+		
+	if(common.DoesFuncReturnSomething(func, typemap)) then
+		hFile:fmt('%s(%s);\n',
+			GetFuncPtrName(func, spec, options),
+			common.GetFuncParamCallList(func, typemap))
+	else
+		hFile:fmt('return %s(%s);\n',
+			GetFuncPtrName(func, spec, options),
+			common.GetFuncParamCallList(func, typemap))
+	end
+	hFile:dec()
+	hFile:write "}\n\n"
+end
+
+function switch.WriteGetExtString(hFile, specData, spec, options, funcSeen)
+	if(funcSeen[spec.GetExtStringFuncName()]) then
+		return
+	end
+
+	local func = specData.funcdefs[spec.GetExtStringFuncName()]
+	if(func) then
+		hFile:write "\n"
+		hFile:fmt("static %s %s(%s)\n",
+			common.GetFuncReturnType(func, typemap),
+			func.name,
+			common.GetFuncParamList(func, specData.funcData.typemap, true))
+		hFile:write "{\n"
+		hFile:inc()
+		hFile:fmt('%s = (%s)%s("%s%s");\n',
+			GetFuncPtrName(func, spec, options),
+			GetFuncPtrTypedefName(func, spec, options),
+			spec.GetPtrLoaderFuncName(),
+			spec.FuncNamePrefix(),
+			func.name)
+			
+		if(common.DoesFuncReturnSomething(func, typemap)) then
+			hFile:fmt('%s(%s);\n',
+				GetFuncPtrName(func, spec, options),
+				common.GetFuncParamCallList(func, typemap))
+		else
+			hFile:fmt('return %s(%s);\n',
+				GetFuncPtrName(func, spec, options),
+				common.GetFuncParamCallList(func, typemap))
+		end
+		hFile:dec()
+		hFile:write "}\n\n"
+	end
+end
+
+local init = {}
+src.init = init
+
+function init.WriteBlockBeginStruct(hFile, spec, options)
+	common.WriteNamespaceBegin(hFile, "")
+	hFile:write("struct InitializeVariables\n")
+	hFile:write "{\n"
+	hFile:inc()
+
+	hFile:write("InitializeVariables()\n")
+	hFile:write "{\n"
+	hFile:inc()
+end
+
+function init.WriteBlockEndStruct(hFile, spec, options)
+	hFile:dec()
+	hFile:write "}\n"
+	hFile:dec()
+	hFile:write "};\n\n"
+	hFile:write("InitializeVariables g_initVariables;\n")
+	common.WriteNamespaceEnd(hFile, "")
+end
+
+function init.WriteFunction(hFile, func, typemap, spec, options, funcSeen)
+	hFile:fmt("%s = Switch_%s;\n", func.name, func.name)
+end
+
+
+local function Create()
+	return util.DeepCopyTable(my_style), struct
+end
+
+return { Create = Create }
+

modules/PointerCPP_Style.lua

+
+local common = require "CommonStyle"
+local util = require "util"
+
+local my_style = {}
+my_style.header = {}
+my_style.source = {}
+
+----------------------------------------------------
+-- Global styling functions.
+function my_style.WriteLargeHeading(hFile, headingName)
+	hFile:write(string.rep("/", 6 + #headingName), "\n")
+	hFile:write("// ", headingName, "\n")
+	hFile:write(string.rep("/", 6 + #headingName), "\n")
+end
+
+function my_style.WriteSmallHeading(hFile, headingName)
+	hFile:write("// ", headingName, "\n")
+end
+
+------------------------------------------------------
+-- Header styling functions
+
+function my_style.header.GetFilename(basename, options)
+	return basename .. ".hpp"
+end
+
+	local function GenIncludeGuardName(hFile, spec, options)
+		local str = "POINTER_CPP_GENERATED_HEADER" ..
+			spec.GetIncludeGuardString() .. "_HPP"
+
+		if(#options.prefix > 0) then
+			return options.prefix:upper() .. "_" .. str
+		end
+		
+		return str
+	end
+
+function my_style.header.WriteBlockBeginIncludeGuard(hFile, spec, options)
+	local inclGuard = GenIncludeGuardName(hFile, spec, options)
+	
+	hFile:fmt("#ifndef %s\n", inclGuard)
+	hFile:fmt("#define %s\n", inclGuard)
+end
+
+function my_style.header.WriteBlockEndIncludeGuard(hFile, spec, options)
+	hFile:fmt("#endif //%s\n", GenIncludeGuardName(hFile, spec, options))
+end
+
+function my_style.header.WriteInit(hFile, spec, options)
+	hFile:rawwrite(spec.GetHeaderInit())
+end
+
+function my_style.header.WriteStdTypedefs(hFile, specData, spec, options)
+	local defArray = common.GetStdTypedefs()
+	hFile:write("#ifndef GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS\n")
+	hFile:write("#define GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS\n")
+	hFile:write("\n")
+	hFile:inc()
+	for _, def in ipairs(defArray) do
+		hFile:write(def)
+	end
+	hFile:dec()
+	hFile:write("\n")
+	hFile:write("#endif /*GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS*/\n")
+end
+
+function my_style.header.WriteSpecTypedefs(hFile, specData, spec, options)
+	hFile:push()
+	common.WritePassthruData(hFile, specData.funcData.passthru)
+	hFile:pop()
+end
+
+	local function StartNamespace(hFile, namespaceName)
+		hFile:fmt("namespace %s\n", namespaceName or "")
+		hFile:write("{\n")
+		hFile:inc()
+	end
+
+	local function EndNamespace(hFile, namespaceName)
+		hFile:dec()
+		hFile:fmt("} //namespace %s\n", namespaceName or "")
+	end
+
+function my_style.header.WriteBlockBeginDecl(hFile, spec, options)
+	if(#options.prefix > 0) then
+		StartNamespace(hFile, options.prefix)
+	end
+	StartNamespace(hFile, spec.FuncNamePrefix())
+end
+
+function my_style.header.WriteBlockEndDecl(hFile, spec, options)
+	EndNamespace(hFile, spec.FuncNamePrefix())
+	if(#options.prefix > 0) then
+		EndNamespace(hFile, options.prefix)
+	end
+end
+
+	local extBlockNamespace = "exts"
+	local extVariableTypeDefinition = [[
+class LoadTest
+{
+private:
+	//Safe bool idiom. Joy!
+	typedef void (LoadTest::*bool_type)() const;
+	void big_long_name_that_really_doesnt_matter() const {}
+	
+public:
+	operator bool_type() const
+	{
+		return m_isLoaded ? &LoadTest::big_long_name_that_really_doesnt_matter : 0;
+	}
+	
+	int GetNumMissing() const {return m_numMissing;}
+	
+	LoadTest() : m_isLoaded(false), m_numMissing(0) {}
+	LoadTest(bool isLoaded, int numMissing) : m_isLoaded(isLoaded), m_numMissing(numMissing) {}
+private:
+	bool m_isLoaded;
+	int m_numMissing;
+};
+]]
+
+function my_style.header.WriteBlockBeginExtVarDecl(hFile, spec, options)
+	StartNamespace(hFile, extBlockNamespace)
+	hFile:writeblock(extVariableTypeDefinition)
+	hFile:write("\n")
+end
+
+function my_style.header.WriteBlockEndExtVarDecl(hFile, spec, options)
+	EndNamespace(hFile, extBlockNamespace)
+end
+
+	local function GenExtensionVarName(extName, spec, options)
+		return "var_" .. extName;
+	end
+
+function my_style.header.WriteExtVariableDecl(hFile, extName,
+	specData, spec, options)
+	hFile:fmt("extern LoadTest %s;\n",
+		GenExtensionVarName(extName, spec, options));
+end
+
+function my_style.header.WriteBlockBeginEnumDecl(hFile, spec, options)
+	hFile:write("enum\n")
+	hFile:write("{\n")
+	hFile:inc()
+end
+
+function my_style.header.WriteBlockEndEnumDecl(hFile, spec, options)
+	hFile:dec()
+	hFile:write("};\n")
+end
+
+	local function GenEnumName(enum)
+		return common.GetCppEnumName(enum)
+	end
+
+function my_style.header.WriteEnumDecl(hFile, enum, enumTable, spec, options,
+	enumSeen)
+	if(enumSeen[enum.name]) then
+		hFile:fmt("//%s taken from ext: %s\n", enum.name, enumSeen[enum.name])
+	else
+	
+		local enumName = GenEnumName(enum)
+		local lenEnum = #enumName
+		local numIndent = 33
+		
+		local numSpaces = numIndent - lenEnum
+		if(numSpaces < 1) then
+			numSpaces = 1
+		end
+
+		hFile:fmt("%s%s= %s,\n",
+			enumName,
+			string.rep(" ", numSpaces),
+			common.ResolveEnumValue(enum, enumTable))
+	end
+end
+
+function my_style.header.WriteBlockBeginFuncDecl(hFile, spec, options)
+	--Block containing all spec function declarations.
+end
+
+function my_style.header.WriteBlockEndFuncDecl(hFile, spec, options)
+	--Block containing all spec function declarations.
+end
+
+function my_style.header.WriteBlockBeginExtFuncDecl(hFile, extName, spec, options)
+	--Block containing all spec function declarations for a particular extension.
+	--Useful for include-guards around extension function pointers.
+end
+
+function my_style.header.WriteBlockEndExtFuncDecl(hFile, extName, spec, options)
+	--Block containing all spec function declarations for a particular extension.
+end
+
+	local function GenFuncPtrName(func, spec, options)
+		return func.name
+	end
+
+	local function GenFuncPtrTypedefName(func, spec, options)
+		return "PFN" .. GenFuncPtrName(func, spec, options):upper()
+	end
+
+	local function WriteFuncPtrTypedefStmt(hFile, func, typemap, spec, options)
+		hFile:fmt("typedef %s (%s *%s)(%s);\n",
+			common.GetFuncReturnType(func, typemap),
+			spec.GetCodegenPtrType(),
+			GenFuncPtrTypedefName(func, spec, options),
+			common.GetFuncParamList(func, typemap))
+	end
+
+	local function GenFuncPtrDefDirect(func, typemap, spec, options)
+		return string.format("%s (%s *%s)(%s)",
+			common.GetFuncReturnType(func, typemap),
+			spec.GetCodegenPtrType(),
+			GenFuncPtrName(func, spec, options),
+			common.GetFuncParamList(func, typemap, true))
+	end
+
+	local function GenFuncPtrDefTypedef(func, typemap, spec, options)
+		return string.format("%s %s",
+			GenFuncPtrTypedefName(func, spec, options),
+			GenFuncPtrName(func, spec, options))
+	end
+
+function my_style.header.WriteFuncDecl(hFile, func, typemap, spec, options)
+	hFile:write("extern ",
+		GenFuncPtrDefDirect(func, typemap, spec, options),
+		";\n")
+end
+
+function my_style.header.WriteBlockBeginSysDecl(hFile, spec, options)
+	StartNamespace(hFile, "sys")
+end
+
+function my_style.header.WriteBlockEndSysDecl(hFile, spec, options)
+	EndNamespace(hFile, "sys")
+end
+
+function my_style.header.WriteUtilityDecls(hFile, spec, options)
+	--Write declarations for public utility stuff. Enums for return values, etc.
+end
+
+function my_style.header.WriteMainLoaderFuncDecl(hFile, spec, options)
+	hFile:fmt("%s::LoadTest LoadFunctions(%s);\n", extBlockNamespace, spec.GetLoaderParams())
+end
+
+function my_style.header.WriteVersioningFuncDecls(hFile, spec, options)
+	hFile:writeblock([[
+int GetMinorVersion();
+int GetMajorVersion();
+bool IsVersionGEQ(int majorVersion, int minorVersion);
+]])
+end
+
+--------------------------------------------------
+-- Source code styling functions.
+function my_style.source.GetFilename(basename, options)
+	return basename .. ".cpp"
+end
+
+function my_style.source.WriteIncludes(hFile, basename, spec, options)
+	hFile:writeblock([[
+#include <algorithm>
+#include <vector>
+#include <string.h>
+#include <stddef.h>
+]])
+
+	local base = util.ParsePath(my_style.header.GetFilename(basename, options))
+	hFile:fmt('#include "%s"\n', base)
+end
+
+function my_style.source.WriteLoaderData(hFile, spec, options)
+	hFile:writeblock(spec.GetLoaderFunc())
+end
+
+function my_style.source.WriteBlockBeginDef(hFile, spec, options)
+	if(#options.prefix > 0) then
+		StartNamespace(hFile, options.prefix)
+	end
+	StartNamespace(hFile, spec.FuncNamePrefix())
+end
+
+function my_style.source.WriteBlockEndDef(hFile, spec, options)
+	EndNamespace(hFile, spec.FuncNamePrefix())
+	if(#options.prefix > 0) then
+		EndNamespace(hFile, options.prefix)
+	end
+end
+
+function my_style.source.WriteBlockBeginExtVarDef(hFile, spec, options)
+	StartNamespace(hFile, extBlockNamespace)
+end
+
+function my_style.source.WriteBlockEndExtVarDef(hFile, spec, options)
+	EndNamespace(hFile, extBlockNamespace)
+end
+
+function my_style.source.WriteExtVariableDef(hFile, extName,
+	specData, spec, options)
+	hFile:fmt("LoadTest %s;\n",
+		GenExtensionVarName(extName, spec, options));
+end
+
+function my_style.source.WriteBlockBeginExtFuncDef(hFile, extName, spec, options)
+	--Block containing the extension function definitions and load function
+	--for the functions in the extension `extName`.
+end
+
+function my_style.source.WriteBlockEndExtFuncDef(hFile, extName, spec, options)
+	--Block containing the extension function definitions and load function
+	--for the functions in the extension `extName`.
+end
+
+function my_style.source.WriteFuncDef(hFile, func, typemap, spec, options)
+	WriteFuncPtrTypedefStmt(hFile, func, typemap, spec, options)
+	hFile:write(GenFuncPtrDefTypedef(func, typemap, spec, options),
+		" = 0;\n")
+end
+
+	local function GenExtLoaderFuncName(extName, spec, options)
+		return "Load_" .. extName;
+	end
+
+function my_style.source.WriteBlockBeginExtLoader(hFile, extName, spec, options)
+	hFile:fmt("static int %s()\n", GenExtLoaderFuncName(extName, spec, options))
+	hFile:write("{\n")
+	hFile:inc()
+	hFile:write("int numFailed = 0;\n")
+end
+
+function my_style.source.WriteBlockEndExtLoader(hFile, extName, spec, options)
+	hFile:write "return numFailed;\n"
+	hFile:dec()
+	hFile:write("}\n")
+end
+
+function my_style.source.WriteExtFuncLoader(hFile, func, typemap, spec, options)
+	hFile:fmt('%s = reinterpret_cast<%s>(%s("%s%s"));\n',
+		GenFuncPtrName(func, spec, options),
+		GenFuncPtrTypedefName(func, spec, options),
+		common.GetProcAddressName(spec),
+		spec.FuncNamePrefix(), func.name)
+	hFile:fmt('if(!%s) ++numFailed;\n', GenFuncPtrName(func, spec, options))
+end
+
+function my_style.source.WriteBlockBeginCoreFuncDef(hFile, version, spec, options)
+	--Block containing the core functions for `version`.
+	--The block also contains the loading function for this version.
+end
+
+function my_style.source.WriteBlockEndCoreFuncDef(hFile, version, spec, options)
+	--Block containing the core functions for `version`.
+end
+
+	local function GenCoreLoaderFuncName(version, spec, options)
+		return "LoadCoreFunctions"
+	end
+
+function my_style.source.WriteBlockBeginCoreLoader(hFile, version, spec, options)
+	hFile:fmt("static int %s()\n", GenCoreLoaderFuncName(version, spec, options))
+	hFile:write("{\n")
+	hFile:inc()
+	hFile:write("int numFailed = 0;\n")
+
+end
+
+function my_style.source.WriteBlockEndCoreLoader(hFile, version, spec, options)
+	hFile:write "return numFailed;\n"
+	hFile:dec()
+	hFile:write("}\n")
+end
+
+function my_style.source.WriteCoreFuncLoader(hFile, func, typemap, spec, options)
+	hFile:fmt('%s = reinterpret_cast<%s>(%s("%s%s"));\n',
+		GenFuncPtrName(func, spec, options),
+		GenFuncPtrTypedefName(func, spec, options),
+		common.GetProcAddressName(spec),
+		spec.FuncNamePrefix(), func.name)
+		
+	--Special hack for DSA_EXT functions in core functions.
+	--They do not count against the loaded count.
+	if(func.name:match("EXT$")) then
+		hFile:write("//An EXT_direct_state_access-based function. Don't count it if it fails to load.\n")
+	else
+		hFile:fmt('if(!%s) ++numFailed;\n', GenFuncPtrName(func, spec, options))
+	end
+end
+
+function my_style.source.WriteExtStringFuncDef(hFile, specData, spec, options, funcSeen)
+	if(funcSeen[spec.GetExtStringFuncName()]) then
+		return
+	end
+	
+	--Check to see if its something we have to load.
+	local function FindFuncName(funcName)
+		for _, func in ipairs(specData.funcData.functions) do
+			if(func.name == funcName) then
+				return func
+			end
+		end
+		
+		return nil
+	end
+	
+	local extStringFunc = FindFuncName(spec.GetExtStringFuncName())
+
+	if(extStringFunc) then
+		hFile:write("\n")
+		local typemap = specData.typemap
+		WriteFuncPtrTypedefStmt(hFile, extStringFunc, typemap, spec, options)
+		hFile:write("static ", GenFuncPtrDefTypedef(extStringFunc, typemap, spec, options),
+			" = 0;\n")
+		hFile:write("\n")
+	end
+end
+
+function my_style.source.WriteBlockBeginSysDef(hFile, spec, options)
+	StartNamespace(hFile, "sys")
+end
+
+function my_style.source.WriteBlockEndSysDef(hFile, spec, options)
+	EndNamespace(hFile, "sys")
+end
+
+function my_style.source.WriteUtilityDefs(hFile, specData, spec, options)
+	--Write our mapping table definitions.
+	StartNamespace(hFile)
+	hFile:writeblock[[
+typedef int (*PFN_LOADEXTENSION)();
+struct MapEntry
+{
+	MapEntry(const char *_extName, exts::LoadTest *_extVariable)
+		: extName(_extName)
+		, extVariable(_extVariable)
+		, loaderFunc(0)
+		{}
+		
+	MapEntry(const char *_extName, exts::LoadTest *_extVariable, PFN_LOADEXTENSION _loaderFunc)
+		: extName(_extName)
+		, extVariable(_extVariable)
+		, loaderFunc(_loaderFunc)
+		{}
+	
+	const char *extName;
+	exts::LoadTest *extVariable;
+	PFN_LOADEXTENSION loaderFunc;
+};
+
+struct MapCompare
+{
+	MapCompare(const char *test_) : test(test_) {}
+	bool operator()(const MapEntry &other) { return strcmp(test, other.extName) == 0; }
+	const char *test;
+};
+
+]]
+
+	--Write the table initialization function.
+	hFile:write "void InitializeMappingTable(std::vector<MapEntry> &table)\n"
+	hFile:write "{\n"
+	hFile:inc()
+	hFile:fmt("table.reserve(%i);\n", #options.extensions)
+	for _, extName in ipairs(options.extensions) do
+		if(#specData.extdefs[extName].funcs > 0) then
+			hFile:fmt('table.push_back(MapEntry("%s", &exts::%s, %s));\n',
+				spec.ExtNamePrefix() .. extName,
+				GenExtensionVarName(extName, spec, options),
+				GenExtLoaderFuncName(extName, spec, options))
+		else
+			hFile:fmt('table.push_back(MapEntry("%s", &exts::%s));\n',
+				spec.ExtNamePrefix() .. extName,
+				GenExtensionVarName(extName, spec, options))
+		end
+	end
+	hFile:dec()
+	hFile:write "}\n"
+	hFile:write "\n"
+	
+	--Write the function to clear the extension variables.
+	hFile:fmt("void ClearExtensionVars()\n")
+	hFile:write("{\n")
+	hFile:inc()
+	for _, extName in ipairs(options.extensions) do
+		hFile:fmt('exts::%s = exts::LoadTest();\n',
+			GenExtensionVarName(extName, spec, options))
+	end
+	hFile:dec()
+	hFile:write("}\n")
+	hFile:write "\n"
+	
+	--Write a function that loads an extension by name. It is called when
+	--processing, so it should also set the extension variable based on the load.
+	hFile:writeblock([[
+void LoadExtByName(std::vector<MapEntry> &table, const char *extensionName)
+{
+	std::vector<MapEntry>::iterator entry = std::find_if(table.begin(), table.end(), MapCompare(extensionName));
+	
+	if(entry != table.end())
+	{
+		if(entry->loaderFunc)
+			(*entry->extVariable) = exts::LoadTest(true, entry->loaderFunc());
+		else
+			(*entry->extVariable) = exts::LoadTest(true, 0);
+	}
+}
+]])
+	EndNamespace(hFile)
+	hFile:write "\n"
+end
+
+	local function GenQualifier(spec, options)
+		local ret = ""
+		if(#options.prefix > 0) then
+			ret = options.prefix .. "::"
+		end
+		ret = ret .. spec.FuncNamePrefix() .. "::"
+		return ret
+	end
+
+	local function GenQualifiedEnumName(enum, spec, options)
+		return GenQualifier(spec, options) .. GenEnumName(enum, spec, options)
+	end
+	
+	local function GenQualifiedFuncPtrName(func, spec, options)
+		return GenQualifier(spec, options) .. GenFuncPtrName(func, spec, options)
+	end
+	
+	local function WriteAncillaryFuncs(hFile, specData, spec, options)
+		local indexed = spec.GetIndexedExtStringFunc(options);
+		if(indexed) then
+			for _, func in ipairs(specData.funcData.functions) do
+				if(indexed[1] == func.name) then
+					indexed[1] = func
+				end
+				if(indexed[3] == func.name) then
+					indexed[3] = func
+				end
+			end
+			for _, enum in ipairs(specData.enumerations) do
+				if(indexed[2] == enum.name) then
+					indexed[2] = enum
+				end
+				if(indexed[4] == enum.name) then
+					indexed[4] = enum
+				end
+			end
+		
+			hFile:writeblock([[
+static void ProcExtsFromExtList(std::vector<MapEntry> &table)
+{
+	GLint iLoop;
+	GLint iNumExtensions = 0;
+	]] .. GenQualifiedFuncPtrName(indexed[1], spec, options)
+	.. [[(]] .. GenQualifiedEnumName(indexed[2], spec, options)
+	.. [[, &iNumExtensions);
+
+	for(iLoop = 0; iLoop < iNumExtensions; iLoop++)
+	{
+		const char *strExtensionName = (const char *)]] ..
+		GenQualifiedFuncPtrName(indexed[3], spec, options) ..
+		[[(]] .. GenQualifiedEnumName(indexed[4], spec, options) .. [[, iLoop);
+		LoadExtByName(table, strExtensionName);
+	}
+}
+]])
+		else
+			hFile:writeblock(common.GetProcessExtsFromStringFunc(
+				"LoadExtByName(table, %s)", ", std::vector<MapEntry> &table"))
+		end
+		
+		hFile:write "\n"
+
+		return indexed
+	end
+
+	
+	local function WriteInMainFuncLoader(hFile, func, spec, options)
+		hFile:fmt('%s = reinterpret_cast<%s>(%s("%s%s"));\n',
+			GenFuncPtrName(func, spec, options),
+			GenFuncPtrTypedefName(func, spec, options),
+			common.GetProcAddressName(spec),
+			spec.FuncNamePrefix(), func.name)
+		hFile:fmt('if(!%s) return exts::LoadTest();\n',
+			GenFuncPtrName(func, spec, options))
+	end
+
+function my_style.source.WriteMainLoaderFunc(hFile, specData, spec, options)
+	StartNamespace(hFile)
+	local indexed = WriteAncillaryFuncs(hFile, specData, spec, options)
+	EndNamespace(hFile)
+	
+	hFile:write "\n"
+	
+	hFile:fmt("exts::LoadTest LoadFunctions(%s)\n", spec.GetLoaderParams())
+	hFile:write("{\n")
+	hFile:inc()
+	hFile:writeblock[[
+ClearExtensionVars();
+std::vector<MapEntry> table;
+InitializeMappingTable(table);
+]]
+	hFile:write("\n")
+	
+	if(indexed) then
+		WriteInMainFuncLoader(hFile, indexed[1], spec, options)
+		WriteInMainFuncLoader(hFile, indexed[3], spec, options)
+		hFile:write("\n")
+		hFile:write("ProcExtsFromExtList(table);\n")
+	else
+		local extListName, needLoad = spec.GetExtStringFuncName()
+		if(needLoad) then
+			for _, func in ipairs(specData.funcData.functions) do
+				if(extListName == func.name) then
+					extListName = func
+					break
+				end
+			end
+			
+			WriteInMainFuncLoader(hFile, extListName, spec, options)
+			
+			extListName = GenQualifiedFuncPtrName(extListName, spec, options);
+		end
+
+		local function EnumResolve(enumName)
+			return GenQualifiedEnumName(specData.enumtable[enumName], spec, options)
+		end
+		
+		hFile:write "\n"
+		hFile:fmt("ProcExtsFromExtString((const char *)%s(%s), table);\n",
+			extListName,
+			spec.GetExtStringParamList(EnumResolve))
+	end
+	
+	if(options.version) then
+		hFile:write "\n"
+		hFile:fmt("int numFailed = %s();\n",
+			GenCoreLoaderFuncName(options.version, spec, options))
+		
+		hFile:write("return exts::LoadTest(true, numFailed);\n")
+	else
+		hFile:fmt("return exts::LoadTest(true, 0);\n")
+	end
+
+
+	hFile:dec()
+	hFile:write("}\n")
+end
+
+function my_style.source.WriteVersioningFuncs(hFile, specData, spec, options)
+	hFile:fmt("static int g_major_version = 0;\n")
+	hFile:fmt("static int g_minor_version = 0;\n")
+	hFile:write "\n"
+	
+	if(tonumber(options.version) >= 3.0) then
+		hFile:writeblock([[
+static void GetGLVersion()
+{
+	GetIntegerv(MAJOR_VERSION, &g_major_version);
+	GetIntegerv(MINOR_VERSION, &g_minor_version);
+}
+]])
+	else
+		hFile:writeblock(common.GetParseVersionFromString())
+		hFile:write "\n"
+		
+		hFile:writeblock([[
+static void GetGLVersion()
+{
+	ParseVersionFromString(&g_major_version, &g_minor_version, GetString(VERSION));
+}
+]])
+	end
+	
+	hFile:write "\n"
+	hFile:writeblock([[
+int GetMajorVersion()
+{
+	if(g_major_version == 0)
+		GetGLVersion();
+	return g_major_version;
+}
+]])
+	hFile:write "\n"
+
+	hFile:writeblock([[
+int GetMinorVersion()
+{
+	if(g_major_version == 0) //Yes, check the major version to get the minor one.
+		GetGLVersion();
+	return g_minor_version;
+}
+]])
+	hFile:write "\n"
+	
+	hFile:writeblock([[
+bool IsVersionGEQ(int majorVersion, int minorVersion)
+{
+	if(g_major_version == 0)
+		GetGLVersion();
+		
+	if(majorVersion > g_major_version) return true;
+	if(majorVersion < g_major_version) return false;
+	if(minorVersion >= g_minor_version) return true;
+	return false;
+}
+]])
+
+end
+
+
+--------------------------------------------------
+-- Style retrieval machinery
+
+local function Create()
+	return common.DeepCopyTable(my_style), common.GetStandardStructure()
+end
+
+return { Create = Create }

modules/PointerC_Style.lua

+
+local common = require "CommonStyle"
+local struct = require "Structure"
+local util = require "util"
+
+
+local my_style = {}
+my_style.header = {}
+my_style.source = {}
+
+function my_style.WriteLargeHeading(hFile, headingName)
+	hFile:write("/*", string.rep("*", #headingName), "*/\n")
+	hFile:write("/*", headingName, "*/\n")
+end
+
+function my_style.WriteSmallHeading(hFile, headingName)
+	hFile:write("/*", headingName, "*/\n")
+end
+
+----------------------------------------------------------------
+-- Header file construction
+
+function my_style.header.GetFilename(basename, options)
+	return basename .. ".h"
+end
+
+
+local function GetIncludeGuard(hFile, spec, options)
+	local str = "POINTER_C_GENERATED_HEADER_" ..
+		spec.GetIncludeGuardString() .. "_H"
+
+	if(#options.prefix > 0) then
+		return options.prefix:upper() .. "_" .. str
+	end
+	
+	return str
+end
+
+function my_style.header.WriteBlockBeginIncludeGuard(hFile, spec, options)
+	local inclGuard = GetIncludeGuard(hFile, spec, options)
+	
+	hFile:fmt("#ifndef %s\n", inclGuard)
+	hFile:fmt("#define %s\n", inclGuard)
+end
+
+function my_style.header.WriteBlockEndIncludeGuard(hFile, spec, options)
+	local inclGuard = GetIncludeGuard(hFile, spec, options)
+	
+	hFile:fmt("#endif //%s\n", inclGuard)
+end
+
+function my_style.header.WriteInit(hFile, spec, options)
+	hFile:rawwrite(spec.GetHeaderInit())
+end
+
+function my_style.header.WriteStdTypedefs(hFile, specData, options)
+	local defArray = common.GetStdTypedefs()
+	
+	--Use include-guards for the typedefs, since they're common among
+	--headers in this style.
+	
+	hFile:write("#ifndef GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS\n")
+	hFile:write("#define GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS\n")
+	hFile:write("\n")
+	hFile:inc()
+	
+	for _, def in ipairs(defArray) do
+		hFile:write(def)
+	end
+	
+	hFile:dec()
+	hFile:write("\n")
+	hFile:write("#endif /*GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS*/\n")
+	hFile:write("\n")
+end
+
+function my_style.header.WriteSpecTypedefs(hFile, specData, options)
+	hFile:push()
+	common.WritePassthruData(hFile, specData.funcData.passthru)
+	hFile:pop()
+end
+
+function my_style.header.WriteBlockBeginDecl(hFile, specData, options)
+	common.WriteExternCStart(hFile)
+end
+
+function my_style.header.WriteBlockBeginExtVarDecl(hFile, spec, options)
+end
+
+function my_style.header.WriteBlockEndExtVarDecl(hFile, spec, options)
+end
+
+local function GetExtVariableName(extName, spec, options)
+	return options.prefix .. spec.DeclPrefix() .. "ext_" .. extName
+end
+
+function my_style.header.WriteExtVariableDecl(hFile, extName, specData, spec, options)
+	hFile:write("extern int ", GetExtVariableName(extName, spec, options), ";\n");
+end
+
+function my_style.header.WriteBlockBeginEnumDecl(hFile, specData, options) end
+
+function my_style.header.WriteBlockEndEnumDecl(hFile, specData, options) end
+
+local function GetEnumName(enum, spec, options)
+	return spec.EnumNamePrefix() .. enum.name
+end
+
+function my_style.header.WriteEnumDecl(hFile, enum, enumTable, spec, options, enumSeen)
+	if(enumSeen[enum.name]) then
+		hFile:fmt("/*Copied %s%s From: %s*/\n",
+			spec.EnumNamePrefix(),
+			enum.name,
+			enumSeen[enum.name])
+	else
+		hFile:fmt("#define %s %s\n",
+			GetEnumName(enum, spec, options),
+			common.ResolveEnumValue(enum, enumTable))
+	end
+end
+
+function my_style.header.WriteBlockBeginFuncDecl(hFile, specData, options)
+end
+
+local function GetFuncPtrName(func, spec, options)
+	return options.prefix .. "_ptrc_".. spec.FuncNamePrefix() .. func.name
+end
+
+local function GetFuncPtrType(hFile, func, typemap, spec, options)
+	return string.format("%s (%s *)(%s)",
+		common.GetFuncReturnType(func, typemap),
+		spec.GetCodegenPtrType(),
+		common.GetFuncParamList(func, typemap))
+end
+
+local function GetFuncPtrDef(hFile, func, typemap, spec, options)
+	return string.format("%s (%s *%s)(%s)",
+		common.GetFuncReturnType(func, typemap),
+		spec.GetCodegenPtrType(),
+		GetFuncPtrName(func, spec, options),
+		common.GetFuncParamList(func, typemap))
+end
+
+function my_style.header.WriteFuncDecl(hFile, func, typemap, spec, options)
+	--Declare the function pointer.
+	hFile:write("extern ",
+		GetFuncPtrDef(hFile, func, typemap, spec, options),
+		";\n")
+	
+	--#define it to the proper OpenGL name.
+	hFile:fmt("#define %s %s\n",
+		common.GetOpenGLFuncName(func, spec),
+		GetFuncPtrName(func, spec, options))
+end
+
+function my_style.header.WriteBlockEndFuncDecl(hFile, specData, options)
+end
+
+function my_style.header.WriteBlockBeginExtFuncDecl(hFile, extName,
+	spec, options)
+	hFile:fmt("#ifndef %s\n", spec.ExtNamePrefix() .. extName)
+	hFile:fmt("#define %s 1\n", spec.ExtNamePrefix() .. extName)
+end
+
+function my_style.header.WriteBlockEndExtFuncDecl(hFile, extName,
+	spec, options)
+	hFile:fmt("#endif /*%s*/ \n", spec.ExtNamePrefix() .. extName)
+end
+
+function my_style.header.WriteBlockBeginSysDecl(hFile, spec, options)
+end
+
+function my_style.header.WriteBlockEndSysDecl(hFile, spec, options)
+end
+
+local function GetStatusCodeEnumName(spec, options)
+	return string.format("%s%sLoadStatus", options.prefix, spec.DeclPrefix())
+end
+
+local function GetStatusCodeName(name, spec, options)
+	return string.format("%s%s%s", options.prefix, spec.DeclPrefix(), name)
+end
+
+function my_style.header.WriteUtilityDecls(hFile, spec, options)
+	hFile:fmt("enum %s\n", GetStatusCodeEnumName(spec, options))
+	hFile:write("{\n")
+	hFile:inc()
+		hFile:write(GetStatusCodeName("LOAD_FAILED", spec, options), " = 0,\n")
+		hFile:write(GetStatusCodeName("LOAD_SUCCEEDED", spec, options), " = 1,\n")
+	hFile:dec()
+	hFile:write("};\n")
+end
+
+local function DecorateFuncName(name, spec, options)
+	return string.format("%s%s%s", options.prefix, spec.DeclPrefix(), name)
+end
+
+local function GetLoaderFuncName(spec, options)
+	return DecorateFuncName("LoadFunctions", spec, options)
+end
+
+function my_style.header.WriteMainLoaderFuncDecl(hFile, spec, options)
+	hFile:fmt("int %s(%s);\n",
+		GetLoaderFuncName(spec, options),
+		spec.GetLoaderParams())
+end
+
+function my_style.header.WriteVersioningFuncDecls(hFile, spec, options)
+	--Only for GL
+	if(options.spec ~= "gl") then
+		return
+	end
+	
+	hFile:fmt("int %s();\n", DecorateFuncName("GetMinorVersion", spec, options))
+	hFile:fmt("int %s();\n", DecorateFuncName("GetMajorVersion", spec, options))
+	hFile:fmt("int %s(int majorVersion, int minorVersion);\n",
+		DecorateFuncName("IsVersionGEQ", spec, options))
+end
+
+function my_style.header.WriteBlockEndDecl(hFile, specData, options)
+	common.WriteExternCEnd(hFile)
+end
+
+--------------------------------------------------
+-- Source file construction functions.
+
+function my_style.source.GetFilename(basename, options)
+	return basename .. ".c"
+end
+
+function my_style.source.WriteIncludes(hFile, basename, spec, options)
+	hFile:writeblock([[
+#include <stdlib.h>
+#include <string.h>
+#include <stddef.h>
+]])
+	local base = util.ParsePath(my_style.header.GetFilename(basename, options))
+	hFile:fmt('#include "%s"\n', base)
+end
+
+function my_style.source.WriteLoaderData(hFile, spec, options)
+	hFile:writeblock(spec.GetLoaderFunc())
+end
+
+function my_style.source.WriteBlockBeginDef(hFile, spec, options) end
+function my_style.source.WriteBlockEndDef(hFile, spec, options) end
+
+function my_style.source.WriteBlockBeginExtVarDef(hFile, spec, options)
+end
+
+function my_style.source.WriteBlockEndExtVarDef(hFile, spec, options)
+end
+
+function my_style.source.WriteExtVariableDef(hFile, extName, specData, spec, options)
+	hFile:fmt("int %s = %s;\n", GetExtVariableName(extName, spec, options),
+		GetStatusCodeName("LOAD_FAILED", spec, options));
+end
+
+function my_style.source.WriteBlockBeginExtFuncDef(hFile, extName, spec, options)
+end
+
+function my_style.source.WriteBlockEndExtFuncDef(hFile, extName, spec, options)
+end
+
+function my_style.source.WriteFuncDef(hFile, func, typemap, spec, options, funcSeen)
+	--Declare the function pointer, if not already declared.
+	if(funcSeen[func.name]) then return end
+	
+	hFile:fmt("%s = NULL;\n",
+		GetFuncPtrDef(hFile, func, typemap, spec, options))
+end
+
+local function GetExtLoaderFuncName(extName, spec, options)
+	return "Load_" .. extName;
+end
+
+function my_style.source.WriteBlockBeginExtLoader(hFile, extName, spec, options)
+	hFile:fmt("static int %s()\n", GetExtLoaderFuncName(extName, spec, options))
+	hFile:write("{\n")
+	hFile:inc()
+	hFile:write("int numFailed = 0;\n")
+end
+
+function my_style.source.WriteBlockEndExtLoader(hFile, extName, spec, options)
+	hFile:write("return numFailed;\n")
+	hFile:dec()
+	hFile:write("}\n")
+end
+
+function my_style.source.WriteExtFuncLoader(hFile, func, typemap, spec, options)
+	hFile:fmt('%s = (%s)%s("%s%s");\n',
+		GetFuncPtrName(func, spec, options),
+		GetFuncPtrType(hFile, func, typemap, spec, options),
+		common.GetProcAddressName(spec),
+		spec.FuncNamePrefix(), func.name)
+	hFile:fmt('if(!%s) numFailed++;\n', GetFuncPtrName(func, spec, options))
+end
+
+function my_style.source.WriteBlockBeginCoreFuncDef(hFile, spec, options)
+end
+
+function my_style.source.WriteBlockEndCoreFuncDef(hFile, spec, options)
+end
+
+local function GetCoreLoaderFuncName(spec, options)
+	return "Load_Version_" .. options.version:gsub("%.", "_")
+end
+
+function my_style.source.WriteBlockBeginCoreLoader(hFile, spec, options)
+	hFile:fmt("static int %s()\n", GetCoreLoaderFuncName(spec, options))
+	hFile:write("{\n")
+	hFile:inc()
+	hFile:write("int numFailed = 0;\n")
+end
+
+function my_style.source.WriteBlockEndCoreLoader(hFile, version, spec, options)
+	hFile:write("return numFailed;\n")
+	hFile:dec()
+	hFile:write("}\n")
+end
+
+function my_style.source.WriteCoreFuncLoader(hFile, func, typemap, spec, options)
+	hFile:fmt('%s = (%s)%s("%s%s");\n',
+		GetFuncPtrName(func, spec, options),
+		GetFuncPtrType(hFile, func, typemap, spec, options),
+		common.GetProcAddressName(spec),
+		spec.FuncNamePrefix(), func.name)
+
+	--Special hack for DSA_EXT functions in core functions.
+	--They do not count against the loaded count.
+	if(func.name:match("EXT$")) then
+		hFile:write("/*An EXT_direct_state_access-based function. Don't count it.*/")
+	else
+		hFile:fmt('if(!%s) numFailed++;\n', GetFuncPtrName(func, spec, options))
+	end
+end
+
+function my_style.source.WriteExtStringFuncDef(hFile, specData, spec, options, funcSeen)
+	if(funcSeen[spec.GetExtStringFuncName()]) then
+		return
+	end
+	
+	--Check to see if its something we have to load.
+	local function FindFuncName(funcName)
+		for _, func in ipairs(specData.funcData.functions) do
+			if(func.name == funcName) then
+				return func
+			end
+		end
+		
+		return nil
+	end
+	
+	local extStringFunc = FindFuncName(spec.GetExtStringFuncName())
+
+	if(extStringFunc) then
+		hFile:write("\n")
+		hFile:fmt("static %s = NULL;\n",
+			GetFuncPtrDef(hFile, extStringFunc, specData.typemap, spec, options))
+		hFile:write("\n")
+	end
+end
+
+local function GetMapTableStructName(spec, options)
+	return string.format("%s%sStrToExtMap", options.prefix, spec.DeclPrefix())
+end
+
+local function GetMapTableVarName()
+	return "ExtensionMap"
+end
+
+function my_style.source.WriteBlockBeginSysDef(hFile, spec, options)
+end
+
+function my_style.source.WriteBlockEndSysDef(hFile, spec, options)
+end
+
+function my_style.source.WriteUtilityDefs(hFile, specData, spec, options)
+	--Write the struct for the mapping table.
+	local mapStructName = string.format("%s%sStrToExtMap_s", options.prefix, spec.DeclPrefix())
+	common.WriteCMappingTable(hFile, specData, spec, options,
+		GetMapTableStructName(spec, options),
+		GetMapTableVarName(),
+		GetExtVariableName,
+		GetExtLoaderFuncName)
+	hFile:write "\n"
+	
+	--Write function to find map entry by name.
+	common.WriteCFindExtEntryFunc(hFile, specData, spec, options,
+		GetMapTableStructName(spec, options),
+		GetMapTableVarName())
+	hFile:write "\n"
+
+	--Write the function to clear the extension variables.
+	common.WriteCClearExtensionVarsFunc(hFile, specData, spec, options,
+		GetExtVariableName,
+		GetStatusCodeName("LOAD_FAILED", spec, options))
+	hFile:write "\n"
+	
+	--Write a function that loads an extension by name.
+	common.WriteCLoadExtByNameFunc(hFile, specData, spec, options,
+		GetMapTableStructName(spec, options),
+		GetStatusCodeName("LOAD_SUCCEEDED", spec, options))
+	hFile:write "\n"
+end
+
+local function WriteAncillaryFuncs(hFile, specData, spec, options)
+	local indexed = spec.GetIndexedExtStringFunc(options);
+	if(indexed) then
+		common.FixupIndexedList(specData, indexed)
+		hFile:writeblock(common.GetProcExtsFromExtListFunc(
+			hFile, specData, spec, options,
+			indexed, GetFuncPtrName, GetEnumName))
+	else
+		hFile:writeblock(common.GetProcessExtsFromStringFunc("LoadExtByName(%s)"))
+	end
+	
+	hFile:write "\n"
+
+	return indexed
+end
+
+local function WriteInMainFuncLoader(hFile, func, typemap, spec, options)
+	hFile:fmt('%s = (%s)%s("%s%s");\n',
+		GetFuncPtrName(func, spec, options),
+		GetFuncPtrType(hFile, func, typemap, spec, options),
+		common.GetProcAddressName(spec),
+		spec.FuncNamePrefix(), func.name)
+	hFile:fmt('if(!%s) return %s;\n',
+		GetFuncPtrName(func, spec, options),
+		GetStatusCodeName("LOAD_FAILED", spec, options))
+end
+
+
+function my_style.source.WriteMainLoaderFunc(hFile, specData, spec, options)
+	local indexed = WriteAncillaryFuncs(hFile, specData, spec, options)
+
+	--Write the function that calls the extension and core loaders.
+	hFile:fmt("int %s(%s)\n",
+		GetLoaderFuncName(spec, options),
+		spec.GetLoaderParams())
+	hFile:write("{\n")
+	hFile:inc()
+
+	if(options.version) then
+		hFile:write("int numFailed = 0;\n")
+	end
+
+	hFile:write("ClearExtensionVars();\n")
+	hFile:write("\n")
+
+	--Load the extension, using runtime-facilities to tell what is available.
+	if(indexed) then
+		WriteInMainFuncLoader(hFile, indexed[1], specData.typemap, spec, options)
+		WriteInMainFuncLoader(hFile, indexed[3], specData.typemap, spec, options)
+		hFile:write("\n")
+		hFile:write("ProcExtsFromExtList();\n")
+	else
+		local extListName, needLoad = spec.GetExtStringFuncName()
+		if(needLoad) then
+			for _, func in ipairs(specData.funcData.functions) do
+				if(extListName == func.name) then
+					extListName = func
+				end
+			end
+			
+			WriteInMainFuncLoader(hFile, extListName, specData.typemap, spec, options)
+			
+			extListName = GetFuncPtrName(extListName, spec, options);
+		end
+
+		local function EnumResolve(enumName)
+			return GetEnumName(specData.enumtable[enumName], spec, options)
+		end
+		
+		hFile:write "\n"
+		hFile:fmt("ProcExtsFromExtString((const char *)%s(%s));\n",
+			extListName,
+			spec.GetExtStringParamList(EnumResolve))
+	end
+	
+	if(options.version) then
+		hFile:fmt("numFailed = %s();\n",
+			GetCoreLoaderFuncName(spec, options))
+		hFile:write "\n"
+		
+		hFile:fmtblock([[
+if(numFailed == 0)
+	return %s;
+else
+	return %s + numFailed;
+]],
+			GetStatusCodeName("LOAD_SUCCEEDED", spec, options),
+			GetStatusCodeName("LOAD_SUCCEEDED", spec, options))
+	else
+		hFile:fmt("return %s;\n",
+			GetStatusCodeName("LOAD_SUCCEEDED", spec, options))
+	end
+	
+	hFile:dec()
+	hFile:write("}\n")
+end
+
+function my_style.source.WriteVersioningFuncs(hFile, specData, spec, options)
+	hFile:fmt("static int g_major_version = 0;\n")
+	hFile:fmt("static int g_minor_version = 0;\n")
+	hFile:write "\n"
+	
+	if(tonumber(options.version) >= 3.0) then
+		hFile:writeblock([[
+static void GetGLVersion()
+{
+	glGetIntegerv(GL_MAJOR_VERSION, &g_major_version);
+	glGetIntegerv(GL_MINOR_VERSION, &g_minor_version);
+}
+]])
+	else
+		hFile:writeblock(common.GetParseVersionFromString())
+		hFile:write "\n"
+		
+		hFile:writeblock([[
+static void GetGLVersion()
+{
+	ParseVersionFromString(&g_major_version, &g_minor_version, glGetString(GL_VERSION));
+}
+]])
+	end
+	
+	hFile:write "\n"
+	hFile:fmt("int %s()\n", DecorateFuncName("GetMajorVersion", spec, options))
+	hFile:writeblock([[
+{
+	if(g_major_version == 0)
+		GetGLVersion();
+	return g_major_version;
+}
+]])
+	hFile:write "\n"
+
+	hFile:fmt("int %s()\n", DecorateFuncName("GetMinorVersion", spec, options))
+	hFile:writeblock([[
+{
+	if(g_major_version == 0) //Yes, check the major version to get the minor one.
+		GetGLVersion();
+	return g_minor_version;
+}
+]])
+	hFile:write "\n"
+	
+	hFile:fmt("int %s(int majorVersion, int minorVersion)\n",
+		DecorateFuncName("IsVersionGEQ", spec, options))
+	hFile:writeblock([[
+{
+	if(g_major_version == 0)
+		GetGLVersion();
+		
+	if(majorVersion > g_major_version) return 1;
+	if(majorVersion < g_major_version) return 0;
+	if(minorVersion >= g_minor_version) return 1;
+	return 0;
+}
+]])
+
+end
+
+
+
+--------------------------------------------------
+-- Style retrieval machinery
+
+local function Create()
+	return common.DeepCopyTable(my_style), common.GetStandardStructure()
+end
+
+return { Create = Create }

modules/Sample_Struct.lua

+local struct = require "Structure"
+local common = require "CommonStruct"
+
+local my_struct = 
+{
+	{ type="file", style="hdr", name="GetFilename(basename, spec, options)",
+		{ type="block", name="IncludeGuard",
+			{ type="write", name="Guards(hFile, spec, options)", },
+			{ type="blank" },
+			{ type="write", name="Typedefs(hFile, specData, spec, options)",},
+			{ type="blank" },
+			{ type="block", name="Extern(hFile)",
+				{ type="ext-iter",
+					{ type="write", name="Extension(hFile, extName, spec, options)", },
+				},
+				{ type="blank" },
+				common.Enumerators(),
+				{ type="blank" },
+				common.Functions(),
+				{ type="blank" },
+				{ type="write", name="MainLoaderFunc(hFile, spec, options)",},
+			},
+		},
+	},
+	{ type="file", style="src", name="GetFilename(basename, spec, options)",
+		{ type="write", name="Includes(hFile, basename, spec, options)", },
+		{ type="blank" },
+		{ type="write", name="LoaderFunc(hFile, spec, options)", },
+		{ type="blank" },
+		{ type="ext-iter",
+			{ type="write", name="Extension(hFile, extName, spec, options)", },
+		},
+		{ type="blank" },
+		common.Functions(),
+		{ type="ext-iter",
+			{ type="block", name="ExtFuncLoader(hFile, extName, spec, options)", cond="func-iter",
+				{ type="func-iter",
+					{ type="write", name="LoadFunction(hFile, func, typemap, spec, options)", },
+				},
+			},
+			{ type="blank", cond="func-iter",},
+		},
+		{ type="block", name="CoreLoader(hFile, spec, options)", cond="core-funcs",
+			{ type="version-iter",
+				{ type="core-ext-iter",
+					{type="func-iter",
+						{ type="write", name="LoadFunction(hFile, func, typemap, spec, options)", },
+					},
+				},
+				{type="func-iter",
+					{ type="write", name="LoadFunction(hFile, func, typemap, spec, options)", },
+				},
+			},
+		},
+		{ type="blank", },
+		{ type="write", name="MainLoaderFunc(hFile, specData, spec, options)",},
+	},
+}
+
+my_struct = struct.BuildStructure(my_struct)
+return my_struct

modules/Sample_Style.lua

+local util = require "util"
+local struct = require "Sample_Struct"
+local common = require "CommonStyle"
+
+local function GetIncludeGuard(spec, options)
+  local temp = 
+    options.prefix .. spec.GetIncludeGuardString() .. "_THIS_IS_A_TEST_H"
+  return temp:upper()
+end
+
+local function GetExtensionVarName(extName, spec, options)
+	return options.prefix .. spec.DeclPrefix() .. "ext_" .. extName
+end
+
+local function GetEnumName(enum, spec, options)
+	return spec.EnumNamePrefix() .. enum.name
+end
+
+local function GetFuncPtrName(func, spec, options)
+  return options.prefix .. "_testc_".. spec.FuncNamePrefix() .. func.name
+end
+
+local function GetFuncPtrDef(hFile, func, typemap, spec, options)
+  return string.format("%s (%s *%s)(%s)",
+    common.GetFuncReturnType(func, typemap),
+    spec.GetCodegenPtrType(),
+    GetFuncPtrName(func, spec, options),
+    common.GetFuncParamList(func, typemap))
+end
+
+local function GetFuncPtrType(hFile, func, typemap, spec, options)
+  return string.format("%s (%s *)(%s)",
+    common.GetFuncReturnType(func, typemap),
+    spec.GetCodegenPtrType(),
+    common.GetFuncParamList(func, typemap))
+end
+
+local function GetMainLoaderFuncName(spec, options)
+  return options.prefix .. spec.DeclPrefix() .. "LoadFunctions"
+end
+
+local function GetExtFuncLoaderName(extName, spec, options)
+  return "Load_" .. extName;
+end
+
+local function GetMappingTableStructName(spec, options)
+  return string.format("%s%sStringToExtMap",
+    options.prefix, spec.DeclPrefix())
+end
+
+local function GetMappingTableVarName()
+  return "g_stringToExtMap"
+end
+
+
+
+
+local my_style = {}
+
+local hdr = {}
+my_style.hdr = hdr
+
+function hdr.GetFilename(basename, spec, options)
+  return basename .. ".h"
+end
+
+function hdr.WriteBlockBeginIncludeGuard(hFile, spec, options)
+  local guard = GetIncludeGuard(spec, options)
+  hFile:fmt("#ifndef %s\n", guard)
+  hFile:fmt("#define %s\n", guard)
+end
+
+function hdr.WriteBlockEndIncludeGuard(hFile, spec, options)
+  hFile:fmt("#endif /*%s*/\n", GetIncludeGuard(spec, options))
+end
+
+function hdr.WriteGuards(hFile, spec, options)
+  hFile:rawwrite(spec.GetHeaderInit())
+end
+
+function hdr.WriteTypedefs(hFile, specData, spec, options)
+  local defArray = common.GetStdTypedefs()
+	
+  --Use include-guards for the typedefs, since they're common among
+  --headers in this style.
+  hFile:write("#ifndef GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS\n")
+  hFile:write("#define GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS\n")
+  hFile:write("\n")
+  hFile:inc()
+	
+  for _, def in ipairs(defArray) do
+    hFile:write(def)
+  end
+	
+  hFile:dec()
+  hFile:write("\n")
+  hFile:write("#endif /*GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS*/\n")
+  hFile:write("\n")
+
+  common.WritePassthruData(hFile, specData.funcData.passthru)
+end
+
+hdr.WriteBlockBeginExtern = common.WriteExternCStart
+hdr.WriteBlockEndExtern = common.WriteExternCEnd
+
+function hdr.WriteExtension(hFile, extName, spec, options)
+  hFile:fmt("extern int %s;\n", GetExtensionVarName(extName, spec, options));
+end
+
+function hdr.WriteEnumerator(hFile, enum, enumTable, spec, options, enumSeen)
+  if(enumSeen[enum.name]) then return end
+
+  hFile:fmt("#define %s %s\n",
+    GetEnumName(enum, spec, options),
+    common.ResolveEnumValue(enum, enumTable))
+end
+
+function hdr.WriteFunction(hFile, func, typemap, spec, options, funcSeen)
+  if(funcSeen[func.name]) then return end
+
+  hFile:fmt("extern %s;\n",
+    GetFuncPtrDef(hFile, func, typemap, spec, options))
+
+  hFile:fmt("#define %s %s\n",
+    common.GetOpenGLFuncName(func, spec),
+    GetFuncPtrName(func, spec, options))
+end
+
+function hdr.WriteMainLoaderFunc(hFile, spec, options)
+	hFile:fmt("int %s(%s);\n",
+		GetMainLoaderFuncName(spec, options),
+		spec.GetLoaderParams())
+end
+
+
+local src = {}
+my_style.src = src
+
+function src.GetFilename(basename, spec, options)
+  return basename .. ".c"
+end
+
+function src.WriteIncludes(hFile, basename, spec, options)
+  hFile:writeblock([[
+#include <stdlib.h>
+#include <string.h>
+]])
+  local base = util.ParsePath(hdr.GetFilename(basename, spec, options))
+  hFile:fmt('#include "%s"\n', base)
+end
+
+function src.WriteLoaderFunc(hFile, spec, options)
+  hFile:writeblock(spec.GetLoaderFunc())
+end
+
+function src.WriteExtension(hFile, extName, spec, options)
+  hFile:fmt("int %s = 0;\n", GetExtensionVarName(extName, spec, options));
+end
+
+function src.WriteFunction(hFile, func, typemap, spec, options, funcSeen)
+  if(funcSeen[func.name]) then return end
+  hFile:fmt("%s = NULL;\n", GetFuncPtrDef(hFile, func, typemap, spec, options));
+end
+
+function src.WriteBlockBeginExtFuncLoader(hFile, extName, spec, options)
+  hFile:fmt("static void %s()\n", GetExtFuncLoaderName(extName, spec, options))
+  hFile:write("{\n")
+  hFile:inc()
+end
+
+function src.WriteBlockEndExtFuncLoader(hFile, extName, spec, options)
+  hFile:dec()
+  hFile:write("}\n")
+end
+
+function src.WriteLoadFunction(hFile, func, typemap, spec, options)
+  hFile:fmt('%s = (%s)%s("%s%s");\n',
+    GetFuncPtrName(func, spec, options),
+	GetFuncPtrType(hFile, func, typemap, spec, options),
+    spec.GetPtrLoaderFuncName(),
+    spec.FuncNamePrefix(),
+    func.name)
+end
+
+function src.WriteBlockBeginCoreLoader(hFile, spec, options)
+  hFile:write("static void Load_Version()\n")
+  hFile:write("{\n")
+  hFile:inc()
+end
+
+function src.WriteBlockEndCoreLoader(hFile, version, spec, options)
+  hFile:dec()
+  hFile:write("}\n")
+end
+
+local function WriteHelpers(hFile, specData, spec, options)
+  common.WriteCClearExtensionVarsFunc(hFile, specData, spec, options,
+    GetExtensionVarName, "0")
+  hFile:write("\n")
+  hFile:write("typedef void (*PFN_LOADFUNCPOINTERS)();\n")
+	hFile:fmt("typedef struct %s_s\n", 
+		GetMappingTableStructName(spec, options))
+	hFile:write("{\n")
+	hFile:inc()
+	hFile:writeblock [[
+char *extensionName;
+int *extensionVariable;
+PFN_LOADFUNCPOINTERS LoadExtension;
+]]
+	hFile:dec()
+	hFile:fmt("} %s;\n", GetMappingTableStructName(spec, options))
+	hFile:write "\n"
+	
+	hFile:write "\n" --From last line of previous code.
+	hFile:fmt("static %s %s[] = {\n",
+	  GetMappingTableStructName(spec, options),
+	  GetMappingTableVarName())
+	hFile:inc()
+	for _, extName in ipairs(options.extensions) do
+	  if(#specData.extdefs[extName].funcs > 0) then
+		hFile:fmt('{"%s", &%s, %s},\n',
+		  spec.ExtNamePrefix() .. extName,
+		  GetExtensionVarName(extName, spec, options),
+		  GetExtFuncLoaderName(extName, spec, options))
+	  else
+		hFile:fmt('{"%s", &%s, NULL},\n',
+		  spec.ExtNamePrefix() .. extName,
+		  GetExtensionVarName(extName, spec, options))
+	  end
+	end
+	hFile:dec()
+	hFile:write("};\n")
+	hFile:write("\n")
+	hFile:fmt("static int g_extensionMapSize = %i;\n", #options.extensions);	
+	hFile:write "\n"
+
+	common.WriteCFindExtEntryFunc(hFile, specData, spec, options,
+		GetMappingTableStructName(spec, options),
+		GetMappingTableVarName())
+		
+	hFile:write("\n")
+
+	hFile:fmtblock([[
+static void LoadExtByName(const char *extensionName)
+{
+	%s *entry = NULL;
+	entry = FindExtEntry(extensionName);
+	if(entry)
+	{
+		if(entry->LoadExtension)
+		{
+			int numFailed = entry->LoadExtension();
+			if(numFailed == 0)
+			{
+				*(entry->extensionVariable) = 1;
+			}
+			else
+			{
+				*(entry->extensionVariable) = 1;
+			}
+		}
+		else
+		{
+			*(entry->extensionVariable) = 1;
+		}
+	}
+}
+]], GetMappingTableStructName(spec, options))
+
+	hFile:write("\n")
+	local indexed = spec.GetIndexedExtStringFunc(options);
+	if(not indexed) then
+	  common.WriteProcessExtsFromStringFunc(hFile, "LoadExtByName(%s)")
+	else
+	  --New style
+	end
+
+	return indexed
+end
+
+function src.WriteMainLoaderFunc(hFile, specData, spec, options)
+  WriteHelpers(hFile, specData, spec, options)
+  hFile:write("\n")
+
+  hFile:fmt("int %s(%s)\n",
+    GetMainLoaderFuncName(spec, options),
+    spec.GetLoaderParams())
+  hFile:write("{\n")
+  hFile:inc()
+  hFile:dec()
+  hFile:write("}\n")
+end
+
+
+
+
+local function Create()
+    return util.DeepCopyTable(my_style), struct
+end
+
+return { Create = Create }

modules/StructNoloadCpp.lua

-
-local struct = require "Structure"
-local common = require "CommonStruct"
-
-
-local sys_functions =
-{ type="block", name="System(hFile, spec, options)",
-	{type="write", name="SetupFunction(hFile, specData, spec, options)", },
-	{type="blank", cond="version-iter" },
-	{type="write", name="VersionFunctions(hFile, specData, spec, options)", cond="version-iter"},
-}
-
-local my_struct =
-{
-	{ type="file", style="hdr", name="GetFilename(basename, spec, options)",
-		{ type="write", name="FilePreamble", optional=true} ,
-		{ type="block", name="IncludeGuard",
-			{ type="blank"},
-			{ type="write", name="Guards(hFile, spec, options)",},
-			{ type="blank"},
-			{ type="write", name="Typedefs(hFile, specData, spec, options)",},
-			{ type="blank"},
-			
-			{ type="block", name="MainNamespace(hFile, spec, options)",
-				{ type="write", name="LargeHeader(hFile, value, options)", value="Extension Variables", },
-				{ type="block", name="ExtVariables(hFile, spec, options)",
-					common.Extensions(),
-				},
-				{ type="blank"},
-				{ type="block", name="Enumerators(hFile, spec, options)",
-					common.Enumerators(),
-				},
-				{ type="blank"},
-				common.Functions(),
-				sys_functions,
-			},
-		},
-	},
-