teal-language / tl

The compiler for Teal, a typed dialect of Lua
MIT License
2.1k stars 108 forks source link

Add classes and objects #537

Closed ghost closed 2 years ago

ghost commented 2 years ago

How do I modify the compiler to add a class type and an Object type.

ghost commented 2 years ago

And of course the new keyword and the constructor feature.

lenscas commented 2 years ago

Records are what Teal uses to create "classes", what would be the benefit of the new keyword?

Remember, Lua doesn't have classes, if you want inheritance you have to set those systems up yourself in lua. There is an entire discussion on how teal should deal with it at https://github.com/teal-language/tl/issues/200

ghost commented 2 years ago

Because adding new types reduces the number of errors raised by using and creating OOP programming on tl.Adding new keywords makes the construction of the OOP programming system simpler.

lenscas commented 2 years ago

again, records are used to create new types. They will act as classes once/if a good model on how to do inheritance in teal is agreed upon. (Read the linked issue). The only difference between records and classes are their names.

new doesn't really do anything besides calling the constructor, you don't need the keyword new for that. Just create static functions that return the type. That is all the new Type() thing abstracts away. As an example, F# code doesn't need the new keyword. If I want to instance something it is just Type() and yet it works perfectly fine with C# types.

Now, there might be a reason to add new depending on the kind of OOP style teal ends up going with, but that is probably better discussed in #200

hishamhm commented 2 years ago

Closing this as a duplicate of #97 — there are no immediate plans to add class and object primiteves, but they're not discarded either.