Classes for luau module

typeof(if type(class) == "string" then nil else class) doesn’t work for some reason

class.rbxm (1.8 KB)

Guys new update now there is autocompletion for classes and stuff

My apologies, the thing I was talking about had been brought down before.

archived comment

Just noticed in the code that you used the functions “getfenv” and “setfenv” which is deprecated and disables a Luau optimization.

I would recommend that you pass the this object to the first argument of constructor and the new function constructor should get the class name from the first passed argument. Only problem is that you will need to cache created class constructors (I know you are already doing that on the global environment.) or just ditch the class "Clazz" {} in exchange of local Clazz = class {} and add the new function on created class constructor

1 Like

New update

I fixed a bug that freezes everything if you use extends

class.rbxm (1.7 KB)

Luau does optimize native code generation with types are applied, as it is like saying “This function should be correct, and will not face deoptimization (most likely)”. setfenv has a negative impact on the performance, but it’s because it disables optimizations across the board (safeenv).

Basically, functions will not face deoptimization when correctly called, and types allow you to get the optimization from the start, why do you think bytecode now includes type information?

1 Like

You can try through the usage of generics

Fixed a small bug

class.rbxm (1.7 KB)

Wow, Awesome module, dude! char

1 Like