Commits

Jason McKesson  committed 5f393a1

Tested WGL and GL code generation.

  • Participants
  • Parent commits 9865828

Comments (0)

Files changed (5)

 local opts = require "GetOptions"
 local gen = require "Generate"
 
-local options = opts.GetOptions {
+local options = opts.GetOptions(arg)
+
+--[[{
 	"test",
 	"-spec=gl",
 	"-extfile=exts.txt",
 	"-version=3.3",
 	"-profile=core",
-}
+}]]
 
 gen.Generate(options)
 

File modules/CommonStyle.lua

 	return "IntGetProcAddress"
 end
 
-function common.GetGLVersionQueryFunc()
-	return [[
-static void GetGLVersion(int *pOutMajor, int *pOutMinor, const char *strVersion)
-{
-	const char *strDotPos = NULL;
-	int iLength = 0;
-	char strWorkBuff[10];
-	*pOutMinor = 0;
-	*pOutMajor = 0;
-
-	strDotPos = strchr(strVersion, '.');
-	if(!strDotPos)
-		return;
-
-	iLength = (int)((ptrdiff_t)strDotPos - (ptrdiff_t)strVersion);
-	strncpy(strWorkBuff, strVersion, iLength);
-	strWorkBuff[iLength] = '\0';
-
-	*pOutMajor = atoi(strWorkBuff);
-	strDotPos = strchr(strVersion + iLength + 1, ' ');
-	if(!strDotPos)
-	{
-		//No extra data. Take the whole rest of the string.
-		strcpy(strWorkBuff, strVersion + iLength + 1);
-	}
-	else
-	{
-		//Copy only up until the space.
-		int iLengthMinor = (int)((ptrdiff_t)strDotPos - (ptrdiff_t)strVersion);
-		iLengthMinor = iLengthMinor - (iLength + 1);
-		strncpy(strWorkBuff, strVersion + iLength + 1, iLengthMinor);
-		strWorkBuff[iLengthMinor] = '\0';
-	}
-
-	*pOutMinor = atoi(strWorkBuff);
-}
-]]
-end
 
 --You give it a function that takes a const char*.
 function common.GetProcessExtsFromStringFunc(funcToCall)

File modules/Generate.lua

 							options, spec, style, specData)
 					end
 				end
-			end
-
-			--Write the actual core functions, if any.
-			local funcList = GetCoreFunctions(specData.coredefs[version],
-				specData, spec, options, version)
 				
