Anyone interested in this kind of OOP approach?

If I put out a Module for this, would anyone be interesting in an OOP approach as such?

Example of a Vector3 replacement class (just to show features)

Some of the things this class does:

Example of a singleton object below also- Not really necessary, but all the more satisfactory to be able to use property getters/setters. It’s mostly for custom service creation

image

Its mostly for personal use, so if no one wants it, I’ll keep it lol. Tell me what you think though.

EDIT: async.method works too. the events part puts a RbxUtility signal into the class.
EDIT 2: I didnt make it clear, It’s already finished in the presented state, but if others are interested I can make different implementations or add features. 295 LOC atm

(also my friend jerrin wants credit for giving me the idea, so, here u go jerrin)

4 Likes

What does var'magnitude'*nil mean?

What do the error messages look like if you forget any single piece of the puzzle?

2 Likes

I’ve made a module similar to this: (OOP) Class Module

Although I’m curious as to how you’d implement this with the limitations of Roblox Lua.

it’s just setting magnitude to nil, but declaring it for the sake of putting a getter in there.

Errors aren’t handled quite nice just yet, but thats why I’m ask what y’all think of this, so I know whether or not to put in the work to make an error handling system

I already did implement it
~295 lines of code as of right now

Some syntax sugar:

func 'string'
-- is short for
func('string')
func {}
-- is short for
func({})
func 'string' {}
-- is short for
func('string')({})
-- aka
local res1 = func('string')
res1({})

These are things you can do right now. I know some people that prefer to do game:GetService'HttpService' instead of game:GetService('HttpService'), for example.

Some metatables:

var, for example, is just a function that returns a table. That table has a metatable which lets it use the * operator with other types and returns some object that’s used internally to define object members. Here’s an example:

local varMeta = {
	__mul = function(self, other)
		self.value = other
		return self
	end,
}
local function var(name)
	return setmetatable({name = name}, varMeta)
end

local example = var 'ExampleVar' * 5
print(example.name,'=',example.value)

Each class or object is just an array of member descriptors, which is probably transformed into a more efficient format internally. The class and object methods likely apply get and set to the last-declared variable, which is why var 'Name' * nil is needed.

This might not match the specific implementation in this case, but it does explain how it is possible in Lua, which seems to be what you were interested in.

3 Likes

Seems interesting, I’d definitely experiment with it at the very least.

2 Likes