Fast class system with support for inheritance. Cannot call super constructor. Constructor is inherited but can be modified
local Base = require("shard.base")
Extends class with specified class name
Creates class with parameters and calls Base:init
Checks if class extends specified class
local Base = require("shard/base")
local Entity = Base:extend("Entity")
function Entity:init()
print("entity created")
end
function Entity:takeDamage(damage)
print("entity took damage " .. damage)
end
local Player = Entity:extend("Player")
function Player:walk()
print("player walked")
end
local player = Player()
player:takeDamage(5.2)
player:walk()
print(player:is(Entity))
- extend - extends class
- new - instantiates class
- is - checks if class extends specified class
- init - constructor, called when instantiating class
- _className - Class name, DONT MODIFY
- _extends - List of class names that this class extends (class cannot extend multiple classes), DONT MODIFY
- _mt - Metatable, you can add custom methods but DO NOT MODIFY __index