Skip to content

Instantly share code, notes, and snippets.

@tekkub
Created August 8, 2010 03:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tekkub/513561 to your computer and use it in GitHub Desktop.
Save tekkub/513561 to your computer and use it in GitHub Desktop.
local f = GetInventoryCount
local memo = setmetatable({}, {
__index = function(t,i)
-- Get the value and stash it for later
local v = f(i)
t[i] = v
return v
end
})
-- This calls the function
local x = memo[123]
-- This pulls the value from the table
-- thus saving a function call
local y = memo[123]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment