All pastes #102973 Raw Edit

Miscellany

public text v1 · immutable
#102973 ·published 2006-07-28 00:39 UTC
rendered paste body
-- myaddon:
function Squishy:Test()
	-- the following examples work
	local unitid = self.rosterlib:GetUnitIDFromName("Nostril")
	print(unitid)
	local u = self.rosterlib:GetUnitObjectFromName("Nostril")
	print(u.class)

	-- this one doesnt:
	for u in self.rosterlib:IterateRoster() do
		print(u.class)
	end
end


-- library:
function RosterLib:GetUnitIDFromName(name)
	if self.roster[name] then
		return self.roster[name].unitid
	else
		return nil
	end
end

function RosterLib:GetUnitObjectFromName(name)
	if self.roster[name] then
		return self.roster[name]
	else
		return nil
	end
end

function RosterLib:IterateRoster()
	local t = self.roster
	local i = 0
	local n = table.getn(t)
	return function()
		i = i + 1
		if i <= n then return t[t[i]] end
	end
end