a recreation of JavaScript classes and prototypes in lua and luau
includes:
- class, new, and extend keywords
- class checking and super functions
- isa and getclass built-in functions
localclass, new, extend=require("classjs")("class", "new", "extend");
localBase=class"Base" {
constructor=function(self, name)
self.Name=name;
end,
AddAttribute=function(self, k, v)
self.Attributes[k] =v;
returnself.Attributes;
end,
Attributes= {}
}
functionBase.ClearAttributes(self)
self.Attributes= {};
returnself.Attributes;
endextend"Base" "User" {
constructor=function(self, id, name)
self.Id=id;
self.__super(name);
end,
RemoveAttribute=function(self, k)
self.Attributes[k] =nil;
end,
Attributes= {
Type="User"
}
}
localuser=new"User"("user_1", "User1");
print(user.Attributes); -- { Type = "User" }user.RemoveAttribute("Type");
user.AddAttribute("Status", "Cool");
print(user.Attributes); -- { Status = "Cool" }user.ClearAttributes();
print(user.Attributes); -- { }