Skip to content

Instantly share code, notes, and snippets.

@abaez
Created January 28, 2014 19:07
Show Gist options
  • Save abaez/8674051 to your computer and use it in GitHub Desktop.
Save abaez/8674051 to your computer and use it in GitHub Desktop.
memoize function example
-- example of Memoize function with color generation. Saves speed!
-- saves colors being used, and appends with new colors.
local results = {}
setmetatable(results, {__mode = "v"})
function create_RGB(r,g,b)
-- defining key by the colors used
local key = string.format("%d-%d-%d", r,g,b)
local color = results[key]
if color == nil then
color = {red = r, green = g, blue = b}
results[key] = color
end
return color
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment