WoW:USERAPI Memorizing table: Difference between revisions

m
Move page script moved page USERAPI Memorizing table to WoW:USERAPI Memorizing table without leaving a redirect
m (Typo fixed to a more precise definition)
m (Move page script moved page USERAPI Memorizing table to WoW:USERAPI Memorizing table without leaving a redirect)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{userfunc}}
{{userfunc}}
__NOTOC__
A '''memoizing table''' is a normal table with a metatable designed to find missing values and save them.  The mechanics are transparent to the caller, it thinks it's just doing a normal lookup.
A '''memoizing table''' is a normal table with a metatable designed to find missing values and save them.  The mechanics are transparent to the caller, it thinks it's just doing a normal lookup.


Line 7: Line 5:


== Code ==
== Code ==
For this example we will cache the name results from a [[API GetItemInfo|GetItemInfo]] call.
For this example, we will cache the name results from a [[API GetItemInfo|GetItemInfo]] call.


  local names = setmetatable({}, {
  local names = setmetatable({}, {
Line 16: Line 14:
  return name
  return name
  end,
  end,
  })  
  })


== How it works ==
== How it works ==
Anonymous user