1
0
Fork
You've already forked lua-class
0
Class-like tables for Lua.
  • Lua 76.9%
  • Python 23.1%
Find a file
2026年06月07日 19:12:03 -07:00
.gitattributes Script to generate rockspec file (WIP) 2026年06月03日 17:07:31 -07:00
.gitignore Exclude .rockspec files from Git 2026年06月03日 17:07:58 -07:00
example.lua Rework 2026年06月07日 19:12:03 -07:00
gen-rockspec.py Find absolute root path in rockspec script 2026年06月04日 01:11:37 -07:00
LICENSE.txt Add license & README texts 2026年06月03日 15:37:57 -07:00
lua-class.lua Rework 2026年06月07日 19:12:03 -07:00
README.md Add to TODO list 2026年06月04日 00:48:08 -07:00

Lua Classes (OOP)

Description

Lua library that provides method for creating class-like tables that can be instantiated.

Notes

Code is AI assisted. AI was used for reference & code checking.

Usage

A single function, NewClass, is provided & can be called with the following parameters:

  • NewClass(): Creates a bare-minimum new class without inheritence.
  • NewClass(template): Creates a new class from template without inheritence. Same as NewClass(nil, template).
  • NewClass(parent, template): Creates a new class from template with inheritence from parent.

Parameter descriptions:

  • template: Table template of new class.
  • parent: The parent class that is being inherited.

Construction calls the template.__init function property. If the template table does not have the function, a default with only the self parameter will be added.

-- example of creating a class with a custom constructor
local MyClass = NewClass({
 __init = function(self, name)
 self.name = name
 end
})

See example.

Licensing

Git Repo Mirrors:

TODO

  • Option to make function properties private.
  • Mixin support.
  • Support calling super-class functions.
  • Support checking inheritence with instanceof like function.