Skip to content

Instantly share code, notes, and snippets.

@BenMcLean
Created November 9, 2017 20:27
Show Gist options
  • Save BenMcLean/2e97497a96552546b86a5b08fe51203a to your computer and use it in GitHub Desktop.
Save BenMcLean/2e97497a96552546b86a5b08fe51203a to your computer and use it in GitHub Desktop.
"Assign by reference"-like behavior in Lua
ref=(function(obj,key)
return (function(...)
local p={...}
if select('#',...)==0 then
return obj[key]
else
obj[key]=p[1]
end
end)
end)
ghost = {boo = true}
boo = ref(ghost,'boo')
boo(nil)
print(boo())
print(ghost.boo)
print(boo())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment