WoW:API wipe: Difference between revisions

188 bytes added ,  15 August 2023
m
Move page script moved page API wipe to WoW:API wipe without leaving a redirect
(→‎Notes: naming a variable 'table' was just brilliant.)
m (Move page script moved page API wipe to WoW:API wipe without leaving a redirect)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{:Lua/Libshortcut|wipe|table.wipe}}
{{wowapi}}
 
 
'''Wipes''' a table of all contents.
'''Wipes''' a table of all contents.
  table = table.wipe(table)
  table = table.wipe(table)
wipe(table)


== Arguments ==
== Arguments ==
:; table : Table - The table to be cleared.
; table : Table - The table to be cleared.


== Returns ==
== Returns ==
:; table : Table - The empty table.
; table : Table - The empty table.
 
== Example ==
local tab = {}
tab.Hello = "Goodbye"
print(tab.Hello) -- print "Goodbye"
tab = table.wipe(tab)
print(tab.Hello) -- print nil


== Notes ==
== Notes ==
The difference between ''wipe(table)'' and ''table={}'' is that ''wipe'' removes the contents of the table, but retains the variable's internal pointer.
* While this function returns an empty table, it is not necessary to assign it to a variable.
 
local t = {"stuff"}
t = wipe(t)
print(#t) -- prints 0
local t = {"stuff"}
wipe(t)
print(#t) -- also prints 0
 
* 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}
  data={1,2,3}
Line 29: Line 45:
  assert(#copy2==0)    -- the copy is expectedly empty,
  assert(#copy2==0)    -- the copy is expectedly empty,
  assert(#data==0)    -- and so is the original table.
  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
{{LUA}}
Anonymous user