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
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)
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
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.