Created
          May 10, 2014 18:42 
        
      - 
      
- 
        Save katlogic/f91e67b61cd3966ad67b to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | -- example class Foo | |
| local Foo = { | |
| attr1 = 1, | |
| attr2 = 2, | |
| } | |
| Foo.__index = Foo | |
| function Foo:getattr1() | |
| return self.attr1 | |
| end | |
| function Foo:getattr2() | |
| return self.attr1 | |
| end | |
| -- example class Bar which inherits from Foo | |
| local Bar = { | |
| attr3 = 3, | |
| attr1 = 4, | |
| } | |
| for k,v in pairs(Foo) do Bar[k] = v end | |
| Bar.__index = Bar | |
| function Bar:getattr3() | |
| return self.attr3 | |
| end | |
| -- usage | |
| inst = setmetatable({attr3=1337}, Bar) | |
| print(inst:getattr3(3)) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment