Navigation menu

WoW:API getn: Difference between revisions

Jump to navigation Jump to search
355 bytes added ,  15 August 2023
m
Move page script moved page API getn to WoW:API getn without leaving a redirect
No edit summary
m (Move page script moved page API getn to WoW:API getn without leaving a redirect)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{:Lua/Libshortcut|getn|table.getn}}
{{ambox
|border=red
|type='''Warning: This article discusses use of a deprecated function.'''
|style=margin-right: 10em
|info=*This function should no longer be used in Lua 5.1 and may be removed in the future.
*Use of it will result in potential future incompatibility.}}{{luaapi}}
From [http://lua-users.org/wiki/TableLibraryTutorial TableLibraryTutorial] of lua-users.org.
From [http://lua-users.org/wiki/TableLibraryTutorial TableLibraryTutorial] of lua-users.org.


  table.getn(table)
  table.getn(table)
getn(table)


{{ambox
|border=red
|type='''Warning: This article discusses use of a deprecated function.'''
|info=*This function should no longer be used in Lua 5.1 and may be removed in the future.
*Use of it will result in potential future incompatibility.}}


This is used to determine the size of a table. The size of a table is discussed at the top of this page.
This is used to determine the size of a table. The size of a table is discussed at the top of this page.
Line 47: Line 48:
  The length of a table t is defined to be any integer index such that t[n] is not nil and t[n+1] is nil.
  The length of a table t is defined to be any integer index such that t[n] is not nil and t[n+1] is nil.
In other words, be careful with this operator if you are using tables with holes in them. If your table has all its values between [1] and [n] for some n, with no nils in that range, the # operator will return n. Otherwise its result may be unclear.
In other words, be careful with this operator if you are using tables with holes in them. If your table has all its values between [1] and [n] for some n, with no nils in that range, the # operator will return n. Otherwise its result may be unclear.
Note:
The reason the returned values are different is because the tables are different. For indexed tables, or tables that start with index values like 1,2,3 for keys, use tinsert and tremove to change the contents. What # returns is actually correct, setting the index value to nil does not change the size of the table for index keys, tremove would.


== See Also ==
== See Also ==
* [[tcount]]
* [[tcount]]
{{LUA}}
Anonymous user