gldatabase / glLoadGen / modules / StyleEnumDB.lua

local util = require "util"
local tab = require "TabbedFile"
local struct = require "Structure"
local common = require "CommonStyle"

local function CollectEnumParams(func, typemap)
	local enumParamList = nil

	for i, param in ipairs(func.params) do
		local paramType = typemap[param.type] or param.type
		if(paramType == "GLenum") then
			enumParamList = enumParamList or {}
			table.insert(enumParamList, param.name)
		end
	end
	
	return enumParamList
end

local my_style = {}

function my_style.StateMakeTable()
	return {}
end

function my_style.CollectEnumParams(func, typemap, functbl_)
	local enumParamList = CollectEnumParams(func, typemap)

	if(enumParamList) then
		table.insert(functbl_, {name=func.name, list=enumParamList})
	end
end

local function WriteTableToFile(basename, filename, functbl_)
	local hFile
	for _, funcEntry in ipairs(functbl_) do
		if(not hFile) then
			local base, dir = util.ParsePath(basename)
			util.EnsurePath(dir)
			local pathname = dir .. filename
			hFile = io.open(pathname, "w")
			if(not hFile) then
				print("Could not write to file " .. pathname)
				return
			end
			
			hFile = tab.TabbedFile(hFile, "tab")
			hFile:write("return {\n")
		end
		
		hFile:fmt("['%s'] = {\n", funcEntry.name)
		hFile:inc()
		for _, enumParamName in ipairs(funcEntry.list) do
			hFile:fmt("['%s'] = {},\n", enumParamName)
		end
		hFile:dec()
		hFile:fmt("},\n\n")
		
	end
	
	if(hFile) then
		hFile:write("}")
		hFile:close()
	end
end

function my_style.WriteExtension(basename, extName, functbl_)
	local filename = extName .. ".lua"
	WriteTableToFile(basename, filename, functbl_)
end

function my_style.WriteVersion(basename, version, functbl_)
	local filename = "Version_" .. version:gsub("%.", "_") .. ".lua"
	WriteTableToFile(basename, filename, functbl_)
end

local my_struct = 
{
{ type="func-seen",
	{ type="ext-iter",
		{ type="context", key="functbl_", name="MakeTable()",
			{ type="func-iter",
				{ type="call", name="CollectEnumParams(func, typemap, functbl_)", },
			},
			
			{ type="call", name="WriteExtension(basename, extName, functbl_)", },
		},
	},
	{ type="version-iter",
		{ type="context", key="functbl_", name="MakeTable()",
			{ type="func-iter",
				{ type="call", name="CollectEnumParams(func, typemap, functbl_)", },
			},

			{ type="call", name="WriteVersion(basename, version, functbl_)", },
		},
	},
	ending,
}
}

my_struct = struct.BuildStructure(my_struct)

local function Create()
    return util.DeepCopyTable(my_style), my_struct
end

return { Create = Create }
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.