G.SortedPairs

From GMod Wiki

Jump to: navigation, search
Function
Syntax SortedPairs( Table table, Boolean reverse )
Where is this used?
Description:
Generates an iterator for traversing tables in key order
Returns: Function iterator, Table state
Part of Library: Global Functions
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=G.SortedPairs]G.SortedPairs [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionIterate through a table in order of its keys
Used onNewerShared.png
Code
local TestTable = {b=2,c=1,a=3}
for k,v in SortedPairs(TestTable) do
  print(k,v)
end
Outputa 3

b 2

c 1
DescriptionIterate through a table in reverse order of its keys
Used onNewerShared.png
Code
local TestTable = {b=2,c=1,a=3}
for k,v in SortedPairs(TestTable, true) do
  print(k,v)
end
Outputc 1

b 2

a 3

Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox