Skip to content

Salvakiya/SClass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

SClass

Small Class Implementation

This readme is incomplete

Features

class() returns the class twice so you can easily make a local alias for it. Given the case of local foo, bar = class() foo is the same as bar

Usage

local class = require('sclass')

local foo = class()

function foo:init()
  print('hello!')
end

local bar = class(foo)

local baz = bar() -- hello!

the function returned from sclass will return the same value twice... this allows you to do the following:

local class = require('sclass')

local Animal = class()

-- Single inheritance
local Dog, self = class(Animal) do
  --self means the same as Dog here
  function self:init(name)
    --shadowed self means instance here
    self.name = name
  end
  
  function self:bark()
    print('woof')
  end
end

local mydog = Dog()
mydog:bark() -- woof

About

Small Class Implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages