Nex - one module for creating classes

Nex

It is a one module to create classes and has few useful tools. You may get it on roblox or github.

On Github you may find a Wiki to learn more about this module.

Here is example code, (it was took from github).

local class = require('nex')

local Square = class "Square" {} -- class "Square" {} == class("Square")({})

function Square:init(width, height)
    self.width = width
    self.height = height
end

function Square:area()
    return self.width * self.height
end

local mySquare = Square(50, 10)
print(mySquare:area())
Why did I created this?

Almost every year for no reason, I write class module for lua, probably just for check my ability in programming in lua. I think It is last time I write class module.

2 Likes

v1.0.4 Pre-release

I just recreated nex from scratch again and changed some syntax/grammar.

Here is small piece of README.md basically to demonstrate most simple use case of nex

```luau
local nex = -- require "nex"

-- to create a class you just need call nex with leading string which is unique name of the class
local player = nex "player"

-- new is reserver function to be a constructor
function player:new(name)
    self.name = name
end

-- metamethods can be overloaded, but be careful, some might lead to unexpected behaviour
-- namely for `__new` and `__newindex`
function player:__tostring()
    return self.name
end

-- to create an instance of the class just call it, and pass arguments if needed
local bop = player("bop")
print(bop) -- output: bop