-			if(#funcList > 0) then
-				WriteCoreFuncLoaderFromList(hFile,
-					funcList, options, spec, style, specData)
+				--Write the actual core functions, if any.
+				local funcList = GetCoreFunctions(specData.coredefs[version],
+					specData, spec, options, version)
+					
+				if(#funcList > 0) then
+					WriteCoreFuncLoaderFromList(hFile,
+						funcList, options, spec, style, specData)
+				end
 			end
 		end
 		source.WriteEndCoreLoaderBlock(hFile, options.version, spec, options)

File modules/Specs.lua

 
 --Extension name prefix.
 function gl_spec.ExtNamePrefix() return "GL_" end
-function wgl_spec.ExtNamePrefix() return "WGL" end
-function glx_spec.ExtNamePrefix() return "GLX" end
+function wgl_spec.ExtNamePrefix() return "WGL_" end
+function glx_spec.ExtNamePrefix() return "GLX_" end
 
 --Enumerator name prefix. This is for defining "proper" GL enumerators.
 function gl_spec.EnumNamePrefix() return "GL_" end
-function wgl_spec.EnumNamePrefix() return "WGL" end
-function glx_spec.EnumNamePrefix() return "GLX" end
+function wgl_spec.EnumNamePrefix() return "WGL_" end
+function glx_spec.EnumNamePrefix() return "GLX_" end
 
 --Function name prefix. This is for defining "proper" GL function names.
 function gl_spec.FuncNamePrefix() return "gl" end
 
 --Parameters given to the loader. No (), just the internals.
 function gl_spec.GetLoaderParams() return "" end
-function wgl_spec.GetLoaderParams() return "HDC *hdc" end
+function wgl_spec.GetLoaderParams() return "HDC hdc" end
 function glx_spec.GetLoaderParams() return "Display *display, int screen" end
 
 --CodeGen function pointer type. For APIFUNC and so forth.

File modules/StylePointerC.lua

 end
 
 function my_style.header.WriteEnumDecl(hFile, enum, enumTable, spec, options)
-	hFile:fmt("#define %s = %s\n",
+	hFile:fmt("#define %s %s\n",
 		GetEnumName(enum, spec, options),
 		common.ResolveEnumValue(enum, enumTable))
 end
 end
 
 function my_style.source.WriteIncludes(hFile, spec, options)
-	hFile:write("#include <stdlib.h>\n")
-	hFile:write("#include <string.h>\n")
+	hFile:writeblock([[
+#include <stdlib.h>
+#include <string.h>
+#ifdef WIN32
+#define strcasecmp(lhs, rhs) _stricmp((lhs), (rhs))
+#endif
+]])
+	hFile:write("\n")
+	
 end
 
 function my_style.source.WriteBeginDef(hFile, spec, options) end
 
 function my_style.source.WriteUtilityDefs(hFile, specData, spec, options)
 	--Write the struct for the mapping table.
-	hFile:write("typedef int (*PFN_LOADEXTENSION)()\n")
+	hFile:write("typedef int (*PFN_LOADEXTENSION)();\n")
 	hFile:fmt("typedef struct %s%sStrToExtMap_s\n",
 		options.prefix, spec.DeclPrefix())
 	hFile:write("{\n")
 	hFile:write("int *extensionVariable;\n")
 	hFile:write("PFN_LOADEXTENSION LoadExtension;\n")
 	hFile:dec()
-	hFile:fmt("} %s\n", GetMapTableStructName(spec, options))
+	hFile:fmt("} %s;\n", GetMapTableStructName(spec, options))
 	hFile:write "\n"
 	
 	--Write the mapping table itself.
 		end
 	end
 	hFile:dec()
-	hFile:write("}\n")
+	hFile:write("};\n")
 	hFile:write "\n"
 	
 	hFile:fmt("static int g_extensionMapSize = %i;\n", #options.extensions);
 		GetMapTableStructName(spec, options))
 	hFile:write("{\n")
 	hFile:inc()
-	hFile:write("int loop;")
-	hFile:fmt("%s *currLoc = %s",
+	hFile:write("int loop;\n")
+	hFile:fmt("%s *currLoc = %s;\n",
 		GetMapTableStructName(spec, options),
 		GetMapTableVarName())
 	hFile:writeblock([[
 for(loop = 0; loop < g_extensionMapSize; ++loop, ++currLoc)
 {
 	if(strcasecmp(extensionName, currLoc->extensionName) == 0)
-		return pCurrLoc;
+		return currLoc;
 }
 
 return NULL;
 	hFile:write("}\n")
 	hFile:write "\n"
 	
-	--Write a function to get the version number from a string.
-	if(options.version) then
-		hFile:writeblock(common.GetGLVersionQueryFunc())
-		hFile:write "\n"
-	end
-
 	--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([[
 		const char *strExtensionName = (const char *)]] ..
 		GetFuncPtrName(indexed[3], spec, options) ..
 		[[(]] .. GetEnumName(indexed[4], spec, options) .. [[, iLoop);
-		LoadExtByName(strExtensionName)
+		LoadExtByName(strExtensionName);
 	}
 }
 ]])
-	elseif(options.version) then
+	else
 		hFile:writeblock(common.GetProcessExtsFromStringFunc("LoadExtByName"))
 	end
 	
 		spec.GetLoaderParams())
 	hFile:write("{\n")
 	hFile:inc()
-	
-	hFile:writeblock([[
-int numFailed = 0;
-ClearExtensionVars();
-	
-]])
+
+	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
 		end
 		
 		hFile:write "\n"
-		hFile:fmt("ProcExtFromExtString((const char *)%s(%s));\n",
+		hFile:fmt("ProcExtsFromExtString((const char *)%s(%s));\n",
 			extListName,
 			spec.GetExtStringParamList(EnumResolve))
 	end
 	
-	hFile:fmt("numFailed = %s();\n",
-		GetCoreLoaderFuncName(options.version, spec, options))
-	hFile:write "\n"
-	
-	hFile:fmtblock([[
+	if(options.version) then
+		hFile:fmt("numFailed = %s();\n",
+			GetCoreLoaderFuncName(options.version, 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))
+			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")
 {
 	if(g_major_version == 0)
 		GetGLVersion();
-	return g_major_version
+	return g_major_version;
 }
 ]])
 	hFile:write "\n"
 {
 	if(g_major_version == 0) //Yes, check the major version to get the minor one.
 		GetGLVersion();
-	return g_minor_version
+	return g_minor_version;
 }
 ]])
 	hFile:write "\n"