Added support for Generic Types with my OOP library
I'm trying to make a better error detection framework for my addons so I made an OOP framework to support strong typing. This has proven to be really useful for me as it has simplified all my debugging.
It has ensured that I am not passing in nil values into functions that expect certain values and means I no longer need to add tons of if-statements to check for nils, or for certain value types.
I have just added generic type classes. It's not one of the most useful features but I have used it and I think it's a cool addition to have. For example, I use it for creating lists that should only contain Frames/Buttons/instances of classes, etc...
This is the syntax:
local KeyValuePair = TestPackage:CreateClass("KeyValuePair<K, V>");
function KeyValuePair:Add(data, key, value)
-- do stuff
local myInstance = KeyValuePair:Of("string", "number")();
Basically, this creates an instance of "KeyValuePair" and specifies that the K generic type must be a string, and V must be a number. If you call the "Add" method with anything else then it will throw an error.
You can also use "any" to specify any value that is not null, and "?string" to specify an optional string.
EDIT: Also, "data" is a special table for holding private instance data. It doesn't take part in the validation and is given to the function after it has been called (you don't pass it manually during the function call).