A lightweight, flexible, and extensible object-oriented programming (OOP) system for Lua.
Provides class creation, inheritance, encapsulation, operator overloading, and utility helpers — all in a single file.
Designed for seamless integration in any Lua project, with support for private members, super calls, and robust debugging tools. Inspired by :
Hump.Class
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
Class is a self-contained OOP system written in pure Lua. Its goal is to bridge the gap between minimalistic design and powerful features. It is especially handy for environments like Garry's Mod or any Lua-based game/modding framework where OOP-like structures can simplify code organization.
Key Features:
- 🔧 Dynamic class creation
- 🧬 Inheritance with
supercall support - 🧱 Public / private members
- 🔄 Operator overloading
- 🔍 Debug helpers
Here’s how to set up the project locally.
You’ll need Lua installed:
-
Clone the repo:
git clone https://github.com/Gopmyc/Class.git cd Class -
Include
class.luain your Lua project:require("class")
local Class = require("class")
local A = Class{
foo = function()
print('foo')
end,
}
local B = Class{
bar = function()
print('bar')
end,
}
-- single inheritance
local C = Class{__includes = A}
instance = C()
instance:foo() -- prints 'foo'
instance:bar() -- error: function not defined
-- multiple inheritance
local D = Class{__includes = {A,B}}
instance = D()
instance:foo() -- prints 'foo'
instance:bar() -- prints 'bar'For more examples, check the documentation.
- Basic class + inheritance
- Private/protected fields
- Super call support
- Operator overloading
- Static fields / class-level attributes
- Decorators / Mixins
- Full test suite
Feel free to suggest features via issues.
Contributions make open source better! If you’ve got a fix or idea, fork and PR it.
Steps:
- Fork this repo
- Create a branch (
git checkout -b feature/MyFeature) - Commit (
git commit -m 'Add MyFeature') - Push (
git push origin feature/MyFeature) - Submit a Pull Request
Distributed under the MIT License.
See LICENSE for more info.
Gopmyc 📧 gopmyc.pro@gmail.com 🔗 https://github.com/Gopmyc/Class