Skip to content

Instantly share code, notes, and snippets.

@prafulliu
Created December 18, 2012 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prafulliu/4325776 to your computer and use it in GitHub Desktop.
Save prafulliu/4325776 to your computer and use it in GitHub Desktop.
setDefault in lua.
function setDefault( t, d )
local mt = {__index = function () return d end}
setmetatable(t, mt)
end
tab = {x=10, y=20}
print(tab.x, tab.z)
setDefault(tab, 0)
print(tab.x, tab.z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment