Jason McKesson avatar Jason McKesson committed 087cb87

Fixes to NoLoad, when not using the extension functions.

Comments (0)

Files changed (3)

modules/CommonStruct.lua

 
 --Iterates over all requested extensions
 --Calls Extension(hFile, extName, spec, options)
-common.extensions = 
+local extensions = 
 { type="group",
 	{ type="ext-iter",
 		{ type="write", name="Extension(hFile, extName, spec, options)", },
 	},
 }
 
+function common.Extensions() return extensions end
+
 --Iterates over every enumerator, in order:
 -- Requested extension enums.
 -- For each version:
 --  Core enumerators from version X
 -- Calls Enumerator(hFile, enum, enumTable, spec, options, enumSeen)
 -- Optional small headers
-common.enumerators =
+local enumerators =
 { type="group",
 { type="enum-seen",
 	{ type="ext-iter",
 },
 }
 
+function common.Enumerators() return enumerators end
+
 --Iterates over each function, in order:
 -- Requested extension functions.
 -- For each version:
 --  Core functions from version X
 -- Calls Function(hFile, func, typemap, spec, options, funcSeen)
 -- Optional small headers.
-common.functions =
-{ type="group",
-{ type="func-seen",
-	{ type="ext-iter",
-		{type="func-iter",
-			{ type="write", name="SmallHeader(hFile, value, options)", value="Extension: %extName", first=true, optional=true},
-			{ type="write", name="Function(hFile, func, typemap, spec, options, funcSeen)", },
-			{ type="blank", last=true },
-		},
-	},
-	{ type="version-iter",
-		{ type="core-ext-cull-iter",
+-- Can provide an optional ending table, that will be placed within
+-- the "func-seen" block.
+function common.Functions(ending)
+	ending = ending or { type="group" }
+	return
+	{ type="func-seen",
+		{ type="ext-iter",
 			{type="func-iter",
 				{ type="write", name="SmallHeader(hFile, value, options)", value="Extension: %extName", first=true, optional=true},
 				{ type="write", name="Function(hFile, func, typemap, spec, options, funcSeen)", },
 				{ type="blank", last=true },
 			},
 		},
-		{type="func-iter",
-			{ type="write", name="SmallHeader(hFile, value, options)", value="Extension: %version", first=true, optional=true},
-			{ type="write", name="Function(hFile, func, typemap, spec, options, funcSeen)", },
-			{ type="blank", last=true },
+		{ type="version-iter",
+			{ type="core-ext-cull-iter",
+				{type="func-iter",
+					{ type="write", name="SmallHeader(hFile, value, options)", value="Extension: %extName", first=true, optional=true},
+					{ type="write", name="Function(hFile, func, typemap, spec, options, funcSeen)", },
+					{ type="blank", last=true },
+				},
+			},
+			{type="func-iter",
+				{ type="write", name="SmallHeader(hFile, value, options)", value="Extension: %version", first=true, optional=true},
+				{ type="write", name="Function(hFile, func, typemap, spec, options, funcSeen)", },
+				{ type="blank", last=true },
+			},
 		},
-	},
-},
-}
+		ending,
+	}
+end
 
 return common

modules/StructNoloadCpp.lua

 
 local struct = require "Structure"
+local common = require "CommonStruct"
 
 
-local ext_variables = 
-{ type="group",
-	{ type="write", name="LargeHeader(hFile, value, options)", value="Extension Variables", },
-	{ type="block", name="ExtVariables(hFile, spec, options)",
-		{ type="ext-iter",
-			{ type="write", name="ExtVariable(hFile, extName, spec, options)", },
-		},
-	},
-}
-
-local func_variables =
-{ type="group",
-{ type="func-seen",
-	{ type="ext-iter",
-		{type="func-iter",
-			{ type="write", name="SmallHeader(hFile, value, options)", value="Extension: %extName", first=true},
-			{ type="write", name="Function(hFile, func, typemap, spec, options, funcSeen)", },
-			{ type="blank", last=true },
-		},
-	},
-	{ type="version-iter",
-		{ type="core-ext-cull-iter",
-			{type="func-iter",
-				{ type="write", name="SmallHeader(hFile, value, options)", value="Extension: %extName", first=true},
-				{ type="write", name="Function(hFile, func, typemap, spec, options, funcSeen)", },
-				{ type="blank", last=true },
-			},
-		},
-		{type="func-iter",
-			{ type="write", name="SmallHeader(hFile, value, options)", value="Extension: %version", first=true},
-			{ type="write", name="Function(hFile, func, typemap, spec, options, funcSeen)", },
-			{ type="blank", last=true },
-		},
-	},
-},
-}
-
 local sys_functions =
 { type="block", name="System(hFile, spec, options)",
 	{type="write", name="SetupFunction(hFile, specData, spec, options)", },
 	{type="write", name="VersionFunctions(hFile, specData, spec, options)", cond="version-iter"},
 }
 
-
 local my_struct =
 {
 	{ type="file", style="hdr", name="GetFilename(basename, spec, options)",
 			{ type="blank"},
 			
 			{ type="block", name="MainNamespace(hFile, spec, options)",
-				ext_variables,
+				{ 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)",
-					{ type="enum-seen",
-						{ type="ext-iter",
-							{type="enum-iter",
-								{ type="write", name="SmallHeader(hFile, value, options)", value="Extension: %extName", first=true},
-								{ type="write", name="Enumerator(hFile, enum, enumTable, spec, options, enumSeen)", },
-								{ type="blank", last=true },
-							},
-						},
-						{ type="version-iter",
-							{ type="core-ext-cull-iter",
-								{type="enum-iter",
-									{ type="write", name="SmallHeader(hFile, value, options)", value="Core Extension: %extName", first=true},
-									{ type="write", name="Enumerator(hFile, enum, enumTable, spec, options, enumSeen)", },
-									{ type="blank", last=true },
-								},
-							},
-							{type="enum-iter",
-								{ type="write", name="SmallHeader(hFile, value, options)", value="Version: %version", first=true},
-								{ type="write", name="Enumerator(hFile, enum, enumTable, spec, options, enumSeen)", },
-								{ type="blank", last=true },
-							},
-						},
-					},
+					common.Enumerators(),
 				},
 				{ type="blank"},
-				func_variables,
+				common.Functions(),
 				sys_functions,
 			},
 		},
 		{ type="write", name="LoaderFunc(hFile, spec, options)", },
 		{ type="blank"},
 		{ type="block", name="MainNamespace(hFile, spec, options)",
-			ext_variables,
+			{ type="block", name="ExtVariables(hFile, spec, options)",
+				common.Extensions(),
+			},
 			{ type="blank"},
 			{ type="group", style="typedefs",
-				func_variables,
+				common.Functions(),
 			},
 			{ type="blank"},
 			{ type="group", style="defs",
-				func_variables,
+				common.Functions(),
 			},
 			{ type="blank"},
 			{ type="group", style="switch",
-				func_variables,
+				common.Functions(),
 			},
 			{ type="blank"},
 			{ type="block", name="Struct(hFile, spec, options)", style="init",
-				func_variables,
+				common.Functions(),
 			},
 			{ type="blank"},
 			sys_functions,

modules/StyleNoloadCpp.lua

 	common.WritePassthruData(hFile, specData.funcData.passthru)
 end
 
-function hdr.WriteExtVariable(hFile, extName, spec, options)
+function hdr.WriteExtension(hFile, extName, spec, options)
 	hFile:fmt("extern bool var_%s;\n", extName)
 end
 
 	hFile:writeblock(spec.GetLoaderFunc())
 end
 
-function src.WriteExtVariable(hFile, extName, spec, options)
+function src.WriteExtension(hFile, extName, spec, options)
 	hFile:fmt("bool var_%s = false;\n", extName)
 end
 
 	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",
-			spec.GetExtStringFuncName(),
+			funcName,
 			spec.GetExtStringParamList(
 				function (name) return spec.FuncNamePrefix() .. "::" .. name end))
 	end
 	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
 
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.