Skip to content

Instantly share code, notes, and snippets.

@fpersson
Created September 9, 2011 20:52
Show Gist options
  • Save fpersson/1207300 to your computer and use it in GitHub Desktop.
Save fpersson/1207300 to your computer and use it in GitHub Desktop.
lua namespace and class
namespace = {}
namespace.class = {}
namespace.class.__index=namespace.class
function namespace.class:create(name)
print("Create a class")
local l = {}
setmetatable(l, namespace.class)
l.m_name = name
print(l.m_name)
return l
end
function namespace.class:getName()
print(self.l_name) --prints nill
return self.l_name --return nill
end
c = namespace.class:create("Hello, world")
print( c:getName())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment