-- -- Sample use of enumerators -- -- Gets an instance word = luacom.GetObject("Word.Application") -- Gets an enumerator for the Documents collection docs_enum = luacom.GetEnumerator(word.Documents) -- Prints the names of all open documents doc = docs_enum:Next() while doc do print(doc.Name) doc = docs_enum:Next() end
The Extended Lua API method pairs allows the traversal of the enumeration using Lua's for statement. The sample above can be rewritten this way:
-- -- Sample use of enumerators -- -- Gets an instance word = luacom.GetObject("Word.Application") -- Prints the names of all open documents for index, doc in luacomE.pairs(word.Documents) do print(doc.Name) end