Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
setDefault in lua.
function setDefault( t, d )
local mt = {__index = function () return d end}
setmetatable(t, mt)
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