WoW:API wipe: Difference between revisions
Jump to navigation
Jump to search
m (bolded title of article; Cleanup) |
(→Notes: naming a variable 'table' was just brilliant.) |
||
| Line 10: | Line 10: | ||
== Returns == | == Returns == | ||
:; table : Table - The empty table. | :; table : Table - The empty table. | ||
== Notes == | |||
The difference between ''wipe(table)'' and ''table={}'' is that ''wipe'' removes the contents of the table, but retains the variable's internal pointer. | |||
data={1,2,3} | |||
copy=data | |||
assert(copy==data) -- they're the same object | |||
copy={} | |||
assert(copy~=data) -- they're no longer the same: | |||
assert(#copy==0) -- the copy is expectedly empty, | |||
assert(#data==3) -- but the original table remains. | |||
copy2=data | |||
assert(copy2==data) -- they're the same object | |||
wipe(copy2) | |||
assert(copy2==data) -- they're still the same object: | |||
assert(#copy2==0) -- the copy is expectedly empty, | |||
assert(#data==0) -- and so is the original table. | |||
== Example == | == Example == | ||
Revision as of 18:29, 5 September 2009
Wipes a table of all contents.
table = table.wipe(table)
Arguments
- table
- Table - The table to be cleared.
Returns
- table
- Table - The empty table.
Notes
The difference between wipe(table) and table={} is that wipe removes the contents of the table, but retains the variable's internal pointer.
data={1,2,3}
copy=data
assert(copy==data) -- they're the same object
copy={}
assert(copy~=data) -- they're no longer the same:
assert(#copy==0) -- the copy is expectedly empty,
assert(#data==3) -- but the original table remains.
copy2=data
assert(copy2==data) -- they're the same object
wipe(copy2)
assert(copy2==data) -- they're still the same object:
assert(#copy2==0) -- the copy is expectedly empty,
assert(#data==0) -- and so is the original table.
Example
local tab = {}
tab.Hello = "Goodbye"
print(tab.Hello) -- print "Goodbye"
tab = table.wipe(tab)
print(tab.Hello) -- print nil