Skip to content

mc-cc-scripts/ccClass-lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ccClass-lib

Simulates Class Instances for Lua

Returns only the class, not in instance of it!

Init by classname(), which returns an Instance of the class!

Exampe

require 'class'

-- definition of classes, "a" beeing the required self reference
Animal = class(function(a,name)
   a.name = name
end)

function Animal:__tostring()
  return self.name..': '..self:speak()
end

Cat = class(Animal, function(c,name,breed)
         Animal.init(c,name)  -- must init base!
         c.breed = breed
      end)

function Cat:speak()
  return 'meow'
end

Lion = class(Cat)

function Lion:speak()
  return 'roar'
end
-- init of class

local BigCat = Lion('Leo', 'African')
print(Leo)
--- "Leo: roar"

print(BigCat:is_a(Cat))
--- "true"

Source: http://lua-users.org/wiki/SimpleLuaClasses

About

Simulates Class Instances for Lua

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages