Skip to content

Instantly share code, notes, and snippets.

@Bradshaw
Forked from hugodes/gist:6489552
Last active December 22, 2015 14:59
Show Gist options
  • Save Bradshaw/6489560 to your computer and use it in GitHub Desktop.
Save Bradshaw/6489560 to your computer and use it in GitHub Desktop.
local class = {} -- Since you're returning this at the end, I assume you want it local to the file
-- Problem is, you can only have this file run once, or otherwise remove the "local" but then you're redefining the values each time you call the file (with an ugly dofile no less)
local health -- This is local to the whole file
function class.getHealth() -- Renamed to avoid confusing, replaced ob:meth() with ob.meth() syntax because that's not how closures are used
return health -- This returns the value, so health is closed to the file, but can be "read" with this function
end
return class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment